Datasets:
AI4M
/

text
stringlengths
0
3.34M
[GOAL] ⊒ 1 = ‖↑reClm 1β€– [PROOFSTEP] simp [GOAL] ⊒ β€–1β€– ≀ 1 [PROOFSTEP] simp [GOAL] ⊒ 1 = ‖↑imClm Iβ€– [PROOFSTEP] simp [GOAL] ⊒ β€–Iβ€– ≀ 1 [PROOFSTEP] simp
postulate ∞ : βˆ€ {a} (A : Set a) β†’ Set a β™―_ : βˆ€ {a} {A : Set a} β†’ A β†’ ∞ A β™­ : βˆ€ {a} {A : Set a} β†’ ∞ A β†’ A {-# BUILTIN INFINITY ∞ #-} {-# BUILTIN SHARP β™―_ #-} {-# BUILTIN FLAT β™­ #-} {-# COMPILE GHC β™­ as flat #-}
import MyNat.Definition import AdditionWorld.Level4 -- add_comm import AdvancedAdditionWorld.Level5 -- add_right_cancel namespace MyNat open MyNat /-! # Advanced Addition World ## Level 7: `add_right_cancel_iff` It's sometimes convenient to have the "if and only if" version of theorems like `add_right_cancel`. Remember that you can use `constructor` to split an `↔` goal into the `β†’` goal and the `←` goal. ## Pro tip: Notice `exact add_right_cancel _ _ _` means "let Lean figure out the missing inputs" so we don't have to spell it out like we did in Level 6. ## Theorem For all naturals `a`, `b` and `t`, `a + t = b + t ↔ a = b.` -/ theorem add_right_cancel_iff (t a b : MyNat) : a + t = b + t ↔ a = b := by constructor exact add_right_cancel _ _ _ intro h rw [h] /-! Next up [Level 8](./Level8.lean.md) -/
informal statement Prove that for each positive integer $n$, the number $10^{10^{10^n}}+10^{10^n}+10^n-1$ is not prime.formal statement theorem exercise_2000_a2 : βˆ€ N : β„•, βˆƒ n : β„•, n > N ∧ βˆƒ i : fin 6 β†’ β„•, n = (i 0)^2 + (i 1)^2 ∧ n + 1 = (i 2)^2 + (i 3)^2 ∧ n + 2 = (i 4)^2 + (i 5)^2 :=
informal statement An ideal $N$ is called nilpotent if $N^{n}$ is the zero ideal for some $n \geq 1$. Prove that the ideal $p \mathbb{Z} / p^{m} \mathbb{Z}$ is a nilpotent ideal in the ring $\mathbb{Z} / p^{m} \mathbb{Z}$.formal statement theorem exercise_7_3_37 {R : Type*} {p m : β„•} (hp : p.prime) (N : ideal $ zmod $ p^m) : is_nilpotent N ↔ is_nilpotent (ideal.span ({p} : set $ zmod $ p^m)) :=
! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. ! See https://llvm.org/LICENSE.txt for license information. ! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception subroutine weird(dummy) class(*), target :: dummy(:) end subroutine weird program main integer(kind=4), pointer :: myptr(:) integer :: j logical rslt(8), expect(8) interface subroutine weird(dummy) class(*), target :: dummy(:) end subroutine weird end interface allocate(myptr(4)) myptr = [(111*j, j=1,4)] expect = .true. do j=1,4 rslt(j) = (myptr(j) .eq. (111*j)) enddo call weird(myptr) do j=1,4 rslt(j+4) = (myptr(j) .eq. (111*j)) enddo call check(rslt,expect,8) end program main
(* Title: HOL/Bali/Trans.thy Author: David von Oheimb and Norbert Schirmer Operational transition (small-step) semantics of the execution of Java expressions and statements PRELIMINARY!!!!!!!! *) theory Trans imports Evaln begin definition groundVar :: "var \<Rightarrow> bool" where "groundVar v \<longleftrightarrow> (case v of LVar ln \<Rightarrow> True | {accC,statDeclC,stat}e..fn \<Rightarrow> \<exists> a. e=Lit a | e1.[e2] \<Rightarrow> \<exists> a i. e1= Lit a \<and> e2 = Lit i | InsInitV c v \<Rightarrow> False)" lemma groundVar_cases: assumes ground: "groundVar v" obtains (LVar) ln where "v=LVar ln" | (FVar) accC statDeclC stat a fn where "v={accC,statDeclC,stat}(Lit a)..fn" | (AVar) a i where "v=(Lit a).[Lit i]" using ground LVar FVar AVar by (cases v) (auto simp add: groundVar_def) definition groundExprs :: "expr list \<Rightarrow> bool" where "groundExprs es \<longleftrightarrow> (\<forall>e \<in> set es. \<exists>v. e = Lit v)" primrec the_val:: "expr \<Rightarrow> val" where "the_val (Lit v) = v" primrec the_var:: "prog \<Rightarrow> state \<Rightarrow> var \<Rightarrow> (vvar \<times> state)" where "the_var G s (LVar ln) = (lvar ln (store s),s)" | the_var_FVar_def: "the_var G s ({accC,statDeclC,stat}a..fn) =fvar statDeclC stat fn (the_val a) s" | the_var_AVar_def: "the_var G s(a.[i]) =avar G (the_val i) (the_val a) s" lemma the_var_FVar_simp[simp]: "the_var G s ({accC,statDeclC,stat}(Lit a)..fn) = fvar statDeclC stat fn a s" by (simp) declare the_var_FVar_def [simp del] lemma the_var_AVar_simp: "the_var G s ((Lit a).[Lit i]) = avar G i a s" by (simp) declare the_var_AVar_def [simp del] abbreviation Ref :: "loc \<Rightarrow> expr" where "Ref a == Lit (Addr a)" abbreviation SKIP :: "expr" where "SKIP == Lit Unit" inductive step :: "[prog,term \<times> state,term \<times> state] \<Rightarrow> bool" ("_\<turnstile>_ \<mapsto>1 _"[61,82,82] 81) for G :: prog where (* evaluation of expression *) (* cf. 15.5 *) Abrupt: "\<lbrakk>\<forall>v. t \<noteq> \<langle>Lit v\<rangle>; \<forall> t. t \<noteq> \<langle>l\<bullet> Skip\<rangle>; \<forall> C vn c. t \<noteq> \<langle>Try Skip Catch(C vn) c\<rangle>; \<forall> x c. t \<noteq> \<langle>Skip Finally c\<rangle> \<and> xc \<noteq> Xcpt x; \<forall> a c. t \<noteq> \<langle>FinA a c\<rangle>\<rbrakk> \<Longrightarrow> G\<turnstile>(t,Some xc,s) \<mapsto>1 (\<langle>Lit undefined\<rangle>,Some xc,s)" | InsInitE: "\<lbrakk>G\<turnstile>(\<langle>c\<rangle>,Norm s) \<mapsto>1 (\<langle>c'\<rangle>, s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>InsInitE c e\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitE c' e\<rangle>, s')" (* SeqE: "G\<turnstile>(\<langle>Seq Skip e\<rangle>,Norm s) \<mapsto>1 (\<langle>e\<rangle>, Norm s)" *) (* Specialised rules to evaluate: InsInitE Skip (NewC C), InisInitE Skip (NewA T[e]) *) (* cf. 15.8.1 *) | NewC: "G\<turnstile>(\<langle>NewC C\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitE (Init C) (NewC C)\<rangle>, Norm s)" | NewCInited: "\<lbrakk>G\<turnstile> Norm s \<midarrow>halloc (CInst C)\<succ>a\<rightarrow> s'\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>InsInitE Skip (NewC C)\<rangle>,Norm s) \<mapsto>1 (\<langle>Ref a\<rangle>, s')" (* Alternative when rule SeqE is present NewCInited: "\<lbrakk>inited C (globs s); G\<turnstile> Norm s \<midarrow>halloc (CInst C)\<succ>a\<rightarrow> s'\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>NewC C\<rangle>,Norm s) \<mapsto>1 (\<langle>Ref a\<rangle>, s')" NewC: "\<lbrakk>\<not> inited C (globs s)\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>NewC C\<rangle>,Norm s) \<mapsto>1 (\<langle>Seq (Init C) (NewC C)\<rangle>, Norm s)" *) (* cf. 15.9.1 *) | NewA: "G\<turnstile>(\<langle>New T[e]\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitE (init_comp_ty T) (New T[e])\<rangle>,Norm s)" | InsInitNewAIdx: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>, s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>InsInitE Skip (New T[e])\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitE Skip (New T[e'])\<rangle>,s')" | InsInitNewA: "\<lbrakk>G\<turnstile>abupd (check_neg i) (Norm s) \<midarrow>halloc (Arr T (the_Intg i))\<succ>a\<rightarrow> s' \<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>InsInitE Skip (New T[Lit i])\<rangle>,Norm s) \<mapsto>1 (\<langle>Ref a\<rangle>,s')" (* cf. 15.15 *) | CastE: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>Cast T e\<rangle>,None,s) \<mapsto>1 (\<langle>Cast T e'\<rangle>,s')" | Cast: "\<lbrakk>s' = abupd (raise_if (\<not>G,s\<turnstile>v fits T) ClassCast) (Norm s)\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>Cast T (Lit v)\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit v\<rangle>,s')" (* can be written without abupd, since we know Norm s *) | InstE: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'::expr\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>e InstOf T\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')" | Inst: "\<lbrakk>b = (v\<noteq>Null \<and> G,s\<turnstile>v fits RefT T)\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>(Lit v) InstOf T\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit (Bool b)\<rangle>,s')" (* cf. 15.7.1 *) (*Lit "G\<turnstile>(Lit v,None,s) \<mapsto>1 (Lit v,None,s)"*) | UnOpE: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s') \<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>UnOp unop e\<rangle>,Norm s) \<mapsto>1 (\<langle>UnOp unop e'\<rangle>,s')" | UnOp: "G\<turnstile>(\<langle>UnOp unop (Lit v)\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit (eval_unop unop v)\<rangle>,Norm s)" | BinOpE1: "\<lbrakk>G\<turnstile>(\<langle>e1\<rangle>,Norm s) \<mapsto>1 (\<langle>e1'\<rangle>,s') \<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>BinOp binop e1 e2\<rangle>,Norm s) \<mapsto>1 (\<langle>BinOp binop e1' e2\<rangle>,s')" | BinOpE2: "\<lbrakk>need_second_arg binop v1; G\<turnstile>(\<langle>e2\<rangle>,Norm s) \<mapsto>1 (\<langle>e2'\<rangle>,s') \<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>BinOp binop (Lit v1) e2\<rangle>,Norm s) \<mapsto>1 (\<langle>BinOp binop (Lit v1) e2'\<rangle>,s')" | BinOpTerm: "\<lbrakk>\<not> need_second_arg binop v1\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>BinOp binop (Lit v1) e2\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit v1\<rangle>,Norm s)" | BinOp: "G\<turnstile>(\<langle>BinOp binop (Lit v1) (Lit v2)\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit (eval_binop binop v1 v2)\<rangle>,Norm s)" (* Maybe its more convenient to add: need_second_arg as precondition to BinOp to make the choice between BinOpTerm and BinOp deterministic *) | Super: "G\<turnstile>(\<langle>Super\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit (val_this s)\<rangle>,Norm s)" | AccVA: "\<lbrakk>G\<turnstile>(\<langle>va\<rangle>,Norm s) \<mapsto>1 (\<langle>va'\<rangle>,s') \<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>Acc va\<rangle>,Norm s) \<mapsto>1 (\<langle>Acc va'\<rangle>,s')" | Acc: "\<lbrakk>groundVar va; ((v,vf),s') = the_var G (Norm s) va\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>Acc va\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit v\<rangle>,s')" (* AccLVar: "G\<turnstile>(\<langle>Acc (LVar vn)\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit (fst (lvar vn s))\<rangle>,Norm s)" AccFVar: "\<lbrakk>((v,vf),s') = fvar statDeclC stat fn a (Norm s)\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>Acc ({accC,statDeclC,stat}(Lit a)..fn)\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit v\<rangle>,s')" AccAVar: "\<lbrakk>((v,vf),s') = avar G i a (Norm s)\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>Acc ((Lit a).[Lit i])\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit v\<rangle>,s')" *) | AssVA: "\<lbrakk>G\<turnstile>(\<langle>va\<rangle>,Norm s) \<mapsto>1 (\<langle>va'\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>va:=e\<rangle>,Norm s) \<mapsto>1 (\<langle>va':=e\<rangle>,s')" | AssE: "\<lbrakk>groundVar va; G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>va:=e\<rangle>,Norm s) \<mapsto>1 (\<langle>va:=e'\<rangle>,s')" | Ass: "\<lbrakk>groundVar va; ((w,f),s') = the_var G (Norm s) va\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>va:=(Lit v)\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit v\<rangle>,assign f v s')" | CondC: "\<lbrakk>G\<turnstile>(\<langle>e0\<rangle>,Norm s) \<mapsto>1 (\<langle>e0'\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>e0? e1:e2\<rangle>,Norm s) \<mapsto>1 (\<langle>e0'? e1:e2\<rangle>,s')" | Cond: "G\<turnstile>(\<langle>Lit b? e1:e2\<rangle>,Norm s) \<mapsto>1 (\<langle>if the_Bool b then e1 else e2\<rangle>,Norm s)" | CallTarget: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>{accC,statT,mode}e\<cdot>mn({pTs}args)\<rangle>,Norm s) \<mapsto>1 (\<langle>{accC,statT,mode}e'\<cdot>mn({pTs}args)\<rangle>,s')" | CallArgs: "\<lbrakk>G\<turnstile>(\<langle>args\<rangle>,Norm s) \<mapsto>1 (\<langle>args'\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>{accC,statT,mode}Lit a\<cdot>mn({pTs}args)\<rangle>,Norm s) \<mapsto>1 (\<langle>{accC,statT,mode}Lit a\<cdot>mn({pTs}args')\<rangle>,s')" | Call: "\<lbrakk>groundExprs args; vs = map the_val args; D = invocation_declclass G mode s a statT \<lparr>name=mn,parTs=pTs\<rparr>; s'=init_lvars G D \<lparr>name=mn,parTs=pTs\<rparr> mode a' vs (Norm s)\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>{accC,statT,mode}Lit a\<cdot>mn({pTs}args)\<rangle>,Norm s) \<mapsto>1 (\<langle>Callee (locals s) (Methd D \<lparr>name=mn,parTs=pTs\<rparr>)\<rangle>,s')" | Callee: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'::expr\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>Callee lcls_caller e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')" | CalleeRet: "G\<turnstile>(\<langle>Callee lcls_caller (Lit v)\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit v\<rangle>,(set_lvars lcls_caller (Norm s)))" | Methd: "G\<turnstile>(\<langle>Methd D sig\<rangle>,Norm s) \<mapsto>1 (\<langle>body G D sig\<rangle>,Norm s)" | Body: "G\<turnstile>(\<langle>Body D c\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitE (Init D) (Body D c)\<rangle>,Norm s)" | InsInitBody: "\<lbrakk>G\<turnstile>(\<langle>c\<rangle>,Norm s) \<mapsto>1 (\<langle>c'\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>InsInitE Skip (Body D c)\<rangle>,Norm s) \<mapsto>1(\<langle>InsInitE Skip (Body D c')\<rangle>,s')" | InsInitBodyRet: "G\<turnstile>(\<langle>InsInitE Skip (Body D Skip)\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit (the ((locals s) Result))\<rangle>,abupd (absorb Ret) (Norm s))" (* LVar: "G\<turnstile>(LVar vn,Norm s)" is already evaluated *) | FVar: "\<lbrakk>\<not> inited statDeclC (globs s)\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>{accC,statDeclC,stat}e..fn\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitV (Init statDeclC) ({accC,statDeclC,stat}e..fn)\<rangle>,Norm s)" | InsInitFVarE: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>InsInitV Skip ({accC,statDeclC,stat}e..fn)\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitV Skip ({accC,statDeclC,stat}e'..fn)\<rangle>,s')" | InsInitFVar: "G\<turnstile>(\<langle>InsInitV Skip ({accC,statDeclC,stat}Lit a..fn)\<rangle>,Norm s) \<mapsto>1 (\<langle>{accC,statDeclC,stat}Lit a..fn\<rangle>,Norm s)" \<comment> \<open>Notice, that we do not have literal values for \<open>vars\<close>. The rules for accessing variables (\<open>Acc\<close>) and assigning to variables (\<open>Ass\<close>), test this with the predicate \<open>groundVar\<close>. After initialisation is done and the \<open>FVar\<close> is evaluated, we can't just throw away the \<open>InsInitFVar\<close> term and return a literal value, as in the cases of \<open>New\<close> or \<open>NewC\<close>. Instead we just return the evaluated \<open>FVar\<close> and test for initialisation in the rule \<open>FVar\<close>.\<close> | AVarE1: "\<lbrakk>G\<turnstile>(\<langle>e1\<rangle>,Norm s) \<mapsto>1 (\<langle>e1'\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>e1.[e2]\<rangle>,Norm s) \<mapsto>1 (\<langle>e1'.[e2]\<rangle>,s')" | AVarE2: "G\<turnstile>(\<langle>e2\<rangle>,Norm s) \<mapsto>1 (\<langle>e2'\<rangle>,s') \<Longrightarrow> G\<turnstile>(\<langle>Lit a.[e2]\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit a.[e2']\<rangle>,s')" (* AVar: \<langle>(Lit a).[Lit i]\<rangle> is fully evaluated *) (* evaluation of expression lists *) \<comment> \<open>\<open>Nil\<close> is fully evaluated\<close> | ConsHd: "\<lbrakk>G\<turnstile>(\<langle>e::expr\<rangle>,Norm s) \<mapsto>1 (\<langle>e'::expr\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>e#es\<rangle>,Norm s) \<mapsto>1 (\<langle>e'#es\<rangle>,s')" | ConsTl: "\<lbrakk>G\<turnstile>(\<langle>es\<rangle>,Norm s) \<mapsto>1 (\<langle>es'\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>(Lit v)#es\<rangle>,Norm s) \<mapsto>1 (\<langle>(Lit v)#es'\<rangle>,s')" (* execution of statements *) (* cf. 14.5 *) | Skip: "G\<turnstile>(\<langle>Skip\<rangle>,Norm s) \<mapsto>1 (\<langle>SKIP\<rangle>,Norm s)" | ExprE: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>Expr e\<rangle>,Norm s) \<mapsto>1 (\<langle>Expr e'\<rangle>,s')" | Expr: "G\<turnstile>(\<langle>Expr (Lit v)\<rangle>,Norm s) \<mapsto>1 (\<langle>Skip\<rangle>,Norm s)" | LabC: "\<lbrakk>G\<turnstile>(\<langle>c\<rangle>,Norm s) \<mapsto>1 (\<langle>c'\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>l\<bullet> c\<rangle>,Norm s) \<mapsto>1 (\<langle>l\<bullet> c'\<rangle>,s')" | Lab: "G\<turnstile>(\<langle>l\<bullet> Skip\<rangle>,s) \<mapsto>1 (\<langle>Skip\<rangle>, abupd (absorb l) s)" (* cf. 14.2 *) | CompC1: "\<lbrakk>G\<turnstile>(\<langle>c1\<rangle>,Norm s) \<mapsto>1 (\<langle>c1'\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>c1;; c2\<rangle>,Norm s) \<mapsto>1 (\<langle>c1';; c2\<rangle>,s')" | Comp: "G\<turnstile>(\<langle>Skip;; c2\<rangle>,Norm s) \<mapsto>1 (\<langle>c2\<rangle>,Norm s)" (* cf. 14.8.2 *) | IfE: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle> ,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>If(e) s1 Else s2\<rangle>,Norm s) \<mapsto>1 (\<langle>If(e') s1 Else s2\<rangle>,s')" | If: "G\<turnstile>(\<langle>If(Lit v) s1 Else s2\<rangle>,Norm s) \<mapsto>1 (\<langle>if the_Bool v then s1 else s2\<rangle>,Norm s)" (* cf. 14.10, 14.10.1 *) | Loop: "G\<turnstile>(\<langle>l\<bullet> While(e) c\<rangle>,Norm s) \<mapsto>1 (\<langle>If(e) (Cont l\<bullet>c;; l\<bullet> While(e) c) Else Skip\<rangle>,Norm s)" | Jmp: "G\<turnstile>(\<langle>Jmp j\<rangle>,Norm s) \<mapsto>1 (\<langle>Skip\<rangle>,(Some (Jump j), s))" | ThrowE: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>Throw e\<rangle>,Norm s) \<mapsto>1 (\<langle>Throw e'\<rangle>,s')" | Throw: "G\<turnstile>(\<langle>Throw (Lit a)\<rangle>,Norm s) \<mapsto>1 (\<langle>Skip\<rangle>,abupd (throw a) (Norm s))" | TryC1: "\<lbrakk>G\<turnstile>(\<langle>c1\<rangle>,Norm s) \<mapsto>1 (\<langle>c1'\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>Try c1 Catch(C vn) c2\<rangle>, Norm s) \<mapsto>1 (\<langle>Try c1' Catch(C vn) c2\<rangle>,s')" | Try: "\<lbrakk>G\<turnstile>s \<midarrow>sxalloc\<rightarrow> s'\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>Try Skip Catch(C vn) c2\<rangle>, s) \<mapsto>1 (if G,s'\<turnstile>catch C then (\<langle>c2\<rangle>,new_xcpt_var vn s') else (\<langle>Skip\<rangle>,s'))" | FinC1: "\<lbrakk>G\<turnstile>(\<langle>c1\<rangle>,Norm s) \<mapsto>1 (\<langle>c1'\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>c1 Finally c2\<rangle>,Norm s) \<mapsto>1 (\<langle>c1' Finally c2\<rangle>,s')" | Fin: "G\<turnstile>(\<langle>Skip Finally c2\<rangle>,(a,s)) \<mapsto>1 (\<langle>FinA a c2\<rangle>,Norm s)" | FinAC: "\<lbrakk>G\<turnstile>(\<langle>c\<rangle>,s) \<mapsto>1 (\<langle>c'\<rangle>,s')\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>FinA a c\<rangle>,s) \<mapsto>1 (\<langle>FinA a c'\<rangle>,s')" | FinA: "G\<turnstile>(\<langle>FinA a Skip\<rangle>,s) \<mapsto>1 (\<langle>Skip\<rangle>,abupd (abrupt_if (a\<noteq>None) a) s)" | Init1: "\<lbrakk>inited C (globs s)\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>Init C\<rangle>,Norm s) \<mapsto>1 (\<langle>Skip\<rangle>,Norm s)" | Init: "\<lbrakk>the (class G C)=c; \<not> inited C (globs s)\<rbrakk> \<Longrightarrow> G\<turnstile>(\<langle>Init C\<rangle>,Norm s) \<mapsto>1 (\<langle>(if C = Object then Skip else (Init (super c)));; Expr (Callee (locals s) (InsInitE (init c) SKIP))\<rangle> ,Norm (init_class_obj G C s))" \<comment> \<open>\<open>InsInitE\<close> is just used as trick to embed the statement \<open>init c\<close> into an expression\<close> | InsInitESKIP: "G\<turnstile>(\<langle>InsInitE Skip SKIP\<rangle>,Norm s) \<mapsto>1 (\<langle>SKIP\<rangle>,Norm s)" abbreviation stepn:: "[prog, term \<times> state,nat,term \<times> state] \<Rightarrow> bool" ("_\<turnstile>_ \<mapsto>_ _"[61,82,82] 81) where "G\<turnstile>p \<mapsto>n p' \<equiv> (p,p') \<in> {(x, y). step G x y}^^n" abbreviation steptr:: "[prog,term \<times> state,term \<times> state] \<Rightarrow> bool" ("_\<turnstile>_ \<mapsto>* _"[61,82,82] 81) where "G\<turnstile>p \<mapsto>* p' \<equiv> (p,p') \<in> {(x, y). step G x y}\<^sup>*" (* Equivalenzen: Bigstep zu Smallstep komplett. Smallstep zu Bigstep, nur wenn nicht die AusdrΓΌcke Callee, FinA ,\<dots> *) (* lemma imp_eval_trans: assumes eval: "G\<turnstile>s0 \<midarrow>t\<succ>\<rightarrow> (v,s1)" shows trans: "G\<turnstile>(t,s0) \<mapsto>* (\<langle>Lit v\<rangle>,s1)" *) (* Jetzt muss man bei trans natΓΌrlich wieder unterscheiden: Stmt, Expr, Var! Sowas blΓΆdes: Am besten den Terminus ground auf Var,Stmt,Expr hochziehen und dann the_vals definieren\<dots> G\<turnstile>(t,s0) \<mapsto>* (t',s1) \<and> the_vals t' = v *) end
informal statement Prove that there exist infinitely many integers $n$ such that $n, n+1, n+2$ are each the sum of the squares of two integers.formal statement theorem exercise_1998_a3 (f : ℝ β†’ ℝ) (hf : cont_diff ℝ 3 f) : βˆƒ a : ℝ, (f a) * (deriv f a) * (iterated_deriv 2 f a) * (iterated_deriv 3 f a) β‰₯ 0 :=
import Smt import Smt.Data.BitVec theorem append_eq_shl_or_2 (x y : BitVec 2) : x ++ y = (x.zeroExtend 2 <<< 2) ||| y.zeroExtend 2 := by smt sorry theorem append_eq_shl_or_3 (x y : BitVec 3) : x ++ y = (x.zeroExtend 3 <<< 3) ||| y.zeroExtend 3 := by smt sorry
From demo Require Import simplified_iris. Section proof. Context `{!heapGS Ξ£}. Theorem coq_swap (P Q: Prop): P ∧ Q β†’ Q ∧ P. Proof. intros H. destruct H as [HP HQ]. split. - apply HQ. - apply HP. Qed. Theorem prove_swap_the_hard_way x y : x ↦ #0 βˆ— y ↦ #3 ⊒ y ↦ #3 βˆ— x ↦ #0. Proof. iIntros "H". iDestruct "H" as "[Hx Hy]". iSplitL "Hy". - iApply "Hy". - iApply "Hx". Qed. Theorem prove_swap_the_easy_way x y : x ↦ #0 βˆ— y ↦ #3 ⊒ y ↦ #3 βˆ— x ↦ #0. Proof. iIntros "[Hx Hy]". iFrame. Qed. Theorem ex01 (x y: loc) : x ↦ #0 βˆ— y ↦ #0 ⊒ WP #x <- #y;; #y <- #x {{ Ξ» _, x ↦ #y βˆ— y ↦ #x }}. Proof. iIntros "[Hx Hy]". wp_bind (Store _ _). iApply wp_frame. iSplitL "Hx". { iApply (wp_store_axiom with "Hx"). } simpl. iIntros (?) "Hx"; wp_pures. iApply wp_frame. iSplitL "Hy". { iApply (wp_store_axiom with "Hy"). } simpl. iIntros (?) "Hy". iFrame. Qed. End proof.
import data.real.basic -- BEGIN theorem not_monotone_iff {f : ℝ β†’ ℝ}: Β¬ monotone f ↔ βˆƒ x y, x ≀ y ∧ f x > f y := by { rw monotone, push_neg } example : Β¬ monotone (Ξ» x : ℝ, -x) := begin rw monotone, push_neg, use -2, use -1, norm_num, end -- END
[GOAL] ⊒ IsPrincipalIdealRing { x // x ∈ π“ž β„š } [PROOFSTEP] convert IsPrincipalIdealRing.of_surjective (Rat.ringOfIntegersEquiv.symm : β„€ β†’+* ringOfIntegers β„š) Rat.ringOfIntegersEquiv.symm.surjective
-- UNDER CONSTRUCTION. IGNORE. /- Now that we've defined our base and step "machines" (lemmas), we assemble them into an overall proof by applying the induction axiom to them. -/ theorem left_zero : βˆ€ n, 0 + n = n := _ /- EXERCISE: Reformulate the formal proof in the class notes, βˆ€ n, 0 + n = n := _ to use Lean's induction tactic. -/ /- EXERCISE: Give a fluent English-language proof (based on the formal proof). EXERCISE: Give a fluent English-language proof that 2 * sum_to n = n * (n+1). Show all of the algebraic steps needed to complete this proof. If you need to transform expressions using the associativity or commutativity of addition or multiplication, say so. Each step must have a justification. EXERCISE: Give an English language proof by induction of the proposition that, for any natural number, n, a set with n elements has 2^n subsets. EXERCISE: Prove by induction that βˆ€ n, P n, where P n is the proposition that the sum of all the squares of the natural numbers from 0 to n = (n(n+1)(2n+1))/6. A. Using the induction axiom for the natural numbers, applied to base and step functions that you define separately, to implement a function that computes this sum of squares for any natural number, n. Write a few test cases to check that your function appears to be working, at least for n = 0, 1, 3, and 5. B. Formally express the property of a natural number, P n, that asserts that the sum of the squares of the numbers from 0 to any given n equals (n(n+1)(2n+1))/6. C. Define the proposition that every natural number, n, has this property. This is what is to be proved by induction. D. Define a proof of the base case, n = 0. E. Define a proof for the inductive or step case, amounting to a function that, when given any n' and a proof of P n' returns a proof of P (n' + 1). F. Construct a proof of the proposition that every natural number has this property by applying the induction axiom for the natural numbers to n and the base and step proofs. G. Give a fluent English-language proof of the universal generalization based on the work done above. Show *all* of your algebra work. -/
-- Derek Johnson def s1 := "Hello, " def s2 := "Nifty!" def s3 := s1 ++ s2 theorem t1 : (s1 ++ s2) = s3 := eq.refl s3 theorem t2 : 4^2 = 16 := eq.refl 16 theorem t3 : (s1 ++ s2) = s3 ∧ (5^2 = 25) := and.intro (eq.refl s3) (eq.refl 25) theorem t4 : βˆ€ (P Q R : Prop), (P ∧ Q) ∧ (Q ∧ R) β†’ (P ∧ R) := Ξ» (P Q R : Prop), Ξ» h, and.intro (h.left.left)(h.right.right)
/- Copyright (c) 2022 Arthur Paulino. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Arthur Paulino -/ import FxyLang.Reasoning.Defs theorem State.stepNComp : (s^[n₁])^[nβ‚‚] = s^[n₁ + nβ‚‚] := by induction n₁ generalizing s with | zero => simp [stepN] | succ n hi => rw [stepN, @hi s.step] have : n.succ + nβ‚‚ = (n + nβ‚‚).succ := by simp only [Nat.add_comm, Nat.add_assoc, Nat.add_left_comm]; rfl rw [this, stepN] theorem State.extendsForward {s : State} (hs : s.extends sβ‚€) : s.step.extends sβ‚€ := by sorry theorem State.reachDeterministic' (h : ret c₁ k v₁ β†  ret cβ‚‚ k vβ‚‚) : v₁ = vβ‚‚ ∧ c₁ = cβ‚‚ := by sorry theorem State.reachDeterministic (h₁ : s β†  ret c₁ k v₁) (hβ‚‚ : s β†  ret cβ‚‚ k vβ‚‚) : v₁ = vβ‚‚ ∧ c₁ = cβ‚‚ := by sorry theorem Determinism (h₁ : ⟦c, p⟧ Β» ⟦c₁, vβ‚βŸ§) (hβ‚‚ : ⟦c, p⟧ Β» ⟦cβ‚‚, vβ‚‚βŸ§) : v₁ = vβ‚‚ ∧ c₁ = cβ‚‚ := State.reachDeterministic (h₁ default) (hβ‚‚ default)
-- Math 52: Quiz 5 -- Open this file in a folder that contains 'utils'. import utils open classical definition divides (a b : β„€) : Prop := βˆƒ (k : β„€), b = a * k local infix ∣ := divides axiom not_3_divides : βˆ€ (m : β„€), Β¬ (3 ∣ m) ↔ 3 ∣ m - 1 ∨ 3 ∣ m + 1 lemma not_3_divides_of_3_divides_minus_1 : βˆ€ (m : β„€), 3 ∣ m - 1 β†’ Β¬ (3 ∣ m) := begin intros m H, rw not_3_divides, left, assumption, end lemma not_3_divides_of_3_divides_plus_1 : βˆ€ (m : β„€), 3 ∣ m + 1 β†’ Β¬ (3 ∣ m) := begin intros m H, rw not_3_divides, right, assumption, end theorem main : βˆ€ (n : β„€), 3 ∣ n * n - 1 β†’ Β¬ (3 ∣ n) := begin intro n, by_contrapositive, end
lemmas landau_symbols_if_at_top_eq [simp] = landau_symbols[THEN landau_symbol_if_at_top_eq]
lemma coeff_0_reflect_poly_0_iff [simp]: "coeff (reflect_poly p) 0 = 0 \<longleftrightarrow> p = 0"
informal statement Suppose $k \geq 3, x, y \in \mathbb{R}^k, |x - y| = d > 0$, and $r > 0$. Prove that if $2r > d$, there are infinitely many $z \in \mathbb{R}^k$ such that $|z-x|=|z-y|=r$.formal statement theorem exercise_1_18a (n : β„•) (h : n > 1) (x : euclidean_space ℝ (fin n)) -- R^n : βˆƒ (y : euclidean_space ℝ (fin n)), y β‰  0 ∧ (inner x y) = (0 : ℝ) :=
informal statement Prove that $\mathbb{Q}$ has no proper subgroups of finite index.formal statement theorem exercise_3_2_21a (H : add_subgroup β„š) (hH : H β‰  ⊀) : H.index = 0 :=
[STATEMENT] lemma subst_simps [simp]: "subst x t x = t" "subst x (Var x) = Var" [PROOF STATE] proof (prove) goal (1 subgoal): 1. subst x t x = t &&& subst x (Var x) = Var [PROOF STEP] by (auto simp: subst_def)
-- Given p : A ⟷ B do action on X act : (A ⟷ B) ⟷ (X ⟷ X) act = ?
theory Axler imports Complex_Main "HOL-Analysis.Inner_Product" "HOL-Analysis.Abstract_Euclidean_Space" "HOL.Vector_Spaces" "Rank_Nullity_Theorem.Fundamental_Subspaces" (*"HOL-Analysis.Weierstrass_Theorems"*) "HOL-Computational_Algebra.Polynomial" (* Note by Angeliki: some types chosen are too general, some others too specific e.g. *real* vector etc. Note to perhaps readjust with appropriate use of locales *) begin (* problem_number:1_2 natural language statement: Show that $\frac{-1 + \sqrt{3}i}{2}$ is a cube root of 1 (meaning that its cube equals 1). lean statement: theorem exercise_1_2 : (\<langle>-1/2, real.sqrt 3 / 2\<rangle> : \<complex>) ^ 3 = -1 := codex statement: theorem cube_root_of_1: shows "(-1 + sqrt 3 * \<i>)^3 = 1" Our comment on the codex statement: wrong function, missed the denominator. *) theorem exercise_1_2: shows "((-1 + sqrt 3 * \<i>)/2)^3 = 1 " oops (* problem_number:1_3 natural language statement: Prove that $-(-v) = v$ for every $v \in V$. lean statement: theorem exercise_1_3 {F V : Type*} [add_comm_group V] [field F] [module F V] {v : V} : -(-v) = v := codex statement: theorem neg_neg_eq_self: fixes v::"'a::ab_group_add" shows "-(-v) = v" Our comment on the codex statement: < the statement is in principle correct, though the type is not specified in the natural language statement. By the choice of notation I assume it's a vector instead. > *) theorem exercise_1_3: fixes v::"'a::ab_group_add"and V::"'a::ab_group_add set" shows "\<forall> v \<in> V. -(-v) = v" oops theorem exercise_1_3_alternative: fixes v :: "'a :: real_vector" shows "-(-v) = v" oops (* problem_number:1_4 natural language statement: Prove that if $a \in \mathbf{F}$, $v \in V$, and $av = 0$, then $a = 0$ or $v = 0$. lean statement: theorem exercise_1_4 {F V : Type*} [add_comm_group V] [field F] [module F V] (v : V) (a : F): a \<bullet> v = 0 \<longleftrightarrow> a = 0 \<or> v = 0 := codex statement: theorem zero_of_scalar_times_vector_eq_zero: fixes a::"'a::field" and v::"'b::real_vector" assumes "a *\<^sub>R v = 0" shows "a = 0 ∨ v = 0" Our comment on the codex statement: <wrong symbol for multiplication. Can work if the field is the reals here in particular. Can we generalise? > *) (*TODO *) theorem exercise_1_4: fixes a::real and v::"'b::real_vector" assumes "scaleR a v = 0" shows "a = 0 ∨ v = 0" oops (* problem_number:1_6 natural language statement: Give an example of a nonempty subset $U$ of $\mathbf{R}^2$ such that $U$ is closed under addition and under taking additive inverses (meaning $-u \in U$ whenever $u \in U$), but $U$ is not a subspace of $\mathbf{R}^2$. lean statement: theorem exercise_1_6 : \<exists> U : set (\<real> \<times> \<real>), (U \<noteq> \<emptyset>) \<and> (\<forall> (u v : \<real> \<times> \<real>), u \<in> U \<and> v \<in> U \<rightarrow> u + v \<in> U) \<and> (\<forall> (u : \<real> \<times> \<real>), u \<in> U \<rightarrow> -u \<in> U) \<and> (\<forall> U' : submodule \<real> (\<real> \<times> \<real>), U \<noteq> ↑U') := codex statement: theorem exists_nonempty_subset_of_R2_closed_under_add_and_inv_not_subspace: shows "βˆƒU. U β‰  {} ∧ (βˆ€x∈U. -x∈U) ∧ (βˆ€x y∈U. x+y∈U) ∧ Β¬(subspace U (UNIV::(real, real) vec set))" Our comment on the codex statement: <quite close but syntactic and type problems> *) theorem exercise_1_6: fixes V::"'a::euclidean_space set" assumes" DIM('a::euclidean_space) = 2" obtains U::"'a::euclidean_space set" where "U \<subseteq> V \<and> U β‰  {} ∧ (\<forall> x \<in> U. -x \<in> U) ∧ (\<forall>x\<in>U . \<forall> y \<in>U. x+y\<in> U) ∧ Β¬(subspace U )" oops (* problem_number:1_7 natural language statement: Give an example of a nonempty subset $U$ of $\mathbf{R}^2$ such that $U$ is closed under scalar multiplication, but $U$ is not a subspace of $\mathbf{R}^2$. lean statement: theorem exercise_1_7 : \<exists> U : set (\<real> \<times> \<real>), (U \<noteq> \<emptyset>) \<and> (\<forall> (c : \<real>) (u : \<real> \<times> \<real>), u \<in> U \<rightarrow> c \<bullet> u \<in> U) \<and> (\<forall> U' : submodule \<real> (\<real> \<times> \<real>), U \<noteq> ↑U') := codex statement: theorem exists_nonempty_subset_closed_under_scalar_multiplication_not_subspace: fixes U::"('a::real_vector) set" assumes "βˆƒU. U β‰  {} ∧ (βˆ€x∈U. βˆ€c. c∈UNIV ⟢ c β€’ x ∈ U)" shows "βˆƒU. U β‰  {} ∧ (βˆ€x∈U. βˆ€c. c∈UNIV ⟢ c β€’ x ∈ U) ∧ Β¬(subspace U)" Our comment on the codex statement: <logically wrong: fixes U and then assumes \exists U, also wrong notation for scalar multiplication> *) theorem exercise_1_7: fixes V::"'a::euclidean_space set" assumes" DIM('a::euclidean_space) = 2" obtains U::"'a::euclidean_space set" where "U \<subseteq> V \<and> U β‰  {} ∧ (\<forall> x \<in> U. \<forall> a::real. scaleR a x \<in> U) ∧ Β¬(subspace U )" oops (* problem_number:1_8 natural language statement: Prove that the intersection of any collection of subspaces of $V$ is a subspace of $V$. lean statement: theorem exercise_1_8 {F V : Type*} [add_comm_group V] [field F] [module F V] {\<iota> : Type*} (u : \<iota> \<rightarrow> submodule F V) : \<exists> U : submodule F V, (\<Inter> (i : \<iota>), (u i).carrier) = ↑U := codex statement: theorem subspace_of_intersection_of_subspaces: fixes V::"'a::real_vector set" assumes "βˆ€S∈S. subspace S" shows "subspace (β‹‚S∈S. S)" Our comment on the codex statement: <The natural language statement does not give the type of V, but from the notation chosen we may infer that it is a vector space. The codex formalisation is wrong: introduces V and then only uses S.> *) theorem exercise_1_8: fixes V::"'a::real_vector set" and C:: "'a::real_vector set set" assumes "C= {S. subspace S \<and> S\<subset> V}" shows "subspace (β‹‚S∈C. S)" oops (* problem_number:1_9 natural language statement: Prove that the union of two subspaces of $V$ is a subspace of $V$ if and only if one of the subspaces is contained in the other. lean statement: theorem exercise_1_9 {F V : Type*} [add_comm_group V] [field F] [module F V] (U W : submodule F V): \<exists> U' : submodule F V, U'.carrier = ↑U ∩ ↑W \<longleftrightarrow> U \<le> W \<or> W \<le> U := codex statement: theorem union_of_subspaces_is_subspace_iff_one_subset_of_other: fixes V::"'a::real_vector set" assumes "subspace V" "subspace U" "subspace W" shows "subspace (U βˆͺ W) ⟷ U βŠ† W ∨ W βŠ† U" Our comment on the codex statement: < introduces V without using it.> *) theorem exercise_1_9: fixes U::"'a::real_vector set" fixes W::"'a::real_vector set" assumes "subspace U" "subspace W" shows "subspace (U βˆͺ W) ⟷ U βŠ† W ∨ W βŠ† U" oops (* problem_number:2_1 natural language statement: Prove that if $\left(v_{1}, \ldots, v_{n}\right)$ spans $V$, then so does the list $\left(v_{1}-v_{2}, v_{2}-v_{3}, \ldots, v_{n-1}-v_{n}, v_{n}\right)$ obtained by subtracting from each vector (except the last one) the following vector. lean statement: codex statement: theorem span_of_subtract_succ_of_span: fixes v::"'a::euclidean_space set" assumes "span v = UNIV" shows "span (Ξ»n. v (Suc n) - v n) = UNIV" Our comment on the codex statement: <wrong, mainly problem with types/indices> *) theorem exercise_2_1: undefined oops (* problem_number:2_2 natural language statement: Prove that if $\left(v_{1}, \ldots, v_{n}\right)$ is linearly independent in $V$, then so is the list $\left(v_{1}-v_{2}, v_{2}-v_{3}, \ldots, v_{n-1}-v_{n}, v_{n}\right)$ obtained by subtracting from each vector (except the last one) the following vector. lean statement: codex statement: theorem linear_independent_of_linear_independent_sub: fixes v::"'a::euclidean_space set" assumes "independent v" shows "independent (Ξ»i. (v (Suc i)) - (v i))" Our comment on the codex statement: <wrong, again mainly problem with types/indices > *) theorem exercise_2_2: undefined oops (* problem_number:2_6 natural language statement: Prove that the real vector space consisting of all continuous real valued functions on the interval $[0,1]$ is infinite dimensional. lean statement: codex statement: theorem infinite_dim_of_continuous_real_valued_functions: fixes f::"real β‡’ real" assumes "continuous_on {0..1} f" shows "βˆƒg. continuous_on {0..1} g ∧ g β‰  f" Our comment on the codex statement: <completely wrong statement. syntax ok, but it talks about a completely different statement> *) theorem exercise_2_6: assumes " V= {f::real \<Rightarrow> real. continuous_on {0..1} f}" shows "infinite V" oops (* problem_number:3_1 natural language statement: Show that every linear map from a one-dimensional vector space to itself is multiplication by some scalar. More precisely, prove that if $\operatorname{dim} V=1$ and $T \in \mathcal{L}(V, V)$, then there exists $a \in \mathbf{F}$ such that $T v=a v$ for all $v \in V$. lean statement: theorem exercise_3_1 {F V : Type*} [add_comm_group V] [field F] [module F V] [finite_dimensional F V] (T : V \<rightarrow>β‚—[F] V) (hT : finrank F V = 1) : \<exists> c : F, \<forall> v : V, T v = c \<bullet> v:= codex statement: theorem linear_map_of_dim_one_is_scalar_mult: fixes V::"'a::real_vector space" and T::"'a β‡’ 'a" assumes "linear T" "DIM('a) = 1" shows "βˆƒa. βˆ€x. T x = a * x" Our comment on the codex statement: <various type issues and multiplication symbol> *) theorem exercise_3_1: fixes T::" 'a:: real_vector β‡’ 'a:: real_vector " (* assumes "linear T" *) (* TODO: how to incorporate assumptions without type issue? *) shows "βˆƒa \<in> \<real>. βˆ€x. T x = scaleR a x" oops (* TODO again I restrict it to real ..*) (* problem_number:3_8 natural language statement: Suppose that $V$ is finite dimensional and that $T \in \mathcal{L}(V, W)$. Prove that there exists a subspace $U$ of $V$ such that $U \cap \operatorname{null} T=\{0\}$ and range $T=\{T u: u \in U\}$. lean statement: theorem exercise_3_8 {F V W : Type*} [add_comm_group V] [add_comm_group W] [field F] [module F V] [module F W] (L : V \<rightarrow>β‚—[F] W) : \<exists> U : submodule F V, U \<sqinter> L.ker = \<bot> \<and> linear_map.range L = range (dom_restrict L U):= codex statement: theorem exists_subspace_of_range_eq_image_of_subspace: fixes V::"'a::euclidean_space set" and W::"'b::euclidean_space set" assumes "finite_dimensional V" "finite_dimensional W" "linear T" shows "βˆƒU. subspace U ∧ U ∩ null_space T = {0} ∧ range T = T ` U" Our comment on the codex statement: < the codex formalisation is incorrect wrt assumptions, conclusions, also it makes up nonexistent Isabelle definitions such as finite_dimensional > *) theorem exercise_3_8: undefined (* TODO*) (* note that null_space refers to matrices *) (* obtains U where " subspace U \<and> U \<subseteq> V ∧ U ∩ null_space T = {0} ∧ range T = T ` U" *) oops (* problem_number:3_9 natural language statement: Prove that if $T$ is a linear map from $\mathbf{F}^{4}$ to $\mathbf{F}^{2}$ such that $\operatorname{null} T=\left\{\left(x_{1}, x_{2}, x_{3}, x_{4}\right) \in \mathbf{F}^{4}: x_{1}=5 x_{2}\right.$ and $\left.x_{3}=7 x_{4}\right\}$, then $T$ is surjective. lean statement: codex statement: theorem surjective_of_null_space: fixes T::"'a::{field}^4 β‡’ 'a^2" assumes "null_space T = {x. x$1 = 5 * x$2 ∧ x$3 = 7 * x$4}" shows "surj T" Our comment on the codex statement: <various type issues >*) theorem exercise_3_9: undefined (* TODO *) oops (* problem_number:3_10 natural language statement: Prove that there does not exist a linear map from $\mathbf{F}^{5}$ to $\mathbf{F}^{2}$ whose null space equals $\left\{\left(x_{1}, x_{2}, x_{3}, x_{4}, x_{5}\right) \in \mathbf{F}^{5}: x_{1}=3 x_{2} \text { and } x_{3}=x_{4}=x_{5}\right\} .$ lean statement: codex statement: theorem not_exists_linear_map_of_null_space_eq_set: fixes f::"real^5 β‡’ real^2" assumes "linear f" "null_space f = {x | x. x$1 = 3 * x$2 ∧ x$3 = x$4 ∧ x$4 = x$5}" shows False Our comment on the codex statement: <wrong, various type issues> *) theorem exercise_3_10: undefined (*TODO *) oops (* problem_number:3_11 natural language statement: Prove that if there exists a linear map on $V$ whose null space and range are both finite dimensional, then $V$ is finite dimensional. lean statement: codex statement: theorem finite_dim_of_linear_map_finite_dim_null_space_range: fixes V::"'a::euclidean_space set" and f::"'a β‡’ 'b::euclidean_space" assumes "linear f" "finite_dimensional (null_space f)" "finite_dimensional (range f)" shows "finite_dimensional V" Our comment on the codex statement: <various type problems but gets close> *) theorem exercise_3_11: fixes V::"'a::real_vector set" and f::"'a β‡’ 'a" assumes (*"linear f"*) (*"finite (null_space f)"*) "finite (range f)" shows "finite V" (* TODO *) oops (* problem_number:4_4 natural language statement: Suppose $p \in \mathcal{P}(\mathbf{C})$ has degree $m$. Prove that $p$ has $m$ distinct roots if and only if $p$ and its derivative $p^{\prime}$ have no roots in common. lean statement: theorem exercise_4_4 (p : polynomial \<complex>) : p.degree = @card (root_set p \<complex>) (polynomial.root_set_fintype p \<complex>) \<longleftrightarrow> disjoint (@card (root_set p.derivative \<complex>) (polynomial.root_set_fintype p.derivative \<complex>)) (@card (root_set p \<complex>) (polynomial.root_set_fintype p \<complex>)) := codex statement: theorem distinct_roots_of_poly_iff_no_common_roots_with_derivative: fixes p::"complex poly" assumes "degree p = m" shows "distinct_roots p ↔ (βˆ€x. poly p x = 0 ⟢ poly (deriv p) x β‰  0)" Our comment on the codex statement: <makes up definitions that do not exist in Isabelle e.g. distinct_roots, uses wrong defs that are inappropriate here like deriv, wrong double implication symbol > *) theorem exercise_4_4: fixes p::"complex poly" assumes "degree p = m" shows "( {x. poly p x = 0}\<inter> {x. pderiv p = 0} = {}) \<longleftrightarrow> card {x. poly p x = 0}=m " oops (* problem_number:5_1 natural language statement: Suppose $T \in \mathcal{L}(V)$. Prove that if $U_{1}, \ldots, U_{m}$ are subspaces of $V$ invariant under $T$, then $U_{1}+\cdots+U_{m}$ is invariant under $T$. lean statement: theorem exercise_5_1 {F V : Type*} [add_comm_group V] [field F] [module F V] {L : V \<rightarrow>β‚—[F] V} {n : \<nat>} (U : fin n \<rightarrow> submodule F V) (hU : \<forall> i : fin n, map L (U i) = U i) : map L (\<Sum> i : fin n, U i : submodule F V) = (\<Sum> i : fin n, U i : submodule F V) := codex statement: theorem sum_of_invariant_subspace_is_invariant: fixes T::"'a::real_vector β‡’ 'a" assumes "βˆ€i. i ≀ m ⟢ subspace (U i)" "βˆ€i. i ≀ m ⟢ T (U i) βŠ† U i" shows "T (⨁i≀m. U i) βŠ† (⨁i≀m. U i)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_5_1: undefined oops (* problem_number:5_4 natural language statement: Suppose that $S, T \in \mathcal{L}(V)$ are such that $S T=T S$. Prove that $\operatorname{null} (T-\lambda I)$ is invariant under $S$ for every $\lambda \in \mathbf{F}$. lean statement: theorem exercise_5_4 {F V : Type*} [add_comm_group V] [field F] [module F V] (S T : V \<rightarrow>β‚—[F] V) (hST : S ∘ T = T ∘ S) (c : F): map S (T - c \<bullet> id).ker = (T - c \<bullet> id).ker := codex statement: theorem null_of_commutative_is_invariant: fixes S T::"'a::{real_normed_algebra_1, finite_dimensional} β‡’ 'a" assumes "commutative S T" shows "βˆ€Ξ». subspace (null_space (T - Ξ» *\<^sub>R 𝟭)) (range S)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_5_4: undefined oops (* problem_number:5_11 natural language statement: Suppose $S, T \in \mathcal{L}(V)$. Prove that $S T$ and $T S$ have the same eigenvalues. lean statement: theorem exercise_5_11 {F V : Type*} [add_comm_group V] [field F] [module F V] (S T : End F V) : (S * T).eigenvalues = (T * S).eigenvalues := codex statement: theorem eigenvalues_of_commutative_linear_operators: fixes S T::"'a::{comm_ring_1,euclidean_space} β‡’ 'a" assumes "linear S" "linear T" shows "eigenvalues (S ∘ T) = eigenvalues (T ∘ S)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_5_11: undefined oops (* problem_number:5_12 natural language statement: Suppose $T \in \mathcal{L}(V)$ is such that every vector in $V$ is an eigenvector of $T$. Prove that $T$ is a scalar multiple of the identity operator. lean statement: theorem exercise_5_12 {F V : Type*} [add_comm_group V] [field F] [module F V] {S : End F V} (hS : \<forall> v : V, \<exists> c : F, v \<in> eigenspace S c) : \<exists> c : F, S = c \<bullet> id := codex statement: theorem scalar_multiple_of_identity_of_eigenvector_of_all_vectors: fixes T::"'a::{real_normed_algebra_1, real_inner} β‡’ 'a" assumes "linear T" "βˆ€x. βˆƒc. T x = c * x" shows "βˆƒc. T = (Ξ»x. c * x)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_5_12: undefined oops (* problem_number:5_13 natural language statement: Suppose $T \in \mathcal{L}(V)$ is such that every subspace of $V$ with dimension $\operatorname{dim} V-1$ is invariant under $T$. Prove that $T$ is a scalar multiple of the identity operator. lean statement: theorem exercise_5_13 {F V : Type*} [add_comm_group V] [field F] [module F V] [finite_dimensional F V] {T : End F V} (hS : \<forall> U : submodule F V, finrank F U = finrank F V - 1 \<rightarrow> map T U = U) : \<exists> c : F, T = c \<bullet> id := codex statement: theorem scalar_multiple_of_identity_of_invariant_subspace_of_dim_pred: fixes T::"'a::euclidean_space β‡’ 'a" assumes "linear T" "βˆ€S. subspace S ⟢ dim S = dim V - 1 ⟢ subspace (T ` S)" shows "T = (Ξ»x. c * x) ∘ T ∘ (Ξ»x. c * x)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_5_13: undefined oops (* problem_number:5_20 natural language statement: Suppose that $T \in \mathcal{L}(V)$ has $\operatorname{dim} V$ distinct eigenvalues and that $S \in \mathcal{L}(V)$ has the same eigenvectors as $T$ (not necessarily with the same eigenvalues). Prove that $S T=T S$. lean statement: theorem exercise_5_20 {F V : Type*} [add_comm_group V] [field F] [module F V] [finite_dimensional F V] {S T : End F V} (h1 : @card T.eigenvalues (eigenvalues.fintype T) = finrank F V) (h2 : \<forall> v : V, \<exists> c : F, v \<in> eigenspace S c \<longleftrightarrow> \<exists> c : F, v \<in> eigenspace T c) : S * T = T * S := codex statement: theorem commutative_of_same_eigenvectors: fixes T::"'a::{finite_dimensional, real_inner} β‡’ 'a" and S::"'a::{finite_dimensional, real_inner} β‡’ 'a" assumes "linear T" "linear S" "βˆ€x. x∈carrier_vec n ⟢ (βˆƒΞ». T x = Ξ» *\<^sub>R x)" "βˆ€x. x∈carrier_vec n ⟢ (βˆƒΞ». S x = Ξ» *\<^sub>R x)" "βˆ€x. x∈carrier_vec n ⟢ (βˆƒΞ». T x = Ξ» *\<^sub>R x) ⟢ (βˆƒΞ». S x = Ξ» *\<^sub>R x)" shows "T ∘ S = S ∘ T" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_5_20: undefined oops (* problem_number:5_24 natural language statement: Suppose $V$ is a real vector space and $T \in \mathcal{L}(V)$ has no eigenvalues. Prove that every subspace of $V$ invariant under $T$ has even dimension. lean statement: theorem exercise_5_24 {V : Type*} [add_comm_group V] [module \<real> V] [finite_dimensional \<real> V] {T : End \<real> V} (hT : \<forall> c : \<real>, eigenspace T c = \<bot>) {U : submodule \<real> V} (hU : map T U = U) : even (finrank U) := codex statement: theorem even_dim_of_invariant_subspace_of_no_eigenvalue: fixes V::"'a::euclidean_space set" and T::"'a β‡’ 'a" assumes "linear T" "βˆ€x. T x β‰  x" shows "βˆ€S. subspace S ⟢ subspace.invariant S T ⟢ even (dim S)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_5_24: undefined oops (* problem_number:6_2 natural language statement: Suppose $u, v \in V$. Prove that $\langle u, v\rangle=0$ if and only if $\|u\| \leq\|u+a v\|$ for all $a \in \mathbf{F}$. lean statement: theorem exercise_6_2 {V : Type*} [add_comm_group V] [module \<complex> V] [inner_product_space \<complex> V] (u v : V) : βŸͺu, v⟫_\<complex> = 0 \<longleftrightarrow> \<forall> (a : \<complex>), βˆ₯uβˆ₯ \<le> βˆ₯u + a \<bullet> vβˆ₯ := codex statement: theorem norm_leq_norm_add_scalar_mul_iff_inner_eq_zero: fixes u v::"'a::euclidean_space" shows "inner u v = 0 ⟷ βˆ€a. norm u ≀ norm (u + a *\<^sub>R v)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_6_2: undefined oops (* problem_number:6_3 natural language statement: Prove that $\left(\sum_{j=1}^{n} a_{j} b_{j}\right)^{2} \leq\left(\sum_{j=1}^{n} j a_{j}{ }^{2}\right)\left(\sum_{j=1}^{n} \frac{b_{j}{ }^{2}}{j}\right)$ for all real numbers $a_{1}, \ldots, a_{n}$ and $b_{1}, \ldots, b_{n}$. lean statement: theorem exercise_6_3 {n : \<nat>} (a b : fin n \<rightarrow> \<real>) : (\<Sum> i, a i * b i) ^ 2 \<le> (\<Sum> i : fin n, i * a i ^ 2) * (\<Sum> i, b i ^ 2 / i) := codex statement: theorem sum_square_leq_sum_square_of_sum_square: fixes a b::"nat β‡’ real" assumes "βˆ€i. i ≀ n ⟢ a i β‰₯ 0" "βˆ€i. i ≀ n ⟢ b i β‰₯ 0" shows "(βˆ‘i=1..n. a i * b i)^2 ≀ (βˆ‘i=1..n. i * (a i)^2) * (βˆ‘i=1..n. (b i)^2 / i)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_6_3: undefined oops (* problem_number:6_7 natural language statement: Prove that if $V$ is a complex inner-product space, then $\langle u, v\rangle=\frac{\|u+v\|^{2}-\|u-v\|^{2}+\|u+i v\|^{2} i-\|u-i v\|^{2} i}{4}$ for all $u, v \in V$. lean statement: theorem exercise_6_7 {V : Type*} [inner_product_space \<complex> V] (u v : V) : βŸͺu, v⟫_\<complex> = (βˆ₯u + vβˆ₯^2 - βˆ₯u - vβˆ₯^2 + I*βˆ₯u + I\<bullet>vβˆ₯^2 - I*βˆ₯u-I\<bullet>vβˆ₯^2) / 4 := codex statement: theorem inner_product_eq_sum_square_sub_square_sum_square_sub_square: fixes u v::"'a::euclidean_space" shows "inner_product u v = (norm (u+v)^2 - norm (u-v)^2 + norm (u+ii*v)^2 - norm (u-ii*v)^2)/4" Our comment on the codex statement: <wrong: missed factors 𝗂 in the expression, uses wrong type, nonexistent definition inner_product> *) theorem exercise_6_7: fixes u v::"complex" shows "inner u v = (norm (u+v)^2 - norm (u-v)^2 + (norm (u+ 𝗂 * v)^2) * 𝗂 - (norm (u- 𝗂 * v)^2)* 𝗂)/4" oops (* problem_number:6_13 natural language statement: Suppose $\left(e_{1}, \ldots, e_{m}\right)$ is an orthonormal list of vectors in $V$. Let $v \in V$. Prove that $\|v\|^{2}=\left|\left\langle v, e_{1}\right\rangle\right|^{2}+\cdots+\left|\left\langle v, e_{m}\right\rangle\right|^{2}$ if and only if $v \in \operatorname{span}\left(e_{1}, \ldots, e_{m}\right)$. lean statement: theorem exercise_6_13 {V : Type*} [inner_product_space \<complex> V] {n : \<nat>} {e : fin n \<rightarrow> V} (he : orthonormal \<complex> e) (v : V) : βˆ₯vβˆ₯^2 = \<Sum> i : fin n, βˆ₯βŸͺv, e i⟫_\<complex>βˆ₯^2 \<longleftrightarrow> v \<in> span \<complex> (e '' univ) := codex statement: theorem norm_square_eq_sum_abs_square_of_orthonormal_list_iff_in_span: fixes v::"'a::euclidean_space" and e::"'a set" assumes "finite e" "e βŠ† orthonormal_basis" "v ∈ span e" shows "norm v ^ 2 = (βˆ‘x∈e. (cinner v x)^2)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_6_13: undefined oops (* problem_number:6_16 natural language statement: Suppose $U$ is a subspace of $V$. Prove that $U^{\perp}=\{0\}$ if and only if $U=V$ lean statement: theorem exercise_6_16 {K V : Type*} [is_R_or_C K] [inner_product_space K V] {U : submodule K V} : U.orthogonal = \<bot> \<longleftrightarrow> U = \<top> := codex statement: theorem orthogonal_of_subspace_eq_zero_iff_eq_space: fixes U::"'a::euclidean_space set" assumes "subspace U" shows "orthogonal_complement U = {0} ⟷ U = UNIV" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_6_16: undefined oops (* problem_number:6_17 natural language statement: Prove that if $P \in \mathcal{L}(V)$ is such that $P^{2}=P$ and every vector in $\operatorname{null} P$ is orthogonal to every vector in $\operatorname{range} P$, then $P$ is an orthogonal projection. lean statement: codex statement: theorem orthogonal_projection_of_null_orthogonal_range: fixes P::"'a::euclidean_space β‡’ 'a" assumes "linear P" "P^2 = P" "βˆ€x∈null_space P. βˆ€y∈range P. xβ‹…y = 0" shows "orthogonal_projection P" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_6_17: undefined oops (* problem_number:6_18 natural language statement: Prove that if $P \in \mathcal{L}(V)$ is such that $P^{2}=P$ and $\|P v\| \leq\|v\|$ for every $v \in V$, then $P$ is an orthogonal projection. lean statement: codex statement: theorem orthogonal_projection_of_square_eq_self_and_norm_leq_norm: fixes P::"'a::euclidean_space β‡’ 'a" assumes "linear P" "P^2 = P" "βˆ€x. norm (P x) ≀ norm x" shows "βˆ€x y. P x = P y ⟢ x = y" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_6_18: undefined oops (* problem_number:6_19 natural language statement: Suppose $T \in \mathcal{L}(V)$ and $U$ is a subspace of $V$. Prove that $U$ is invariant under $T$ if and only if $P_{U} T P_{U}=T P_{U}$. lean statement: codex statement: theorem invariant_of_projection_eq_projection_comp: fixes T::"'a::euclidean_space β‡’ 'a" and U::"'a set" assumes "subspace U" shows "invariant_under T U ⟷ (T ∘ (projection U) = projection U ∘ T)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_6_19: undefined oops (* problem_number:6_20 natural language statement: Suppose $T \in \mathcal{L}(V)$ and $U$ is a subspace of $V$. Prove that $U$ and $U^{\perp}$ are both invariant under $T$ if and only if $P_{U} T=T P_{U}$. lean statement: codex statement: theorem orthogonal_projection_eq_projection_orthogonal_iff_invariant: fixes T::"'a::euclidean_space β‡’ 'a" and U::"'a set" assumes "subspace U" shows "T ` U βŠ† U ∧ T ` UβŠ₯ βŠ† UβŠ₯ ⟷ (T ∘ (projection U) = (projection U) ∘ T)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_6_20: undefined oops (* problem_number:6_29 natural language statement: Suppose $T \in \mathcal{L}(V)$ and $U$ is a subspace of $V$. Prove that $U$ is invariant under $T$ if and only if $U^{\perp}$ is invariant under $T^{*}$. lean statement: codex statement: theorem invariant_of_adjoint_invariant: fixes T::"'a::euclidean_space β‡’ 'a" and U::"'a set" assumes "linear T" "subspace U" shows "U βŠ† carrier T ⟺ (orthogonal_complement U) βŠ† carrier (adjoint T)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_6_29: undefined oops (* problem_number:7_4 natural language statement: Suppose $P \in \mathcal{L}(V)$ is such that $P^{2}=P$. Prove that $P$ is an orthogonal projection if and only if $P$ is self-adjoint. lean statement: codex statement: theorem orthogonal_projection_iff_self_adjoint: fixes P::"'a::euclidean_space β‡’ 'a" assumes "linear P" "P^2 = P" shows "orthogonal_projection P ⟷ selfadjoint P" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_7_4: undefined oops (* problem_number:7_5 natural language statement: Show that if $\operatorname{dim} V \geq 2$, then the set of normal operators on $V$ is not a subspace of $\mathcal{L}(V)$. lean statement: theorem exercise_7_5 {V : Type*} [inner_product_space \<complex> V] [finite_dimensional \<complex> V] (hV : finrank V \<ge> 2) : \<forall> U : submodule \<complex> (End \<complex> V), U.carrier \<noteq> {T | T * T.adjoint = T.adjoint * T} := codex statement: theorem normal_operators_not_subspace_of_linear_operators: fixes V::"'a::euclidean_space set" assumes "DIM('a) β‰₯ 2" shows "βˆ€N. linear N ⟢ normal N ⟢ False" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_7_5: undefined oops (* problem_number:7_6 natural language statement: Prove that if $T \in \mathcal{L}(V)$ is normal, then $\operatorname{range} T=\operatorname{range} T^{*}.$ lean statement: theorem exercise_7_6 {V : Type*} [inner_product_space \<complex> V] [finite_dimensional \<complex> V] (T : End \<complex> V) (hT : T * T.adjoint = T.adjoint * T) : T.range = T.adjoint.range := codex statement: theorem range_of_normal_eq_range_of_adjoint: fixes T::"'a::euclidean_space \<Rightarrow> 'a" assumes "linear T" "T adjoint = T" shows "range T = range (T adjoint)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_7_6: undefined oops (* problem_number:7_8 natural language statement: Prove that there does not exist a self-adjoint operator $T \in \mathcal{L}\left(\mathbf{R}^{3}\right)$ such that $T(1,2,3)=(0,0,0)$ and $T(2,5,7)=(2,5,7)$. lean statement: codex statement: theorem not_exists_self_adjoint_operator_of_two_eigenvectors: fixes T::"real^3 \<Rightarrow> real^3" assumes "linear T" "self_adjoint T" "T (vector [1,2,3]) = 0" "T (vector [2,5,7]) = vector [2,5,7]" shows False Our comment on the codex statement: <linear assumption issue. makes use of nonexistent def. self_adjoint> *) theorem exercise_7_8: fixes T::"real^3 \<Rightarrow> real^3" assumes (* "linear T"*) (* TODO T linear *) "T (vector [1,2,3]) = 0" "T (vector [2,5,7]) = vector [2,5,7]" "adjoint T = T" shows False oops (* problem_number:7_9 natural language statement: Prove that a normal operator on a complex inner-product space is self-adjoint if and only if all its eigenvalues are real. lean statement: theorem exercise_7_9 {V : Type*} [inner_product_space \<complex> V] [finite_dimensional \<complex> V] (T : End \<complex> V) (hT : T * T.adjoint = T.adjoint * T) : is_self_adjoint T \<longleftrightarrow> \<forall> e : T.eigenvalues, (e : \<complex>).im = 0 := codex statement: theorem normal_operator_is_self_adjoint_iff_eigenvalues_are_real: fixes A::"'a::euclidean_space \<Rightarrow> 'a" assumes "normal_operator A" shows "self_adjoint A \<longleftrightarrow> (\<forall>x. eigenvalue A x \<longrightarrow> x\<in>\<real>)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_7_9: undefined oops (* problem_number:7_10 natural language statement: Suppose $V$ is a complex inner-product space and $T \in \mathcal{L}(V)$ is a normal operator such that $T^{9}=T^{8}$. Prove that $T$ is self-adjoint and $T^{2}=T$. lean statement: theorem exercise_7_10 {V : Type*} [inner_product_space \<complex> V] [finite_dimensional \<complex> V] (T : End \<complex> V) (hT : T * T.adjoint = T.adjoint * T) (hT1 : T^9 = T^8) : is_self_adjoint T \<and> T^2 = T := codex statement: theorem normal_operator_of_power_eq_power_succ: fixes T::"'a::complex_inner_product_space \<Rightarrow> 'a" assumes "normal T" "T^9 = T^8" shows "T = adjoint T \<and> T^2 = T" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_7_10: undefined oops (* problem_number:7_11 natural language statement: Suppose $V$ is a complex inner-product space. Prove that every normal operator on $V$ has a square root. ( An operator $S \in \mathcal{L}(V)$ is called a square root of $T \in \mathcal{L}(V)$ if $S^{2}=T$.) lean statement: theorem exercise_7_11 {V : Type*} [inner_product_space \<complex> V] [finite_dimensional \<complex> V] {T : End \<complex> V} (hT : T*T.adjoint = T.adjoint*T) : \<exists> (S : End \<complex> V), S ^ 2 = T := codex statement: theorem exists_sqrt_of_normal_operator: fixes V::"'a::complex_inner_product_space" assumes "normal_operator V" shows "\<exists>S. bounded_linear S \<and> S^2 = T" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_7_11: undefined oops (* problem_number:7_14 natural language statement: Suppose $T \in \mathcal{L}(V)$ is self-adjoint, $\lambda \in \mathbf{F}$, and $\epsilon>0$. Prove that if there exists $v \in V$ such that $\|v\|=1$ and $\|T v-\lambda v\|<\epsilon,$ then $T$ has an eigenvalue $\lambda^{\prime}$ such that $\left|\lambda-\lambda^{\prime}\right|<\epsilon$. lean statement: theorem exercise_7_14 {π•œ V : Type*} [is_R_or_C π•œ] [inner_product_space π•œ V] [finite_dimensional π•œ V] {T : End π•œ V} (hT : is_self_adjoint T) {l : π•œ} {\<epsilon> : \<real>} (he : \<epsilon> > 0) : \<exists> v : V, βˆ₯vβˆ₯ = 1 \<and> βˆ₯T v - l \<bullet> vβˆ₯ < \<epsilon> \<rightarrow> \<exists> l' : T.eigenvalues, βˆ₯l - l'βˆ₯ < \<epsilon> := codex statement: theorem exists_eigenvalue_of_self_adjoint_operator: fixes T::"'a::euclidean_space \<Rightarrow> 'a" assumes "self_adjoint T" "\<exists>v. norm v = 1 \<and> norm (T v - \<lambda> v) < \<epsilon>" shows "\<exists>\<lambda>'. eigenvalue T \<lambda>' \<and> abs (\<lambda> - \<lambda>') < \<epsilon>" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_7_14: undefined oops (* problem_number:7_15 natural language statement: Suppose $U$ is a finite-dimensional real vector space and $T \in$ $\mathcal{L}(U)$. Prove that $U$ has a basis consisting of eigenvectors of $T$ if and only if there is an inner product on $U$ that makes $T$ into a self-adjoint operator. lean statement: codex statement: theorem exists_inner_product_of_eigenvectors_basis: fixes T::"'a::euclidean_space \<Rightarrow> 'a" assumes "linear T" "\<exists>b. independent b \<and> b \<subseteq> carrier_vec n \<and> span b = carrier_vec n" shows "\<exists>B. inner_product_space B \<and> (\<forall>x\<in>b. eigenvector B T x)" Our comment on the codex statement: <various type errors, wrong statement, and makes up defs that don't exist in Isabelle.> *) theorem exercise_7_15: undefined oops (* problem_number:7_17 natural language statement: Prove that the sum of any two positive operators on $V$ is positive. lean statement: codex statement: theorem sum_of_positive_operators_is_positive: fixes V::"'a::euclidean_space set" and f g::"'a \<Rightarrow> 'a" assumes "linear f" "linear g" "\<forall>x\<in>V. 0 \<le> f x β‹… x" "\<forall>x\<in>V. 0 \<le> g x β‹… x" shows "\<forall>x\<in>V. 0 \<le> (f + g) x β‹… x" Our comment on the codex statement: <wrong assumptions and type issues> *) theorem exercise_7_17: undefined oops (* problem_number:7_18 natural language statement: Prove that if $T \in \mathcal{L}(V)$ is positive, then so is $T^{k}$ for every positive integer $k$. lean statement: codex statement: theorem positive_of_positive_power: fixes T::"'a::euclidean_space \<Rightarrow> 'a" assumes "linear T" "positive T" shows "positive (T^k)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_7_18: undefined oops end
/- Copyright (c) 2021 OpenAI. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f -/ import mathzoo.imports.miniF2F open_locale nat rat real big_operators topological_space theorem mathd_algebra_140 (a b c : ℝ) (hβ‚€ : 0 < a ∧ 0 < b ∧ 0 < c) (h₁ : βˆ€ x, 24 * x^2 - 19 * x - 35 = (((a * x) - 5) * ((2 * (b * x)) + c))) : a * b - 3 * c = -9 := begin have hβ‚‚ := h₁ 0, have hβ‚‚ := h₁ 1, have h₃ := h₁ (-1), linarith, end
import data.list.basic open list universe u variables {Ξ± : Type} (x y z : Ξ±) (xs ys zs : list Ξ±) def mk_symm (xs : list Ξ±) := xs ++ reverse xs theorem reverse_mk_symm (xs : list Ξ±) : reverse (mk_symm xs) = mk_symm xs := by simp [mk_symm] attribute [simp] reverse_mk_symm example (xs ys : list β„•) : reverse (xs ++ mk_symm ys) = mk_symm ys ++ reverse xs := by simp example (xs ys : list β„•) (p : list β„• β†’ Prop) (h : p (reverse (xs ++ (mk_symm ys)))) : p (mk_symm ys ++ reverse xs) := by simp at h; assumption
import smt2 lemma negation_of_conj : forall (P Q : Prop), not (P ∧ Q) ↔ not P ∨ not Q := by intros; z3 "d1.log" lemma negation_of_disj : forall (P Q : Prop), Β¬ (P ∨ Q) ↔ Β¬ P ∧ Β¬ Q := begin intros, z3 end #print negation_of_conj #print negation_of_disj
informal statement Show that if $\prod X_\alpha$ is regular, then so is $X_\alpha$. Assume that each $X_\alpha$ is nonempty.formal statement theorem exercise_32_3 {X : Type*} [topological_space X] (hX : locally_compact_space X) (hX' : t2_space X) : regular_space X :=
import M4R.Algebra.Ring.IdealZorn import M4R.Algebra.Ring.Localisation import M4R.Algebra.Ring.Radical namespace M4R open Monoid NCSemiring Semiring NCRing variable {A : Type _} [Ring A] {I : Ideal A} -- Theorem 1.1 private theorem t1_1 (hI : I.proper_ideal) : βˆƒ J : Ideal A, I βŠ† J ∧ J.is_maximal := let ⟨m, hm₁, hmβ‚‚βŸ© := Ideal.ideal_zorn {J | I βŠ† J ∧ J.proper_ideal} (by intro c cs hc cases Classical.em (Nonempty c) with | inl h => have hub₁ := fun (a : Ideal A) (ha : a ∈ c) => Ideal.ideal_chain_subset c ha hc have hubβ‚‚ := Ideal.ideal_chain_proper c h hc (fun J Jc => (cs Jc).right) exact ⟨Ideal.ideal_chain c h hc, ⟨let ⟨J, Jc⟩ := Classical.choice h Subset.trans (cs Jc).left (hub₁ J Jc), hubβ‚‚βŸ©, hubβ‚βŸ© | inr h => exact ⟨I, ⟨Subset.refl _, hI⟩, fun a ac => absurd ⟨a, ac⟩ h⟩) ⟨m, hm₁.left, ⟨hm₁.right, by intro J mJ; exact (Classical.em J.proper_ideal).imp (fun h => hmβ‚‚ J ⟨Subset.trans hm₁.left mJ, h⟩ mJ) of_not_not⟩⟩ theorem Ideal.exists_maximal_containing (hI : I.proper_ideal) : βˆƒ J : Ideal A, I βŠ† J ∧ J.is_maximal := t1_1 hI theorem Ideal.exists_prime_containing (hI : I.proper_ideal) : βˆƒ J : Ideal A, I βŠ† J ∧ J.is_prime := let ⟨J, hIJ, hJ⟩ := t1_1 hI; ⟨J, hIJ, maximal_is_prime hJ⟩ theorem Ideal.exists_maximal_containing_nonunit {x : A} (hx : Β¬isUnit x) : βˆƒ I : Ideal A, I.is_maximal ∧ x ∈ I := let ⟨I, hxI, hI⟩ := t1_1 (unit_not_principal hx); ⟨I, hI, hxI (generator_in_principal x)⟩ theorem Ideal.exists_maximal_ideal_of_nontrivial [Ring A] (h : Ring.is_NonTrivial A) : βˆƒ I : Ideal A, I.is_maximal := let ⟨I, _, hI⟩ := t1_1 (zero_ideal_proper_of_nontrivial h) ⟨I, hI⟩ theorem Ideal.exists_prime_ideal_of_nontrivial [Ring A] (h : Ring.is_NonTrivial A) : βˆƒ I : Ideal A, I.is_prime := let ⟨I, hI⟩ := exists_maximal_ideal_of_nontrivial h; ⟨I, maximal_is_prime hI⟩ theorem Ideal.exists_maximal_ideal (A) [NonTrivialRing A] : βˆƒ I : Ideal A, I.is_maximal := let ⟨I, _, hI⟩ := t1_1 (zero_ideal_proper A); ⟨I, hI⟩ theorem Ideal.exists_prime_ideal (A) [NonTrivialRing A] : βˆƒ I : Ideal A, I.is_prime := let ⟨I, hI⟩ := exists_maximal_ideal A; ⟨I, maximal_is_prime hI⟩ theorem Ring.jacobson_radical.units {x : A} : x ∈ jacobson_radical A ↔ ↑{y : A | βˆƒ r, 1 + r * x = y} βŠ† unit_set A := ⟨fun hx => fun y ⟨r, hrxy⟩ => Classical.byContradiction fun hy => by let ⟨M, hM, hyM⟩ := Ideal.exists_maximal_containing_nonunit hy rw [←hrxy] at hyM have := M.add_closed hyM ((M.mul_closed (-r) (maximal_subset_jacobson hM hx))) rw [add_assoc, neg_mul, add_neg, add_zero] at this exact absurd (Ideal.is_unit_ideal.mpr this) hM.left, fun hx => Ideal.sIntersection.mem.mpr fun M hM => Classical.byContradiction fun h => let ⟨m, hm, x', ⟨s, hs⟩, h'⟩ := Ideal.is_unit_ideal.mp ((hM.right (Ideal.add.subset M (Ideal.principal x))).resolve_left fun h' => h (h' β–Έ Ideal.add.subset' _ _ (Ideal.generator_in_principal x))) absurd (Ideal.is_unit_ideal'.mpr ⟨1 + -s * x, hx ⟨-s, rfl⟩, by rw [←h', ←hs, mul_comm, neg_mul, add_assoc, add_neg, add_zero]; exact hm⟩) hM.left⟩ theorem Ring.nakayama {M : Ideal A} (hM : M.finitely_generated) {I : Ideal A} (hI : I βŠ† Ring.jacobson_radical A) (hIM : M = I * M) : M = 0 := by let ⟨f, hfM, hfmax⟩ := hM.has_minimal_generating_set byCases hf : f = βˆ… { rw [hf, Finset.empty_toSet, Ideal.from_set.empty] at hfM; exact hfM } { let ⟨g, hg⟩ : βˆƒ g, g ∈ f := Classical.byContradiction fun h => hf (Finset.ext fun x => by rw [Finset.mem_empty, iff_false]; exact not_exists.mp h x) have : g ∈ I * M := hIM β–Έ hfM β–Έ Ideal.from_set.contains_mem hg let ⟨c, hcI, hfc⟩ : βˆƒ c : A β†’ A, (βˆ€ x, c x ∈ I) ∧ g = βˆ‘ x in f, c x * x := let ⟨fs, c, hf, hc⟩ := Ideal.from_set.mem_as_sum.mp this @Finset.cons_induction _ (fun fs : Finset A => fs.toSet βŠ† Ideal.product_gen I M β†’ βˆ€ g, g = (βˆ‘ x in fs, c x * x) β†’ βˆƒ c : A β†’ A, (βˆ€ x, c x ∈ I) ∧ g = βˆ‘ x in f, c x * x) (fun _ g hg => ⟨fun _ => 0, fun _ => I.has_zero, by rw [hg, Finset.map_sum.empty, Finset.map_sum.eq_zero (fun _ _ => by rw [zero_mul])]⟩) (fun x fs hx ih hfs g hg => let ⟨c', hc', hgc'⟩ := ih (Subset.trans (fun _ => Finset.mem_cons_self' hx) hfs) (g - c x * x) (by rw [Finset.map_sum.cons] at hg; exact Group.sub_eq.mpr hg) let ⟨i, hi, m, hm, him⟩ := hfs (Finset.mem_cons_self fs hx) let ⟨mc, hmc⟩ := Ideal.from_set.mem_as_sum_finset.mp (hfM β–Έ hm : m ∈ Ideal.from_set f.toSet) ⟨fun y => c' y + c x * i * mc y, fun y => I.add_closed (hc' y) (mul_right_comm _ _ _ β–Έ I.mul_closed _ hi), by simp only [mul_distrib_right, Finset.map_sum.distrib, mul_assoc, ←Finset.map_sum.mul_sum]; rw [←hgc', ←hmc, ←him, Group.sub_add]⟩) fs hf g hc let ⟨u, hu⟩ : isUnit (1 - c g) := by exact jacobson_radical.units.mp (hI (hcI g)) ⟨-1, by rw [neg_one_mul, Group.sub_def]⟩ have : (1 - c g) * g = βˆ‘ x in f.erase g, c x * x := by rw [sub_mul_distrib_right, one_mul, Group.sub_eq, ←Finset.map_sum.sum_term _ _ hg, hfc] have := hfmax (f.erase g) (hfM β–Έ Ideal.antisymm (Ideal.from_set.ideal_contained fun x hx => by byCases hxg : x = g { exact Ideal.from_set.mem_as_sum_finset.mpr ⟨fun y => u * c y, by simp only [mul_assoc]; rw [←Finset.map_sum.mul_sum, ←this, ←mul_assoc, mul_comm u, hu, one_mul, hxg]⟩ } { exact Ideal.from_set.contains_mem (Finset.mem_erase.mpr ⟨hxg, hx⟩) }) (Ideal.from_set.subset fun x hx => (Finset.mem_erase.mp hx).right)); exact absurd this (have : (f.erase g).length.succ = f.length := by rw [congrArg Finset.length (Finset.erase_cons f hg), Finset.length_cons] Nat.not_le.mpr (this β–Έ Nat.lt.base _)) } -- Theorem 1.2 private theorem t1_2 (I) (S : MultiplicativeSet A) (hIS : Set.disjoint I.subset S.subset) : βˆƒ J : Ideal A, I βŠ† J ∧ Set.disjoint J.subset S.subset ∧ J.is_prime := let ⟨m, hm₁, hmβ‚‚βŸ© := Ideal.ideal_zorn {J | I βŠ† J ∧ Set.disjoint J.subset S.subset} (by intro c cs hc; byCases h : Nonempty c { have hub₁ := fun (a : Ideal A) (ha : a ∈ c) => Ideal.ideal_chain_subset c ha hc have hubβ‚‚ := Ideal.ideal_chain_disjoint c h hc S.subset fun J Jc => (cs Jc).right; exact ⟨Ideal.ideal_chain c h hc, ⟨let ⟨J, Jc⟩ := Classical.choice h Subset.trans (cs Jc).left (hub₁ J Jc), hubβ‚‚βŸ©, hubβ‚βŸ© } { exact ⟨I, ⟨Subset.refl _, hIS⟩, fun a ac => absurd ⟨a, ac⟩ h⟩ }) ⟨m, hm₁.left, hm₁.right, S.disjoint_ideal_proper hm₁.right, by intro r s hrs; apply Classical.byContradiction; rw [not_or_iff_and_not]; intro ⟨nrm, nsm⟩ have : βˆ€ {x}, x βˆ‰ m β†’ Β¬Set.disjoint (m + Ideal.principal x).subset S.subset := by intro x xnm h; apply xnm have := hmβ‚‚ (m + Ideal.principal x) ⟨Subset.trans hm₁.left (Ideal.add.subset m (Ideal.principal x)), h⟩ (Ideal.add.subset m (Ideal.principal x)) rw [←this]; exact ⟨0, m.has_zero, x, Ideal.generator_in_principal x, zero_add x⟩ have ⟨r', ⟨r'i, r'im, r'j, ⟨r'', hr''⟩, hr'ij⟩, r'S⟩ := Classical.choice (Set.nonempty.mp (this nrm)) have ⟨s', ⟨s'i, s'im, s'j, ⟨s'', hs''⟩, hs'ij⟩, s'S⟩ := Classical.choice (Set.nonempty.mp (this nsm)) have h₁ := S.mul_closed r'S s'S rw [←hr'ij, ←hs'ij, ←hr'', ←hs'', mul_distrib_left, mul_distrib_right, mul_distrib_right, ←add_assoc] at h₁ have hβ‚‚ : r'i * s'i + r * r'' * s'i + r'i * (s * s'') + r * r'' * (s * s'') ∈ m + Ideal.principal (r * s) := ⟨r'i * s'i + r * r'' * s'i + r'i * (s * s''), m.add_closed (m.add_closed (m.mul_closed _ s'im) (m.mul_closed _ s'im)) (m.mul_closed' r'im _), r * r'' * (s * s''), ⟨r'' * s'', by rw [mul_assoc, ←mul_assoc s, mul_comm s, mul_assoc, ←mul_assoc r]⟩, rfl⟩ have h₃ : m + Ideal.principal (r * s) = m := Ideal.add.of_subset (Ideal.principal_in hrs) rw [h₃] at hβ‚‚ exact Set.nonempty.mpr (⟨_, hβ‚‚, hβ‚βŸ© : Nonempty ↑(m.subset ∩ S.subset)) hm₁.right⟩ theorem Ideal.radical_prime_intersection (I : Ideal A) : I.radical = β‹‚β‚€ {J | I βŠ† J ∧ J.is_prime} := Ideal.antisymm (fun x hx => propext sIntersection.mem β–Έ fun J ⟨hIJ, hJ⟩ => (prime_radical hJ).eq_rad β–Έ radical.subset hIJ hx) fun x hx => Classical.byContradiction fun hxI => let S : MultiplicativeSet A := { subset := {a | βˆƒ n : Nat, a = x ^ n} has_one := ⟨0, rfl⟩ mul_closed := fun ⟨m, hm⟩ ⟨n, hn⟩ => ⟨m + n, hm β–Έ hn β–Έ (pow_nat_add_distrib x m n).symm⟩ } let ⟨J, hIJ, hJS, hJ⟩ := t1_2 I.radical S (by apply Set.disjoint.elementwise.mpr; intro a haI ⟨n, hn⟩ byCases hn0 : n = 0 { apply ((is_unit_ideal.mpr (pow_nat_0 x β–Έ hn0 β–Έ hn β–Έ haI)) β–Έ hxI : x βˆ‰ (1 : Ideal A)); trivial } { exact absurd (radical.is_radical I x n hn0 (hn β–Έ haI)) hxI }) absurd ⟨1, rfl⟩ (Set.disjoint.elementwise.mp hJS x (sIntersection.mem.mp hx J ⟨Subset.trans (radical.sub_self I) hIJ, hJ⟩)) theorem Ring.nil_radical.eq_prime_intersection (A : Type _) [Ring A] : Ring.nil_radical A = β‹‚β‚€ Ring.Spec A := (Ideal.radical_prime_intersection 0).trans (Ideal.ext'.mpr fun x => by rw [Ideal.sIntersection.mem, Ideal.sIntersection.mem]; exact forall_congr' fun P => (by simp only [P.zero_ideal_in, true_and]; exact Iff.rfl : _ ∧ _ β†’ _ ↔ _)) -- Theorem 1.3 private theorem t1_3 (fI : Finset (Ideal A)) (hfI : βˆ€ I ∈ fI, βˆ€ J ∈ fI, I β‰  J β†’ Ideal.coprime I J) : β‹‚β‚€ fI.toSet = ∏ fI := @Finset.cons_induction _ (fun f => f βŠ† fI β†’ β‹‚β‚€ f.toSet = ∏ f) (fun _ => by rw [Finset.empty_toSet, Ideal.sIntersection.empty]; rfl) (fun J s hJs ih hsfI => by rw [Finset.prod.cons, Ideal.product.coprime_eq_inter ((Ideal.coprime.comm _ _).mp (Ideal.product.prod_coprime (fun K hK => hfI J (hsfI (s.mem_cons_self hJs)) K (hsfI (Finset.mem_cons_self' hJs hK)) fun h => absurd (h β–Έ hK) hJs))), ←ih fun x hx => hsfI (Finset.mem_cons_self' hJs hx), ←Ideal.sIntersection.insert, Finset.cons_toSet]) fI (Subset.refl fI) open QuotientRing -- Theorem 1.4 private noncomputable def t1_4 (fI : Finset (Ideal A)) (hfI : βˆ€ I ∈ fI, βˆ€ J ∈ fI, I β‰  J β†’ Ideal.coprime I J) : QClass (β‹‚β‚€ fI.toSet) β‰…α΅£ MultiProd (fun i : fI => QClass i.val) := Classical.choice (@Finset.cons_induction _ (fun f : Finset (Ideal A) => f βŠ† fI β†’ Nonempty (QClass (β‹‚β‚€ f.toSet) β‰…α΅£ MultiProd (fun i : f => QClass i.val))) (fun _ => by rw [Finset.empty_toSet, Ideal.sIntersection.empty] exact ⟨{ hom := fun _ _ => 0 preserve_zero := rfl preserve_add := fun _ _ => (add_zero _).symm preserve_neg := fun _ => Group.neg_zero.symm preserve_mul := fun _ _ => (mul_zero _).symm inv := fun _ => 0 left_inv := fun x => (QuotientRing.trivial_zero x).symm right_inv := fun x => funext fun ⟨_, _⟩ => by contradiction }⟩) (fun I s hI ih hs => by have f₁ := chinese_remainder_theorem (β‹‚β‚€ s.toSet) I ((Ideal.coprime.comm _ _).mp (Ideal.sIntersection.sinter_coprime fun J hJ => hfI I (hs (s.mem_cons_self hI)) J (hs (Finset.mem_cons_self' hI hJ)) fun h => absurd (h β–Έ hJ) hI)) have fβ‚‚ : QClass (β‹‚β‚€Finset.toSet s) Γ— QClass I β‰…α΅£ MultiProd (fun i : s => QClass i.val) Γ— QClass I := (Classical.choice (ih (fun x hx => hs (Finset.mem_cons_self' hI hx)))).Product RIsomorphism.Identity rw [Finset.cons_toSet, Ideal.sIntersection.insert] exact ⟨(f₁.comp fβ‚‚).comp (RIsomorphism.MultiProd_cons QClass hI)⟩) fI (Subset.refl _)) end M4R
lemma holomorphic_on_If_Un [holomorphic_intros]: assumes "f holomorphic_on A" "g holomorphic_on B" "open A" "open B" assumes "\<And>z. z \<in> A \<Longrightarrow> z \<in> B \<Longrightarrow> f z = g z" shows "(\<lambda>z. if z \<in> A then f z else g z) holomorphic_on (A \<union> B)" (is "?h holomorphic_on _")
-- structure S := (g {Ξ±} : Ξ± β†’ Ξ±) def f (h : Nat β†’ ({Ξ± : Type} β†’ Ξ± β†’ Ξ±) Γ— Bool) : Nat := (h 0).1 1 def tst : Nat := f fun n => (fun x => x, true) theorem ex : id (Nat β†’ Nat) := by { intro; assumption } def g (i j k : Nat) (a : Array Nat) (h₁ : i < k) (hβ‚‚ : k < j) (h₃ : j < a.size) : Nat := let vj := a.get ⟨j, hβ‚ƒβŸ©; let vi := a.get ⟨i, Nat.ltTrans h₁ (Nat.ltTrans hβ‚‚ h₃)⟩; vi + vj set_option pp.all true in #print g #check g.proof_1 theorem ex1 {p q r s : Prop} : p ∧ q ∧ r ∧ s β†’ r ∧ s ∧ q ∧ p := fun ⟨hp, hq, hr, hs⟩ => ⟨hr, hs, hq, hp⟩ theorem ex2 {p q r s : Prop} : p ∧ q ∧ r ∧ s β†’ r ∧ s ∧ q ∧ p := by intro ⟨hp, hq, hr, hs⟩ exact ⟨hr, hs, hq, hp⟩
lemma connected_empty [simp]: "connected {}"
def g (x : Nat) : List (Nat Γ— List Nat) := [(x, [x, x]), (x, [])] def h (x : Nat) : List (Nat Γ— List Nat) := g x |>.filter fun ⟨_, xs⟩ => xs.isEmpty theorem ex1 : g 10 = [(10, [10, 10]), (10, [])] := rfl theorem ex2 : h 10 = [(10, [])] := rfl
opaque A : Nat β†’ Type opaque f (x : Nat) (a : A x) : Nat example (x : Nat) (a : A (x + 0)) : f (x + 0) a = x := by simp trace_state -- ⊒ f x a = x sorry example (x : Nat) (a : A (x + 0)) : f (x + 0) a = x := by simp (config := { dsimp := false }) trace_state -- ⊒ f (x + 0) a = x sorry
----------------------------------------------------------------------------- -- | -- Module : Berp.Base.Truth -- Copyright : (c) 2010 Bernie Pope -- License : BSD-style -- Maintainer : [email protected] -- Stability : experimental -- Portability : ghc -- -- Implementation of the truth predicate on Python objects. -- ----------------------------------------------------------------------------- module Berp.Base.Truth (truth) where import {-# SOURCE #-} Berp.Base.HashTable as HashTable (sizeIO) import {-# SOURCE #-} Berp.Base.HashSet as HashSet (sizeIO) import Berp.Base.SemanticTypes (Object (..)) import Data.Complex (Complex (..)) import System.IO.Unsafe (unsafePerformIO) import Data.IORef (readIORef) -- XXX incomplete truth :: Object -> Bool truth (Bool { object_bool = b }) = b truth (Integer { object_integer = i }) = i /= 0 truth (Float { object_float = f }) = f /= 0 truth (Complex { object_complex = c }) = c /= (0 :+ 0) truth None = False truth obj@(Tuple {}) = object_length obj /= 0 truth obj@(String {}) = object_string obj /= [] truth obj@(List {}) = unsafePerformIO $ do numElems <- readIORef $ object_list_num_elements obj return (numElems /= 0) truth obj@(Dictionary {}) = unsafePerformIO $ do numElems <- HashTable.sizeIO $ object_hashTable obj return (numElems /= 0) truth obj@(Set {}) = unsafePerformIO $ do numElems <- HashSet.sizeIO $ object_hashSet obj return (numElems /= 0) truth _other = True {- Python Language Reference, section 5.10 "Boolean operations": In the context of Boolean operations, and also when expressions are used by control flow statements, the following values are interpreted as false: False, None, numeric zero of all types, and empty strings and containers (including strings, tuples, lists, dictionaries, sets and frozensets). All other values are interpreted as true. User-defined objects can customize their truth value by providing a __bool__() method. -}
theory deMorgan1 imports Main begin text\<open> Apply style \<close> lemma lem_k_1 : "\<not>(p \<or> q) \<longrightarrow> (\<not>p \<and> \<not>q)" apply (rule impI) apply (rule conjI) apply (rule notI) apply (erule notE) apply(rule disjI1) apply assumption apply (rule notI) apply (erule notE) apply (rule disjI2) apply assumption done end
import smt2 lemma p_implies_p (P : Prop) : P β†’ P := begin intros, z3 end
theory Check imports Submission begin theorem double_len: "length (double xs) = 2 * length xs" by (rule Submission.double_len) theorem reverse_double: "reverse (double xs) = double (reverse xs)" by (rule Submission.reverse_double) theorem rev_double: "rev (double xs) = double (rev xs)" by (rule Submission.rev_double) end
lemmas continuous_Re [simp] = bounded_linear.continuous [OF bounded_linear_Re]
def head {Ξ±} : (as : List Ξ±) β†’ as β‰  [] β†’ Ξ± | [], h => absurd rfl h | a::as, _ => a theorem head_cons {Ξ±} (a : Ξ±) (as : List Ξ±) : head (a::as) (fun h => List.noConfusion h) = a := rfl theorem head_cons' {Ξ±} (a : Ξ±) (as : List Ξ±) (h : a::as β‰  []) : head (a::as) h = a := rfl
import data.nat.digits open nat open int /- (a) Prove the "rule of 9": an integer is divisible by 9 if and only if the sum of its digits is divisible by 9. (b) Prove the "rule of 11" stated in Example 13.6. Use this rule to decide in your head whether the number 82918073579 is divisible by 11. -/ lemma part_a (n : β„€) : 9 ∣ n ↔ 9 ∣ (digits 10 n.nat_abs).sum := begin sorry end lemma part_b (n : β„€) : 11 ∣ n ↔ (11 : β„€) ∣ ((digits 10 n.nat_abs).map (Ξ» (n : β„•), ↑n)).alternating_sum := begin sorry end
(* Title: Code_Int_Integer_Conversion.thy Author: Andreas Lochbihler, ETH Zurich *) chapter \<open>A special case of a conversion.\<close> theory Code_Int_Integer_Conversion imports Main begin text \<open> Use this function to convert numeral @{typ integer}s quickly into @{typ int}s. By default, it works only for symbolic evaluation; normally generated code raises an exception at run-time. If theory \<^text>\<open>Code_Target_Int_Bit\<close> is imported, it works again, because then @{typ int} is implemented in terms of @{typ integer} even for symbolic evaluation. \<close> definition int_of_integer_symbolic :: "integer \<Rightarrow> int" where "int_of_integer_symbolic = int_of_integer" lemma int_of_integer_symbolic_aux_code [code nbe]: "int_of_integer_symbolic 0 = 0" "int_of_integer_symbolic (Code_Numeral.Pos n) = Int.Pos n" "int_of_integer_symbolic (Code_Numeral.Neg n) = Int.Neg n" by (simp_all add: int_of_integer_symbolic_def) end
/- Copyright (c) 2019 Neil Strickland. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Neil Strickland -/ import data.nat.choose import algebra.prod_equiv import tactic.squeeze /- Consider the identity (choose n k) = (choose k-1 k-1) + (choose k k-1) + ... + (choose n-1 k-1) or (choose n+1 k+1) = (choose k k) + (choose k+1 k) + ... + (choose n k) This can be proved algebraically by induction. Alternatively, we can consider the set (P n k) of subsets A of size k in {0,..,n-1}, so |(P n k)| = (choose n k). We can split this set up according to the value of (max A), and recover a combinatorial proof of the identity. -/ lemma choose_sum' (k m : β„•) : nat.choose (k + m) (k + 1) = (finset.range m).sum (Ξ» i, nat.choose (k + i) k) := begin induction m with m ih, {rw[finset.range_zero,finset.sum_empty,add_zero,nat.choose_succ_self]}, {rw[finset.sum_range_succ,← ih,nat.add_succ,nat.choose, add_comm],} end lemma choose_sum (n k : β„•) : nat.choose n.succ k.succ = (finset.Ico k n.succ).sum (Ξ» i, nat.choose i k) := begin by_cases h : k ≀ n.succ, { let m := n.succ - k, have : n.succ = k + m := by rw [add_comm, nat.sub_add_cancel h], rw [this] at h ⊒, rw [choose_sum' k m], let f : β„• β†’ β„• := Ξ» p, nat.choose p k, let g : β„• β†’ β„• := has_add.add k, change (finset.range m).sum (Ξ» i, f (g i)) = (finset.Ico k (k + m)).sum f, rw [← @finset.sum_image β„• β„• β„• f _ _ (finset.range m) g (Ξ» _ _ _ _, nat.add_left_cancel)], have : finset.range m = finset.Ico 0 m := begin ext i, simp only [finset.mem_range, finset.mem_Ico, nat.zero_le i, true_and] end, rw [this], have := finset.image_add_left_Ico 0 m k, rw[add_zero] at this, rw[← this]}, { have : finset.Ico k n.succ = βˆ… := finset.Ico_eq_empty_iff.mpr (Ξ» hβ‚€, h (le_of_lt hβ‚€)), rw[this, finset.sum_empty], rw [nat.choose_eq_zero_of_lt (lt_trans (lt_of_not_ge h) k.lt_succ_self)] } end
informal statement Let $R$ be the ring of $2 \times 2$ matrices over the real numbers; suppose that $I$ is an ideal of $R$. Show that $I = (0)$ or $I = R$.formal statement theorem exercise_4_5_16 {p n: β„•} (hp : nat.prime p) {q : polynomial (zmod p)} (hq : irreducible q) (hn : q.degree = n) : βˆƒ is_fin : fintype $ polynomial (zmod p) β§Έ ideal.span ({q} : set (polynomial $ zmod p)), @card (polynomial (zmod p) β§Έ ideal.span {q}) is_fin = p ^ n ∧ is_field (polynomial $ zmod p):=
/- ----------------------------------------------------------------------- Categories. ----------------------------------------------------------------------- -/ import ...p0_stdlib namespace qp open stdaux universe variables β„“ β„“obj β„“hom β„“obj₁ β„“hom₁ β„“objβ‚‚ β„“homβ‚‚ /-! #brief A strict category. -/ structure Cat : Type ((max β„“obj β„“hom) + 1) := (obj : Type β„“obj) (hom : βˆ€ (x y : obj) , Sort β„“hom) (id : βˆ€ (x : obj) , hom x x) (circ : βˆ€ {x y z : obj} , hom y z β†’ hom x y β†’ hom x z) (circ_assoc : βˆ€ {x y z w : obj} {h : hom z w} {g : hom y z} {f : hom x y} , circ h (circ g f) = circ (circ h g) f) (circ_id_left : βˆ€ {x y : obj} {f : hom x y} , circ (id y) f = f) (circ_id_right : βˆ€ {x y : obj} {f : hom x y} , circ f (id x) = f) attribute [simp] Cat.circ_id_left attribute [simp] Cat.circ_id_right /-! #brief Equality of categories. -/ theorem Cat.eq : βˆ€ {C₁ Cβ‚‚ : Cat.{β„“obj β„“hom}} , C₁^.obj = Cβ‚‚^.obj β†’ C₁^.hom == Cβ‚‚^.hom β†’ C₁^.id == Cβ‚‚^.id β†’ @Cat.circ C₁ == @Cat.circ Cβ‚‚ β†’ C₁ = Cβ‚‚ | C₁ Cβ‚‚ Ο‰obj Ο‰hom Ο‰id Ο‰circ := begin cases C₁ with obj₁ hom₁ id₁ circ₁ ω₁₁ ω₁₂ ω₁₃, cases Cβ‚‚ with objβ‚‚ homβ‚‚ idβ‚‚ circβ‚‚ ω₂₁ Ο‰β‚‚β‚‚ ω₂₃, simp at Ο‰obj, subst Ο‰obj, simp at Ο‰hom, cases Ο‰hom, simp at Ο‰id, cases Ο‰id, simp at Ο‰circ, cases Ο‰circ, exact rfl end /-! #brief Left congruence for circ. -/ theorem Cat.circ.congr_left {C : Cat.{β„“obj β„“hom}} {x y z : C^.obj} : βˆ€ {g₁ gβ‚‚ : C^.hom y z} {f : C^.hom x y} (Ο‰g : g₁ = gβ‚‚) , C^.circ g₁ f = C^.circ gβ‚‚ f | g .(g) f (eq.refl .(g)) := rfl /-! #brief Right congruence for circ. -/ theorem Cat.circ.congr_right {C : Cat.{β„“obj β„“hom}} {x y z : C^.obj} : βˆ€ {g : C^.hom y z} {f₁ fβ‚‚ : C^.hom x y} (Ο‰f : f₁ = fβ‚‚) , C^.circ g f₁ = C^.circ g fβ‚‚ | g f .(f) (eq.refl .(f)) := rfl /-! #brief Bi-congruence for circ. -/ theorem Cat.circ.congr {C : Cat.{β„“obj β„“hom}} {x y z : C^.obj} : βˆ€ {g₁ gβ‚‚ : C^.hom y z} {f₁ fβ‚‚ : C^.hom x y} (Ο‰g : g₁ = gβ‚‚) (Ο‰f : f₁ = fβ‚‚) , C^.circ g₁ f₁ = C^.circ gβ‚‚ fβ‚‚ | g .(g) f .(f) (eq.refl .(g)) (eq.refl .(f)) := rfl -- An object in a category. -- \[[ \]] notation `⟦` C `⟧` := Cat.obj C -- The identity hom at an object. -- \langle\langle \rangle\rangle notation `⟨⟨` x `⟩⟩` := Cat.id _ x -- A hom in a category. -- \[[ : \to\to \]] notation `⟦` C ` : ` x ` β†’β†’ ` y `⟧` := Cat.hom C x y -- Composition of hom's in a category. -- \o\o infixl ` ∘∘ ` : 100 := Cat.circ _ /-! #brief A finite category. -/ class Cat.Finite (C : Cat.{β„“obj β„“hom}) : Type (max β„“obj β„“hom) := (obj_fin : FinType C^.obj) (hom_fin : βˆ€ (x y : C^.obj), FinSort (C^.hom x y)) attribute [instance] Cat.Finite.obj_fin attribute [instance] Cat.Finite.hom_fin /- ----------------------------------------------------------------------- The empty and star categories. ----------------------------------------------------------------------- -/ /-! #brief The category with one object and one hom. -/ definition UnitCat : Cat.{β„“obj β„“hom} := { obj := punit , hom := Ξ» u₁ uβ‚‚, punit , id := Ξ» u, punit.star , circ := Ξ» u₁ uβ‚‚ u₃ g f, punit.star , circ_assoc := Ξ» u₁ uβ‚‚ u₃ uβ‚„ h g f, rfl , circ_id_left := Ξ» u₁ uβ‚‚ f, begin cases f, trivial end , circ_id_right := Ξ» u₁ uβ‚‚ f, begin cases f, trivial end } /-! #brief UnitCat is a finite category. -/ instance UnitCat.Finite : Cat.Finite (UnitCat.{β„“obj β„“hom}) := { obj_fin := punit.FinSort , hom_fin := Ξ» u₁ uβ‚‚, punit.FinSort } /-! #brief The category with no objects. -/ definition EmptyCat : Cat.{β„“obj β„“hom} := { obj := pempty , hom := Ξ» u₁ uβ‚‚, pempty , id := Ξ» u, by cases u , circ := Ξ» u₁ uβ‚‚ u₃ g f, by cases f , circ_assoc := Ξ» u₁ uβ‚‚ u₃ uβ‚„ h g f, by cases f , circ_id_left := Ξ» u₁ uβ‚‚ f, by cases f , circ_id_right := Ξ» u₁ uβ‚‚ f, by cases f } /-! #brief EmptyCat is a finite category. -/ instance EmptyCat.Finite : Cat.Finite (EmptyCat.{β„“obj β„“hom}) := { obj_fin := pempty.FinSort , hom_fin := Ξ» u₁ uβ‚‚, pempty.FinSort } /- ----------------------------------------------------------------------- The Lean categories. ----------------------------------------------------------------------- -/ /-! #brief The category of Lean sorts at level β„“. -/ definition SortCat : Cat.{β„“ β„“} := { obj := Sort.{β„“} , hom := Ξ» X Y, X β†’ Y , id := Ξ» X x, x , circ := Ξ» X Y Z g f x, g (f x) , circ_assoc := Ξ» X Y Z W h g f, rfl , circ_id_left := Ξ» X Y f, rfl , circ_id_right := Ξ» X Y f, rfl } /-! #brief Composition in SortCat. -/ theorem SortCat.simp_circ {X Y Z : SortCat.{β„“}^.obj} {g : SortCat^.hom Y Z} {f : SortCat^.hom X Y} {x : X} : SortCat^.circ g f x = g (f x) := rfl /-! #brief The category of Lean propositions. -/ definition PropCat : Cat.{0 0} := SortCat.{0} example : PropCat^.obj := true /-! #brief Composition in PropCat. -/ theorem PropCat.simp_circ {X Y Z : PropCat^.obj} {g : PropCat^.hom Y Z} {f : PropCat^.hom X Y} {x : X} : PropCat^.circ g f x = g (f x) := rfl /-! #brief The category of Lean types at level β„“. -/ definition LeanCat : Cat.{(β„“ + 1) (β„“ + 1)} := SortCat.{β„“ + 1} example : LeanCat.{0}^.obj := β„• example : LeanCat.{1}^.obj := β„• β†’ LeanCat.{0}^.obj example : LeanCat.{β„“}^.obj := punit example : LeanCat.{β„“}^.obj := list punit /-! #brief Composition in LeanCat. -/ theorem LeanCat.simp_circ {X Y Z : LeanCat.{β„“}^.obj} {g : LeanCat^.hom Y Z} {f : LeanCat^.hom X Y} {x : X} : LeanCat^.circ g f x = g (f x) := rfl /- ----------------------------------------------------------------------- Categories which box up certain theories. ----------------------------------------------------------------------- -/ /-! #brief The category of relations and monotone functions. -/ definition CatOfRels : Cat.{(β„“ + 1) (β„“ + 1)} := { obj := Ξ£ (A : Type β„“), (A β†’ A β†’ Prop) , hom := Ξ» A B, { f : A^.fst β†’ B^.fst // monotone A^.snd B^.snd f } , id := Ξ» A, { val := id, property := id.monotone A^.snd } , circ := Ξ» A B C g f, { val := Ξ» a, g^.val (f^.val a) , property := begin intros a₁ aβ‚‚ Ο‰, apply g^.property, apply f^.property, exact Ο‰ end } , circ_assoc := Ξ» A B C D h g f, subtype.eq rfl , circ_id_left := Ξ» A B f, subtype.eq rfl , circ_id_right := Ξ» A B f, subtype.eq rfl } /-! #brief The category of preorders and monotone functions. -/ definition CatOfPreorders : Cat.{(β„“ + 1) (β„“ + 1)} := { obj := { A : Ξ£ (A : Type β„“), (A β†’ A β†’ Prop) // reflexive A^.snd ∧ transitive A^.snd } , hom := Ξ» A B, { f : A^.val^.fst β†’ B^.val^.fst // monotone A^.val^.snd B^.val^.snd f } , id := Ξ» A, { val := id, property := id.monotone A^.val^.snd } , circ := Ξ» A B C g f, { val := Ξ» a, g^.val (f^.val a) , property := begin intros a₁ aβ‚‚ Ο‰, apply g^.property, apply f^.property, exact Ο‰ end } , circ_assoc := Ξ» A B C D h g f, subtype.eq rfl , circ_id_left := Ξ» A B f, subtype.eq rfl , circ_id_right := Ξ» A B f, subtype.eq rfl } /-! #brief The category of semigroups. -/ definition CatOfSemigroups : Cat.{(β„“ + 1) (β„“ + 1)} := { obj := Ξ£ (A : Type β„“), semigroup A , hom := Ξ» A B, { f : A^.fst β†’ B^.fst // @semigroup.hom _ A^.snd _ B^.snd f } , id := Ξ» A, { val := id, property := @semigroup.hom_id _ A^.snd } , circ := Ξ» A B C g f, { val := Ξ» a, g^.val (f^.val a) , property := @semigroup.hom_comp _ A^.snd _ B^.snd _ C^.snd _ g^.property _ f^.property } , circ_assoc := Ξ» A B C D h g f, subtype.eq rfl , circ_id_left := Ξ» A B f, subtype.eq rfl , circ_id_right := Ξ» A B f, subtype.eq rfl } /-! #brief The category of monoids. -/ definition CatOfMonoids : Cat.{(β„“ + 1) (β„“ + 1)} := { obj := Ξ£ (A : Type β„“), monoid A , hom := Ξ» A B, { f : A^.fst β†’ B^.fst // @monoid.hom _ A^.snd _ B^.snd f } , id := Ξ» A, { val := id, property := @monoid.hom_id _ A^.snd } , circ := Ξ» A B C g f, { val := Ξ» a, g^.val (f^.val a) , property := @monoid.hom_comp _ A^.snd _ B^.snd _ C^.snd _ g^.property _ f^.property } , circ_assoc := Ξ» A B C D h g f, subtype.eq rfl , circ_id_left := Ξ» A B f, subtype.eq rfl , circ_id_right := Ξ» A B f, subtype.eq rfl } /-! #brief The category of groups. -/ definition CatOfGroups : Cat.{(β„“ + 1) (β„“ + 1)} := { obj := Ξ£ (A : Type β„“), group A , hom := Ξ» A B, { f : A^.fst β†’ B^.fst // @group.hom _ A^.snd _ B^.snd f } , id := Ξ» A, { val := id, property := @group.hom_id _ A^.snd } , circ := Ξ» A B C g f, { val := Ξ» a, g^.val (f^.val a) , property := @group.hom_comp _ A^.snd _ B^.snd _ C^.snd _ g^.property _ f^.property } , circ_assoc := Ξ» A B C D h g f, subtype.eq rfl , circ_id_left := Ξ» A B f, subtype.eq rfl , circ_id_right := Ξ» A B f, subtype.eq rfl } /-! #brief The category of commutative rings. -/ definition CatOfCommRings : Cat.{(β„“ + 1) (β„“ + 1)} := { obj := Ξ£ (A : Type β„“), comm_ring A , hom := Ξ» A B, { f : A^.fst β†’ B^.fst // @comm_ring.hom _ A^.snd _ B^.snd f } , id := Ξ» A, { val := id, property := @comm_ring.hom_id _ A^.snd } , circ := Ξ» A B C g f, { val := Ξ» a, g^.val (f^.val a) , property := @comm_ring.hom_comp _ A^.snd _ B^.snd _ C^.snd _ g^.property _ f^.property } , circ_assoc := Ξ» A B C D h g f, subtype.eq rfl , circ_id_left := Ξ» A B f, subtype.eq rfl , circ_id_right := Ξ» A B f, subtype.eq rfl } /- ----------------------------------------------------------------------- Categories induced by monoids and groups. ----------------------------------------------------------------------- -/ /-! #brief A monoid category. -/ definition MonoidCat (A : Type β„“) [A_monoid : monoid A] : Cat.{(β„“ + 1) (β„“ + 1)} := { obj := punit , hom := Ξ» u₁ uβ‚‚, A , id := Ξ» u, 1 , circ := Ξ» u₁ uβ‚‚ u₃ g f, g * f , circ_assoc := Ξ» u₁ uβ‚‚ u₃ uβ‚„ h g f, eq.symm (mul_assoc h g f) , circ_id_left := Ξ» u₁ uβ‚‚ f, one_mul f , circ_id_right := Ξ» u₁ uβ‚‚ f, mul_one f } /-! #brief A group category. -/ definition GroupCat (A : Type β„“) [A_group : group A] : Cat.{(β„“ + 1) (β„“ + 1)} := MonoidCat A /- ----------------------------------------------------------------------- Preorder categories and categories of objects. ----------------------------------------------------------------------- -/ /-! #brief A preorder category. -/ definition PreorderCat {A : Type β„“} (r : A β†’ A β†’ Prop) (r_refl : reflexive r) (r_trans : transitive r) : Cat.{β„“ 0} := { obj := A , hom := r , id := r_refl , circ := Ξ» a₁ aβ‚‚ a₃ g f, r_trans f g , circ_assoc := Ξ» a₁ aβ‚‚ a₃ aβ‚„ h g f, proof_irrel _ _ , circ_id_left := Ξ» a₁ aβ‚‚ f, proof_irrel _ _ , circ_id_right := Ξ» a₁ aβ‚‚ f, proof_irrel _ _ } /-! #brief The category of natural numbers, ordered by nat.le -/ definition NatCat : Cat.{0 0} := PreorderCat nat.le @nat.le_refl @nat.le_trans /-! #brief Decidable preorders on finite types induce finite categories. -/ instance PreorderCat.Finite {A : Type β„“} (r : A β†’ A β†’ Prop) (r_refl : reflexive r) (r_trans : transitive r) [A_FinType : FinType A] [r_decidable : decidable_rel r] : Cat.Finite (PreorderCat r r_refl r_trans) := { obj_fin := A_FinType , hom_fin := Ξ» a₁ aβ‚‚, @Prop.decidable_FinSort (r a₁ aβ‚‚) (r_decidable a₁ aβ‚‚) } /-! #brief A category of objects. -/ definition ObjCat (A : Type β„“) : Cat.{β„“ 0} := PreorderCat (@eq A) (@eq.refl A) (@eq.trans A) /-! #brief Finite types yield finite object categories. -/ instance ObjCat.Finite (A : Type β„“) [A_FinType : FinType A] : Cat.Finite (ObjCat A) := PreorderCat.Finite (@eq A) (@eq.refl A) (@eq.trans A) /-! #brief The finite category with N objects. -/ definition FinCat (N : β„•) : Cat.{0 0} := ObjCat (fin N) /-! #brief The finite category is finite. -/ instance FinCat.Finite (N : β„•) : Cat.Finite (FinCat N) := ObjCat.Finite (fin N) /- ----------------------------------------------------------------------- Arrow categories. ----------------------------------------------------------------------- -/ /-! #brief An object in an arrow category. -/ structure Arr (C : Cat.{β„“obj β„“hom}) : Type (max β„“obj β„“hom) := (dom : C^.obj) (codom : C^.obj) (hom : C^.hom dom codom) /-! #brief A hom in an arrow category. -/ structure ArrHom (C : Cat.{β„“obj β„“hom}) (X Y : Arr C) : Sort (max 1 β„“hom) := (hom_dom : C^.hom X^.dom Y^.dom) (hom_codom : C^.hom X^.codom Y^.codom) (comm : hom_codom ∘∘ X^.hom = Y^.hom ∘∘ hom_dom) /-! #brief Equality helper for ArrHom. -/ theorem ArrHom.eq {C : Cat.{β„“obj β„“hom}} {X Y : Arr C} : βˆ€ {f₁ fβ‚‚ : ArrHom C X Y} (Ο‰dom : f₁^.hom_dom = fβ‚‚^.hom_dom) (Ο‰codom : f₁^.hom_codom = fβ‚‚^.hom_codom) , f₁ = fβ‚‚ | (ArrHom.mk dom codom ω₁) (ArrHom.mk .(dom) .(codom) Ο‰β‚‚) (eq.refl .(dom)) (eq.refl .(codom)) := rfl /-! #brief The identity hom in an arrow category. -/ definition ArrHom.id {C : Cat.{β„“obj β„“hom}} (X : Arr C) : ArrHom C X X := { hom_dom := C^.id X^.dom , hom_codom := C^.id X^.codom , comm := by rw [C^.circ_id_left, C^.circ_id_right] } /-! #brief Composition of homs in an arrow category. -/ definition ArrHom.comp {C : Cat.{β„“obj β„“hom}} {X Y Z : Arr C} (g : ArrHom C Y Z) (f : ArrHom C X Y) : ArrHom C X Z := { hom_dom := g^.hom_dom ∘∘ f^.hom_dom , hom_codom := g^.hom_codom ∘∘ f^.hom_codom , comm := begin repeat { rw -C^.circ_assoc }, rw f^.comm, repeat { rw C^.circ_assoc }, rw g^.comm end } /-! #brief ArrHom.id is a left-identity for ArrHom.comp. -/ theorem ArrHom.comp_id_left {C : Cat.{β„“obj β„“hom}} {X Y : Arr C} {f : ArrHom C X Y} : ArrHom.comp (ArrHom.id Y) f = f := ArrHom.eq C^.circ_id_left C^.circ_id_left /-! #brief ArrHom.id is a right-identity for ArrHom.comp. -/ theorem ArrHom.comp_id_right {C : Cat.{β„“obj β„“hom}} {X Y : Arr C} {f : ArrHom C X Y} : ArrHom.comp f (ArrHom.id X) = f := ArrHom.eq C^.circ_id_right C^.circ_id_right /-! #brief ArrHom.comp is associative. -/ theorem ArrHom.comp_assoc {C : Cat.{β„“obj β„“hom}} {X Y Z W : Arr C} {h : ArrHom C Z W} {g : ArrHom C Y Z} {f : ArrHom C X Y} : ArrHom.comp h (ArrHom.comp g f) = ArrHom.comp (ArrHom.comp h g) f := ArrHom.eq C^.circ_assoc C^.circ_assoc /-! #brief An arrow category. -/ definition ArrCat (C : Cat.{β„“obj β„“hom}) : Cat.{(max β„“obj β„“hom) (max 1 β„“hom)} := { obj := Arr C , hom := ArrHom C , id := ArrHom.id , circ := @ArrHom.comp C , circ_id_left := Ξ» x y f, ArrHom.comp_id_left , circ_id_right := Ξ» x y f, ArrHom.comp_id_right , circ_assoc := Ξ» x y z w h g f, ArrHom.comp_assoc } /- ----------------------------------------------------------------------- Product categories. ----------------------------------------------------------------------- -/ /-! #brief The product category. -/ definition ProdCat (C : Cat.{β„“obj₁ β„“hom₁}) (D : Cat.{β„“objβ‚‚ β„“homβ‚‚}) : Cat.{(max β„“obj₁ β„“objβ‚‚) (max 1 β„“hom₁ β„“homβ‚‚)} := { obj := prod C^.obj D^.obj , hom := Ξ» cd₁ cdβ‚‚, pprod (C^.hom cd₁^.fst cdβ‚‚^.fst) (D^.hom cd₁^.snd cdβ‚‚^.snd) , id := Ξ» cd, { fst := C^.id cd^.fst , snd := D^.id cd^.snd } , circ := Ξ» x y z g f, { fst := C^.circ g^.fst f^.fst , snd := D^.circ g^.snd f^.snd } , circ_assoc := Ξ» x y z w h g f, by rw [C^.circ_assoc, D^.circ_assoc] , circ_id_left := Ξ» x y f, begin cases f, simp end , circ_id_right := Ξ» x y f, begin cases f, simp end } -- A product category. -- \times\times infixr `Γ—Γ—` : 200 := ProdCat /- ----------------------------------------------------------------------- Opposite categories. ----------------------------------------------------------------------- -/ /-! #brief The opposite category. -/ @[reducible] definition OpCat (C : Cat.{β„“obj β„“hom}) : Cat.{β„“obj β„“hom} := { obj := C^.obj , hom := Ξ» x y, C^.hom y x , id := Ξ» x, C^.id x , circ := Ξ» x y z g f, C^.circ f g , circ_assoc := Ξ» x y z w h g f, eq.symm C^.circ_assoc , circ_id_left := Ξ» x y f, C^.circ_id_right , circ_id_right := Ξ» x y f, C^.circ_id_left } -- An opposite category. -- \inv notation C `⁻¹` := OpCat C /-! #brief OpCat is an involution. -/ theorem OpCat_OpCat (C : Cat.{β„“obj β„“hom}) : OpCat (OpCat C) = C := begin apply Cat.eq, { trivial }, { trivial }, { trivial }, { trivial } end /-! #brief OpCat distributes over ProdCat. -/ theorem OpCat_ProdCat (C : Cat.{β„“obj₁ β„“hom₁}) (D : Cat.{β„“objβ‚‚ β„“homβ‚‚}) : OpCat (ProdCat C D) = ProdCat (OpCat C) (OpCat D) := begin apply Cat.eq, { trivial }, { trivial }, { trivial }, { trivial } end /- ----------------------------------------------------------------------- Over and under categories. ----------------------------------------------------------------------- -/ /-! #brief An object in an over category. -/ structure OverObj (C : Cat.{β„“obj β„“hom}) (X : C^.obj) : Type (max β„“obj β„“hom) := (obj : C^.obj) (hom : C^.hom obj X) /-! #brief The object contained within an over object. -/ @[reducible] definition OverObj.dom {C : Cat.{β„“obj β„“hom}} {X : C^.obj} (A : OverObj C X) : C^.obj := A^.obj /-! #brief The hom contained within an over object. -/ @[reducible] definition OverObj.down {C : Cat.{β„“obj β„“hom}} {X : C^.obj} (A : OverObj C X) : C^.hom (OverObj.dom A) X := A^.hom /-! #brief Eqaulity of objects in an over category. -/ theorem OverObj.eq {C : Cat.{β„“obj β„“hom}} {X : C^.obj} : βˆ€ {A B : OverObj C X} (Ο‰obj : A^.dom = B^.dom) (Ο‰hom : A^.down == B^.down) , A = B | (OverObj.mk obj hom) (OverObj.mk .(obj) .(hom)) (eq.refl .(obj)) (heq.refl .(hom)) := rfl /-! #brief A hom in an over category. -/ structure OverHom (C : Cat.{β„“obj β„“hom}) (X : C^.obj) (A B : OverObj C X) : Sort (max 1 β„“hom) := (hom : C^.hom A^.dom B^.dom) (triangle : A^.down = C^.circ B^.down hom) /-! #brief Equality of homs in an over category. -/ theorem OverHom.eq {C : Cat.{β„“obj β„“hom}} {X : C^.obj} {A B : OverObj C X} : βˆ€ {f₁ fβ‚‚ : OverHom C X A B} , f₁^.hom = fβ‚‚^.hom β†’ f₁ = fβ‚‚ | (OverHom.mk hom ω₁) (OverHom.mk .(hom) Ο‰β‚‚) (eq.refl .(hom)) := rfl /-! #brief Heterogeneous equality of homs in an over category. -/ theorem OverHom.heq {C : Cat.{β„“obj β„“hom}} {X : C^.obj} : βˆ€ {A₁ B₁ Aβ‚‚ Bβ‚‚ : OverObj C X} {f₁ : OverHom C X A₁ B₁} {fβ‚‚ : OverHom C X Aβ‚‚ Bβ‚‚} , A₁ = Aβ‚‚ β†’ B₁ = Bβ‚‚ β†’ f₁^.hom == fβ‚‚^.hom β†’ f₁ == fβ‚‚ | (OverObj.mk a fa) (OverObj.mk b fb) (OverObj.mk .(a) .(fa)) (OverObj.mk .(b) .(fb)) (OverHom.mk f Ο‰f₁) (OverHom.mk .(f) Ο‰fβ‚‚) (eq.refl ._) (eq.refl ._) (heq.refl ._) := heq.refl _ /-! #brief The identity hom in an over category. -/ definition OverHom.id (C : Cat.{β„“obj β„“hom}) (X : C^.obj) (A : OverObj C X) : OverHom C X A A := { hom := C^.id A^.dom , triangle := eq.symm C^.circ_id_right } /-! #brief Composition of homs in an over category. -/ definition OverHom.comp (C : Cat.{β„“obj β„“hom}) (X : C^.obj) (P Q R : OverObj C X) (g : OverHom C X Q R) (f : OverHom C X P Q) : OverHom C X P R := { hom := C^.circ g^.hom f^.hom , triangle := by rw [f^.triangle, g^.triangle, C^.circ_assoc] } /-! #brief Associativity of hom composition in an over category. -/ theorem OverHom.comp_assoc (C : Cat.{β„“obj β„“hom}) (X : C^.obj) (P Q R S : OverObj C X) (h : OverHom C X R S) (g : OverHom C X Q R) (f : OverHom C X P Q) : OverHom.comp C X _ _ _ h (OverHom.comp C X _ _ _ g f) = OverHom.comp C X _ _ _ (OverHom.comp C X _ _ _ h g) f := begin apply OverHom.eq, exact C^.circ_assoc end /-! #brief Left-identity of hom composition in an over category. -/ theorem OverHom.comp_id_left (C : Cat.{β„“obj β„“hom}) (X : C^.obj) (P Q : OverObj C X) (f : OverHom C X P Q) : OverHom.comp C X _ _ _ (OverHom.id C X _) f = f := begin apply OverHom.eq, exact C^.circ_id_left end /-! #brief Right-identity of hom composition in an over category. -/ theorem OverHom.comp_id_right (C : Cat.{β„“obj β„“hom}) (X : C^.obj) (P Q : OverObj C X) (f : OverHom C X P Q) : OverHom.comp C X _ _ _ f (OverHom.id C X _) = f := begin apply OverHom.eq, exact C^.circ_id_right end /-! #brief An over category. -/ definition OverCat (C : Cat.{β„“obj β„“hom}) (X : C^.obj) : Cat.{(max β„“obj β„“hom) (max 1 β„“hom)} := { obj := OverObj C X , hom := OverHom C X , id := OverHom.id C X , circ := OverHom.comp C X , circ_assoc := OverHom.comp_assoc C X , circ_id_left := OverHom.comp_id_left C X , circ_id_right := OverHom.comp_id_right C X } -- An over category. -- // notation C `//` X := OverCat C X /-! #brief An under category. -/ definition UnderCat (C : Cat.{β„“obj β„“hom}) (X : C^.obj) : Cat.{(max β„“obj β„“hom) (max 1 β„“hom)} --:= OpCat (OverCat (OpCat C) X) := OpCat (OverCat (OpCat C) X) -- An under category. -- \\ notation C `\\` X := UnderCat C X /-! #brief An object in an under category. -/ definition UnderObj (C : Cat.{β„“obj β„“hom}) (X : C^.obj) : Type (max β„“obj β„“hom) := (UnderCat C X)^.obj /-! #brief A hom in an under category. -/ definition UnderHom (C : Cat.{β„“obj β„“hom}) (X : C^.obj) (A B : UnderObj C X) : Sort (max 1 β„“hom) := (UnderCat C X)^.hom A B /-! #brief Constructor for an object in an under category. -/ definition UnderObj.mk {C : Cat.{β„“obj β„“hom}} {X : C^.obj} {A : C^.obj} (f : C^.hom X A) : UnderObj C X := { obj := A, hom := f } /-! #brief The object contained within an under object. -/ @[reducible] definition UnderObj.codom {C : Cat.{β„“obj β„“hom}} {X : C^.obj} (A : UnderObj C X) : C^.obj := A^.obj /-! #brief The hom contained within an under object. -/ @[reducible] definition UnderObj.up {C : Cat.{β„“obj β„“hom}} {X : C^.obj} (A : UnderObj C X) : C^.hom X (UnderObj.codom A) := A^.hom /-! #brief Constructor for a hom in an under category. -/ definition UnderHom.mk {C : Cat.{β„“obj β„“hom}} {X : C^.obj} {A B : UnderObj C X} (f : C^.hom (UnderObj.codom A) (UnderObj.codom B)) (Ο‰ : B^.up = C^.circ f A^.up) : UnderHom C X A B := { hom := f, triangle := Ο‰ } /-! #brief The hom contained within an under hom. -/ @[reducible] definition UnderHom.hom {C : Cat.{β„“obj β„“hom}} {X : C^.obj} {A B : UnderObj C X} (f : UnderHom C X A B) : C^.hom (UnderObj.codom A) (UnderObj.codom B) := f^.hom /-! #brief The hom contained within an under hom. -/ @[reducible] theorem UnderHom.triangle {C : Cat.{β„“obj β„“hom}} {X : C^.obj} (A B : UnderObj C X) (f : UnderHom C X A B) : B^.up = UnderHom.hom f ∘∘ A^.up := f^.triangle /- ----------------------------------------------------------------------- Isomorphisms in categories. ----------------------------------------------------------------------- -/ /-! #brief An isomorphism in a category. -/ structure Iso {C : Cat.{β„“obj β„“hom}} {c₁ cβ‚‚ : C^.obj} (f : C^.hom c₁ cβ‚‚) (g : C^.hom cβ‚‚ c₁) : Prop := (id₁ : C^.circ g f = C^.id c₁) (idβ‚‚ : C^.circ f g = C^.id cβ‚‚) /-! #brief Iso's can be 'flipped' to run in the other direction. -/ definition Iso.flip {C : Cat.{β„“obj β„“hom}} {c₁ cβ‚‚ : C^.obj} {f : C^.hom c₁ cβ‚‚} {g : C^.hom cβ‚‚ c₁} (iso : Iso f g) : Iso g f := { id₁ := iso^.idβ‚‚ , idβ‚‚ := iso^.id₁ } /-! #brief Iso's have unique inverses. -/ definition Iso.inv_uniqβ‚‚ {C : Cat.{β„“obj β„“hom}} {c₁ cβ‚‚ : C^.obj} {f : C^.hom c₁ cβ‚‚} {g₁ gβ‚‚ : C^.hom cβ‚‚ c₁} (iso₁ : Iso f g₁) (isoβ‚‚ : Iso f gβ‚‚) : g₁ = gβ‚‚ := by calc g₁ = g₁ ∘∘ ⟨⟨cβ‚‚βŸ©βŸ© : by rw C^.circ_id_right ... = g₁ ∘∘ (f ∘∘ gβ‚‚) : by rw isoβ‚‚^.idβ‚‚ ... = (g₁ ∘∘ f) ∘∘ gβ‚‚ : by rw C^.circ_assoc ... = ⟨⟨cβ‚βŸ©βŸ© ∘∘ gβ‚‚ : by rw iso₁^.id₁ ... = gβ‚‚ : by rw C^.circ_id_left /-! #brief Iso's have unique inverses. -/ definition Iso.inv_uniq₁ {C : Cat.{β„“obj β„“hom}} {c₁ cβ‚‚ : C^.obj} {f₁ fβ‚‚ : C^.hom c₁ cβ‚‚} {g : C^.hom cβ‚‚ c₁} (iso₁ : Iso f₁ g) (isoβ‚‚ : Iso fβ‚‚ g) : f₁ = fβ‚‚ := Iso.inv_uniqβ‚‚ (Iso.flip iso₁) (Iso.flip isoβ‚‚) /-! #brief Identity homs are isomorphisms. -/ theorem Cat.id.Iso {C : Cat.{β„“obj β„“hom}} (c : C^.obj) : Iso (C^.id c) (C^.id c) := { id₁ := C^.circ_id_left , idβ‚‚ := C^.circ_id_left } /-! #brief Isomorphisms are closed under composition. -/ theorem Cat.circ.Iso {C : Cat.{β„“obj β„“hom}} {c₁ cβ‚‚ c₃ : C^.obj} {f₂₃ : C^.hom cβ‚‚ c₃} {g₂₃ : C^.hom c₃ cβ‚‚} (iso₂₃ : Iso f₂₃ g₂₃) {f₁₂ : C^.hom c₁ cβ‚‚} {g₁₂ : C^.hom cβ‚‚ c₁} (iso₁₂ : Iso f₁₂ g₁₂) : Iso (C^.circ f₂₃ f₁₂) (C^.circ g₁₂ g₂₃) := { id₁ := by calc g₁₂ ∘∘ g₂₃ ∘∘ (f₂₃ ∘∘ f₁₂) = g₁₂ ∘∘ (g₂₃ ∘∘ f₂₃) ∘∘ f₁₂ : by repeat {rw C^.circ_assoc} ... = g₁₂ ∘∘ ⟨⟨cβ‚‚βŸ©βŸ© ∘∘ f₁₂ : by rw iso₂₃^.id₁ ... = g₁₂ ∘∘ f₁₂ : by rw C^.circ_id_right ... = ⟨⟨cβ‚βŸ©βŸ© : by rw iso₁₂^.id₁ , idβ‚‚ := by calc f₂₃ ∘∘ f₁₂ ∘∘ (g₁₂ ∘∘ g₂₃) = f₂₃ ∘∘ (f₁₂ ∘∘ g₁₂) ∘∘ g₂₃ : by repeat {rw C^.circ_assoc} ... = f₂₃ ∘∘ ⟨⟨cβ‚‚βŸ©βŸ© ∘∘ g₂₃ : by rw iso₁₂^.idβ‚‚ ... = f₂₃ ∘∘ g₂₃ : by rw C^.circ_id_right ... = ⟨⟨cβ‚ƒβŸ©βŸ© : by rw iso₂₃^.idβ‚‚ } /- ----------------------------------------------------------------------- Monomorphism and epimorphisms. ----------------------------------------------------------------------- -/ /-! #brief A monomorphism. -/ class Monic {C : Cat.{β„“obj β„“hom}} {x y : C^.obj} (g : C^.hom x y) : Prop := (inj : βˆ€ {a : C^.obj} {f₁ fβ‚‚ : C^.hom a x} (Ο‰ : C^.circ g f₁ = C^.circ g fβ‚‚) , f₁ = fβ‚‚) /-! #brief Helper for showing a hom is monic. -/ definition Monic.show {C : Cat.{β„“obj β„“hom}} {x y : C^.obj} {g : C^.hom x y} (Ο‰ : βˆ€ {a : C^.obj} {f₁ fβ‚‚ : C^.hom a x} (Ο‰f : C^.circ g f₁ = C^.circ g fβ‚‚), f₁ = fβ‚‚) : Monic g := { inj := @Ο‰ } /-! #brief Using a monic. -/ definition monic_cancel {C : Cat.{β„“obj β„“hom}} {x y : C^.obj} (g : C^.hom x y) [g_Monic : Monic g] {a : C^.obj} {f₁ fβ‚‚ : C^.hom a x} (Ο‰ : C^.circ g f₁ = C^.circ g fβ‚‚) : f₁ = fβ‚‚ := Monic.inj Ο‰ /-! #brief Identity homs are monic. -/ instance Cat.id.Monic {C : Cat.{β„“obj β„“hom}} (c : C^.obj) : Monic (C^.id c) := Monic.show (Ξ» a f₁ fβ‚‚ Ο‰, by calc f₁ = ⟨⟨c⟩⟩ ∘∘ f₁ : eq.symm C^.circ_id_left ... = ⟨⟨c⟩⟩ ∘∘ fβ‚‚ : Ο‰ ... = fβ‚‚ : C^.circ_id_left) /-! #brief Monics are closed under composition. -/ instance Monic.circ {C : Cat.{β„“obj β„“hom}} {x y z : C^.obj} {g : C^.hom y z} [g_Monic : Monic g] {f : C^.hom x y} [f_Monic : Monic f] : Monic (C^.circ g f) := Monic.show (Ξ» c f₁ fβ‚‚ Ο‰ , begin apply monic_cancel f, apply monic_cancel g, repeat { rw C^.circ_assoc }, exact Ο‰ end) /-! #brief In LeanCat, monics are injective. -/ theorem LeanCat.Monic.inj {X Y : LeanCat.{β„“}^.obj} {f : LeanCat.{β„“}^.hom X Y} (f_Monic : @Monic LeanCat.{β„“} X Y f) : function.injective f := Ξ» x₁ xβ‚‚ Ο‰x , let f₁ : X β†’ X := Ξ» x, x₁ in let fβ‚‚ : X β†’ X := Ξ» x, xβ‚‚ in let Ο‰f : f₁ = fβ‚‚ := begin apply @Monic.inj LeanCat.{β„“} X Y f, apply funext, intro x, exact Ο‰x end in calc x₁ = f₁ x₁ : rfl ... = fβ‚‚ x₁ : by rw Ο‰f ... = xβ‚‚ : rfl /-! #brief In LeanCat, left-inverses witness monics. -/ definition LeanCat.Monic.by_witness {X Y : Type β„“} {f : X β†’ Y} {g : Y β†’ X} (Ο‰fg : βˆ€ {x : X}, g (f x) = x) : @Monic LeanCat.{β„“} X Y f := Monic.show (Ξ» T f₁ fβ‚‚ Ο‰ , sorry) /-! #brief An epimorphism. -/ @[class] definition Epic {C : Cat.{β„“obj β„“hom}} {x y : C^.obj} (f : C^.hom x y) : Prop := @Monic (OpCat C) y x f /-! #brief Helper for showing a hom is epic. -/ definition Epic.show {C : Cat.{β„“obj β„“hom}} {x y : C^.obj} {f : C^.hom x y} (Ο‰ : βˆ€ {z : C^.obj} (g₁ gβ‚‚ : C^.hom y z) (Ο‰g : C^.circ g₁ f = C^.circ gβ‚‚ f), g₁ = gβ‚‚) : Epic f := Monic.show @Ο‰ /-! #brief Using an epic. -/ definition epic_cancel {C : Cat.{β„“obj β„“hom}} {x y : C^.obj} (f : C^.hom x y) [f_Epic : Epic f] {z : C^.obj} {g₁ gβ‚‚ : C^.hom y z} (Ο‰ : C^.circ g₁ f = C^.circ gβ‚‚ f) : g₁ = gβ‚‚ := @Monic.inj (OpCat C) _ _ f f_Epic z g₁ gβ‚‚ Ο‰ /-! #brief Identity homs are epic. -/ instance Cat.id.Epic {C : Cat.{β„“obj β„“hom}} (c : C^.obj) : Epic (C^.id c) := Epic.show (Ξ» z g₁ gβ‚‚ Ο‰, by calc g₁ = g₁ ∘∘ ⟨⟨c⟩⟩ : eq.symm C^.circ_id_right ... = gβ‚‚ ∘∘ ⟨⟨c⟩⟩ : Ο‰ ... = gβ‚‚ : C^.circ_id_right) /-! #brief Epics are closed under composition. -/ instance Epic.circ {C : Cat.{β„“obj β„“hom}} {x y z : C^.obj} {g : C^.hom y z} [g_Epic : Epic g] {f : C^.hom x y} [f_Epic : Epic f] : Epic (C^.circ g f) := Epic.show (Ξ» c f₁ fβ‚‚ Ο‰ , begin apply epic_cancel g, apply epic_cancel f, repeat { rw -C^.circ_assoc }, exact Ο‰ end) /- ----------------------------------------------------------------------- Casting homs. ----------------------------------------------------------------------- -/ /-! #brief A casting hom. -/ definition cast_hom {C : Cat.{β„“obj β„“hom}} : βˆ€ {c₁ cβ‚‚ : C^.obj} (Ο‰ : c₁ = cβ‚‚) , C^.hom c₁ cβ‚‚ | c .(c) (eq.refl .(c)) := C^.id c /-! #brief Casting homs are just identities. -/ theorem cast_hom.simp {C : Cat.{β„“obj β„“hom}} : βˆ€ {c : C^.obj} (Ο‰ : c = c) , cast_hom Ο‰ = C^.id c | c (eq.refl .(c)) := rfl /-! #brief composition of casting homs. -/ theorem cast_hom.circ {C : Cat.{β„“obj β„“hom}} : βˆ€ {c₁ cβ‚‚ c₃ : C^.obj} {ω₁₂ : c₁ = cβ‚‚} {ω₂₃ : cβ‚‚ = c₃} , C^.circ (cast_hom ω₂₃) (cast_hom ω₁₂) = cast_hom (eq.trans ω₁₂ ω₂₃) | c .(c) .(c) (eq.refl .(c)) (eq.refl .(c)) := C^.circ_id_left /-! #brief Left congruence of composition with casting homs. -/ theorem cast_hom.circ.congr_left {C : Cat.{β„“obj β„“hom}} : βˆ€ {b c₁ cβ‚‚ d : C^.obj} {ω₁ : b = c₁} {Ο‰β‚‚ : b = cβ‚‚} {g₁ : C^.hom c₁ d} {gβ‚‚ : C^.hom cβ‚‚ d} (Ο‰g : g₁ == gβ‚‚) , C^.circ g₁ (cast_hom ω₁) = C^.circ gβ‚‚ (cast_hom Ο‰β‚‚) | b .(b) .(b) d (eq.refl .(b)) (eq.refl .(b)) g .(g) (heq.refl .(g)) := rfl /-! #brief Right congruence of composition with casting homs. -/ theorem cast_hom.circ.congr_right {C : Cat.{β„“obj β„“hom}} : βˆ€ {b c₁ cβ‚‚ d : C^.obj} {ω₁ : c₁ = d} {Ο‰β‚‚ : cβ‚‚ = d} {f₁ : C^.hom b c₁} {fβ‚‚ : C^.hom b cβ‚‚} (Ο‰f : f₁ == fβ‚‚) , C^.circ (cast_hom ω₁) f₁ = C^.circ (cast_hom Ο‰β‚‚) fβ‚‚ | b c .(c) .(c) (eq.refl .(c)) (eq.refl .(c)) f .(f) (heq.refl .(f)) := rfl /-! #brief Casting homs and heq. -/ theorem cast_hom.circ_left_heq {C : Cat.{β„“obj β„“hom}} : βˆ€ {b c₁ cβ‚‚ : C^.obj} (Ο‰ : c₁ = cβ‚‚) (f : C^.hom b c₁) , C^.circ (cast_hom Ο‰) f == f | b c .(c) (eq.refl .(c)) f := heq_of_eq C^.circ_id_left /-! #brief Casting homs and heq. -/ theorem cast_hom.circ_right_heq {C : Cat.{β„“obj β„“hom}} : βˆ€ {c₁ cβ‚‚ d : C^.obj} (Ο‰ : c₁ = cβ‚‚) (g : C^.hom cβ‚‚ d) , C^.circ g (cast_hom Ο‰) == g | c .(c) d (eq.refl .(c)) g := heq_of_eq C^.circ_id_right /-! #brief Casting homs are isos. -/ theorem cast_hom.Iso {C : Cat.{β„“obj β„“hom}} : βˆ€ {c₁ cβ‚‚ : C^.obj} (ω₁₂ : c₁ = cβ‚‚) (ω₂₁ : cβ‚‚ = c₁) , Iso (cast_hom ω₁₂) (cast_hom ω₂₁) | c .(c) (eq.refl .(c)) (eq.refl .(c)) := Cat.id.Iso c /-! #brief Casting homs are monic. -/ instance cast_hom.Monic {C : Cat.{β„“obj β„“hom}} : βˆ€ {c₁ cβ‚‚ : C^.obj} (Ο‰ : c₁ = cβ‚‚) , Monic (cast_hom Ο‰) | c .(c) (eq.refl .(c)) := Cat.id.Monic c /-! #brief Casting homs are epic. -/ instance cast_hom.Epic {C : Cat.{β„“obj β„“hom}} : βˆ€ {c₁ cβ‚‚ : C^.obj} (Ο‰ : c₁ = cβ‚‚) , Epic (cast_hom Ο‰) | c .(c) (eq.refl .(c)) := Cat.id.Epic c /- ----------------------------------------------------------------------- Initial and final objects in categories. ----------------------------------------------------------------------- -/ /-! #brief A final object in a category. -/ structure IsFinal (C : Cat.{β„“obj β„“hom}) (obj : C^.obj) (hom : βˆ€ (c : C^.obj), C^.hom c obj) : Type (max β„“obj β„“hom) := (hom_uniq : βˆ€ {c : C^.obj} {h : C^.hom c obj}, h = hom c) /-! #brief A category with a final object. -/ class HasFinal (C : Cat.{β„“obj β„“hom}) : Type (max β„“obj β„“hom) := (obj : C^.obj) (hom : βˆ€ (c : C^.obj), C^.hom c obj) (final : IsFinal C obj hom) /-! #brief Helper for showing a category has a final object. -/ definition HasFinal.show {C : Cat.{β„“obj β„“hom}} (x : C^.obj) (hom : βˆ€ (c : C^.obj), C^.hom c x) (hom_uniq : βˆ€ {c : C^.obj} {h : C^.hom c x}, h = hom c) : HasFinal C := { obj := x , hom := hom , final := { hom_uniq := @hom_uniq } } /-! #brief The final object in a category with a final object. -/ definition final (C : Cat.{β„“obj β„“hom}) [C_HasFinal : HasFinal C] : C^.obj := HasFinal.obj C /-! #brief The final hom in a category with a final object. -/ definition final_hom {C : Cat.{β„“obj β„“hom}} [C_HasFinal : HasFinal C] (c : C^.obj) : C^.hom c (final C) := HasFinal.hom c /-! #brief The final hom is unique. -/ theorem final_hom.uniq (C : Cat.{β„“obj β„“hom}) {C_HasFinal : HasFinal C} {c : C^.obj} {f : C^.hom c (final C)} : f = final_hom c := (HasFinal.final C)^.hom_uniq /-! #brief The initial hom is unique. -/ definition final_hom.uniq' (C : Cat.{β„“obj β„“hom}) {C_HasFinal : HasFinal C} {c : C^.obj} {f g : C^.hom c (final C)} : f = g := eq.trans (final_hom.uniq C) (eq.symm (final_hom.uniq C)) /-! #brief The final hom to the final object is the identity. -/ theorem final_hom.id (C : Cat.{β„“obj β„“hom}) {C_HasFinal : HasFinal C} : final_hom (final C) = C^.id (final C) := eq.symm (final_hom.uniq C) /-! #brief The unique iso between two final objects. -/ definition final.iso {C : Cat.{β„“obj β„“hom}} (C_HasFinal₁ C_HasFinalβ‚‚ : HasFinal C) : C^.hom (@final C C_HasFinal₁) (@final C C_HasFinalβ‚‚) := @final_hom C C_HasFinalβ‚‚ (@final C C_HasFinal₁) /-! #brief Final objects are unique up-to unique isomorphism. -/ theorem HasFinal_uniq {C : Cat.{β„“obj β„“hom}} (C_HasFinal₁ C_HasFinalβ‚‚ : HasFinal C) : Iso (final.iso C_HasFinal₁ C_HasFinalβ‚‚) (final.iso C_HasFinalβ‚‚ C_HasFinal₁) := { id₁ := eq.trans (@final_hom.uniq _ C_HasFinal₁ _ _) (eq.symm (@final_hom.uniq _ C_HasFinal₁ _ _)) , idβ‚‚ := eq.trans (@final_hom.uniq _ C_HasFinalβ‚‚ _ _) (eq.symm (@final_hom.uniq _ C_HasFinalβ‚‚ _ _)) } /-! #brief Final objects are unique up-to unique isomorphism. -/ theorem HasFinal_uniq₁ {C : Cat.{β„“obj β„“hom}} (C_HasFinal₁ C_HasFinalβ‚‚ : HasFinal C) {f : C^.hom (@final _ C_HasFinalβ‚‚) (@final _ C_HasFinal₁)} {g : C^.hom (@final _ C_HasFinal₁) (@final _ C_HasFinalβ‚‚)} (iso : Iso f g) : f = final.iso C_HasFinalβ‚‚ C_HasFinal₁ := @final_hom.uniq _ C_HasFinal₁ _ _ /-! #brief Final objects are unique up-to unique isomorphism. -/ theorem HasFinal_uniqβ‚‚ {C : Cat.{β„“obj β„“hom}} (C_HasFinal₁ C_HasFinalβ‚‚ : HasFinal C) {f : C^.hom (@final _ C_HasFinalβ‚‚) (@final _ C_HasFinal₁)} {g : C^.hom (@final _ C_HasFinal₁) (@final _ C_HasFinalβ‚‚)} (iso : Iso f g) : g = final.iso C_HasFinal₁ C_HasFinalβ‚‚ := @final_hom.uniq _ C_HasFinalβ‚‚ _ _ /-! #brief An initial object in a category. -/ definition IsInit (C : Cat.{β„“obj β„“hom}) (obj : C^.obj) (hom : βˆ€ (c : C^.obj), C^.hom obj c) : Type (max β„“obj β„“hom) := IsFinal (OpCat C) obj hom /-! #brief A category with an initial object. -/ @[class] definition HasInit (C : Cat.{β„“obj β„“hom}) : Type (max β„“obj β„“hom) := HasFinal (OpCat C) /-! #brief Helper for showing a category has a final object. -/ definition HasInit.show {C : Cat.{β„“obj β„“hom}} (x : C^.obj) (hom : βˆ€ (c : C^.obj), C^.hom x c) (hom_uniq : βˆ€ {c : C^.obj} {h : C^.hom x c}, h = hom c) : HasInit C := HasFinal.show x hom @hom_uniq /-! #brief The initial object in a category with a initial object. -/ definition init (C : Cat.{β„“obj β„“hom}) [C_HasInit : HasInit C] : C^.obj := @final (OpCat C) C_HasInit /-! #brief The initial hom in a category with a initial object. -/ definition init_hom {C : Cat.{β„“obj β„“hom}} [C_HasInit : HasInit C] (c : C^.obj) : C^.hom (init C) c := @final_hom (OpCat C) C_HasInit c /-! #brief The initial hom is unique. -/ definition init_hom.uniq (C : Cat.{β„“obj β„“hom}) {C_HasInit : HasInit C} {c : C^.obj} {f : C^.hom (init C) c} : f = init_hom c := @final_hom.uniq (OpCat C) C_HasInit c f /-! #brief The initial hom is unique. -/ definition init_hom.uniq' (C : Cat.{β„“obj β„“hom}) {C_HasInit : HasInit C} {c : C^.obj} {f g : C^.hom (init C) c} : f = g := eq.trans (init_hom.uniq C) (eq.symm (init_hom.uniq C)) /-! #brief The unique iso between two initial objects. -/ definition init.iso {C : Cat.{β„“obj β„“hom}} (C_HasInit₁ C_HasInitβ‚‚ : HasInit C) : C^.hom (@init C C_HasInit₁) (@init C C_HasInitβ‚‚) := @init_hom C C_HasInit₁ (@init C C_HasInitβ‚‚) /-! #brief Initial objects are unique up-to unique isomorphism. -/ theorem HasInit_uniq {C : Cat.{β„“obj β„“hom}} (C_HasInit₁ C_HasInitβ‚‚ : HasInit C) : Iso (init.iso C_HasInit₁ C_HasInitβ‚‚) (init.iso C_HasInitβ‚‚ C_HasInit₁) := { id₁ := eq.trans (@init_hom.uniq _ C_HasInit₁ _ _) (eq.symm (@init_hom.uniq _ C_HasInit₁ _ _)) , idβ‚‚ := eq.trans (@init_hom.uniq _ C_HasInitβ‚‚ _ _) (eq.symm (@init_hom.uniq _ C_HasInitβ‚‚ _ _)) } /-! #brief Initial and final are dual concepts. -/ theorem IsInit_dual_IsFinal (C : Cat.{β„“obj β„“hom}) : IsInit C = IsFinal (OpCat C) := rfl /-! #brief Final and initial are dual concepts. -/ theorem IsFinal_dual_IsInit (C : Cat.{β„“obj β„“hom}) : IsFinal C = IsInit (OpCat C) := funext (Ξ» obj, funext (Ξ» hom, begin cases C, trivial end)) /- ----------------------------------------------------------------------- Examples of initial and final objects in categories. ----------------------------------------------------------------------- -/ /-! #brief OverCat has an initial object when the global category does. -/ instance OverCat.HasInit (C : Cat.{β„“obj β„“hom}) (X : C^.obj) [C_HasInit : HasInit C] : HasInit (OverCat C X) := HasInit.show { obj := init C, hom := init_hom X } (Ξ» Y, { hom := init_hom Y^.obj, triangle := init_hom.uniq' C }) (Ξ» Y h, OverHom.eq (init_hom.uniq C)) /-! #brief OverCat has a final object. -/ instance OverCat.HasFinal (C : Cat.{β„“obj β„“hom}) (X : C^.obj) : HasFinal (OverCat C X) := HasFinal.show { obj := X, hom := C^.id X } (Ξ» Z, { hom := Z^.hom, triangle := eq.symm C^.circ_id_left }) (Ξ» Z h, OverHom.eq (eq.symm (eq.trans h^.triangle C^.circ_id_left ))) /-! #brief UnitCat has an initial object. -/ instance UnitCat.HasInit : HasInit UnitCat.{β„“obj β„“hom} := HasInit.show punit.star (Ξ» c, punit.star) (Ξ» c h, begin cases h, trivial end) /-! #brief UnitCat has a final object. -/ instance UnitCat.HasFinal : HasFinal UnitCat.{β„“obj β„“hom} := HasFinal.show punit.star (Ξ» c, punit.star) (Ξ» c h, begin cases h, trivial end) /-! #brief SortCat has an initial object. -/ instance SortCat.HasInit : HasInit SortCat.{β„“} := HasInit.show pempty (Ξ» T e, by cases e) (Ξ» c h, funext (Ξ» e, by cases e)) /-! #brief PropCat has an initial object. -/ instance PropCat.HasInit : HasInit PropCat := SortCat.HasInit /-! #brief LeanCat has an initial object. -/ instance LeanCat.HasInit : HasInit LeanCat.{β„“} := SortCat.HasInit /-! #brief Initial objects in LeanCat are uninhabited. -/ theorem LeanCat.Init.elim [LeanCat_HasInit : HasInit LeanCat.{β„“}] (e : init LeanCat.{β„“}) : false := by cases (init.iso LeanCat_HasInit LeanCat.HasInit e) /-! #brief SortCat has a final object. -/ instance SortCat.HasFinal : HasFinal SortCat.{β„“} := HasFinal.show punit (Ξ» T t, punit.star) (Ξ» c h, funext (Ξ» t, begin cases (h t), trivial end)) /-! #brief PropCat has a final object. -/ instance PropCat.HasFinal : HasFinal PropCat := SortCat.HasFinal /-! #brief LeanCat has a final object. -/ instance LeanCat.HasFinal : HasFinal LeanCat.{β„“} := SortCat.HasFinal /-! #brief Final objects in LeanCat are uniquely inhabited. -/ definition LeanCat.Final.intro [LeanCat_HasFinal : HasFinal LeanCat.{β„“}] : final LeanCat.{β„“} := final.iso LeanCat.HasFinal LeanCat_HasFinal punit.star /-! #brief Final objects in LeanCat are uniquely. -/ theorem LeanCat.Final.uniq {LeanCat_HasFinal : HasFinal LeanCat.{β„“}} {u₁ uβ‚‚ : final LeanCat.{β„“}} : u₁ = uβ‚‚ := let f₁ : LeanCat.{β„“}^.hom punit (final LeanCat.{β„“}) := Ξ» u, u₁ in let fβ‚‚ : LeanCat.{β„“}^.hom punit (final LeanCat.{β„“}) := Ξ» u, uβ‚‚ in let Ο‰f : f₁ = fβ‚‚ := by calc f₁ = @final_hom _ LeanCat_HasFinal punit : @final_hom.uniq _ LeanCat_HasFinal _ f₁ ... = fβ‚‚ : eq.symm (@final_hom.uniq _ LeanCat_HasFinal _ fβ‚‚) in by calc u₁ = f₁ punit.star : rfl ... = fβ‚‚ punit.star : by rw Ο‰f ... = uβ‚‚ : rfl /-! #brief The category of natural numbers has an initial object. -/ instance NatCat.HasInit :HasInit NatCat := HasInit.show nat.zero nat.zero_le (Ξ» c h, proof_irrel _ _) end qp
lemma monom_eq_1 [simp]: "monom 1 0 = 1"
(* * Copyright 2014, NICTA * * This software may be distributed and modified according to the terms of * the BSD 2-Clause license. Note that NO WARRANTY is provided. * See "LICENSE_BSD2.txt" for details. * * @TAG(NICTA_BSD) *) theory ptr_modifies imports "Word_Lib.WordSetup" "CParser.CTranslation" begin external_file "ptr_modifies.c" install_C_file "ptr_modifies.c" context ptr_modifies begin thm foo_ptr_new_modifies thm f_modifies thm f_body_def thm g_modifies thm h_modifies end lemma (in f_spec) g_spec: "\<forall> i. \<Gamma> \<turnstile> \<lbrace> \<acute>i = i \<rbrace> \<acute>ret__unsigned :== CALL g(\<acute>i) \<lbrace> \<acute>ret__unsigned = i + 4 \<rbrace>" apply vcg apply simp done end
import data.real.irrational import topology.basic import algebra.order.floor --OUTPUT 1 theorem irrational_orbit_dense {Ξ± : ℝ} (hΞ±_irrat : irrational Ξ±) : closure ((Ξ» m : β„€, int.fract (Ξ± * ↑m)) '' (@set.univ β„€)) = set.Icc 0 1 :=density_of_irrational_orbit (Ξ± : ℝ) (hΞ± : Β¬ is_rat Ξ±) : βˆ€ y ∈ Icc 0 1, βˆƒ x ∈ Icc 0 1, x β‰  y := begin assume y h1, have h2 : βˆ€ i j : β„€, i β‰  j β†’ (i : ℝ) * Ξ± - (i : ℝ) β‰  (j : ℝ) * Ξ± - (j : ℝ), from by { assume i j h3, assume h4 : (i : ℝ) * Ξ± - (i : ℝ) = (j : ℝ) * Ξ± - (j : ℝ), have h5 : (i : ℝ) * Ξ± = (j : ℝ) * Ξ±, from by { rw ← h4, ring, }, have h6 : (i : ℝ) = (j : ℝ), from by { rw ← h5, rw ← mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ), rw mul_assoc, rw mul_comm Ξ± (j : ℝ), rw mul_assoc, rw mul_comm Ξ± (i : ℝ end --Needs more than 2000 tokens! /- FEW SHOT PROMPTS TO CODEX(START) /--`theorem` Power Set is Closed under Intersection Let $S$ be a set. Let $\powerset S$ be the power set of $S$. Then: :$\forall A, B \in \powerset S: A \cap B \in \powerset S$ `proof` Let $A, B \in \powerset S$. Then by the definition of power set, $A \subseteq S$ and $B \subseteq S$. From Intersection is Subset we have that $A \cap B \subseteq A$. It follows from Subset Relation is Transitive that $A \cap B \subseteq S$. Thus $A \cap B \in \powerset S$ and closure is proved. {{qed}} -/ theorem power_set_intersection_closed {Ξ± : Type*} (S : set Ξ±) : βˆ€ A B ∈ 𝒫 S, (A ∩ B) ∈ 𝒫 S := begin assume (A : set Ξ±) (hA : A ∈ 𝒫 S) (B : set Ξ±) (hB : B ∈ 𝒫 S), have h1 : (A βŠ† S) ∧ (B βŠ† S), from by {split,apply set.subset_of_mem_powerset,exact hA,apply set.subset_of_mem_powerset,exact hB}, have h2 : (A ∩ B) βŠ† A, from by apply set.inter_subset_left, have h3 : (A ∩ B) βŠ† S, from by {apply set.subset.trans h2 h1.left}, show (A ∩ B) ∈ 𝒫 S, from by {apply set.mem_powerset h3}, end /--`theorem` Square of Sum :$\forall x, y \in \R: \paren {x + y}^2 = x^2 + 2 x y + y^2$ `proof` Follows from the distribution of multiplication over addition: {{begin-eqn}} {{eqn | l = \left({x + y}\right)^2 | r = \left({x + y}\right) \cdot \left({x + y}\right) }} {{eqn | r = x \cdot \left({x + y}\right) + y \cdot \left({x + y}\right) | c = Real Multiplication Distributes over Addition }} {{eqn | r = x \cdot x + x \cdot y + y \cdot x + y \cdot y | c = Real Multiplication Distributes over Addition }} {{eqn | r = x^2 + 2xy + y^2 | c = }} {{end-eqn}} {{qed}} -/ theorem square_of_sum (x y : ℝ) : (x + y)^2 = (x^2 + 2*x*y + y^2) := begin calc (x + y)^2 = (x+y)*(x+y) : by rw sq ... = x*(x+y) + y*(x+y) : by rw add_mul ... = x*x + x*y + y*x + y*y : by {rw [mul_comm x (x+y),mul_comm y (x+y)], rw [add_mul,add_mul], ring} ... = x^2 + 2*x*y + y^2 : by {repeat {rw ← sq}, rw mul_comm y x, ring} end /--`theorem` Identity of Group is Unique Let $\struct {G, \circ}$ be a group. Then there is a unique identity element $e \in G$. `proof` From Group has Latin Square Property, there exists a unique $x \in G$ such that: :$a x = b$ and there exists a unique $y \in G$ such that: :$y a = b$ Setting $b = a$, this becomes: There exists a unique $x \in G$ such that: :$a x = a$ and there exists a unique $y \in G$ such that: :$y a = a$ These $x$ and $y$ are both $e$, by definition of identity element. {{qed}} -/ theorem group_identity_unique {G : Type*} [group G] : βˆƒ! e : G, βˆ€ a : G, e * a = a ∧ a * e = a := begin have h1 : βˆ€ a b : G, βˆƒ! x : G, a * x = b, from by { assume a b : G, use a⁻¹ * b, obviously, }, have h2 : βˆ€ a b : G, βˆƒ! y : G, y * a = b, from by { assume a b : G, use b * a⁻¹, obviously, }, have h3 : βˆ€ a : G, βˆƒ! x : G, a * x = a, from assume a : G, h1 a a, have h4 : βˆ€ a : G, βˆƒ! y : G, y * a = a, from assume a : G, h2 a a, have h5 : βˆ€ a : G, classical.some (h3 a).exists = (1 : G), from assume a :G, exists_unique.unique (h3 a) (classical.some_spec (exists_unique.exists (h3 a))) (mul_one a), have h6 : βˆ€ a : G, classical.some (h4 a).exists = (1 : G), from assume a : G, exists_unique.unique (h4 a) (classical.some_spec (exists_unique.exists (h4 a))) (one_mul a), show βˆƒ! e : G, βˆ€ a : G, e * a = a ∧ a * e = a, from by { use (1 : G), have h7 : βˆ€ e : G, (βˆ€ a : G, e * a = a ∧ a * e = a) β†’ e = 1, from by { assume (e : G) (hident : βˆ€ a : G, e * a = a ∧ a * e = a), have h8 : βˆ€ a : G, e = classical.some (h3 a).exists, from assume (a : G), exists_unique.unique (h3 a) (hident a).right (classical.some_spec (exists_unique.exists (h3 a))), have h9 : βˆ€ a : G, e = classical.some (h4 a).exists, from assume (a : G), exists_unique.unique (h4 a) (hident a).left (classical.some_spec (exists_unique.exists (h4 a))), show e = (1 : G), from eq.trans (h9 e) (h6 _), }, exact ⟨by obviously, h7⟩, } end /--`theorem` Squeeze Theorem for Real Numbers Let $\sequence {x_n}$, $\sequence {y_n}$ and $\sequence {z_n}$ be sequences in $\R$. Let $\sequence {y_n}$ and $\sequence {z_n}$ both be convergent to the following limit: :$\ds \lim_{n \mathop \to \infty} y_n = l, \lim_{n \mathop \to \infty} z_n = l$ Suppose that: :$\forall n \in \N: y_n \le x_n \le z_n$ Then: :$x_n \to l$ as $n \to \infty$ that is: :$\ds \lim_{n \mathop \to \infty} x_n = l$ `proof` From Negative of Absolute Value: :$\size {x - l} < \epsilon \iff l - \epsilon < x < l + \epsilon$ Let $\epsilon > 0$. We need to prove that: :$\exists N: \forall n > N: \size {x_n - l} < \epsilon$ As $\ds \lim_{n \mathop \to \infty} y_n = l$ we know that: :$\exists N_1: \forall n > N_1: \size {y_n - l} < \epsilon$ As $\ds \lim_{n \mathop \to \infty} z_n = l$ we know that: :$\exists N_2: \forall n > N_2: \size {z_n - l} < \epsilon$ Let $N = \max \set {N_1, N_2}$. Then if $n > N$, it follows that $n > N_1$ and $n > N_2$. So: :$\forall n > N: l - \epsilon < y_n < l + \epsilon$ :$\forall n > N: l - \epsilon < z_n < l + \epsilon$ But: :$\forall n \in \N: y_n \le x_n \le z_n$ So: :$\forall n > N: l - \epsilon < y_n \le x_n \le z_n < l + \epsilon$ and so: :$\forall n > N: l - \epsilon < x_n < l + \epsilon$ So: :$\forall n > N: \size {x_n - l} < \epsilon$ Hence the result. {{qed}} -/ theorem squeeze_theorem_real_numbers (x y z : β„• β†’ ℝ) (l : ℝ) : let seq_limit : (β„• β†’ ℝ) β†’ ℝ β†’ Prop := Ξ» (u : β„• β†’ ℝ) (l : ℝ), βˆ€ Ξ΅ > 0, βˆƒ N, βˆ€ n > N, |u n - l| < Ξ΅ in seq_limit y l β†’ seq_limit z l β†’ (βˆ€ n : β„•, (y n) ≀ (x n) ∧ (x n) ≀ (z n)) β†’ seq_limit x l := begin assume seq_limit (h2 : seq_limit y l) (h3 : seq_limit z l) (h4 : βˆ€ (n : β„•), y n ≀ x n ∧ x n ≀ z n) (Ξ΅), have h5 : βˆ€ x, |x - l| < Ξ΅ ↔ (((l - Ξ΅) < x) ∧ (x < (l + Ξ΅))), from by { intro x0, have h6 : |x0 - l| < Ξ΅ ↔ ((x0 - l) < Ξ΅) ∧ ((l - x0) < Ξ΅), from abs_sub_lt_iff, rw h6, split, rintro ⟨ S_1, S_2 ⟩, split; linarith, rintro ⟨ S_3, S_4 ⟩, split; linarith, }, assume (h7 : Ξ΅ > 0), cases h2 Ξ΅ h7 with N1 h8, cases h3 Ξ΅ h7 with N2 h9, let N := max N1 N2, use N, have h10 : βˆ€ n > N, n > N1 ∧ n > N2 := by { assume n h, split, exact lt_of_le_of_lt (le_max_left N1 N2) h, exact lt_of_le_of_lt (le_max_right N1 N2) h, }, have h11 : βˆ€ n > N, (((l - Ξ΅) < (y n)) ∧ ((y n) ≀ (x n))) ∧ (((x n) ≀ (z n)) ∧ ((z n) < l+Ξ΅)), from by { intros n h12, split, { have h13 := (h8 n (h10 n h12).left), rw h5 (y n) at h13, split, exact h13.left, exact (h4 n).left, }, { have h14 := (h9 n (h10 n h12).right),rw h5 (z n) at h14, split, exact (h4 n).right, exact h14.right, }, }, have h15 : βˆ€ n > N, ((l - Ξ΅) < (x n)) ∧ ((x n) < (l+Ξ΅)), from by { intros n1 h16, cases (h11 n1 h16); split; linarith, }, show βˆ€ (n : β„•), n > N β†’ |x n - l| < Ξ΅, from by { intros n h17, cases h5 (x n) with h18 h19, apply h19, exact h15 n h17, }, end /--`theorem` Density of irrational orbit The fractional parts of the integer multiples of an irrational number form a dense subset of the unit interval `proof` Let $\alpha$ be an irrational number. Then for distinct $i, j \in \mathbb{Z}$, we must have $\{i \alpha\} \neq\{j \alpha\}$. If this were not true, then $$ i \alpha-\lfloor i \alpha\rfloor=\{i \alpha\}=\{j \alpha\}=j \alpha-\lfloor j \alpha\rfloor, $$ which yields the false statement $\alpha=\frac{\lfloor i \alpha\rfloor-\lfloor j \alpha\rfloor}{i-j} \in \mathbb{Q}$. Hence, $$ S:=\{\{i \alpha\} \mid i \in \mathbb{Z}\} $$ is an infinite subset of $\left[0,1\right]$. By the Bolzano-Weierstrass theorem, $S$ has a limit point in $[0, 1]$. One can thus find pairs of elements of $S$ that are arbitrarily close. Since (the absolute value of) the difference of any two elements of $S$ is also an element of $S$, it follows that $0$ is a limit point of $S$. To show that $S$ is dense in $[0, 1]$, consider $y \in[0,1]$, and $\epsilon>0$. Then by selecting $x \in S$ such that $\{x\}<\epsilon$ (which exists as $0$ is a limit point), and $N$ such that $N \cdot\{x\} \leq y<(N+1) \cdot\{x\}$, we get: $|y-\{N x\}|<\epsilon$. QED -/ theorem FEW SHOT PROMPTS TO CODEX(END)-/
def s1 := "Hello, " def s2 := "Nifty!" def s3 := s1 ++ s2 theorem t1 : s1 ++ s2 = s3 := _ theorem t2 : 4^2 = 16 := _ theorem t3 : s1 ++ s2 = s3 ∧ 5^2 = 25 := _ theorem t4 : βˆ€ (P Q R : Prop), (P ∧ Q) ∧ (Q ∧ R) β†’ (P ∧ R) := Ξ» (P Q R : Prop), and.intro _ _
import algebra.module.basic import algebra.module.linear_map import linear_algebra.basic import linear_algebra.prod import linear_algebra.projection import order.bounded_lattice theorem cpge_reduction_3_a (R : Type*) (M : Type*) [semiring R] [add_comm_monoid M] [module R M] [E : submodule R M] (u : linear_map R E E) (v : linear_map R E E) : (u.comp v) = (v.comp u) -> v '' u.ker βŠ‚ u.ker ∧ u '' v.ker βŠ‚ v.ker := sorry
import data.real.basic #check sub_self #check abs_zero def converges_to (s : β„• β†’ ℝ) (a : ℝ) := βˆ€ Ξ΅ > 0, βˆƒ N, βˆ€ n β‰₯ N, abs (s n - a) < Ξ΅ theorem converges_to_const (a : ℝ) : converges_to (Ξ» x : β„•, a) a := begin intros Ξ΅ epos, dsimp, rw sub_self, norm_num, use 0, intros n nge, exact epos, end example (a : ℝ) : converges_to (Ξ» x : β„•, a) a := begin intros Ξ΅ epos, use 0, intros n nge, dsimp, rw sub_self, rw abs_zero, apply epos, end
/- Copyright (c) 2021 Sara DΓ­az Real. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sara DΓ­az Real -/ import data.int.basic import algebra.associated import tactic.linarith import tactic.ring /-! # IMO 2001 Q6 Let $a$, $b$, $c$, $d$ be integers with $a > b > c > d > 0$. Suppose that $$ a*c + b*d = (a + b - c + d) * (-a + b + c + d). $$ Prove that $a*b + c*d$ is not prime. -/ variables {a b c d : β„€} theorem imo2001_q6 (hd : 0 < d) (hdc : d < c) (hcb : c < b) (hba : b < a) (h : a*c + b*d = (a + b - c + d) * (-a + b + c + d)) : Β¬ prime (a*b + c*d) := begin assume h0 : prime (a*b + c*d), have ha : 0 < a, { linarith }, have hb : 0 < b, { linarith }, have hc : 0 < c, { linarith }, -- the key step is to show that `a*c + b*d` divides the product `(a*b + c*d) * (a*d + b*c)` have dvd_mul : a*c + b*d ∣ (a*b + c*d) * (a*d + b*c), { use b^2 + b*d + d^2, have equivalent_sums : a^2 - a*c + c^2 = b^2 + b*d + d^2, { ring_nf at h, nlinarith only [h], }, calc (a * b + c * d) * (a * d + b * c) = a*c * (b^2 + b*d + d^2) + b*d * (a^2 - a*c + c^2) : by ring ... = a*c * (b^2 + b*d + d^2) + b*d * (b^2 + b*d + d^2) : by rw equivalent_sums ... = (a * c + b * d) * (b ^ 2 + b * d + d ^ 2) : by ring, }, -- since `a*b + c*d` is prime (by assumption), it must divide `a*c + b*d` or `a*d + b*c` obtain (h1 : a*b + c*d ∣ a*c + b*d) | (h2 : a*c + b*d ∣ a*d + b*c) := h0.left_dvd_or_dvd_right_of_dvd_mul dvd_mul, -- in both cases, we derive a contradiction { have aux : 0 < a*c + b*d, { nlinarith only [ha, hb, hc, hd] }, have : a*b + c*d ≀ a*c + b*d, { from int.le_of_dvd aux h1 }, have : Β¬ (a*b + c*d ≀ a*c + b*d), { nlinarith only [hba, hcb, hdc, h] }, contradiction, }, { have aux : 0 < a*d + b*c, { nlinarith only [ha, hb, hc, hd] }, have : a*c + b*d ≀ a*d + b*c, { from int.le_of_dvd aux h2 }, have : Β¬ (a*c + b*d ≀ a*d + b*c), { nlinarith only [hba, hdc, h] }, contradiction, }, end
////////////////////////////////////////////////////////////////////////////////////// // distribution::toolkit::distributions::chi_squared::description.hpp // // // // (C) Copyright 2009 Erwann Rogard // // Use, modification and distribution are subject to the // // Boost Software License, Version 1.0. (See accompanying file // // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // ////////////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_STATISTICS_DETAIL_DISTRIBUTION_TOOLKIT_CHI_SQUARED_DESCRIPTION_HPP_ER_2009 #define BOOST_STATISTICS_DETAIL_DISTRIBUTION_TOOLKIT_CHI_SQUARED_DESCRIPTION_HPP_ER_2009 #include <ostream> #include <boost/format.hpp> #include <boost/math/distributions/chi_squared.hpp> namespace boost{ namespace math{ template<typename T,typename P> std::string description(const boost::math::chi_squared_distribution<T,P>& dist) { static const char* msg = "chi_squared(%1%)"; format f(msg); f % dist.degrees_of_freedom(); return f.str(); } }// math }// boost #endif
informal statement Let $\Omega$ be a bounded open subset of $\mathbb{C}$, and $\varphi: \Omega \rightarrow \Omega$ a holomorphic function. Prove that if there exists a point $z_{0} \in \Omega$ such that $\varphi\left(z_{0}\right)=z_{0} \quad \text { and } \quad \varphi^{\prime}\left(z_{0}\right)=1$ then $\varphi$ is linear.formal statement theorem exercise_3_3 (a : ℝ) (ha : 0 < a) : tendsto (Ξ» y, ∫ x in -y..y, real.cos x / (x ^ 2 + a ^ 2)) at_top (𝓝 (real.pi * (real.exp (-a) / a))) :=
/- Copyright (c) 2021 OpenAI. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f -/ import mathzoo.imports.miniF2F open_locale nat rat real big_operators topological_space theorem mathd_algebra_547 (x y : ℝ) (hβ‚€ : x = 5) (h₁ : y = 2) : real.sqrt (x^3 - 2^y) = 11 := begin simp [hβ‚€, h₁], norm_num [real.sqrt_eq_cases], end
class CommAddSemigroup (Ξ± : Type u) extends Add Ξ± where addComm : {a b : Ξ±} β†’ a + b = b + a addAssoc : {a b c : Ξ±} β†’ a + b + c = a + (b + c) open CommAddSemigroup theorem addComm3 [CommAddSemigroup Ξ±] {a b c : Ξ±} : a + b + c = a + c + b := by { have h : b + c = c + b := addComm; have h' := congrArg (a + Β·) h; simp at h'; rw [←addAssoc] at h'; rw [←addAssoc (a := a)] at h'; exact h'; } theorem addComm4 [CommAddSemigroup Ξ±] {a b c : Ξ±} : a + b + c = a + c + b := by { rw [addAssoc, addAssoc]; rw [addComm (a := b)]; } theorem addComm5 [CommAddSemigroup Ξ±] {a b c : Ξ±} : a + b + c = a + c + b := by { have h : b + c = c + b := addComm; have h' := congrArg (a + Β·) h; simp at h'; rw [←addAssoc] at h'; rw [←@addAssoc (a := a)] at h'; exact h'; } theorem addComm6 [CommAddSemigroup Ξ±] {a b c : Ξ±} : a + b + c = a + c + b := by { have h : b + c = c + b := addComm; have h' := congrArg (a + Β·) h; simp at h'; rw [←addAssoc] at h'; rw [←addAssoc] at h'; exact h'; }
import Smt theorem assoc (f : Prop β†’ Prop β†’ Prop) (p q r : Prop) : f p (f q r) = f (f p q) r := by smt admit
import data.set.basic variables {Ξ± : Type*} {Ξ² : Type*} [s : setoid Ξ±] namespace quotient lemma prod_preimage_eq_image (g : quotient s β†’ Ξ²) {h : Ξ± β†’ Ξ²} (Hh : h = g ∘ quotient.mk) (r : set (Ξ² Γ— Ξ²)) : {x : quotient s Γ— quotient s | (g x.1, g x.2) ∈ r} = (Ξ» a : Ξ± Γ— Ξ±, (⟦a.1⟧, ⟦a.2⟧)) '' ((Ξ» a : Ξ± Γ— Ξ±, (h a.1, h a.2)) ⁻¹' r) := Hh.symm β–Έ set.ext (Ξ» ⟨a₁, aβ‚‚βŸ©, ⟨quotient.induction_onβ‚‚ a₁ aβ‚‚ (Ξ» a₁ aβ‚‚ h, ⟨(a₁, aβ‚‚), h, rfl⟩), Ξ» ⟨⟨b₁, bβ‚‚βŸ©, h₁, hβ‚‚βŸ©, show (g a₁, g aβ‚‚) ∈ r, from have h₃ : ⟦bβ‚βŸ§ = a₁ ∧ ⟦bβ‚‚βŸ§ = aβ‚‚ := prod.ext_iff.1 hβ‚‚, h₃.1 β–Έ h₃.2 β–Έ hβ‚βŸ©) end quotient
import data.real.basic -- TODO: Move. lemma mul_Inf {K : ℝ} (hK : 0 ≀ K) {p : ℝ β†’ Prop} (h : βˆƒ x, 0 ≀ x ∧ p x) (hp : p (Inf {x | 0 ≀ x ∧ p x})) : K * Inf {x | 0 ≀ x ∧ p x} = Inf {y | βˆƒ x, (y : ℝ) = K * x ∧ 0 ≀ x ∧ p x} := begin rcases h with ⟨i, hnni, hpi⟩, let S := {y | βˆƒ x, y = K * x ∧ 0 ≀ x ∧ p x}, apply le_antisymm, { have h1 : (βˆƒ (x : ℝ), x ∈ S) := ⟨K * i, ⟨i, rfl, hnni, hpi⟩⟩, have h2 : (βˆƒ (x : ℝ), βˆ€ (y : ℝ), y ∈ S β†’ x ≀ y), { existsi (0 : ℝ), rintros y ⟨x, hy, hnnx, hpx⟩, rw hy, exact mul_nonneg hK hnnx, }, rw real.le_Inf S h1 h2, rintros z ⟨w, hz, hnnw, hpw⟩, rw hz, mono, { refine cInf_le _ ⟨hnnw, hpw⟩, use 0, intros a ha, exact ha.1, }, { apply le_cInf, { use [i, ⟨hnni, hpi⟩], }, { intros b hb, exact hb.1, }, }, }, { apply real.Inf_le, { use [0], intros y hy, rcases hy with ⟨x, ⟨hy, hnnx, hpx⟩⟩, rw hy, exact mul_nonneg hK hnnx, }, { use [Inf {x : ℝ | 0 ≀ x ∧ p x}], refine ⟨rfl, _, _⟩, { apply le_cInf, { use [i, ⟨hnni, hpi⟩], }, { intros b hb, exact hb.1, }, }, { exact hp, }, }, }, end
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Eric Wieser -/ import linear_algebra.span import linear_algebra.bilinear_map /-! # Images of pairs of submodules under bilinear maps > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file provides `submodule.mapβ‚‚`, which is later used to implement `submodule.has_mul`. ## Main results * `submodule.mapβ‚‚_eq_span_image2`: the image of two submodules under a bilinear map is the span of their `set.image2`. ## Notes This file is quite similar to the n-ary section of `data.set.basic` and to `order.filter.n_ary`. Please keep them in sync. -/ universes uΞΉ u v open set open_locale big_operators open_locale pointwise namespace submodule variables {ΞΉ : Sort uΞΉ} {R M N P : Type*} variables [comm_semiring R] [add_comm_monoid M] [add_comm_monoid N] [add_comm_monoid P] variables [module R M] [module R N] [module R P] /-- Map a pair of submodules under a bilinear map. This is the submodule version of `set.image2`. -/ def mapβ‚‚ (f : M β†’β‚—[R] N β†’β‚—[R] P) (p : submodule R M) (q : submodule R N) : submodule R P := ⨆ s : p, q.map $ f s theorem apply_mem_mapβ‚‚ (f : M β†’β‚—[R] N β†’β‚—[R] P) {m : M} {n : N} {p : submodule R M} {q : submodule R N} (hm : m ∈ p) (hn : n ∈ q) : f m n ∈ mapβ‚‚ f p q := (le_supr _ ⟨m, hm⟩ : _ ≀ mapβ‚‚ f p q) ⟨n, hn, rfl⟩ theorem mapβ‚‚_le {f : M β†’β‚—[R] N β†’β‚—[R] P} {p : submodule R M} {q : submodule R N} {r : submodule R P} : mapβ‚‚ f p q ≀ r ↔ βˆ€ (m ∈ p) (n ∈ q), f m n ∈ r := ⟨λ H m hm n hn, H $ apply_mem_mapβ‚‚ _ hm hn, Ξ» H, supr_le $ Ξ» ⟨m, hm⟩, map_le_iff_le_comap.2 $ Ξ» n hn, H m hm n hn⟩ variables R theorem mapβ‚‚_span_span (f : M β†’β‚—[R] N β†’β‚—[R] P) (s : set M) (t : set N) : mapβ‚‚ f (span R s) (span R t) = span R (set.image2 (Ξ» m n, f m n) s t) := begin apply le_antisymm, { rw mapβ‚‚_le, intros a ha b hb, apply span_induction ha, work_on_goal 1 { intros, apply span_induction hb, work_on_goal 1 { intros, exact subset_span ⟨_, _, β€Ή_β€Ί, β€Ή_β€Ί, rfl⟩ } }, all_goals { intros, simp only [linear_map.map_zero, linear_map.zero_apply, zero_mem, linear_map.map_add, linear_map.add_apply, linear_map.map_smul, linear_map.smul_apply] }, all_goals { solve_by_elim [add_mem _ _, zero_mem _, smul_mem _ _ _] { max_depth := 4, discharger := tactic.interactive.apply_instance } } }, { rw span_le, rintros _ ⟨a, b, ha, hb, rfl⟩, exact apply_mem_mapβ‚‚ _ (subset_span ha) (subset_span hb) } end variables {R} @[simp] theorem mapβ‚‚_bot_right (f : M β†’β‚—[R] N β†’β‚—[R] P) (p : submodule R M) : mapβ‚‚ f p βŠ₯ = βŠ₯ := eq_bot_iff.2 $ mapβ‚‚_le.2 $ Ξ» m hm n hn, by { rw [submodule.mem_bot] at hn ⊒, rw [hn, linear_map.map_zero] } @[simp] theorem mapβ‚‚_bot_left (f : M β†’β‚—[R] N β†’β‚—[R] P) (q : submodule R N) : mapβ‚‚ f βŠ₯ q = βŠ₯ := eq_bot_iff.2 $ mapβ‚‚_le.2 $ Ξ» m hm n hn, by { rw [submodule.mem_bot] at hm ⊒, rw [hm, linear_map.map_zeroβ‚‚] } @[mono] theorem mapβ‚‚_le_mapβ‚‚ {f : M β†’β‚—[R] N β†’β‚—[R] P} {p₁ pβ‚‚ : submodule R M} {q₁ qβ‚‚ : submodule R N} (hp : p₁ ≀ pβ‚‚) (hq : q₁ ≀ qβ‚‚) : mapβ‚‚ f p₁ q₁ ≀ mapβ‚‚ f pβ‚‚ qβ‚‚ := mapβ‚‚_le.2 $ Ξ» m hm n hn, apply_mem_mapβ‚‚ _ (hp hm) (hq hn) theorem mapβ‚‚_le_mapβ‚‚_left {f : M β†’β‚—[R] N β†’β‚—[R] P} {p₁ pβ‚‚ : submodule R M} {q : submodule R N} (h : p₁ ≀ pβ‚‚) : mapβ‚‚ f p₁ q ≀ mapβ‚‚ f pβ‚‚ q := mapβ‚‚_le_mapβ‚‚ h (le_refl q) theorem mapβ‚‚_le_mapβ‚‚_right {f : M β†’β‚—[R] N β†’β‚—[R] P} {p : submodule R M} {q₁ qβ‚‚ : submodule R N} (h : q₁ ≀ qβ‚‚): mapβ‚‚ f p q₁ ≀ mapβ‚‚ f p qβ‚‚ := mapβ‚‚_le_mapβ‚‚ (le_refl p) h theorem mapβ‚‚_sup_right (f : M β†’β‚—[R] N β†’β‚—[R] P) (p : submodule R M) (q₁ qβ‚‚ : submodule R N) : mapβ‚‚ f p (q₁ βŠ” qβ‚‚) = mapβ‚‚ f p q₁ βŠ” mapβ‚‚ f p qβ‚‚ := le_antisymm (mapβ‚‚_le.2 $ Ξ» m hm np hnp, let ⟨n, hn, p, hp, hnp⟩ := mem_sup.1 hnp in mem_sup.2 ⟨_, apply_mem_mapβ‚‚ _ hm hn, _, apply_mem_mapβ‚‚ _ hm hp, hnp β–Έ (map_add _ _ _).symm⟩) (sup_le (mapβ‚‚_le_mapβ‚‚_right le_sup_left) (mapβ‚‚_le_mapβ‚‚_right le_sup_right)) theorem mapβ‚‚_sup_left (f : M β†’β‚—[R] N β†’β‚—[R] P) (p₁ pβ‚‚ : submodule R M) (q : submodule R N) : mapβ‚‚ f (p₁ βŠ” pβ‚‚) q = mapβ‚‚ f p₁ q βŠ” mapβ‚‚ f pβ‚‚ q := le_antisymm (mapβ‚‚_le.2 $ Ξ» mn hmn p hp, let ⟨m, hm, n, hn, hmn⟩ := mem_sup.1 hmn in mem_sup.2 ⟨_, apply_mem_mapβ‚‚ _ hm hp, _, apply_mem_mapβ‚‚ _ hn hp, hmn β–Έ (linear_map.map_addβ‚‚ _ _ _ _).symm⟩) (sup_le (mapβ‚‚_le_mapβ‚‚_left le_sup_left) (mapβ‚‚_le_mapβ‚‚_left le_sup_right)) lemma image2_subset_mapβ‚‚ (f : M β†’β‚—[R] N β†’β‚—[R] P) (p : submodule R M) (q : submodule R N) : set.image2 (Ξ» m n, f m n) (↑p : set M) (↑q : set N) βŠ† (↑(mapβ‚‚ f p q) : set P) := by { rintros _ ⟨i, j, hi, hj, rfl⟩, exact apply_mem_mapβ‚‚ _ hi hj } lemma mapβ‚‚_eq_span_image2 (f : M β†’β‚—[R] N β†’β‚—[R] P) (p : submodule R M) (q : submodule R N) : mapβ‚‚ f p q = span R (set.image2 (Ξ» m n, f m n) (p : set M) (q : set N)) := by rw [← mapβ‚‚_span_span, span_eq, span_eq] lemma mapβ‚‚_flip (f : M β†’β‚—[R] N β†’β‚—[R] P) (p : submodule R M) (q : submodule R N) : mapβ‚‚ f.flip q p = mapβ‚‚ f p q := by { rw [mapβ‚‚_eq_span_image2, mapβ‚‚_eq_span_image2, set.image2_swap], refl } lemma mapβ‚‚_supr_right (f : M β†’β‚—[R] N β†’β‚—[R] P) (s : submodule R M) (t : ΞΉ β†’ submodule R N) : mapβ‚‚ f s (⨆ i, t i) = ⨆ i, mapβ‚‚ f s (t i) := begin suffices : mapβ‚‚ f (span R s) (⨆ i, span R (t i : set N)) = (⨆ i, mapβ‚‚ f (span R s) (span R (t i))), { simpa only [span_eq] using this }, simp_rw [mapβ‚‚_span_span, ← span_Union, mapβ‚‚_span_span, set.image2_Union_right], end theorem mapβ‚‚_span_singleton_eq_map (f : M β†’β‚—[R] N β†’β‚—[R] P) (m : M) : mapβ‚‚ f (span R {m}) = map (f m) := begin funext, rw mapβ‚‚_eq_span_image2, apply le_antisymm, { rw [span_le, set.image2_subset_iff], intros x hx y hy, obtain ⟨a, rfl⟩ := mem_span_singleton.1 hx, rw [f.map_smul], exact smul_mem _ a (mem_map_of_mem hy) }, { rintro _ ⟨n, hn, rfl⟩, exact subset_span ⟨m, n, mem_span_singleton_self m, hn, rfl⟩ }, end theorem mapβ‚‚_span_singleton_eq_map_flip (f : M β†’β‚—[R] N β†’β‚—[R] P) (s : submodule R M) (n : N) : mapβ‚‚ f s (span R {n}) = map (f.flip n) s := by rw [← mapβ‚‚_span_singleton_eq_map, mapβ‚‚_flip] end submodule
my_f(x,y) = 2*x+3*y derivative_of_my_f(x,y) = ForwardDiff.derivative(x->my_f(x,y),x)
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov ! This file was ported from Lean 3 source module analysis.complex.upper_half_plane.metric ! leanprover-community/mathlib commit f06058e64b7e8397234455038f3f8aec83aaba5a ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.Analysis.Complex.UpperHalfPlane.Topology import Mathbin.Analysis.SpecialFunctions.Arsinh import Mathbin.Geometry.Euclidean.Inversion /-! # Metric on the upper half-plane In this file we define a `metric_space` structure on the `upper_half_plane`. We use hyperbolic (PoincarΓ©) distance given by `dist z w = 2 * arsinh (dist (z : β„‚) w / (2 * real.sqrt (z.im * w.im)))` instead of the induced Euclidean distance because the hyperbolic distance is invariant under holomorphic automorphisms of the upper half-plane. However, we ensure that the projection to `topological_space` is definitionally equal to the induced topological space structure. We also prove that a metric ball/closed ball/sphere in PoincarΓ© metric is a Euclidean ball/closed ball/sphere with another center and radius. -/ noncomputable section open UpperHalfPlane ComplexConjugate NNReal Topology MatrixGroups open Set Metric Filter Real variable {z w : ℍ} {r R : ℝ} namespace UpperHalfPlane instance : Dist ℍ := ⟨fun z w => 2 * arsinh (dist (z : β„‚) w / (2 * sqrt (z.im * w.im)))⟩ theorem dist_eq (z w : ℍ) : dist z w = 2 * arsinh (dist (z : β„‚) w / (2 * sqrt (z.im * w.im))) := rfl #align upper_half_plane.dist_eq UpperHalfPlane.dist_eq theorem sinh_half_dist (z w : ℍ) : sinh (dist z w / 2) = dist (z : β„‚) w / (2 * sqrt (z.im * w.im)) := by rw [dist_eq, mul_div_cancel_left (arsinh _) two_ne_zero, sinh_arsinh] #align upper_half_plane.sinh_half_dist UpperHalfPlane.sinh_half_dist theorem cosh_half_dist (z w : ℍ) : cosh (dist z w / 2) = dist (z : β„‚) (conj (w : β„‚)) / (2 * sqrt (z.im * w.im)) := by have H₁ : (2 ^ 2 : ℝ) = 4 := by norm_num1 have Hβ‚‚ : 0 < z.im * w.im := mul_pos z.im_pos w.im_pos have H₃ : 0 < 2 * sqrt (z.im * w.im) := mul_pos two_pos (sqrt_pos.2 Hβ‚‚) rw [← sq_eq_sq (cosh_pos _).le (div_nonneg dist_nonneg H₃.le), cosh_sq', sinh_half_dist, div_pow, div_pow, one_add_div (pow_ne_zero 2 H₃.ne'), mul_pow, sq_sqrt Hβ‚‚.le, H₁] congr 1 simp only [Complex.dist_eq, Complex.sq_abs, Complex.normSq_sub, Complex.normSq_conj, Complex.conj_conj, Complex.mul_re, Complex.conj_re, Complex.conj_im, coe_im] ring #align upper_half_plane.cosh_half_dist UpperHalfPlane.cosh_half_dist theorem tanh_half_dist (z w : ℍ) : tanh (dist z w / 2) = dist (z : β„‚) w / dist (z : β„‚) (conj ↑w) := by rw [tanh_eq_sinh_div_cosh, sinh_half_dist, cosh_half_dist, div_div_div_comm, div_self, div_one] exact (mul_pos (zero_lt_two' ℝ) (sqrt_pos.2 <| mul_pos z.im_pos w.im_pos)).ne' #align upper_half_plane.tanh_half_dist UpperHalfPlane.tanh_half_dist theorem exp_half_dist (z w : ℍ) : exp (dist z w / 2) = (dist (z : β„‚) w + dist (z : β„‚) (conj ↑w)) / (2 * sqrt (z.im * w.im)) := by rw [← sinh_add_cosh, sinh_half_dist, cosh_half_dist, add_div] #align upper_half_plane.exp_half_dist UpperHalfPlane.exp_half_dist theorem cosh_dist (z w : ℍ) : cosh (dist z w) = 1 + dist (z : β„‚) w ^ 2 / (2 * z.im * w.im) := by rw [dist_eq, cosh_two_mul, cosh_sq', add_assoc, ← two_mul, sinh_arsinh, div_pow, mul_pow, sq_sqrt (mul_pos z.im_pos w.im_pos).le, sq (2 : ℝ), mul_assoc, ← mul_div_assoc, mul_assoc, mul_div_mul_left _ _ (two_ne_zero' ℝ)] #align upper_half_plane.cosh_dist UpperHalfPlane.cosh_dist theorem sinh_half_dist_add_dist (a b c : ℍ) : sinh ((dist a b + dist b c) / 2) = (dist (a : β„‚) b * dist (c : β„‚) (conj ↑b) + dist (b : β„‚) c * dist (a : β„‚) (conj ↑b)) / (2 * sqrt (a.im * c.im) * dist (b : β„‚) (conj ↑b)) := by simp only [add_div _ _ (2 : ℝ), sinh_add, sinh_half_dist, cosh_half_dist, div_mul_div_comm] rw [← add_div, Complex.dist_self_conj, coe_im, abs_of_pos b.im_pos, mul_comm (dist ↑b _), dist_comm (b : β„‚), Complex.dist_conj_comm, mul_mul_mul_comm, mul_mul_mul_comm _ _ _ b.im] congr 2 rw [sqrt_mul, sqrt_mul, sqrt_mul, mul_comm (sqrt a.im), mul_mul_mul_comm, mul_self_sqrt, mul_comm] <;> exact (im_pos _).le #align upper_half_plane.sinh_half_dist_add_dist UpperHalfPlane.sinh_half_dist_add_dist protected theorem dist_comm (z w : ℍ) : dist z w = dist w z := by simp only [dist_eq, dist_comm (z : β„‚), mul_comm] #align upper_half_plane.dist_comm UpperHalfPlane.dist_comm theorem dist_le_iff_le_sinh : dist z w ≀ r ↔ dist (z : β„‚) w / (2 * sqrt (z.im * w.im)) ≀ sinh (r / 2) := by rw [← div_le_div_right (zero_lt_two' ℝ), ← sinh_le_sinh, sinh_half_dist] #align upper_half_plane.dist_le_iff_le_sinh UpperHalfPlane.dist_le_iff_le_sinh theorem dist_eq_iff_eq_sinh : dist z w = r ↔ dist (z : β„‚) w / (2 * sqrt (z.im * w.im)) = sinh (r / 2) := by rw [← div_left_inj' (two_ne_zero' ℝ), ← sinh_inj, sinh_half_dist] #align upper_half_plane.dist_eq_iff_eq_sinh UpperHalfPlane.dist_eq_iff_eq_sinh theorem dist_eq_iff_eq_sq_sinh (hr : 0 ≀ r) : dist z w = r ↔ dist (z : β„‚) w ^ 2 / (4 * z.im * w.im) = sinh (r / 2) ^ 2 := by rw [dist_eq_iff_eq_sinh, ← sq_eq_sq, div_pow, mul_pow, sq_sqrt, mul_assoc] Β· norm_num Β· exact (mul_pos z.im_pos w.im_pos).le Β· exact div_nonneg dist_nonneg (mul_nonneg zero_le_two <| sqrt_nonneg _) Β· exact sinh_nonneg_iff.2 (div_nonneg hr zero_le_two) #align upper_half_plane.dist_eq_iff_eq_sq_sinh UpperHalfPlane.dist_eq_iff_eq_sq_sinh protected theorem dist_triangle (a b c : ℍ) : dist a c ≀ dist a b + dist b c := by rw [dist_le_iff_le_sinh, sinh_half_dist_add_dist, div_mul_eq_div_div _ _ (dist _ _), le_div_iff, div_mul_eq_mul_div] Β· exact div_le_div_of_le (mul_nonneg zero_le_two (sqrt_nonneg _)) (EuclideanGeometry.mul_dist_le_mul_dist_add_mul_dist (a : β„‚) b c (conj ↑b)) Β· rw [dist_comm, dist_pos, Ne.def, Complex.eq_conj_iff_im] exact b.im_ne_zero #align upper_half_plane.dist_triangle UpperHalfPlane.dist_triangle theorem dist_le_dist_coe_div_sqrt (z w : ℍ) : dist z w ≀ dist (z : β„‚) w / sqrt (z.im * w.im) := by rw [dist_le_iff_le_sinh, ← div_mul_eq_div_div_swap, self_le_sinh_iff] exact div_nonneg dist_nonneg (mul_nonneg zero_le_two (sqrt_nonneg _)) #align upper_half_plane.dist_le_dist_coe_div_sqrt UpperHalfPlane.dist_le_dist_coe_div_sqrt /-- An auxiliary `metric_space` instance on the upper half-plane. This instance has bad projection to `topological_space`. We replace it later. -/ def metricSpaceAux : MetricSpace ℍ where dist := dist dist_self z := by rw [dist_eq, dist_self, zero_div, arsinh_zero, MulZeroClass.mul_zero] dist_comm := UpperHalfPlane.dist_comm dist_triangle := UpperHalfPlane.dist_triangle eq_of_dist_eq_zero z w h := by simpa [dist_eq, Real.sqrt_eq_zero', (mul_pos z.im_pos w.im_pos).not_le, Subtype.coe_inj] using h #align upper_half_plane.metric_space_aux UpperHalfPlane.metricSpaceAux open Complex theorem cosh_dist' (z w : ℍ) : Real.cosh (dist z w) = ((z.re - w.re) ^ 2 + z.im ^ 2 + w.im ^ 2) / (2 * z.im * w.im) := by have H : 0 < 2 * z.im * w.im := mul_pos (mul_pos two_pos z.im_pos) w.im_pos field_simp [cosh_dist, Complex.dist_eq, Complex.sq_abs, norm_sq_apply, H, H.ne'] ring #align upper_half_plane.cosh_dist' UpperHalfPlane.cosh_dist' /-- Euclidean center of the circle with center `z` and radius `r` in the hyperbolic metric. -/ def center (z : ℍ) (r : ℝ) : ℍ := ⟨⟨z.re, z.im * cosh r⟩, mul_pos z.im_pos (cosh_pos _)⟩ #align upper_half_plane.center UpperHalfPlane.center @[simp] theorem center_re (z r) : (center z r).re = z.re := rfl #align upper_half_plane.center_re UpperHalfPlane.center_re @[simp] theorem center_im (z r) : (center z r).im = z.im * cosh r := rfl #align upper_half_plane.center_im UpperHalfPlane.center_im @[simp] theorem center_zero (z : ℍ) : center z 0 = z := Subtype.ext <| ext rfl <| by rw [coe_im, coe_im, center_im, Real.cosh_zero, mul_one] #align upper_half_plane.center_zero UpperHalfPlane.center_zero theorem dist_coe_center_sq (z w : ℍ) (r : ℝ) : dist (z : β„‚) (w.center r) ^ 2 = 2 * z.im * w.im * (cosh (dist z w) - cosh r) + (w.im * sinh r) ^ 2 := by have H : 2 * z.im * w.im β‰  0 := by apply_rules [mul_ne_zero, two_ne_zero, im_ne_zero] simp only [Complex.dist_eq, Complex.sq_abs, norm_sq_apply, coe_re, coe_im, center_re, center_im, cosh_dist', mul_div_cancel' _ H, sub_sq z.im, mul_pow, Real.cosh_sq, sub_re, sub_im, mul_sub, ← sq] ring #align upper_half_plane.dist_coe_center_sq UpperHalfPlane.dist_coe_center_sq theorem dist_coe_center (z w : ℍ) (r : ℝ) : dist (z : β„‚) (w.center r) = sqrt (2 * z.im * w.im * (cosh (dist z w) - cosh r) + (w.im * sinh r) ^ 2) := by rw [← sqrt_sq dist_nonneg, dist_coe_center_sq] #align upper_half_plane.dist_coe_center UpperHalfPlane.dist_coe_center theorem cmp_dist_eq_cmp_dist_coe_center (z w : ℍ) (r : ℝ) : cmp (dist z w) r = cmp (dist (z : β„‚) (w.center r)) (w.im * sinh r) := by letI := metric_space_aux cases' lt_or_le r 0 with hrβ‚€ hrβ‚€ Β· trans Ordering.gt exacts[(hrβ‚€.trans_le dist_nonneg).cmp_eq_gt, ((mul_neg_of_pos_of_neg w.im_pos (sinh_neg_iff.2 hrβ‚€)).trans_le dist_nonneg).cmp_eq_gt.symm] have hrβ‚€' : 0 ≀ w.im * sinh r := mul_nonneg w.im_pos.le (sinh_nonneg_iff.2 hrβ‚€) have hzwβ‚€ : 0 < 2 * z.im * w.im := mul_pos (mul_pos two_pos z.im_pos) w.im_pos simp only [← cosh_strict_mono_on.cmp_map_eq dist_nonneg hrβ‚€, ← (@strictMonoOn_pow ℝ _ _ two_pos).cmp_map_eq dist_nonneg hrβ‚€', dist_coe_center_sq] rw [← cmp_mul_pos_left hzwβ‚€, ← cmp_sub_zero, ← mul_sub, ← cmp_add_right, zero_add] #align upper_half_plane.cmp_dist_eq_cmp_dist_coe_center UpperHalfPlane.cmp_dist_eq_cmp_dist_coe_center theorem dist_eq_iff_dist_coe_center_eq : dist z w = r ↔ dist (z : β„‚) (w.center r) = w.im * sinh r := eq_iff_eq_of_cmp_eq_cmp (cmp_dist_eq_cmp_dist_coe_center z w r) #align upper_half_plane.dist_eq_iff_dist_coe_center_eq UpperHalfPlane.dist_eq_iff_dist_coe_center_eq @[simp] theorem dist_self_center (z : ℍ) (r : ℝ) : dist (z : β„‚) (z.center r) = z.im * (cosh r - 1) := by rw [dist_of_re_eq (z.center_re r).symm, dist_comm, Real.dist_eq, mul_sub, mul_one] exact abs_of_nonneg (sub_nonneg.2 <| le_mul_of_one_le_right z.im_pos.le (one_le_cosh _)) #align upper_half_plane.dist_self_center UpperHalfPlane.dist_self_center @[simp] theorem dist_center_dist (z w : ℍ) : dist (z : β„‚) (w.center (dist z w)) = w.im * sinh (dist z w) := dist_eq_iff_dist_coe_center_eq.1 rfl #align upper_half_plane.dist_center_dist UpperHalfPlane.dist_center_dist theorem dist_lt_iff_dist_coe_center_lt : dist z w < r ↔ dist (z : β„‚) (w.center r) < w.im * sinh r := lt_iff_lt_of_cmp_eq_cmp (cmp_dist_eq_cmp_dist_coe_center z w r) #align upper_half_plane.dist_lt_iff_dist_coe_center_lt UpperHalfPlane.dist_lt_iff_dist_coe_center_lt theorem lt_dist_iff_lt_dist_coe_center : r < dist z w ↔ w.im * sinh r < dist (z : β„‚) (w.center r) := lt_iff_lt_of_cmp_eq_cmp (cmp_eq_cmp_symm.1 <| cmp_dist_eq_cmp_dist_coe_center z w r) #align upper_half_plane.lt_dist_iff_lt_dist_coe_center UpperHalfPlane.lt_dist_iff_lt_dist_coe_center theorem dist_le_iff_dist_coe_center_le : dist z w ≀ r ↔ dist (z : β„‚) (w.center r) ≀ w.im * sinh r := le_iff_le_of_cmp_eq_cmp (cmp_dist_eq_cmp_dist_coe_center z w r) #align upper_half_plane.dist_le_iff_dist_coe_center_le UpperHalfPlane.dist_le_iff_dist_coe_center_le theorem le_dist_iff_le_dist_coe_center : r < dist z w ↔ w.im * sinh r < dist (z : β„‚) (w.center r) := lt_iff_lt_of_cmp_eq_cmp (cmp_eq_cmp_symm.1 <| cmp_dist_eq_cmp_dist_coe_center z w r) #align upper_half_plane.le_dist_iff_le_dist_coe_center UpperHalfPlane.le_dist_iff_le_dist_coe_center /-- For two points on the same vertical line, the distance is equal to the distance between the logarithms of their imaginary parts. -/ theorem dist_of_re_eq (h : z.re = w.re) : dist z w = dist (log z.im) (log w.im) := by have hβ‚€ : 0 < z.im / w.im := div_pos z.im_pos w.im_pos rw [dist_eq_iff_dist_coe_center_eq, Real.dist_eq, ← abs_sinh, ← log_div z.im_ne_zero w.im_ne_zero, sinh_log hβ‚€, dist_of_re_eq, coe_im, coe_im, center_im, cosh_abs, cosh_log hβ‚€, inv_div] <;> [skip, exact h] nth_rw 4 [← abs_of_pos w.im_pos] simp only [← _root_.abs_mul, coe_im, Real.dist_eq] congr 1 field_simp [z.im_pos, w.im_pos, z.im_ne_zero, w.im_ne_zero] ring #align upper_half_plane.dist_of_re_eq UpperHalfPlane.dist_of_re_eq /-- Hyperbolic distance between two points is greater than or equal to the distance between the logarithms of their imaginary parts. -/ theorem dist_log_im_le (z w : ℍ) : dist (log z.im) (log w.im) ≀ dist z w := calc dist (log z.im) (log w.im) = @dist ℍ _ ⟨⟨0, z.im⟩, z.im_pos⟩ ⟨⟨0, w.im⟩, w.im_pos⟩ := Eq.symm <| @dist_of_re_eq ⟨⟨0, z.im⟩, z.im_pos⟩ ⟨⟨0, w.im⟩, w.im_pos⟩ rfl _ ≀ dist z w := mul_le_mul_of_nonneg_left (arsinh_le_arsinh.2 <| div_le_div_of_le (mul_nonneg zero_le_two (sqrt_nonneg _)) <| by simpa [sqrt_sq_eq_abs] using Complex.abs_im_le_abs (z - w)) zero_le_two #align upper_half_plane.dist_log_im_le UpperHalfPlane.dist_log_im_le theorem im_le_im_mul_exp_dist (z w : ℍ) : z.im ≀ w.im * exp (dist z w) := by rw [← div_le_iff' w.im_pos, ← exp_log z.im_pos, ← exp_log w.im_pos, ← Real.exp_sub, exp_le_exp] exact (le_abs_self _).trans (dist_log_im_le z w) #align upper_half_plane.im_le_im_mul_exp_dist UpperHalfPlane.im_le_im_mul_exp_dist theorem im_div_exp_dist_le (z w : ℍ) : z.im / exp (dist z w) ≀ w.im := (div_le_iff (exp_pos _)).2 (im_le_im_mul_exp_dist z w) #align upper_half_plane.im_div_exp_dist_le UpperHalfPlane.im_div_exp_dist_le /-- An upper estimate on the complex distance between two points in terms of the hyperbolic distance and the imaginary part of one of the points. -/ theorem dist_coe_le (z w : ℍ) : dist (z : β„‚) w ≀ w.im * (exp (dist z w) - 1) := calc dist (z : β„‚) w ≀ dist (z : β„‚) (w.center (dist z w)) + dist (w : β„‚) (w.center (dist z w)) := dist_triangle_right _ _ _ _ = w.im * (exp (dist z w) - 1) := by rw [dist_center_dist, dist_self_center, ← mul_add, ← add_sub_assoc, Real.sinh_add_cosh] #align upper_half_plane.dist_coe_le UpperHalfPlane.dist_coe_le /-- An upper estimate on the complex distance between two points in terms of the hyperbolic distance and the imaginary part of one of the points. -/ theorem le_dist_coe (z w : ℍ) : w.im * (1 - exp (-dist z w)) ≀ dist (z : β„‚) w := calc w.im * (1 - exp (-dist z w)) = dist (z : β„‚) (w.center (dist z w)) - dist (w : β„‚) (w.center (dist z w)) := by rw [dist_center_dist, dist_self_center, ← Real.cosh_sub_sinh] ring _ ≀ dist (z : β„‚) w := sub_le_iff_le_add.2 <| dist_triangle _ _ _ #align upper_half_plane.le_dist_coe UpperHalfPlane.le_dist_coe /-- The hyperbolic metric on the upper half plane. We ensure that the projection to `topological_space` is definitionally equal to the subtype topology. -/ instance : MetricSpace ℍ := metricSpaceAux.replaceTopology <| by refine' le_antisymm (continuous_id_iff_le.1 _) _ Β· refine' (@continuous_iff_continuous_dist _ _ metric_space_aux.to_pseudo_metric_space _ _).2 _ have : βˆ€ x : ℍ Γ— ℍ, 2 * Real.sqrt (x.1.im * x.2.im) β‰  0 := fun x => mul_ne_zero two_ne_zero (Real.sqrt_pos.2 <| mul_pos x.1.im_pos x.2.im_pos).ne' -- `continuity` fails to apply `continuous.div` apply_rules [Continuous.div, Continuous.mul, continuous_const, Continuous.arsinh, Continuous.dist, continuous_coe.comp, continuous_fst, continuous_snd, real.continuous_sqrt.comp, continuous_im.comp] Β· letI : MetricSpace ℍ := metric_space_aux refine' le_of_nhds_le_nhds fun z => _ rw [nhds_induced] refine' (nhds_basis_ball.le_basis_iff (nhds_basis_ball.comap _)).2 fun R hR => _ have h₁ : 1 < R / im z + 1 := lt_add_of_pos_left _ (div_pos hR z.im_pos) have hβ‚€ : 0 < R / im z + 1 := one_pos.trans h₁ refine' ⟨log (R / im z + 1), Real.log_pos h₁, _⟩ refine' fun w hw => (dist_coe_le w z).trans_lt _ rwa [← lt_div_iff' z.im_pos, sub_lt_iff_lt_add, ← Real.lt_log_iff_exp_lt hβ‚€] theorem im_pos_of_dist_center_le {z : ℍ} {r : ℝ} {w : β„‚} (h : dist w (center z r) ≀ z.im * sinh r) : 0 < w.im := calc 0 < z.im * (cosh r - sinh r) := mul_pos z.im_pos (sub_pos.2 <| sinh_lt_cosh _) _ = (z.center r).im - z.im * sinh r := (mul_sub _ _ _) _ ≀ (z.center r).im - dist (z.center r : β„‚) w := (sub_le_sub_left (by rwa [dist_comm]) _) _ ≀ w.im := sub_le_comm.1 <| (le_abs_self _).trans (abs_im_le_abs <| z.center r - w) #align upper_half_plane.im_pos_of_dist_center_le UpperHalfPlane.im_pos_of_dist_center_le theorem image_coe_closedBall (z : ℍ) (r : ℝ) : (coe : ℍ β†’ β„‚) '' closedBall z r = closedBall (z.center r) (z.im * sinh r) := by ext w; constructor Β· rintro ⟨w, hw, rfl⟩ exact dist_le_iff_dist_coe_center_le.1 hw Β· intro hw lift w to ℍ using im_pos_of_dist_center_le hw exact mem_image_of_mem _ (dist_le_iff_dist_coe_center_le.2 hw) #align upper_half_plane.image_coe_closed_ball UpperHalfPlane.image_coe_closedBall theorem image_coe_ball (z : ℍ) (r : ℝ) : (coe : ℍ β†’ β„‚) '' ball z r = ball (z.center r) (z.im * sinh r) := by ext w; constructor Β· rintro ⟨w, hw, rfl⟩ exact dist_lt_iff_dist_coe_center_lt.1 hw Β· intro hw lift w to ℍ using im_pos_of_dist_center_le (ball_subset_closed_ball hw) exact mem_image_of_mem _ (dist_lt_iff_dist_coe_center_lt.2 hw) #align upper_half_plane.image_coe_ball UpperHalfPlane.image_coe_ball theorem image_coe_sphere (z : ℍ) (r : ℝ) : (coe : ℍ β†’ β„‚) '' sphere z r = sphere (z.center r) (z.im * sinh r) := by ext w; constructor Β· rintro ⟨w, hw, rfl⟩ exact dist_eq_iff_dist_coe_center_eq.1 hw Β· intro hw lift w to ℍ using im_pos_of_dist_center_le (sphere_subset_closed_ball hw) exact mem_image_of_mem _ (dist_eq_iff_dist_coe_center_eq.2 hw) #align upper_half_plane.image_coe_sphere UpperHalfPlane.image_coe_sphere instance : ProperSpace ℍ := by refine' ⟨fun z r => _⟩ rw [← inducing_coe.is_compact_iff, image_coe_closed_ball] apply is_compact_closed_ball theorem isometry_vertical_line (a : ℝ) : Isometry fun y => mk ⟨a, exp y⟩ (exp_pos y) := by refine' Isometry.of_dist_eq fun y₁ yβ‚‚ => _ rw [dist_of_re_eq] exacts[congr_argβ‚‚ _ (log_exp _) (log_exp _), rfl] #align upper_half_plane.isometry_vertical_line UpperHalfPlane.isometry_vertical_line theorem isometry_real_vadd (a : ℝ) : Isometry ((Β· +α΅₯ Β·) a : ℍ β†’ ℍ) := Isometry.of_dist_eq fun y₁ yβ‚‚ => by simp only [dist_eq, coe_vadd, vadd_im, dist_add_left] #align upper_half_plane.isometry_real_vadd UpperHalfPlane.isometry_real_vadd theorem isometry_pos_mul (a : { x : ℝ // 0 < x }) : Isometry ((Β· β€’ Β·) a : ℍ β†’ ℍ) := by refine' Isometry.of_dist_eq fun y₁ yβ‚‚ => _ simp only [dist_eq, coe_pos_real_smul, pos_real_im]; congr 2 rw [dist_smulβ‚€, mul_mul_mul_comm, Real.sqrt_mul (mul_self_nonneg _), Real.sqrt_mul_self_eq_abs, Real.norm_eq_abs, mul_left_comm] exact mul_div_mul_left _ _ (mt _root_.abs_eq_zero.1 a.2.ne') #align upper_half_plane.isometry_pos_mul UpperHalfPlane.isometry_pos_mul /-- `SL(2, ℝ)` acts on the upper half plane as an isometry.-/ instance : IsometricSMul SL(2, ℝ) ℍ := ⟨fun g => by have hβ‚€ : Isometry (fun z => ModularGroup.s β€’ z : ℍ β†’ ℍ) := Isometry.of_dist_eq fun y₁ yβ‚‚ => by have h₁ : 0 ≀ im y₁ * im yβ‚‚ := mul_nonneg y₁.property.le yβ‚‚.property.le have hβ‚‚ : Complex.abs (y₁ * yβ‚‚) β‰  0 := by simp [y₁.ne_zero, yβ‚‚.ne_zero] simp only [dist_eq, modular_S_smul, inv_neg, neg_div, div_mul_div_comm, coe_mk, mk_im, div_one, Complex.inv_im, Complex.neg_im, coe_im, neg_neg, Complex.normSq_neg, mul_eq_mul_left_iff, Real.arsinh_inj, bit0_eq_zero, one_ne_zero, or_false_iff, dist_neg_neg, mul_neg, neg_mul, dist_inv_invβ‚€ y₁.ne_zero yβ‚‚.ne_zero, ← map_mul, ← Complex.normSq_mul, Real.sqrt_div h₁, ← Complex.abs_apply, mul_div (2 : ℝ), div_div_div_comm, div_self hβ‚‚, Complex.norm_eq_abs] by_cases hc : g 1 0 = 0 Β· obtain ⟨u, v, h⟩ := exists_SL2_smul_eq_of_apply_zero_one_eq_zero g hc rw [h] exact (isometry_real_vadd v).comp (isometry_pos_mul u) Β· obtain ⟨u, v, w, h⟩ := exists_SL2_smul_eq_of_apply_zero_one_ne_zero g hc rw [h] exact (isometry_real_vadd w).comp (hβ‚€.comp <| (isometry_real_vadd v).comp <| isometry_pos_mul u)⟩ end UpperHalfPlane
-- Notes 11/26/2019 -- false is not provable, except from a contradiction -- if we reach a proof of false, our proposition must be false -- false also implies anything example : false β†’ 0 = 1 := false.elim example : βˆ€ (P : Prop), false β†’ P := Ξ» (p), Ξ» (f), false.elim f #check @false.elim -- If we can show that P β†’ false, then P must not be true -- No proof could exist for P axiom P : Prop example : P β†’ Β¬P β†’ false := begin assume hp, assume hnp, contradiction end example : P β†’ Β¬P β†’ false := Ξ» (hp), Ξ» (hnp), (hnp hp) example : P β†’ Β¬ P β†’ 0 = 1 := Ξ» (hp), Ξ» (hnp), false.elim (hnp hp) example : P β†’ (P β†’ Β¬ P) β†’ false := begin assume hp, assume pnp, apply pnp hp, exact hp, end axiom Q : Prop axiom q : Q example : P ∨ Q := begin apply or.intro_right, -- or.intro_right lets you construct a proof of P ∨ Q from Q exact q, end axiom excluded_middle : βˆ€ (P : Prop), P ∨ Β¬P example : P ∨ Β¬P := begin exact (excluded_middle P), end -- or elimination : P ∨ Q β†’ (P β†’ R) β†’ (Q β†’ R) β†’ R -- if we have P or Q, and P implies R, and Q implies R, then R must be true!! -- case analysis axioms (R : Prop) (p : P) (pr : P β†’ R) (qr : Q β†’ R) example : (P ∨ Q) β†’ R := begin assume pq, apply or.elim pq pr qr, end example : (P ∨ Q) β†’ R := Ξ» pq, match pq with | or.inl hp := pr hp | or.inr hq := qr hq end example : (P ∨ Q) β†’ R := begin assume pq, cases pq with hp hq, apply pr hp, apply qr hq, end
informal statement If $f$ is a continuous mapping of a metric space $X$ into a metric space $Y$, prove that $f(\overline{E}) \subset \overline{f(E)}$ for every set $E \subset X$. ($\overline{E}$ denotes the closure of $E$).formal statement theorem exercise_4_2a {Ξ± : Type} [metric_space Ξ±] {Ξ² : Type} [metric_space Ξ²] (f : Ξ± β†’ Ξ²) (h₁ : continuous f) : βˆ€ (x : set Ξ±), f '' (closure x) βŠ† closure (f '' x) :=
State Before: Ξ± : Type u Ξ² : Type v ΞΉ : Type ?u.76247 Ο€ : ΞΉ β†’ Type ?u.76252 inst✝¹ : TopologicalSpace Ξ± inst✝ : TopologicalSpace Ξ² s t : Set Ξ± h : βˆ€ {ΞΉ : Type u} (Z : ΞΉ β†’ Set Ξ±), (βˆ€ (i : ΞΉ), IsClosed (Z i)) β†’ (β‹‚ (i : ΞΉ), Z i) = βˆ… β†’ βˆƒ t, (β‹‚ (i : ΞΉ) (_ : i ∈ t), Z i) = βˆ… ι✝ : Type u Z : ι✝ β†’ Set Ξ± ⊒ (βˆ€ (i : ι✝), IsClosed (Z i)) β†’ (univ ∩ β‹‚ (i : ι✝), Z i) = βˆ… β†’ βˆƒ t, (univ ∩ β‹‚ (i : ι✝) (_ : i ∈ t), Z i) = βˆ… State After: no goals Tactic: simpa using h Z
lemma poly_shift_id [simp]: "poly_shift 0 = (\<lambda>x. x)"
lemma psize_eq_0_iff [simp]: "psize p = 0 \<longleftrightarrow> p = 0"
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import number_theory.arithmetic_function import number_theory.lucas_lehmer import algebra.geom_sum import ring_theory.multiplicity /-! # Perfect Numbers This file proves Theorem 70 from the [100 Theorems List](https://www.cs.ru.nl/~freek/100/). The theorem characterizes even perfect numbers. Euclid proved that if `2 ^ (k + 1) - 1` is prime (these primes are known as Mersenne primes), then `2 ^ k * 2 ^ (k + 1) - 1` is perfect. Euler proved the converse, that if `n` is even and perfect, then there exists `k` such that `n = 2 ^ k * 2 ^ (k + 1) - 1` and `2 ^ (k + 1) - 1` is prime. ## References https://en.wikipedia.org/wiki/Euclid%E2%80%93Euler_theorem -/ lemma odd_mersenne_succ (k : β„•) : Β¬ 2 ∣ mersenne (k + 1) := by simp [← even_iff_two_dvd, ← nat.even_succ, nat.succ_eq_add_one] with parity_simps namespace nat open arithmetic_function finset open_locale arithmetic_function lemma sigma_two_pow_eq_mersenne_succ (k : β„•) : Οƒ 1 (2 ^ k) = mersenne (k + 1) := by simpa [mersenne, prime_two, ← geom_sum_mul_add 1 (k+1)] /-- Euclid's theorem that Mersenne primes induce perfect numbers -/ theorem perfect_two_pow_mul_mersenne_of_prime (k : β„•) (pr : (mersenne (k + 1)).prime) : perfect ((2 ^ k) * mersenne (k + 1)) := begin rw [perfect_iff_sum_divisors_eq_two_mul, ← mul_assoc, ← pow_succ, ← sigma_one_apply, mul_comm, is_multiplicative_sigma.map_mul_of_coprime (nat.prime_two.coprime_pow_of_not_dvd (odd_mersenne_succ _)), sigma_two_pow_eq_mersenne_succ], { simp [pr, nat.prime_two] }, { apply mul_pos (pow_pos _ k) (mersenne_pos (nat.succ_pos k)), norm_num } end lemma ne_zero_of_prime_mersenne (k : β„•) (pr : (mersenne (k + 1)).prime) : k β‰  0 := begin rintro rfl, simpa [mersenne, not_prime_one] using pr, end theorem even_two_pow_mul_mersenne_of_prime (k : β„•) (pr : (mersenne (k + 1)).prime) : even ((2 ^ k) * mersenne (k + 1)) := by simp [ne_zero_of_prime_mersenne k pr] with parity_simps lemma eq_two_pow_mul_odd {n : β„•} (hpos : 0 < n) : βˆƒ (k m : β„•), n = 2 ^ k * m ∧ Β¬ even m := begin have h := (multiplicity.finite_nat_iff.2 ⟨nat.prime_two.ne_one, hpos⟩), cases multiplicity.pow_multiplicity_dvd h with m hm, use [(multiplicity 2 n).get h, m], refine ⟨hm, _⟩, rw even_iff_two_dvd, have hg := multiplicity.is_greatest' h (nat.lt_succ_self _), contrapose! hg, rcases hg with ⟨k, rfl⟩, apply dvd.intro k, rw [pow_succ', mul_assoc, ← hm], end /-- Euler's theorem that even perfect numbers can be factored as a power of two times a Mersenne prime. -/ theorem eq_two_pow_mul_prime_mersenne_of_even_perfect {n : β„•} (ev : even n) (perf : perfect n) : βˆƒ (k : β„•), prime (mersenne (k + 1)) ∧ n = 2 ^ k * mersenne (k + 1) := begin have hpos := perf.2, rcases eq_two_pow_mul_odd hpos with ⟨k, m, rfl, hm⟩, use k, rw [perfect_iff_sum_divisors_eq_two_mul hpos, ← sigma_one_apply, is_multiplicative_sigma.map_mul_of_coprime (nat.prime_two.coprime_pow_of_not_dvd hm).symm, sigma_two_pow_eq_mersenne_succ, ← mul_assoc, ← pow_succ] at perf, rcases nat.coprime.dvd_of_dvd_mul_left (nat.prime_two.coprime_pow_of_not_dvd (odd_mersenne_succ _)) (dvd.intro _ perf) with ⟨j, rfl⟩, rw [← mul_assoc, mul_comm _ (mersenne _), mul_assoc] at perf, have h := mul_left_cancel' (ne_of_gt (mersenne_pos (nat.succ_pos _))) perf, rw [sigma_one_apply, sum_divisors_eq_sum_proper_divisors_add_self, ← succ_mersenne, add_mul, one_mul, add_comm] at h, have hj := add_left_cancel h, cases sum_proper_divisors_dvd (by { rw hj, apply dvd.intro_left (mersenne (k + 1)) rfl }), { have j1 : j = 1 := eq.trans hj.symm h_1, rw [j1, mul_one, sum_proper_divisors_eq_one_iff_prime] at h_1, simp [h_1, j1] }, { have jcon := eq.trans hj.symm h_1, rw [← one_mul j, ← mul_assoc, mul_one] at jcon, have jcon2 := mul_right_cancel' _ jcon, { exfalso, cases k, { apply hm, rw [← jcon2, pow_zero, one_mul, one_mul] at ev, rw [← jcon2, one_mul], exact ev }, apply ne_of_lt _ jcon2, rw [mersenne, ← nat.pred_eq_sub_one, lt_pred_iff, ← pow_one (nat.succ 1)], apply pow_lt_pow (nat.lt_succ_self 1) (nat.succ_lt_succ (nat.succ_pos k)) }, contrapose! hm, simp [hm] } end /-- The Euclid-Euler theorem characterizing even perfect numbers -/ theorem even_and_perfect_iff {n : β„•} : (even n ∧ perfect n) ↔ βˆƒ (k : β„•), prime (mersenne (k + 1)) ∧ n = 2 ^ k * mersenne (k + 1) := begin split, { rintro ⟨ev, perf⟩, exact eq_two_pow_mul_prime_mersenne_of_even_perfect ev perf }, { rintro ⟨k, pr, rfl⟩, exact ⟨even_two_pow_mul_mersenne_of_prime k pr, perfect_two_pow_mul_mersenne_of_prime k pr⟩ } end end nat
Require Import Program Arith. Program Fixpoint check_n (n : nat) (P : { i | i < n } -> bool) (p : nat) (H : forall (i : { i | i < n }), i < p -> P i = true) {measure (n - p)} : Exc (forall (p : { i | i < n}), P p = true) := match le_lt_dec n p with | left _ => value _ | right cmp => if dec (P p) then check_n n P (S p) _ else error end. Require Import Omega. Solve Obligations with program_simpl ; auto with *; try omega. Next Obligation. apply H. simpl. omega. Defined. Next Obligation. case (le_lt_dec p i) ; intros. assert(i = p) by omega. subst. revert H0. clear_subset_proofs. auto. apply H. simpl. assumption. Defined.
/- Copyright (c) 2023 MarΓ­a InΓ©s de Frutos-FernΓ‘ndez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author : MarΓ­a InΓ©s de Frutos-FernΓ‘ndez -/ import tactic import data.real.basic /- # LΓ­mites de secuencias en Lean Escribimos la definicΓ³n `Ξ΅` - `N` del lΓ­mite de una secuencia de nΓΊmeros reales y demostramos resultados sobre lΓ­mites. NOTA: adaptado de los cursos de formalizaciΓ³n de Kevin Buzzard. -/ /- ### NotaciΓ³n lambda (Ξ») para funciones Recordatorio: para representar una funciΓ³n `f` en Lean, utilizamos notaciΓ³n lambda: `Ξ» x, f x` es la funciΓ³n que asigna a `x` el valor `f (x)`. -/ def f : β„• β†’ ℝ := Ξ» n, n^2 + 3 -- `f(n) = n^2 + 3` example : f 3 = 12 := begin rw f, dsimp only, -- Para simplificar la aplicaciΓ³n de funciones norm_num, -- Normaliza expresiones numΓ©ricas end /- ## LΓ­mite de una secuencia -/ /-- Si `a(n)` es una secuencia de nΓΊmeros reales y `L` es un real, `tends_to a L` dice que el lΓ­mite de `a(n)` cuando `n β†’ ∞` es `L`. -/ def tends_to (a : β„• β†’ ℝ) (L : ℝ) : Prop := βˆ€ Ξ΅ > 0, βˆƒ N : β„•, βˆ€ n, N ≀ n β†’ |a n - L| < Ξ΅ /-- Este lema nos permite reescribir la definiciΓ³n de `tends_to` en nuestras pruebas. -/ theorem tends_to_def {a : β„• β†’ ℝ} {t : ℝ} : tends_to a t ↔ βˆ€ Ξ΅, 0 < Ξ΅ β†’ βˆƒ B : β„•, βˆ€ n, B ≀ n β†’ |a n - t| < Ξ΅ := begin refl end /- ## Ejercicios -/ /-- El lΓ­mite de la secuencia constante con valor `c` es `c`. -/ theorem tends_to_const (c : ℝ) : tends_to (Ξ» n, c) c := begin rw tends_to_def, intros Ξ΅ hΞ΅, use 0, intros n hn, simp only [sub_self, abs_zero], exact hΞ΅, end /-- Si `a(n)` tiende a `L` entonces `a(n) + c` tiende a `t + c` -/ theorem tends_to_add_const {a : β„• β†’ ℝ} {L : ℝ} (c : ℝ) (h : tends_to a L) : tends_to (Ξ» n, a n + c) (L + c) := begin intros Ξ΅ hΞ΅, specialize h Ξ΅ hΞ΅, cases h with N hN, use N, intros n hn, dsimp only, convert hN n hn using 1, simp only [add_sub_add_right_eq_sub], end /-- Si `a(n)` tiende a `L`, entonces `-a(n)` tiende a `-L`. Si simplificar la expresiΓ³n dentro del valor absoluto te estΓ‘ dando problemas, ve a la hoja `reales.lean`. -/ theorem tends_to_neg {a : β„• β†’ ℝ} {L : ℝ} (ha : tends_to a L) : tends_to (Ξ» n, - a n) (-L) := begin intros Ξ΅ hΞ΅, obtain ⟨N, hN⟩ := ha Ξ΅ hΞ΅, use N, intros n hn, dsimp only, rw [neg_sub_neg, abs_sub_comm], exact hN n hn, end /-- Si `a(n)` tiende a `La` y `b(n)` tiende a `Lb` entonces `a(n) + b(n)` tiende a `La + Lb`. Esta demostraciΓ³n es mΓ‘s complicada que las anteriores. -/ theorem tends_to_add {a b : β„• β†’ ℝ} {La Lb : ℝ} (ha : tends_to a La) (hb : tends_to b Lb) : tends_to (Ξ» n, a n + b n) (La + Lb) := begin intros Ξ΅ hΞ΅, obtain ⟨Na, hNa⟩ := ha (Ξ΅/2) (by linarith), obtain ⟨Nb, hNb⟩ := hb (Ξ΅/2) (by linarith), use max Na Nb, intros n hn, dsimp only, rw max_le_iff at hn, specialize hNa n hn.1, specialize hNb n hn.2, rw abs_lt at hNa hNb ⊒, split; -- El `;` en lugar de `,` hace que la siguiente instrucciΓ³n se aplique a todas las metas. linarith, end /-- Si `a(n)` tiende a `La` y `b(n)` tiende a `Lb` entonces `a(n) - b(n)` tiende a `La - Lb`. -/ theorem tends_to_sub {a b : β„• β†’ ℝ} {La Lb : ℝ} (ha : tends_to a La) (hb : tends_to b Lb) : tends_to (Ξ» n, a n - b n) (La - Lb) := begin exact tends_to_add ha (tends_to_neg hb), end /-- Si `a(n)` tiende a `L`, entonces `c*a(n)` tiende a `c*L`. Pista: tratad el caso `c = 0` por separado, utilizando `by_cases hc : c = 0`. -/ lemma tends_to_mul_const_left {a : β„• β†’ ℝ} {L c : ℝ} (h : tends_to a L) : tends_to (Ξ» n, c * (a n)) (c * L) := begin intros Ξ΅ hΞ΅, by_cases hc : c = 0, { use 0, intros n hn, simp only [hc, zero_mul, tsub_zero, abs_zero], exact hΞ΅ }, { have hΞ΅' : 0 < Ξ΅/|c|, { apply div_pos hΞ΅ (abs_pos.mpr hc) }, obtain ⟨N, hN⟩ := h (Ξ΅/|c|) hΞ΅', use N, intros n hn, dsimp only, rw [← mul_sub, abs_mul, ← lt_div_iff' (abs_pos.mpr hc)], exact hN n hn, } end /- Lema del sandwich. -/ theorem sandwich (a b c : β„• β†’ ℝ) (L : ℝ) (ha : tends_to a L) (hc : tends_to c L) (hab : βˆ€ n, a n ≀ b n) (hbc : βˆ€ n, b n ≀ c n) : tends_to b L := begin intros Ξ΅ hΞ΅, obtain ⟨Na, hNa⟩ := ha Ξ΅ hΞ΅, obtain ⟨Nc, hNc⟩ := hc Ξ΅ hΞ΅, use max Na Nc, intros n hn, rw max_le_iff at hn, specialize hNa n hn.1, specialize hNc n hn.2, rw abs_lt at hNa hNc ⊒, specialize hab n, specialize hbc n, split; linarith, end
informal statement Let $V$ be a vector space over an infinite field $F$. Show that $V$ cannot be the set-theoretic union of a finite number of proper subspaces of $V$.formal statement theorem exercise_5_3_10 : is_algebraic β„š (cos (real.pi / 180)) :=
postulate T : Set β†’ Set X : Set Class : Set β†’ Set member : βˆ€ {A} {{C : Class A}} β†’ A β†’ A iX : Class X iT : βˆ€ {A} {{CA : Class A}} β†’ Class (T A) -- Should get type Class (T X), -- not {{_ : Class X}} β†’ Class (T X) iTX = iT {A = X} -- Fails if not expanding instance argument in iTX f : T X β†’ T X f = member
(* * Copyright 2014, NICTA * * This software may be distributed and modified according to the terms of * the GNU General Public License version 2. Note that NO WARRANTY is provided. * See "LICENSE_GPLv2.txt" for details. * * @TAG(NICTA_GPL) *) theory CToCRefine imports "../../spec/cspec/Substitute" "../SimplRewrite" "../TypHeapLib" begin lemma spec_statefn_simulates_lookup_tree_Node: "\<lbrakk> exec_statefn_simulates g UNIV UNIV v v'; spec_statefn_simulates g (lookup_tree a f) (lookup_tree c f); spec_statefn_simulates g (lookup_tree b f) (lookup_tree d f) \<rbrakk> \<Longrightarrow> spec_statefn_simulates g (lookup_tree (Node n v a b) f) (lookup_tree (Node n v' c d) f)" by (simp add: spec_statefn_simulates_def) lemma spec_statefn_simulates_lookup_tree_Leaf: "spec_statefn_simulates g (lookup_tree Leaf f) (lookup_tree Leaf f')" by (simp add: spec_statefn_simulates_def) ML {* fun mk_meta_eq_safe t = mk_meta_eq t handle THM _ => t; val unfold_bodies = Simplifier.make_simproc @{context} "unfold constants named *_body" {lhss = [@{term "v"}], proc= fn _ => (fn ctxt => (fn t => case head_of (Thm.term_of t) of Const (s, _) => if String.isSuffix "_body" s then try (Global_Theory.get_thm (Proof_Context.theory_of ctxt) #> mk_meta_eq_safe) (suffix "_def" s) else NONE | _ => NONE))} *} theorem spec_refine: notes if_split[split del] shows "spec_statefn_simulates id (kernel_all_global_addresses.\<Gamma> symbol_table) (kernel_all_substitute.\<Gamma> symbol_table domain)" apply (simp add: kernel_all_global_addresses.\<Gamma>_def kernel_all_substitute.\<Gamma>_def) apply (intro spec_statefn_simulates_lookup_tree_Node spec_statefn_simulates_lookup_tree_Leaf) apply (tactic {* ALLGOALS (asm_simp_tac (put_simpset HOL_ss @{context} addsimps @{thms switch.simps fst_conv snd_conv} addsimprocs [unfold_bodies] |> Splitter.del_split @{thm if_split})) THEN ALLGOALS (TRY o resolve_tac @{context} @{thms exec_statefn_simulates_refl}) *}) apply (tactic {* ALLGOALS (REPEAT_ALL_NEW (resolve_tac @{context} @{thms exec_statefn_simulates_comI exec_statefn_simulates_additionals})) *}) apply (unfold id_apply) apply (tactic {* ALLGOALS (TRY o resolve_tac @{context} @{thms refl bij_id}) *}) apply (tactic {* ALLGOALS (TRY o (resolve_tac @{context} @{thms subsetI} THEN' resolve_tac @{context} @{thms CollectI} THEN' REPEAT_ALL_NEW (eresolve_tac @{context} @{thms IntE CollectE conjE exE h_t_valid_c_guard conjI} ORELSE' assume_tac @{context}))) *}) (* apply (tactic {* ALLGOALS (TRY o ((REPEAT_ALL_NEW (rtac @{thm c_guard_field}) THEN' etac @{thm h_t_valid_c_guard}) THEN_ALL_NEW simp_tac @{simpset} THEN_ALL_NEW simp_tac @{simpset} THEN_ALL_NEW K no_tac)) *}) *) apply (rule bij_id[simplified id_def])+ done (* Woo! *) end
import Smt theorem refl (p : Prop) : p = p := by smt
State Before: V : Type u V' : Type v V'' : Type w G : SimpleGraph V G' : SimpleGraph V' G'' : SimpleGraph V'' u v : V p : Walk G u v H : SimpleGraph V hp : βˆ€ (e : Sym2 V), e ∈ edges p β†’ e ∈ edgeSet H pp : IsPath p ⊒ IsPath (Walk.transfer p H hp) State After: no goals Tactic: induction p with | nil => simp | cons _ _ ih => simp only [Walk.transfer, cons_isPath_iff, support_transfer _ ] at pp ⊒ exact ⟨ih _ pp.1, pp.2⟩ State Before: case nil V : Type u V' : Type v V'' : Type w G : SimpleGraph V G' : SimpleGraph V' G'' : SimpleGraph V'' u v : V p : Walk G u v H : SimpleGraph V u✝ : V hp : βˆ€ (e : Sym2 V), e ∈ edges Walk.nil β†’ e ∈ edgeSet H pp : IsPath Walk.nil ⊒ IsPath (Walk.transfer Walk.nil H hp) State After: no goals Tactic: simp State Before: case cons V : Type u V' : Type v V'' : Type w G : SimpleGraph V G' : SimpleGraph V' G'' : SimpleGraph V'' u v : V p : Walk G u v H : SimpleGraph V u✝ v✝ w✝ : V h✝ : Adj G u✝ v✝ p✝ : Walk G v✝ w✝ ih : βˆ€ (hp : βˆ€ (e : Sym2 V), e ∈ edges p✝ β†’ e ∈ edgeSet H), IsPath p✝ β†’ IsPath (Walk.transfer p✝ H hp) hp : βˆ€ (e : Sym2 V), e ∈ edges (cons h✝ p✝) β†’ e ∈ edgeSet H pp : IsPath (cons h✝ p✝) ⊒ IsPath (Walk.transfer (cons h✝ p✝) H hp) State After: case cons V : Type u V' : Type v V'' : Type w G : SimpleGraph V G' : SimpleGraph V' G'' : SimpleGraph V'' u v : V p : Walk G u v H : SimpleGraph V u✝ v✝ w✝ : V h✝ : Adj G u✝ v✝ p✝ : Walk G v✝ w✝ ih : βˆ€ (hp : βˆ€ (e : Sym2 V), e ∈ edges p✝ β†’ e ∈ edgeSet H), IsPath p✝ β†’ IsPath (Walk.transfer p✝ H hp) hp : βˆ€ (e : Sym2 V), e ∈ edges (cons h✝ p✝) β†’ e ∈ edgeSet H pp : IsPath p✝ ∧ Β¬u✝ ∈ support p✝ ⊒ IsPath (Walk.transfer p✝ H (_ : βˆ€ (e : Sym2 V), e ∈ edges p✝ β†’ e ∈ edgeSet H)) ∧ Β¬u✝ ∈ support p✝ Tactic: simp only [Walk.transfer, cons_isPath_iff, support_transfer _ ] at pp ⊒ State Before: case cons V : Type u V' : Type v V'' : Type w G : SimpleGraph V G' : SimpleGraph V' G'' : SimpleGraph V'' u v : V p : Walk G u v H : SimpleGraph V u✝ v✝ w✝ : V h✝ : Adj G u✝ v✝ p✝ : Walk G v✝ w✝ ih : βˆ€ (hp : βˆ€ (e : Sym2 V), e ∈ edges p✝ β†’ e ∈ edgeSet H), IsPath p✝ β†’ IsPath (Walk.transfer p✝ H hp) hp : βˆ€ (e : Sym2 V), e ∈ edges (cons h✝ p✝) β†’ e ∈ edgeSet H pp : IsPath p✝ ∧ Β¬u✝ ∈ support p✝ ⊒ IsPath (Walk.transfer p✝ H (_ : βˆ€ (e : Sym2 V), e ∈ edges p✝ β†’ e ∈ edgeSet H)) ∧ Β¬u✝ ∈ support p✝ State After: no goals Tactic: exact ⟨ih _ pp.1, pp.2⟩
header {* \isaheader{Generic Compare Algorithms} *} theory Gen_Comp imports "../Intf/Intf_Comp" "../../../Automatic_Refinement/Automatic_Refinement" begin subsection {* Order for Product *} (* TODO: Optimization? Or only go via prod_cmp? *) lemma autoref_prod_cmp_dflt_id[autoref_rules_raw]: "(dflt_cmp op \<le> op <, dflt_cmp op \<le> op <) \<in> \<langle>Id,Id\<rangle>prod_rel \<rightarrow> \<langle>Id,Id\<rangle>prod_rel \<rightarrow> Id" by auto lemma gen_prod_cmp_dflt[autoref_rules_raw]: assumes PRIO_TAG_GEN_ALGO assumes "GEN_OP cmp1 (dflt_cmp op \<le> op <) (R1 \<rightarrow> R1 \<rightarrow> Id)" assumes "GEN_OP cmp2 (dflt_cmp op \<le> op <) (R2 \<rightarrow> R2 \<rightarrow> Id)" shows "(cmp_prod cmp1 cmp2, dflt_cmp op \<le> op <) \<in> \<langle>R1,R2\<rangle>prod_rel \<rightarrow> \<langle>R1,R2\<rangle>prod_rel \<rightarrow> Id" proof - have E: "dflt_cmp op \<le> op < = cmp_prod (dflt_cmp op \<le> op <) (dflt_cmp op \<le> op <)" by (auto simp: dflt_cmp_def prod_less_def prod_le_def intro!: ext) show ?thesis using assms unfolding autoref_tag_defs E by parametricity qed end
State Before: q : β„š x y : ℝ ⊒ Irrational (x + y) β†’ Irrational x ∨ Irrational y State After: q : β„š x y : ℝ ⊒ Β¬x + y ∈ Set.range Rat.cast β†’ Β¬x ∈ Set.range Rat.cast ∨ Β¬y ∈ Set.range Rat.cast Tactic: delta Irrational State Before: q : β„š x y : ℝ ⊒ Β¬x + y ∈ Set.range Rat.cast β†’ Β¬x ∈ Set.range Rat.cast ∨ Β¬y ∈ Set.range Rat.cast State After: q : β„š x y : ℝ ⊒ x ∈ Set.range Rat.cast ∧ y ∈ Set.range Rat.cast β†’ x + y ∈ Set.range Rat.cast Tactic: contrapose! State Before: q : β„š x y : ℝ ⊒ x ∈ Set.range Rat.cast ∧ y ∈ Set.range Rat.cast β†’ x + y ∈ Set.range Rat.cast State After: case intro.intro.intro q rx ry : β„š ⊒ ↑rx + ↑ry ∈ Set.range Rat.cast Tactic: rintro ⟨⟨rx, rfl⟩, ⟨ry, rfl⟩⟩ State Before: case intro.intro.intro q rx ry : β„š ⊒ ↑rx + ↑ry ∈ Set.range Rat.cast State After: no goals Tactic: exact ⟨rx + ry, cast_add rx ry⟩
lemma reflect_poly_1 [simp]: "reflect_poly 1 = 1"
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler ! This file was ported from Lean 3 source module number_theory.modular_forms.jacobi_theta ! leanprover-community/mathlib commit fe44cd36149e675eb5dec87acc7e8f1d6568e081 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.NumberTheory.ModularForms.Basic import Mathbin.Analysis.SpecialFunctions.Gaussian import Mathbin.Analysis.Calculus.Series import Mathbin.Analysis.Complex.LocallyUniformLimit /-! # Jacobi's theta function This file defines the Jacobi theta function $$\theta(\tau) = \sum_{n \in \mathbb{Z}} \exp (i \pi n ^ 2 \tau),$$ and proves the modular transformation properties `ΞΈ (Ο„ + 2) = ΞΈ Ο„` and `ΞΈ (-1 / Ο„) = (-I * Ο„) ^ (1 / 2) * ΞΈ Ο„`, using Poisson's summation formula for the latter. We also show that `ΞΈ` is differentiable on `ℍ`, and `ΞΈ(Ο„) - 1` has exponential decay as `im Ο„ β†’ ∞`. -/ open Complex Real Asymptotics open Real BigOperators UpperHalfPlane Manifold /-- Jacobi's theta function `βˆ‘' (n : β„€), exp (Ο€ * I * n ^ 2 * Ο„)`. -/ noncomputable def jacobiTheta (Ο„ : ℍ) : β„‚ := βˆ‘' n : β„€, cexp (Ο€ * I * n ^ 2 * Ο„) #align jacobi_theta jacobiTheta theorem norm_exp_mul_sq_le {z : β„‚} (hz : 0 < z.im) (n : β„€) : β€–cexp (Ο€ * I * n ^ 2 * z)β€– ≀ exp (-Ο€ * z.im) ^ n.natAbs := by let y := rexp (-Ο€ * z.im) have h : y < 1 := exp_lt_one_iff.mpr (mul_neg_of_neg_of_pos (neg_lt_zero.mpr pi_pos) hz) refine' (le_of_eq _).trans (_ : y ^ n ^ 2 ≀ _) Β· rw [Complex.norm_eq_abs, Complex.abs_exp] have : (↑π * I * n ^ 2 * z).re = -Ο€ * z.im * n ^ 2 := by rw [(by push_cast ring : ↑π * I * n ^ 2 * z = ↑(Ο€ * n ^ 2) * (z * I)), of_real_mul_re, mul_I_re] ring obtain ⟨m, hm⟩ := Int.eq_ofNat_of_zero_le (sq_nonneg n) rw [this, exp_mul, ← Int.cast_pow, rpow_int_cast, hm, zpow_ofNat] Β· have : n ^ 2 = ↑(n.nat_abs ^ 2) := by rw [Nat.cast_pow, Int.natAbs_sq] rw [this, zpow_ofNat] exact pow_le_pow_of_le_one (exp_pos _).le h.le ((sq n.nat_abs).symm β–Έ n.nat_abs.le_mul_self) #align norm_exp_mul_sq_le norm_exp_mul_sq_le theorem exists_summable_bound_exp_mul_sq {R : ℝ} (hR : 0 < R) : βˆƒ bd : β„€ β†’ ℝ, Summable bd ∧ βˆ€ {Ο„ : β„‚} (hΟ„ : R ≀ Ο„.im) (n : β„€), β€–cexp (Ο€ * I * n ^ 2 * Ο„)β€– ≀ bd n := by let y := rexp (-Ο€ * R) have h : y < 1 := exp_lt_one_iff.mpr (mul_neg_of_neg_of_pos (neg_lt_zero.mpr pi_pos) hR) refine' ⟨fun n => y ^ n.natAbs, summable_int_of_summable_nat _ _, fun Ο„ hΟ„ n => _⟩ pick_goal 3 Β· refine' (norm_exp_mul_sq_le (hR.trans_le hΟ„) n).trans _ refine' pow_le_pow_of_le_left (exp_pos _).le (real.exp_le_exp.mpr _) _ rwa [mul_le_mul_left_of_neg (neg_lt_zero.mpr pi_pos)] all_goals simpa only [Int.natAbs_neg, Int.natAbs_ofNat] using summable_geometric_of_lt_1 (Real.exp_pos _).le h #align exists_summable_bound_exp_mul_sq exists_summable_bound_exp_mul_sq theorem summable_exp_mul_sq {z : β„‚} (hz : 0 < z.im) : Summable fun n : β„€ => cexp (Ο€ * I * n ^ 2 * z) := let ⟨bd, h, h'⟩ := exists_summable_bound_exp_mul_sq hz summable_norm_iff.mp (summable_of_nonneg_of_le (fun n => norm_nonneg _) (h' <| le_refl _) h) #align summable_exp_mul_sq summable_exp_mul_sq theorem jacobiTheta_two_vadd (Ο„ : ℍ) : jacobiTheta ((2 : ℝ) +α΅₯ Ο„) = jacobiTheta Ο„ := by refine' tsum_congr fun n => _ rw [UpperHalfPlane.coe_vadd, of_real_bit0, of_real_one] suffices cexp (↑π * I * ↑n ^ 2 * 2) = 1 by rw [mul_add, Complex.exp_add, this, one_mul] rw [(by push_cast ring : ↑π * I * ↑n ^ 2 * 2 = ↑(n ^ 2) * (2 * Ο€ * I)), Complex.exp_int_mul, Complex.exp_two_pi_mul_i, one_zpow] #align jacobi_theta_two_vadd jacobiTheta_two_vadd theorem jacobiTheta_t_sq_smul (Ο„ : ℍ) : jacobiTheta (ModularGroup.t ^ 2 β€’ Ο„) = jacobiTheta Ο„ := by suffices : (2 : ℝ) +α΅₯ Ο„ = ModularGroup.t ^ (2 : β„€) β€’ Ο„; exact this β–Έ jacobiTheta_two_vadd Ο„ simp only [← Subtype.coe_inj, UpperHalfPlane.modular_t_zpow_smul, Int.cast_two] #align jacobi_theta_T_sq_smul jacobiTheta_t_sq_smul theorem jacobiTheta_s_smul (Ο„ : ℍ) : jacobiTheta (ModularGroup.s β€’ Ο„) = (-I * Ο„) ^ (1 / 2 : β„‚) * jacobiTheta Ο„ := by unfold jacobiTheta rw [UpperHalfPlane.modular_s_smul, UpperHalfPlane.coe_mk] have ha : 0 < (-I * Ο„).re := by rw [neg_mul, neg_re, mul_re, I_re, I_im, MulZeroClass.zero_mul, one_mul, zero_sub, neg_neg] exact Ο„.im_pos have ha' : (-I * Ο„) ^ (1 / 2 : β„‚) β‰  0 := by rw [Ne.def, cpow_eq_zero_iff] contrapose! ha rw [ha.1, zero_re] have hΟ„ : (Ο„ : β„‚) β‰  0 := Ο„.ne_zero have := Complex.tsum_exp_neg_mul_int_sq ha rw [mul_comm ((1 : β„‚) / _) _, mul_one_div, eq_div_iff ha', mul_comm _ (_ ^ _), eq_comm] at this convert this using 3 Β· ext1 n congr 1 field_simp [hΟ„, I_ne_zero] ring_nf rw [I_sq, mul_neg, mul_one, neg_mul, neg_neg] Β· ext1 n congr 1 ring_nf #align jacobi_theta_S_smul jacobiTheta_s_smul theorem hasSum_nat_jacobiTheta (Ο„ : ℍ) : HasSum (fun n : β„• => cexp (Ο€ * I * (n + 1) ^ 2 * Ο„)) ((jacobiTheta Ο„ - 1) / 2) := by have := (summable_exp_mul_sq Ο„.im_pos).HasSum.sum_nat_of_sum_int rw [← @hasSum_nat_add_iff' β„‚ _ _ _ _ 1] at this simp_rw [Finset.sum_range_one, Int.cast_neg, Int.cast_ofNat, Nat.cast_zero, neg_zero, Int.cast_zero, sq (0 : β„‚), MulZeroClass.mul_zero, MulZeroClass.zero_mul, neg_sq, ← mul_two, Complex.exp_zero, add_sub_assoc, (by norm_num : (1 : β„‚) - 1 * 2 = -1), ← sub_eq_add_neg, Nat.cast_add, Nat.cast_one] at this convert this.div_const 2 simp_rw [mul_div_cancel _ two_ne_zero] #align has_sum_nat_jacobi_theta hasSum_nat_jacobiTheta theorem jacobiTheta_eq_tsum_nat (Ο„ : ℍ) : jacobiTheta Ο„ = 1 + 2 * βˆ‘' n : β„•, cexp (Ο€ * I * (n + 1) ^ 2 * Ο„) := by rw [(hasSum_nat_jacobiTheta Ο„).tsum_eq, mul_div_cancel' _ (two_ne_zero' β„‚), ← add_sub_assoc, add_sub_cancel'] #align jacobi_theta_eq_tsum_nat jacobiTheta_eq_tsum_nat /-- An explicit upper bound for `β€–jacobi_theta Ο„ - 1β€–`. -/ theorem norm_jacobiTheta_sub_one_le (Ο„ : ℍ) : β€–jacobiTheta Ο„ - 1β€– ≀ 2 / (1 - exp (-Ο€ * Ο„.im)) * exp (-Ο€ * Ο„.im) := by suffices β€–βˆ‘' n : β„•, cexp (Ο€ * I * (n + 1) ^ 2 * Ο„)β€– ≀ exp (-Ο€ * Ο„.im) / (1 - exp (-Ο€ * Ο„.im)) by calc β€–jacobiTheta Ο„ - 1β€– = 2 * β€–βˆ‘' n : β„•, cexp (Ο€ * I * (n + 1) ^ 2 * Ο„)β€– := by rw [sub_eq_iff_eq_add'.mpr (jacobiTheta_eq_tsum_nat Ο„), norm_mul, Complex.norm_eq_abs, Complex.abs_two] _ ≀ 2 * (rexp (-Ο€ * Ο„.im) / (1 - rexp (-Ο€ * Ο„.im))) := by rwa [mul_le_mul_left (zero_lt_two' ℝ)] _ = 2 / (1 - rexp (-Ο€ * Ο„.im)) * rexp (-Ο€ * Ο„.im) := by rw [div_mul_comm, mul_comm] have : βˆ€ n : β„•, β€–cexp (Ο€ * I * (n + 1) ^ 2 * Ο„)β€– ≀ exp (-Ο€ * Ο„.im) ^ (n + 1) := by intro n simpa only [Int.cast_add, Int.cast_one] using norm_exp_mul_sq_le Ο„.im_pos (n + 1) have s : HasSum (fun n : β„• => rexp (-Ο€ * Ο„.im) ^ (n + 1)) (exp (-Ο€ * Ο„.im) / (1 - exp (-Ο€ * Ο„.im))) := by simp_rw [pow_succ, div_eq_mul_inv, hasSum_mul_left_iff (Real.exp_ne_zero _)] exact hasSum_geometric_of_lt_1 (exp_pos (-Ο€ * Ο„.im)).le (exp_lt_one_iff.mpr <| mul_neg_of_neg_of_pos (neg_lt_zero.mpr pi_pos) Ο„.im_pos) have aux : Summable fun n : β„• => β€–cexp (↑π * I * (↑n + 1) ^ 2 * ↑τ)β€– := summable_of_nonneg_of_le (fun n => norm_nonneg _) this s.summable exact (norm_tsum_le_tsum_norm aux).trans ((tsum_mono aux s.summable this).trans (le_of_eq s.tsum_eq)) #align norm_jacobi_theta_sub_one_le norm_jacobiTheta_sub_one_le /-- The norm of `jacobi_theta Ο„ - 1` decays exponentially as `im Ο„ β†’ ∞`. -/ theorem isO_atImInfty_jacobiTheta_sub_one : IsO UpperHalfPlane.atImInfty (fun Ο„ => jacobiTheta Ο„ - 1) fun Ο„ => rexp (-Ο€ * Ο„.im) := by simp_rw [is_O, is_O_with, Filter.Eventually, UpperHalfPlane.atImInfty_mem] refine' ⟨2 / (1 - rexp (-Ο€)), 1, fun Ο„ hΟ„ => (norm_jacobiTheta_sub_one_le Ο„).trans _⟩ rw [Real.norm_eq_abs, Real.abs_exp] refine' mul_le_mul_of_nonneg_right _ (exp_pos _).le rw [div_le_div_left (zero_lt_two' ℝ), sub_le_sub_iff_left, exp_le_exp, neg_mul, neg_le_neg_iff] Β· exact le_mul_of_one_le_right pi_pos.le hΟ„ Β· rw [sub_pos, exp_lt_one_iff, neg_mul, neg_lt_zero] exact mul_pos pi_pos Ο„.im_pos Β· rw [sub_pos, exp_lt_one_iff, neg_lt_zero] exact pi_pos #align is_O_at_im_infty_jacobi_theta_sub_one isO_atImInfty_jacobiTheta_sub_one theorem differentiableAt_tsum_exp_mul_sq (Ο„ : ℍ) : DifferentiableAt β„‚ (fun z => βˆ‘' n : β„€, cexp (Ο€ * I * n ^ 2 * z)) ↑τ := by suffices : βˆ€ (y : ℝ) (hy : 0 < y), DifferentiableOn β„‚ (fun z => βˆ‘' n : β„€, cexp (Ο€ * I * n ^ 2 * z)) { w : β„‚ | y < im w } exact let ⟨y, hy, hy'⟩ := exists_between Ο„.im_pos (this y hy).DifferentiableAt ((complex.continuous_im.is_open_preimage _ isOpen_Ioi).mem_nhds (Ο„.coe_im β–Έ hy')) intro y hy have h1 : βˆ€ (n : β„€) (w : β„‚) (hw : y < im w), DifferentiableWithinAt β„‚ (fun v : β„‚ => cexp (↑π * I * ↑n ^ 2 * v)) { z : β„‚ | y < im z } w := fun n w hw => (differentiable_at_id.const_mul _).cexp.DifferentiableWithinAt have h2 : IsOpen { w : β„‚ | y < im w } := continuous_im.is_open_preimage _ isOpen_Ioi obtain ⟨bd, bd_s, le_bd⟩ := exists_summable_bound_exp_mul_sq hy exact differentiable_on_tsum_of_summable_norm bd_s h1 h2 fun i w hw => le_bd (le_of_lt hw) i #align differentiable_at_tsum_exp_mul_sq differentiableAt_tsum_exp_mul_sq theorem mdifferentiable_jacobiTheta : Mdifferentiable π“˜(β„‚) π“˜(β„‚) jacobiTheta := fun Ο„ => (differentiableAt_tsum_exp_mul_sq Ο„).MdifferentiableAt.comp Ο„ Ο„.mdifferentiable_coe #align mdifferentiable_jacobi_theta mdifferentiable_jacobiTheta theorem continuous_jacobiTheta : Continuous jacobiTheta := mdifferentiable_jacobiTheta.Continuous #align continuous_jacobi_theta continuous_jacobiTheta
Require Import LiterateCoq.Tactics. Require Import Compiler. Require Import ZArith. Lemma list_pointless_split : forall A B:Type, forall l : list A, forall x : B, match l with | nil => x | (_ :: _)%list => x end = x. Proof. destruct l; eauto. Qed. Lemma list_pointless_split' : forall A B:Type, forall l : list A, forall x : B, match l with | nil => x | (_ :: nil)%list => x | (_ :: _ :: _)%list => x end = x. Proof. destruct l; intros; eauto. destruct l; eauto. Qed. Lemma eval_step : forall a : Arith, forall s : list Num.Int, forall xs : list StackOp, eval s (compile a ++ xs) = eval (eval' a :: s) xs. Proof. hint_rewrite List.app_assoc_reverse. hint_rewrite list_pointless_split, list_pointless_split'. induction a; intros; simpl; iauto; hint_rewrite IHa1, IHa2; iauto'. Qed. Lemma compiler_correctness' : forall a : Arith, forall s : list Num.Int, eval s (compile a) = Data.Either.Right (eval' a). Proof. hint_rewrite eval_step. hint_rewrite list_pointless_split, list_pointless_split'. induction a; intros; simpl; hint_simpl; iauto'. Qed. Theorem compiler_correctness : forall a : Arith, eval nil (compile a) = Data.Either.Right (eval' a). Proof. hint compiler_correctness'. intros; iauto. Qed.
/- Copyright (c) 2019 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Yury Kudriashov -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.set.intervals.ord_connected import Mathlib.data.set.intervals.image_preimage import Mathlib.data.complex.module import Mathlib.linear_algebra.affine_space.affine_map import Mathlib.algebra.module.ordered import Mathlib.PostPort universes u u_1 v v' w x u' namespace Mathlib /-! # Convex sets and functions on real vector spaces In a real vector space, we define the following objects and properties. * `segment x y` is the closed segment joining `x` and `y`. * A set `s` is `convex` if for any two points `x y ∈ s` it includes `segment x y`; * A function `f : E β†’ Ξ²` is `convex_on` a set `s` if `s` is itself a convex set, and for any two points `x y ∈ s` the segment joining `(x, f x)` to `(y, f y)` is (non-strictly) above the graph of `f`; equivalently, `convex_on f s` means that the epigraph `{p : E Γ— Ξ² | p.1 ∈ s ∧ f p.1 ≀ p.2}` is a convex set; * Center mass of a finite set of points with prescribed weights. * Convex hull of a set `s` is the minimal convex set that includes `s`. * Standard simplex `std_simplex ΞΉ [fintype ΞΉ]` is the intersection of the positive quadrant with the hyperplane `s.sum = 1` in the space `ΞΉ β†’ ℝ`. We also provide various equivalent versions of the definitions above, prove that some specific sets are convex, and prove Jensen's inequality. Note: To define convexity for functions `f : E β†’ Ξ²`, we need `Ξ²` to be an ordered vector space, defined using the instance `ordered_semimodule ℝ Ξ²`. ## Notations We use the following local notations: * `I = Icc (0:ℝ) 1`; * `[x, y] = segment x y`. They are defined using `local notation`, so they are not available outside of this file. -/ /-! ### Segment -/ /-- Segments in a vector space. -/ def segment {E : Type u} [add_comm_group E] [vector_space ℝ E] (x : E) (y : E) : set E := set_of fun (z : E) => βˆƒ (a : ℝ), βˆƒ (b : ℝ), βˆƒ (ha : 0 ≀ a), βˆƒ (hb : 0 ≀ b), βˆƒ (hab : a + b = 1), a β€’ x + b β€’ y = z theorem segment_symm {E : Type u} [add_comm_group E] [vector_space ℝ E] (x : E) (y : E) : segment x y = segment y x := sorry theorem left_mem_segment {E : Type u} [add_comm_group E] [vector_space ℝ E] (x : E) (y : E) : x ∈ segment x y := sorry theorem right_mem_segment {E : Type u} [add_comm_group E] [vector_space ℝ E] (x : E) (y : E) : y ∈ segment x y := segment_symm y x β–Έ left_mem_segment y x theorem segment_same {E : Type u} [add_comm_group E] [vector_space ℝ E] (x : E) : segment x x = singleton x := sorry theorem segment_eq_image {E : Type u} [add_comm_group E] [vector_space ℝ E] (x : E) (y : E) : segment x y = (fun (ΞΈ : ℝ) => (1 - ΞΈ) β€’ x + ΞΈ β€’ y) '' set.Icc 0 1 := sorry theorem segment_eq_image' {E : Type u} [add_comm_group E] [vector_space ℝ E] (x : E) (y : E) : segment x y = (fun (ΞΈ : ℝ) => x + ΞΈ β€’ (y - x)) '' set.Icc 0 1 := sorry theorem segment_eq_imageβ‚‚ {E : Type u} [add_comm_group E] [vector_space ℝ E] (x : E) (y : E) : segment x y = (fun (p : ℝ Γ— ℝ) => prod.fst p β€’ x + prod.snd p β€’ y) '' set_of fun (p : ℝ Γ— ℝ) => 0 ≀ prod.fst p ∧ 0 ≀ prod.snd p ∧ prod.fst p + prod.snd p = 1 := sorry theorem segment_eq_Icc {a : ℝ} {b : ℝ} (h : a ≀ b) : segment a b = set.Icc a b := sorry theorem segment_eq_Icc' (a : ℝ) (b : ℝ) : segment a b = set.Icc (min a b) (max a b) := sorry theorem segment_eq_interval (a : ℝ) (b : ℝ) : segment a b = set.interval a b := segment_eq_Icc' a b theorem mem_segment_translate {E : Type u} [add_comm_group E] [vector_space ℝ E] (a : E) {x : E} {b : E} {c : E} : a + x ∈ segment (a + b) (a + c) ↔ x ∈ segment b c := sorry theorem segment_translate_preimage {E : Type u} [add_comm_group E] [vector_space ℝ E] (a : E) (b : E) (c : E) : (fun (x : E) => a + x) ⁻¹' segment (a + b) (a + c) = segment b c := set.ext fun (x : E) => mem_segment_translate a theorem segment_translate_image {E : Type u} [add_comm_group E] [vector_space ℝ E] (a : E) (b : E) (c : E) : (fun (x : E) => a + x) '' segment b c = segment (a + b) (a + c) := Eq.subst (segment_translate_preimage a b c) (set.image_preimage_eq (segment (a + b) (a + c))) (add_left_surjective a) /-! ### Convexity of sets -/ /-- Convexity of sets. -/ def convex {E : Type u} [add_comm_group E] [vector_space ℝ E] (s : set E) := βˆ€ {x y : E}, x ∈ s β†’ y ∈ s β†’ βˆ€ {a b : ℝ}, 0 ≀ a β†’ 0 ≀ b β†’ a + b = 1 β†’ a β€’ x + b β€’ y ∈ s theorem convex_iff_forall_pos {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} : convex s ↔ βˆ€ {x y : E}, x ∈ s β†’ y ∈ s β†’ βˆ€ {a b : ℝ}, 0 < a β†’ 0 < b β†’ a + b = 1 β†’ a β€’ x + b β€’ y ∈ s := sorry theorem convex_iff_segment_subset {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} : convex s ↔ βˆ€ {x y : E}, x ∈ s β†’ y ∈ s β†’ segment x y βŠ† s := sorry theorem convex.segment_subset {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} (h : convex s) {x : E} {y : E} (hx : x ∈ s) (hy : y ∈ s) : segment x y βŠ† s := iff.mp convex_iff_segment_subset h x y hx hy /-- Alternative definition of set convexity, in terms of pointwise set operations. -/ theorem convex_iff_pointwise_add_subset {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} : convex s ↔ βˆ€ {a b : ℝ}, 0 ≀ a β†’ 0 ≀ b β†’ a + b = 1 β†’ a β€’ s + b β€’ s βŠ† s := sorry /-- Alternative definition of set convexity, using division. -/ theorem convex_iff_div {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} : convex s ↔ βˆ€ {x y : E}, x ∈ s β†’ y ∈ s β†’ βˆ€ {a b : ℝ}, 0 ≀ a β†’ 0 ≀ b β†’ 0 < a + b β†’ (a / (a + b)) β€’ x + (b / (a + b)) β€’ y ∈ s := sorry /-! ### Examples of convex sets -/ theorem convex_empty {E : Type u} [add_comm_group E] [vector_space ℝ E] : convex βˆ… := sorry theorem convex_singleton {E : Type u} [add_comm_group E] [vector_space ℝ E] (c : E) : convex (singleton c) := sorry theorem convex_univ {E : Type u} [add_comm_group E] [vector_space ℝ E] : convex set.univ := fun (_x _x_1 : E) (_x : _x ∈ set.univ) (_x : _x_1 ∈ set.univ) (_x _x_2 : ℝ) (_x_3 : 0 ≀ _x) (_x_4 : 0 ≀ _x_2) (_x : _x + _x_2 = 1) => trivial theorem convex.inter {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {t : set E} (hs : convex s) (ht : convex t) : convex (s ∩ t) := fun (x y : E) (hx : x ∈ s ∩ t) (hy : y ∈ s ∩ t) (a b : ℝ) (ha : 0 ≀ a) (hb : 0 ≀ b) (hab : a + b = 1) => { left := hs (and.left hx) (and.left hy) ha hb hab, right := ht (and.right hx) (and.right hy) ha hb hab } theorem convex_sInter {E : Type u} [add_comm_group E] [vector_space ℝ E] {S : set (set E)} (h : βˆ€ (s : set E), s ∈ S β†’ convex s) : convex (β‹‚β‚€S) := fun (x y : E) (hx : x ∈ β‹‚β‚€S) (hy : y ∈ β‹‚β‚€S) (a b : ℝ) (ha : 0 ≀ a) (hb : 0 ≀ b) (hab : a + b = 1) (s : set E) (hs : s ∈ S) => h s hs (hx s hs) (hy s hs) ha hb hab theorem convex_Inter {E : Type u} [add_comm_group E] [vector_space ℝ E] {ΞΉ : Sort u_1} {s : ΞΉ β†’ set E} (h : βˆ€ (i : ΞΉ), convex (s i)) : convex (set.Inter fun (i : ΞΉ) => s i) := Eq.subst (set.sInter_range s) convex_sInter (iff.mpr set.forall_range_iff h) theorem convex.prod {E : Type u} {F : Type v} [add_comm_group E] [vector_space ℝ E] [add_comm_group F] [vector_space ℝ F] {s : set E} {t : set F} (hs : convex s) (ht : convex t) : convex (set.prod s t) := sorry theorem convex.combo_to_vadd {E : Type u} [add_comm_group E] [vector_space ℝ E] {a : ℝ} {b : ℝ} {x : E} {y : E} (h : a + b = 1) : a β€’ x + b β€’ y = b β€’ (y - x) + x := sorry /-- Applying an affine map to an affine combination of two points yields an affine combination of the images. -/ theorem convex.combo_affine_apply {E : Type u} {F : Type v} [add_comm_group E] [vector_space ℝ E] [add_comm_group F] [vector_space ℝ F] {a : ℝ} {b : ℝ} {x : E} {y : E} {f : affine_map ℝ E F} (h : a + b = 1) : coe_fn f (a β€’ x + b β€’ y) = a β€’ coe_fn f x + b β€’ coe_fn f y := sorry /-- The preimage of a convex set under an affine map is convex. -/ theorem convex.affine_preimage {E : Type u} {F : Type v} [add_comm_group E] [vector_space ℝ E] [add_comm_group F] [vector_space ℝ F] (f : affine_map ℝ E F) {s : set F} (hs : convex s) : convex (⇑f ⁻¹' s) := sorry /-- The image of a convex set under an affine map is convex. -/ theorem convex.affine_image {E : Type u} {F : Type v} [add_comm_group E] [vector_space ℝ E] [add_comm_group F] [vector_space ℝ F] (f : affine_map ℝ E F) {s : set E} (hs : convex s) : convex (⇑f '' s) := sorry theorem convex.linear_image {E : Type u} {F : Type v} [add_comm_group E] [vector_space ℝ E] [add_comm_group F] [vector_space ℝ F] {s : set E} (hs : convex s) (f : linear_map ℝ E F) : convex (⇑f '' s) := convex.affine_image (linear_map.to_affine_map f) hs theorem convex.is_linear_image {E : Type u} {F : Type v} [add_comm_group E] [vector_space ℝ E] [add_comm_group F] [vector_space ℝ F] {s : set E} (hs : convex s) {f : E β†’ F} (hf : is_linear_map ℝ f) : convex (f '' s) := convex.linear_image hs (is_linear_map.mk' f hf) theorem convex.linear_preimage {E : Type u} {F : Type v} [add_comm_group E] [vector_space ℝ E] [add_comm_group F] [vector_space ℝ F] {s : set F} (hs : convex s) (f : linear_map ℝ E F) : convex (⇑f ⁻¹' s) := convex.affine_preimage (linear_map.to_affine_map f) hs theorem convex.is_linear_preimage {E : Type u} {F : Type v} [add_comm_group E] [vector_space ℝ E] [add_comm_group F] [vector_space ℝ F] {s : set F} (hs : convex s) {f : E β†’ F} (hf : is_linear_map ℝ f) : convex (f ⁻¹' s) := convex.linear_preimage hs (is_linear_map.mk' f hf) theorem convex.neg {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} (hs : convex s) : convex ((fun (z : E) => -z) '' s) := convex.is_linear_image hs is_linear_map.is_linear_map_neg theorem convex.neg_preimage {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} (hs : convex s) : convex ((fun (z : E) => -z) ⁻¹' s) := convex.is_linear_preimage hs is_linear_map.is_linear_map_neg theorem convex.smul {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} (c : ℝ) (hs : convex s) : convex (c β€’ s) := convex.linear_image hs (coe_fn (linear_map.lsmul ℝ E) c) theorem convex.smul_preimage {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} (c : ℝ) (hs : convex s) : convex ((fun (z : E) => c β€’ z) ⁻¹' s) := convex.linear_preimage hs (coe_fn (linear_map.lsmul ℝ E) c) theorem convex.add {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {t : set E} (hs : convex s) (ht : convex t) : convex (s + t) := eq.mpr (id (Eq._oldrec (Eq.refl (convex (s + t))) (Eq.symm set.add_image_prod))) (convex.is_linear_image (convex.prod hs ht) is_linear_map.is_linear_map_add) theorem convex.sub {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {t : set E} (hs : convex s) (ht : convex t) : convex ((fun (x : E Γ— E) => prod.fst x - prod.snd x) '' set.prod s t) := convex.is_linear_image (convex.prod hs ht) is_linear_map.is_linear_map_sub theorem convex.translate {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} (hs : convex s) (z : E) : convex ((fun (x : E) => z + x) '' s) := convex.affine_image (affine_map.const ℝ E z +α΅₯ affine_map.id ℝ E) hs /-- The translation of a convex set is also convex. -/ theorem convex.translate_preimage_right {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} (hs : convex s) (a : E) : convex ((fun (z : E) => a + z) ⁻¹' s) := convex.affine_preimage (affine_map.const ℝ E a +α΅₯ affine_map.id ℝ E) hs /-- The translation of a convex set is also convex. -/ theorem convex.translate_preimage_left {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} (hs : convex s) (a : E) : convex ((fun (z : E) => z + a) ⁻¹' s) := sorry theorem convex.affinity {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} (hs : convex s) (z : E) (c : ℝ) : convex ((fun (x : E) => z + c β€’ x) '' s) := convex.affine_image (affine_map.const ℝ E z +α΅₯ c β€’ affine_map.id ℝ E) hs theorem real.convex_iff_ord_connected {s : set ℝ} : convex s ↔ set.ord_connected s := sorry theorem convex.ord_connected {s : set ℝ} : convex s β†’ set.ord_connected s := iff.mp real.convex_iff_ord_connected theorem convex_Iio (r : ℝ) : convex (set.Iio r) := set.ord_connected.convex set.ord_connected_Iio theorem convex_Ioi (r : ℝ) : convex (set.Ioi r) := set.ord_connected.convex set.ord_connected_Ioi theorem convex_Iic (r : ℝ) : convex (set.Iic r) := set.ord_connected.convex set.ord_connected_Iic theorem convex_Ici (r : ℝ) : convex (set.Ici r) := set.ord_connected.convex set.ord_connected_Ici theorem convex_Ioo (r : ℝ) (s : ℝ) : convex (set.Ioo r s) := set.ord_connected.convex set.ord_connected_Ioo theorem convex_Ico (r : ℝ) (s : ℝ) : convex (set.Ico r s) := set.ord_connected.convex set.ord_connected_Ico theorem convex_Ioc (r : ℝ) (s : ℝ) : convex (set.Ioc r s) := set.ord_connected.convex set.ord_connected_Ioc theorem convex_Icc (r : ℝ) (s : ℝ) : convex (set.Icc r s) := set.ord_connected.convex set.ord_connected_Icc theorem convex_interval (r : ℝ) (s : ℝ) : convex (set.interval r s) := set.ord_connected.convex set.ord_connected_interval theorem convex_segment {E : Type u} [add_comm_group E] [vector_space ℝ E] (a : E) (b : E) : convex (segment a b) := sorry theorem convex_halfspace_lt {E : Type u} [add_comm_group E] [vector_space ℝ E] {f : E β†’ ℝ} (h : is_linear_map ℝ f) (r : ℝ) : convex (set_of fun (w : E) => f w < r) := convex.is_linear_preimage (convex_Iio r) h theorem convex_halfspace_le {E : Type u} [add_comm_group E] [vector_space ℝ E] {f : E β†’ ℝ} (h : is_linear_map ℝ f) (r : ℝ) : convex (set_of fun (w : E) => f w ≀ r) := convex.is_linear_preimage (convex_Iic r) h theorem convex_halfspace_gt {E : Type u} [add_comm_group E] [vector_space ℝ E] {f : E β†’ ℝ} (h : is_linear_map ℝ f) (r : ℝ) : convex (set_of fun (w : E) => r < f w) := convex.is_linear_preimage (convex_Ioi r) h theorem convex_halfspace_ge {E : Type u} [add_comm_group E] [vector_space ℝ E] {f : E β†’ ℝ} (h : is_linear_map ℝ f) (r : ℝ) : convex (set_of fun (w : E) => r ≀ f w) := convex.is_linear_preimage (convex_Ici r) h theorem convex_hyperplane {E : Type u} [add_comm_group E] [vector_space ℝ E] {f : E β†’ ℝ} (h : is_linear_map ℝ f) (r : ℝ) : convex (set_of fun (w : E) => f w = r) := id (eq.mpr (id (Eq._oldrec (Eq.refl (convex (f ⁻¹' set_of fun (p : ℝ) => p = r))) set.set_of_eq_eq_singleton)) (convex.is_linear_preimage (convex_singleton r) h)) theorem convex_halfspace_re_lt (r : ℝ) : convex (set_of fun (c : β„‚) => complex.re c < r) := convex_halfspace_lt (is_linear_map.mk complex.add_re complex.smul_re) r theorem convex_halfspace_re_le (r : ℝ) : convex (set_of fun (c : β„‚) => complex.re c ≀ r) := convex_halfspace_le (is_linear_map.mk complex.add_re complex.smul_re) r theorem convex_halfspace_re_gt (r : ℝ) : convex (set_of fun (c : β„‚) => r < complex.re c) := convex_halfspace_gt (is_linear_map.mk complex.add_re complex.smul_re) r theorem convex_halfspace_re_lge (r : ℝ) : convex (set_of fun (c : β„‚) => r ≀ complex.re c) := convex_halfspace_ge (is_linear_map.mk complex.add_re complex.smul_re) r theorem convex_halfspace_im_lt (r : ℝ) : convex (set_of fun (c : β„‚) => complex.im c < r) := convex_halfspace_lt (is_linear_map.mk complex.add_im complex.smul_im) r theorem convex_halfspace_im_le (r : ℝ) : convex (set_of fun (c : β„‚) => complex.im c ≀ r) := convex_halfspace_le (is_linear_map.mk complex.add_im complex.smul_im) r theorem convex_halfspace_im_gt (r : ℝ) : convex (set_of fun (c : β„‚) => r < complex.im c) := convex_halfspace_gt (is_linear_map.mk complex.add_im complex.smul_im) r theorem convex_halfspace_im_lge (r : ℝ) : convex (set_of fun (c : β„‚) => r ≀ complex.im c) := convex_halfspace_ge (is_linear_map.mk complex.add_im complex.smul_im) r /-! ### Convex combinations in intervals -/ theorem convex.combo_self {Ξ± : Type v'} [linear_ordered_field Ξ±] (a : Ξ±) {x : Ξ±} {y : Ξ±} (h : x + y = 1) : a = x * a + y * a := sorry /-- If `x` is in an `Ioo`, it can be expressed as a convex combination of the endpoints. -/ theorem convex.mem_Ioo {Ξ± : Type v'} [linear_ordered_field Ξ±] {a : Ξ±} {b : Ξ±} {x : Ξ±} (h : a < b) : x ∈ set.Ioo a b ↔ βˆƒ (x_a : Ξ±), βˆƒ (x_b : Ξ±), 0 < x_a ∧ 0 < x_b ∧ x_a + x_b = 1 ∧ x_a * a + x_b * b = x := sorry /-- If `x` is in an `Ioc`, it can be expressed as a convex combination of the endpoints. -/ theorem convex.mem_Ioc {Ξ± : Type v'} [linear_ordered_field Ξ±] {a : Ξ±} {b : Ξ±} {x : Ξ±} (h : a < b) : x ∈ set.Ioc a b ↔ βˆƒ (x_a : Ξ±), βˆƒ (x_b : Ξ±), 0 ≀ x_a ∧ 0 < x_b ∧ x_a + x_b = 1 ∧ x_a * a + x_b * b = x := sorry /-- If `x` is in an `Ico`, it can be expressed as a convex combination of the endpoints. -/ theorem convex.mem_Ico {Ξ± : Type v'} [linear_ordered_field Ξ±] {a : Ξ±} {b : Ξ±} {x : Ξ±} (h : a < b) : x ∈ set.Ico a b ↔ βˆƒ (x_a : Ξ±), βˆƒ (x_b : Ξ±), 0 < x_a ∧ 0 ≀ x_b ∧ x_a + x_b = 1 ∧ x_a * a + x_b * b = x := sorry /-- If `x` is in an `Icc`, it can be expressed as a convex combination of the endpoints. -/ theorem convex.mem_Icc {Ξ± : Type v'} [linear_ordered_field Ξ±] {a : Ξ±} {b : Ξ±} {x : Ξ±} (h : a ≀ b) : x ∈ set.Icc a b ↔ βˆƒ (x_a : Ξ±), βˆƒ (x_b : Ξ±), 0 ≀ x_a ∧ 0 ≀ x_b ∧ x_a + x_b = 1 ∧ x_a * a + x_b * b = x := sorry theorem submodule.convex {E : Type u} [add_comm_group E] [vector_space ℝ E] (K : submodule ℝ E) : convex ↑K := id fun (x y : E) (αΎ° : x ∈ ↑K) (αΎ°_1 : y ∈ ↑K) (a b : ℝ) (αΎ°_2 : 0 ≀ a) (αΎ°_3 : 0 ≀ b) (αΎ°_4 : a + b = 1) => submodule.add_mem K (submodule.smul_mem K a αΎ°) (submodule.smul_mem K b αΎ°_1) theorem subspace.convex {E : Type u} [add_comm_group E] [vector_space ℝ E] (K : subspace ℝ E) : convex ↑K := submodule.convex K /-! ### Convex and concave functions -/ /-- Convexity of functions -/ def convex_on {E : Type u} [add_comm_group E] [vector_space ℝ E] {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] (s : set E) (f : E β†’ Ξ²) := convex s ∧ βˆ€ {x y : E}, x ∈ s β†’ y ∈ s β†’ βˆ€ {a b : ℝ}, 0 ≀ a β†’ 0 ≀ b β†’ a + b = 1 β†’ f (a β€’ x + b β€’ y) ≀ a β€’ f x + b β€’ f y /-- Concavity of functions -/ def concave_on {E : Type u} [add_comm_group E] [vector_space ℝ E] {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] (s : set E) (f : E β†’ Ξ²) := convex s ∧ βˆ€ {x y : E}, x ∈ s β†’ y ∈ s β†’ βˆ€ {a b : ℝ}, 0 ≀ a β†’ 0 ≀ b β†’ a + b = 1 β†’ a β€’ f x + b β€’ f y ≀ f (a β€’ x + b β€’ y) /-- A function `f` is concave iff `-f` is convex. -/ @[simp] theorem neg_convex_on_iff {E : Type u} [add_comm_group E] [vector_space ℝ E] {Ξ³ : Type u_1} [ordered_add_comm_group Ξ³] [semimodule ℝ Ξ³] (s : set E) (f : E β†’ Ξ³) : convex_on s (-f) ↔ concave_on s f := sorry /-- A function `f` is concave iff `-f` is convex. -/ @[simp] theorem neg_concave_on_iff {E : Type u} [add_comm_group E] [vector_space ℝ E] {Ξ³ : Type u_1} [ordered_add_comm_group Ξ³] [semimodule ℝ Ξ³] (s : set E) (f : E β†’ Ξ³) : concave_on s (-f) ↔ convex_on s f := eq.mpr (id (Eq._oldrec (Eq.refl (concave_on s (-f) ↔ convex_on s f)) (Eq.symm (propext (neg_convex_on_iff s (-f)))))) (eq.mpr (id (Eq._oldrec (Eq.refl (convex_on s ( --f) ↔ convex_on s f)) (neg_neg f))) (iff.refl (convex_on s f))) theorem convex_on_id {s : set ℝ} (hs : convex s) : convex_on s id := sorry theorem concave_on_id {s : set ℝ} (hs : convex s) : concave_on s id := sorry theorem convex_on_const {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] (c : Ξ²) (hs : convex s) : convex_on s fun (x : E) => c := sorry theorem concave_on_const {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] (c : Ξ²) (hs : convex s) : concave_on s fun (x : E) => c := convex_on_const c hs theorem convex_on_iff_div {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] {f : E β†’ Ξ²} : convex_on s f ↔ convex s ∧ βˆ€ {x y : E}, x ∈ s β†’ y ∈ s β†’ βˆ€ {a b : ℝ}, 0 ≀ a β†’ 0 ≀ b β†’ 0 < a + b β†’ f ((a / (a + b)) β€’ x + (b / (a + b)) β€’ y) ≀ (a / (a + b)) β€’ f x + (b / (a + b)) β€’ f y := sorry theorem concave_on_iff_div {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] {f : E β†’ Ξ²} : concave_on s f ↔ convex s ∧ βˆ€ {x y : E}, x ∈ s β†’ y ∈ s β†’ βˆ€ {a b : ℝ}, 0 ≀ a β†’ 0 ≀ b β†’ 0 < a + b β†’ (a / (a + b)) β€’ f x + (b / (a + b)) β€’ f y ≀ f ((a / (a + b)) β€’ x + (b / (a + b)) β€’ y) := convex_on_iff_div /-- For a function on a convex set in a linear ordered space, in order to prove that it is convex it suffices to verify the inequality `f (a β€’ x + b β€’ y) ≀ a β€’ f x + b β€’ f y` only for `x < y` and positive `a`, `b`. The main use case is `E = ℝ` however one can apply it, e.g., to `ℝ^n` with lexicographic order. -/ theorem linear_order.convex_on_of_lt {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] {f : E β†’ Ξ²} [linear_order E] (hs : convex s) (hf : βˆ€ {x y : E}, x ∈ s β†’ y ∈ s β†’ x < y β†’ βˆ€ {a b : ℝ}, 0 < a β†’ 0 < b β†’ a + b = 1 β†’ f (a β€’ x + b β€’ y) ≀ a β€’ f x + b β€’ f y) : convex_on s f := sorry /-- For a function on a convex set in a linear ordered space, in order to prove that it is concave it suffices to verify the inequality `a β€’ f x + b β€’ f y ≀ f (a β€’ x + b β€’ y)` only for `x < y` and positive `a`, `b`. The main use case is `E = ℝ` however one can apply it, e.g., to `ℝ^n` with lexicographic order. -/ theorem linear_order.concave_on_of_lt {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] {f : E β†’ Ξ²} [linear_order E] (hs : convex s) (hf : βˆ€ {x y : E}, x ∈ s β†’ y ∈ s β†’ x < y β†’ βˆ€ {a b : ℝ}, 0 < a β†’ 0 < b β†’ a + b = 1 β†’ a β€’ f x + b β€’ f y ≀ f (a β€’ x + b β€’ y)) : concave_on s f := linear_order.convex_on_of_lt hs hf /-- For a function `f` defined on a convex subset `D` of `ℝ`, if for any three points `x<y<z` the slope of the secant line of `f` on `[x, y]` is less than or equal to the slope of the secant line of `f` on `[x, z]`, then `f` is convex on `D`. This way of proving convexity of a function is used in the proof of convexity of a function with a monotone derivative. -/ theorem convex_on_real_of_slope_mono_adjacent {s : set ℝ} (hs : convex s) {f : ℝ β†’ ℝ} (hf : βˆ€ {x y z : ℝ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y)) : convex_on s f := sorry /-- For a function `f` defined on a subset `D` of `ℝ`, if `f` is convex on `D`, then for any three points `x<y<z`, the slope of the secant line of `f` on `[x, y]` is less than or equal to the slope of the secant line of `f` on `[x, z]`. -/ theorem convex_on.slope_mono_adjacent {s : set ℝ} {f : ℝ β†’ ℝ} (hf : convex_on s f) {x : ℝ} {y : ℝ} {z : ℝ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := sorry /-- For a function `f` defined on a convex subset `D` of `ℝ`, `f` is convex on `D` iff for any three points `x<y<z` the slope of the secant line of `f` on `[x, y]` is less than or equal to the slope of the secant line of `f` on `[x, z]`. -/ theorem convex_on_real_iff_slope_mono_adjacent {s : set ℝ} (hs : convex s) {f : ℝ β†’ ℝ} : convex_on s f ↔ βˆ€ {x y z : ℝ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f y - f x) / (y - x) ≀ (f z - f y) / (z - y) := { mp := convex_on.slope_mono_adjacent, mpr := convex_on_real_of_slope_mono_adjacent hs } /-- For a function `f` defined on a convex subset `D` of `ℝ`, if for any three points `x<y<z` the slope of the secant line of `f` on `[x, y]` is greater than or equal to the slope of the secant line of `f` on `[x, z]`, then `f` is concave on `D`. -/ theorem concave_on_real_of_slope_mono_adjacent {s : set ℝ} (hs : convex s) {f : ℝ β†’ ℝ} (hf : βˆ€ {x y z : ℝ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x)) : concave_on s f := sorry /-- For a function `f` defined on a subset `D` of `ℝ`, if `f` is concave on `D`, then for any three points `x<y<z`, the slope of the secant line of `f` on `[x, y]` is greater than or equal to the slope of the secant line of `f` on `[x, z]`. -/ theorem concave_on.slope_mono_adjacent {s : set ℝ} {f : ℝ β†’ ℝ} (hf : concave_on s f) {x : ℝ} {y : ℝ} {z : ℝ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := sorry /-- For a function `f` defined on a convex subset `D` of `ℝ`, `f` is concave on `D` iff for any three points `x<y<z` the slope of the secant line of `f` on `[x, y]` is greater than or equal to the slope of the secant line of `f` on `[x, z]`. -/ theorem concave_on_real_iff_slope_mono_adjacent {s : set ℝ} (hs : convex s) {f : ℝ β†’ ℝ} : concave_on s f ↔ βˆ€ {x y z : ℝ}, x ∈ s β†’ z ∈ s β†’ x < y β†’ y < z β†’ (f z - f y) / (z - y) ≀ (f y - f x) / (y - x) := { mp := concave_on.slope_mono_adjacent, mpr := concave_on_real_of_slope_mono_adjacent hs } theorem convex_on.subset {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] {t : set E} {f : E β†’ Ξ²} (h_convex_on : convex_on t f) (h_subset : s βŠ† t) (h_convex : convex s) : convex_on s f := { left := h_convex, right := fun (x y : E) (hx : x ∈ s) (hy : y ∈ s) => and.right h_convex_on x y (h_subset hx) (h_subset hy) } theorem concave_on.subset {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] {t : set E} {f : E β†’ Ξ²} (h_concave_on : concave_on t f) (h_subset : s βŠ† t) (h_convex : convex s) : concave_on s f := convex_on.subset h_concave_on h_subset h_convex theorem convex_on.add {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] {f : E β†’ Ξ²} {g : E β†’ Ξ²} (hf : convex_on s f) (hg : convex_on s g) : convex_on s fun (x : E) => f x + g x := sorry theorem concave_on.add {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] {f : E β†’ Ξ²} {g : E β†’ Ξ²} (hf : concave_on s f) (hg : concave_on s g) : concave_on s fun (x : E) => f x + g x := convex_on.add hf hg theorem convex_on.smul {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] [ordered_semimodule ℝ Ξ²] {f : E β†’ Ξ²} {c : ℝ} (hc : 0 ≀ c) (hf : convex_on s f) : convex_on s fun (x : E) => c β€’ f x := sorry theorem concave_on.smul {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] [ordered_semimodule ℝ Ξ²] {f : E β†’ Ξ²} {c : ℝ} (hc : 0 ≀ c) (hf : concave_on s f) : concave_on s fun (x : E) => c β€’ f x := convex_on.smul hc hf /-- A convex function on a segment is upper-bounded by the max of its endpoints. -/ theorem convex_on.le_on_segment' {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ³ : Type u_1} [linear_ordered_add_comm_group Ξ³] [semimodule ℝ Ξ³] [ordered_semimodule ℝ Ξ³] {f : E β†’ Ξ³} {x : E} {y : E} {a : ℝ} {b : ℝ} (hf : convex_on s f) (hx : x ∈ s) (hy : y ∈ s) (ha : 0 ≀ a) (hb : 0 ≀ b) (hab : a + b = 1) : f (a β€’ x + b β€’ y) ≀ max (f x) (f y) := sorry /-- A concave function on a segment is lower-bounded by the min of its endpoints. -/ theorem concave_on.le_on_segment' {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ³ : Type u_1} [linear_ordered_add_comm_group Ξ³] [semimodule ℝ Ξ³] [ordered_semimodule ℝ Ξ³] {f : E β†’ Ξ³} {x : E} {y : E} {a : ℝ} {b : ℝ} (hf : concave_on s f) (hx : x ∈ s) (hy : y ∈ s) (ha : 0 ≀ a) (hb : 0 ≀ b) (hab : a + b = 1) : min (f x) (f y) ≀ f (a β€’ x + b β€’ y) := convex_on.le_on_segment' hf hx hy ha hb hab /-- A convex function on a segment is upper-bounded by the max of its endpoints. -/ theorem convex_on.le_on_segment {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ³ : Type u_1} [linear_ordered_add_comm_group Ξ³] [semimodule ℝ Ξ³] [ordered_semimodule ℝ Ξ³] {f : E β†’ Ξ³} (hf : convex_on s f) {x : E} {y : E} {z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ segment x y) : f z ≀ max (f x) (f y) := sorry /-- A concave function on a segment is lower-bounded by the min of its endpoints. -/ theorem concave_on.le_on_segment {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ³ : Type u_1} [linear_ordered_add_comm_group Ξ³] [semimodule ℝ Ξ³] [ordered_semimodule ℝ Ξ³] {f : E β†’ Ξ³} (hf : concave_on s f) {x : E} {y : E} {z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ segment x y) : min (f x) (f y) ≀ f z := convex_on.le_on_segment hf hx hy hz theorem convex_on.convex_le {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] [ordered_semimodule ℝ Ξ²] {f : E β†’ Ξ²} (hf : convex_on s f) (r : Ξ²) : convex (has_sep.sep (fun (x : E) => f x ≀ r) s) := sorry theorem concave_on.concave_le {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] [ordered_semimodule ℝ Ξ²] {f : E β†’ Ξ²} (hf : concave_on s f) (r : Ξ²) : convex (has_sep.sep (fun (x : E) => r ≀ f x) s) := convex_on.convex_le hf r theorem convex_on.convex_lt {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ³ : Type u_1} [ordered_cancel_add_comm_monoid Ξ³] [semimodule ℝ Ξ³] [ordered_semimodule ℝ Ξ³] {f : E β†’ Ξ³} (hf : convex_on s f) (r : Ξ³) : convex (has_sep.sep (fun (x : E) => f x < r) s) := sorry theorem concave_on.convex_lt {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ³ : Type u_1} [ordered_cancel_add_comm_monoid Ξ³] [semimodule ℝ Ξ³] [ordered_semimodule ℝ Ξ³] {f : E β†’ Ξ³} (hf : concave_on s f) (r : Ξ³) : convex (has_sep.sep (fun (x : E) => r < f x) s) := convex_on.convex_lt hf r theorem convex_on.convex_epigraph {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ³ : Type u_1} [ordered_add_comm_group Ξ³] [semimodule ℝ Ξ³] [ordered_semimodule ℝ Ξ³] {f : E β†’ Ξ³} (hf : convex_on s f) : convex (set_of fun (p : E Γ— Ξ³) => prod.fst p ∈ s ∧ f (prod.fst p) ≀ prod.snd p) := sorry theorem concave_on.convex_hypograph {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ³ : Type u_1} [ordered_add_comm_group Ξ³] [semimodule ℝ Ξ³] [ordered_semimodule ℝ Ξ³] {f : E β†’ Ξ³} (hf : concave_on s f) : convex (set_of fun (p : E Γ— Ξ³) => prod.fst p ∈ s ∧ prod.snd p ≀ f (prod.fst p)) := convex_on.convex_epigraph hf theorem convex_on_iff_convex_epigraph {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ³ : Type u_1} [ordered_add_comm_group Ξ³] [semimodule ℝ Ξ³] [ordered_semimodule ℝ Ξ³] {f : E β†’ Ξ³} : convex_on s f ↔ convex (set_of fun (p : E Γ— Ξ³) => prod.fst p ∈ s ∧ f (prod.fst p) ≀ prod.snd p) := sorry theorem concave_on_iff_convex_hypograph {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {Ξ³ : Type u_1} [ordered_add_comm_group Ξ³] [semimodule ℝ Ξ³] [ordered_semimodule ℝ Ξ³] {f : E β†’ Ξ³} : concave_on s f ↔ convex (set_of fun (p : E Γ— Ξ³) => prod.fst p ∈ s ∧ prod.snd p ≀ f (prod.fst p)) := convex_on_iff_convex_epigraph /-- If a function is convex on `s`, it remains convex when precomposed by an affine map. -/ theorem convex_on.comp_affine_map {E : Type u} {F : Type v} [add_comm_group E] [vector_space ℝ E] [add_comm_group F] [vector_space ℝ F] {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] {f : F β†’ Ξ²} (g : affine_map ℝ E F) {s : set F} (hf : convex_on s f) : convex_on (⇑g ⁻¹' s) (f ∘ ⇑g) := sorry /-- If a function is concave on `s`, it remains concave when precomposed by an affine map. -/ theorem concave_on.comp_affine_map {E : Type u} {F : Type v} [add_comm_group E] [vector_space ℝ E] [add_comm_group F] [vector_space ℝ F] {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] {f : F β†’ Ξ²} (g : affine_map ℝ E F) {s : set F} (hf : concave_on s f) : concave_on (⇑g ⁻¹' s) (f ∘ ⇑g) := convex_on.comp_affine_map g hf /-- If `g` is convex on `s`, so is `(g ∘ f)` on `f ⁻¹' s` for a linear `f`. -/ theorem convex_on.comp_linear_map {E : Type u} {F : Type v} [add_comm_group E] [vector_space ℝ E] [add_comm_group F] [vector_space ℝ F] {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] {g : F β†’ Ξ²} {s : set F} (hg : convex_on s g) (f : linear_map ℝ E F) : convex_on (⇑f ⁻¹' s) (g ∘ ⇑f) := convex_on.comp_affine_map (linear_map.to_affine_map f) hg /-- If `g` is concave on `s`, so is `(g ∘ f)` on `f ⁻¹' s` for a linear `f`. -/ theorem concave_on.comp_linear_map {E : Type u} {F : Type v} [add_comm_group E] [vector_space ℝ E] [add_comm_group F] [vector_space ℝ F] {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] {g : F β†’ Ξ²} {s : set F} (hg : concave_on s g) (f : linear_map ℝ E F) : concave_on (⇑f ⁻¹' s) (g ∘ ⇑f) := concave_on.comp_affine_map (linear_map.to_affine_map f) hg /-- If a function is convex on `s`, it remains convex after a translation. -/ theorem convex_on.translate_right {E : Type u} [add_comm_group E] [vector_space ℝ E] {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] {f : E β†’ Ξ²} {s : set E} {a : E} (hf : convex_on s f) : convex_on ((fun (z : E) => a + z) ⁻¹' s) (f ∘ fun (z : E) => a + z) := convex_on.comp_affine_map (affine_map.const ℝ E a +α΅₯ affine_map.id ℝ E) hf /-- If a function is concave on `s`, it remains concave after a translation. -/ theorem concave_on.translate_right {E : Type u} [add_comm_group E] [vector_space ℝ E] {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] {f : E β†’ Ξ²} {s : set E} {a : E} (hf : concave_on s f) : concave_on ((fun (z : E) => a + z) ⁻¹' s) (f ∘ fun (z : E) => a + z) := concave_on.comp_affine_map (affine_map.const ℝ E a +α΅₯ affine_map.id ℝ E) hf /-- If a function is convex on `s`, it remains convex after a translation. -/ theorem convex_on.translate_left {E : Type u} [add_comm_group E] [vector_space ℝ E] {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] {f : E β†’ Ξ²} {s : set E} {a : E} (hf : convex_on s f) : convex_on ((fun (z : E) => a + z) ⁻¹' s) (f ∘ fun (z : E) => z + a) := sorry /-- If a function is concave on `s`, it remains concave after a translation. -/ theorem concave_on.translate_left {E : Type u} [add_comm_group E] [vector_space ℝ E] {Ξ² : Type u_1} [ordered_add_comm_monoid Ξ²] [semimodule ℝ Ξ²] {f : E β†’ Ξ²} {s : set E} {a : E} (hf : concave_on s f) : concave_on ((fun (z : E) => a + z) ⁻¹' s) (f ∘ fun (z : E) => z + a) := sorry /-! ### Center of mass -/ /-- Center of mass of a finite collection of points with prescribed weights. Note that we require neither `0 ≀ w i` nor `βˆ‘ w = 1`. -/ def finset.center_mass {E : Type u} {ΞΉ : Type w} [add_comm_group E] [vector_space ℝ E] (t : finset ΞΉ) (w : ΞΉ β†’ ℝ) (z : ΞΉ β†’ E) : E := (finset.sum t fun (i : ΞΉ) => w i)⁻¹ β€’ finset.sum t fun (i : ΞΉ) => w i β€’ z i theorem finset.center_mass_empty {E : Type u} {ΞΉ : Type w} [add_comm_group E] [vector_space ℝ E] (w : ΞΉ β†’ ℝ) (z : ΞΉ β†’ E) : finset.center_mass βˆ… w z = 0 := sorry theorem finset.center_mass_pair {E : Type u} {ΞΉ : Type w} [add_comm_group E] [vector_space ℝ E] (i : ΞΉ) (j : ΞΉ) (w : ΞΉ β†’ ℝ) (z : ΞΉ β†’ E) (hne : i β‰  j) : finset.center_mass (insert i (singleton j)) w z = (w i / (w i + w j)) β€’ z i + (w j / (w i + w j)) β€’ z j := sorry theorem finset.center_mass_insert {E : Type u} {ΞΉ : Type w} [add_comm_group E] [vector_space ℝ E] (i : ΞΉ) (t : finset ΞΉ) {w : ΞΉ β†’ ℝ} (z : ΞΉ β†’ E) (ha : Β¬i ∈ t) (hw : (finset.sum t fun (j : ΞΉ) => w j) β‰  0) : finset.center_mass (insert i t) w z = (w i / (w i + finset.sum t fun (j : ΞΉ) => w j)) β€’ z i + ((finset.sum t fun (j : ΞΉ) => w j) / (w i + finset.sum t fun (j : ΞΉ) => w j)) β€’ finset.center_mass t w z := sorry theorem finset.center_mass_singleton {E : Type u} {ΞΉ : Type w} [add_comm_group E] [vector_space ℝ E] (i : ΞΉ) {w : ΞΉ β†’ ℝ} (z : ΞΉ β†’ E) (hw : w i β‰  0) : finset.center_mass (singleton i) w z = z i := sorry theorem finset.center_mass_eq_of_sum_1 {E : Type u} {ΞΉ : Type w} [add_comm_group E] [vector_space ℝ E] (t : finset ΞΉ) {w : ΞΉ β†’ ℝ} (z : ΞΉ β†’ E) (hw : (finset.sum t fun (i : ΞΉ) => w i) = 1) : finset.center_mass t w z = finset.sum t fun (i : ΞΉ) => w i β€’ z i := sorry theorem finset.center_mass_smul {E : Type u} {ΞΉ : Type w} [add_comm_group E] [vector_space ℝ E] (c : ℝ) (t : finset ΞΉ) {w : ΞΉ β†’ ℝ} (z : ΞΉ β†’ E) : (finset.center_mass t w fun (i : ΞΉ) => c β€’ z i) = c β€’ finset.center_mass t w z := sorry /-- A convex combination of two centers of mass is a center of mass as well. This version deals with two different index types. -/ theorem finset.center_mass_segment' {E : Type u} {ΞΉ : Type w} {ΞΉ' : Type x} [add_comm_group E] [vector_space ℝ E] (s : finset ΞΉ) (t : finset ΞΉ') (ws : ΞΉ β†’ ℝ) (zs : ΞΉ β†’ E) (wt : ΞΉ' β†’ ℝ) (zt : ΞΉ' β†’ E) (hws : (finset.sum s fun (i : ΞΉ) => ws i) = 1) (hwt : (finset.sum t fun (i : ΞΉ') => wt i) = 1) (a : ℝ) (b : ℝ) (hab : a + b = 1) : a β€’ finset.center_mass s ws zs + b β€’ finset.center_mass t wt zt = finset.center_mass (finset.map function.embedding.inl s βˆͺ finset.map function.embedding.inr t) (sum.elim (fun (i : ΞΉ) => a * ws i) fun (j : ΞΉ') => b * wt j) (sum.elim zs zt) := sorry /-- A convex combination of two centers of mass is a center of mass as well. This version works if two centers of mass share the set of original points. -/ theorem finset.center_mass_segment {E : Type u} {ΞΉ : Type w} [add_comm_group E] [vector_space ℝ E] (s : finset ΞΉ) (w₁ : ΞΉ β†’ ℝ) (wβ‚‚ : ΞΉ β†’ ℝ) (z : ΞΉ β†’ E) (hw₁ : (finset.sum s fun (i : ΞΉ) => w₁ i) = 1) (hwβ‚‚ : (finset.sum s fun (i : ΞΉ) => wβ‚‚ i) = 1) (a : ℝ) (b : ℝ) (hab : a + b = 1) : a β€’ finset.center_mass s w₁ z + b β€’ finset.center_mass s wβ‚‚ z = finset.center_mass s (fun (i : ΞΉ) => a * w₁ i + b * wβ‚‚ i) z := sorry theorem finset.center_mass_ite_eq {E : Type u} {ΞΉ : Type w} [add_comm_group E] [vector_space ℝ E] (i : ΞΉ) (t : finset ΞΉ) (z : ΞΉ β†’ E) (hi : i ∈ t) : finset.center_mass t (fun (j : ΞΉ) => ite (i = j) 1 0) z = z i := sorry theorem finset.center_mass_subset {E : Type u} {ΞΉ : Type w} [add_comm_group E] [vector_space ℝ E] {t : finset ΞΉ} {w : ΞΉ β†’ ℝ} (z : ΞΉ β†’ E) {t' : finset ΞΉ} (ht : t βŠ† t') (h : βˆ€ (i : ΞΉ), i ∈ t' β†’ Β¬i ∈ t β†’ w i = 0) : finset.center_mass t w z = finset.center_mass t' w z := sorry theorem finset.center_mass_filter_ne_zero {E : Type u} {ΞΉ : Type w} [add_comm_group E] [vector_space ℝ E] {t : finset ΞΉ} {w : ΞΉ β†’ ℝ} (z : ΞΉ β†’ E) : finset.center_mass (finset.filter (fun (i : ΞΉ) => w i β‰  0) t) w z = finset.center_mass t w z := sorry /-- The center of mass of a finite subset of a convex set belongs to the set provided that all weights are non-negative, and the total weight is positive. -/ theorem convex.center_mass_mem {E : Type u} {ΞΉ : Type w} [add_comm_group E] [vector_space ℝ E] {s : set E} {t : finset ΞΉ} {w : ΞΉ β†’ ℝ} {z : ΞΉ β†’ E} (hs : convex s) : (βˆ€ (i : ΞΉ), i ∈ t β†’ 0 ≀ w i) β†’ (0 < finset.sum t fun (i : ΞΉ) => w i) β†’ (βˆ€ (i : ΞΉ), i ∈ t β†’ z i ∈ s) β†’ finset.center_mass t w z ∈ s := sorry theorem convex.sum_mem {E : Type u} {ΞΉ : Type w} [add_comm_group E] [vector_space ℝ E] {s : set E} {t : finset ΞΉ} {w : ΞΉ β†’ ℝ} {z : ΞΉ β†’ E} (hs : convex s) (hβ‚€ : βˆ€ (i : ΞΉ), i ∈ t β†’ 0 ≀ w i) (h₁ : (finset.sum t fun (i : ΞΉ) => w i) = 1) (hz : βˆ€ (i : ΞΉ), i ∈ t β†’ z i ∈ s) : (finset.sum t fun (i : ΞΉ) => w i β€’ z i) ∈ s := sorry theorem convex_iff_sum_mem {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} : convex s ↔ βˆ€ (t : finset E) (w : E β†’ ℝ), (βˆ€ (i : E), i ∈ t β†’ 0 ≀ w i) β†’ (finset.sum t fun (i : E) => w i) = 1 β†’ (βˆ€ (x : E), x ∈ t β†’ x ∈ s) β†’ (finset.sum t fun (x : E) => w x β€’ x) ∈ s := sorry /-- Jensen's inequality, `finset.center_mass` version. -/ theorem convex_on.map_center_mass_le {E : Type u} {ΞΉ : Type w} [add_comm_group E] [vector_space ℝ E] {s : set E} {t : finset ΞΉ} {w : ΞΉ β†’ ℝ} {z : ΞΉ β†’ E} {f : E β†’ ℝ} (hf : convex_on s f) (hβ‚€ : βˆ€ (i : ΞΉ), i ∈ t β†’ 0 ≀ w i) (hpos : 0 < finset.sum t fun (i : ΞΉ) => w i) (hmem : βˆ€ (i : ΞΉ), i ∈ t β†’ z i ∈ s) : f (finset.center_mass t w z) ≀ finset.center_mass t w (f ∘ z) := sorry /-- Jensen's inequality, `finset.sum` version. -/ theorem convex_on.map_sum_le {E : Type u} {ΞΉ : Type w} [add_comm_group E] [vector_space ℝ E] {s : set E} {t : finset ΞΉ} {w : ΞΉ β†’ ℝ} {z : ΞΉ β†’ E} {f : E β†’ ℝ} (hf : convex_on s f) (hβ‚€ : βˆ€ (i : ΞΉ), i ∈ t β†’ 0 ≀ w i) (h₁ : (finset.sum t fun (i : ΞΉ) => w i) = 1) (hmem : βˆ€ (i : ΞΉ), i ∈ t β†’ z i ∈ s) : f (finset.sum t fun (i : ΞΉ) => w i β€’ z i) ≀ finset.sum t fun (i : ΞΉ) => w i * f (z i) := sorry /-- If a function `f` is convex on `s` takes value `y` at the center of mass of some points `z i ∈ s`, then for some `i` we have `y ≀ f (z i)`. -/ theorem convex_on.exists_ge_of_center_mass {E : Type u} {ΞΉ : Type w} [add_comm_group E] [vector_space ℝ E] {s : set E} {t : finset ΞΉ} {w : ΞΉ β†’ ℝ} {z : ΞΉ β†’ E} {f : E β†’ ℝ} (h : convex_on s f) (hwβ‚€ : βˆ€ (i : ΞΉ), i ∈ t β†’ 0 ≀ w i) (hws : 0 < finset.sum t fun (i : ΞΉ) => w i) (hz : βˆ€ (i : ΞΉ), i ∈ t β†’ z i ∈ s) : βˆƒ (i : ΞΉ), βˆƒ (H : i ∈ t), f (finset.center_mass t w z) ≀ f (z i) := sorry /-! ### Convex hull -/ /-- The convex hull of a set `s` is the minimal convex set that includes `s`. -/ def convex_hull {E : Type u} [add_comm_group E] [vector_space ℝ E] (s : set E) : set E := set.Inter fun (t : set E) => set.Inter fun (hst : s βŠ† t) => set.Inter fun (ht : convex t) => t theorem subset_convex_hull {E : Type u} [add_comm_group E] [vector_space ℝ E] (s : set E) : s βŠ† convex_hull s := set.subset_Inter fun (t : set E) => set.subset_Inter fun (hst : s βŠ† t) => set.subset_Inter fun (ht : convex t) => hst theorem convex_convex_hull {E : Type u} [add_comm_group E] [vector_space ℝ E] (s : set E) : convex (convex_hull s) := convex_Inter fun (t : set E) => convex_Inter fun (ht : s βŠ† t) => convex_Inter id theorem convex_hull_min {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {t : set E} (hst : s βŠ† t) (ht : convex t) : convex_hull s βŠ† t := set.Inter_subset_of_subset t (set.Inter_subset_of_subset hst (set.Inter_subset (fun (ht : convex t) => t) ht)) theorem convex_hull_mono {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {t : set E} (hst : s βŠ† t) : convex_hull s βŠ† convex_hull t := convex_hull_min (set.subset.trans hst (subset_convex_hull t)) (convex_convex_hull t) theorem convex.convex_hull_eq {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} (hs : convex s) : convex_hull s = s := set.subset.antisymm (convex_hull_min (set.subset.refl s) hs) (subset_convex_hull s) @[simp] theorem convex_hull_singleton {E : Type u} [add_comm_group E] [vector_space ℝ E] {x : E} : convex_hull (singleton x) = singleton x := convex.convex_hull_eq (convex_singleton x) theorem is_linear_map.image_convex_hull {E : Type u} {F : Type v} [add_comm_group E] [vector_space ℝ E] [add_comm_group F] [vector_space ℝ F] {s : set E} {f : E β†’ F} (hf : is_linear_map ℝ f) : f '' convex_hull s = convex_hull (f '' s) := sorry theorem linear_map.image_convex_hull {E : Type u} {F : Type v} [add_comm_group E] [vector_space ℝ E] [add_comm_group F] [vector_space ℝ F] {s : set E} (f : linear_map ℝ E F) : ⇑f '' convex_hull s = convex_hull (⇑f '' s) := is_linear_map.image_convex_hull (linear_map.is_linear f) theorem finset.center_mass_mem_convex_hull {E : Type u} {ΞΉ : Type w} [add_comm_group E] [vector_space ℝ E] {s : set E} (t : finset ΞΉ) {w : ΞΉ β†’ ℝ} (hwβ‚€ : βˆ€ (i : ΞΉ), i ∈ t β†’ 0 ≀ w i) (hws : 0 < finset.sum t fun (i : ΞΉ) => w i) {z : ΞΉ β†’ E} (hz : βˆ€ (i : ΞΉ), i ∈ t β†’ z i ∈ s) : finset.center_mass t w z ∈ convex_hull s := convex.center_mass_mem (convex_convex_hull s) hwβ‚€ hws fun (i : ΞΉ) (hi : i ∈ t) => subset_convex_hull s (hz i hi) -- TODO : Do we need other versions of the next lemma? /-- Convex hull of `s` is equal to the set of all centers of masses of `finset`s `t`, `z '' t βŠ† s`. This version allows finsets in any type in any universe. -/ theorem convex_hull_eq {E : Type u} [add_comm_group E] [vector_space ℝ E] (s : set E) : convex_hull s = set_of fun (x : E) => βˆƒ (ΞΉ : Type u'), βˆƒ (t : finset ΞΉ), βˆƒ (w : ΞΉ β†’ ℝ), βˆƒ (z : ΞΉ β†’ E), βˆƒ (hwβ‚€ : βˆ€ (i : ΞΉ), i ∈ t β†’ 0 ≀ w i), βˆƒ (hw₁ : (finset.sum t fun (i : ΞΉ) => w i) = 1), βˆƒ (hz : βˆ€ (i : ΞΉ), i ∈ t β†’ z i ∈ s), finset.center_mass t w z = x := sorry /-- Maximum principle for convex functions. If a function `f` is convex on the convex hull of `s`, then `f` can't have a maximum on `convex_hull s` outside of `s`. -/ theorem convex_on.exists_ge_of_mem_convex_hull {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} {f : E β†’ ℝ} (hf : convex_on (convex_hull s) f) {x : E} (hx : x ∈ convex_hull s) : βˆƒ (y : E), βˆƒ (H : y ∈ s), f x ≀ f y := sorry theorem finset.convex_hull_eq {E : Type u} [add_comm_group E] [vector_space ℝ E] (s : finset E) : convex_hull ↑s = set_of fun (x : E) => βˆƒ (w : E β†’ ℝ), βˆƒ (hwβ‚€ : βˆ€ (y : E), y ∈ s β†’ 0 ≀ w y), βˆƒ (hw₁ : (finset.sum s fun (y : E) => w y) = 1), finset.center_mass s w id = x := sorry theorem set.finite.convex_hull_eq {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} (hs : set.finite s) : convex_hull s = set_of fun (x : E) => βˆƒ (w : E β†’ ℝ), βˆƒ (hwβ‚€ : βˆ€ (y : E), y ∈ s β†’ 0 ≀ w y), βˆƒ (hw₁ : (finset.sum (set.finite.to_finset hs) fun (y : E) => w y) = 1), finset.center_mass (set.finite.to_finset hs) w id = x := sorry theorem convex_hull_eq_union_convex_hull_finite_subsets {E : Type u} [add_comm_group E] [vector_space ℝ E] (s : set E) : convex_hull s = set.Union fun (t : finset E) => set.Union fun (w : ↑t βŠ† s) => convex_hull ↑t := sorry theorem is_linear_map.convex_hull_image {E : Type u} {F : Type v} [add_comm_group E] [vector_space ℝ E] [add_comm_group F] [vector_space ℝ F] {f : E β†’ F} (hf : is_linear_map ℝ f) (s : set E) : convex_hull (f '' s) = f '' convex_hull s := sorry theorem linear_map.convex_hull_image {E : Type u} {F : Type v} [add_comm_group E] [vector_space ℝ E] [add_comm_group F] [vector_space ℝ F] (f : linear_map ℝ E F) (s : set E) : convex_hull (⇑f '' s) = ⇑f '' convex_hull s := is_linear_map.convex_hull_image (linear_map.is_linear f) s /-! ### Simplex -/ /-- The standard simplex in the space of functions `ΞΉ β†’ ℝ` is the set of vectors with non-negative coordinates with total sum `1`. -/ def std_simplex (ΞΉ : Type u_1) [fintype ΞΉ] : set (ΞΉ β†’ ℝ) := set_of fun (f : ΞΉ β†’ ℝ) => (βˆ€ (x : ΞΉ), 0 ≀ f x) ∧ (finset.sum finset.univ fun (x : ΞΉ) => f x) = 1 theorem std_simplex_eq_inter (ΞΉ : Type w) [fintype ΞΉ] : std_simplex ΞΉ = (set.Inter fun (x : ΞΉ) => set_of fun (f : ΞΉ β†’ ℝ) => 0 ≀ f x) ∩ set_of fun (f : ΞΉ β†’ ℝ) => (finset.sum finset.univ fun (x : ΞΉ) => f x) = 1 := sorry theorem convex_std_simplex (ΞΉ : Type w) [fintype ΞΉ] : convex (std_simplex ΞΉ) := sorry theorem ite_eq_mem_std_simplex {ΞΉ : Type w} [fintype ΞΉ] (i : ΞΉ) : (fun (j : ΞΉ) => ite (i = j) 1 0) ∈ std_simplex ΞΉ := sorry /-- `std_simplex ΞΉ` is the convex hull of the canonical basis in `ΞΉ β†’ ℝ`. -/ theorem convex_hull_basis_eq_std_simplex {ΞΉ : Type w} [fintype ΞΉ] : convex_hull (set.range fun (i j : ΞΉ) => ite (i = j) 1 0) = std_simplex ΞΉ := sorry /-- The convex hull of a finite set is the image of the standard simplex in `s β†’ ℝ` under the linear map sending each function `w` to `βˆ‘ x in s, w x β€’ x`. Since we have no sums over finite sets, we use sum over `@finset.univ _ hs.fintype`. The map is defined in terms of operations on `(s β†’ ℝ) β†’β‚—[ℝ] ℝ` so that later we will not need to prove that this map is linear. -/ theorem set.finite.convex_hull_eq_image {E : Type u} [add_comm_group E] [vector_space ℝ E] {s : set E} (hs : set.finite s) : convex_hull s = ⇑(finset.sum finset.univ fun (x : β†₯s) => linear_map.smul_right (linear_map.proj x) (subtype.val x)) '' std_simplex β†₯s := sorry /-- All values of a function `f ∈ std_simplex ΞΉ` belong to `[0, 1]`. -/ theorem mem_Icc_of_mem_std_simplex {ΞΉ : Type w} [fintype ΞΉ] {f : ΞΉ β†’ ℝ} (hf : f ∈ std_simplex ΞΉ) (x : ΞΉ) : f x ∈ set.Icc 0 1 := { left := and.left hf x, right := and.right hf β–Έ finset.single_le_sum (fun (y : ΞΉ) (hy : y ∈ finset.univ) => and.left hf y) (finset.mem_univ x) } end Mathlib
/- Copyright (c) 2022 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll ! This file was ported from Lean 3 source module data.fin.tuple.bubble_sort_induction ! leanprover-community/mathlib commit 4c19a16e4b705bf135cf9a80ac18fcc99c438514 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathlib.Data.Fin.Tuple.Sort import Mathlib.Data.Fintype.Perm import Mathlib.Order.WellFounded /-! # "Bubble sort" induction We implement the following induction principle `Tuple.bubble_sort_induction` on tuples with values in a linear order `Ξ±`. Let `f : Fin n β†’ Ξ±` and let `P` be a predicate on `Fin n β†’ Ξ±`. Then we can show that `f ∘ sort f` satisfies `P` if `f` satisfies `P`, and whenever some `g : Fin n β†’ Ξ±` satisfies `P` and `g i > g j` for some `i < j`, then `g ∘ swap i j` also satisfies `P`. We deduce it from a stronger variant `Tuple.bubble_sort_induction'`, which requires the assumption only for `g` that are permutations of `f`. The latter is proved by well-founded induction via `WellFounded.induction_bot'` with respect to the lexicographic ordering on the finite set of all permutations of `f`. -/ namespace Tuple /-- *Bubble sort induction*: Prove that the sorted version of `f` has some property `P` if `f` satsifies `P` and `P` is preserved on permutations of `f` when swapping two antitone values. -/ theorem bubble_sort_induction' {n : β„•} {Ξ± : Type _} [LinearOrder Ξ±] {f : Fin n β†’ Ξ±} {P : (Fin n β†’ Ξ±) β†’ Prop} (hf : P f) (h : βˆ€ (Οƒ : Equiv.Perm (Fin n)) (i j : Fin n), i < j β†’ (f ∘ Οƒ) j < (f ∘ Οƒ) i β†’ P (f ∘ Οƒ) β†’ P (f ∘ Οƒ ∘ Equiv.swap i j)) : P (f ∘ sort f) := by letI := @Preorder.lift _ (Lex (Fin n β†’ Ξ±)) _ fun Οƒ : Equiv.Perm (Fin n) => toLex (f ∘ Οƒ) refine' @WellFounded.induction_bot' _ _ _ (@Finite.Preorder.wellFounded_lt (Equiv.Perm (Fin n)) _ _) (Equiv.refl _) (sort f) P (fun Οƒ => f ∘ Οƒ) (fun Οƒ hΟƒ hfΟƒ => _) hf obtain ⟨i, j, hij₁, hijβ‚‚βŸ© := antitone_pair_of_not_sorted' hΟƒ exact βŸ¨Οƒ * Equiv.swap i j, Pi.lex_desc hij₁ hijβ‚‚, h Οƒ i j hij₁ hijβ‚‚ hfΟƒβŸ© #align tuple.bubble_sort_induction' Tuple.bubble_sort_induction' /-- *Bubble sort induction*: Prove that the sorted version of `f` has some property `P` if `f` satsifies `P` and `P` is preserved when swapping two antitone values. -/ theorem bubble_sort_induction {n : β„•} {Ξ± : Type _} [LinearOrder Ξ±] {f : Fin n β†’ Ξ±} {P : (Fin n β†’ Ξ±) β†’ Prop} (hf : P f) (h : βˆ€ (g : Fin n β†’ Ξ±) (i j : Fin n), i < j β†’ g j < g i β†’ P g β†’ P (g ∘ Equiv.swap i j)) : P (f ∘ sort f) := bubble_sort_induction' hf fun _ => h _ #align tuple.bubble_sort_induction Tuple.bubble_sort_induction end Tuple
import hilbert.wr.or import hilbert.wr.or_bot namespace clfrags namespace hilbert namespace wr namespace or_bot theorem db₁_or {a b : Prop} (h₁ : or b (or a bot)) : or b a := have hβ‚‚ : or (or b a) bot, from or.dβ‚„ h₁, show or b a, from db₁ hβ‚‚ theorem b₁ {a : Prop} (h₁ : bot) : a := have hβ‚‚ : or bot a, from or.d₁ h₁, have h₃ : or a bot, from or.d₃ hβ‚‚, show a, from db₁ h₃ end or_bot end wr end hilbert end clfrags
Require ILLImplementation. Require ResILLBase. Extract Inductive bool => "bool" [ "true" "false" ]. Extract Inductive sumbool => "bool" ["true" "false" ]. Extract Inductive sumor => "option" ["Some" "None" ]. Extract Inductive option => "option" ["Some" "None" ]. Extract Inductive unit => "unit" ["()"]. Extract Inductive nat => "Common.Types.nat" ["Common.Types.O" "Common.Types.S"]. Extract Inductive list => "list" [ "[]" "(::)" ]. Extract Inductive prod => "(*)" [ "(,)" ]. Recursive Extraction Library ILLImplementation. Recursive Extraction Library ResILLBase. (* Local Variables: coq-prog-args: ("-emacs-U" "-I" ".." "-R" "." "ILL") End: *)
[STATEMENT] lemma rule_states_l_correct[simp]: "ls_\<alpha> (rule_states_l r) = rule_states r" "ls_invar (rule_states_l r)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. ls.\<alpha> (rule_states_l r) = rule_states r &&& ls.invar (rule_states_l r) [PROOF STEP] by (cases r, simp add: ls.correct)+
import algebra.group_power tactic.norm_num algebra.big_operators theorem Q2 (n : β„•) : n β‰₯ 2 β†’ nat.pow 4 n > nat.pow 3 n + nat.pow 2 n :=
PRINT X ++ 5 END
State Before: f g : β„‚ β†’ β„‚ s : Set β„‚ f' g' x c : β„‚ ⊒ ↑((g x * f x ^ (g x - 1)) β€’ ContinuousLinearMap.smulRight 1 f' + (f x ^ g x * log (f x)) β€’ ContinuousLinearMap.smulRight 1 g') 1 = g x * f x ^ (g x - 1) * f' + f x ^ g x * log (f x) * g' State After: no goals Tactic: simp only [Algebra.id.smul_eq_mul, one_mul, ContinuousLinearMap.one_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.add_apply, Pi.smul_apply, ContinuousLinearMap.coe_smul']
[STATEMENT] lemma eval_tm_SNOC[simp]: "\<lbrakk>length is \<le> #\<^sub>V \<AA>; #\<^sub>V \<AA> = length x\<rbrakk> \<Longrightarrow> eval_tm (SNOC x \<AA>) is = eval_tm \<AA> is + 2 ^ Length \<AA> * scalar_product x is" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>length is \<le> #\<^sub>V \<AA>; #\<^sub>V \<AA> = length x\<rbrakk> \<Longrightarrow> eval_tm (SNOC x \<AA>) is = eval_tm \<AA> is + 2 ^ Length \<AA> * scalar_product (map of_bool x) is [PROOF STEP] by transfer (auto simp: scalar_product_SNOC[symmetric] intro!: arg_cong2[of _ _ _ _ scalar_product] nth_equalityI)
Welcome to Coq 8.4pl4 (November 2015) Coq < Theorem mult_0_plus' : forall n m : nat, (0 + n) * m = n * m. 1 subgoal ============================ forall n m : nat, (0 + n) * m = n * m mult_0_plus' < Proof. 1 subgoal ============================ forall n m : nat, (0 + n) * m = n * m mult_0_plus' < info_auto. (* info auto : *) intro. intro. apply @eq_refl. No more subgoals. mult_0_plus' < Qed. info_auto. mult_0_plus' is defined
variables (f : β„• β†’ β„•) (a b : β„•) example (h₁ : a = b) (hβ‚‚ : f a = 0) : f b = 0 := begin rw [←h₁, hβ‚‚] end
theory Scratch imports Main begin lemma \<open>\<forall>x. P x\<close> oops text \<open>This is another test. There are multiple things to do. \<close> notepad begin fix S T :: 'a have \<open>T = S\<close> if \<open>S = T\<close> for S using that by auto have \<open>T = S\<close> if \<open>S = T\<close> for S unfolding that by auto end datatype finite_type = A | B instantiation finite_type :: finite begin lemma UNIV_finite_type: \<open>UNIV = {A, B}\<close> apply auto using finite_type.exhaust by blast instance apply standard unfolding UNIV_finite_type apply auto done end proposition fixes x assumes \<open>P x\<close> and \<open>Q x\<close> obtains y z where \<open>y = P x\<close> and \<open>z = Q x\<close> and \<open>True\<close> using TrueI oops lemma \<open>P x\<close> proof - have \<open>P x\<close> if \<open>P x\<close> for x proof - have \<open>P x\<close> if \<open>P x\<close> for x by (use that in auto) have \<open>True\<close> by auto show ?thesis using that by auto qed then show \<open>?thesis\<close> oops lemma \<open>True\<close> .. lemma \<open>P x\<close> if \<open>P x\<close> proof - show \<open>P x\<close> by (use that in auto) qed lemma \<open>P x\<close> for x :: \<open>nat list\<close> proof (induction x) case Nil then show ?case sorry next case (Cons a x) have H: \<open>P \<Longrightarrow> P\<close> for P by auto show ?case apply - apply (rule H) sorry qed lemma \<open>P x\<close> for x :: \<open>nat list\<close> proof - show \<open>P x\<close> for x proof (induction x) case Nil then show ?case sorry next case (Cons a x) then show ?case sorry qed qed section \<open>There is more\<close> subsection \<open>Indented to the right\<close> notepad begin have P if "P ==> P" for P apply (rule that) subgoal sorry done end lemma name_with_boundary: \<open>P \<Longrightarrow> P\<close> by auto lemma \<open>P \<Longrightarrow> P\<close> apply (rule name_with_boundary) oops section \<open>Known indentation bugs\<close> notepad begin have P if "P \<Longrightarrow> P" "P" for P apply (rule that) subgoal apply (rule that(2)) done \<comment> \<open>This done is wrong, but I cannot fix it without knowdegde from the goals.\<close> done end text \<open>The labels in the following predicate is wrongly indented, but jEdit is not better:\<close> inductive rtranclp :: \<open>('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool\<close> for r :: \<open>'a \<Rightarrow> 'a \<Rightarrow> bool\<close> where base: \<open>rtranclp r a a\<close> | step: \<open>rtranclp r a c\<close> if \<open>r a b\<close> \<open>rtranclp r b c\<close> section \<open>Test part\<close> lemma False by auto lemma True by simp lemma True by simp end
#ifndef _GDRDGEMM_H #define _GDRDGEMM_H #ifndef MKL #include <cblas.h> #else #include <mkl_cblas.h> #endif #define NMAT 2048 void gdr_check_and_restart(double a[][NMAT], double b[][NMAT], double c[][NMAT]); void gdrblas_dgemm ( #ifndef MKL const enum CBLAS_ORDER ORDER, const enum CBLAS_TRANSPOSE TRANSA, const enum CBLAS_TRANSPOSE TRANSB, #else const CBLAS_ORDER ORDER, const CBLAS_TRANSPOSE TRANSA, const CBLAS_TRANSPOSE TRANSB, #endif const int M, const int N, const int K, const double ALPHA, const double * A, const int LDA, const double * B, const int LDB, const double BETA, double * C, const int LDC ); void mygdrdgemm(int m, int n, int k, double alpha, double * a, int na, double * b, int nb, double beta, double * c, int nc); #endif
/- Copyright (c) 2022 Jannis Limperg. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Asta H. From, Jannis Limperg -/ -- This test checks whether the output of trace.aesop.proof is -- copy-and-pastable. When the test breaks because Aesop's output has changed, -- please copy-and-paste the output to All.split_consβ‚‚ and check whether it -- still works. import Aesop @[aesop safe [constructors, (cases (patterns := [All _ [], All _ (_ :: _)]))]] inductive All (P : Ξ± β†’ Prop) : List Ξ± β†’ Prop | nil : All P [] | cons {x xs} : P x β†’ All P xs β†’ All P (x :: xs) theorem All.split_cons (P : Ξ± β†’ Prop) (x : Ξ±) (xs : List Ξ±) (h : All P (x :: xs)) : P x ∧ All P xs := by set_option trace.aesop.proof true in aesop set_option linter.unusedVariables false in theorem All.split_consβ‚‚ (P : Ξ± β†’ Prop) (x : Ξ±) (xs : List Ξ±) (h : All P (x :: xs)) : P x ∧ All P xs := (fun (h_1 : All P (x :: xs)) => ((fun (h_2 : All P (x :: xs)) => (All.casesOn (P := P) (motive := fun a x_1 => x :: xs = a β†’ HEq h x_1 β†’ P x ∧ All P xs) h_2 (fun h_1 => List.noConfusion h_1) fun {x_1} {xs_1} a a_1 h_1 => List.noConfusion h_1 fun head_eq => Eq.ndrec (motive := fun {x_1} => βˆ€ (a : P x_1), xs = xs_1 β†’ HEq h (All.cons (P := P) a a_1) β†’ P x ∧ All P xs) (fun a tail_eq => Eq.ndrec (motive := fun {xs_1} => βˆ€ (a_1 : All P xs_1), HEq h (All.cons (P := P) a a_1) β†’ P x ∧ All P xs) (fun a_1 h_1 => Eq.ndrec (motive := fun h => P x ∧ All P xs) (of_eq_true (Eq.trans (congr (congrArg And (eq_true a)) (eq_true a_1)) (and_self True))) (Eq.symm (eq_of_heq h_1))) tail_eq a_1) head_eq a : x :: xs = x :: xs β†’ HEq h h_2 β†’ P x ∧ All P xs)) h_1 : x :: xs = x :: xs β†’ HEq h h_1 β†’ P x ∧ All P xs)) h (Eq.refl (x :: xs)) (HEq.refl h)
theorem my_first_theorem (P : Prop) : P β†’ P := begin intro, assumption, end
informal statement Let $f: S^{1} \rightarrow \mathbb{R}$ be a continuous map. Show there exists a point $x$ of $S^{1}$ such that $f(x)=f(-x)$.formal statement theorem exercise_25_4 {X : Type*} [topological_space X] [loc_path_connected_space X] (U : set X) (hU : is_open U) (hcU : is_connected U) : is_path_connected U :=
/- This example demonstrates why allowing types such as inductive D : Type := | intro : (D β†’ D) β†’ D would make the system inconsistent -/ /- If we were allowed to form the inductive type inductive D : Type := | intro : (D β†’ D) β†’ D we would get the following -/ universe l -- The new type A axiom D : Type.{l} -- The constructor axiom introD : (D β†’ D) β†’ D -- The eliminator axiom recD : Ξ  {C : D β†’ Type}, (Ξ  (f : D β†’ D) (r : Ξ  d, C (f d)), C (introD f)) β†’ (Ξ  (d : D), C d) -- We would also get a computational rule for the eliminator, but we don't need it for deriving the inconsistency. noncomputable definition id' : D β†’ D := Ξ»d, d noncomputable definition v : D := introD id' theorem inconsistent : false := recD (Ξ» f ih, ih v) v
/- Copyright (c) 2021 OpenAI. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f -/ import mathzoo.imports.miniF2F open_locale nat rat real big_operators topological_space theorem mathd_algebra_11 (a b : ℝ) (hβ‚€ : a β‰  b) (h₁ : a β‰  2*b) (hβ‚‚ : (4 * a + 3 * b) / (a - 2 * b) = 5) : (a + 11 * b) / (a - b) = 2 := begin field_simp [*, sub_ne_zero, mul_assoc, mul_comm] at *, linarith, end
lemma iff_trans (P Q R : Prop) : (P ↔ Q) β†’ (Q ↔ R) β†’ (P ↔ R) := begin intros pq qr, split, { intro p, apply qr.1, apply pq.1, exact p, }, { intro r, apply pq.2, apply qr.2, exact r, }, end lemma iff_trans_2 (P Q R : Prop) : (P ↔ Q) β†’ (Q ↔ R) β†’ (P ↔ R) := begin intros pq qr, rw pq, rw qr, end
partial def inf (u : Unit) : List Unit := u :: inf u theorem aa : False := nomatch (⟨inf._unsafe_rec (), rfl⟩ : βˆƒ l, l = () :: l)
lemma le_refl (x : mynat) : x ≀ x := begin use 0, refl, end