text
stringlengths 0
3.34M
|
---|
[STATEMENT]
lemma ent_disjI2_direct[simp]: "B \<Longrightarrow>\<^sub>A A \<or>\<^sub>A B"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. B \<Longrightarrow>\<^sub>A A \<or>\<^sub>A B
[PROOF STEP]
by (simp add: entails_def) |
Load LFindLoad.
From lfind Require Import LFind.
From QuickChick Require Import QuickChick.
From adtind Require Import goal33.
Derive Show for natural.
Derive Arbitrary for natural.
Instance Dec_Eq_natural : Dec_Eq natural.
Proof. dec_eq. Qed.
Lemma conj3eqsynthconj4 : forall (lv0 : natural) (lv1 : natural), (@eq natural (plus lv0 lv1) (plus lv0 lv1)).
Admitted.
QuickChick conj3eqsynthconj4.
|
module ZOOclient
using Base.Dates.now
export Dimension, dim_print
export Objective, get_history_bestsofar, obj_clean_history
export zoo_min
export Parameter, print_population, get_positive_data, get_negative_data
export Solution, sol_print, sol_equal, sol_write, write_population
export zoolog
export rng, my_precision, set_seed, set_precision
export construct_init_sample
include("ZOOclient/utils/tool_function.jl")
include("ZOOclient/utils/zoo_global.jl")
include("ZOOclient/dimension.jl")
include("ZOOclient/objective.jl")
include("ZOOclient/parameter.jl")
include("ZOOclient/solution.jl")
include("ZOOclient/algos/racos/racos_classification.jl")
include("ZOOclient/algos/racos/racos_common.jl")
include("ZOOclient/algos/racos/racos.jl")
include("ZOOclient/algos/racos/sracos.jl")
include("ZOOclient/algos/racos/racos_optimization.jl")
include("ZOOclient/algos/asracos/asracos.jl")
include("ZOOclient/algos/asracos/asracos_opt.jl")
include("ZOOclient/algos/pracos/pracos.jl")
include("ZOOclient/algos/pracos/pracos_opt.jl")
include("ZOOclient/algos/psracos/psracos.jl")
include("ZOOclient/algos/psracos/psracos_opt.jl")
include("ZOOclient/algos/pposs/pposs_opt.jl")
include("ZOOclient/optimize.jl")
end
|
import SOAS.Syntax.Signature as Sig
open import SOAS.Families.Core
-- Term syntax for a signature
module SOAS.Syntax.Term
{T : Set}(open Sig T)
{O : Set}(S : Signature O) where
open import SOAS.Syntax.Arguments {T}
open import SOAS.Metatheory.Syntax {T}
open import SOAS.Common
open import SOAS.Context {T}
open import SOAS.Variable
open import SOAS.Construction.Structure
open import SOAS.ContextMaps.Inductive
open import SOAS.Abstract.Hom
open import Categories.Object.Initial
open import Data.List.Base using (List ; [] ; [_] ; _∷_)
open import Data.Unit
open Signature S
private
variable
α β τ : T
Γ Δ Π : Ctx
module _ (𝔛 : Familyₛ) where
open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛
-- Grammar of terms for a (⅀,𝔛)-meta-algebra
data 𝕋 : Familyₛ where
con : ⅀ 𝕋 τ Γ → 𝕋 τ Γ
var : ℐ τ Γ → 𝕋 τ Γ
mvar : 𝔛 τ Π → Sub 𝕋 Π Γ → 𝕋 τ Γ
Tmᵃ : MetaAlg 𝕋
Tmᵃ = record { 𝑎𝑙𝑔 = con ; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 ε → mvar 𝔪 (tabulate ε) }
-- 𝕋 is the initial meta-algebra
𝕋:Init : Initial 𝕄etaAlgebras
𝕋:Init = record
{ ⊥ = 𝕋 ⋉ Tmᵃ
; ⊥-is-initial = record
{ ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → (𝕤𝕖𝕞 𝒜ᵃ) ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }
; !-unique = λ { {𝒜 ⋉ 𝒜ᵃ}(g ⋉ gᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ gᵃ⇒ t } } }
where
module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where
open MetaAlg 𝒜ᵃ
𝕤𝕖𝕞 : 𝕋 ⇾̣ 𝒜
𝔸 : (as : List (Ctx × T)) → Arg as 𝕋 Γ → Arg as 𝒜 Γ
𝔸 [] tt = tt
𝔸 (_ ∷ []) t = 𝕤𝕖𝕞 t
𝔸 (_ ∷ a ∷ as) (t , ts) = (𝕤𝕖𝕞 t , 𝔸 (a ∷ as) ts)
𝕊 : Sub 𝕋 Π Γ → Π ~[ 𝒜 ]↝ Γ
𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t
𝕊 (t ◂ σ) (old v) = 𝕊 σ v
𝕤𝕖𝕞 (con (o ⋮ a)) = 𝑎𝑙𝑔 (o ⋮ 𝔸 (Arity o) a)
𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v
𝕤𝕖𝕞 (mvar 𝔪 ε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 ε)
𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ Tmᵃ 𝒜ᵃ 𝕤𝕖𝕞
𝕤𝕖𝕞ᵃ⇒ = record
{ ⟨𝑎𝑙𝑔⟩ = λ{ {t = (o ⋮ a)} → cong (λ - → 𝑎𝑙𝑔 (o ⋮ -)) (𝔸-Arg₁ (Arity o) a) }
; ⟨𝑣𝑎𝑟⟩ = refl
; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{ε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab ε)) }
}
where
𝔸-Arg₁ : (as : List (Ctx × T))(a : Arg as 𝕋 Γ)
→ 𝔸 as a ≡ Arg₁ as 𝕤𝕖𝕞 a
𝔸-Arg₁ [] tt = refl
𝔸-Arg₁ (_ ∷ []) t = refl
𝔸-Arg₁ (_ ∷ a ∷ as) (t , ap) = cong (_ ,_) (𝔸-Arg₁ (a ∷ as) ap)
𝕊-tab : (ε : Π ~[ 𝕋 ]↝ Γ)(v : ℐ α Π)
→ 𝕊 (tabulate ε) v ≡ 𝕤𝕖𝕞 (ε v)
𝕊-tab ε new = refl
𝕊-tab ε (old v) = 𝕊-tab (ε ∘ old) v
module _ {g : 𝕋 ⇾̣ 𝒜}(gᵃ⇒ : MetaAlg⇒ Tmᵃ 𝒜ᵃ g) where
open MetaAlg⇒ gᵃ⇒
𝕤𝕖𝕞! : (t : 𝕋 α Γ) → 𝕤𝕖𝕞 t ≡ g t
𝕊-ix : (ε : Sub 𝕋 Π Γ)(v : ℐ α Π) → 𝕊 ε v ≡ g (index ε v)
𝕊-ix (x ◂ ε) new = 𝕤𝕖𝕞! x
𝕊-ix (x ◂ ε) (old v) = 𝕊-ix ε v
𝔸-Arg₁ : (as : List (Ctx × T))(ar : Arg as 𝕋 Γ)
→ 𝔸 as ar ≡ Arg₁ as g ar
𝔸-Arg₁ [] tt = refl
𝔸-Arg₁ (_ ∷ []) t = 𝕤𝕖𝕞! t
𝔸-Arg₁ (_ ∷ a ∷ as) (t , ap) = cong₂ _,_ (𝕤𝕖𝕞! t) (𝔸-Arg₁ (a ∷ as) ap)
𝕤𝕖𝕞! (con (o ⋮ a)) rewrite 𝔸-Arg₁ (Arity o) a = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩
𝕤𝕖𝕞! (mvar 𝔪 ε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix ε)) =
trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id ε))
-- Syntax instance for a term grammar
𝕋:Syn : Syntax
𝕋:Syn = record
{ ⅀F = ⅀F
; ⅀:CS = ⅀:CompatStr
; 𝕋:Init = 𝕋:Init
; mvarᵢ = mvar }
|
lemma (in bounded_linear) isUCont: "isUCont f" |
[GOAL]
X Y B : Profinite
f : X ⟶ B
g : Y ⟶ B
⊢ fst f g ≫ f = snd f g ≫ g
[PROOFSTEP]
ext ⟨_, h⟩
[GOAL]
case w.mk
X Y B : Profinite
f : X ⟶ B
g : Y ⟶ B
val✝ : ↑X.toCompHaus.toTop × ↑Y.toCompHaus.toTop
h : val✝ ∈ {xy | ↑f xy.fst = ↑g xy.snd}
⊢ ↑(fst f g ≫ f) { val := val✝, property := h } = ↑(snd f g ≫ g) { val := val✝, property := h }
[PROOFSTEP]
exact h
[GOAL]
X Y B : Profinite
f : X ⟶ B
g : Y ⟶ B
Z : Profinite
a : Z ⟶ X
b : Z ⟶ Y
w : a ≫ f = b ≫ g
z : ↑Z.toCompHaus.toTop
⊢ (↑a z, ↑b z) ∈ {xy | ↑f xy.fst = ↑g xy.snd}
[PROOFSTEP]
apply_fun (· z) at w
[GOAL]
X Y B : Profinite
f : X ⟶ B
g : Y ⟶ B
Z : Profinite
a : Z ⟶ X
b : Z ⟶ Y
z : ↑Z.toCompHaus.toTop
w : ↑(a ≫ f) z = ↑(b ≫ g) z
⊢ (↑a z, ↑b z) ∈ {xy | ↑f xy.fst = ↑g xy.snd}
[PROOFSTEP]
exact w
[GOAL]
X Y B : Profinite
f : X ⟶ B
g : Y ⟶ B
Z : Profinite
a : Z ⟶ X
b : Z ⟶ Y
w : a ≫ f = b ≫ g
⊢ Continuous fun z => { val := (↑a z, ↑b z), property := (_ : ↑(a ≫ f) z = ↑(b ≫ g) z) }
[PROOFSTEP]
apply Continuous.subtype_mk
[GOAL]
case h
X Y B : Profinite
f : X ⟶ B
g : Y ⟶ B
Z : Profinite
a : Z ⟶ X
b : Z ⟶ Y
w : a ≫ f = b ≫ g
⊢ Continuous fun x => (↑a x, ↑b x)
[PROOFSTEP]
rw [continuous_prod_mk]
[GOAL]
case h
X Y B : Profinite
f : X ⟶ B
g : Y ⟶ B
Z : Profinite
a : Z ⟶ X
b : Z ⟶ Y
w : a ≫ f = b ≫ g
⊢ (Continuous fun x => ↑a x) ∧ Continuous fun x => ↑b x
[PROOFSTEP]
exact ⟨a.continuous, b.continuous⟩
[GOAL]
X Y B : Profinite
f : X ⟶ B
g : Y ⟶ B
Z : Profinite
a b : Z ⟶ pullback f g
hfst : a ≫ fst f g = b ≫ fst f g
hsnd : a ≫ snd f g = b ≫ snd f g
⊢ a = b
[PROOFSTEP]
ext z
[GOAL]
case w
X Y B : Profinite
f : X ⟶ B
g : Y ⟶ B
Z : Profinite
a b : Z ⟶ pullback f g
hfst : a ≫ fst f g = b ≫ fst f g
hsnd : a ≫ snd f g = b ≫ snd f g
z : (forget Profinite).obj Z
⊢ ↑a z = ↑b z
[PROOFSTEP]
apply_fun (· z) at hfst hsnd
[GOAL]
case w
X Y B : Profinite
f : X ⟶ B
g : Y ⟶ B
Z : Profinite
a b : Z ⟶ pullback f g
z : (forget Profinite).obj Z
hfst : ↑(a ≫ fst f g) z = ↑(b ≫ fst f g) z
hsnd : ↑(a ≫ snd f g) z = ↑(b ≫ snd f g) z
⊢ ↑a z = ↑b z
[PROOFSTEP]
apply Subtype.ext
[GOAL]
case w.a
X Y B : Profinite
f : X ⟶ B
g : Y ⟶ B
Z : Profinite
a b : Z ⟶ pullback f g
z : (forget Profinite).obj Z
hfst : ↑(a ≫ fst f g) z = ↑(b ≫ fst f g) z
hsnd : ↑(a ≫ snd f g) z = ↑(b ≫ snd f g) z
⊢ ↑(↑a z) = ↑(↑b z)
[PROOFSTEP]
apply Prod.ext
[GOAL]
case w.a.h₁
X Y B : Profinite
f : X ⟶ B
g : Y ⟶ B
Z : Profinite
a b : Z ⟶ pullback f g
z : (forget Profinite).obj Z
hfst : ↑(a ≫ fst f g) z = ↑(b ≫ fst f g) z
hsnd : ↑(a ≫ snd f g) z = ↑(b ≫ snd f g) z
⊢ (↑(↑a z)).fst = (↑(↑b z)).fst
[PROOFSTEP]
exact hfst
[GOAL]
case w.a.h₂
X Y B : Profinite
f : X ⟶ B
g : Y ⟶ B
Z : Profinite
a b : Z ⟶ pullback f g
z : (forget Profinite).obj Z
hfst : ↑(a ≫ fst f g) z = ↑(b ≫ fst f g) z
hsnd : ↑(a ≫ snd f g) z = ↑(b ≫ snd f g) z
⊢ (↑(↑a z)).snd = (↑(↑b z)).snd
[PROOFSTEP]
exact hsnd
[GOAL]
X Y B : Profinite
f : X ⟶ B
g : Y ⟶ B
⊢ pullback.fst f g = (pullbackIsoPullback f g).hom ≫ Limits.pullback.fst
[PROOFSTEP]
dsimp [pullbackIsoPullback]
[GOAL]
X Y B : Profinite
f : X ⟶ B
g : Y ⟶ B
⊢ pullback.fst f g =
(Limits.IsLimit.conePointUniqueUpToIso (pullback.isLimit f g) (Limits.limit.isLimit (Limits.cospan f g))).hom ≫
Limits.pullback.fst
[PROOFSTEP]
simp only [Limits.limit.conePointUniqueUpToIso_hom_comp, pullback.cone_pt, pullback.cone_π]
[GOAL]
X Y B : Profinite
f : X ⟶ B
g : Y ⟶ B
⊢ pullback.snd f g = (pullbackIsoPullback f g).hom ≫ Limits.pullback.snd
[PROOFSTEP]
dsimp [pullbackIsoPullback]
[GOAL]
X Y B : Profinite
f : X ⟶ B
g : Y ⟶ B
⊢ pullback.snd f g =
(Limits.IsLimit.conePointUniqueUpToIso (pullback.isLimit f g) (Limits.limit.isLimit (Limits.cospan f g))).hom ≫
Limits.pullback.snd
[PROOFSTEP]
simp only [Limits.limit.conePointUniqueUpToIso_hom_comp, pullback.cone_pt, pullback.cone_π]
[GOAL]
α : Type
inst✝ : Fintype α
X : α → Profinite
B : Profinite
e : (a : α) → X a ⟶ B
⊢ Continuous fun x =>
match x with
| { fst := a, snd := x } => ↑(e a) x
[PROOFSTEP]
apply continuous_sigma
[GOAL]
case hf
α : Type
inst✝ : Fintype α
X : α → Profinite
B : Profinite
e : (a : α) → X a ⟶ B
⊢ ∀ (i : α),
Continuous fun a =>
match { fst := i, snd := a } with
| { fst := a, snd := x } => ↑(e a) x
[PROOFSTEP]
intro a
[GOAL]
case hf
α : Type
inst✝ : Fintype α
X : α → Profinite
B : Profinite
e : (a : α) → X a ⟶ B
a : α
⊢ Continuous fun a_1 =>
match { fst := a, snd := a_1 } with
| { fst := a, snd := x } => ↑(e a) x
[PROOFSTEP]
exact (e a).continuous
[GOAL]
α : Type
inst✝ : Fintype α
X : α → Profinite
B : Profinite
f g : finiteCoproduct X ⟶ B
h : ∀ (a : α), ι X a ≫ f = ι X a ≫ g
⊢ f = g
[PROOFSTEP]
ext ⟨a, x⟩
[GOAL]
case w.mk
α : Type
inst✝ : Fintype α
X : α → Profinite
B : Profinite
f g : finiteCoproduct X ⟶ B
h : ∀ (a : α), ι X a ≫ f = ι X a ≫ g
a : α
x : ↑(X a).toCompHaus.toTop
⊢ ↑f { fst := a, snd := x } = ↑g { fst := a, snd := x }
[PROOFSTEP]
specialize h a
[GOAL]
case w.mk
α : Type
inst✝ : Fintype α
X : α → Profinite
B : Profinite
f g : finiteCoproduct X ⟶ B
a : α
x : ↑(X a).toCompHaus.toTop
h : ι X a ≫ f = ι X a ≫ g
⊢ ↑f { fst := a, snd := x } = ↑g { fst := a, snd := x }
[PROOFSTEP]
apply_fun (· x) at h
[GOAL]
case w.mk
α : Type
inst✝ : Fintype α
X : α → Profinite
B : Profinite
f g : finiteCoproduct X ⟶ B
a : α
x : ↑(X a).toCompHaus.toTop
h : ↑(ι X a ≫ f) x = ↑(ι X a ≫ g) x
⊢ ↑f { fst := a, snd := x } = ↑g { fst := a, snd := x }
[PROOFSTEP]
exact h
[GOAL]
α : Type
inst✝ : Fintype α
X : α → Profinite
s : Limits.Cocone (Discrete.functor X)
m : (cocone X).pt ⟶ s.pt
hm : ∀ (j : Discrete α), NatTrans.app (cocone X).ι j ≫ m = NatTrans.app s.ι j
a : α
⊢ ι (fun a => X a) a ≫ m = ι (fun a => X a) a ≫ (fun s => desc (fun a => X a) fun a => NatTrans.app s.ι { as := a }) s
[PROOFSTEP]
specialize hm ⟨a⟩
[GOAL]
α : Type
inst✝ : Fintype α
X : α → Profinite
s : Limits.Cocone (Discrete.functor X)
m : (cocone X).pt ⟶ s.pt
a : α
hm : NatTrans.app (cocone X).ι { as := a } ≫ m = NatTrans.app s.ι { as := a }
⊢ ι (fun a => X a) a ≫ m = ι (fun a => X a) a ≫ (fun s => desc (fun a => X a) fun a => NatTrans.app s.ι { as := a }) s
[PROOFSTEP]
ext t
[GOAL]
case w
α : Type
inst✝ : Fintype α
X : α → Profinite
s : Limits.Cocone (Discrete.functor X)
m : (cocone X).pt ⟶ s.pt
a : α
hm : NatTrans.app (cocone X).ι { as := a } ≫ m = NatTrans.app s.ι { as := a }
t : (forget Profinite).obj (X a)
⊢ ↑(ι (fun a => X a) a ≫ m) t =
↑(ι (fun a => X a) a ≫ (fun s => desc (fun a => X a) fun a => NatTrans.app s.ι { as := a }) s) t
[PROOFSTEP]
apply_fun (· t) at hm
[GOAL]
case w
α : Type
inst✝ : Fintype α
X : α → Profinite
s : Limits.Cocone (Discrete.functor X)
m : (cocone X).pt ⟶ s.pt
a : α
t : (forget Profinite).obj (X a)
hm : ↑(NatTrans.app (cocone X).ι { as := a } ≫ m) t = ↑(NatTrans.app s.ι { as := a }) t
⊢ ↑(ι (fun a => X a) a ≫ m) t =
↑(ι (fun a => X a) a ≫ (fun s => desc (fun a => X a) fun a => NatTrans.app s.ι { as := a }) s) t
[PROOFSTEP]
exact hm
[GOAL]
α : Type
inst✝ : Fintype α
X : α → Profinite
a : α
⊢ Limits.Sigma.ι X a ≫ (coproductIsoCoproduct X).inv = finiteCoproduct.ι X a
[PROOFSTEP]
simp only [coproductIsoCoproduct, Limits.colimit.comp_coconePointUniqueUpToIso_inv, finiteCoproduct.cocone_pt,
finiteCoproduct.cocone_ι, Discrete.natTrans_app]
[GOAL]
α : Type
inst✝ : Fintype α
X : α → Profinite
a : α
⊢ Function.Injective ↑(ι X a)
[PROOFSTEP]
intro x y hxy
[GOAL]
α : Type
inst✝ : Fintype α
X : α → Profinite
a : α
x y : (forget Profinite).obj (X a)
hxy : ↑(ι X a) x = ↑(ι X a) y
⊢ x = y
[PROOFSTEP]
exact eq_of_heq (Sigma.ext_iff.mp hxy).2
[GOAL]
α : Type
inst✝ : Fintype α
X : α → Profinite
B : Profinite
π : (a : α) → X a ⟶ B
a : α
⊢ ∀ (x : (forget Profinite).obj (X a)), ↑(desc X π) (↑(ι X a) x) = ↑(π a) x
[PROOFSTEP]
intro x
[GOAL]
α : Type
inst✝ : Fintype α
X : α → Profinite
B : Profinite
π : (a : α) → X a ⟶ B
a : α
x : (forget Profinite).obj (X a)
⊢ ↑(desc X π) (↑(ι X a) x) = ↑(π a) x
[PROOFSTEP]
change (ι X a ≫ desc X π) _ = _
[GOAL]
α : Type
inst✝ : Fintype α
X : α → Profinite
B : Profinite
π : (a : α) → X a ⟶ B
a : α
x : (forget Profinite).obj (X a)
⊢ ↑(ι X a ≫ desc X π) x = ↑(π a) x
[PROOFSTEP]
simp only [ι_desc]
|
[STATEMENT]
lemma diff_union_cancelR: "M + N - N = (M::'a multiset)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. M + N - N = M
[PROOF STEP]
by (fact add_diff_cancel_right') |
The imaginary part of $\iota z$ is equal to the real part of $z$. |
Promoted to the rank of brigadier , after the German surrender in North Africa , Wheeler was sent to Algiers where he was part of the staff committee planning the invasion of Italy . There , he learned that the India Office had requested that the army relieve him of his duties to permit him to be appointed Director General of Archaeology in India . Although he had never been to the country , he agreed that he would take the job on the condition that he be permitted to take part in the invasion of Italy first . As intended , Wheeler and his 12th Anti @-@ Aircraft Brigade then took part in the invasion of Sicily and then mainland Italy , where they were ordered to use their anti @-@ aircraft guns to protect the British 10th Corps . As the Allies advanced north through Italy , Wheeler spent time in Naples and then Capri , where he met various aristocrats who had anti @-@ fascist sympathies .
|
(* Title: HOL/Library/Product_Plus.thy
Author: Brian Huffman
*)
section \<open>Additive group operations on product types\<close>
theory Product_Plus
imports Main
begin
subsection \<open>Operations\<close>
instantiation prod :: (zero, zero) zero
begin
definition zero_prod_def: "0 = (0, 0)"
instance ..
end
instantiation prod :: (plus, plus) plus
begin
definition plus_prod_def:
"x + y = (fst x + fst y, snd x + snd y)"
instance ..
end
instantiation prod :: (minus, minus) minus
begin
definition minus_prod_def:
"x - y = (fst x - fst y, snd x - snd y)"
instance ..
end
instantiation prod :: (uminus, uminus) uminus
begin
definition uminus_prod_def:
"- x = (- fst x, - snd x)"
instance ..
end
lemma fst_zero [simp]: "fst 0 = 0"
unfolding zero_prod_def by simp
lemma snd_zero [simp]: "snd 0 = 0"
unfolding zero_prod_def by simp
lemma fst_add [simp]: "fst (x + y) = fst x + fst y"
unfolding plus_prod_def by simp
lemma snd_add [simp]: "snd (x + y) = snd x + snd y"
unfolding plus_prod_def by simp
lemma fst_diff [simp]: "fst (x - y) = fst x - fst y"
unfolding minus_prod_def by simp
lemma snd_diff [simp]: "snd (x - y) = snd x - snd y"
unfolding minus_prod_def by simp
lemma fst_uminus [simp]: "fst (- x) = - fst x"
unfolding uminus_prod_def by simp
lemma snd_uminus [simp]: "snd (- x) = - snd x"
unfolding uminus_prod_def by simp
lemma add_Pair [simp]: "(a, b) + (c, d) = (a + c, b + d)"
unfolding plus_prod_def by simp
lemma diff_Pair [simp]: "(a, b) - (c, d) = (a - c, b - d)"
unfolding minus_prod_def by simp
lemma uminus_Pair [simp, code]: "- (a, b) = (- a, - b)"
unfolding uminus_prod_def by simp
subsection \<open>Class instances\<close>
instance prod :: (semigroup_add, semigroup_add) semigroup_add
by standard (simp add: prod_eq_iff add.assoc)
instance prod :: (ab_semigroup_add, ab_semigroup_add) ab_semigroup_add
by standard (simp add: prod_eq_iff add.commute)
instance prod :: (monoid_add, monoid_add) monoid_add
by standard (simp_all add: prod_eq_iff)
instance prod :: (comm_monoid_add, comm_monoid_add) comm_monoid_add
by standard (simp add: prod_eq_iff)
instance prod :: (cancel_semigroup_add, cancel_semigroup_add) cancel_semigroup_add
by standard (simp_all add: prod_eq_iff)
instance prod :: (cancel_ab_semigroup_add, cancel_ab_semigroup_add) cancel_ab_semigroup_add
by standard (simp_all add: prod_eq_iff diff_diff_eq)
instance prod :: (cancel_comm_monoid_add, cancel_comm_monoid_add) cancel_comm_monoid_add ..
instance prod :: (group_add, group_add) group_add
by standard (simp_all add: prod_eq_iff)
instance prod :: (ab_group_add, ab_group_add) ab_group_add
by standard (simp_all add: prod_eq_iff)
lemma fst_sum: "fst (\<Sum>x\<in>A. f x) = (\<Sum>x\<in>A. fst (f x))"
proof (cases "finite A")
case True
then show ?thesis by induct simp_all
next
case False
then show ?thesis by simp
qed
lemma snd_sum: "snd (\<Sum>x\<in>A. f x) = (\<Sum>x\<in>A. snd (f x))"
proof (cases "finite A")
case True
then show ?thesis by induct simp_all
next
case False
then show ?thesis by simp
qed
lemma sum_prod: "(\<Sum>x\<in>A. (f x, g x)) = (\<Sum>x\<in>A. f x, \<Sum>x\<in>A. g x)"
proof (cases "finite A")
case True
then show ?thesis by induct (simp_all add: zero_prod_def)
next
case False
then show ?thesis by (simp add: zero_prod_def)
qed
end
|
lemma eventually_at_left_field: "eventually P (at_left x) \<longleftrightarrow> (\<exists>b<x. \<forall>y>b. y < x \<longrightarrow> P y)" for x :: "'a::{linordered_field, linorder_topology}" |
(* Title: HOL/Auth/n_germanSymIndex_lemma_inv__3_on_rules.thy
Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences
Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences
*)
header{*The n_germanSymIndex Protocol Case Study*}
theory n_germanSymIndex_lemma_inv__3_on_rules imports n_germanSymIndex_lemma_on_inv__3
begin
section{*All lemmas on causal relation between inv__3*}
lemma lemma_inv__3_on_rules:
assumes b1: "r \<in> rules N" and b2: "(f=inv__3 )"
shows "invHoldForRule s f r (invariants N)"
proof -
have c1: "(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)\<or>
(\<exists> i. i\<le>N\<and>r=n_SendReqS i)\<or>
(\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i)\<or>
(\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i)\<or>
(\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)\<or>
(\<exists> i. i\<le>N\<and>r=n_RecvReqE N i)\<or>
(\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)\<or>
(\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)\<or>
(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)\<or>
(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)\<or>
(\<exists> i. i\<le>N\<and>r=n_SendGntS i)\<or>
(\<exists> i. i\<le>N\<and>r=n_SendGntE N i)\<or>
(\<exists> i. i\<le>N\<and>r=n_RecvGntS i)\<or>
(\<exists> i. i\<le>N\<and>r=n_RecvGntE i)"
apply (cut_tac b1, auto) done
moreover {
assume d1: "(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_StoreVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqS i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_SendReqSVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_SendReqE__part__0Vsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_SendReqE__part__1Vsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_RecvReqSVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqE N i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_RecvReqEVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_SendInv__part__0Vsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_SendInv__part__1Vsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_SendInvAckVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_RecvInvAckVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendGntS i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_SendGntSVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendGntE N i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_SendGntEVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntS i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_RecvGntSVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntE i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_RecvGntEVsinv__3) done
}
ultimately show "invHoldForRule s f r (invariants N)"
by satx
qed
end
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import data.finset.sort
/-!
# Finite sets
This file defines predicates `finite : set α → Prop` and `infinite : set α → Prop` and proves some
basic facts about finite sets.
-/
open set function
universes u v w x
variables {α : Type u} {β : Type v} {ι : Sort w} {γ : Type x}
namespace set
/-- A set is finite if the subtype is a fintype, i.e. there is a
list that enumerates its members. -/
inductive finite (s : set α) : Prop
| intro : fintype s → finite
lemma finite_def {s : set α} : finite s ↔ nonempty (fintype s) := ⟨λ ⟨h⟩, ⟨h⟩, λ ⟨h⟩, ⟨h⟩⟩
/-- A set is infinite if it is not finite. -/
def infinite (s : set α) : Prop := ¬ finite s
/-- The subtype corresponding to a finite set is a finite type. Note
that because `finite` isn't a typeclass, this will not fire if it
is made into an instance -/
noncomputable def finite.fintype {s : set α} (h : finite s) : fintype s :=
classical.choice $ finite_def.1 h
/-- Get a finset from a finite set -/
noncomputable def finite.to_finset {s : set α} (h : finite s) : finset α :=
@set.to_finset _ _ h.fintype
@[simp] lemma not_infinite {s : set α} : ¬ s.infinite ↔ s.finite :=
by simp [infinite]
@[simp] theorem finite.mem_to_finset {s : set α} (h : finite s) {a : α} : a ∈ h.to_finset ↔ a ∈ s :=
@mem_to_finset _ _ h.fintype _
@[simp] theorem finite.to_finset.nonempty {s : set α} (h : finite s) :
h.to_finset.nonempty ↔ s.nonempty :=
show (∃ x, x ∈ h.to_finset) ↔ (∃ x, x ∈ s),
from exists_congr (λ _, h.mem_to_finset)
@[simp] lemma finite.coe_to_finset {s : set α} (h : finite s) : ↑h.to_finset = s :=
@set.coe_to_finset _ s h.fintype
@[simp] lemma finite.coe_sort_to_finset {s : set α} (h : finite s) :
(h.to_finset : Type*) = s :=
by rw [← finset.coe_sort_coe _, h.coe_to_finset]
@[simp] lemma finite_empty_to_finset (h : finite (∅ : set α)) : h.to_finset = ∅ :=
by rw [← finset.coe_inj, h.coe_to_finset, finset.coe_empty]
@[simp] lemma finite.to_finset_inj {s t : set α} {hs : finite s} {ht : finite t} :
hs.to_finset = ht.to_finset ↔ s = t :=
by simp [←finset.coe_inj]
lemma subset_to_finset_iff {s : finset α} {t : set α} (ht : finite t) :
s ⊆ ht.to_finset ↔ ↑s ⊆ t :=
by rw [← finset.coe_subset, ht.coe_to_finset]
@[simp] lemma finite_to_finset_eq_empty_iff {s : set α} {h : finite s} :
h.to_finset = ∅ ↔ s = ∅ :=
by simp [←finset.coe_inj]
theorem finite.exists_finset {s : set α} : finite s →
∃ s' : finset α, ∀ a : α, a ∈ s' ↔ a ∈ s
| ⟨h⟩ := by exactI ⟨to_finset s, λ _, mem_to_finset⟩
theorem finite.exists_finset_coe {s : set α} (hs : finite s) :
∃ s' : finset α, ↑s' = s :=
⟨hs.to_finset, hs.coe_to_finset⟩
/-- Finite sets can be lifted to finsets. -/
instance : can_lift (set α) (finset α) :=
{ coe := coe,
cond := finite,
prf := λ s hs, hs.exists_finset_coe }
theorem finite_mem_finset (s : finset α) : finite {a | a ∈ s} :=
⟨fintype.of_finset s (λ _, iff.rfl)⟩
theorem finite.of_fintype [fintype α] (s : set α) : finite s :=
by classical; exact ⟨set_fintype s⟩
theorem exists_finite_iff_finset {p : set α → Prop} :
(∃ s, finite s ∧ p s) ↔ ∃ s : finset α, p ↑s :=
⟨λ ⟨s, hs, hps⟩, ⟨hs.to_finset, hs.coe_to_finset.symm ▸ hps⟩,
λ ⟨s, hs⟩, ⟨↑s, finite_mem_finset s, hs⟩⟩
lemma finite.fin_embedding {s : set α} (h : finite s) : ∃ (n : ℕ) (f : fin n ↪ α), range f = s :=
⟨_, (fintype.equiv_fin (h.to_finset : set α)).symm.as_embedding, by simp⟩
lemma finite.fin_param {s : set α} (h : finite s) :
∃ (n : ℕ) (f : fin n → α), injective f ∧ range f = s :=
let ⟨n, f, hf⟩ := h.fin_embedding in ⟨n, f, f.injective, hf⟩
/-- Membership of a subset of a finite type is decidable.
Using this as an instance leads to potential loops with `subtype.fintype` under certain decidability
assumptions, so it should only be declared a local instance. -/
def decidable_mem_of_fintype [decidable_eq α] (s : set α) [fintype s] (a) : decidable (a ∈ s) :=
decidable_of_iff _ mem_to_finset
instance fintype_empty : fintype (∅ : set α) :=
fintype.of_finset ∅ $ by simp
theorem empty_card : fintype.card (∅ : set α) = 0 := rfl
@[simp] theorem empty_card' {h : fintype.{u} (∅ : set α)} :
@fintype.card (∅ : set α) h = 0 :=
eq.trans (by congr) empty_card
@[simp] theorem finite_empty : @finite α ∅ := ⟨set.fintype_empty⟩
instance finite.inhabited : inhabited {s : set α // finite s} := ⟨⟨∅, finite_empty⟩⟩
/-- A `fintype` structure on `insert a s`. -/
def fintype_insert' {a : α} (s : set α) [fintype s] (h : a ∉ s) : fintype (insert a s : set α) :=
fintype.of_finset ⟨a ::ₘ s.to_finset.1,
multiset.nodup_cons_of_nodup (by simp [h]) s.to_finset.2⟩ $ by simp
theorem card_fintype_insert' {a : α} (s : set α) [fintype s] (h : a ∉ s) :
@fintype.card _ (fintype_insert' s h) = fintype.card s + 1 :=
by rw [fintype_insert', fintype.card_of_finset];
simp [finset.card, to_finset]; refl
@[simp] theorem card_insert {a : α} (s : set α)
[fintype s] (h : a ∉ s) {d : fintype.{u} (insert a s : set α)} :
@fintype.card _ d = fintype.card s + 1 :=
by rw ← card_fintype_insert' s h; congr
lemma card_image_of_inj_on {s : set α} [fintype s]
{f : α → β} [fintype (f '' s)] (H : ∀x∈s, ∀y∈s, f x = f y → x = y) :
fintype.card (f '' s) = fintype.card s :=
by haveI := classical.prop_decidable; exact
calc fintype.card (f '' s) = (s.to_finset.image f).card : fintype.card_of_finset' _ (by simp)
... = s.to_finset.card : finset.card_image_of_inj_on
(λ x hx y hy hxy, H x (mem_to_finset.1 hx) y (mem_to_finset.1 hy) hxy)
... = fintype.card s : (fintype.card_of_finset' _ (λ a, mem_to_finset)).symm
lemma card_image_of_injective (s : set α) [fintype s]
{f : α → β} [fintype (f '' s)] (H : function.injective f) :
fintype.card (f '' s) = fintype.card s :=
card_image_of_inj_on $ λ _ _ _ _ h, H h
section
local attribute [instance] decidable_mem_of_fintype
instance fintype_insert [decidable_eq α] (a : α) (s : set α) [fintype s] :
fintype (insert a s : set α) :=
if h : a ∈ s then by rwa [insert_eq, union_eq_self_of_subset_left (singleton_subset_iff.2 h)]
else fintype_insert' _ h
end
@[simp] theorem finite.insert (a : α) {s : set α} : finite s → finite (insert a s)
| ⟨h⟩ := ⟨@set.fintype_insert _ (classical.dec_eq α) _ _ h⟩
lemma to_finset_insert [decidable_eq α] {a : α} {s : set α} (hs : finite s) :
(hs.insert a).to_finset = insert a hs.to_finset :=
finset.ext $ by simp
@[simp] lemma insert_to_finset [decidable_eq α] {a : α} {s : set α} [fintype s] :
(insert a s).to_finset = insert a s.to_finset :=
by simp [finset.ext_iff, mem_insert_iff]
@[elab_as_eliminator]
theorem finite.induction_on {C : set α → Prop} {s : set α} (h : finite s)
(H0 : C ∅) (H1 : ∀ {a s}, a ∉ s → finite s → C s → C (insert a s)) : C s :=
let ⟨t⟩ := h in by exactI
match s.to_finset, @mem_to_finset _ s _ with
| ⟨l, nd⟩, al := begin
change ∀ a, a ∈ l ↔ a ∈ s at al,
clear _let_match _match t h, revert s nd al,
refine multiset.induction_on l _ (λ a l IH, _); intros s nd al,
{ rw show s = ∅, from eq_empty_iff_forall_not_mem.2 (by simpa using al),
exact H0 },
{ rw ← show insert a {x | x ∈ l} = s, from set.ext (by simpa using al),
cases multiset.nodup_cons.1 nd with m nd',
refine H1 _ ⟨finset.subtype.fintype ⟨l, nd'⟩⟩ (IH nd' (λ _, iff.rfl)),
exact m }
end
end
@[elab_as_eliminator]
theorem finite.dinduction_on {C : ∀s:set α, finite s → Prop} {s : set α} (h : finite s)
(H0 : C ∅ finite_empty)
(H1 : ∀ {a s}, a ∉ s → ∀ h : finite s, C s h → C (insert a s) (h.insert a)) :
C s h :=
have ∀ h : finite s, C s h,
from finite.induction_on h (λ h, H0) (λ a s has hs ih h, H1 has hs (ih _)),
this h
instance fintype_singleton (a : α) : fintype ({a} : set α) :=
unique.fintype
@[simp] theorem card_singleton (a : α) :
fintype.card ({a} : set α) = 1 :=
fintype.card_of_subsingleton _
@[simp] theorem finite_singleton (a : α) : finite ({a} : set α) :=
⟨set.fintype_singleton _⟩
lemma subsingleton.finite {s : set α} (h : s.subsingleton) : finite s :=
h.induction_on finite_empty finite_singleton
lemma finite_is_top (α : Type*) [partial_order α] : finite {x : α | is_top x} :=
(subsingleton_is_top α).finite
lemma finite_is_bot (α : Type*) [partial_order α] : finite {x : α | is_bot x} :=
(subsingleton_is_bot α).finite
instance fintype_pure : ∀ a : α, fintype (pure a : set α) :=
set.fintype_singleton
theorem finite_pure (a : α) : finite (pure a : set α) :=
⟨set.fintype_pure a⟩
instance fintype_univ [fintype α] : fintype (@univ α) :=
fintype.of_equiv α $ (equiv.set.univ α).symm
theorem finite_univ [fintype α] : finite (@univ α) := ⟨set.fintype_univ⟩
/-- If `(set.univ : set α)` is finite then `α` is a finite type. -/
noncomputable def fintype_of_univ_finite (H : (univ : set α).finite ) :
fintype α :=
@fintype.of_equiv _ (univ : set α) H.fintype (equiv.set.univ _)
lemma univ_finite_iff_nonempty_fintype :
(univ : set α).finite ↔ nonempty (fintype α) :=
begin
split,
{ intro h, exact ⟨fintype_of_univ_finite h⟩ },
{ rintro ⟨_i⟩, exactI finite_univ }
end
theorem infinite_univ_iff : (@univ α).infinite ↔ _root_.infinite α :=
⟨λ h₁, ⟨λ h₂, h₁ $ @finite_univ α h₂⟩, λ ⟨h₁⟩ h₂, h₁ (fintype_of_univ_finite h₂)⟩
theorem infinite_univ [h : _root_.infinite α] : infinite (@univ α) :=
infinite_univ_iff.2 h
theorem infinite_coe_iff {s : set α} : _root_.infinite s ↔ infinite s :=
⟨λ ⟨h₁⟩ h₂, h₁ h₂.fintype, λ h₁, ⟨λ h₂, h₁ ⟨h₂⟩⟩⟩
theorem infinite.to_subtype {s : set α} (h : infinite s) : _root_.infinite s :=
infinite_coe_iff.2 h
/-- Embedding of `ℕ` into an infinite set. -/
noncomputable def infinite.nat_embedding (s : set α) (h : infinite s) : ℕ ↪ s :=
by { haveI := h.to_subtype, exact infinite.nat_embedding s }
lemma infinite.exists_subset_card_eq {s : set α} (hs : infinite s) (n : ℕ) :
∃ t : finset α, ↑t ⊆ s ∧ t.card = n :=
⟨((finset.range n).map (hs.nat_embedding _)).map (embedding.subtype _), by simp⟩
lemma infinite.nonempty {s : set α} (h : s.infinite) : s.nonempty :=
let a := infinite.nat_embedding s h 37 in ⟨a.1, a.2⟩
instance fintype_union [decidable_eq α] (s t : set α) [fintype s] [fintype t] :
fintype (s ∪ t : set α) :=
fintype.of_finset (s.to_finset ∪ t.to_finset) $ by simp
theorem finite.union {s t : set α} : finite s → finite t → finite (s ∪ t)
| ⟨hs⟩ ⟨ht⟩ := ⟨@set.fintype_union _ (classical.dec_eq α) _ _ hs ht⟩
lemma finite.sup {s t : set α} : finite s → finite t → finite (s ⊔ t) := finite.union
lemma infinite_of_finite_compl [_root_.infinite α] {s : set α}
(hs : sᶜ.finite) : s.infinite :=
λ h, set.infinite_univ (by simpa using hs.union h)
lemma finite.infinite_compl [_root_.infinite α] {s : set α}
(hs : s.finite) : sᶜ.infinite :=
λ h, set.infinite_univ (by simpa using hs.union h)
instance fintype_sep (s : set α) (p : α → Prop) [fintype s] [decidable_pred p] :
fintype ({a ∈ s | p a} : set α) :=
fintype.of_finset (s.to_finset.filter p) $ by simp
instance fintype_inter (s t : set α) [fintype s] [decidable_pred (∈ t)] : fintype (s ∩ t : set α) :=
set.fintype_sep s t
/-- A `fintype` structure on a set defines a `fintype` structure on its subset. -/
def fintype_subset (s : set α) {t : set α} [fintype s] [decidable_pred (∈ t)] (h : t ⊆ s) :
fintype t :=
by rw ← inter_eq_self_of_subset_right h; apply_instance
theorem finite.subset {s : set α} : finite s → ∀ {t : set α}, t ⊆ s → finite t
| ⟨hs⟩ t h := ⟨@set.fintype_subset _ _ _ hs (classical.dec_pred t) h⟩
lemma finite.union_iff {s t : set α} : finite (s ∪ t) ↔ finite s ∧ finite t :=
⟨λ h, ⟨h.subset (subset_union_left _ _), h.subset (subset_union_right _ _)⟩,
λ ⟨hs, ht⟩, hs.union ht⟩
lemma finite.diff {s t u : set α} (hs : s.finite) (ht : t.finite) (h : u \ t ≤ s) : u.finite :=
begin
refine finite.subset (ht.union hs) _,
exact diff_subset_iff.mp h
end
theorem finite.inter_of_left {s : set α} (h : finite s) (t : set α) : finite (s ∩ t) :=
h.subset (inter_subset_left _ _)
theorem finite.inter_of_right {s : set α} (h : finite s) (t : set α) : finite (t ∩ s) :=
h.subset (inter_subset_right _ _)
theorem finite.inf_of_left {s : set α} (h : finite s) (t : set α) : finite (s ⊓ t) :=
h.inter_of_left t
theorem finite.inf_of_right {s : set α} (h : finite s) (t : set α) : finite (t ⊓ s) :=
h.inter_of_right t
protected theorem infinite.mono {s t : set α} (h : s ⊆ t) : infinite s → infinite t :=
mt (λ ht, ht.subset h)
lemma infinite.diff {s t : set α} (hs : s.infinite) (ht : t.finite) :
(s \ t).infinite :=
λ h, hs ((h.union ht).subset (s.subset_diff_union t))
instance fintype_image [decidable_eq β] (s : set α) (f : α → β) [fintype s] : fintype (f '' s) :=
fintype.of_finset (s.to_finset.image f) $ by simp
instance fintype_range [decidable_eq α] (f : ι → α) [fintype (plift ι)] :
fintype (range f) :=
fintype.of_finset (finset.univ.image $ f ∘ plift.down) $
by simp [(@equiv.plift ι).exists_congr_left]
theorem finite_range (f : ι → α) [fintype (plift ι)] : finite (range f) :=
by haveI := classical.dec_eq α; exact ⟨by apply_instance⟩
theorem finite.image {s : set α} (f : α → β) : finite s → finite (f '' s)
| ⟨h⟩ := ⟨@set.fintype_image _ _ (classical.dec_eq β) _ _ h⟩
theorem infinite_of_infinite_image (f : α → β) {s : set α} (hs : (f '' s).infinite) :
s.infinite :=
mt (finite.image f) hs
lemma finite.dependent_image {s : set α} (hs : finite s) (F : Π i ∈ s, β) :
finite {y : β | ∃ x (hx : x ∈ s), y = F x hx} :=
begin
letI : fintype s := hs.fintype,
convert finite_range (λ x : s, F x x.2),
simp only [set_coe.exists, subtype.coe_mk, eq_comm],
end
theorem finite.of_preimage {f : α → β} {s : set β} (h : finite (f ⁻¹' s)) (hf : surjective f) :
finite s :=
hf.image_preimage s ▸ h.image _
instance fintype_map {α β} [decidable_eq β] :
∀ (s : set α) (f : α → β) [fintype s], fintype (f <$> s) := set.fintype_image
theorem finite.map {α β} {s : set α} :
∀ (f : α → β), finite s → finite (f <$> s) := finite.image
/-- If a function `f` has a partial inverse and sends a set `s` to a set with `[fintype]` instance,
then `s` has a `fintype` structure as well. -/
def fintype_of_fintype_image (s : set α)
{f : α → β} {g} (I : is_partial_inv f g) [fintype (f '' s)] : fintype s :=
fintype.of_finset ⟨_, @multiset.nodup_filter_map β α g _
(@injective_of_partial_inv_right _ _ f g I) (f '' s).to_finset.2⟩ $ λ a,
begin
suffices : (∃ b x, f x = b ∧ g b = some a ∧ x ∈ s) ↔ a ∈ s,
by simpa [exists_and_distrib_left.symm, and.comm, and.left_comm, and.assoc],
rw exists_swap,
suffices : (∃ x, x ∈ s ∧ g (f x) = some a) ↔ a ∈ s, {simpa [and.comm, and.left_comm, and.assoc]},
simp [I _, (injective_of_partial_inv I).eq_iff]
end
theorem finite_of_finite_image {s : set α} {f : α → β} (hi : set.inj_on f s) :
finite (f '' s) → finite s | ⟨h⟩ :=
⟨@fintype.of_injective _ _ h (λ a : s, ⟨f a.1, mem_image_of_mem f a.2⟩) $
λ a b eq, subtype.eq $ hi a.2 b.2 $ subtype.ext_iff_val.1 eq⟩
theorem finite_image_iff {s : set α} {f : α → β} (hi : inj_on f s) :
finite (f '' s) ↔ finite s :=
⟨finite_of_finite_image hi, finite.image _⟩
theorem infinite_image_iff {s : set α} {f : α → β} (hi : inj_on f s) :
infinite (f '' s) ↔ infinite s :=
not_congr $ finite_image_iff hi
theorem infinite_of_inj_on_maps_to {s : set α} {t : set β} {f : α → β}
(hi : inj_on f s) (hm : maps_to f s t) (hs : infinite s) : infinite t :=
((infinite_image_iff hi).2 hs).mono (maps_to'.mp hm)
theorem infinite.exists_ne_map_eq_of_maps_to {s : set α} {t : set β} {f : α → β}
(hs : infinite s) (hf : maps_to f s t) (ht : finite t) :
∃ (x ∈ s) (y ∈ s), x ≠ y ∧ f x = f y :=
begin
contrapose! ht,
exact infinite_of_inj_on_maps_to (λ x hx y hy, not_imp_not.1 (ht x hx y hy)) hf hs
end
theorem infinite.exists_lt_map_eq_of_maps_to [linear_order α] {s : set α} {t : set β} {f : α → β}
(hs : infinite s) (hf : maps_to f s t) (ht : finite t) :
∃ (x ∈ s) (y ∈ s), x < y ∧ f x = f y :=
let ⟨x, hx, y, hy, hxy, hf⟩ := hs.exists_ne_map_eq_of_maps_to hf ht
in hxy.lt_or_lt.elim (λ hxy, ⟨x, hx, y, hy, hxy, hf⟩) (λ hyx, ⟨y, hy, x, hx, hyx, hf.symm⟩)
theorem infinite_range_of_injective [_root_.infinite α] {f : α → β} (hi : injective f) :
infinite (range f) :=
by { rw [←image_univ, infinite_image_iff (inj_on_of_injective hi _)], exact infinite_univ }
theorem infinite_of_injective_forall_mem [_root_.infinite α] {s : set β} {f : α → β}
(hi : injective f) (hf : ∀ x : α, f x ∈ s) : infinite s :=
by { rw ←range_subset_iff at hf, exact (infinite_range_of_injective hi).mono hf }
theorem finite.preimage {s : set β} {f : α → β}
(I : set.inj_on f (f⁻¹' s)) (h : finite s) : finite (f ⁻¹' s) :=
finite_of_finite_image I (h.subset (image_preimage_subset f s))
theorem finite.preimage_embedding {s : set β} (f : α ↪ β) (h : s.finite) : (f ⁻¹' s).finite :=
finite.preimage (λ _ _ _ _ h', f.injective h') h
lemma finite_option {s : set (option α)} : finite s ↔ finite {x : α | some x ∈ s} :=
⟨λ h, h.preimage_embedding embedding.some,
λ h, ((h.image some).insert none).subset $
λ x, option.cases_on x (λ _, or.inl rfl) (λ x hx, or.inr $ mem_image_of_mem _ hx)⟩
instance fintype_Union [decidable_eq α] [fintype (plift ι)]
(f : ι → set α) [∀ i, fintype (f i)] : fintype (⋃ i, f i) :=
fintype.of_finset (finset.univ.bUnion (λ i : plift ι, (f i.down).to_finset)) $ by simp
theorem finite_Union [fintype (plift ι)] {f : ι → set α} (H : ∀i, finite (f i)) :
finite (⋃ i, f i) :=
⟨@set.fintype_Union _ _ (classical.dec_eq α) _ _ (λ i, finite.fintype (H i))⟩
/-- A union of sets with `fintype` structure over a set with `fintype` structure has a `fintype`
structure. -/
def fintype_bUnion [decidable_eq α] {ι : Type*} {s : set ι} [fintype s]
(f : ι → set α) (H : ∀ i ∈ s, fintype (f i)) : fintype (⋃ i ∈ s, f i) :=
by rw bUnion_eq_Union; exact
@set.fintype_Union _ _ _ _ _ (by rintro ⟨i, hi⟩; exact H i hi)
instance fintype_bUnion' [decidable_eq α] {ι : Type*} {s : set ι} [fintype s]
(f : ι → set α) [H : ∀ i, fintype (f i)] : fintype (⋃ i ∈ s, f i) :=
fintype_bUnion _ (λ i _, H i)
theorem finite.sUnion {s : set (set α)} (h : finite s) (H : ∀t∈s, finite t) : finite (⋃₀ s) :=
by rw sUnion_eq_Union; haveI := finite.fintype h;
apply finite_Union; simpa using H
theorem finite.bUnion {α} {ι : Type*} {s : set ι} {f : Π i ∈ s, set α} :
finite s → (∀ i ∈ s, finite (f i ‹_›)) → finite (⋃ i∈s, f i ‹_›)
| ⟨hs⟩ h := by rw [bUnion_eq_Union]; exactI finite_Union (λ i, h _ _)
instance fintype_lt_nat (n : ℕ) : fintype {i | i < n} :=
fintype.of_finset (finset.range n) $ by simp
instance fintype_le_nat (n : ℕ) : fintype {i | i ≤ n} :=
by simpa [nat.lt_succ_iff] using set.fintype_lt_nat (n+1)
lemma finite_le_nat (n : ℕ) : finite {i | i ≤ n} := ⟨set.fintype_le_nat _⟩
lemma finite_lt_nat (n : ℕ) : finite {i | i < n} := ⟨set.fintype_lt_nat _⟩
lemma infinite.exists_nat_lt {s : set ℕ} (hs : infinite s) (n : ℕ) : ∃ m ∈ s, n < m :=
let ⟨m, hm⟩ := (hs.diff $ set.finite_le_nat n).nonempty in ⟨m, by simpa using hm⟩
instance fintype_prod (s : set α) (t : set β) [fintype s] [fintype t] : fintype (set.prod s t) :=
fintype.of_finset (s.to_finset.product t.to_finset) $ by simp
lemma finite.prod {s : set α} {t : set β} : finite s → finite t → finite (set.prod s t)
| ⟨hs⟩ ⟨ht⟩ := by exactI ⟨set.fintype_prod s t⟩
/-- `image2 f s t` is finitype if `s` and `t` are. -/
instance fintype_image2 [decidable_eq γ] (f : α → β → γ) (s : set α) (t : set β)
[hs : fintype s] [ht : fintype t] : fintype (image2 f s t : set γ) :=
by { rw ← image_prod, apply set.fintype_image }
lemma finite.image2 (f : α → β → γ) {s : set α} {t : set β} (hs : finite s) (ht : finite t) :
finite (image2 f s t) :=
by { rw ← image_prod, exact (hs.prod ht).image _ }
/-- If `s : set α` is a set with `fintype` instance and `f : α → set β` is a function such that
each `f a`, `a ∈ s`, has a `fintype` structure, then `s >>= f` has a `fintype` structure. -/
def fintype_bind {α β} [decidable_eq β] (s : set α) [fintype s]
(f : α → set β) (H : ∀ a ∈ s, fintype (f a)) : fintype (s >>= f) :=
set.fintype_bUnion _ H
instance fintype_bind' {α β} [decidable_eq β] (s : set α) [fintype s]
(f : α → set β) [H : ∀ a, fintype (f a)] : fintype (s >>= f) :=
fintype_bind _ _ (λ i _, H i)
theorem finite.bind {α β} {s : set α} {f : α → set β} (h : finite s) (hf : ∀ a ∈ s, finite (f a)) :
finite (s >>= f) :=
h.bUnion hf
instance fintype_seq [decidable_eq β] (f : set (α → β)) (s : set α) [fintype f] [fintype s] :
fintype (f.seq s) :=
by { rw seq_def, apply set.fintype_bUnion' }
instance fintype_seq' {α β : Type u} [decidable_eq β]
(f : set (α → β)) (s : set α) [fintype f] [fintype s] :
fintype (f <*> s) :=
set.fintype_seq f s
theorem finite.seq {f : set (α → β)} {s : set α} (hf : finite f) (hs : finite s) :
finite (f.seq s) :=
by { rw seq_def, exact hf.bUnion (λ f _, hs.image _) }
theorem finite.seq' {α β : Type u} {f : set (α → β)} {s : set α} (hf : finite f) (hs : finite s) :
finite (f <*> s) :=
hf.seq hs
/-- There are finitely many subsets of a given finite set -/
lemma finite.finite_subsets {α : Type u} {a : set α} (h : finite a) : finite {b | b ⊆ a} :=
⟨fintype.of_finset ((finset.powerset h.to_finset).map finset.coe_emb.1) $ λ s,
by simpa [← @exists_finite_iff_finset α (λ t, t ⊆ a ∧ t = s), subset_to_finset_iff,
← and.assoc] using h.subset⟩
lemma exists_min_image [linear_order β] (s : set α) (f : α → β) (h1 : finite s) :
s.nonempty → ∃ a ∈ s, ∀ b ∈ s, f a ≤ f b
| ⟨x, hx⟩ := by simpa only [exists_prop, finite.mem_to_finset]
using h1.to_finset.exists_min_image f ⟨x, h1.mem_to_finset.2 hx⟩
lemma exists_max_image [linear_order β] (s : set α) (f : α → β) (h1 : finite s) :
s.nonempty → ∃ a ∈ s, ∀ b ∈ s, f b ≤ f a
| ⟨x, hx⟩ := by simpa only [exists_prop, finite.mem_to_finset]
using h1.to_finset.exists_max_image f ⟨x, h1.mem_to_finset.2 hx⟩
theorem exists_lower_bound_image [hα : nonempty α] [linear_order β] (s : set α) (f : α → β)
(h : s.finite) : ∃ (a : α), ∀ b ∈ s, f a ≤ f b :=
begin
by_cases hs : set.nonempty s,
{ exact let ⟨x₀, H, hx₀⟩ := set.exists_min_image s f h hs in ⟨x₀, λ x hx, hx₀ x hx⟩ },
{ exact nonempty.elim hα (λ a, ⟨a, λ x hx, absurd (set.nonempty_of_mem hx) hs⟩) }
end
theorem exists_upper_bound_image [hα : nonempty α] [linear_order β] (s : set α) (f : α → β)
(h : s.finite) : ∃ (a : α), ∀ b ∈ s, f b ≤ f a :=
begin
by_cases hs : set.nonempty s,
{ exact let ⟨x₀, H, hx₀⟩ := set.exists_max_image s f h hs in ⟨x₀, λ x hx, hx₀ x hx⟩ },
{ exact nonempty.elim hα (λ a, ⟨a, λ x hx, absurd (set.nonempty_of_mem hx) hs⟩) }
end
end set
namespace finset
variables [decidable_eq β]
variables {s : finset α}
lemma finite_to_set (s : finset α) : set.finite (↑s : set α) :=
set.finite_mem_finset s
@[simp] lemma coe_bUnion {f : α → finset β} : ↑(s.bUnion f) = (⋃x ∈ (↑s : set α), ↑(f x) : set β) :=
by simp [set.ext_iff]
@[simp] lemma finite_to_set_to_finset {α : Type*} (s : finset α) :
(finite_to_set s).to_finset = s :=
by { ext, rw [set.finite.mem_to_finset, mem_coe] }
end finset
namespace set
/-- Finite product of finite sets is finite -/
lemma finite.pi {δ : Type*} [fintype δ] {κ : δ → Type*} {t : Π d, set (κ d)}
(ht : ∀ d, (t d).finite) :
(pi univ t).finite :=
begin
lift t to Π d, finset (κ d) using ht,
classical,
rw ← fintype.coe_pi_finset,
exact (fintype.pi_finset t).finite_to_set,
end
/-- A finite union of finsets is finite. -/
lemma union_finset_finite_of_range_finite (f : α → finset β) (h : (range f).finite) :
(⋃ a, (f a : set β)).finite :=
begin
rw ← bUnion_range,
exact h.bUnion (λ y hy, y.finite_to_set)
end
lemma eq_finite_Union_of_finite_subset_Union {ι} {s : ι → set α} {t : set α} (tfin : finite t)
(h : t ⊆ ⋃ i, s i) :
∃ I : set ι, (finite I) ∧ ∃ σ : {i | i ∈ I} → set α,
(∀ i, finite (σ i)) ∧ (∀ i, σ i ⊆ s i) ∧ t = ⋃ i, σ i :=
let ⟨I, Ifin, hI⟩ := finite_subset_Union tfin h in
⟨I, Ifin, λ x, s x ∩ t,
λ i, tfin.subset (inter_subset_right _ _),
λ i, inter_subset_left _ _,
begin
ext x,
rw mem_Union,
split,
{ intro x_in,
rcases mem_Union.mp (hI x_in) with ⟨i, _, ⟨hi, rfl⟩, H⟩,
use [i, hi, H, x_in] },
{ rintros ⟨i, hi, H⟩,
exact H }
end⟩
/-- An increasing union distributes over finite intersection. -/
lemma Union_Inter_of_monotone {ι ι' α : Type*} [fintype ι] [linear_order ι']
[nonempty ι'] {s : ι → ι' → set α} (hs : ∀ i, monotone (s i)) :
(⋃ j : ι', ⋂ i : ι, s i j) = ⋂ i : ι, ⋃ j : ι', s i j :=
begin
ext x, refine ⟨λ hx, Union_Inter_subset hx, λ hx, _⟩,
simp only [mem_Inter, mem_Union, mem_Inter] at hx ⊢, choose j hj using hx,
obtain ⟨j₀⟩ := show nonempty ι', by apply_instance,
refine ⟨finset.univ.fold max j₀ j, λ i, hs i _ (hj i)⟩,
rw [finset.fold_op_rel_iff_or (@le_max_iff _ _)],
exact or.inr ⟨i, finset.mem_univ i, le_rfl⟩
end
instance nat.fintype_Iio (n : ℕ) : fintype (Iio n) :=
fintype.of_finset (finset.range n) $ by simp
/--
If `P` is some relation between terms of `γ` and sets in `γ`,
such that every finite set `t : set γ` has some `c : γ` related to it,
then there is a recursively defined sequence `u` in `γ`
so `u n` is related to the image of `{0, 1, ..., n-1}` under `u`.
(We use this later to show sequentially compact sets
are totally bounded.)
-/
lemma seq_of_forall_finite_exists {γ : Type*}
{P : γ → set γ → Prop} (h : ∀ t, finite t → ∃ c, P c t) :
∃ u : ℕ → γ, ∀ n, P (u n) (u '' Iio n) :=
⟨λ n, @nat.strong_rec_on' (λ _, γ) n $ λ n ih, classical.some $ h
(range $ λ m : Iio n, ih m.1 m.2)
(finite_range _),
λ n, begin
classical,
refine nat.strong_rec_on' n (λ n ih, _),
rw nat.strong_rec_on_beta', convert classical.some_spec (h _ _),
ext x, split,
{ rintros ⟨m, hmn, rfl⟩, exact ⟨⟨m, hmn⟩, rfl⟩ },
{ rintros ⟨⟨m, hmn⟩, rfl⟩, exact ⟨m, hmn, rfl⟩ }
end⟩
lemma finite_range_ite {p : α → Prop} [decidable_pred p] {f g : α → β} (hf : finite (range f))
(hg : finite (range g)) : finite (range (λ x, if p x then f x else g x)) :=
(hf.union hg).subset range_ite_subset
lemma finite_range_const {c : β} : finite (range (λ x : α, c)) :=
(finite_singleton c).subset range_const_subset
lemma range_find_greatest_subset {P : α → ℕ → Prop} [∀ x, decidable_pred (P x)] {b : ℕ}:
range (λ x, nat.find_greatest (P x) b) ⊆ ↑(finset.range (b + 1)) :=
by { rw range_subset_iff, intro x, simp [nat.lt_succ_iff, nat.find_greatest_le] }
lemma finite_range_find_greatest {P : α → ℕ → Prop} [∀ x, decidable_pred (P x)] {b : ℕ} :
finite (range (λ x, nat.find_greatest (P x) b)) :=
(finset.range (b + 1)).finite_to_set.subset range_find_greatest_subset
lemma card_lt_card {s t : set α} [fintype s] [fintype t] (h : s ⊂ t) :
fintype.card s < fintype.card t :=
fintype.card_lt_of_injective_not_surjective (set.inclusion h.1) (set.inclusion_injective h.1) $
λ hst, (ssubset_iff_subset_ne.1 h).2 (eq_of_inclusion_surjective hst)
lemma card_le_of_subset {s t : set α} [fintype s] [fintype t] (hsub : s ⊆ t) :
fintype.card s ≤ fintype.card t :=
fintype.card_le_of_injective (set.inclusion hsub) (set.inclusion_injective hsub)
lemma eq_of_subset_of_card_le {s t : set α} [fintype s] [fintype t]
(hsub : s ⊆ t) (hcard : fintype.card t ≤ fintype.card s) : s = t :=
(eq_or_ssubset_of_subset hsub).elim id
(λ h, absurd hcard $ not_le_of_lt $ card_lt_card h)
lemma subset_iff_to_finset_subset (s t : set α) [fintype s] [fintype t] :
s ⊆ t ↔ s.to_finset ⊆ t.to_finset :=
by simp
@[simp, mono] lemma finite.to_finset_mono {s t : set α} {hs : finite s} {ht : finite t} :
hs.to_finset ⊆ ht.to_finset ↔ s ⊆ t :=
begin
split,
{ intros h x,
rw [←finite.mem_to_finset hs, ←finite.mem_to_finset ht],
exact λ hx, h hx },
{ intros h x,
rw [finite.mem_to_finset hs, finite.mem_to_finset ht],
exact λ hx, h hx }
end
@[simp, mono] lemma finite.to_finset_strict_mono {s t : set α} {hs : finite s} {ht : finite t} :
hs.to_finset ⊂ ht.to_finset ↔ s ⊂ t :=
begin
rw [←lt_eq_ssubset, ←finset.lt_iff_ssubset, lt_iff_le_and_ne, lt_iff_le_and_ne],
simp
end
lemma card_range_of_injective [fintype α] {f : α → β} (hf : injective f)
[fintype (range f)] : fintype.card (range f) = fintype.card α :=
eq.symm $ fintype.card_congr $ equiv.of_injective f hf
lemma finite.exists_maximal_wrt [partial_order β] (f : α → β) (s : set α) (h : set.finite s) :
s.nonempty → ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a' :=
begin
classical,
refine h.induction_on _ _,
{ exact λ h, absurd h empty_not_nonempty },
intros a s his _ ih _,
cases s.eq_empty_or_nonempty with h h,
{ use a, simp [h] },
rcases ih h with ⟨b, hb, ih⟩,
by_cases f b ≤ f a,
{ refine ⟨a, set.mem_insert _ _, λ c hc hac, le_antisymm hac _⟩,
rcases set.mem_insert_iff.1 hc with rfl | hcs,
{ refl },
{ rwa [← ih c hcs (le_trans h hac)] } },
{ refine ⟨b, set.mem_insert_of_mem _ hb, λ c hc hbc, _⟩,
rcases set.mem_insert_iff.1 hc with rfl | hcs,
{ exact (h hbc).elim },
{ exact ih c hcs hbc } }
end
lemma finite.card_to_finset {s : set α} [fintype s] (h : s.finite) :
h.to_finset.card = fintype.card s :=
by { rw [← finset.card_attach, finset.attach_eq_univ, ← fintype.card], congr' 2, funext,
rw set.finite.mem_to_finset }
lemma infinite.exists_not_mem_finset {s : set α} (hs : s.infinite) (f : finset α) :
∃ a ∈ s, a ∉ f :=
let ⟨a, has, haf⟩ := (hs.diff f.finite_to_set).nonempty in ⟨a, has, λ h, haf $ finset.mem_coe.1 h⟩
section decidable_eq
lemma to_finset_compl {α : Type*} [fintype α] [decidable_eq α]
(s : set α) [fintype (sᶜ : set α)] [fintype s] : sᶜ.to_finset = (s.to_finset)ᶜ :=
by ext; simp
lemma to_finset_inter {α : Type*} [decidable_eq α] (s t : set α) [fintype (s ∩ t : set α)]
[fintype s] [fintype t] : (s ∩ t).to_finset = s.to_finset ∩ t.to_finset :=
by ext; simp
lemma to_finset_union {α : Type*} [decidable_eq α] (s t : set α) [fintype (s ∪ t : set α)]
[fintype s] [fintype t] : (s ∪ t).to_finset = s.to_finset ∪ t.to_finset :=
by ext; simp
lemma to_finset_ne_eq_erase {α : Type*} [decidable_eq α] [fintype α] (a : α)
[fintype {x : α | x ≠ a}] : {x : α | x ≠ a}.to_finset = finset.univ.erase a :=
by ext; simp
lemma card_ne_eq [fintype α] (a : α) [fintype {x : α | x ≠ a}] :
fintype.card {x : α | x ≠ a} = fintype.card α - 1 :=
begin
haveI := classical.dec_eq α,
rw [←to_finset_card, to_finset_ne_eq_erase, finset.card_erase_of_mem (finset.mem_univ _),
finset.card_univ, nat.pred_eq_sub_one],
end
end decidable_eq
section
variables [semilattice_sup α] [nonempty α] {s : set α}
/--A finite set is bounded above.-/
protected lemma finite.bdd_above (hs : finite s) : bdd_above s :=
finite.induction_on hs bdd_above_empty $ λ a s _ _ h, h.insert a
/--A finite union of sets which are all bounded above is still bounded above.-/
lemma finite.bdd_above_bUnion {I : set β} {S : β → set α} (H : finite I) :
(bdd_above (⋃i∈I, S i)) ↔ (∀i ∈ I, bdd_above (S i)) :=
finite.induction_on H
(by simp only [bUnion_empty, bdd_above_empty, ball_empty_iff])
(λ a s ha _ hs, by simp only [bUnion_insert, ball_insert_iff, bdd_above_union, hs])
end
section
variables [semilattice_inf α] [nonempty α] {s : set α}
/--A finite set is bounded below.-/
protected lemma finite.bdd_below (hs : finite s) : bdd_below s :=
@finite.bdd_above (order_dual α) _ _ _ hs
/--A finite union of sets which are all bounded below is still bounded below.-/
lemma finite.bdd_below_bUnion {I : set β} {S : β → set α} (H : finite I) :
(bdd_below (⋃i∈I, S i)) ↔ (∀i ∈ I, bdd_below (S i)) :=
@finite.bdd_above_bUnion (order_dual α) _ _ _ _ _ H
end
end set
namespace finset
/-- A finset is bounded above. -/
protected lemma bdd_above [semilattice_sup α] [nonempty α] (s : finset α) :
bdd_above (↑s : set α) :=
s.finite_to_set.bdd_above
/-- A finset is bounded below. -/
protected lemma bdd_below [semilattice_inf α] [nonempty α] (s : finset α) :
bdd_below (↑s : set α) :=
s.finite_to_set.bdd_below
end finset
namespace fintype
variables [fintype α] {p q : α → Prop} [decidable_pred p] [decidable_pred q]
@[simp]
lemma card_subtype_compl : fintype.card {x // ¬ p x} = fintype.card α - fintype.card {x // p x} :=
begin
classical,
rw [fintype.card_of_subtype (set.to_finset pᶜ), set.to_finset_compl p, finset.card_compl,
fintype.card_of_subtype (set.to_finset p)];
intros; simp; refl
end
/-- If two subtypes of a fintype have equal cardinality, so do their complements. -/
lemma card_compl_eq_card_compl (h : fintype.card {x // p x} = fintype.card {x // q x}) :
fintype.card {x // ¬ p x} = fintype.card {x // ¬ q x} :=
by simp only [card_subtype_compl, h]
end fintype
/--
If a set `s` does not contain any elements between any pair of elements `x, z ∈ s` with `x ≤ z`
(i.e if given `x, y, z ∈ s` such that `x ≤ y ≤ z`, then `y` is either `x` or `z`), then `s` is
finite.
-/
lemma set.finite_of_forall_between_eq_endpoints {α : Type*} [linear_order α] (s : set α)
(h : ∀ (x ∈ s) (y ∈ s) (z ∈ s), x ≤ y → y ≤ z → x = y ∨ y = z) :
set.finite s :=
begin
by_contra hinf,
change s.infinite at hinf,
rcases hinf.exists_subset_card_eq 3 with ⟨t, hts, ht⟩,
let f := t.order_iso_of_fin ht,
let x := f 0,
let y := f 1,
let z := f 2,
have := h x (hts x.2) y (hts y.2) z (hts z.2)
(f.monotone $ by dec_trivial) (f.monotone $ by dec_trivial),
have key₁ : (0 : fin 3) ≠ 1 := by dec_trivial,
have key₂ : (1 : fin 3) ≠ 2 := by dec_trivial,
cases this,
{ dsimp only [x, y] at this, exact key₁ (f.injective $ subtype.coe_injective this) },
{ dsimp only [y, z] at this, exact key₂ (f.injective $ subtype.coe_injective this) }
end
|
[GOAL]
I : Type u
f : I → Type v
x y : (i : I) → f i
i : I
g : I → Type u_1
r : (i : I) → Semiring (f i)
m : (i : I) → AddCommMonoid (g i)
inst✝ : (i : I) → Module (f i) (g i)
⊢ ∀ (r_1 s : (i : I) → f i) (x : (i : I) → g i), (r_1 + s) • x = r_1 • x + s • x
[PROOFSTEP]
intros
[GOAL]
I : Type u
f : I → Type v
x y : (i : I) → f i
i : I
g : I → Type u_1
r : (i : I) → Semiring (f i)
m : (i : I) → AddCommMonoid (g i)
inst✝ : (i : I) → Module (f i) (g i)
r✝ s✝ : (i : I) → f i
x✝ : (i : I) → g i
⊢ (r✝ + s✝) • x✝ = r✝ • x✝ + s✝ • x✝
[PROOFSTEP]
ext1
[GOAL]
case h
I : Type u
f : I → Type v
x y : (i : I) → f i
i : I
g : I → Type u_1
r : (i : I) → Semiring (f i)
m : (i : I) → AddCommMonoid (g i)
inst✝ : (i : I) → Module (f i) (g i)
r✝ s✝ : (i : I) → f i
x✝¹ : (i : I) → g i
x✝ : I
⊢ ((r✝ + s✝) • x✝¹) x✝ = (r✝ • x✝¹ + s✝ • x✝¹) x✝
[PROOFSTEP]
apply add_smul
[GOAL]
I : Type u
f : I → Type v
x y : (i : I) → f i
i : I
g : I → Type u_1
r : (i : I) → Semiring (f i)
m : (i : I) → AddCommMonoid (g i)
inst✝ : (i : I) → Module (f i) (g i)
⊢ ∀ (x : (i : I) → g i), 0 • x = 0
[PROOFSTEP]
intros
[GOAL]
I : Type u
f : I → Type v
x y : (i : I) → f i
i : I
g : I → Type u_1
r : (i : I) → Semiring (f i)
m : (i : I) → AddCommMonoid (g i)
inst✝ : (i : I) → Module (f i) (g i)
x✝ : (i : I) → g i
⊢ 0 • x✝ = 0
[PROOFSTEP]
ext1
-- Porting note: not sure why `apply zero_smul` fails here.
[GOAL]
case h
I : Type u
f : I → Type v
x y : (i : I) → f i
i : I
g : I → Type u_1
r : (i : I) → Semiring (f i)
m : (i : I) → AddCommMonoid (g i)
inst✝ : (i : I) → Module (f i) (g i)
x✝¹ : (i : I) → g i
x✝ : I
⊢ (0 • x✝¹) x✝ = OfNat.ofNat 0 x✝
[PROOFSTEP]
rw [zero_smul]
|
subroutine rpn2(ixy,maxm,meqn,mwaves,maux,mbc,mx,ql,qr,auxl,auxr,wave,s,amdq,apdq)
! Riemann solver for the elasticity equations in 2d, with varying
! material properties rho, lambda, and mu, in a mapped grid
!
! This Riemann solver is for mapped grids. It implements the Riemann solver
! in the normal direction (it doesn't do a rotation of coordinates)
!
! Note that although there are 5 eigenvectors, one eigenvalue
! is always zero and so we only need to compute 4 waves.
!
! solve Riemann problems along one slice of data.
!
! On input, ql contains the state vector at the left edge of each cell
! qr contains the state vector at the right edge of each cell
!
! Note that the i'th Riemann problem has left state qr(:,i-1)
! and right state ql(:,i)
! From the basic clawpack routines, this routine is called with ql = qr
!
! This data is along a slice in the x-direction if ixy=1
! or the y-direction if ixy=2.
!
! Contents of ql and qr:
!
! q(1,:) = sigma^{11} if ixy=1 or sigma^{22} if ixy=2
! q(2,:) = sigma^{22} if ixy=1 or sigma^{11} if ixy=2
! q(3,:) = sigma^{12} = sigma^{21}
! q(4,:) = u if ixy=1 or v if ixy=2
! q(5,:) = v if ixy=1 or u if ixy=2
!
! auxl and auxr hold corresponding slice of the aux array:
! Here it is assumed that auxl=auxr gives the cell values
! for this slice.
!
! auxl(1,i) = rho, density
! auxl(2,i) = lambda
! auxl(3,i) = mu
! auxl(4,i) = cp, P-wave speed
! auxl(5,i) = cs, S-wave speed
!
!
! On output, wave contains the waves,
! s the speeds,
! amdq the left-going flux difference A^- \Delta q
! apdq the right-going flux difference A^+ \Delta q
!
! Note that the waves are *not* in order of increasing lambda.
! Instead the 1- and 2-waves are the P-waves and the 3- and 4-waves
! are the S-waves. (The 5th wave has speed zero and is not used.)
implicit none
integer, intent(in) :: ixy, maxm, meqn, mwaves, mbc, mx, maux
double precision, intent(in) :: ql, qr, auxl, auxr
double precision, intent(out) :: wave, s, amdq, apdq
dimension wave( meqn, mwaves, 1-mbc:maxm+mbc)
dimension s(mwaves, 1-mbc:maxm+mbc)
dimension ql(meqn, 1-mbc:maxm+mbc)
dimension qr(meqn, 1-mbc:maxm+mbc)
dimension apdq(meqn, 1-mbc:maxm+mbc)
dimension amdq(meqn, 1-mbc:maxm+mbc)
dimension auxl(maux, 1-mbc:maxm+mbc)
dimension auxr(maux, 1-mbc:maxm+mbc)
integer :: ksig11, ksig22, ku, kv, i, m
double precision :: dsig11, dsig22, dsig12, du, dv
double precision :: alamr, amur, bulkr, cpr, csr
double precision :: alaml, amul, bulkl, cpl, csl
double precision :: det, a1, a2, a3, a4
! Variables required for mapped grid version
integer :: map, mw
double precision :: nx, ny, nx2, ny2, nxy
! set ku to point to the component of the system that corresponds
! to velocity in the direction of this slice, kv to the orthogonal
! velocity. Similarly ksig11 and ksig22 point to normal stresses.
! 3rd component is always shear stress sig12.
if (ixy.eq.1) then
ksig11 = 1
ksig22 = 2
ku = 4
kv = 5
map = 6
else
ksig11 = 2
ksig22 = 1
ku = 5
kv = 4
map = 9
endif
! note that notation for u and v reflects assumption that the
! Riemann problems are in the x-direction with u in the normal
! direciton and v in the orthogonal direcion, but with the above
! definitions of ku and kv the routine also works with ixy=2
! split the jump in q at each interface into waves
! The jump is split into leftgoing waves traveling at speeds -cp, -cs
! relative to the material properties to the left of the interface,
! and rightgoing waves traveling at speeds +cp, +cs
! relative to the material properties to the right of the interface,
do i = 2-mbc, mx+mbc
!Define direction of normal to grid edge normals
nx = auxl(map,i)
ny = auxl(map+1,i)
nx2 = nx*nx
ny2 = ny*ny
nxy = nx*ny
dsig11 = ql(1,i) - qr(1,i-1)
dsig22 = ql(2,i) - qr(2,i-1)
dsig12 = ql(3,i) - qr(3,i-1)
du = ql(4,i) - qr(4,i-1)
dv = ql(5,i) - qr(5,i-1)
! material properties in cells i (on right) and i-1 (on left):
alamr = auxl(2,i)
amur = auxl(3,i)
bulkr = alamr + 2.d0*amur
cpr = auxl(4,i)
csr = auxl(5,i)
alaml = auxr(2,i-1)
amul = auxr(3,i-1)
bulkl = alaml + 2.d0*amul
cpl = auxr(4,i-1)
csl = auxr(5,i-1)
! P-wave strengths:
det = bulkl*cpr + bulkr*cpl
if (det.eq.0.d0) then
write(6,*) 'det=0 in rpn2'
stop
endif
a1 = (cpr*(dsig11*nx2 + dsig22*ny2 + 2*nxy*dsig12) + bulkr*(nx*du + ny*dv)) / det
a2 = (cpl*(dsig11*nx2 + dsig22*ny2 + 2*nxy*dsig12) - bulkl*(nx*du + ny*dv)) / det
! S-wave strengths:
det = amul*csr + amur*csl
if (det.eq.0.d0) then
! no s-waves
a3 = 0.d0
a4 = 0.d0
else
a3 = (csr*(dsig12*(nx2 - ny2) + nxy*(dsig22 - dsig11)) + amur*(nx*dv - ny*du)) / det
a4 = (csl*(dsig12*(nx2 - ny2) + nxy*(dsig22 - dsig11)) + amul*(ny*du - nx*dv)) / det
endif
! 5th wave has velocity 0 so is not computed or propagated.
! Compute the waves.
wave(:,1,i) = 0.d0
wave(1,1,i) = a1 * (alaml + 2*amul*nx2)
wave(2,1,i) = a1 * (alaml + 2*amul*ny2)
wave(3,1,i) = a1 * (2*amul*nxy)
wave(4,1,i) = a1 * cpl * nx
wave(5,1,i) = a1 * cpl * ny
s(1,i) = -cpl
wave(:,2,i) = 0.d0
wave(1,2,i) = a2 * (alamr + 2*amur*nx2)
wave(2,2,i) = a2 * (alamr + 2*amur*ny2)
wave(3,2,i) = a2 * (2*amur*nxy)
wave(4,2,i) = - a2 * cpr * nx
wave(5,2,i) = - a2 * cpr * ny
s(2,i) = cpr
wave(:,3,i) = 0.d0
wave(1,3,i) = - a3 * (2*nxy*amul)
wave(2,3,i) = a3 * (2*nxy*amul)
wave(3,3,i) = a3 * amul*(nx2 - ny2)
wave(4,3,i) = - a3 * csl * ny
wave(5,3,i) = a3 * csl * nx
s(3,i) = -csl
wave(:,4,i) = 0.d0
wave(1,4,i) = - a4 * (2*nxy*amur)
wave(2,4,i) = a4 * (2*nxy*amur)
wave(3,4,i) = a4 * amur*(nx2 - ny2)
wave(4,4,i) = a4 * csr * ny
wave(5,4,i) = -a4 * csr * nx
s(4,i) = csr
! Scales speed by relative length of edge of mapped grid
do mw=1,mwaves
s(mw,i) = s(mw,i)*auxl(map+2,i)
end do
! compute the leftgoing and rightgoing flux differences:
! Note s(i,1),s(i,3) < 0 and s(i,2),s(i,4) > 0.
do m=1,meqn
amdq(m,i) = s(1,i)*wave(m,1,i) + s(3,i)*wave(m,3,i)
apdq(m,i) = s(2,i)*wave(m,2,i) + s(4,i)*wave(m,4,i)
enddo
enddo
return
end subroutine rpn2
|
lemma open_ball: "open {y. dist x y < d}" |
Require Import Coq.Logic.Classical_Prop.
Require Import Logic.lib.Ensembles_ext.
Require Import Logic.lib.Bijection.
Require Import Logic.lib.Countable.
Require Import Logic.GeneralLogic.Base.
Require Import Logic.GeneralLogic.KripkeModel.
Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus.
Require Import Logic.GeneralLogic.Semantics.Kripke.
Require Import Logic.GeneralLogic.Complete.ContextProperty.
Require Import Logic.GeneralLogic.Complete.ContextProperty_Kripke.
Require Import Logic.GeneralLogic.Complete.Lindenbaum.
Require Import Logic.GeneralLogic.Complete.Lindenbaum_Kripke.
Require Import Logic.GeneralLogic.Complete.Canonical_Kripke.
Require Import Logic.GeneralLogic.Complete.Complete_Kripke.
Require Import Logic.MinimunLogic.Syntax.
Require Import Logic.MinimunLogic.ProofTheory.Minimun.
Require Import Logic.MinimunLogic.Semantics.Kripke.
Require Import Logic.MinimunLogic.Complete.ContextProperty_Kripke.
Require Import Logic.MinimunLogic.Complete.Lindenbaum_Kripke.
Require Import Logic.MinimunLogic.Complete.Truth_Kripke.
Require Import Logic.PropositionalLogic.Syntax.
Require Import Logic.PropositionalLogic.ProofTheory.Intuitionistic.
Require Import Logic.PropositionalLogic.ProofTheory.DeMorgan.
Require Import Logic.PropositionalLogic.ProofTheory.GodelDummett.
Require Import Logic.PropositionalLogic.ProofTheory.Classical.
Require Import Logic.PropositionalLogic.Semantics.Kripke.
Require Import Logic.PropositionalLogic.Complete.ContextProperty_Kripke.
Require Import Logic.PropositionalLogic.Complete.Lindenbaum_Kripke.
Require Import Logic.PropositionalLogic.Complete.Truth_Kripke.
Require Import Logic.PropositionalLogic.Complete.Canonical_Kripke.
Require Import Logic.SeparationLogic.Syntax.
Require Import Logic.SeparationLogic.ProofTheory.SeparationLogic.
Require Import Logic.SeparationLogic.ProofTheory.RewriteClass.
Require Import Logic.SeparationLogic.ProofTheory.DerivedRules.
Require Import Logic.SeparationLogic.Model.SeparationAlgebra.
Require Import Logic.SeparationLogic.Model.OrderedSA.
Require Import Logic.SeparationLogic.Semantics.FlatSemantics.
Require Import Logic.SeparationLogic.Complete.ContextProperty_Flat.
Require Import Logic.SeparationLogic.Complete.Lindenbaum_Flat.
Require Import Logic.SeparationLogic.Complete.Truth_Flat.
Require Import Logic.SeparationLogic.Complete.Canonical_Flat.
Require Import Logic.SeparationLogic.DeepEmbedded.Parameter.
Require Logic.SeparationLogic.DeepEmbedded.SeparationEmpLanguage.
Require Logic.SeparationLogic.DeepEmbedded.FlatSemantics.
Require Logic.SeparationLogic.DeepEmbedded.ParametricSeparationLogic.
Local Open Scope logic_base.
Local Open Scope syntax.
Local Open Scope kripke_model.
Local Open Scope kripke_model_class.
Import PropositionalLanguageNotation.
Import SeparationLogicNotation.
Import KripkeModelFamilyNotation.
Import KripkeModelNotation_Intuitionistic.
Import KripkeModelClass.
Section Complete.
Context {Sigma: SeparationEmpLanguage.PropositionalVariables}
{CV: Countable SeparationEmpLanguage.Var}
(SLP: SL_Parameter).
Existing Instances SeparationEmpLanguage.L SeparationEmpLanguage.minL SeparationEmpLanguage.pL SeparationEmpLanguage.sL SeparationEmpLanguage.s'L.
Existing Instances ParametricSeparationLogic.G ParametricSeparationLogic.AX ParametricSeparationLogic.minAX ParametricSeparationLogic.ipG ParametricSeparationLogic.sG ParametricSeparationLogic.eG ParametricSeparationLogic.ParG.
Existing Instances Axiomatization2SequentCalculus_SC Axiomatization2SequentCalculus_bSC Axiomatization2SequentCalculus_fwSC Axiomatization2SequentCalculus_minSC Axiomatization2SequentCalculus_ipSC Axiomatization2SequentCalculus_cpSC.
Existing Instances FlatSemantics.MD FlatSemantics.kMD FlatSemantics.R FlatSemantics.J FlatSemantics.SM FlatSemantics.kminSM FlatSemantics.kpSM FlatSemantics.fsSM FlatSemantics.feSM.
Definition cP : context -> Prop := Intersection _ (Intersection _ derivable_closed orp_witnessed) consistent.
Lemma AL_DC: at_least derivable_closed cP.
Proof. solve_at_least. Qed.
Lemma AL_OW: at_least orp_witnessed cP.
Proof. solve_at_least. Qed.
Lemma AL_CONSI: at_least consistent cP.
Proof. solve_at_least. Qed.
Lemma LIN_CD: forall x: expr, Lindenbaum_constructable (cannot_derive x) cP.
Proof.
intros.
apply Lindenbaum_constructable_suffice; auto.
+ apply SeparationEmpLanguage.formula_countable; auto.
+ apply Lindenbaum_preserves_cannot_derive.
+ unfold cP.
repeat apply Lindenbaum_ensures_by_conjunct.
- apply Lindenbaum_cannot_derive_ensures_derivable_closed.
- apply Lindenbaum_cannot_derive_ensures_orp_witnessed.
- apply Lindenbaum_cannot_derive_ensures_consistent.
Qed.
Lemma LIN_SL: forall (Phi: context) (Psi: sig cP), Lindenbaum_constructable (context_sepcon_included_l Phi (proj1_sig Psi)) cP.
Proof.
intros.
apply Lindenbaum_constructable_suffice; auto.
+ apply SeparationEmpLanguage.formula_countable; auto.
+ apply Lindenbaum_preserves_context_sepcon_included_l.
+ unfold cP.
repeat apply Lindenbaum_ensures_by_conjunct.
- apply Lindenbaum_context_sepcon_included_l_ensures_derivable_closed.
- apply Lindenbaum_context_sepcon_included_l_ensures_orp_witnessed.
* apply AL_DC, (proj2_sig Psi).
* apply AL_OW, (proj2_sig Psi).
- apply Lindenbaum_context_sepcon_included_l_ensures_consistent.
apply AL_CONSI, (proj2_sig Psi).
Qed.
Lemma LIN_SR: forall (Phi: context) (Psi: sig cP), Lindenbaum_constructable (context_sepcon_included_r Phi (proj1_sig Psi)) cP.
Proof.
intros.
eapply Lindenbaum_constructable_Same_set.
+ symmetry.
apply context_sepcon_included_equiv.
apply AL_DC, (proj2_sig Psi).
+ apply LIN_SL.
Qed.
Definition canonical_frame: FlatSemantics.frame :=
FlatSemantics.Build_frame (sig cP)
(fun a b => Included _ (proj1_sig a) (proj1_sig b))
(fun a b c => Included _ (context_sepcon (proj1_sig a) (proj1_sig b)) (proj1_sig c)).
Definition canonical_eval: SeparationEmpLanguage.Var -> FlatSemantics.sem canonical_frame :=
fun p a => proj1_sig a (SeparationEmpLanguage.varp p).
Definition canonical_Kmodel: @Kmodel FlatSemantics.MD FlatSemantics.kMD :=
FlatSemantics.Build_Kmodel canonical_frame canonical_eval.
Definition rel: bijection (Kworlds canonical_Kmodel) (sig cP) := bijection_refl.
Definition H_R:
forall m n Phi Psi, rel m Phi -> rel n Psi ->
(m <= n <-> Included _ (proj1_sig Phi) (proj1_sig Psi)).
Proof.
intros.
change (m = Phi) in H.
change (n = Psi) in H0.
subst; reflexivity.
Qed.
Definition H_J:
forall m1 m2 m Phi1 Phi2 Phi, rel m1 Phi1 -> rel m2 Phi2 -> rel m Phi ->
(join m1 m2 m <-> Included _ (context_sepcon (proj1_sig Phi1) (proj1_sig Phi2)) (proj1_sig Phi)).
Proof.
intros.
change (m = Phi) in H1.
change (m1 = Phi1) in H.
change (m2 = Phi2) in H0.
subst; reflexivity.
Qed.
Lemma TRUTH:
forall x: expr, forall m Phi, rel m Phi ->
(KRIPKE: canonical_Kmodel, m |= x <-> proj1_sig Phi x).
Proof.
induction x.
+ exact (truth_lemma_andp cP rel AL_DC x1 x2 IHx1 IHx2).
+ exact (truth_lemma_orp cP rel AL_DC AL_OW x1 x2 IHx1 IHx2).
+ exact (truth_lemma_impp cP rel H_R AL_DC LIN_CD x1 x2 IHx1 IHx2).
+ exact (truth_lemma_sepcon cP rel H_J AL_DC LIN_SL LIN_SR x1 x2 IHx1 IHx2).
+ exact (truth_lemma_wand cP rel H_J AL_DC LIN_CD LIN_SR x1 x2 IHx1 IHx2).
+ exact (truth_lemma_emp cP rel H_R H_J AL_DC LIN_CD LIN_SR).
+ exact (truth_lemma_falsep cP rel AL_CONSI).
+ intros; change (m = Phi) in H; subst; reflexivity.
Qed.
Context (SAP: SA_Parameter).
Hypothesis PC: Parameter_coincide SLP SAP.
Theorem ParametricCompleteness:
strongly_complete (ParametricSeparationLogic.G SLP) FlatSemantics.SM
(KripkeModelClass _
(FlatSemantics.Kmodel_Monotonic +
FlatSemantics.Kmodel_PreOrder +
FlatSemantics.Kmodel_SeparationAlgebra +
FlatSemantics.Kmodel_UpwardsClosed +
FlatSemantics.Kmodel_DownwardsClosed +
FlatSemantics.Kmodel_Unital +
FlatSemantics.Parametric_Kmodel_Class SAP)).
Proof.
apply (@general_completeness _ _ _ _ _ _ _ _ cP rel LIN_CD TRUTH).
split; [split; [split; [split; [split; [split |] |] |] |] |].
+ hnf; intros.
exact (denote_monotonic cP rel H_R
(SeparationEmpLanguage.varp v)
(TRUTH (SeparationEmpLanguage.varp v))).
+ exact (po_R cP rel H_R).
+ exact (SA cP rel H_J AL_DC LIN_SR).
+ exact (uSA cP rel H_R H_J AL_DC).
+ exact (dSA cP rel H_R H_J AL_DC).
+ exact (unitSA cP rel H_R H_J AL_DC LIN_SR TRUTH).
+ inversion PC.
constructor; intros HH; rewrite HH in *.
- pose proof ParametricSeparationLogic.Parametric_C H.
exact (classical_canonical_ident cP rel H_R AL_DC AL_OW AL_CONSI).
- pose proof ParametricSeparationLogic.Parametric_GD H0.
exact (GodelDummett_canonical_no_branch cP rel H_R AL_DC AL_OW).
- pose proof ParametricSeparationLogic.Parametric_DM H1.
exact (DeMorgan_canonical_branch_join cP rel H_R AL_DC AL_OW AL_CONSI LIN_CD).
- pose proof ParametricSeparationLogic.Parametric_GC H2.
exact (garbage_collected_canonical_increaing cP rel H_R H_J AL_DC).
- pose proof ParametricSeparationLogic.Parametric_NE H3.
exact (nonsplit_canonical_split_smaller cP rel H_R H_J AL_DC TRUTH).
- pose proof ParametricSeparationLogic.Parametric_ED H4.
exact (dup_canonical_incr_join cP rel H_J AL_DC TRUTH).
Qed.
End Complete.
|
(* This file requires:
- An Isabelle Snapshot from no earlier than October 5, 2007
*)
(*
This contains occurence typing with:
- variables as tests
- eta-expansion
*)
theory TypedSchemePreOr
imports Nominal
begin
ML {*ResAtp.set_prover "vampire"*}
(* ML {* ThmDeps.enable() *} *)
(* datatype definitions *)
atom_decl name
datatype ty =
Top | Int | TT | FF | Arr "ty" "ty" "latent_eff" ("_ \<rightarrow> _ : _" [100,100] 100) | Union "ty list"
and latent_eff = NE | Latent ty
constdefs
"BoolTy == Union [TT , FF]"
primrec (unchecked perm_ty)
"pi\<bullet>(ty.Top) = ty.Top"
"pi\<bullet>(ty.Int) = ty.Int"
"pi\<bullet>(TT) = TT"
"pi\<bullet>(FF) = FF"
"pi\<bullet>(\<tau> \<rightarrow> \<sigma> : L) = ((pi\<bullet>\<tau>) \<rightarrow> (pi\<bullet>\<sigma>) : (pi\<bullet>L))"
"pi\<bullet>(Union l) = Union (pi\<bullet>l)"
"pi\<bullet>latent_eff.NE = latent_eff.NE"
"pi\<bullet>(Latent S) = Latent (pi\<bullet>S)"
declare perm_ty.simps[eqvt]
lemma perm_ty_latent_eff_ty_list[simp]:
fixes pi ::"name prm"
and \<tau> ::"ty"
and Ts ::"ty list"
and l ::"latent_eff"
shows "pi\<bullet>\<tau> = \<tau>" and "pi\<bullet>l = l" and "pi\<bullet>Ts = Ts"
by (induct \<tau> and l rule: ty_latent_eff.inducts) auto
instance ty :: pt_name
by intro_classes auto
instance ty :: fs_name
by intro_classes (simp add: supp_def)
instance latent_eff :: pt_name
by intro_classes auto
instance latent_eff :: fs_name
by intro_classes (simp add: supp_def)
fun
size_ty :: "ty \<Rightarrow> nat" and
size_le :: "latent_eff \<Rightarrow> nat"
where
"size_ty (ty.Int) = 1"
| "size_ty (TT) = 1"
| "size_ty (FF) = 1"
| "size_ty (Top) = 1"
| "size_ty (Union []) = 1"
| "size_ty (Union (t#ts)) = size_ty t + size_ty (Union ts)"
| "size_ty (T1 \<rightarrow> T2 : L) = (size_ty T1) + (size_ty T2) + (size_le L)"
| "size_le (Latent L) = size_ty L"
| "size_le (latent_eff.NE) = 1"
lemma size_ty_pos:
"size_ty T > 0"
proof (induct T )
fix l
show "0 < size_ty (Union l)" by (induct l) auto
qed (auto)
nominal_datatype eff = NE | TE "ty" "name" | VE "name" | TT | FF
nominal_datatype builtin = Add1 | NumberP | BooleanP | Nott | ProcP
nominal_datatype trm =
Var "name"
| App "trm" "trm"
| Abs "\<guillemotleft>name\<guillemotright>trm" "ty"
| Iff "trm" "trm" "trm"
| Num "nat"
| Bool "bool"
| BI "builtin"
abbreviation
"lam" :: "name \<Rightarrow> ty \<Rightarrow> trm \<Rightarrow> trm" ("Lam [_:_]._" [100,100,100] 100) where
"Lam[x:T].b \<equiv> trm.Abs x b T"
(* lemmas about names, types, effects *)
lemma trm_finite_supp:
fixes x::"trm"
shows "finite ((supp x)::name set)"
using fs_name_class.axioms[of x] by simp
lemma pt_trm_inst: "pt TYPE(trm) TYPE(name)" using pt_name_inst by auto
lemma fs_trm_inst: "fs TYPE(trm) TYPE(name)" using fs_name_inst by auto
lemma perm_ty_latent[simp]:
fixes T::"ty"
and le::"latent_eff"
and pi::"name prm"
shows "pi\<bullet>le = le \<and> pi\<bullet>T = T"
by simp
lemma perm_ty:
fixes T::"ty"
and le::"latent_eff"
and pi::"name prm"
shows "pi\<bullet>T = T"
by simp
lemma perm_builtin[simp]:
fixes e::"builtin"
and pi::"name prm"
shows "pi\<bullet>e = e"
by (induct rule: builtin.weak_induct) (simp_all)
lemma fresh_ty[simp]:
fixes x::"name"
and T::"ty"
shows "x\<sharp>T"
by (simp add: fresh_def supp_def)
lemma fresh_latent_eff[simp]:
fixes x::"name"
and T::"latent_eff"
shows "x\<sharp>T"
by (simp add: fresh_def supp_def)
lemma fresh_builtin[simp]:
fixes x::"name"
and b::"builtin"
shows "x\<sharp>b"
by (simp add: fresh_def supp_def)
lemma supp_latent_eff_ty:
fixes T::ty and le::latent_eff
shows " supp le = ({}::name set) \<and> supp T = ({}::name set)"
by (simp add: supp_def)
text {* size of a term *}
instance trm :: size ..
nominal_primrec
"size (Var x) = 1"
"size (BI b) = 1"
"size (Bool b) = 1"
"size (Num b) = 1"
"size (App t1 t2) = (max (size t1) (size t2)) + 1"
"size (Iff t1 t2 t3) = (max (size t1) (max (size t2) (size t3))) + 1"
"size (Lam [a:T].t) = (size t) + 1"
by (auto simp add: fresh_nat, finite_guess+, fresh_guess+)
abbreviation
"smaller_than_abb" :: "trm \<Rightarrow> trm \<Rightarrow> bool" ("_ \<guillemotleft> _" [80,80] 80)
where
"a \<guillemotleft> b == size a < size b"
text {* complete induction on terms *}
lemma trm_comp_induct[consumes 0, case_names Var App Lam BI Num Bool Iff]:
fixes P::"'a::fs_name \<Rightarrow> trm \<Rightarrow> bool"
and t::"trm"
and x::"'a::fs_name"
assumes a1:"!! n z. (!! x t. (t \<guillemotleft> Var n) \<Longrightarrow> P x t) \<Longrightarrow> P z (Var n)"
and a2:"!! t1 t2 z. (!! x t. (t \<guillemotleft> App t1 t2) \<Longrightarrow> P x t) \<Longrightarrow> (!! x. P x t1) \<Longrightarrow> (!! x . P x t2)
\<Longrightarrow> P z (App t1 t2)"
and a3:"!! a b z T. \<lbrakk>a \<sharp> z ; (!! x t. (t \<guillemotleft> Lam[a:T].b) \<Longrightarrow> P x t)\<rbrakk> \<Longrightarrow> (!! x . P x b) \<Longrightarrow> P z (Lam[a:T].b)"
and a4:"!! b z. (!! x t. (t \<guillemotleft> BI b) \<Longrightarrow> P x t) \<Longrightarrow> P z (BI b)"
and a5:"!! n z. (!! x t. (t \<guillemotleft> Num n) \<Longrightarrow> P x t) \<Longrightarrow> P z (Num n)"
and a6:"!! b z. (!! x t. (t \<guillemotleft> Bool b) \<Longrightarrow> P x t) \<Longrightarrow> P z (Bool b)"
and a7:"!! t1 t2 t3 z. (!! x t. t \<guillemotleft> (Iff t1 t2 t3) \<Longrightarrow> P x t)
\<Longrightarrow> (!! x. P x t1) \<Longrightarrow> (!! x . P x t2) \<Longrightarrow> (!! x. P x t3) \<Longrightarrow> P z (Iff t1 t2 t3)"
shows "P x t"
proof (induct t arbitrary: x taking:"(% t :: trm. size t)" rule: measure_induct_rule)
case (less s x) thus ?case
-- "This would go through automatically, but I'm skeptical of that sort of thing"
proof (nominal_induct s avoiding: x rule: trm.induct)
case (Var v) thus ?case using a1 by auto
next
case (App t1 t2) thus ?case using a2 by auto
next
case (Abs a b T) thus ?case using a3 by auto
next
case (Iff t1 t2 t3) thus ?case using a7 by auto
next
case (BI b) thus ?case using a4 by auto
next
case (Num n) thus ?case using a5 by auto
next
case (Bool b) thus ?case using a6 by auto
qed
qed
text {* closed terms *}
constdefs
fv :: "trm \<Rightarrow> name set"
fv_def[simp]:"fv e == ((supp e):: name set)"
constdefs
closed :: "trm \<Rightarrow> bool"
closed_def: "closed e == (fv e = {})"
lemma closed_lam: --"A statement about the free variables of lam bodies"
assumes "closed (Lam[x:T].b)" (is "closed ?e")
shows "fv b <= {x}"
proof -
have "(supp ([x].b)::name set) = supp b - {x}"
using fs_name_class.axioms abs_fun_supp[of b x] pt_trm_inst at_name_inst by auto
hence "supp ?e = ((((supp b):: name set) - {x}) :: name set)" using supp_latent_eff_ty trm.supp by simp
thus ?thesis using prems closed_def by auto
qed
lemma closed_eqvt[eqvt]:
fixes pi::"name prm"
shows "closed e \<Longrightarrow> closed (pi\<bullet>e)"
proof -
have A:"(pi\<bullet>fv e) = fv (pi\<bullet>e)" using pt_perm_supp[of pi e] at_name_inst pt_trm_inst by auto
assume "closed e"
hence "fv e = {}" using closed_def by simp
hence "(pi\<bullet>fv e) = {}" using empty_eqvt[of pi] by auto
hence "closed (pi\<bullet>e)" using A closed_def by auto
thus ?thesis .
qed
text {* capture-avoiding substitution *}
consts subst :: "trm \<Rightarrow> name \<Rightarrow> trm \<Rightarrow> trm" ("_[_::=_]" [100,100,100] 100)
nominal_primrec
"(Var x)[y::=t'] = (if x=y then t' else (Var x))"
"(App t1 t2)[y::=t'] = App (t1[y::=t']) (t2[y::=t'])"
"x\<sharp>(y,t',T) \<Longrightarrow> (Lam[x:T].t)[y::=t'] = Lam[x:T].(t[y::=t'])"
"(Iff tst thn els)[y::=t'] = (Iff (tst[y::=t']) (thn[y::=t']) (els[y::=t']))"
"(BI c)[y::=t'] = (BI c)"
"(Num c)[y::=t'] = (Num c)"
"(Bool c)[y::=t'] = (Bool c)"
by (finite_guess+, auto simp add: abs_fresh, fresh_guess+)
lemma subst_eqvt[simp, eqvt]:
fixes pi:: "name prm"
and t1:: "trm"
and t2:: "trm"
and a :: "name"
shows "pi\<bullet>(t1[b::=t2]) = (pi\<bullet>t1)[(pi\<bullet>b)::=(pi\<bullet>t2)]"
by (nominal_induct t1 avoiding: b t2 rule: trm.induct)
(auto simp add: perm_bij fresh_prod fresh_atm fresh_bij)
lemma subst_rename[rule_format]:
shows "c\<sharp>t1 \<longrightarrow> (t1[a::=t2] = ([(c,a)]\<bullet>t1)[c::=t2])"
by (nominal_induct t1 avoiding: a c t2 rule: trm.induct)
(auto simp add: calc_atm fresh_atm abs_fresh fresh_nat trm.inject perm_nat_def perm_bool)
lemma forget:
assumes a: "a\<sharp>t1"
shows "t1[a::=t2] = t1"
using a
by (nominal_induct t1 avoiding: a t2 rule: trm.induct)
(auto simp add: abs_fresh fresh_atm)
lemma subst_removes_var:
assumes "e1[x::=e0] = e2" and "x \<sharp> e0"
shows "x \<sharp> e2"
using prems
proof (nominal_induct e1 avoiding: e0 x e2 rule: trm.induct)
case (Var v e0' x' e2')
thus ?case using at_fresh[of x' v] at_name_inst
by (cases "x' = v") auto
next
case App thus ?case by auto
next
case Iff thus ?case by auto
next
case BI thus ?case by auto
next
case Num thus ?case by (auto simp add: fresh_nat)
next
case (Bool b) thus ?case
by (auto simp add: fresh_def supp_bool trm.supp)
next
case (Abs v e1' T e0' x' e2')
let ?body = "(e1'[x'::=e0'])"
have a:"finite ((supp ?body) :: name set)" using fs_name1 by auto
have f:"x' \<sharp> (e1'[x'::=e0'])" using Abs by auto
hence "v \<sharp> (x',e0',T)" using Abs by auto
hence "(Abs v e1' T)[x'::=e0'] = Abs v (e1'[x'::=e0']) T" by auto
hence "\<dots> = e2'" using Abs by auto
have "v \<noteq> x'" using `v \<sharp> x'` at_fresh[of v x'] at_name_inst by auto
hence "x' \<sharp> v" using at_fresh[of x' v] at_name_inst by auto
have "x' \<sharp> T" using fresh_def supp_latent_eff_ty by auto
have "x' \<sharp> [v].(e1'[x'::=e0'])" using `v ~= x'` fresh_abs_funI1[of ?body x' v ] pt_trm_inst at_name_inst a f by auto
hence "x' \<sharp> Abs v (e1'[x'::=e0']) T" using f trm.fresh Abs by auto
thus ?case using Abs by auto
qed
lemma fv_lam:
fixes name
shows "fv (Lam[name:T].body) = fv body - {name}"
proof -
have sT:"supp T = ({} :: name set)" using supp_latent_eff_ty by auto
have "fv (Lam[name:T].body) = (supp ([name].body):: name set) \<union> supp T" using trm.supp by auto
also have "\<dots> = (supp ([name].body):: name set)" using sT by auto
also have "\<dots> = supp body - ({name} :: name set)"
using abs_fun_supp[of body name] at_name_inst pt_trm_inst fs_name1[of body] by simp
also have "\<dots> = fv body - {name}" by simp
finally show "fv (Lam[name:T].body) = fv body - {name}" by simp
qed
lemma subst_closed:
assumes "e1[x::=e0] = e2" and "closed e0"
shows "fv e2 <= fv e1"
using prems
proof (nominal_induct e1 avoiding: e0 x e2 rule: trm.induct)
case (Var v e0' x' e2')
thus ?case using at_fresh[of x' v] at_name_inst closed_def
by (cases "x' = v") auto
next
case (App rator rand e0' x' e2')
let ?subrator = "rator[x'::=e0']"
let ?subrand = "rand[x'::=e0']"
have a:"e2' = App ?subrator ?subrand" using App by simp
have s1:"fv ?subrator <= fv rator" using App by simp
have s2:"fv ?subrand <= fv rand" using App by simp
have b:"fv e2' = fv ?subrator \<union> fv ?subrand" using trm.supp App a by simp
have d:"fv (App rator rand) = fv rator \<union> fv rand" using trm.supp by simp
show ?case using d s1 s2 b by auto
next
case BI thus ?case by auto
next
case Num thus ?case by (auto simp add: fresh_nat)
next
case (Bool b) thus ?case
by (auto simp add: fresh_def supp_bool trm.supp)
next
case (Iff tst thn els e0' x' e2')
let ?subtst = "tst[x'::=e0']"
let ?subthn = "thn[x'::=e0']"
let ?subels = "els[x'::=e0']"
have a:"e2' = Iff ?subtst ?subthn ?subels" using Iff by simp
have s1:"fv ?subtst <= fv tst" using Iff by simp
have s2:"fv ?subthn <= fv thn" using Iff by simp
have s3:"fv ?subels <= fv els" using Iff by simp
have b:"fv e2' = fv ?subtst \<union> fv ?subthn \<union> fv ?subels" using trm.supp Iff a by auto
have d:"fv (Iff tst thn els) = fv tst \<union> fv thn \<union> fv els" using trm.supp by auto
show ?case using d s1 s2 s3 b by auto
next
case (Abs name body T e0' x' e2')
have aa:"fv (body[x'::=e0']) \<subseteq> fv body" using Abs by auto
have a:"fv (Lam[name:T].body) = fv body - {name}" using fv_lam by simp
have b:"fv (Lam[name:T].(body[x'::=e0'])) = fv (body[x'::=e0']) - {name}" using fv_lam by simp
have "name \<sharp> (e0',T,x')" using Abs by auto
hence c:"(Lam[name:T].(body[x'::=e0'])) = (Lam[name:T].(body))[x'::=e0']" by simp
hence d:"fv e2' = fv (body[x'::=e0']) - {name}" using b Abs by auto
thus ?case using a aa by auto
qed
lemma subst_only_var_closed:
assumes "closed e0" and "fv e1 <= {x}"
shows "closed (e1[x::=e0])"
proof -
let ?e2 = "(e1[x::=e0])"
have a:"fv ?e2 <= {x}" using prems subst_closed[of e1 x e0 ?e2] by auto
have "x \<sharp> e0" using prems fresh_def[of x e0] closed_def[of e0] by auto
hence "x \<sharp> ?e2" using subst_removes_var[of e1 x e0 ?e2] by auto
hence b:"x \<notin> fv ?e2" using fresh_def[of x ?e2] closed_def[of ?e2] by auto
from a b have "fv ?e2 = {}" by auto
thus ?thesis using closed_def by simp
qed
lemma beta_closed_closed:
assumes "closed (Lam[x:T].b)" and "closed v"
shows "closed (b[x::=v])"
using prems closed_lam subst_only_var_closed
by auto
text {* values *}
inductive values :: "trm \<Rightarrow> bool" ("_ : values" [80])
where
abs_value[simp]: "Lam[x:t].b : values"
| bi_value[simp]: "BI c : values"
| num_value[simp]: "Num n : values"
| bool_value[simp]: "Bool b : values"
equivariance values
abbreviation
"in_values" :: "trm \<Rightarrow> bool" ("_ \<in> values" [100] 100) where
"e \<in> values \<equiv> (e : values)"
abbreviation
"not_in_values" :: "trm \<Rightarrow> bool" ("_ \<notin> values" [100] 100) where
"e \<notin> values \<equiv> (~ e : values)"
lemma not_false_eqvt:
fixes pi :: "name prm"
and t :: "trm"
assumes a:"t ~= trm.Bool False" and b:"t : values"
shows "(pi\<bullet>t) ~= trm.Bool False"
using b a
by induct (auto simp add: perm_bool)
inductive_cases iff_value:"Iff a b c : values"
inductive_cases app_value:"App a b : values"
inductive_cases var_value:"Var a : values"
nominal_inductive values by (simp add: abs_fresh)
text {* Typing Constants *}
consts
\<Delta>\<^isub>\<tau> :: "builtin \<Rightarrow> ty"
nominal_primrec
"\<Delta>\<^isub>\<tau> NumberP = (Top \<rightarrow> BoolTy : Latent ty.Int)"
"\<Delta>\<^isub>\<tau> BooleanP = (Top \<rightarrow> BoolTy : Latent BoolTy)"
"\<Delta>\<^isub>\<tau> ProcP = (Top \<rightarrow> BoolTy : Latent (Union [] \<rightarrow> Top : latent_eff.NE))"
"\<Delta>\<^isub>\<tau> Add1 = (ty.Int \<rightarrow> ty.Int : latent_eff.NE)"
"\<Delta>\<^isub>\<tau> Nott = (Top \<rightarrow> BoolTy : latent_eff.NE)"
by simp_all
lemma delta_t_eqvt[eqvt]:
fixes pi :: "name prm"
shows "pi \<bullet> \<Delta>\<^isub>\<tau> b = \<Delta>\<^isub>\<tau> (pi \<bullet> b)"
by (nominal_induct b rule: builtin.induct) auto
(* Delta Function *)
consts
\<Delta> :: "builtin \<Rightarrow> trm \<Rightarrow> trm option"
add1_fun :: "trm \<Rightarrow> trm option"
nott_fun :: "trm \<Rightarrow> trm option"
numberp_fun :: "trm \<Rightarrow> bool"
booleanp_fun :: "trm \<Rightarrow> bool"
procp_fun :: "trm \<Rightarrow> bool"
procp_bi_fun :: "builtin \<Rightarrow> bool"
nominal_primrec
"add1_fun (Num n) = Some (Num (n+1))"
"add1_fun (Lam[x:ty].b) = None"
"add1_fun (Iff a b c) = None"
"add1_fun (App a b) = None"
"add1_fun (Bool a) = None"
"add1_fun (BI a) = None"
"add1_fun (Var a) = None"
by (auto, finite_guess+, fresh_guess+)
nominal_primrec
"nott_fun (Num n) = (Some (Bool False))"
"nott_fun (Lam[x:ty].b) = (Some (Bool False))"
"nott_fun (Iff a b c) = (Some (Bool False))"
"nott_fun (App a b) = (Some (Bool False))"
"nott_fun (Bool b) = Some (Bool (~b))"
"nott_fun (BI a) = (Some (Bool False))"
"nott_fun (Var a) = (Some (Bool False))"
by (auto, finite_guess+, fresh_guess+)
nominal_primrec
"booleanp_fun (Bool b) = True"
"booleanp_fun (Num n) = False"
"booleanp_fun (Abs a b c) = False"
"booleanp_fun (App a b) = False"
"booleanp_fun (BI c) = False"
"booleanp_fun (Var v) = False"
"booleanp_fun (Iff a b c) = False"
by (auto, finite_guess+, fresh_guess+)
nominal_primrec
"procp_fun (Bool b) = False"
"procp_fun (Num n) = False"
"procp_fun (Abs a b c) = True"
"procp_fun (App a b) = False"
"procp_fun (BI c) = True"
"procp_fun (Var v) = False"
"procp_fun (Iff a b c) = False"
by (auto, finite_guess+, fresh_guess+)
nominal_primrec
"numberp_fun (Bool b) = False"
"numberp_fun (Num n) = True"
"numberp_fun (Abs a b c) = False"
"numberp_fun (App a b) = False"
"numberp_fun (BI c) = False"
"numberp_fun (Var v) = False"
"numberp_fun (Iff a b c) = False"
by (auto, finite_guess+, fresh_guess+)
nominal_primrec
"\<Delta> Add1 t = add1_fun t"
"\<Delta> Nott t = nott_fun t"
"\<Delta> BooleanP t = Some (Bool (booleanp_fun t))"
"\<Delta> NumberP t = Some (Bool (numberp_fun t))"
"\<Delta> ProcP t = Some (Bool (procp_fun t))"
by simp_all
lemma delta_eqvt:
fixes pi :: "name prm"
and b :: builtin
and t :: "trm"
shows "\<Delta> (pi\<bullet>b) (pi\<bullet>t) = \<Delta> b t"
proof -
have A:"(pi\<bullet>b) = b" by (nominal_induct b rule: builtin.induct) auto
have B:"\<Delta> b (pi\<bullet>t) = \<Delta> b t"
proof (nominal_induct rule: builtin.induct)
case Add1
thus ?case
by (nominal_induct t rule: trm.induct) (auto simp add: perm_nat_def)
next
case Nott
thus ?case
by (nominal_induct t rule: trm.induct) (auto simp add: perm_bool)
next
case BooleanP
thus ?case
by (nominal_induct t rule: trm.induct) (auto simp add: perm_bool)
next
case NumberP
thus ?case
by (nominal_induct t rule: trm.induct) (auto simp add: perm_bool)
next
case ProcP
thus ?case
by (nominal_induct t rule: trm.induct) (auto simp add: perm_bool)
qed
from A B show ?thesis by auto
qed
lemma delta_eqvt2[eqvt]:
fixes pi :: "name prm"
and b :: builtin
and t :: "trm"
shows "(pi\<bullet>(\<Delta> b t)) = \<Delta> (pi\<bullet>b) (pi\<bullet>t)"
proof -
have A:"(pi\<bullet>b) = b" by (nominal_induct b rule: builtin.induct) auto
have B:"\<Delta> b (pi\<bullet>t) = (pi\<bullet>(\<Delta> b t))"
proof (nominal_induct rule: builtin.induct)
case Add1
thus ?case
by (nominal_induct t rule: trm.induct) (auto simp add: perm_nat_def)
next
case Nott
thus ?case
by (nominal_induct t rule: trm.induct) (auto simp add: perm_bool)
next
case BooleanP
thus ?case
by (nominal_induct t rule: trm.induct) (auto simp add: perm_bool)
next
case NumberP
thus ?case
by (nominal_induct t rule: trm.induct) (auto simp add: perm_bool)
next
case ProcP
thus ?case
by (nominal_induct t rule: trm.induct) (auto simp add: perm_bool)
qed
from A B show ?thesis by auto
qed
lemma delta_closed:
fixes b :: builtin and t::trm
assumes "\<Delta> b t = Some v"
shows "closed v"
using prems
proof (nominal_induct b rule: builtin.induct)
case Add1
thus ?case
by (nominal_induct t rule: trm.induct)
(auto simp add: supp_nat closed_def trm.supp)
next
case Nott
thus ?case
by (nominal_induct t rule: trm.induct)
(auto simp add: supp_def perm_bool closed_def trm.supp)
next
case BooleanP
thus ?case
by (nominal_induct t rule: trm.induct)
(auto simp add: supp_def perm_bool closed_def trm.supp)
next
case NumberP
thus ?case
by (nominal_induct t rule: trm.induct)
(auto simp add: supp_def perm_bool closed_def trm.supp)
next
case ProcP
thus ?case
by (nominal_induct t rule: trm.induct)
(auto simp add: supp_def perm_bool closed_def trm.supp)
qed
lemma delta_value:
fixes b :: builtin and t::trm
assumes "\<Delta> b t = Some v"
shows "v : values"
using prems
proof (nominal_induct b rule: builtin.induct)
case Add1
thus ?case by (nominal_induct t rule: trm.induct) auto
next
case Nott
thus ?case
by (nominal_induct t rule: trm.induct) auto
next
case BooleanP
thus ?case
by (nominal_induct t rule: trm.induct) auto
next
case NumberP
thus ?case
by (nominal_induct t rule: trm.induct) auto
next
case ProcP
thus ?case
by (nominal_induct t rule: trm.induct) auto
qed
text {* Evaluation contexts *}
inductive_set ctxt :: "(trm \<Rightarrow> trm) set"
where
C_Hole[simp, intro]: "(%t. t) \<in> ctxt"
| C_App1[simp, intro]: "E : ctxt \<Longrightarrow> (%t . (App (E t) u)) : ctxt"
| C_App2[simp, intro]: "E : ctxt \<Longrightarrow> v : values \<Longrightarrow> (%t . (App v (E t))) : ctxt"
| C_Iff[simp, intro]: "E : ctxt \<Longrightarrow> (%t . (Iff (E t) thn els)) : ctxt"
lemma ctxt_compose:
assumes a:"E1 : ctxt" and b:"E2 : ctxt"
shows "(%t. E1 (E2 t)) : ctxt"
using a b
by (induct E1) auto
constdefs
closed_ctxt :: "(trm \<Rightarrow> trm) \<Rightarrow> bool"
closed_ctxt_def[simp]:"closed_ctxt C == (C : ctxt \<and> closed (C (Num 3)))" --"3 is a trivially closed term"
lemma ctxt_closed:
assumes "closed_ctxt C"
shows "closed (C e) = closed e"
using prems
proof -
have "C : ctxt" using prems by simp
thus ?thesis using prems
by (induct) (auto simp add: closed_def trm.supp)
qed
lemma closed_in_ctxt_closed_ctxt:
assumes "closed e" and a:"C : ctxt" and "e = C L"
shows "closed L \<and> closed_ctxt C"
using a prems
proof (induct C arbitrary: L e rule: ctxt.induct)
case C_Hole
thus ?case by (auto simp add: closed_def trm.supp supp_nat)
next
case (C_App1 E arg L' e')
have IH:"!!e L. \<lbrakk>closed e; E \<in> ctxt; e = E L\<rbrakk> \<Longrightarrow> closed L \<and> closed_ctxt E" using prems by blast
have cl:"closed (App (E L') arg)" using `e' = (App (E L') arg)` `closed e'` by simp
from cl have "closed arg"by (auto simp add: closed_def trm.supp)
from cl have "closed (E L')" by (auto simp add: closed_def trm.supp)
thus ?case using IH[of "(E L')" L'] `E : ctxt` `closed arg`
by (auto simp add: trm.supp closed_def)
next
case (C_App2 E rator L' e')
have IH:"!!e L. \<lbrakk>closed e; E \<in> ctxt; e = E L\<rbrakk> \<Longrightarrow> closed L \<and> closed_ctxt E" using prems by blast
have cl:"closed (App rator (E L'))" using prems by blast
from cl have "closed rator" by (auto simp add: closed_def trm.supp)
from cl have "closed (E L')" by (auto simp add: closed_def trm.supp)
thus ?case using IH[of "(E L')" L'] `E : ctxt` `closed rator`
by (auto simp add: trm.supp closed_def)
next
case (C_Iff E thn els L' e')
let ?trm = "Iff (E L') thn els"
have IH:"!!e L. \<lbrakk>closed e; E \<in> ctxt; e = E L\<rbrakk> \<Longrightarrow> closed L \<and> closed_ctxt E" using prems by blast
have cl:"closed ?trm" using prems by blast
from cl have "closed thn" and "closed els" by (auto simp add: closed_def trm.supp)
from cl have "closed (E L')" by (auto simp add: closed_def trm.supp)
thus ?case using IH[of "(E L')" L'] `E : ctxt` `closed thn` `closed els`
by (auto simp add: trm.supp closed_def)
qed
lemma closed_in_ctxt:
assumes "closed (C L)"
and "C : ctxt"
shows "closed L"
using `C : ctxt` `closed (C L)`
by (induct C) (auto simp add: closed_def trm.supp)
text{* Reduction *}
inductive reduce :: "trm \<Rightarrow> trm \<Rightarrow> bool" ("_ \<hookrightarrow> _" [200,200] 200)
where
e_beta[simp]: "v : values \<Longrightarrow> x \<sharp> v \<Longrightarrow> (App (Lam[x:t].b) v) \<hookrightarrow> (b[x::=v])"
| e_if_false[simp]: "Iff (Bool False) e1 e2 \<hookrightarrow> e2"
| e_if_true[simp]: "v ~= Bool False \<Longrightarrow> v : values \<Longrightarrow> Iff v e1 e2 \<hookrightarrow> e1"
| e_delta[simp]: "\<lbrakk>v : values; \<Delta> p v = Some e\<rbrakk> \<Longrightarrow> App (BI p) v \<hookrightarrow> e"
equivariance reduce
nominal_inductive reduce
by (simp_all add: abs_fresh subst_removes_var)
inductive
"step" :: "trm\<Rightarrow>trm\<Rightarrow>bool" (" _ \<longrightarrow> _" [80,80]80)
where
step_one[intro]:"\<lbrakk>E : ctxt; L \<hookrightarrow> R\<rbrakk> \<Longrightarrow> E L \<longrightarrow> E R"
inductive
step_multi :: "trm \<Rightarrow> trm \<Rightarrow> bool" (" _ \<longrightarrow>\<^sup>* _" [80,80] 80)
where
sm_refl:"a \<longrightarrow>\<^sup>* a"
| sm_trans:"a \<longrightarrow> b \<Longrightarrow> b \<longrightarrow>\<^sup>* c \<Longrightarrow> a \<longrightarrow>\<^sup>* c"
(* doesn't work *)
(* equivariance step *)
constdefs
reduce_forever :: "trm \<Rightarrow> bool"
"reduce_forever e == \<forall>e' . (e \<longrightarrow>\<^sup>* e') \<longrightarrow> (EX e''. e' \<longrightarrow> e'')"
(* reduction examples *)
lemma "(App (Lam [x:t].(Var x)) (Num 4)) \<hookrightarrow> Num 4"
proof -
have "Num 4 : values" "x \<sharp> Num 4" by (auto simp add: fresh_nat)
hence h:"(App (Lam [x:t].(Var x)) (Num 4)) \<hookrightarrow> ((Var x)[x::=(Num 4)])" by (rule e_beta)
have "((Var x)[x::=(Num 4)]) = Num 4" by auto
thus ?thesis using h by auto
qed
(* some lemmas about reduction *)
lemma if_val_reduces:
assumes a:"tst : values"
shows "Iff tst thn els \<hookrightarrow> thn \<or> Iff tst thn els \<hookrightarrow> els"
using a
proof (nominal_induct tst rule: trm.induct)
case (Bool b)
thus ?case using e_if_true e_if_false
by (cases b) (auto simp add: trm.inject)
qed (auto)
(* a helper lemma - whee abstraction *)
lemma ex_help:
assumes a:"e = E t \<and> E : ctxt \<and> t \<hookrightarrow> t'"
shows "\<exists>E t t' . e = E t \<and> E \<in> ctxt \<and> t \<hookrightarrow> t'"
using a by blast
lemma reduce_in_ctxt:
fixes e :: trm
assumes ct:"C : ctxt"
and ih:"(EX E L R. e = E L \<and> E : ctxt \<and> L \<hookrightarrow> R)"
shows "(EX E L R. C e = E L \<and> E : ctxt \<and> L \<hookrightarrow> R)"
proof -
from ih ct obtain Enew tnew t'new where "e = Enew tnew" and 1:"Enew \<in> ctxt" and g1:"tnew \<hookrightarrow> t'new" by auto
let ?E="(%t . C (Enew t))"
have g3:"?E tnew = C e" using `e = Enew tnew` by auto
thus "\<exists>E t t' . C e = E t \<and> E \<in> ctxt \<and> t \<hookrightarrow> t'"
using ctxt_compose[OF ct 1] g1 g3 ex_help[of "C e" ?E tnew] by auto
qed
inductive_cases iff_bi_red : "(Iff (Const (BI bi)) thn els) \<hookrightarrow> e"
inductive_cases iff_red : "(Iff tst thn els) \<hookrightarrow> e"
lemma reduce_closed:
assumes "closed L" and "L \<hookrightarrow> R"
shows "closed R"
using `L \<hookrightarrow> R` `closed L`
proof (induct)
case (e_beta v x t b)
have a:"closed (Abs x b t)" using e_beta closed_def trm.supp by simp
have b:"closed v" using e_beta closed_def trm.supp by simp
from a b show ?case using e_beta beta_closed_closed by simp
next
case e_if_true thus ?case using closed_def trm.supp by auto
next
case e_if_false thus ?case using closed_def trm.supp by auto
next
case e_delta thus ?case using delta_closed by auto
qed
lemma step_closed:
assumes A:"closed e" and B:"(e :: trm) \<longrightarrow> e'"
shows "closed e'"
proof -
from B obtain E L R where C:"E : ctxt" "e = E L" "L \<hookrightarrow> R" "e' = E R" by induct auto
hence D:"closed L" "closed_ctxt E" using A closed_in_ctxt_closed_ctxt[of e E L] by auto
hence "closed R" using C reduce_closed[of L R] by auto
hence "closed e'" using C D ctxt_closed[of E R] by auto
thus ?thesis .
qed
lemma multi_step_closed:
assumes A:"closed e" and B:"e \<longrightarrow>\<^sup>* e'"
shows "closed e'"
using B A step_closed
by induct auto
text {* "partial order" (not really) between effects *}
inductive
subeff :: "eff \<Rightarrow> eff \<Rightarrow> bool"("\<turnstile> _ <e: _" [60,60] 60)
where
SE_Refl[intro]: "\<turnstile> F <e: F"
| SE_FF[intro]: "F \<noteq> TT \<Longrightarrow> \<turnstile> FF <e: F"
| SE_TT[intro]: "F \<noteq> FF \<Longrightarrow> \<turnstile> TT <e: F"
| SE_VE[intro]: "\<turnstile> NE <e: VE x"
| SE_TE[intro]: "\<turnstile> NE <e: TE S x"
equivariance subeff
inductive_cases ne_case:"\<turnstile> F1 <e: eff.NE"
inductive_cases ne_case_rev:"\<turnstile> eff.NE <e: F1"
inductive_cases tt_case:"\<turnstile> F1 <e: eff.TT"
inductive_cases tt_case_rev:"\<turnstile> eff.TT <e: F1"
inductive_cases ff_case:"\<turnstile> F1 <e: eff.FF"
inductive_cases ff_case_rev:"\<turnstile> eff.FF <e: F1"
lemma no_sub_FF:
"\<lbrakk>\<turnstile> T <e: T' ; T' = FF \<rbrakk> \<Longrightarrow> T = FF"
by (induct rule: subeff.induct) auto
lemma no_sub_TT:
"\<lbrakk>\<turnstile> T <e: T' ; T' = TT \<rbrakk> \<Longrightarrow> T = TT"
by (induct rule: subeff.induct) auto
constdefs
simple_eff :: "eff \<Rightarrow> bool"
simple_eff_def[simp]:"simple_eff e == e = eff.NE \<or> e = FF \<or> e = TT"
lemma simple_eff_cases[consumes 1, case_names NE FF TT]:
fixes F::eff
and P :: "eff \<Rightarrow> bool"
assumes a:"simple_eff F"
and a1:"P NE"
and a2:"P FF"
and a3:"P TT"
shows "P F"
using prems
by (nominal_induct F rule: eff.induct) auto
lemma simple_eff_below_ne:
assumes "simple_eff F"
shows "\<turnstile> F <e: NE"
using prems
by (nominal_induct F rule: eff.induct) auto
lemma SE_Trans[intro]:
assumes"\<turnstile> F1 <e: F2 "and "\<turnstile> F2 <e: F3 " and "simple_eff F1" and "simple_eff F2" and "simple_eff F3"
shows " \<turnstile> F1 <e: F3"
using `simple_eff F3` prems
proof (induct F3 rule: simple_eff_cases)
case NE thus ?case using simple_eff_below_ne by auto
next
case FF thus ?case using no_sub_FF by auto
next
case TT thus ?case using no_sub_TT by auto
qed
text{* subtyping *}
inductive
subtype :: "ty \<Rightarrow> ty \<Rightarrow> bool" ("\<turnstile> _ <: _" [60,60] 60)
where
S_Refl[intro]: "\<turnstile> T <: T"
| S_Fun[intro]: "\<lbrakk>\<turnstile> S1 <: T1 ; \<turnstile> T2 <: S2 ; eff = eff' \<or> eff' = latent_eff.NE\<rbrakk> \<Longrightarrow> \<turnstile> (T1 \<rightarrow> T2 : eff) <: (S1 \<rightarrow> S2 : eff')"
| S_Top[intro]: "\<turnstile> T <: Top"
| S_UnionAbove[intro]: "\<lbrakk>T : set Ts ; \<turnstile> S <: T\<rbrakk> \<Longrightarrow> \<turnstile> S <: Union Ts"
| S_UnionBelow[intro]: "\<lbrakk>!! T.( T : set Ts \<Longrightarrow> \<turnstile> T <: S)\<rbrakk> \<Longrightarrow> \<turnstile> Union Ts <: S"
equivariance subtype
nominal_inductive subtype done
inductive_cases sub_arr_cases: "\<turnstile> T <: S1 \<rightarrow> S2 : L"
lemma subtype_arr_elim:
"\<lbrakk>\<turnstile> T <: S ; S = S0 \<rightarrow> S1 : le\<rbrakk> \<Longrightarrow> (EX T0 T1. T = T0 \<rightarrow> T1 : le \<and> \<turnstile> S0 <: T0 \<and> \<turnstile> T1 <: S1) \<or> (EX T0 T1 le'. T = T0 \<rightarrow> T1 : le' \<and> le = latent_eff.NE \<and> \<turnstile> S0 <: T0 \<and> \<turnstile> T1 <: S1) \<or> (EX Ts. T = Union Ts)"
proof (induct arbitrary: S0 S1 rule: subtype.induct)
qed (auto)
lemma S_TopE:
assumes a: "\<turnstile> Top <: T"
shows "T = Top \<or> (EX Ts T'. T = Union Ts \<and> T' : set Ts \<and> \<turnstile> Top <: T')"
using a by (cases, auto)
lemma S_ArrowE_left:
assumes a: "\<turnstile> S\<^isub>1 \<rightarrow> S\<^isub>2 : L <: T"
shows "T = Top \<or> (\<exists>T\<^isub>1 T\<^isub>2. T = T\<^isub>1 \<rightarrow> T\<^isub>2 : L \<and> \<turnstile> T\<^isub>1 <: S\<^isub>1 \<and> \<turnstile> S\<^isub>2 <: T\<^isub>2) \<or>
(\<exists>T\<^isub>1 T\<^isub>2. T = T\<^isub>1 \<rightarrow> T\<^isub>2 : latent_eff.NE \<and> \<turnstile> T\<^isub>1 <: S\<^isub>1 \<and> \<turnstile> S\<^isub>2 <: T\<^isub>2) \<or>
(EX Ts T1. T = Union Ts \<and> T1 : set Ts \<and> \<turnstile> S\<^isub>1 \<rightarrow> S\<^isub>2 : L <: T1)"
using a by (cases, auto simp add: ty.inject)
lemma union_size_ty:
assumes "T : set Ts"
shows "size_ty T < size_ty (Union Ts)"
using prems size_ty_pos
by (induct Ts) auto
fun size_ty3 :: "ty*ty*ty \<Rightarrow> nat"
where
size_ty3_def[simp]:"size_ty3 (a,b,c) = size_ty a + size_ty b + size_ty c"
inductive_cases union_sub_cases[consumes 1, case_names 1 2 3 4]:"\<turnstile> Union Ts <: S"
lemma union_sub_elim:
assumes A:"\<turnstile> Union Ts <: T " (is "\<turnstile> ?S <: T")
and B:" T1 : set Ts "
shows "\<turnstile> T1 <: T"
using prems
proof (induct "X"=="(T1,?S,T)" arbitrary: T1 Ts T taking: "size_ty3" rule: measure_induct_rule)
case (less X)
show " \<turnstile> T1 <: T" using `\<turnstile> Union Ts <: T` less
proof (induct rule: union_sub_cases)
case 1 thus ?case by auto
next
case 2 thus ?case by auto
next
case (3 T' Ts')
have X_inst:"X = (T1, ty.Union Ts, T)" .
have "size_ty T' < size_ty T" using 3 union_size_ty by auto
hence "\<turnstile> T1 <: T'" using X_inst 3(4)[OF _ ` \<turnstile> ty.Union Ts <: T'` `T1 : set Ts`] by auto
thus ?case using 3 by auto
next
case 4 thus ?case by auto
qed
qed
lemma S_Trans[intro]:
assumes "\<turnstile>S<:Q" and " \<turnstile>Q<:T"
shows "\<turnstile>S<:T"
using prems
proof (induct "X"=="(S,Q,T)" arbitrary: S Q T taking: "size_ty3" rule: measure_induct_rule)
case (less X S Q T)
show " \<turnstile> S <: T" using `\<turnstile> S <: Q` less
proof (induct S Q\<equiv>Q rule: subtype.induct)
case S_Refl thus ?case by auto
next
case (S_Top A)
have X_inst:"X = (A,Q,T)" .
show ?case
proof -
{
assume "EX Ts T'. T = Union Ts \<and> T' : set Ts \<and> \<turnstile> Q <: T'"
then obtain Ts T' where "T = Union Ts "" T' : set Ts "" \<turnstile> Q <: T'" by auto
hence "size_ty T' < size_ty T" using union_size_ty by auto
hence "size_ty3 (A,Q,T') < size_ty3 (A,Q,T)" by auto
hence "\<turnstile> A <: T'" using `\<turnstile> A <: Q` `\<turnstile> Q <: T'` using less(1)[of "(A,Q,T')" A Q T'] X_inst by auto
hence ?thesis using S_Top prems by auto
}
thus ?thesis using S_TopE S_Top by auto
qed
next
case (S_Fun Q1 S1 S2 Q2 L L')
hence rh_drv: " \<turnstile> Q1 \<rightarrow> Q2 : L' <: T" by simp
have X_inst:"X = (S1 \<rightarrow> S2 : L, Q1 \<rightarrow> Q2 : L', T)" using S_Fun by auto
note `Q1 \<rightarrow> Q2 : L' = Q`
hence Q12_less: "size_ty Q1 < size_ty Q" "size_ty Q2 < size_ty Q" using size_ty_pos by auto
have lh_drv_prm1: " \<turnstile> Q1 <: S1" by fact
have lh_drv_prm2: " \<turnstile> S2 <: Q2" by fact
have "T=Top \<or> (\<exists>T1 T2 LL. T=T1\<rightarrow>T2 : LL \<and> \<turnstile>T1<:Q1 \<and> \<turnstile>Q2<:T2 \<and> LL = L') \<or>
(\<exists>T1 T2. T=T1\<rightarrow>T2 : latent_eff.NE \<and> \<turnstile>T1<:Q1 \<and> \<turnstile>Q2<:T2) \<or>
(EX Ts T1. T = Union Ts \<and> T1 : set Ts \<and> \<turnstile> Q1 \<rightarrow> Q2 : L' <: T1)"
using S_ArrowE_left[OF rh_drv] by auto
moreover
{
assume "\<exists>T1 T2 LL. T=T1\<rightarrow>T2:LL \<and> \<turnstile>T1<:Q1 \<and> \<turnstile>Q2<:T2 \<and> LL = L'"
then obtain T1 T2 LL
where T_inst: "T = T1 \<rightarrow> T2 : L'"
and rh_drv_prm1: " \<turnstile> T1 <: Q1"
and rh_drv_prm2: " \<turnstile> Q2 <: T2"
and LL': "LL = L'" by auto
from X_inst T_inst have X_inst':"X = (S1 \<rightarrow> S2 : L, Q1 \<rightarrow> Q2 : L', T1 \<rightarrow> T2 : L')" by simp
hence "size_ty3 (T1, Q1, S1) < size_ty3 X" using size_ty_pos by auto
from X_inst' lh_drv_prm1 rh_drv_prm1 have " \<turnstile> T1 <: S1" using S_Fun(6)[of _ T1 Q1 S1] size_ty_pos by auto
moreover
from X_inst' lh_drv_prm2 rh_drv_prm2 have " \<turnstile> S2 <: T2" using S_Fun(6)[of _ S2 Q2 T2] size_ty_pos by auto
ultimately have " \<turnstile> S1 \<rightarrow> S2 : L <: T1 \<rightarrow> T2 : LL" using LL' S_Fun by (simp add: subtype.S_Fun)
hence " \<turnstile> S1 \<rightarrow> S2 : L <: T" using T_inst LL' by simp
}
moreover
{
assume "EX Ts T1. T = Union Ts \<and> T1 : set Ts \<and> \<turnstile> Q1 \<rightarrow> Q2 : L' <: T1"
then obtain Ts T1
where T_inst: "T = Union Ts"
and elem: "T1 : set Ts"
and sub:"\<turnstile> Q1 \<rightarrow> Q2 : L' <: T1"
by auto
have sub':"\<turnstile> S1 \<rightarrow> S2 : L <: Q1 \<rightarrow> Q2 : L'" using S_Fun by simp
have sz:"size_ty T1 < size_ty T" using T_inst elem union_size_ty by auto
from X_inst T_inst have X_inst':"X = (S1 \<rightarrow> S2 : L, Q1 \<rightarrow> Q2 : L', Union Ts)" by simp
from sub sub' X_inst'
have " \<turnstile> S1 \<rightarrow> S2 : L <: T1" using S_Fun(6)[OF _ sub' sub] sz T_inst by auto
hence " \<turnstile> S1 \<rightarrow> S2 : L <: T" using T_inst elem S_UnionAbove by auto
}
moreover
{
assume "\<exists>T1 T2. T=T1\<rightarrow>T2:latent_eff.NE \<and> \<turnstile>T1<:Q1 \<and> \<turnstile>Q2<:T2 "
then obtain T1 T2 LL
where T_inst: "T = T1 \<rightarrow> T2 : latent_eff.NE"
and rh_drv_prm1: " \<turnstile> T1 <: Q1"
and rh_drv_prm2: " \<turnstile> Q2 <: T2"
by auto
from X_inst T_inst have X_inst':"X = (S1 \<rightarrow> S2 : L, Q1 \<rightarrow> Q2 : L', T1 \<rightarrow> T2 : latent_eff.NE)" by simp
hence "size_ty3 (T1, Q1, S1) < size_ty3 X" using size_ty_pos by auto
from X_inst' lh_drv_prm1 rh_drv_prm1 have " \<turnstile> T1 <: S1" using S_Fun(6)[of _ T1 Q1 S1] size_ty_pos by auto
moreover
from X_inst' lh_drv_prm2 rh_drv_prm2 have " \<turnstile> S2 <: T2" using S_Fun(6)[of _ S2 Q2 T2] size_ty_pos by auto
ultimately have " \<turnstile> S1 \<rightarrow> S2 : L <: T1 \<rightarrow> T2 : latent_eff.NE" using S_Fun by (simp add: subtype.S_Fun)
hence " \<turnstile> S1 \<rightarrow> S2 : L <: T" using T_inst by simp
}
ultimately show " \<turnstile> S1 \<rightarrow> S2 : L <: T" by blast
next
case (S_UnionAbove T1 Ts S)
have sub1:"\<turnstile> S <: T1" .
hence sub2:"\<turnstile> T1 <: T" using S_UnionAbove union_sub_elim[of Ts T T1] by auto
have sz:"size_ty T1 < size_ty Q" using S_UnionAbove union_size_ty by auto
hence "\<turnstile> S <: T" using S_UnionAbove(4)[OF _ sub1 sub2] sz S_UnionAbove(7) by auto
thus ?case .
next
case (S_UnionBelow Ts S)
have "!! T0. T0 : set Ts \<Longrightarrow> \<turnstile> T0 <: T"
proof -
fix T0
assume "T0 : set Ts"
hence sz:"size_ty T0 < size_ty (Union Ts)" using union_size_ty by auto
have s1:"\<turnstile> T0 <: S" using S_UnionBelow `T0 : set Ts` by auto
have s2:"\<turnstile> S <: T" using S_UnionBelow by auto
note S_UnionBelow(6)
thus "\<turnstile> T0 <: T" using S_UnionBelow(3)[OF _ s1 s2] sz `S = Q` by auto
qed
thus ?case ..
qed
qed
text {* type environments *}
types varEnv = "(name*ty) list"
text {* valid contexts *}
inductive
valid :: "(name\<times>ty) list \<Rightarrow> bool"
where
v1[intro]: "valid []"
| v2[intro]: "\<lbrakk>valid \<Gamma>;a\<sharp>\<Gamma>\<rbrakk>\<Longrightarrow> valid ((a,\<sigma>)#\<Gamma>)"
equivariance valid
nominal_inductive valid done
lemma fresh_context[rule_format]:
fixes \<Gamma> :: "(name\<times>ty)list"
and a :: "name"
assumes a: "a\<sharp>\<Gamma>"
shows "\<not>(\<exists>\<tau>::ty. (a,\<tau>)\<in>set \<Gamma>)"
using a
by (induct \<Gamma>)
(auto simp add: fresh_prod fresh_list_cons fresh_atm)
lemma valid_elim:
fixes \<Gamma> :: "(name\<times>ty)list"
and pi:: "name prm"
and a :: "name"
and \<tau> :: "ty"
shows "valid ((a,\<tau>)#\<Gamma>) \<Longrightarrow> valid \<Gamma> \<and> a\<sharp>\<Gamma>"
by (ind_cases "valid ((a,\<tau>)#\<Gamma>)") simp
lemma valid_unicity[rule_format]:
assumes a: "valid \<Gamma>"
and b: "(c,\<sigma>)\<in>set \<Gamma>"
and c: "(c,\<tau>)\<in>set \<Gamma>"
shows "\<sigma>=\<tau>"
using a b c
by (induct \<Gamma>) (auto dest!: valid_elim fresh_context)
declare fresh_list_cons[simp]
declare fresh_list_nil[simp]
(* environment operations *)
consts
env_plus :: "eff \<Rightarrow> varEnv => varEnv"
env_minus :: "eff \<Rightarrow> varEnv => varEnv"
(* original type is the SECOND argument *)
constdefs
less_ty :: "((ty * ty) * ty * ty) set"
"less_ty == {((a,b),c,d) . (size_ty b) < (size_ty d)}"
function (sequential)
restrict :: "ty \<Rightarrow> ty \<Rightarrow> ty"
where
restrict_union: "restrict r (Union (ls :: ty list)) =
(if (\<turnstile> r <: Union ls) then r else (if (\<turnstile> Union ls <: r) then (Union ls) else Union (map (restrict r) ls)))"
| restrict_top:"restrict r Top = r"
| restrict_other:"restrict r T = (if (\<turnstile> r <: T) then r else T)"
by pat_completeness auto
termination using union_size_ty
by (relation "measure (% (a,b). size_ty b)") auto
lemma restrict_eqvt[eqvt]:
fixes pi::"name prm"
shows "pi\<bullet>(restrict T1 T2) = restrict (pi\<bullet>T1) (pi\<bullet>T2)"
by (induct T2) (auto)
text {* this is the key lemma in the whole soundness proof *}
fun simple_ty :: "ty \<Rightarrow> bool"
where
"simple_ty ty.Int = True"
| "simple_ty ty.TT = True"
| "simple_ty ty.FF = True"
| "simple_ty (A1 \<rightarrow> A2 : L) = True"
(* | "simple_ty (Union [ty.TT,ty.FF]) = True" *)
| "simple_ty T = False"
lemma ty_cases[consumes 0, case_names Top Int TT FF Arr Union]:
fixes P :: "ty \<Rightarrow> bool"
and T :: ty
assumes a1:"P Top"
and a2:"P ty.Int"
and a3:"P ty.TT"
and a3':"P ty.FF"
and a4:"!! t1 t2 L. P (t1 \<rightarrow> t2 : L)"
and a5:"!! Ts . P (Union Ts)"
shows "P T"
using ty_latent_eff.induct[of P "(%e . True)" "(%e . True)" T] prems
by auto
inductive_cases tt_below_union: "\<turnstile> ty.TT <: ty.Union Ts"
inductive_cases ff_below_union: "\<turnstile> ty.FF <: ty.Union Ts"
(* I believe this to be true without C, but it's easier to prove this way, and that's all we need *)
lemma restrict_soundness:
assumes A:"\<turnstile> T0 <: T"
and B:"\<turnstile> T0 <: S"
and C:"simple_ty T0"
shows "\<turnstile> T0 <: restrict S T"
using prems
proof (induct T arbitrary: S T0 taking:"size_ty" rule: measure_induct_rule)
case (less T S T0)
thus ?case
proof (induct T==T rule: ty_cases)
case Top thus ?case by auto
next
case Int thus ?case by auto
next
case TT thus ?case by auto
next
case FF thus ?case by auto
next
case Arr thus ?case by auto
next
case (Union Ts)
have r:"restrict S T = (if (\<turnstile> S <:T) then S else (if (\<turnstile> T <: S) then T else Union (map (restrict S) Ts)))"
using prems restrict_union[of S Ts] by auto
thus ?case
proof -
{
assume "\<turnstile> S <: T"
hence "restrict S T = S" using r by simp
hence ?thesis using prems by auto
}
moreover
{
assume "\<turnstile> T <: S" "~ (\<turnstile> S <: T)"
hence "restrict S T = T" using r by simp
hence ?thesis using prems by auto
}
moreover
{
assume "~ (\<turnstile> T <: S)" "~ (\<turnstile> S <: T)"
hence req:"restrict S T = Union (map (restrict S) Ts)" using r by auto
have T:"\<turnstile> T0 <: Union Ts" using prems by simp
have "?this \<Longrightarrow> ?thesis"
proof (ind_cases "\<turnstile> T0 <: Union Ts")
assume 0:"Union Ts = T0" thus ?thesis using `simple_ty T0` by (induct T0 rule: simple_ty.induct) auto
next
fix Ts'
assume "T0 = ty.Union Ts'" thus ?thesis using `simple_ty T0` by (induct T0 rule: simple_ty.induct) auto
(*
hence 1:"T0 = Union [ty.TT,ty.FF]" using `simple_ty T0` by (induct T0 rule: simple_ty.induct) auto
have "\<turnstile> ty.TT <: T0" using 1 by auto
hence "\<turnstile> ty.TT <: Union Ts" "\<turnstile> ty.TT <: T" "\<turnstile> ty.TT <: S" using T `\<turnstile> T0 <: S` `\<turnstile> T0 <: T` by auto
hence "EX \<sigma> . \<sigma> : set Ts \<and> \<turnstile> ty.TT <: \<sigma>" using tt_below_union by auto
then guess \<sigma> by auto
hence "size_ty \<sigma> < size_ty T" using prems union_size_ty by auto
note prems(4)[OF `size_ty \<sigma> < size_ty T` `\<turnstile> ty.TT <: \<sigma>` `\<turnstile> ty.TT <: S`, simplified]
hence A_tt:"\<turnstile> ty.TT <: restrict S \<sigma>" .
have mem:"restrict S \<sigma> : set (map (restrict S) Ts)" using `\<sigma> : set Ts` by auto
hence "\<turnstile> ty.TT <: Union (map (restrict S) Ts)" using A_tt S_UnionAbove by auto
hence tt_sub:"\<turnstile> ty.TT <: restrict S T" using req by auto
have "\<turnstile> ty.FF <: T0" using 1 by auto
hence "\<turnstile> ty.FF <: Union Ts" "\<turnstile> ty.FF <: T" "\<turnstile> ty.FF <: S" using T `\<turnstile> T0 <: S` `\<turnstile> T0 <: T` by auto
hence "EX \<sigma> . \<sigma> : set Ts \<and> \<turnstile> ty.FF <: \<sigma>" using ff_below_union by auto
then guess \<sigma> by auto
hence "size_ty \<sigma> < size_ty T" using prems union_size_ty by auto
note prems(4)[OF `size_ty \<sigma> < size_ty T` `\<turnstile> ty.FF <: \<sigma>` `\<turnstile> ty.FF <: S`, simplified]
hence A_ff:"\<turnstile> ty.FF <: restrict S \<sigma>" .
have mem:"restrict S \<sigma> : set (map (restrict S) Ts)" using `\<sigma> : set Ts` by auto
hence "\<turnstile> ty.FF <: Union (map (restrict S) Ts)" using A_ff S_UnionAbove by auto
hence ff_sub:"\<turnstile> ty.FF <: restrict S T" using req by auto
from ff_sub tt_sub have "\<turnstile> Union [ty.TT, ty.FF] <: restrict S T" by auto
thus ?thesis using 1 by auto
*)
next
fix T'
assume "T' : set Ts" "\<turnstile> T0 <: T'"
have 1:"\<turnstile> T0 <: restrict S T'" using union_size_ty prems by auto
have 2:"set (map (restrict S) Ts) = (restrict S) ` set Ts" by auto
have 3:"T' : set Ts" using prems by auto
have 4:"restrict S T' : set (map (restrict S) Ts)" using 2 3 by auto
hence "\<turnstile> T0 <: Union (map (restrict S) Ts)" using subtype.S_UnionAbove[OF 4 1] by auto
thus ?thesis using req by auto
qed
hence ?thesis using T by simp
}
ultimately show ?thesis by auto
qed
qed
qed
function (sequential)
remove :: "ty \<Rightarrow> ty \<Rightarrow> ty"
where
remove_union: "remove r (Union (ls :: ty list)) = (if (\<turnstile> Union ls <: r) then (Union []) else Union (map (remove r) ls))"
| remove_other:"remove r T = (if (\<turnstile> T <: r) then (Union []) else T)"
by pat_completeness auto
termination using union_size_ty
by (relation "measure (% (a,b). size_ty b)") auto
lemma remove_eqvt[eqvt]:
fixes pi::"name prm"
shows "pi\<bullet>(remove T1 T2) = remove (pi\<bullet>T1) (pi\<bullet>T2)"
by (induct T2) (auto)
lemma remove_soundness:
assumes A:"\<turnstile> T0 <: T" and B:"~ (\<turnstile> T0 <: S)" and C:"simple_ty T0"
shows "\<turnstile> T0 <: remove S T"
using prems
proof (induct T arbitrary: S T0 taking:"size_ty" rule: measure_induct_rule)
case (less T S T0)
thus ?case
proof (induct T==T rule: ty_cases)
case (Union Ts)
have r:"remove S T = (if (\<turnstile> T <:S) then (Union []) else Union (map (remove S) Ts))"
using prems remove_union[of S Ts] by auto
thus ?case
proof -
{
assume "\<turnstile> T <: S"
hence "remove S T = (Union [])" using r by simp
hence ?thesis using prems by auto
}
moreover
{
assume "~ (\<turnstile> T <: S)"
hence req:"remove S T = Union (map (remove S) Ts)" using r by auto
have T:"\<turnstile> T0 <: Union Ts" using prems by simp
have "?this \<Longrightarrow> ?thesis"
proof (ind_cases "\<turnstile> T0 <: Union Ts")
assume 0:"Union Ts = T0" thus ?thesis using `simple_ty T0` by auto
next
fix Ts'
assume "T0 = ty.Union Ts'"
thus ?thesis using `simple_ty T0` by auto
next
fix T'
assume "T' : set Ts" "\<turnstile> T0 <: T'"
have 1:"\<turnstile> T0 <: remove S T'" using union_size_ty prems by auto
have 2:"set (map (remove S) Ts) = (remove S) ` set Ts" by auto
have 3:"T' : set Ts" using prems by auto
have 4:"remove S T' : set (map (remove S) Ts)" using 2 3 by auto
hence "\<turnstile> T0 <: Union (map (remove S) Ts)" using subtype.S_UnionAbove[OF 4 1] by auto
thus ?thesis using req by auto
qed
hence ?thesis using T by simp
}
ultimately show ?thesis by auto
qed
qed (auto)
qed
lemma restrict_remove_soundness:
assumes A:"\<turnstile> T0 <: T" and B:"simple_ty T0"
shows
"(\<turnstile> T0 <: S \<and> \<turnstile> T0 <: restrict S T) \<or> (~ (\<turnstile> T0 <: S) \<and> \<turnstile> T0 <: remove S T)"
using restrict_soundness[OF A _ B] remove_soundness[OF A _ B]
by auto
fun replace :: "ty \<Rightarrow> ty \<Rightarrow> ty"
where
"replace t u = t"
fun mapfun :: "(ty \<Rightarrow> ty \<Rightarrow> ty) \<Rightarrow> ty \<Rightarrow> name \<Rightarrow> (name*ty) \<Rightarrow> (name * ty)"
where
mapfun_def: "mapfun f T x (v,S) = (if (x = v) then (v, f T S) else (v,S))"
constdefs
envop :: "(ty \<Rightarrow> ty \<Rightarrow> ty) \<Rightarrow> name \<Rightarrow> ty \<Rightarrow> (name*ty) list \<Rightarrow> (name*ty) list"
envop_def[simp]:"envop f n t G == map (% (v,ty). (if (n = v) then (v,f t ty) else (v,ty))) G"
lemma envop_mapfun:
shows "map (mapfun f T x) \<Gamma> = envop f x T \<Gamma> " using mapfun_def by auto
lemma envop_fresh:
fixes v::name
assumes a:"v \<sharp> \<Gamma>" and c:"valid \<Gamma>"
shows "v \<sharp> (envop f n t \<Gamma>)"
using c a
by (induct \<Gamma> rule: valid.induct) auto
lemma envop_valid:
assumes "valid \<Gamma>"
shows "valid (envop f n t \<Gamma>)"
using assms envop_fresh
by induct auto
lemma envop_forget:
assumes "valid \<Gamma>" and "x \<sharp> \<Gamma>"
shows "envop f x T \<Gamma> = \<Gamma>"
using prems
proof (induct rule: valid.induct)
case v1 thus ?case by auto
next
case (v2 \<Gamma>' a S)
have "x ~= a" and "x \<sharp> \<Gamma>'" using v2 fresh_list_cons fresh_atm[of x a] by auto
hence A:"envop f x T ((a,S)#\<Gamma>') = (a,S)# (envop f x T \<Gamma>')" by auto
thus ?case using v2 `x \<sharp> \<Gamma>'` by auto
qed
nominal_primrec
"env_plus (NE) G = G"
"env_plus (TE T x) G = envop restrict x T G"
"env_plus (VE x) G = envop remove x (ty.FF) G"
"env_plus (TT) G = G"
"env_plus (FF) G = G"
by auto
lemma map_eqvt[eqvt]:
fixes pi::"name prm"
and l::"('a::pt_name) list"
shows "pi\<bullet>(map f l) = map (pi\<bullet>f) (pi\<bullet>l)"
by (induct l) perm_simp+
lemma env_plus_eqvt[eqvt]:
fixes pi::"name prm"
shows "pi\<bullet>(env_plus X G ) = env_plus (pi\<bullet>X) (pi\<bullet>G)"
proof (nominal_induct X rule: eff.induct)
case (TE T x) thus ?case by (perm_simp add: eqvts split_def) auto
next
case (VE x) thus ?case by (perm_simp add: eqvts split_def) auto
qed(auto)
nominal_primrec
"env_minus (NE) G = G"
"env_minus (TE T x) G = envop remove x T G"
"env_minus (VE x) G = envop replace x ty.FF G"
"env_minus (TT) G = G"
"env_minus (FF) G = G"
by auto
lemma env_minus_eqvt[eqvt]:
fixes pi::"name prm"
shows "pi\<bullet>(env_minus X G) = env_minus (pi\<bullet>X) (pi\<bullet>G)"
proof (nominal_induct X rule: eff.induct)
case (TE T x) thus ?case
by (perm_simp add: eqvts perm_fun_def split_def) auto
case (VE x) thus ?case
by (perm_simp add: eqvts perm_fun_def split_def)
qed(auto)
abbreviation env_plus_syn :: "varEnv \<Rightarrow> eff \<Rightarrow> varEnv" ("_ |+ _" [70,70] 70)
where
"(G |+ eff) == env_plus eff G"
abbreviation env_minus_syn :: "varEnv \<Rightarrow> eff \<Rightarrow> varEnv" ("_ |- _" [70,70] 70)
where
"(G |- eff) == env_minus eff G"
--"Induction principle for type envs"
lemma env_induct[case_names Nil Cons]:
fixes \<Gamma> :: varEnv
assumes a1:"P []"
and a2:"!!G v T. P G \<Longrightarrow> P ((v,T)#G)"
shows "P \<Gamma>"
using a1 a2
by (induct \<Gamma>) auto
lemma envop_eqvt:
fixes pi::"name prm"
shows "envop f (pi\<bullet>n) T (pi\<bullet>\<Gamma>) = (pi\<bullet> (envop f n T \<Gamma>))"
proof (induct \<Gamma> rule: env_induct)
case Nil thus ?case by auto
next
case (Cons G v T0) thus ?case using pt_bij4[of pi n v] pt_name_inst at_name_inst by auto
qed
lemma env_plus_eqvt:
fixes pi::"name prm"
shows "(pi\<bullet>\<Gamma>) |+ pi\<bullet>eff = pi\<bullet>(\<Gamma> |+ eff)"
by (nominal_induct eff avoiding: \<Gamma> rule: eff.induct)
(auto simp add: eff.eqvts envop_eqvt simp del: envop_def)
lemma env_minus_eqvt:
fixes pi::"name prm"
shows "(pi\<bullet>\<Gamma>) |- pi\<bullet>eff = pi\<bullet>(\<Gamma> |- eff)"
by (nominal_induct eff avoiding: \<Gamma> rule: eff.induct)
(auto simp add: eff.eqvts envop_eqvt simp del: envop_def)
lemma env_plus_simple_eff:
assumes "simple_eff eff"
shows "\<Gamma> |+ eff = \<Gamma>"
using prems
by (induct eff rule: simple_eff_cases) auto
lemma env_minus_simple_eff:
assumes "simple_eff eff"
shows "\<Gamma> |- eff = \<Gamma>"
using prems
by (induct eff rule: simple_eff_cases) auto
fun comb_eff :: "eff \<Rightarrow> eff \<Rightarrow> eff \<Rightarrow> eff"
where
"comb_eff F1 F2 F3 = eff.NE"
lemma comb_eff_eqvt[eqvt]:
fixes pi :: "name prm"
shows "(pi\<bullet> (comb_eff F1 F2 F3)) = comb_eff (pi\<bullet>F1) (pi\<bullet>F2) (pi\<bullet>F3) "
using comb_eff.simps by auto
text {* type judgments *}
inductive
typing :: "varEnv \<Rightarrow> trm \<Rightarrow> ty \<Rightarrow> eff \<Rightarrow> bool" (" _ \<turnstile> _ : _ ; _ " [60,60,60,60] 60)
where
T_Var[intro]: "\<lbrakk>valid \<Gamma>; (v,T)\<in>set \<Gamma>\<rbrakk>\<Longrightarrow> \<Gamma> \<turnstile> Var v : T ; VE v"
| T_Const[intro]: "valid \<Gamma> \<Longrightarrow> \<Delta>\<^isub>\<tau> b = T \<Longrightarrow> \<Gamma> \<turnstile> (BI b) : T ; TT"
| T_Num[intro]: "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> (Num n) : ty.Int ; TT"
| T_True[intro]: "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> (Bool True) : ty.TT ; TT"
| T_False[intro]: "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> (Bool False) : ty.FF ; FF"
| T_Abs[intro]: "\<lbrakk>x \<sharp> \<Gamma>; ((x,T1)#\<Gamma>) \<turnstile> b : T2; eff\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Lam [x:T1].b : (T1\<rightarrow>T2 : latent_eff.NE) ; TT"
| T_App[intro]: "\<lbrakk>(\<Gamma> \<turnstile> e1 : U ; eff1) ; \<turnstile> U <: (T0 \<rightarrow> T1 : le); (\<Gamma> \<turnstile> e2 : T; eff2) ; \<turnstile> T <: T0\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> App e1 e2 : T1 ; NE"
| T_AppPred[intro]: "\<lbrakk>\<Gamma> \<turnstile> e1 : U; eff1; \<turnstile> U <: (T0 \<rightarrow> T1 : Latent S); \<Gamma> \<turnstile> e2 : T; VE x ; \<turnstile> T <: T0\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> App e1 e2 : T1 ; TE S x"
| T_If[intro]: "\<lbrakk>\<Gamma> \<turnstile> e1 : T1; eff1; (\<Gamma> |+ eff1) \<turnstile> e2 : T2; eff2; (\<Gamma> |- eff1) \<turnstile> e3 : T3; eff3; \<turnstile> T2 <: T; \<turnstile> T3 <: T\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> (Iff e1 e2 e3) : T ; comb_eff eff1 eff2 eff3"
| T_AppPredTrue[intro]:
"\<lbrakk>\<Gamma> \<turnstile> e1 : U; eff1; \<turnstile> U <: (T0 \<rightarrow> T1 : Latent S); \<Gamma> \<turnstile> e2 : T; eff2 ; \<turnstile> T <: T0; \<turnstile> T <: S\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> App e1 e2 : T1 ; TT"
| T_AppPredFalse[intro]:
"\<lbrakk>\<Gamma> \<turnstile> e1 : U; eff1; \<turnstile> U <: (T0 \<rightarrow> T1 : Latent S); \<Gamma> \<turnstile> e2 : T; eff2 ; \<turnstile> T <: T0; ~(\<turnstile> T <: S) ; e2 : values ; closed e2\<rbrakk>
\<Longrightarrow> \<Gamma> \<turnstile> App e1 e2 : T1 ; FF"
| T_IfTrue[intro]: "\<lbrakk>\<Gamma> \<turnstile> e1 : T1 ; TT ; \<Gamma> \<turnstile> e2 : T2 ; eff; \<turnstile> T2 <: T\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> (Iff e1 e2 e3) : T ; NE"
| T_IfFalse[intro]: "\<lbrakk>\<Gamma> \<turnstile> e1 : T1 ; FF ; \<Gamma> \<turnstile> e3 : T3 ; eff; \<turnstile> T3 <: T\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> (Iff e1 e2 e3) : T ; NE"
| T_AbsPred[intro]: "\<lbrakk>x \<sharp> \<Gamma>; ((x,T1)#\<Gamma>) \<turnstile> b : T2; TE S x\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Lam [x:T1].b : (T1\<rightarrow>T2 : Latent S) ; TT"
equivariance typing
nominal_inductive typing
by (auto simp add: abs_fresh)
text {* then we begin on preservation *}
abbreviation
"sub" :: "(name\<times>ty) list \<Rightarrow> (name\<times>ty) list \<Rightarrow> bool" (" _ \<lless> _ " [80,80] 80) where
"\<Gamma>1 \<lless> \<Gamma>2 \<equiv> \<forall>a \<sigma>. (a,\<sigma>)\<in>set \<Gamma>1 \<longrightarrow> (a,\<sigma>)\<in>set \<Gamma>2"
lemma envplus_empty:
shows "env_plus eff [] = []"
by (nominal_induct rule: eff.induct) auto
lemma envminus_empty:
shows "env_minus eff [] = []"
by (nominal_induct rule: eff.induct) auto
lemma w_lem1:
fixes \<Gamma> \<Gamma>'
assumes "\<Gamma> \<lless> \<Gamma>'" and a:"valid \<Gamma>'"
shows "map f \<Gamma> \<lless> map f \<Gamma>'"
proof -
let ?mapfun = f
from prems have "set \<Gamma> <= set \<Gamma>'" by auto
hence "set (map ?mapfun \<Gamma>) <= set (map ?mapfun \<Gamma>')" by auto
hence "(map ?mapfun \<Gamma>) \<lless> (map ?mapfun \<Gamma>')" by blast
thus ?thesis .
qed
lemma weakening_envplus:
assumes b:"\<Gamma> \<lless> \<Gamma>'" and a:"valid \<Gamma>'"
shows "env_plus eff \<Gamma> \<lless> env_plus eff \<Gamma>'"
using a prems w_lem1[of \<Gamma> \<Gamma>']
by (nominal_induct eff avoiding: \<Gamma> \<Gamma>' rule: eff.induct) auto
lemma weakening_envminus:
assumes "\<Gamma> \<lless> \<Gamma>'" and a:"valid \<Gamma>'" and b:"valid \<Gamma>"
shows "env_minus eff \<Gamma> \<lless> env_minus eff \<Gamma>'"
using a prems w_lem1[of \<Gamma> \<Gamma>']
by (nominal_induct eff avoiding: \<Gamma> \<Gamma>' rule: eff.induct) auto
lemma envplus_valid:
assumes "valid \<Gamma>"
shows "valid (\<Gamma> |+ F)"
using prems
proof (induct rule: valid.induct)
case v1 thus ?case using envplus_empty by auto
next
case (v2 \<Gamma>' a T)
from v2 show ?case
proof (nominal_induct rule: eff.induct)
case (TE S x)
let ?op = "restrict"
let ?G = "((a, T) # \<Gamma>')"
let ?mapfun = "(% (v,ty). (if (x = v) then (v,?op S ty) else (v,ty)))"
have C:"valid (map ?mapfun \<Gamma>')" using v2 `valid (\<Gamma>' |+ TE S x)` by auto
hence D:"a \<sharp> (map ?mapfun \<Gamma>')" using v2 envop_fresh `valid (\<Gamma>' |+ TE S x)` by auto
thus ?case
proof (cases "a = x")
case False
from D have E:"valid ((a,T)# (map ?mapfun \<Gamma>'))" using C by auto
from False have B:"?G |+ TE S x = ((a,T)# (map ?mapfun \<Gamma>'))" by auto
thus ?thesis using E by auto
next
case True
hence B:"?G |+ TE S x = ((a,?op S T)# (map ?mapfun \<Gamma>'))" by auto
from D have E:"valid ((a,?op S T)# (map ?mapfun \<Gamma>'))" using C by auto
thus ?thesis using B by auto
qed
next
case (VE x)
thus ?case
proof -
let ?op = "remove"
let ?G = "((a, T) # \<Gamma>')"
let ?mapfun = "(% (v,ty). (if (x = v) then (v,?op ty.FF ty) else (v,ty)))"
have C:"valid (map ?mapfun \<Gamma>')" using v2 `valid (\<Gamma>' |+ VE x)` by auto
hence D:"a \<sharp> (map ?mapfun \<Gamma>')" using v2 envop_fresh `valid (\<Gamma>' |+ VE x)` by auto
thus ?case
proof (cases "a = x")
case False
from D have E:"valid ((a,T)# (map ?mapfun \<Gamma>'))" using C by auto
from False have B:"?G |+ VE x = ((a,T)# (map ?mapfun \<Gamma>'))" by auto
thus ?thesis using E by auto
next
case True
hence B:"?G |+ VE x = ((a,?op ty.FF T)# (map ?mapfun \<Gamma>'))" by auto
from D have E:"valid ((a,?op ty.FF T)# (map ?mapfun \<Gamma>'))" using C by auto
thus ?thesis using B by auto
qed
qed
qed (auto)
qed
lemma envminus_valid:
assumes "valid \<Gamma>"
shows "valid (\<Gamma> |- F)"
using prems
proof (induct rule: valid.induct)
case v1 thus ?case using envminus_empty by auto
next
case (v2 \<Gamma>' a T) thus ?case
proof (nominal_induct rule: eff.induct)
case (TE S x)
let ?op = "remove"
let ?G = "((a, T) # \<Gamma>')"
let ?mapfun = "(% (v,ty). (if (x = v) then (v,?op S ty) else (v,ty)))"
have C:"valid (map ?mapfun \<Gamma>')" using v2 `valid (\<Gamma>' |- TE S x)` by auto
hence D:"a \<sharp> (map ?mapfun \<Gamma>')" using v2 envop_fresh `valid (\<Gamma>' |- TE S x)` by auto
thus ?case
proof (cases "a = x")
case False
from D have E:"valid ((a,T)# (map ?mapfun \<Gamma>'))" using C by auto
from False have B:"?G |- TE S x = ((a,T)# (map ?mapfun \<Gamma>'))" by auto
thus ?thesis using E by auto
next
case True
hence B:"?G |- TE S x = ((a,?op S T)# (map ?mapfun \<Gamma>'))" by auto
from D have E:"valid ((a,?op S T)# (map ?mapfun \<Gamma>'))" using C by auto
thus ?thesis using B by auto
qed
next
case (VE x)
thus ?case
proof -
let ?op = "replace"
let ?G = "((a, T) # \<Gamma>')"
let ?mapfun = "(% (v,ty). (if (x = v) then (v,?op ty.FF ty) else (v,ty)))"
have C:"valid (map ?mapfun \<Gamma>')" using v2 `valid (\<Gamma>' |- VE x)` by auto
hence D:"a \<sharp> (map ?mapfun \<Gamma>')" using v2 envop_fresh `valid (\<Gamma>' |- VE x)` by auto
thus ?case
proof (cases "a = x")
case False
from D have E:"valid ((a,T)# (map ?mapfun \<Gamma>'))" using C by auto
from False have B:"?G |- VE x = ((a,T)# (map ?mapfun \<Gamma>'))" by auto
thus ?thesis using E by auto
next
case True
hence B:"?G |- VE x = ((a,?op ty.FF T)# (map ?mapfun \<Gamma>'))" by auto
from D have E:"valid ((a,?op ty.FF T)# (map ?mapfun \<Gamma>'))" using C by auto
thus ?thesis using B by auto
qed
qed
qed (auto)
qed
lemma weakening:
assumes a: "\<Gamma>1 \<turnstile> t : \<sigma> ; F"
and b: "valid \<Gamma>2"
and c: "\<Gamma>1 \<lless> \<Gamma>2"
and d:"valid \<Gamma>1"
shows "\<Gamma>2 \<turnstile> t:\<sigma> ; F"
using a b c d
proof (nominal_induct \<Gamma>1 t \<sigma> F avoiding: \<Gamma>2 rule: typing.strong_induct)
case (T_If \<Gamma> t1 T1 F1 t2 T2 F2 t3 T3 F3 T \<Gamma>2)
have A:"valid (\<Gamma> |+ F1)" using T_If envplus_valid by auto
have B:"valid (\<Gamma> |- F1)" using T_If envminus_valid by auto
have A':"valid (\<Gamma>2 |+ F1)" using T_If envplus_valid by auto
have B':"valid (\<Gamma>2 |- F1)" using T_If envminus_valid by auto
have C:"(\<Gamma> |+ F1) \<lless> (\<Gamma>2 |+ F1)" using T_If weakening_envplus by auto
have D:"(\<Gamma> |- F1) \<lless> (\<Gamma>2 |- F1)" using T_If weakening_envminus by auto
show ?case using T_If A B C D A' B' by blast
qed (auto | atomize)+
(* FIXME: before using meta-connectives and the new induction *)
(* method, this was completely automatic *)
(* need weakening lemmas about env+/- *)
lemma "[] \<turnstile> (Lam[x:Top]. (Iff (App (BI NumberP) (Var x)) (App (BI Add1) (Var x)) (Num 12))) : (Top \<rightarrow> ty.Int : latent_eff.NE) ; TT"
apply (rule T_Abs)
apply (auto simp add: fresh_def supp_def perm_fun_def)
apply (rule T_If)
apply auto
apply (rule T_AppPred)
apply (auto simp add: valid.intros)
apply (rule T_App)
apply (rule T_Const)
defer
apply ( simp add: valid.intros)
apply (rule S_Refl)
apply (rule T_Var)
apply (simp add: valid.intros)+
apply (rule S_Refl)
apply (simp add: valid.intros)+
done
(* inductive cases about typing *)
inductive_cases iff_t_cases : "G \<turnstile> Iff tst thn els : t ; e"
inductive_cases app_bi_cases : "G \<turnstile> App (Const (BI b)) rand : t ; e"
inductive_cases type_arr_case_num: "\<Gamma> \<turnstile> ((Num n)) : (T1 \<rightarrow> T2 : eff) ; eff'"
inductive_cases type_arr_case_bool: "\<Gamma> \<turnstile> ((Bool b)) : (T1 \<rightarrow> T2 : eff) ; eff'"
inductive_cases type_bi_case: "\<Gamma> \<turnstile> ((BI b)) : t ; eff"
inductive_cases type_add1_case: "\<Gamma> \<turnstile> ((BI Add1)) : t ; eff"
inductive_cases bi_typing_cases: "\<Gamma> \<turnstile> (BI b) : t ; eff"
inductive_cases abs_ty_int: "\<Gamma> \<turnstile> (Abs x body t) : ty.Int ; eff'"
inductive_cases abs_ty_bool: "\<Gamma> \<turnstile> (Abs x body t) : BoolTy ; eff'"
inductive_cases const_ty_int: "\<Gamma> \<turnstile> e : ty.Int ; eff'"
inductive_cases const_ty_bool: "\<Gamma> \<turnstile> e : BoolTy ; eff'"
inductive_cases iff_false_ty: "\<Gamma> \<turnstile> Iff (Bool False) thn els : t ; eff"
inductive_cases app_bi_ty: "\<Gamma> \<turnstile> App (BI b) arg : t ; eff"
(* Typing Values*)
lemma false_ty_elim[rule_format]:
"\<Gamma> \<turnstile> (trm.Bool False) : \<sigma> ; eff \<Longrightarrow> \<sigma> = ty.FF \<and> eff = FF \<and> valid \<Gamma>"
apply (ind_cases "\<Gamma> \<turnstile> (trm.Bool False) : \<sigma> ; eff")
apply (auto simp add: trm.inject)
done
lemma num_ty_elim[rule_format]:
"\<Gamma> \<turnstile> (Num n) : \<sigma> ; eff \<Longrightarrow> \<sigma> = ty.Int \<and> eff = TT \<and> valid \<Gamma>"
by (ind_cases "\<Gamma> \<turnstile> (Num n) : \<sigma> ; eff") auto
lemma true_ty_elim[rule_format]:
"\<Gamma> \<turnstile> (trm.Bool True) : \<sigma> ; eff \<Longrightarrow> \<sigma> = ty.TT \<and> eff = TT \<and> valid \<Gamma> "
by (ind_cases "\<Gamma> \<turnstile> (trm.Bool True) : \<sigma> ; eff")
(auto simp add: trm.inject)
lemma bool_ty_elim[rule_format]:
"\<Gamma> \<turnstile> (trm.Bool b) : \<sigma> ; eff \<Longrightarrow> (\<sigma> = ty.TT \<or> \<sigma> = ty.FF) \<and> valid \<Gamma> "
apply (ind_cases "\<Gamma> \<turnstile> (trm.Bool b) : \<sigma> ; eff")
apply (auto simp add: trm.inject)
done
lemma bi_ty_elim[rule_format]:
"\<Gamma> \<turnstile> (BI b) : \<sigma> ; eff \<Longrightarrow> eff = TT \<and> \<sigma> = \<Delta>\<^isub>\<tau> b \<and> valid \<Gamma>"
apply (ind_cases "\<Gamma> \<turnstile> (BI b) : \<sigma> ; eff")
apply (auto simp add: trm.inject)
done
inductive_cases bool_sub_int: "\<turnstile> BoolTy <: ty.Int"
inductive_cases tt_sub_int: "\<turnstile> ty.TT <: ty.Int"
inductive_cases ff_sub_int: "\<turnstile> ty.FF <: ty.Int"
thm bool_sub_int
inductive_cases arr_sub_int: "\<turnstile> A\<rightarrow>B:L <: ty.Int"
inductive_cases int_sub_tt: "\<turnstile> ty.Int <: ty.TT"
inductive_cases int_sub_ff: "\<turnstile> ty.Int <: ty.FF"
inductive_cases arr_sub_tt: "\<turnstile> A\<rightarrow>B:L <: ty.TT"
inductive_cases arr_sub_ff: "\<turnstile> A\<rightarrow>B:L <: ty.FF"
inductive_cases int_sub_bool_cases: "\<turnstile> ty.Int <: Union [ty.TT, ty.FF]"
inductive_cases arr_sub_bool_cases: "\<turnstile> A\<rightarrow>B:L <: Union [ty.TT, ty.FF]"
declare BoolTy_def[simp]
lemma int_sub_bool:
assumes "\<turnstile> ty.Int <: BoolTy"
shows "P"
using prems
proof -
have "\<turnstile> ty.Int <: ty.TT \<or> \<turnstile> ty.Int <: ty.FF" using prems int_sub_bool_cases by auto
thus ?thesis using int_sub_ff int_sub_tt by auto
qed
lemma arr_sub_bool:
assumes "\<turnstile> A\<rightarrow>B:L <: BoolTy"
shows "P"
using prems
proof -
have "\<turnstile> A\<rightarrow>B:L <: ty.TT \<or> \<turnstile> A\<rightarrow>B:L <: ty.FF" using prems arr_sub_bool_cases[of A B L] by auto
thus ?thesis using arr_sub_ff[of A B L] arr_sub_tt[of A B L] by auto
qed
thm int_sub_bool
inductive_cases abs_ty_elim2[consumes 1, case_names 1]: "\<Gamma> \<turnstile> Lam[x:S].b : T ; eff"
lemma int_value:
assumes a:"v : values"
and b:"\<Gamma> \<turnstile> v : T ; F"
and c:"\<turnstile> T <: ty.Int"
shows "EX n. v = (Num n)"
using prems
proof (induct rule: values.induct)
case num_value thus ?case by auto
next
case (bool_value b)
hence "T = ty.TT \<or> T = ty.FF" using bool_ty_elim by auto
thus ?case using bool_value tt_sub_int ff_sub_int by auto
next
case (abs_value b S x)
thus ?case using arr_sub_int
by (induct rule: abs_ty_elim2) auto
next
case (bi_value b)
thus ?case using bi_ty_elim[of \<Gamma> b T F] using arr_sub_int by (nominal_induct b rule: builtin.induct) auto
qed
lemma bool_value:
assumes a:"v : values"
and b:"\<Gamma> \<turnstile> v : T ; F"
and c:"\<turnstile> T <: BoolTy"
shows "EX b. v = (Bool b)"
using prems
proof (induct rule: values.induct)
case num_value thus ?case using num_ty_elim[of \<Gamma> _ T F] int_sub_bool by auto
next
case (bool_value b) thus ?case by auto
next
case (abs_value b S x)
thus ?case using arr_sub_bool
by (induct rule: abs_ty_elim2) auto
next
case (bi_value b)
thus ?case using bi_ty_elim[of \<Gamma> b T F] using arr_sub_bool by (nominal_induct b rule: builtin.induct) auto
qed
lemma value_int_ty:
assumes a:"\<Gamma> \<turnstile> e : ty.Int ; eff"
and b: "e : values"
shows "EX n. e = (Num n)"
using b a int_value[of e _ ty.Int] by auto
lemma value_bool_ty:
assumes a:"\<Gamma> \<turnstile> e : BoolTy ; eff"
and b: "e : values"
shows "EX b. e = (Bool b)"
using b a bool_value[OF b a] by auto
lemma typing_bi:
assumes a:"\<Gamma> \<turnstile> (BI b) : t ; eff"
shows "t = \<Delta>\<^isub>\<tau> b"
using a bi_typing_cases[of \<Gamma> b t eff "t = \<Delta>\<^isub>\<tau> b"]
by (simp add: trm.inject)
inductive_cases arr_sub_arr_cases:"\<turnstile> A1 \<rightarrow> A2 : L <: B1 \<rightarrow> B2 : L'"
lemma typed_prim_reduce:
assumes a:"\<Gamma> \<turnstile> (BI b) : U ; eff" and b:"\<Gamma> \<turnstile> v : T ; eff'" and c:"v : values"
and sub:"\<turnstile> T <: T0" and d: "\<turnstile> U <: T0 \<rightarrow> T1 : le"
shows "EX v'. \<Delta> b v = Some v'"
using a b c d sub
proof (nominal_induct b rule: builtin.induct)
case Add1
have "U = \<Delta>\<^isub>\<tau> Add1" using Add1 typing_bi[of \<Gamma> Add1 "U" eff] by simp
hence "U = ty.Int \<rightarrow> ty.Int : latent_eff.NE" by auto
hence "\<turnstile> T <: ty.Int " and "le = latent_eff.NE" using sub d arr_sub_arr_cases[of ty.Int ty.Int latent_eff.NE T0 T1 le]
by auto
hence "EX n. v = (Num n)" using c b int_value by auto
then obtain n where "v = (Num n)" by auto
thus ?case by (auto simp add: \<Delta>.simps)
next
case Nott show ?case using `v : values` Nott
by (induct v rule: values.induct) auto
next
case NumberP thus ?case by auto
next
case BooleanP thus ?case by auto
next
case ProcP thus ?case by auto
qed
text {* Progress together with necessary lemmas *}
(* first some lemmas about decomposing various kinds of syntax *)
lemma if_decomp:
assumes b:"closed tst \<Longrightarrow> (\<exists>E L R. tst = E L \<and> E \<in> ctxt \<and> L \<hookrightarrow> R) \<or> tst : values"
and c:"closed (Iff tst thn els)"
shows "(EX E L R. (Iff tst thn els) = E L \<and> E : ctxt \<and> L \<hookrightarrow> R) \<or> (Iff tst thn els) : values"
proof -
{
assume "tst : values"
hence "EX E L R. Iff tst thn els = E L \<and> E : ctxt \<and> (L \<hookrightarrow> R)"
using if_val_reduces[of tst thn els] ex_help[of "Iff tst thn els" "(%t. t)"] by auto
}
moreover
{
assume asm:"~ tst : values"
have cl:"closed tst" using `closed (Iff tst thn els)` by (auto simp add: closed_def trm.supp)
hence ih:"\<exists>E t t'. tst = E t \<and> E \<in> ctxt \<and> t \<hookrightarrow> t'" using b asm by auto
hence "\<exists>E t t' . Iff tst thn els = E t \<and> E \<in> ctxt \<and> t \<hookrightarrow> t'"
using reduce_in_ctxt[of "(%t . (Iff t thn els))"] ih by auto
}
ultimately show ?thesis by auto
qed
inductive_cases tt_sub_arr_cases: "\<turnstile> ty.TT <:A1 \<rightarrow> A2 : L"
inductive_cases ff_sub_arr_cases: "\<turnstile> ty.FF <:A1 \<rightarrow> A2 : L"
inductive_cases num_sub_arr_cases: "\<turnstile> ty.Int <:A1 \<rightarrow> A2 : L"
lemma app_decomp:
assumes a:" G \<turnstile> rator : U ; eff1"
and a':"\<turnstile> U <: T0 \<rightarrow> T1 : le"
and aa:" G \<turnstile> rand : T ; eff"
and b:"closed rator \<Longrightarrow> (\<exists>E L R. rator = E L \<and> E \<in> ctxt \<and> L \<hookrightarrow> R) \<or> rator \<in> values"
and bb:"closed rand \<Longrightarrow> (\<exists>E L R. rand = E L \<and> E \<in> ctxt \<and> L \<hookrightarrow> R) \<or> rand \<in> values"
and c:"closed (App rator rand)"
and sub:"\<turnstile> T <: T0"
shows "(EX E L R. (App rator rand) = E L \<and> E : ctxt \<and> L \<hookrightarrow> R) \<or> (App rator rand) : values"
proof -
have well_typed:"G \<turnstile> (App rator rand) : T1 ; eff.NE"
using T_App[of G rator U eff1 T0 T1 le rand T eff] a a' aa sub by auto
have "closed rator" using c by (auto simp add: closed_def trm.supp)
hence ih1:"(\<exists>E L R. rator = E L \<and> E \<in> ctxt \<and> L \<hookrightarrow> R) \<or> rator \<in> values" using b by simp
have "closed rand" using c by (auto simp add: closed_def trm.supp)
hence ih2:"(\<exists>E L R. rand = E L \<and> E \<in> ctxt \<and> L \<hookrightarrow> R) \<or> rand \<in> values" using bb by simp
{
assume asm1:"rator \<in> values" and asm2:"rand \<in> values"
hence "(EX E L R. (App rator rand) = E L \<and> E : ctxt \<and> L \<hookrightarrow> R)" using asm1 a aa a' sub well_typed
proof (nominal_induct avoiding: rand rule: values.strong_induct )
case (abs_value x t b)
let ?E = "(%t. t)"
let ?L = "App (Abs x b t) rand"
have "?L \<hookrightarrow> (b[x::=rand])" by (rule e_beta)
thus ?case using ex_help[of ?L ?E ?L] by auto
next
case (bool_value b)
hence "U = ty.TT \<or> U = ty.FF" using true_ty_elim false_ty_elim by (cases b) auto
thus ?case using tt_sub_arr_cases[of T0 T1 le] ff_sub_arr_cases[of T0 T1 le] `\<turnstile> U <: T0 \<rightarrow> T1 : le` by blast
next
case (num_value b)
hence "U = ty.Int" using num_ty_elim by auto
thus ?case using num_sub_arr_cases[of T0 T1 le] num_value by auto
next
case (bi_value b)
let ?E = "(%t. t)"
let ?L = "App ((BI b)) rand"
have h:"\<And>v. (\<Delta> b rand) = (Some v) \<Longrightarrow> App ((BI b)) rand \<hookrightarrow> v" using bi_value by auto
have "EX v . (\<Delta> b rand) = (Some v)" using bi_value typed_prim_reduce[of G b U] by auto
then obtain v' where "(\<Delta> b rand) = (Some v')" by auto
then show ?case using h[of v'] ex_help[of ?L ?E] by auto
qed
}
moreover
{
assume asm1:"rator \<in> values" and asm2:"rand \<notin> values"
have "\<exists>E t t' . App rator rand = E t \<and> E \<in> ctxt \<and> t \<hookrightarrow> t'"
using asm1 asm2 reduce_in_ctxt[of "(%t . (App rator t))"] ih2 by auto
}
moreover
{
assume asm:"rator \<notin> values"
have "\<exists>E t t' . App rator rand = E t \<and> E \<in> ctxt \<and> t \<hookrightarrow> t'"
using asm reduce_in_ctxt[of "(%t . (App t rand))"] ih1 by auto
}
ultimately show ?thesis by auto
qed
(* then the main lemma, that every well typed term can be decomposed
into a context and a redex *)
lemma decomposition:
assumes a:"closed e" and b:"\<Gamma> \<turnstile> e : t ; eff"
shows "(EX E L R. e = E L \<and> E : ctxt \<and> L \<hookrightarrow> R) \<or> e : values"
using b a
proof (induct rule: typing.induct)
case T_Var
thus ?case using closed_def by (auto simp add: at_supp at_name_inst trm.supp)
next
case T_If
thus ?case using if_decomp by auto
next
case T_IfTrue
thus ?case using if_decomp by auto
next
case T_IfFalse
thus ?case using if_decomp by auto
next
case T_App
thus ?case using app_decomp by auto
next
case T_AppPred
thus ?case using app_decomp by auto
next
case T_AppPredTrue
thus ?case using app_decomp by auto
next
case T_AppPredFalse
thus ?case using app_decomp by auto
qed (simp_all) (* The value cases are automatic *)
(* Now we conclude progress *)
theorem progress:
assumes typed:"\<Gamma> \<turnstile> e : t ; eff" and cl:"closed e"
shows "e : values \<or> (EX e'. e \<longrightarrow> e')"
proof (cases "e : values")
case False
hence "(\<exists>E L R. e = E L \<and> E \<in> ctxt \<and> L \<hookrightarrow> R)" using decomposition[OF cl typed] by auto
thus ?thesis by auto
qed (simp)
(* Some useful lemmas for deriving facts from typing derivations *)
inductive_cases app_ty_elim2[consumes 1, case_names 1 2 3 4]: "\<Gamma> \<turnstile> App t1 t2 : \<sigma> ; eff"
thm app_ty_elim2
inductive_cases iff_ty_elim2[consumes 1, case_names 1 2 3]: "\<Gamma> \<turnstile> Iff t1 t2 t3 : T ; eff"
thm abs_ty_elim2
(* slow *)
lemma app_ty_elim[rule_format]:
"\<Gamma> \<turnstile> App t1 t2 : \<sigma> ; eff \<Longrightarrow>
\<exists> T0 T0' T1 le eff' eff'' U. (\<Gamma> \<turnstile> t1 : U ; eff' \<and> \<Gamma> \<turnstile> t2 : T0' ; eff'' \<and> \<turnstile> U <: T0 \<rightarrow> T1 : le \<and> \<turnstile> T0' <: T0 \<and> T1 = \<sigma>)"
apply (ind_cases "\<Gamma> \<turnstile> App t1 t2 : \<sigma> ; eff")
apply (auto simp add: trm.inject ty.inject)
by metis+
lemma abs_ty_elim_eff[rule_format]:
"\<lbrakk>\<Gamma> \<turnstile> Lam[a:T0].b : \<sigma> ; eff\<rbrakk> \<Longrightarrow> eff = eff.TT"
by (ind_cases "\<Gamma> \<turnstile> Lam[a:T0].b : \<sigma> ; eff")
(auto simp add: trm.inject)
lemma abs_ty_elim[rule_format]:
"\<lbrakk>\<Gamma> \<turnstile> Lam[a:T0].b : \<sigma> ; eff ; a \<sharp> \<Gamma>\<rbrakk> \<Longrightarrow>
\<exists> T1 eff' L S. ((a,T0)#\<Gamma> \<turnstile> b : T1 ; eff' \<and> \<sigma> = (T0 \<rightarrow> T1 : L) \<and> eff = eff.TT \<and> ((eff' = TE S a \<and> L = Latent S) \<or> L = latent_eff.NE))"
apply (ind_cases "\<Gamma> \<turnstile> Lam[a:T0].b: \<sigma> ; eff")
apply(auto simp add: trm.distinct trm.inject alpha)
apply(drule_tac pi="[(a,x)]::name prm" in typing.eqvt)
apply(auto)
apply(subgoal_tac "([(a,x)]::name prm)\<bullet>\<Gamma> = \<Gamma>")(*A*)
apply(force simp add: calc_atm)
(*A*)
apply(force intro!: pt_fresh_fresh[OF pt_name_inst, OF at_name_inst])
apply(drule_tac pi="[(a,x)]::name prm" in typing.eqvt)
apply(auto)
apply(subgoal_tac "([(a,x)]::name prm)\<bullet>\<Gamma> = \<Gamma>")(*A*)
apply(force simp add: calc_atm)
(*A*)
apply(force intro!: pt_fresh_fresh[OF pt_name_inst, OF at_name_inst])
done
inductive_cases abs_ty_cases[consumes 1, case_names 1 2]:"\<Gamma> \<turnstile> Lam[a:T0].b: \<sigma> ; eff"
thm abs_ty_cases
(*
lemma app_abs_ty_elim_eff[rule_format]:
"\<lbrakk>\<Gamma> \<turnstile> App (Abs x b T) t2 : \<sigma> ; eff ; x \<sharp> \<Gamma>\<rbrakk> \<Longrightarrow> eff = eff.NE"
proof (ind_cases "\<Gamma> \<turnstile> App (Abs x b T) t2 : \<sigma> ; eff", auto simp add: trm.inject abs_ty_elim)
fix T0 S eff1 U
assume "\<Gamma> \<turnstile> Lam [x:T].b : U ; eff1 "" \<turnstile> U <: T0 \<rightarrow> \<sigma> : Latent S" "x \<sharp> \<Gamma>"
then obtain T1 L where "U = T \<rightarrow> T1 : L" using abs_ty_elim[of \<Gamma> x b T "U" L] by auto
thus False using prems arr_sub_arr_cases[of T _ latent_eff.NE T0 \<sigma> "Latent S"] by (auto simp add: ty.inject)
next
fix T0 S eff1 U
assume "\<Gamma> \<turnstile> Lam [x:T].b : U ; eff1 "" \<turnstile> U <: T0 \<rightarrow> \<sigma> : Latent S" "x \<sharp> \<Gamma>"
then obtain T1 where "U = T \<rightarrow> T1 : latent_eff.NE" using abs_ty_elim[of \<Gamma> x b T "U"] by auto
thus False using prems arr_sub_arr_cases[of T _ latent_eff.NE T0 \<sigma> "Latent S"] by (auto simp add: ty.inject)
next
fix T0 S eff1 U
assume "\<Gamma> \<turnstile> Lam [x:T].b : U ; eff1 "" \<turnstile> U <: T0 \<rightarrow> \<sigma> : Latent S" "x \<sharp> \<Gamma>"
then obtain T1 where "U = T \<rightarrow> T1 : latent_eff.NE" using abs_ty_elim[of \<Gamma> x b T "U"] by auto
thus False using prems arr_sub_arr_cases[of T _ latent_eff.NE T0 \<sigma> "Latent S"] by (auto simp add: ty.inject)
qed
*)
lemma if_ty_elim_weak[rule_format]:
"\<Gamma> \<turnstile> Iff t1 t2 t3: \<sigma> ; eff \<Longrightarrow> \<exists> T0 eff'. (\<Gamma> \<turnstile> t1 : T0 ; eff') \<and> eff = NE"
by (ind_cases "\<Gamma> \<turnstile> Iff t1 t2 t3: \<sigma> ; eff")
(auto simp add: trm.inject)
lemma if_ty_elim[rule_format]:
"\<Gamma> \<turnstile> Iff t1 t2 t3: \<sigma> ; eff \<Longrightarrow>
(\<exists> T1 T2 T3 F1 F2 F3. (\<Gamma> \<turnstile> t1 : T1 ; F1) \<and> \<Gamma> |+ F1 \<turnstile> t2 : T2 ; F2 \<and> \<Gamma> |- F1 \<turnstile> t3 : T3 ; F3 \<and> \<turnstile> T2 <: \<sigma> \<and> \<turnstile> T3 <: \<sigma> \<and> eff = NE)
\<or>
(\<exists> T1 T3 F3. (\<Gamma> \<turnstile> t1 : T1 ; FF) \<and> \<Gamma> \<turnstile> t3 : T3 ; F3 \<and> \<turnstile> T3 <: \<sigma> \<and> eff = NE)
\<or>
(\<exists> T1 T2 F2. (\<Gamma> \<turnstile> t1 : T1 ; TT) \<and> \<Gamma> \<turnstile> t2 : T2 ; F2 \<and> \<turnstile> T2 <: \<sigma> \<and> eff = NE)"
proof (ind_cases "\<Gamma> \<turnstile> Iff t1 t2 t3: \<sigma> ; eff")
fix e1 T1 eff1 e2 T2 eff2 e3 T3 eff3
assume "Iff t1 t2 t3 = Iff e1 e2 e3"" eff = eff.NE"" \<Gamma> \<turnstile> e1 : T1 ; eff1"" env_plus eff1 \<Gamma> \<turnstile> e2 : T2 ; eff2 "
"env_minus eff1 \<Gamma> \<turnstile> e3 : T3 ; eff3"" \<turnstile> T2 <: \<sigma>"" \<turnstile> T3 <: \<sigma>"
hence A:"t1 = e1" "t2 = e2" "t3 = e3" using trm.inject by auto
thus ?thesis using prems by blast
next
fix e1 T1 e2 T2 effa e3
assume "Iff t1 t2 t3 = Iff e1 e2 e3"" eff = eff.NE"" \<Gamma> \<turnstile> e1 : T1 ; TT "" \<Gamma> \<turnstile> e2 : T2 ; effa "" \<turnstile> T2 <: \<sigma>"
thus ?thesis by (auto simp add: trm.inject)
next
fix e1 T1 e2 T3 effa e3
assume "Iff t1 t2 t3 = Iff e1 e2 e3"" eff = eff.NE"" \<Gamma> \<turnstile> e1 : T1 ; FF "" \<Gamma> \<turnstile> e3 : T3 ; effa "" \<turnstile> T3 <: \<sigma>"
thus ?thesis by (auto simp add: trm.inject)
qed
inductive_cases iff_false_ty_cases: "\<Gamma> \<turnstile> Iff (trm.Bool False) t2 t3: \<sigma> ; eff"
inductive_cases ff_eff_cases: "\<Gamma> \<turnstile> e : T; FF"
inductive_cases tt_eff_cases: "\<Gamma> \<turnstile> e : T; TT"
inductive_cases ne_eff_cases: "\<Gamma> \<turnstile> e : T; NE"
lemma if_true_ty_elim[rule_format]:
"\<lbrakk>\<Gamma> \<turnstile> Iff v t2 t3: \<sigma> ; eff ; v : values; v ~= Bool False\<rbrakk> \<Longrightarrow>
\<exists> T0 eff'. ((\<Gamma> \<turnstile> t2 : T0 ; eff') \<and> \<turnstile> T0 <: \<sigma> \<and> eff = NE)"
proof (ind_cases "\<Gamma> \<turnstile> Iff (v) t2 t3: \<sigma> ; eff")
fix eff1 eff2 T1 T2 e1 e2 e3
assume "v : values" "env_plus eff1 \<Gamma> \<turnstile> e2 : T2 ; eff2" "Iff v t2 t3 = Iff e1 e2 e3" "\<turnstile> T2 <: \<sigma>"
"\<Gamma> \<turnstile> e1 : T1 ; eff1" "eff = NE"
have "\<Gamma> \<turnstile> v : T1 ; eff1" using prems by (simp add: trm.inject)
have "eff1 = eff.NE \<or> eff1 = FF \<or> eff1 = TT" using `v : values` `\<Gamma> \<turnstile> v : T1 ; eff1`
proof (induct rule: values.induct)
case (abs_value b T x) thus ?case using abs_value abs_ty_elim_eff by auto
next
case (num_value n) thus ?case using num_ty_elim by auto
next
case (bool_value n) thus ?case using false_ty_elim true_ty_elim by (cases n) auto
next
case bi_value thus ?case using bi_ty_elim by auto
qed
hence "env_plus eff1 \<Gamma> = \<Gamma>" by auto
hence "\<Gamma> \<turnstile> e2 : T2 ; eff2 \<and> \<turnstile> T2 <: \<sigma>" using prems by auto
thus ?thesis using prems by (auto simp add: trm.inject)
next
fix e1 T2 e2 e3 effa
assume "Iff v t2 t3 = Iff e1 e2 e3" "\<Gamma> \<turnstile> e2 : T2 ; effa" "\<turnstile> T2 <: \<sigma>" "eff = NE"
thus ?thesis by (auto simp add: trm.inject)
next
fix e1 T1 e3 T3 effa e2
assume "v : values" "v \<noteq> trm.Bool False" "Iff v t2 t3 = Iff e1 e2 e3" "\<Gamma> \<turnstile> e1 : T1 ; FF" "eff = NE"
have "v = e1" using prems trm.inject by auto
hence tv:"\<Gamma> \<turnstile> v : T1 ; FF" by simp
have "v = Bool False" using `v : values` tv
proof (induct v rule: values.induct)
case (abs_value x T b) thus ?case using abs_ty_elim_eff[of \<Gamma> x b T T1 FF] by auto
next
case (num_value n) thus ?case using num_ty_elim[of _ _ _ FF] by auto
next
case (bool_value n) thus ?case using true_ty_elim[of _ _ FF] by (cases n) auto
next
case bi_value thus ?case using bi_ty_elim[of _ _ _ FF] by auto
qed
show ?thesis using `v = Bool False` `v ~= Bool False` by auto
qed
lemma if_false_ty_elim[rule_format]:
"\<Gamma> \<turnstile> Iff (trm.Bool False) t2 t3: \<sigma> ; eff \<Longrightarrow>
\<exists> T0 eff'. ((\<Gamma> \<turnstile> t3 : T0 ; eff') \<and> \<turnstile> T0 <: \<sigma> \<and> eff = eff.NE)"
proof (ind_cases "\<Gamma> \<turnstile> Iff (trm.Bool False) t2 t3: \<sigma> ; eff")
fix e1 e2 e3 T1
assume "Iff (trm.Bool False) t2 t3 = Iff e1 e2 e3" and "\<Gamma> \<turnstile> e1 : T1 ; TT"
hence "\<Gamma> \<turnstile> (trm.Bool False) : T1 ; TT" by (simp add: trm.inject)
hence "TT = FF" using false_ty_elim[of \<Gamma> T1 TT] by simp
thus ?thesis by (simp)
next
fix e1 e2 e3 T1 T3 effa
assume "Iff (trm.Bool False) t2 t3 = Iff e1 e2 e3" and " eff = eff.NE"and" \<Gamma> \<turnstile> e1 : T1 ; FF" and " \<Gamma> \<turnstile> e3 : T3 ; effa"and " \<turnstile> T3 <: \<sigma>"
thus ?thesis by (auto simp add: trm.inject)
next
fix e1 e2 e3 T1 T3 eff1 eff3
assume "Iff (trm.Bool False) t2 t3 = Iff e1 e2 e3" and "eff = eff.NE"
and f:"\<Gamma> \<turnstile> e1 : T1 ; eff1" and g:"env_minus eff1 \<Gamma> \<turnstile> e3 : T3 ; eff3" and "\<turnstile> T3 <: \<sigma>"
hence "e1 = Bool False" and "t3 = e3" by (auto simp add: trm.inject)
hence "eff1 = FF" using f false_ty_elim by auto
hence "env_minus eff1 \<Gamma> = \<Gamma>" by simp
hence "\<Gamma> \<turnstile> e3 : T3 ; eff3" using g by simp
thus ?thesis using `t3 = e3` `\<turnstile> T3 <: \<sigma>` `eff = eff.NE` by auto
qed
lemma var_ty_elim:
"\<Gamma> \<turnstile> Var v : \<sigma> ; eff \<Longrightarrow> (v,\<sigma>) : set \<Gamma> \<and> eff = VE v \<and> valid \<Gamma>"
by (ind_cases "\<Gamma> \<turnstile> Var v : \<sigma> ; eff")
(auto simp add: trm.inject)
inductive_cases app_ty_ff:"\<Gamma> \<turnstile> App e arg : T' ; FF"
lemma app_ty_ff_elim:
"\<Gamma> \<turnstile> App rator rand : T ; FF \<Longrightarrow>
EX S T0 le F1 T0' F2 U. \<Gamma> \<turnstile> rator : U ; F1 \<and> \<Gamma> \<turnstile> rand : T0' ; F2 \<and> \<turnstile> T0' <: T0 \<and> \<turnstile> U <: T0 \<rightarrow> T : le \<and>
le = Latent S \<and> (~ (\<turnstile> T0' <: S)) \<and> rand : values \<and> closed rand"
proof (ind_cases "\<Gamma> \<turnstile> App rator rand : T ; FF")
fix e1 T0 S eff1 e2 Ta eff2 U
assume "App rator rand = App e1 e2 "" \<Gamma> \<turnstile> e1 : U ; eff1 " "\<turnstile> U <: T0 \<rightarrow> T : Latent S"
"\<Gamma> \<turnstile> e2 : Ta ; eff2 ""\<turnstile> Ta <: T0""~ (\<turnstile> Ta <: S)" "e2 : values" "closed e2"
have a:" \<Gamma> \<turnstile> rator : U ; eff1 " using prems trm.inject by auto
have b:"\<Gamma> \<turnstile> rand : Ta ; eff2" using prems trm.inject by auto
have c:"rand : values" "closed rand" using prems trm.inject by auto
from a b c prems show ?thesis by blast
qed
lemma app_ty_tt_elim:
"\<Gamma> \<turnstile> App rator rand : T ; TT \<Longrightarrow>
EX S T0 le F1 T0' F2 U. \<Gamma> \<turnstile> rator : U ; F1 \<and> \<Gamma> \<turnstile> rand : T0' ; F2 \<and> \<turnstile> T0' <: T0 \<and> \<turnstile> U <: T0 \<rightarrow> T : le
\<and> le = Latent S \<and> \<turnstile> T0' <: S "
proof (ind_cases "\<Gamma> \<turnstile> App rator rand : T ; TT")
fix e1 T0 S eff1 e2 Ta eff2 U
assume "App rator rand = App e1 e2 "" \<Gamma> \<turnstile> e1 : U ; eff1 " "\<turnstile> U <: T0 \<rightarrow> T : Latent S"
"\<Gamma> \<turnstile> e2 : Ta ; eff2 ""\<turnstile> Ta <: T0"" \<turnstile> Ta <: S"
have a:" \<Gamma> \<turnstile> rator : U ; eff1 " using prems trm.inject by auto
have b:"\<Gamma> \<turnstile> rand : Ta ; eff2" using prems trm.inject by auto
from a b prems show ?thesis by blast
qed
text {* values don't have union types *}
lemma value_simple_type:
assumes A:"\<Gamma> \<turnstile> v : T ; F" and B:"v : values"
shows "simple_ty T"
using B A
proof (nominal_induct v avoiding: \<Gamma> rule: values.strong_induct)
case (bi_value b) thus ?case using bi_ty_elim[of \<Gamma> b T F]
by (nominal_induct b rule: builtin.induct)
(auto simp add: trm.inject)
next
case num_value thus ?case using num_ty_elim[OF num_value] by auto
next
case bool_value thus ?case using bool_ty_elim[OF bool_value] by auto
next
case (abs_value a T' b \<Gamma>') thus ?case using abs_ty_elim[of \<Gamma>' a b T' T F] by auto
qed
text {* lemmas about the effects of closed terms *}
lemma ve_not_closed:
"\<Gamma> \<turnstile> e : T ; eff.VE x \<Longrightarrow>
x : supp e"
by (ind_cases "\<Gamma> \<turnstile> e : T ; eff.VE x")
(auto simp add: eff.inject trm.supp at_supp supp_atm)
lemma te_not_closed:
"\<Gamma> \<turnstile> e : T ; eff.TE T' x \<Longrightarrow>
x : supp e"
proof (ind_cases "\<Gamma> \<turnstile> e : T ; eff.TE T' x")
fix e1 T0 S eff1 e2 Ta xa
assume "e = App e1 e2" "TE T' x = TE S xa" "\<Gamma> \<turnstile> e2 : Ta ; VE xa"
have "x = xa" using prems eff.inject by auto
hence "\<Gamma> \<turnstile> e2 : Ta ; VE x" using prems eff.inject by auto
hence "x : supp e2" using ve_not_closed by auto
thus "x : supp e" using prems trm.supp by auto
qed
lemma closed_eff:
assumes "closed e" and "\<Gamma> \<turnstile> e : T ; eff"
shows "simple_eff eff"
using prems
proof (nominal_induct eff rule: eff.induct)
case (VE name) thus ?case using ve_not_closed[of _ e _ name] closed_def by auto
next
case (TE _ name) thus ?case using te_not_closed[of _ e _ _ name] closed_def by auto
qed (auto)
lemma closed_eff_below_NE:
assumes "closed e" and "\<Gamma> \<turnstile> e : T ; eff"
shows "\<turnstile> eff <e: eff.NE"
using closed_eff simple_eff_below_ne prems by auto
inductive_cases const_ty_int_case: "\<Gamma> \<turnstile> (Num n) : ty.Int ; eff"
inductive_cases trm_ty_int_case: "\<Gamma> \<turnstile> e : ty.Int ; eff"
inductive_cases const_ty_bool_case: "\<Gamma> \<turnstile> (Bool b) : BoolTy ; eff"
lemma add1_eff_ne:
"\<Gamma> \<turnstile> (App (BI Add1) v) : T1 ; eff1 \<Longrightarrow> eff1 = eff.NE"
proof (ind_cases " \<Gamma> \<turnstile> (App (BI Add1) v) : T1 ; eff1")
assume "eff1 = eff.NE" thus ?thesis by simp
next
fix T0 T1 S eff1a e1 e2 U
assume "\<Gamma> \<turnstile> e1 : U ; eff1a" "App (BI Add1) v = App e1 e2" "\<turnstile> U <: T0 \<rightarrow> T1 : Latent S"
hence "\<Gamma> \<turnstile> (BI Add1) : U ; eff1a" by (simp add: trm.inject)
hence "\<Delta>\<^isub>\<tau> Add1 = U" using type_add1_case[of \<Gamma> "U"] by (auto simp add: trm.inject)
hence "\<dots> = ty.Int \<rightarrow> ty.Int : latent_eff.NE" by auto
thus ?thesis using prems arr_sub_arr_cases[of ty.Int ty.Int latent_eff.NE] by (auto simp add: ty.inject)
next
fix T0 T1 S eff1a e1 e2 U
assume "\<Gamma> \<turnstile> e1 : U ; eff1a" "App (BI Add1) v = App e1 e2" "\<turnstile> U <: T0 \<rightarrow> T1 : Latent S"
hence "\<Gamma> \<turnstile> (BI Add1) : U ; eff1a" by (simp add: trm.inject)
hence "\<Delta>\<^isub>\<tau> Add1 = U" using type_add1_case[of \<Gamma> "U"] by (auto simp add: trm.inject)
hence "\<dots> = ty.Int \<rightarrow> ty.Int : latent_eff.NE" by auto
thus ?thesis using prems arr_sub_arr_cases[of ty.Int ty.Int latent_eff.NE] by (auto simp add: ty.inject)
next
fix T0 T1 S eff1a e1 e2 U
assume "\<Gamma> \<turnstile> e1 : U ; eff1a" "App (BI Add1) v = App e1 e2" "\<turnstile> U <: T0 \<rightarrow> T1 : Latent S"
hence "\<Gamma> \<turnstile> (BI Add1) : U ; eff1a" by (simp add: trm.inject)
hence "\<Delta>\<^isub>\<tau> Add1 = U" using type_add1_case[of \<Gamma> "U"] by (auto simp add: trm.inject)
hence "\<dots> = ty.Int \<rightarrow> ty.Int : latent_eff.NE" by auto
thus ?thesis using prems arr_sub_arr_cases[of ty.Int ty.Int latent_eff.NE] by (auto simp add: ty.inject)
qed
inductive_cases type_nott_case: "\<Gamma> \<turnstile> (BI Nott) : t ; e"
lemma nott_eff_ne:
"\<Gamma> \<turnstile> (App (BI Nott) v) : T1 ; eff1 \<Longrightarrow> eff1 = eff.NE"
proof (ind_cases " \<Gamma> \<turnstile> (App (BI Nott) v) : T1 ; eff1")
assume "eff1 = eff.NE" thus ?thesis by simp
next
fix T0 T1 S eff1a e1 e2 U
assume "\<Gamma> \<turnstile> e1 : U ; eff1a" "App (BI Nott) v = App e1 e2" "\<turnstile> U <: T0 \<rightarrow> T1 : Latent S"
hence "\<Gamma> \<turnstile> (BI Nott) : U ; eff1a" by (simp add: trm.inject)
hence "\<Delta>\<^isub>\<tau> Nott = U" using type_nott_case[of \<Gamma> "U"] by (auto simp add: trm.inject)
hence "\<dots> = Top \<rightarrow> BoolTy : latent_eff.NE" by auto
thus ?thesis using prems arr_sub_arr_cases[of Top BoolTy latent_eff.NE] by (auto simp add: ty.inject)
next
fix T0 T1 S eff1a e1 e2 U
assume "\<Gamma> \<turnstile> e1 : U ; eff1a" "App (BI Nott) v = App e1 e2" "\<turnstile> U <: T0 \<rightarrow> T1 : Latent S"
hence "\<Gamma> \<turnstile> (BI Nott) : U ; eff1a" by (simp add: trm.inject)
hence "\<Delta>\<^isub>\<tau> Nott = U" using type_nott_case[of \<Gamma> "U"] by (auto simp add: trm.inject)
hence "\<dots> = Top \<rightarrow> BoolTy : latent_eff.NE" by auto
thus ?thesis using prems arr_sub_arr_cases[of Top BoolTy latent_eff.NE] by (auto simp add: ty.inject)
next
fix T0 T1 S eff1a e1 e2 U
assume "\<Gamma> \<turnstile> e1 : U ; eff1a" "App (BI Nott) v = App e1 e2" "\<turnstile> U <: T0 \<rightarrow> T1 : Latent S"
hence "\<Gamma> \<turnstile> (BI Nott) : U ; eff1a" by (simp add: trm.inject)
hence "\<Delta>\<^isub>\<tau> Nott = U" using type_nott_case[of \<Gamma> "U"] by (auto simp add: trm.inject)
hence "\<dots> = Top \<rightarrow> BoolTy : latent_eff.NE" by auto
thus ?thesis using prems arr_sub_arr_cases[of Top BoolTy latent_eff.NE] by (auto simp add: ty.inject)
qed
inductive_cases type_booleanp_case: "\<Gamma> \<turnstile> (BI BooleanP) : t ; e"
lemma value_eff:
assumes "v : values" and "\<Gamma> \<turnstile> v : T ; eff"
shows "simple_eff eff"
using prems
proof (induct v rule :values.induct)
case abs_value thus ?case using abs_ty_elim_eff by auto
next
case num_value thus ?case using num_ty_elim by auto
next
case (bool_value b) thus ?case using true_ty_elim false_ty_elim by (cases b) auto
next
case bi_value thus ?case using bi_ty_elim by auto
qed
lemma booleanp_eff_simple:
"\<lbrakk>\<Gamma> \<turnstile> (App (BI BooleanP) v) : T1 ; eff1 ; v : values\<rbrakk> \<Longrightarrow> simple_eff eff1"
proof (ind_cases " \<Gamma> \<turnstile> (App (BI BooleanP) v) : T1 ; eff1")
fix T0 T1 S eff1a e1 e2 xa T
assume "\<Gamma> \<turnstile> e2 : T ; VE xa" "App (BI BooleanP) v = App e1 e2" "v : values"
hence "VE xa = eff.NE \<or> VE xa = eff.TT \<or> VE xa = eff.FF " using value_eff[of v \<Gamma> T "VE xa"]
by (auto simp add: trm.inject)
thus ?thesis using ty.distinct by auto
qed (auto)
lemma numberp_eff_simple:
"\<lbrakk>\<Gamma> \<turnstile> (App (BI NumberP) v) : T1 ; eff1 ; v : values\<rbrakk> \<Longrightarrow> simple_eff eff1"
proof (ind_cases " \<Gamma> \<turnstile> (App (BI NumberP) v) : T1 ; eff1")
fix T0 T1 S eff1a e1 e2 xa T
assume "\<Gamma> \<turnstile> e2 : T ; VE xa" "App (BI NumberP) v = App e1 e2" "v : values"
hence "VE xa = eff.NE \<or> VE xa = eff.TT \<or> VE xa = eff.FF " using value_eff[of v \<Gamma> T "VE xa"]
by (auto simp add: trm.inject)
thus ?thesis using ty.distinct by auto
qed (auto)
lemma procp_eff_simple:
"\<lbrakk>\<Gamma> \<turnstile> (App (BI ProcP) v) : T1 ; eff1 ; v : values\<rbrakk> \<Longrightarrow> simple_eff eff1"
proof (ind_cases " \<Gamma> \<turnstile> (App (BI ProcP) v) : T1 ; eff1")
fix T0 T1 S eff1a e1 e2 xa T
assume "\<Gamma> \<turnstile> e2 : T ; VE xa" "App (BI ProcP) v = App e1 e2" "v : values"
hence "VE xa = eff.NE \<or> VE xa = eff.TT \<or> VE xa = eff.FF " using value_eff[of v \<Gamma> T "VE xa"]
by (auto simp add: trm.inject)
thus ?thesis using ty.distinct by auto
qed (auto)
inductive_cases app_boolp_ff: "\<Gamma> \<turnstile> (App (BI BooleanP) v) : T1 ; FF"
lemma booleanp_FF_preserved:
assumes "\<Gamma> \<turnstile> (App (BI BooleanP) v) : T1 ; FF" and "v : values" and "\<Delta> BooleanP v = Some u"
shows "u = Bool False"
using `v : values` prems
proof (induct v rule: values.induct)
case (bool_value b)
let ?P = "\<Gamma> \<turnstile> App (BI BooleanP) (trm.Bool b) : T1 ; FF"
have "?P ==> ?case"
proof (ind_cases ?P)
fix S T e1 e2 T0 eff1 eff2 U
assume "App (BI BooleanP) (trm.Bool b) = App e1 e2" "\<Gamma> \<turnstile> e1 : U ; eff1 " "\<Gamma> \<turnstile> e2 : T ; eff2"
"~ (\<turnstile> T <: S)" "e2 : values" "\<turnstile> U <: T0 \<rightarrow> T1 : Latent S"
hence a:"\<Gamma> \<turnstile> (BI BooleanP) : U ; eff1 " using trm.inject by auto
from prems have b:"\<Gamma> \<turnstile> Bool b : T ; eff2" using trm.inject by auto
have "U = Top \<rightarrow> BoolTy : Latent BoolTy" using a bi_ty_elim[of \<Gamma> BooleanP "U"] by auto
hence c:"S = BoolTy" using prems arr_sub_arr_cases[of Top BoolTy _ T0 T1 "Latent S"] latent_eff.inject by auto
from b have d:"T = ty.TT \<or> T = ty.FF" using true_ty_elim false_ty_elim by (cases b) auto
from c d have "\<turnstile> T <: S" by auto
thus ?thesis using prems by auto
qed
thus ?case using bool_value by auto
qed (auto)
lemma typing_valid:
assumes "\<Gamma> \<turnstile> e : T ; F"
shows "valid \<Gamma>"
using prems
proof (induct)
case (T_Abs a \<Gamma> T b T' F') thus ?case using valid_elim[of a T \<Gamma>] by auto
next
case (T_AbsPred a \<Gamma> T b T' F') thus ?case using valid_elim[of a T \<Gamma>] by auto
qed (auto)
lemma booleanp_TT_preserved:
assumes "\<Gamma> \<turnstile> (App (BI BooleanP) v) : T1 ; TT" and "v : values" and "\<Delta> BooleanP v = Some u"
shows "u = Bool True"
proof -
note app_ty_tt_elim[of \<Gamma> "(BI BooleanP)" v T1]
then obtain A1 U T0 T1 S eff1 eff2 where
A:"\<Gamma> \<turnstile> (BI BooleanP) : U ; eff1" "\<turnstile> U <: A1 \<rightarrow> T1 : Latent S" "\<Gamma> \<turnstile> v : T0 ; eff2" "\<turnstile> T0 <: A1" "\<turnstile> T0 <: S"
using prems by auto
hence B:"U = Top \<rightarrow> BoolTy : Latent BoolTy " using bi_ty_elim[of \<Gamma> BooleanP U] by auto
hence C:"\<turnstile> T0 <: BoolTy"
using prems arr_sub_arr_cases[of Top BoolTy "Latent BoolTy" _ _ "Latent S"] latent_eff.inject A by auto
then obtain b where D:"v = Bool b" using A bool_value[of v \<Gamma> T0] prems by auto
thus ?thesis using prems by auto
qed
lemma booleanp_soundness_eff:
assumes "\<Gamma> \<turnstile> App (BI BooleanP) v : T ; F" and "v : values" and "\<Delta> BooleanP v = Some u" and "\<Gamma> \<turnstile> u : T' ; F'"
shows "\<turnstile> F' <e: F"
proof -
have cl:"closed u" using prems delta_closed[of BooleanP v u] by auto
hence se:"simple_eff F'" using prems closed_eff by auto
have or:"simple_eff F" using booleanp_eff_simple prems by auto
thus ?thesis using prems
proof (induct rule: simple_eff_cases)
case NE thus ?case using se simple_eff_below_ne by auto
next
case FF thus ?case using false_ty_elim[of \<Gamma> T' F'] booleanp_FF_preserved by auto
next
case TT thus ?case using true_ty_elim[of \<Gamma> T' F'] booleanp_TT_preserved by auto
qed
qed
inductive_cases app_nump_ff: "\<Gamma> \<turnstile> (App (BI NumberP) v) : T1 ; FF"
thm app_nump_ff
lemma numberp_FF_preserved:
assumes "\<Gamma> \<turnstile> (App (BI NumberP) v) : T1 ; FF" and "v : values" and "\<Delta> NumberP v = Some u"
shows "u = Bool False"
using `v : values` prems
proof (induct v rule: values.induct)
case (bool_value b) thus ?case by (cases b) auto
next
case (num_value b)
let ?P = "\<Gamma> \<turnstile> App (BI NumberP) (trm.Num b) : T1 ; FF"
have "?P ==> ?case"
proof (ind_cases ?P)
fix S T e1 e2 T0 eff1 eff2 U
assume "App (BI NumberP) (trm.Num b) = App e1 e2" "\<Gamma> \<turnstile> e1 : U ; eff1 " "\<Gamma> \<turnstile> e2 : T ; eff2"
"~ (\<turnstile> T <: S)" "e2 : values" "\<turnstile> U <: T0 \<rightarrow> T1 : Latent S"
hence a:"\<Gamma> \<turnstile> (BI NumberP) : U ; eff1 " using trm.inject by auto
from prems have b:"\<Gamma> \<turnstile> Num b : T ; eff2" using trm.inject by auto
have "U = Top \<rightarrow> BoolTy : Latent ty.Int" using a bi_ty_elim[of \<Gamma> NumberP "U"] by auto
hence c:"S = ty.Int" using prems arr_sub_arr_cases[of Top _ _ T0 T1 "Latent S"] latent_eff.inject by auto
from b have d:"T = ty.Int" using num_ty_elim by auto
from c d have "\<turnstile> T <: S" by auto
thus ?thesis using prems by auto
qed
thus ?case using num_value by auto
qed (auto)
lemma numberp_TT_preserved:
assumes "\<Gamma> \<turnstile> (App (BI NumberP) v) : T1 ; TT" and "v : values" and "\<Delta> NumberP v = Some u"
shows "u = Bool True"
proof -
note app_ty_tt_elim[of \<Gamma> "(BI NumberP)" v T1]
then obtain A1 U T0 T1 S eff1 eff2 where
A:"\<Gamma> \<turnstile> (BI NumberP) : U ; eff1" "\<turnstile> U <: A1 \<rightarrow> T1 : Latent S" "\<Gamma> \<turnstile> v : T0 ; eff2" "\<turnstile> T0 <: A1" "\<turnstile> T0 <: S"
using prems by auto
hence B:"U = Top \<rightarrow> BoolTy : Latent ty.Int " using bi_ty_elim[of \<Gamma> NumberP U] by auto
hence C:"\<turnstile> T0 <: ty.Int"
using prems arr_sub_arr_cases[of Top BoolTy "Latent ty.Int" _ _ "Latent S"] latent_eff.inject A by auto
then obtain b where D:"v = Num b" using A int_value[of v \<Gamma> T0] prems by auto
thus ?thesis using prems by auto
qed
lemma numberp_soundness_eff:
assumes "\<Gamma> \<turnstile> App (BI NumberP) v : T ; F" and "v : values" and "\<Delta> NumberP v = Some u" and "\<Gamma> \<turnstile> u : T' ; F'"
shows "\<turnstile> F' <e: F"
proof -
have cl:"closed u" using prems delta_closed[of NumberP v u] by auto
hence se:"simple_eff F'" using prems closed_eff by auto
have or:"simple_eff F" using numberp_eff_simple prems by auto
thus ?thesis using prems
proof (induct rule: simple_eff_cases)
case NE thus ?case using se simple_eff_below_ne by auto
next
case FF thus ?case using false_ty_elim[of \<Gamma> T' F'] numberp_FF_preserved by auto
next
case TT thus ?case using true_ty_elim[of \<Gamma> T' F'] numberp_TT_preserved by auto
qed
qed
lemma empty_un_bot:
fixes T :: ty
shows "\<turnstile> Union [] <: T"
by auto
lemma all_fun_ty_below:
fixes S T :: ty
shows "\<turnstile> S \<rightarrow> T : F <: (Union []) \<rightarrow> Top : latent_eff.NE"
by (rule S_Fun) auto
inductive_cases below_latent_ne_cases: "\<turnstile> S \<rightarrow> T : F <: S' \<rightarrow> T' : latent_eff.NE"
thm below_latent_ne_cases
inductive_cases app_procp_ff: "\<Gamma> \<turnstile> (App (BI ProcP) v) : T1 ; FF"
thm app_nump_ff
thm app_procp_ff
lemma procp_FF_preserved:
assumes "\<Gamma> \<turnstile> (App (BI ProcP) v) : T1 ; FF" and "v : values" and "\<Delta> ProcP v = Some u"
shows "u = Bool False"
using `v : values` prems
proof (nominal_induct v avoiding: \<Gamma> rule: values.strong_induct)
case (bool_value b) thus ?case by (cases b) auto
next
case (num_value b) thus ?case by auto
next
case (abs_value x t b)
let ?P = "\<Gamma> \<turnstile> App (BI ProcP) (Lam[x:t].b) : T1 ; FF"
have "?P ==> ?case"
proof (ind_cases ?P)
fix e1 U eff1 T0 S e2 T eff2
assume "App (BI ProcP) (Lam [x:t].b) = App e1 e2 "" \<Gamma> \<turnstile> e1 : U ; eff1 "" \<turnstile> U <: T0 \<rightarrow> T1 : Latent S "
"\<Gamma> \<turnstile> e2 : T ; eff2 "" \<turnstile> T <: T0 "" \<not> \<turnstile> T <: S "" e2 \<in> values "" closed e2"
hence a:"\<Gamma> \<turnstile> (BI ProcP) : U ; eff1 " using trm.inject by auto
from prems have b:"\<Gamma> \<turnstile> Lam[x:t].b : T ; eff2" using trm.inject by auto
have "U = Top \<rightarrow> BoolTy : Latent (Union [] \<rightarrow> Top : latent_eff.NE)" using a bi_ty_elim[of \<Gamma> ProcP "U"] by auto
hence c:"S = Union [] \<rightarrow> Top : latent_eff.NE" using prems arr_sub_arr_cases[of Top _ _ T0 T1 "Latent S"] latent_eff.inject by auto
have "EX A1 A2 L. T = A1 \<rightarrow> A2 : L" using abs_ty_elim[OF b `x \<sharp> \<Gamma>`] by auto
then obtain A1 A2 L where d:"T = A1 \<rightarrow> A2 : L" by auto
from c d have "\<turnstile> T <: S" using all_fun_ty_below by auto
thus ?thesis using prems by auto
qed
thus ?case using abs_value by auto
next
case (bi_value c)
let ?P = "\<Gamma> \<turnstile> App (BI ProcP) (BI c) : T1 ; FF"
have "?P ==> ?case"
proof (ind_cases ?P)
fix e1 U eff1 T0 S e2 T eff2
assume "App (BI ProcP) (BI c) = App e1 e2 "" \<Gamma> \<turnstile> e1 : U ; eff1 "" \<turnstile> U <: T0 \<rightarrow> T1 : Latent S "
"\<Gamma> \<turnstile> e2 : T ; eff2 "" \<turnstile> T <: T0 "" \<not> \<turnstile> T <: S "" e2 \<in> values "" closed e2"
hence a:"\<Gamma> \<turnstile> (BI ProcP) : U ; eff1 " using trm.inject by auto
from prems have b:"\<Gamma> \<turnstile> (BI c) : T ; eff2" using trm.inject by auto
have "U = Top \<rightarrow> BoolTy : Latent (Union [] \<rightarrow> Top : latent_eff.NE)" using a bi_ty_elim[of \<Gamma> ProcP "U"] by auto
hence c:"S = Union [] \<rightarrow> Top : latent_eff.NE" using prems arr_sub_arr_cases[of Top _ _ T0 T1 "Latent S"] latent_eff.inject by auto
have b':"T = \<Delta>\<^isub>\<tau> c" using bi_ty_elim[OF b] by auto
hence "EX A1 A2 FA. T = A1 \<rightarrow> A2 : FA" by (nominal_induct c rule: builtin.induct) auto
then obtain A1 A2 F where d:"T = A1 \<rightarrow> A2 : F" by auto
hence "\<turnstile> T <: S" using c d all_fun_ty_below by auto
thus ?thesis using prems by auto
qed
thus ?case using bi_value by auto
qed
lemma proc_value:
assumes "\<Gamma> \<turnstile> v : T ; F"
and "v : values"
and "\<turnstile> T <: (A1 \<rightarrow> A2 : latent_eff.NE)"
shows "EX x b t. v = Lam[x:t].b \<or> (EX c. v = BI c)"
using `v : values` prems
proof (nominal_induct v avoiding: \<Gamma> rule: values.strong_induct)
case abs_value thus ?case by auto
next
case (bool_value b)
hence "T = ty.TT \<or> T = ty.FF" using bool_ty_elim by auto
thus ?case using sub_arr_cases[of T A1 A2 latent_eff.NE] using bool_value by auto
next
case (num_value b)
hence "T = ty.Int" using num_ty_elim by auto
thus ?case using sub_arr_cases[of T A1 A2 latent_eff.NE] using num_value by auto
next
case (bi_value c) thus ?case by auto
qed
lemma procp_TT_preserved:
assumes "\<Gamma> \<turnstile> (App (BI ProcP) v) : T1 ; TT" and "v : values" and "\<Delta> ProcP v = Some u"
shows "u = Bool True"
proof -
note app_ty_tt_elim[of \<Gamma> "(BI ProcP)" v T1]
then obtain A1 U T0 T1 S eff1 eff2 where
A:"\<Gamma> \<turnstile> (BI ProcP) : U ; eff1" "\<turnstile> U <: A1 \<rightarrow> T1 : Latent S" "\<Gamma> \<turnstile> v : T0 ; eff2" "\<turnstile> T0 <: A1" "\<turnstile> T0 <: S"
using prems by auto
hence B:"U = Top \<rightarrow> BoolTy : Latent (Union [] \<rightarrow> Top : latent_eff.NE) " using bi_ty_elim[of \<Gamma> ProcP U] by auto
hence C:"\<turnstile> T0 <: (Union [] \<rightarrow> Top : latent_eff.NE)"
using prems arr_sub_arr_cases[of Top BoolTy "Latent (Union [] \<rightarrow> Top : latent_eff.NE)" _ _ "Latent S"] latent_eff.inject A
by auto
moreover
{
assume D:"EX x b t. v = Lam[x:t].b"
then obtain x b t where "v = Lam[x:t].b" by auto
hence ?thesis using prems by auto
}
moreover
{
assume "EX c. v = BI c"
then obtain c where "v = BI c" by auto
hence ?thesis using prems by (nominal_induct c rule: builtin.induct) auto
}
ultimately show ?thesis using prems proc_value[of \<Gamma> v T0 eff2 "Union []" Top] by auto
qed
lemma procp_soundness_eff:
assumes "\<Gamma> \<turnstile> App (BI ProcP) v : T ; F" and "v : values" and "\<Delta> ProcP v = Some u" and "\<Gamma> \<turnstile> u : T' ; F'"
shows "\<turnstile> F' <e: F"
proof -
have cl:"closed u" using prems delta_closed[of ProcP v u] by auto
hence se:"simple_eff F'" using prems closed_eff by auto
have or:"simple_eff F" using procp_eff_simple prems by auto
thus ?thesis using prems
proof (induct rule: simple_eff_cases)
case NE thus ?case using se simple_eff_below_ne by auto
next
case FF thus ?case using false_ty_elim[of \<Gamma> T' F'] procp_FF_preserved by auto
next
case TT thus ?case using true_ty_elim[of \<Gamma> T' F'] procp_TT_preserved by auto
qed
qed
text {* soundness of the \<Delta> rule *}
lemma bool_sub_boolty[simp]: "\<turnstile> ty.FF <: BoolTy" "\<turnstile> ty.TT <: BoolTy" by auto
lemma delta_soundness:
assumes "\<Delta>\<^isub>\<tau> b = (T0 \<rightarrow> T1 : le)" and "v : values" and "\<Gamma> \<turnstile> v : T ; eff1" and "\<turnstile> T <: T0"
and "\<Gamma> \<turnstile> (App (BI b) v) : T1' ; eff" and "\<turnstile> T1 <: T1'"
and "\<Delta> b v = Some u" and "valid \<Gamma>"
shows "EX eff' T1'. \<Gamma> \<turnstile> u : T1' ; eff' \<and> \<turnstile> eff' <e: eff \<and> \<turnstile> T1' <: T1"
using prems
proof (nominal_induct b rule: builtin.induct)
case Add1
hence a:"eff = NE" using add1_eff_ne[of \<Gamma> v T1' eff] by auto
have "EX eff'. \<Gamma> \<turnstile> u : T1 ; eff'" using `v : values` `valid \<Gamma>` Add1
by (induct v rule: values.induct) (auto simp add: ty.inject)
then obtain eff' where b:"\<Gamma> \<turnstile> u : T1 ; eff'" by auto
have "simple_eff eff'" using delta_closed[of Add1 v u] closed_eff b Add1 by auto
hence c:"\<turnstile> eff' <e: eff" using a simple_eff_below_ne by auto
from b c show ?case by auto
next
case Nott
hence a:"eff = NE" using nott_eff_ne[of \<Gamma> v T1' eff] by auto
have "EX eff' T1'. \<Gamma> \<turnstile> u : T1' ; eff' \<and> \<turnstile> T1' <: T1" using `v : values` `valid \<Gamma>` Nott
proof (induct v rule: values.induct)
case (bool_value b)
thus ?case using bool_value bool_sub_boolty by (cases b) auto
next
case num_value thus ?case using bool_sub_boolty by auto
next
case bi_value thus ?case using bool_sub_boolty by auto
next
case abs_value thus ?case using bool_sub_boolty by auto
qed
then obtain eff' T1' where b:"\<Gamma> \<turnstile> u : T1' ; eff'" and b':"\<turnstile> T1' <: T1" by auto
have "simple_eff eff'" using delta_closed[of Nott v u] closed_eff b Nott by auto
hence c:"\<turnstile> eff' <e: eff" using a simple_eff_below_ne by auto
from b b' c show ?case by auto
next
case BooleanP
have "valid \<Gamma>" using typing_valid prems by auto
have "T1 = BoolTy" using BooleanP by (simp add: ty.inject)
then obtain bb where veq:"\<Delta> BooleanP v = Some (Bool bb)" by (nominal_induct v rule: trm.induct) (auto)
hence "EX T1' eff'. \<Gamma> \<turnstile> u : T1' ; eff' \<and> \<turnstile> T1' <: T1"
using `T1 = BoolTy` BooleanP bool_sub_boolty
proof (cases bb)
case True
hence "u = Bool True" using veq BooleanP by auto
hence "\<Gamma> \<turnstile> u : ty.TT; TT" using `valid \<Gamma>` by auto
thus ?thesis using `T1 = BoolTy` bool_sub_boolty by auto
next
case False
hence "u = Bool False" using veq BooleanP by auto
hence "\<Gamma> \<turnstile> u : ty.FF; FF" using `valid \<Gamma>` by auto
thus ?thesis using `T1 = BoolTy` bool_sub_boolty by auto
qed
then obtain T1a eff' where a:"\<Gamma> \<turnstile> u : T1a ; eff'" and a':"\<turnstile> T1a <: T1" by auto
have c:"simple_eff eff'" using delta_closed[of BooleanP v u] closed_eff prems by auto
have b:"simple_eff eff" using BooleanP booleanp_eff_simple by auto
hence "\<turnstile> eff' <e: eff" using b prems
proof (induct rule: simple_eff_cases)
case NE thus ?case using simple_eff_below_ne c by auto
next
case FF
hence "u = Bool False"
using booleanp_FF_preserved `v : values` `\<Gamma> \<turnstile> App (BI BooleanP) v : T1' ; eff` `\<Delta> BooleanP v = Some u` by auto
hence "eff'= FF" using a false_ty_elim by auto
thus ?case using FF by auto
next
case TT
hence "u = Bool True"
using booleanp_TT_preserved `v : values` `\<Gamma> \<turnstile> App (BI BooleanP) v : T1' ; eff` `\<Delta> BooleanP v = Some u` by auto
hence "eff'= TT" using a true_ty_elim by auto
thus ?case using TT by auto
qed
thus ?case using a a' by auto
next
case NumberP
have "valid \<Gamma>" using typing_valid prems by auto
have "T1 = BoolTy" using NumberP by (simp add: ty.inject)
then obtain bb where veq:"\<Delta> NumberP v = Some (Bool bb)" by (nominal_induct v rule: trm.induct) (auto)
hence "EX T1' eff'. \<Gamma> \<turnstile> u : T1' ; eff' \<and> \<turnstile> T1' <: T1"
using `T1 = BoolTy` NumberP bool_sub_boolty
proof (cases bb)
case True
hence "u = Bool True" using veq NumberP by auto
hence "\<Gamma> \<turnstile> u : ty.TT; TT" using `valid \<Gamma>` by auto
thus ?thesis using `T1 = BoolTy` bool_sub_boolty by auto
next
case False
hence "u = Bool False" using veq NumberP by auto
hence "\<Gamma> \<turnstile> u : ty.FF; FF" using `valid \<Gamma>` by auto
thus ?thesis using `T1 = BoolTy` bool_sub_boolty by auto
qed
then obtain T1a eff' where a:"\<Gamma> \<turnstile> u : T1a ; eff'" and a':"\<turnstile> T1a <: T1" by auto
have c:"simple_eff eff'" using delta_closed[of NumberP v u] closed_eff prems by auto
have b:"simple_eff eff" using NumberP numberp_eff_simple by auto
hence "\<turnstile> eff' <e: eff" using b prems
proof (induct rule: simple_eff_cases)
case NE thus ?case using simple_eff_below_ne c by auto
next
case FF
hence "u = Bool False"
using numberp_FF_preserved `v : values` `\<Gamma> \<turnstile> App (BI NumberP) v : T1' ; eff` `\<Delta> NumberP v = Some u` by auto
hence "eff'= FF" using a false_ty_elim by auto
thus ?case using FF by auto
next
case TT
hence "u = Bool True"
using numberp_TT_preserved `v : values` `\<Gamma> \<turnstile> App (BI NumberP) v : T1' ; eff` `\<Delta> NumberP v = Some u` by auto
hence "eff'= TT" using a true_ty_elim by auto
thus ?case using TT by auto
qed
thus ?case using a a' by auto
next
case ProcP
have "valid \<Gamma>" using typing_valid prems by auto
have "T1 = BoolTy" using ProcP by (simp add: ty.inject)
then obtain bb where veq:"\<Delta> ProcP v = Some (Bool bb)" by (nominal_induct v rule: trm.induct) (auto)
hence "EX T1' eff'. \<Gamma> \<turnstile> u : T1' ; eff' \<and> \<turnstile> T1' <: T1"
using `T1 = BoolTy` ProcP bool_sub_boolty
proof (cases bb)
case True
hence "u = Bool True" using veq ProcP by auto
hence "\<Gamma> \<turnstile> u : ty.TT; TT" using `valid \<Gamma>` by auto
thus ?thesis using `T1 = BoolTy` bool_sub_boolty by auto
next
case False
hence "u = Bool False" using veq ProcP by auto
hence "\<Gamma> \<turnstile> u : ty.FF; FF" using `valid \<Gamma>` by auto
thus ?thesis using `T1 = BoolTy` bool_sub_boolty by auto
qed
then obtain T1a eff' where a:"\<Gamma> \<turnstile> u : T1a ; eff'" and a':"\<turnstile> T1a <: T1" by auto
have c:"simple_eff eff'" using delta_closed[of ProcP v u] closed_eff prems by auto
have b:"simple_eff eff" using ProcP procp_eff_simple by auto
hence "\<turnstile> eff' <e: eff" using b prems
proof (induct rule: simple_eff_cases)
case NE thus ?case using simple_eff_below_ne c by auto
next
case FF
hence "u = Bool False"
using procp_FF_preserved `v : values` `\<Gamma> \<turnstile> App (BI ProcP) v : T1' ; eff` `\<Delta> ProcP v = Some u` by auto
hence "eff'= FF" using a false_ty_elim by auto
thus ?case using FF by auto
next
case TT
hence "u = Bool True"
using procp_TT_preserved `v : values` `\<Gamma> \<turnstile> App (BI ProcP) v : T1' ; eff` `\<Delta> ProcP v = Some u` by auto
hence "eff'= TT" using a true_ty_elim by auto
thus ?case using TT by auto
qed
thus ?case using a a' by auto
qed
lemma simple_eff_below_ve:
assumes "simple_eff F"
shows "\<turnstile> F <e: VE x"
using prems
by (induct F rule: simple_eff_cases) auto
lemma below_ne_simple:
assumes "\<turnstile> F <e: G" and "G = NE"
shows "simple_eff F"
using prems no_sub_TT no_sub_FF
by induct auto
lemma below_ve_simple:
assumes "\<turnstile> F <e: G" and "G = VE x"
shows "simple_eff F \<or> F = VE x"
using prems
by induct auto
consts
remove_env :: "'a list => 'a => 'a list" ("_ - _" [100,100] 100)
primrec
"[] - x = []"
"(y#xs) - x = (if x=y then (xs - x) else y#(xs - x))"
lemma fresh_remove:
fixes a::"name"
and \<Gamma>::"(name\<times>ty) list"
assumes a: "a\<sharp>\<Gamma>"
shows "a\<sharp>(\<Gamma> - (x,T))"
using a
by (induct \<Gamma>) (auto simp add: fresh_list_cons)
lemma valid_remove:
fixes pair::"name\<times>ty"
assumes a: "valid \<Gamma>"
shows "valid (\<Gamma> - (x,T))"
using a
by (induct \<Gamma>) (auto simp add: fresh_remove)
lemma set_remove:
assumes a: "(a,T)\<in>set \<Gamma>"
and b: "a\<noteq>x"
shows "(a,T)\<in>set (\<Gamma> - (x,T'))"
using a b
by (induct \<Gamma>) (auto)
lemma closed_elim:"closed e \<Longrightarrow> (supp e = ({}::name set))" using closed_def by auto
lemma set_remove_comm:
shows "set (l - a) = (set l) - {a}"
by (induct l) auto
lemma envplus_set:
shows "set (\<Gamma> |+ TE T x) = (mapfun restrict T x) ` set \<Gamma>"
proof -
have A:"!! a b. a = b \<Longrightarrow> set a = set b" by auto
have "\<Gamma> |+ TE T x = map (mapfun restrict T x) \<Gamma>" by auto
hence "set (\<Gamma> |+ TE T x) = set (map (mapfun restrict T x) \<Gamma>)"
using A[of "(\<Gamma> |+ TE T x)" "map (mapfun restrict T x) \<Gamma>"] by auto
also have "\<dots> = (mapfun restrict T x) ` set \<Gamma>" by auto
ultimately show ?thesis by auto
qed
lemma envminus_set:
shows "set (\<Gamma> |- TE T x) = (mapfun remove T x) ` set \<Gamma>"
proof -
have A:"!! a b. a = b \<Longrightarrow> set a = set b" by auto
have "\<Gamma> |- TE T x = map (mapfun remove T x) \<Gamma>" by auto
hence "set (\<Gamma> |- TE T x) = set (map (mapfun remove T x) \<Gamma>)"
using A[of "(\<Gamma> |- TE T x)" "map (mapfun remove T x) \<Gamma>"] by auto
also have "\<dots> = (mapfun remove T x) ` set \<Gamma>" by auto
ultimately show ?thesis by auto
qed
lemma envplus_set_ve:
shows "set (\<Gamma> |+ VE x) = (mapfun remove ty.FF x) ` set \<Gamma>"
proof -
have A:"!! a b. a = b \<Longrightarrow> set a = set b" by auto
have "\<Gamma> |+ VE x = map (mapfun remove ty.FF x) \<Gamma>" by auto
hence "set (\<Gamma> |+ VE x) = set (map (mapfun remove ty.FF x) \<Gamma>)"
using A[of "(\<Gamma> |+ VE x)" "map (mapfun remove ty.FF x) \<Gamma>"] by auto
also have "\<dots> = (mapfun remove ty.FF x) ` set \<Gamma>" by auto
ultimately show ?thesis by auto
qed
lemma envminus_set_ve:
shows "set (\<Gamma> |- VE x) = (mapfun replace ty.FF x) ` set \<Gamma>"
proof -
have A:"!! a b. a = b \<Longrightarrow> set a = set b" by auto
have "\<Gamma> |- VE x = map (mapfun replace ty.FF x) \<Gamma>" by auto
hence "set (\<Gamma> |- VE x) = set (map (mapfun replace ty.FF x) \<Gamma>)"
using A[of "(\<Gamma> |- VE x)" "map (mapfun replace ty.FF x) \<Gamma>"] by auto
also have "\<dots> = (mapfun replace ty.FF x) ` set \<Gamma>" by auto
ultimately show ?thesis by auto
qed
lemma fresh_weakening:
assumes a:"x\<sharp>e" and b:"\<Gamma> \<turnstile> e : T ; F" and c: "valid \<Gamma>"
shows "(\<Gamma> - (x,T')) \<turnstile> e : T ; F"
using b a c
proof (nominal_induct \<Gamma> e T F avoiding: x T' rule: typing.strong_induct)
case T_Var thus ?case
by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+
next
case (T_App \<Gamma>' _ _ t1 t2) thus ?case
by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)
next
case T_Abs thus ?case
by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+
next
case T_AbsPred thus ?case
by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+
next
case T_AppPred thus ?case
by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+
next
case T_IfTrue thus ?case
by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+
next
case T_IfFalse thus ?case
by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+
next
case T_True thus ?case
by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+
next
case T_False thus ?case
by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+
next
case T_Num thus ?case
by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+
next
case T_Const thus ?case
by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+
next
case (T_AppPredTrue \<Gamma>' e1 U F1 T0 T1 S e2 T F2 x T')
have A:"x \<sharp> e1" "x \<sharp> e2" using T_AppPredTrue by auto
hence "\<Gamma>' - (x,T') \<turnstile> e1 : U; F1" using T_AppPredTrue by auto
also have "\<Gamma>' - (x,T') \<turnstile> e2 : T ; F2" using T_AppPredTrue A by auto
ultimately show ?case using T_AppPredTrue(3) `\<turnstile> T <: T0` `\<turnstile> T <: S` by auto
next
case (T_AppPredFalse \<Gamma>' e1 U F1 T0 T1 S e2 T F2 x T')
have A:"x \<sharp> e1" "x \<sharp> e2" using T_AppPredFalse by auto
hence "\<Gamma>' - (x,T') \<turnstile> e1 : U ; F1" using T_AppPredFalse by auto
also have "\<Gamma>' - (x,T') \<turnstile> e2 : T ; F2" using T_AppPredFalse A by auto
ultimately show ?case using `~ (\<turnstile> T <: S)` `\<turnstile> T <: T0` `e2 : values` `closed e2` T_AppPredFalse(3) by auto
next
case (T_If \<Gamma>' e1 T1 F1 e2 T2 F2 e3 T3 F3 T x)
have A:"x \<sharp> e1" "x \<sharp> e2" "x \<sharp> e3" using T_If by auto
have "\<Gamma>' - (x,T') \<turnstile> e1 : T1 ; F1" using T_If A by auto
thus ?case using T_If
proof (nominal_induct "F1" rule: eff.induct)
case NE
from NE have 1:"\<Gamma>' - (x, T') \<turnstile> e1 : T1 ; eff.NE" by auto
from NE have 2:"(\<Gamma>' - (x, T') |+ eff.NE) \<turnstile> e2 : T2 ; F2" by auto
from NE have 3:"(\<Gamma>' - (x, T') |- eff.NE) \<turnstile> e3 : T3 ; F3" by auto
from 1 2 3 show ?case using `\<turnstile> T2 <: T` `\<turnstile> T3 <: T` ..
next
case TT
from TT have 1:"\<Gamma>' - (x, T') \<turnstile> e1 : T1 ; eff.TT" by auto
from TT have 2:"(\<Gamma>' - (x, T') |+ eff.TT) \<turnstile> e2 : T2 ; F2" by auto
from 1 2 show ?case using `\<turnstile> T2 <: T` by auto
next
case FF
from FF have 1:"\<Gamma>' - (x, T') \<turnstile> e1 : T1 ; eff.FF" by auto
from FF have 3:"(\<Gamma>' - (x, T') |+ eff.FF) \<turnstile> e3 : T3 ; F3" by auto
from 1 3 show ?case using `\<turnstile> T3 <: T` by auto
next
case (VE z)
from VE have 1:"\<Gamma>' - (x, T') \<turnstile> e1 : T1 ; VE z" by auto
have val1:"valid (\<Gamma>' |+ VE z)" using VE envplus_valid[of \<Gamma>' "VE z"] by auto
have val2:"valid (\<Gamma>' |- VE z)" using VE envminus_valid[of \<Gamma>' "VE z"] by auto
have "valid (\<Gamma>' |- VE z)" using VE envminus_valid[of \<Gamma>' "VE z"] by auto
have A0:"!!T0 . (\<Gamma>' |- VE z) - (x, T0) \<turnstile> e3 : T3 ; F3" using VE(7) A `valid (\<Gamma>' |- VE z)` by auto
have A:"!!T0 . (\<Gamma>' |+ VE z) - (x, T0) \<turnstile> e2 : T2 ; F2" using VE(5) A `valid (\<Gamma>' |+ VE z)` by auto
let ?op = "replace"
let ?mapfun = "(% (v,ty). (if (x = v) then (v,?op ty.FF ty) else (v,ty)))"
have B:"!! p. set ((\<Gamma>' |+ VE z) - p) = ((mapfun remove ty.FF z) ` (set \<Gamma>')) - {p}"
using envplus_set_ve set_remove_comm[of "(\<Gamma>' |+ VE z)"] by auto
have image_lem:"!! f S v. (f ` S) - {(f v)} <= (f ` (S - {v}))" by auto
note image_lem[of "mapfun remove ty.FF z" "set \<Gamma>'" "(x,T0)"]
have eq1:"!! p. mapfun remove ty.FF z ` set \<Gamma>' - {mapfun remove ty.FF z p} = set ((\<Gamma>' |+ VE z) - (mapfun remove ty.FF z p))" using envplus_set_ve set_remove_comm[of "(\<Gamma>' |+ VE z)"] by auto
have eq2:"!! p. mapfun remove ty.FF z ` (set \<Gamma>' - {p}) = set (\<Gamma>' - p |+ VE z)"
proof -
fix p
show "mapfun remove ty.FF z ` (set \<Gamma>' - {p}) = set (\<Gamma>' - p |+ VE z)"
using envplus_set_ve[of _ "\<Gamma>' - p"] set_remove_comm[of \<Gamma>'] by auto
qed
have eq3:"!! x T0. mapfun remove ty.FF z (x,T0) = (x, (if (x = z) then (remove ty.FF T0) else (T0)))" by auto
let ?removeT' = "(if (x = z) then (remove ty.FF T') else (T'))"
have goal:"((\<Gamma>' |+ VE z) - (x,?removeT')) \<lless> ((\<Gamma>' - (x,T')) |+ VE z)"
proof -
have " mapfun remove ty.FF z ` set \<Gamma>' - {mapfun remove ty.FF z (x,T')} <=
mapfun remove ty.FF z ` (set \<Gamma>' - {(x,T')})" using image_lem[of "mapfun remove ty.FF z" "set \<Gamma>'" "(x,T')"] by auto
hence " mapfun remove ty.FF z ` set \<Gamma>' - {mapfun remove ty.FF z (x,T')} <=
set ((\<Gamma>' - ((x,T'))) |+ VE z)" using eq2[of " (x, T')"] by auto
hence "set ((\<Gamma>' |+ VE z) - (mapfun remove ty.FF z (x,T'))) <=
set ((\<Gamma>' - ((x,T'))) |+ VE z)"
using eq1[of "(x,T')"] by auto
hence "set ((\<Gamma>' |+ VE z) - (x,?removeT')) <= set ((\<Gamma>' - (x,T')) |+ VE z)" using eq3 by auto
thus ?thesis by auto
qed
have val3:"valid ((\<Gamma>' |+ VE z) - (x,?removeT'))" using val1 valid_remove by auto
have "valid ((\<Gamma>' - (x, T')))" using `valid \<Gamma>'` valid_remove envplus_valid by auto
hence val4:"valid ((\<Gamma>' - (x, T')) |+ VE z)" using envplus_valid[of "\<Gamma>' - (x, T')" "VE z"] by auto
from A have "(\<Gamma>' |+ VE z) - (x,?removeT') \<turnstile> e2 : T2 ; F2" by auto
hence 2:"(\<Gamma>' - (x, T')) |+ VE z \<turnstile> e2 : T2 ; F2" using goal val3 val4
weakening[of "(\<Gamma>' |+ VE z) - (x,?removeT')" e2 T2 F2 "\<Gamma>' - (x,T') |+ VE z"] by auto
have eq4:"!! p. mapfun replace ty.FF z ` set \<Gamma>' - {mapfun replace ty.FF z p} = set ((\<Gamma>' |- VE z) - (mapfun replace ty.FF z p))" using envminus_set_ve[of _ \<Gamma>'] set_remove_comm[of "(\<Gamma>' |- VE z)"] by auto
have eq5:"!! p. mapfun replace ty.FF z ` (set \<Gamma>' - {p}) = set (\<Gamma>' - p |- VE z)"
proof -
fix p
show "mapfun replace ty.FF z ` (set \<Gamma>' - {p}) = set (\<Gamma>' - p |- VE z)"
using envminus_set_ve[of _ "\<Gamma>' - p" ] set_remove_comm[of \<Gamma>'] by auto
qed
have eq6:"!! x T0. mapfun replace ty.FF z (x,T0) = (x, (if (x = z) then (replace ty.FF T0) else (T0)))" by auto
let ?replaceT' = "(if (x = z) then (replace ty.FF T') else (T'))"
have goal':"((\<Gamma>' |- VE z) - (x,?replaceT')) \<lless> ((\<Gamma>' - (x,T')) |- VE z)"
proof -
have " mapfun replace ty.FF z ` set \<Gamma>' - {mapfun replace ty.FF z (x,T')} <=
mapfun replace ty.FF z ` (set \<Gamma>' - {(x,T')})" using image_lem[of "mapfun replace ty.FF z" "set \<Gamma>'" "(x,T')"] by auto
hence " mapfun replace ty.FF z ` set \<Gamma>' - {mapfun replace ty.FF z (x,T')} <=
set ((\<Gamma>' - ((x,T'))) |- VE z)" using eq5[of " (x, T')"] by auto
hence "set ((\<Gamma>' |- VE z) - (mapfun replace ty.FF z (x,T'))) <=
set ((\<Gamma>' - ((x,T'))) |- VE z)"
using eq4[of "(x,T')"] by auto
hence "set ((\<Gamma>' |- VE z) - (x,?replaceT')) <= set ((\<Gamma>' - (x,T')) |- VE z)" using eq6 by auto
thus ?thesis by auto
qed
have val5:"valid ((\<Gamma>' |- VE z) - (x,?replaceT'))" using val2 valid_remove by auto
have "valid ((\<Gamma>' - (x, T')))" using `valid \<Gamma>'` valid_remove envminus_valid by auto
hence val6:"valid ((\<Gamma>' - (x, T')) |- VE z)" using envminus_valid[of "\<Gamma>' - (x, T')" "VE z"] by auto
from A0 have "(\<Gamma>' |- VE z) - (x,?replaceT') \<turnstile> e3 : T3 ; F3" by auto
hence 3:"(\<Gamma>' - (x, T')) |- VE z \<turnstile> e3 : T3 ; F3" using goal' val5 val6
weakening[of "(\<Gamma>' |- VE z) - (x,?replaceT')" e3 T3 F3 "\<Gamma>' - (x,T') |- VE z"] by auto
from 1 2 3 show ?case using `\<turnstile> T2 <: T` `\<turnstile> T3 <: T` ..
next
case (TE U z)
from TE have 1:"\<Gamma>' - (x, T') \<turnstile> e1 : T1 ; TE U z" by auto
have val1:"valid (\<Gamma>' |+ TE U z)" using TE envplus_valid[of \<Gamma>' "TE U z"] by auto
have val2:"valid (\<Gamma>' |- TE U z)" using TE envminus_valid[of \<Gamma>' "TE U z"] by auto
have "valid (\<Gamma>' |- TE U z)" using TE envminus_valid[of \<Gamma>' "TE U z"] by auto
have A0:"!!T0 . (\<Gamma>' |- TE U z) - (x, T0) \<turnstile> e3 : T3 ; F3" using TE(7) A `valid (\<Gamma>' |- TE U z)` by auto
have A:"!!T0 . (\<Gamma>' |+ TE U z) - (x, T0) \<turnstile> e2 : T2 ; F2" using TE(5) A `valid (\<Gamma>' |+ TE U z)` by auto
let ?op = "remove"
let ?mapfun = "(% (v,ty). (if (x = v) then (v,?op S ty) else (v,ty)))"
have B:"!! p. set ((\<Gamma>' |+ TE U z) - p) = ((mapfun restrict U z) ` (set \<Gamma>')) - {p}"
using envplus_set set_remove_comm[of "(\<Gamma>' |+ TE U z)"] by auto
have image_lem:"!! f S v. (f ` S) - {(f v)} <= (f ` (S - {v}))" by auto
note image_lem[of "mapfun restrict U z" "set \<Gamma>'" "(x,T0)"]
have eq1:"!! p. mapfun restrict U z ` set \<Gamma>' - {mapfun restrict U z p} = set ((\<Gamma>' |+ TE U z) - (mapfun restrict U z p))" using envplus_set set_remove_comm[of "(\<Gamma>' |+ TE U z)"] by auto
have eq2:"!! p. mapfun restrict U z ` (set \<Gamma>' - {p}) = set (\<Gamma>' - p |+ TE U z)"
proof -
fix p
show "mapfun restrict U z ` (set \<Gamma>' - {p}) = set (\<Gamma>' - p |+ TE U z)"
using envplus_set[of _ _ "\<Gamma>' - p"] set_remove_comm[of \<Gamma>'] by auto
qed
have eq3:"!! x T0. mapfun restrict U z (x,T0) = (x, (if (x = z) then (restrict U T0) else (T0)))" by auto
let ?restrictT' = "(if (x = z) then (restrict U T') else (T'))"
have goal:"((\<Gamma>' |+ TE U z) - (x,?restrictT')) \<lless> ((\<Gamma>' - (x,T')) |+ TE U z)"
proof -
have " mapfun restrict U z ` set \<Gamma>' - {mapfun restrict U z (x,T')} <=
mapfun restrict U z ` (set \<Gamma>' - {(x,T')})" using image_lem[of "mapfun restrict U z" "set \<Gamma>'" "(x,T')"] by auto
hence " mapfun restrict U z ` set \<Gamma>' - {mapfun restrict U z (x,T')} <=
set ((\<Gamma>' - ((x,T'))) |+ TE U z)" using eq2[of " (x, T')"] by auto
hence "set ((\<Gamma>' |+ TE U z) - (mapfun restrict U z (x,T'))) <=
set ((\<Gamma>' - ((x,T'))) |+ TE U z)"
using eq1[of "(x,T')"] by auto
hence "set ((\<Gamma>' |+ TE U z) - (x,?restrictT')) <= set ((\<Gamma>' - (x,T')) |+ TE U z)" using eq3 by auto
thus ?thesis by auto
qed
have val3:"valid ((\<Gamma>' |+ TE U z) - (x,?restrictT'))" using val1 valid_remove by auto
have "valid ((\<Gamma>' - (x, T')))" using `valid \<Gamma>'` valid_remove envplus_valid by auto
hence val4:"valid ((\<Gamma>' - (x, T')) |+ TE U z)" using envplus_valid[of "\<Gamma>' - (x, T')" "TE U z"] by auto
from A have "(\<Gamma>' |+ TE U z) - (x,?restrictT') \<turnstile> e2 : T2 ; F2" by auto
hence 2:"(\<Gamma>' - (x, T')) |+ TE U z \<turnstile> e2 : T2 ; F2" using goal val3 val4
weakening[of "(\<Gamma>' |+ TE U z) - (x,?restrictT')" e2 T2 F2 "\<Gamma>' - (x,T') |+ TE U z"] by auto
have eq4:"!! p. mapfun remove U z ` set \<Gamma>' - {mapfun remove U z p} = set ((\<Gamma>' |- TE U z) - (mapfun remove U z p))" using envminus_set[of _ _ \<Gamma>'] set_remove_comm[of "(\<Gamma>' |- TE U z)"] by auto
have eq5:"!! p. mapfun remove U z ` (set \<Gamma>' - {p}) = set (\<Gamma>' - p |- TE U z)"
proof -
fix p
show "mapfun remove U z ` (set \<Gamma>' - {p}) = set (\<Gamma>' - p |- TE U z)"
using envminus_set[of _ _ "\<Gamma>' - p" ] set_remove_comm[of \<Gamma>'] by auto
qed
have eq6:"!! x T0. mapfun remove U z (x,T0) = (x, (if (x = z) then (remove U T0) else (T0)))" by auto
let ?removeT' = "(if (x = z) then (remove U T') else (T'))"
have goal':"((\<Gamma>' |- TE U z) - (x,?removeT')) \<lless> ((\<Gamma>' - (x,T')) |- TE U z)"
proof -
have " mapfun remove U z ` set \<Gamma>' - {mapfun remove U z (x,T')} <=
mapfun remove U z ` (set \<Gamma>' - {(x,T')})" using image_lem[of "mapfun remove U z" "set \<Gamma>'" "(x,T')"] by auto
hence " mapfun remove U z ` set \<Gamma>' - {mapfun remove U z (x,T')} <=
set ((\<Gamma>' - ((x,T'))) |- TE U z)" using eq5[of " (x, T')"] by auto
hence "set ((\<Gamma>' |- TE U z) - (mapfun remove U z (x,T'))) <=
set ((\<Gamma>' - ((x,T'))) |- TE U z)"
using eq4[of "(x,T')"] by auto
hence "set ((\<Gamma>' |- TE U z) - (x,?removeT')) <= set ((\<Gamma>' - (x,T')) |- TE U z)" using eq6 by auto
thus ?thesis by auto
qed
have val5:"valid ((\<Gamma>' |- TE U z) - (x,?removeT'))" using val2 valid_remove by auto
have "valid ((\<Gamma>' - (x, T')))" using `valid \<Gamma>'` valid_remove envminus_valid by auto
hence val6:"valid ((\<Gamma>' - (x, T')) |- TE U z)" using envminus_valid[of "\<Gamma>' - (x, T')" "TE U z"] by auto
from A0 have "(\<Gamma>' |- TE U z) - (x,?removeT') \<turnstile> e3 : T3 ; F3" by auto
hence 3:"(\<Gamma>' - (x, T')) |- TE U z \<turnstile> e3 : T3 ; F3" using goal' val5 val6
weakening[of "(\<Gamma>' |- TE U z) - (x,?removeT')" e3 T3 F3 "\<Gamma>' - (x,T') |- TE U z"] by auto
from 1 2 3 show ?case using `\<turnstile> T2 <: T` `\<turnstile> T3 <: T` ..
qed
qed
lemma fresh_weakening_cons:
assumes "valid ((a,S)#\<Gamma>)" (is "valid ?\<Gamma>") and "(a,S)# \<Gamma> \<turnstile> e : T ; F" and "a \<sharp> e"
shows "\<Gamma> \<turnstile> e : T ; F"
proof -
have v1:"valid \<Gamma>" using prems valid_elim by blast
hence v2:"valid (\<Gamma> - (a,S))" using valid_remove by auto
have A:"?\<Gamma> - (a,S) \<turnstile> e : T ; F" using prems fresh_weakening[of a e ?\<Gamma> T F S] by auto
have "?\<Gamma> - (a,S) = \<Gamma> - (a,S)" by auto
hence B:"\<Gamma> - (a,S) \<lless> \<Gamma>" by (induct \<Gamma>) auto
thus ?thesis using A weakening[of _ e T F \<Gamma>] v1 v2 by auto
qed
lemma closed_empty_env:
assumes "closed e" and "\<Gamma> \<turnstile> e : T ; F" and "valid \<Gamma>"
shows "[] \<turnstile> e : T ; F"
using `valid \<Gamma>` prems
proof (induct \<Gamma> rule: valid.induct)
case v1 thus ?case by simp
next
case (v2 \<Gamma>' a S)
have "a \<sharp> e" using `closed e` closed_def fresh_def[of a e] by auto
thus ?case using v2 fresh_weakening_cons by auto
qed
lemma closed_any_env:
assumes "closed e" and "\<Gamma> \<turnstile> e : T ; F" and val1:"valid \<Gamma>" and val2:"valid \<Gamma>'"
shows "\<Gamma>' \<turnstile> e : T ; F"
using prems closed_empty_env weakening
proof -
have A:"[] \<turnstile> e : T ; F" using prems closed_empty_env by auto
note weakening
have B:"[] \<lless> \<Gamma>'" by auto
from A B val1 val2 have "\<Gamma>' \<turnstile> e : T ; F" using weakening by blast
thus ?thesis by simp
qed
inductive_cases ve_ty_elim: "\<Gamma> \<turnstile> e : T ; VE x"
lemma te_ty_elim:
"\<Gamma> \<turnstile> t1 : T ; TE U z \<Longrightarrow>
EX f A A1 Fn S B. t1 = (App f (Var z)) \<and> \<Gamma> \<turnstile> f : B ; Fn \<and> \<turnstile> B <: A1 \<rightarrow> T : Latent U \<and>
\<Gamma> \<turnstile> (Var z) : A ; VE z \<and> \<turnstile> A <: A1 "
proof (ind_cases "\<Gamma> \<turnstile> t1 : T ; TE U z")
fix e1 T0 eff1 e2 Ta x S B
assume "t1 = App e1 e2" "TE U z = TE S x"
"\<Gamma> \<turnstile> e1 : B ; eff1 "" \<Gamma> \<turnstile> e2 : Ta ; VE x " "\<turnstile> B <: T0 \<rightarrow> T : Latent S"
"\<turnstile> Ta <: T0"
from prems have A:"e2 = Var x" using ve_ty_elim[of \<Gamma> e2 Ta x] eff.inject by auto
hence B:"t1 = App e1 (Var z)" using prems trm.inject eff.inject by auto
have C:" \<Gamma> \<turnstile> (Var z) : Ta ; VE z" using prems A trm.inject eff.inject by auto
have D:" \<Gamma> \<turnstile> e1 : B ; eff1" using ty.inject latent_eff.inject prems eff.inject by auto
have E:"\<turnstile> B <: T0 \<rightarrow> T : Latent U" using ty.inject latent_eff.inject prems eff.inject by auto
from `\<turnstile> Ta <: T0` B C D E show ?thesis by blast
qed
lemma unique_var_typing:
assumes "(x,T)#\<Gamma> \<turnstile> Var x : T; VE x" and "(x,T)#\<Gamma> \<turnstile> Var x : T' ; VE x"
shows "T = T'"
proof (rule ccontr)
assume "T ~= T'"
have "(x,T) : set ((x,T)#\<Gamma>)" using var_ty_elim[of _ x T "VE x"] prems by auto
have "(x,T') : set ((x,T)#\<Gamma>)" "valid ((x,T)#\<Gamma>)" using var_ty_elim[of "((x,T)#\<Gamma>)" x T' "VE x"] prems by auto
hence A:"(x,T') : set \<Gamma>" "valid \<Gamma>" "x \<sharp> \<Gamma>" using prems valid_elim[of x T \<Gamma>] by auto
have "x : supp \<Gamma>" using `valid \<Gamma>` A
proof (induct \<Gamma> rule: valid.induct)
case v1 thus ?case by auto
next
case (v2 \<Gamma>' a S)
hence "x \<sharp> (a,S)" "x \<sharp> \<Gamma>'" using fresh_list_cons by auto
hence "x \<sharp> a" by auto
hence "x ~= a" using fresh_atm by auto
hence "(x,T') : set \<Gamma>'" using v2 by auto
have "valid \<Gamma>'" using v2 valid_elim[of a S \<Gamma>'] by auto
hence "x : supp \<Gamma>'" using v2 `(x,T') : set \<Gamma>'` `x \<sharp> \<Gamma>'` by auto
hence "x : supp (a,S) \<union> supp \<Gamma>'" by auto
hence "x : (supp ((a,S)#\<Gamma>') :: name set)" using supp_list_cons[of "(a,S)" \<Gamma>'] by force
thus ?case by simp
qed
hence "~ (x \<sharp> \<Gamma>)" using fresh_def[of x \<Gamma>] by blast
thus False using `x \<sharp> \<Gamma>` by auto
qed
inductive_cases tt_sub_ff:"\<turnstile> ty.TT <: ty.FF"
inductive_cases ff_sub_tt:"\<turnstile> ty.FF <: ty.TT"
lemma value_effect_tt_or_ff:
assumes "v : values" and "\<Gamma> \<turnstile> v : T ; F"
shows "F = FF \<and> v = Bool False \<or> F = TT \<and> v ~= Bool False"
using prems
proof (nominal_induct v avoiding: \<Gamma> rule: values.strong_induct)
case num_value thus ?case using num_ty_elim by auto
next
case bi_value thus ?case using bi_ty_elim by auto
next
case abs_value thus ?case using abs_ty_elim[of \<Gamma> _ _ _ T F] by auto
next
case (bool_value b)
thus ?case using true_ty_elim false_ty_elim by (cases b) auto
qed
lemma remove_fresh_env:
assumes A:"y \<sharp> \<Gamma>" and B:"valid \<Gamma>"
shows "\<Gamma> - (y,T) = \<Gamma>"
using B A
proof (induct \<Gamma> rule: valid.induct)
case v1 thus ?case by auto
next
case (v2 \<Gamma>' a S)
have "y \<noteq> a" "y \<sharp> \<Gamma>'" using `y \<sharp> ((a, S) # \<Gamma>')` using fresh_atm[of y a] fresh_list_cons by auto
hence "((a, S) # \<Gamma>') - (y, T) = (a, S) # (\<Gamma>' - (y, T))" by auto
thus ?case using v2 `y \<sharp> \<Gamma>'` by auto
qed
lemma subst_preserve_TE_app:
assumes tapp:"(y,T0)#\<Gamma> \<turnstile> App e1 e2 : T ; TE S x"
and neq:"y \<noteq> x"
and val:"valid ((y,T0)#\<Gamma>)"
and ih: "!! t bc bf . \<lbrakk>t \<guillemotleft> App e1 e2; (y, T0) # \<Gamma> \<turnstile> t : bc ; bf \<rbrakk>
\<Longrightarrow> \<exists>T' F'. \<Gamma> \<turnstile> t[y::=v] : T' ; F' \<and> \<turnstile> T' <: bc \<and> \<turnstile> F' <e: bf"
shows "\<Gamma> \<turnstile> (App e1 e2)[y::=v] : T ; TE S x"
proof -
note te_ty_elim[OF tapp]
then obtain f A A1 Fn Sa B
where sz:"App e1 e2 = App f (Var x)"
and tf:"(y, T0) # \<Gamma> \<turnstile> f : B ; Fn "" \<turnstile> B <: A1 \<rightarrow> T : Latent S"
and tvx:"(y, T0) # \<Gamma> \<turnstile> Var x : A ; VE x" and sub:" \<turnstile> A <: A1"
by auto
hence "e1 = f" and "e2 = Var x" using trm.inject by auto
hence "e2[y::=v] = Var x" using `y \<noteq> x` forget by auto
hence tsub:" (y, T0)#\<Gamma> \<turnstile> e2[y::=v] : A ; VE x" using `e2=Var x` tvx by auto
have fr:"y \<sharp> e2[y::=v]" using `e2 = Var x``e2[y::=v] = Var x` `y \<noteq> x` using fresh_atm by auto
have "y \<sharp> \<Gamma>" "valid \<Gamma>" using valid_elim[OF val] by auto
hence "((y, T0) # \<Gamma>) - (y, T0) = \<Gamma>" using remove_fresh_env[OF `y \<sharp> \<Gamma>` `valid \<Gamma>`] by auto
hence te2:"\<Gamma> \<turnstile> e2[y::=v] : A ; VE x" using fresh_weakening[OF fr tsub `valid ((y,T0)#\<Gamma>)`, of T0] by auto
have szf:"f \<guillemotleft> App e1 e2" using sz by auto
note ih[OF szf tf(1)]
then obtain T' F' where tfsub:"\<Gamma> \<turnstile> f[y::=v] : T' ; F' "" \<turnstile> T' <: B " "\<turnstile> F' <e: Fn" by auto
hence " \<turnstile> T' <: A1 \<rightarrow> T : Latent S " using `\<turnstile> B <: A1 \<rightarrow> T : Latent S` by auto
hence "\<Gamma> \<turnstile> (App f e2)[y::=v] : T ; TE S x" using te2 tfsub `\<turnstile> A <: A1` by auto
thus ?thesis using sz using trm.inject by auto
qed
inductive_cases te_elim_auto: "\<Gamma> \<turnstile> e : T ; TE S x"
thm te_elim_auto
lemma subst_preserve_TE:
fixes v
assumes tapp:"(y,T0)#\<Gamma> \<turnstile> e : T ; TE S x"
and neq:"y \<noteq> x"
and val:"valid ((y,T0)#\<Gamma>)"
and ih: "!! t bc bf . \<lbrakk>t \<guillemotleft> e; (y, T0) # \<Gamma> \<turnstile> t : bc ; bf \<rbrakk>
\<Longrightarrow> \<exists>T' F'. \<Gamma> \<turnstile> t[y::=v] : T' ; F' \<and> \<turnstile> T' <: bc \<and> \<turnstile> F' <e: bf"
shows "\<Gamma> \<turnstile> e[y::=v] : T ; TE S x"
proof -
obtain e1 e2 where "e = App e1 e2" using te_elim_auto[OF tapp, of thesis] by auto
hence A:"(y,T0)#\<Gamma> \<turnstile> App e1 e2 : T ; TE S x" using tapp by auto
note subst_preserve_TE_app[OF A neq val , of v]
have "!! t bc bf . \<lbrakk>t \<guillemotleft> App e1 e2; (y, T0) # \<Gamma> \<turnstile> t : bc ; bf \<rbrakk>
\<Longrightarrow> \<exists>T' F'. \<Gamma> \<turnstile> t[y::=v] : T' ; F' \<and> \<turnstile> T' <: bc \<and> \<turnstile> F' <e: bf" using ih `e = App e1 e2` by auto
hence "\<Gamma> \<turnstile> App e1 e2[y::=v] : T ; TE S x" using subst_preserve_TE_app[OF A neq val , of v] by auto
thus ?thesis using `e = App e1 e2` by auto
qed
inductive_cases lam_latent_eff_elim_auto: "\<Gamma> \<turnstile> Lam[x:T].b : S1 \<rightarrow> S2 : Latent U ; F"
thm lam_latent_eff_elim_auto
lemma preserve_subst:
assumes "(x,T0)#\<Gamma> \<turnstile> e : T ; F" and "\<Gamma> \<turnstile> e' : T1 ; G" and "\<turnstile> T1 <: T0" and "valid ((x,T0)#\<Gamma>)"
and "closed e'" and "e' : values"
shows "EX T' F'. \<Gamma> \<turnstile> e[x::=e'] : T' ; F' \<and> \<turnstile> T' <: T \<and> \<turnstile> F' <e: F"
using prems
proof (nominal_induct e avoiding: \<Gamma> x e' T T1 T0 F G rule: trm_comp_induct)
case (Var v)
have a1: "\<Gamma> \<turnstile>e':T1;G" by fact
have a2: "((x,T0)#\<Gamma>) \<turnstile> Var v:T;F" by fact
hence a21: "(v,T)\<in>set((x,T0)#\<Gamma>)" and a22: "valid((x,T0)#\<Gamma>)" and a22b:"F = VE v"
using var_ty_elim[of "(x, T0) # \<Gamma>"] by auto
from a22 have a23: "valid \<Gamma>" and a24: "x\<sharp>\<Gamma>" by (auto dest: valid_elim)
from a24 have a25: "\<not>(\<exists>\<tau>. (x,\<tau>)\<in>set \<Gamma>)" by (rule fresh_context)
show ?case
proof (cases "v=x")
assume case1: "v=x"
hence "(Var v)[x::=e'] = e'" by simp
hence A:"\<Gamma> \<turnstile> (Var v)[x::=e'] : T1; G" using Var by auto
have "simple_eff G" using closed_eff `closed e'` prems by auto
hence C:"\<turnstile> G <e: F" using a22b simple_eff_below_ve by auto
have B:"T = T0"
proof (rule ccontr)
assume a3:"T ~= T0"
from a3 a21 have "(v,T)\<in>set \<Gamma>" by force
with case1 a25 show False by force
qed
hence D:"\<turnstile> T1 <: T" using `\<turnstile> T1 <: T0` by auto
have "~ (\<exists>S y. F = TE S y)" using a22b by auto
thus ?thesis using A a22b C D by blast
next
assume case2: "v\<noteq>x"
with a21 have a26: "(v,T)\<in>set \<Gamma>" by force
have a27:" Var v[x::=e'] = Var v" using case2 by simp
from a23 a26 a27 have "\<Gamma> \<turnstile> Var v:T;VE v" by force
thus ?thesis using a27 a22b by auto
qed
next
case (Num n)
have A:"(Num n)[x::=e'] = Num n" by auto
have B:"F = eff.TT" using Num num_ty_elim by auto
have "T = ty.Int" using num_ty_elim Num by auto
hence "\<Gamma> \<turnstile> (Num n)[x::=e'] : T ; eff.TT" using Num A valid_elim[of x T0 \<Gamma>] by auto
thus ?case using Num B by auto
next
case (Bool b)
have v:"valid \<Gamma>" using prems typing_valid by auto
have A:"(Bool b)[x::=e'] = Bool b" by auto
thus ?case
proof (cases b)
case True
hence B:"T = ty.TT" and "F = TT" using Bool true_ty_elim by auto
thus ?thesis using A v True by auto
next
case False
hence B:"T = ty.FF" and "F = FF" using Bool false_ty_elim by auto
thus ?thesis using A v False by auto
qed
next
case (BI b)
have A:"(BI b)[x::=e'] = (BI b)" by auto
have B:"F = eff.TT" using BI bi_ty_elim by auto
have "T = \<Delta>\<^isub>\<tau> b" using bi_ty_elim BI by auto
hence "\<Gamma> \<turnstile> (BI b)[x::=e'] : T ; eff.TT" using BI A valid_elim[of x T0 \<Gamma>] by auto
thus ?case using BI B by auto
next
case (App s1 s2 \<Gamma>' x' e'' T' T1' T0' F' G')
have ih_s1: "\<And>c \<sigma> T F T' F' e' \<Gamma>. ((c,\<sigma>)#\<Gamma>) \<turnstile> s1:T; F \<Longrightarrow> closed e' \<Longrightarrow> e' : values \<Longrightarrow> valid ((c,\<sigma>)#\<Gamma>) \<Longrightarrow> \<Gamma>\<turnstile> e': T' ; F' \<Longrightarrow> \<turnstile> T' <: \<sigma> \<Longrightarrow> EX S G. \<Gamma> \<turnstile> s1[c::=e']:S ; G \<and> \<turnstile> S <: T \<and> \<turnstile> G <e: F" .
have ih_s2: "\<And>c \<sigma> T F T' F' e' \<Gamma>. ((c,\<sigma>)#\<Gamma>) \<turnstile> s2:T; F \<Longrightarrow> closed e' \<Longrightarrow> e' : values \<Longrightarrow> valid ((c,\<sigma>)#\<Gamma>) \<Longrightarrow> \<Gamma>\<turnstile> e': T' ; F' \<Longrightarrow> \<turnstile> T' <: \<sigma> \<Longrightarrow> EX S G. \<Gamma> \<turnstile> s2[c::=e']:S ; G \<and> \<turnstile> S <: T \<and> \<turnstile> G <e: F" .
have appty:"((x',T0')#\<Gamma>')\<turnstile>App s1 s2 : T'; F'" .
from appty have
elim1:"\<exists>T0 T0'a T1 le eff' eff'' U.(x',T0')#\<Gamma>' \<turnstile> s1 :U;eff' \<and> (x',T0')# \<Gamma>'\<turnstile> s2 : T0'a;eff'' \<and> \<turnstile> U <: T0\<rightarrow>T1:le \<and> \<turnstile> T0'a <: T0 \<and> T1 = T'"
using app_ty_elim by auto
from appty
have elim2:"(x', T0') # \<Gamma>' \<turnstile> App s1 s2 : T' ; FF \<Longrightarrow> \<exists>T0 T0'a leS eff' eff'' le U.(x',T0')#\<Gamma>' \<turnstile> s1 :U;eff' \<and>
(x',T0')# \<Gamma>'\<turnstile> s2 : T0'a;eff'' \<and> \<turnstile> T0'a <: T0\<and> \<turnstile> U <: T0\<rightarrow>T':le \<and> le = Latent leS \<and> ~ (\<turnstile> T0'a <: leS) \<and> s2 : values \<and> closed s2"
using app_ty_ff_elim[of "((x',T0')#\<Gamma>')" s1 s2 T'] by blast
have elim3:"(x', T0') # \<Gamma>' \<turnstile> App s1 s2 : T' ; TT \<Longrightarrow> \<exists>T0 T0'a leS eff' eff'' U le.(x',T0')#\<Gamma>' \<turnstile> s1 :U;eff' \<and>
(x',T0')# \<Gamma>'\<turnstile> s2 : T0'a;eff'' \<and> \<turnstile> T0'a <: T0 \<and> \<turnstile> U <: T0\<rightarrow>T':le \<and> le = Latent leS \<and> \<turnstile> T0'a <: leS "
using app_ty_tt_elim[of "((x',T0')#\<Gamma>')" s1 s2 T'] by blast
from elim1 obtain T0 T0'a T1 le eff' eff'' U where
P:"(x',T0')#\<Gamma>' \<turnstile> s1 :U;eff'"" (x',T0')# \<Gamma>'\<turnstile> s2 : T0'a;eff''"" \<turnstile> T0'a <: T0 "" T1 = T'" "\<turnstile> U <: T0\<rightarrow>T1:le" by auto
hence "EX S1 G1. \<Gamma>' \<turnstile> s1[x'::=e''] : S1 ; G1 \<and> \<turnstile> S1 <: U \<and> \<turnstile> G1 <e: eff'"
using ih_s1 App by auto
then obtain S1 G1 where Q:" \<Gamma>' \<turnstile> s1[x'::=e''] : S1 ; G1 "" \<turnstile> S1 <: U" "\<turnstile> G1 <e: eff'" by auto
have sub1:"\<turnstile>S1 <: T0\<rightarrow>T1:le" using P Q by auto
(* then apply ih_s2, get something about the substition of s2, and put it all back together. *)
from P have "EX S G. \<Gamma>' \<turnstile> s2[x'::=e'']:S ; G \<and> \<turnstile> S <: T0'a \<and> \<turnstile> G <e: eff''"
using ih_s2[of x' T0' \<Gamma>' T0'a eff''] App by auto
then obtain S2 G2 where S:"\<Gamma>' \<turnstile> s2[x'::=e'']:S2 ; G2 "" \<turnstile> S2 <: T0'a" "\<turnstile> G2 <e: eff''" by auto
let ?ns1 = "s1[x'::=e'']" and ?ns2 = "s2[x'::=e'']"
have sub2:"\<turnstile> S2 <: T0" using P S by auto
have L1:"\<Gamma>' \<turnstile> App ?ns1 ?ns2 : T1 ; NE" using Q S sub1 sub2 by auto
have L2:"T1 = T'" .
show ?case using appty
proof (nominal_induct F' rule: eff.induct)
case NE thus ?case using L1 L2 by auto
next
case VE thus ?case using L1 L2 by auto
next
case (TE ty var) thus ?case using L1 L2 by auto
next
case TT
from elim3 TT obtain T0 T0'a T1 le leS eff' eff'' U where
P:"(x',T0')#\<Gamma>' \<turnstile> s1 :U;eff'"" (x',T0')# \<Gamma>'\<turnstile> s2 : T0'a;eff''"" \<turnstile> T0'a <: T0 "" T1 = T'" "\<turnstile> U <: T0\<rightarrow>T1:le"
"le = Latent leS" "\<turnstile> T0'a <: leS" by auto
hence "EX S1 G1. \<Gamma>' \<turnstile> s1[x'::=e''] : S1 ; G1 \<and> \<turnstile> S1 <: U \<and> \<turnstile> G1 <e: eff'"
using ih_s1 App by blast
then obtain S1 G1 where Q:" \<Gamma>' \<turnstile> s1[x'::=e''] : S1 ; G1 "" \<turnstile> S1 <: U" "\<turnstile> G1 <e: eff'" by auto
hence R:"\<turnstile> S1 <: T0\<rightarrow>T1:le" using P by auto
(* then apply ih_s2, get something about the substition of s2, and put it all back together. *)
from P have "EX S G. \<Gamma>' \<turnstile> s2[x'::=e'']:S ; G \<and> \<turnstile> S <: T0'a \<and> \<turnstile> G <e: eff''"
using ih_s2[of x' T0' \<Gamma>' T0'a eff''] App by auto
then obtain S2 G2 where S:"\<Gamma>' \<turnstile> s2[x'::=e'']:S2 ; G2 "" \<turnstile> S2 <: T0'a" "\<turnstile> G2 <e: eff''" by auto
let ?ns1 = "s1[x'::=e'']" and ?ns2 = "s2[x'::=e'']"
have noover: "\<turnstile> S2 <: leS" using `\<turnstile> S2 <: T0'a` `\<turnstile> T0'a <: leS` by auto
have L1:"\<Gamma>' \<turnstile> App ?ns1 ?ns2 : T1 ; TT" using P Q R S noover T_AppPredFalse[of \<Gamma>' " s1[x'::=e'']" U] by auto
have L2:"T1 = T'" .
from L1 L2 show ?case by auto
next
case FF
from elim2 FF obtain T0 T0'a T1 le leS eff' eff'' U where
P:"(x',T0')#\<Gamma>' \<turnstile> s1 :U;eff'"" (x',T0')# \<Gamma>'\<turnstile> s2 : T0'a;eff''"" \<turnstile> T0'a <: T0 "" T1 = T'" "\<turnstile> U <: T0\<rightarrow>T1:le"
"le = Latent leS" "~ (\<turnstile> T0'a <: leS)" "s2 :values" "closed s2" by auto
hence "EX S1 G1. \<Gamma>' \<turnstile> s1[x'::=e''] : S1 ; G1 \<and> \<turnstile> S1 <: U \<and> \<turnstile> G1 <e: eff'"
using ih_s1 App by auto
then obtain S1 G1 where Q:" \<Gamma>' \<turnstile> s1[x'::=e''] : S1 ; G1 "" \<turnstile> S1 <: U" "\<turnstile> G1 <e: eff'" by auto
hence R:"\<turnstile> S1 <: T0\<rightarrow>T1:le" using P by auto
(* then apply ih_s2, get something about the substition of s2, and put it all back together. *)
from P have "EX S G. \<Gamma>' \<turnstile> s2[x'::=e'']:S ; G \<and> \<turnstile> S <: T0'a \<and> \<turnstile> G <e: eff''"
using ih_s2[of x' T0' \<Gamma>' T0'a eff''] App by auto
then obtain S2 G2 where S:"\<Gamma>' \<turnstile> s2[x'::=e'']:S2 ; G2 "" \<turnstile> S2 <: T0'a" "\<turnstile> G2 <e: eff''" by auto
let ?ns1 = "s1[x'::=e'']" and ?ns2 = "s2[x'::=e'']"
have "x' \<sharp> s2" using closed_def fresh_def[of x' s2] `closed s2` by auto
hence "s2 = ?ns2" using forget by auto
hence S':"\<Gamma>' \<turnstile> ?ns2 : T0'a ; eff''"
using `(x',T0')#\<Gamma>' \<turnstile> s2 : T0'a ; eff''` fresh_weakening_cons `valid ((x',T0')#\<Gamma>')` `x' \<sharp> s2`
by auto
have noover: "~(\<turnstile> T0'a <: leS)" .
have T:"closed ?ns2" "?ns2 : values" using `s2 = ?ns2` `closed s2` `s2 : values` by auto
have L1:"\<Gamma>' \<turnstile> App ?ns1 ?ns2 : T1 ; FF" using P Q R S' T noover by auto
have L2:"T1 = T'" by fact
from L1 L2 show ?case by auto
qed
next
case (Lam a body \<Gamma>' x' e'' T' T1' T0' F' G' ty )
hence f1: "a\<sharp>\<Gamma>'" and f2: "a\<noteq>x'" and f2': "x'\<sharp>a" and f3: "a\<sharp>e''" and f4: "a\<sharp>((x',T0')#\<Gamma>')"
by (auto simp add: fresh_atm fresh_prod fresh_list_cons)
have c1: "((x',T0')#\<Gamma>')\<turnstile>Lam [a:ty].body : T' ; F'" by fact
(* hence "\<exists>\<tau>2 eff L S. ((a,ty)#(x',T0')#\<Gamma>') \<turnstile> body : \<tau>2 ; eff \<and> T'=ty\<rightarrow>\<tau>2:L \<and> F' = TT" using f4 abs_ty_elim by auto *)
then obtain \<tau>2 eff L S where c11: "T'=ty\<rightarrow>\<tau>2:L" and c12: "((a,ty)#(x',T0')#\<Gamma>') \<turnstile> body : \<tau>2 ; eff" and "F' = TT"
and c13:"L = latent_eff.NE \<or> (eff = TE S a \<and> L = Latent S)" using f4 abs_ty_elim by blast
from c12 have "valid ((a,ty)#(x',T0')#\<Gamma>')" using Lam by auto
hence ca: "valid \<Gamma>'" and cb: "a\<sharp>\<Gamma>'" and cc: "x'\<sharp>\<Gamma>'"
by (auto dest: valid_elim simp add: fresh_list_cons)
have c2: "((a,ty)#(x',T0')#\<Gamma>') \<lless> ((x',T0')#(a,ty)#\<Gamma>')" by force
have c3: "valid ((x',T0')#(a,ty)#\<Gamma>')"
by (rule v2, rule v2, auto simp add: fresh_list_cons fresh_prod ca cb cc f2' fresh_ty)
from c12 c2 c3 have c14: "((x',T0')#(a,ty)#\<Gamma>') \<turnstile> body : \<tau>2 ; eff" using `valid ((a, ty) # (x', T0') # \<Gamma>')`
by (force intro: weakening)
let ?inner\<Gamma> = "(a,ty)#\<Gamma>'"
have validig:"valid ?inner\<Gamma>" using `a \<sharp> \<Gamma>'` `valid \<Gamma>'` by auto
have c15:"\<Gamma>' \<lless> ?inner\<Gamma>" by auto
hence c16:"?inner\<Gamma> \<turnstile> e'' : T1' ; G'"
using weakening[of \<Gamma>' _ _ _ ?inner\<Gamma>] `\<Gamma>' \<turnstile> e'' : T1' ; G'` validig `valid \<Gamma>'` by simp
have "EX TA0 FA0. ?inner\<Gamma> \<turnstile> body[x'::=e''] : TA0 ; FA0 \<and> \<turnstile> TA0 <: \<tau>2 \<and> \<turnstile> FA0 <e: eff"
using c16 Lam(10)[of x' T0' ?inner\<Gamma> \<tau>2 eff e'' T1' G'] ` \<turnstile> T1' <: T0'` `valid ((x', T0') # (a, ty) # \<Gamma>')` c14 `closed e''`
`e'' : values`
by auto
then obtain TA0 FA0 where body_ty:"?inner\<Gamma> \<turnstile> body[x'::=e''] : TA0 ; FA0 "" \<turnstile> TA0 <: \<tau>2" by auto
hence L11:"\<Gamma>' \<turnstile> (Lam[a:ty].(body[x'::=e''])) : ty \<rightarrow> TA0 : latent_eff.NE; eff.TT" using `a \<sharp> \<Gamma>'` by auto
note Lam(9)[OF _ _ `(a, ty)# \<Gamma>' \<turnstile> e'' : T1' ; G'` `\<turnstile> T1' <: T0'` `valid ((x', T0')# (a, ty) # \<Gamma>')` `closed e''` `e'' : values`]
hence "!! t bc bf . \<lbrakk>t \<guillemotleft> Lam [a:ty].body; (x', T0') #(a, ty)# \<Gamma>' \<turnstile> t : bc ; bf \<rbrakk>
\<Longrightarrow> \<exists>T' F'. (a, ty)#\<Gamma>' \<turnstile> t[x'::=e''] : T' ; F' \<and> \<turnstile> T' <: bc \<and> \<turnstile> F' <e: bf" .
hence ih_body:"!! t bc bf . \<lbrakk>t \<guillemotleft> body; (x', T0') # (a, ty)#\<Gamma>' \<turnstile> t : bc ; bf \<rbrakk>
\<Longrightarrow> \<exists>T' F'. (a, ty)#\<Gamma>' \<turnstile> t[x'::=e''] : T' ; F' \<and> \<turnstile> T' <: bc \<and> \<turnstile> F' <e: bf" by auto
hence L12:"L = Latent S \<Longrightarrow> \<Gamma>' \<turnstile> (Lam[a:ty].(body[x'::=e''])) : ty \<rightarrow> \<tau>2 : Latent S; eff.TT"
proof -
assume "L = Latent S"
hence "eff = TE S a" using c13 by auto
hence c12':"(a, ty) # (x', T0') # \<Gamma>' \<turnstile> body : \<tau>2 ; TE S a" using c12 by simp
have c12'':" (x', T0') # (a, ty) # \<Gamma>' \<turnstile> body : \<tau>2 ; TE S a" using weakening[OF c12' _ c2 ]
using `valid ((x', T0') # (a, ty) # \<Gamma>')` `valid ((a, ty) # (x', T0') # \<Gamma>')` by auto
have f2':"x' \<noteq> a" using f2 by auto
note body_ty subst_preserve_TE[OF c12'' f2' `valid ((x', T0') # (a, ty) # \<Gamma>')` , of e'']
hence "(a, ty) # \<Gamma>' \<turnstile> body[x'::=e''] : \<tau>2 ; TE S a" using ih_body by auto
hence "?inner\<Gamma> \<turnstile> body[x'::=e''] : \<tau>2 ; TE S a " .
thus ?thesis using `a \<sharp> \<Gamma>'` by auto
qed
(* from L11 L12 have L1:"\<Gamma>' \<turnstile> (Lam[a:ty].(body[x'::=e''])) : ty \<rightarrow> TA0 : L; eff.TT" using c13 by auto *)
have L21:"\<turnstile> ty \<rightarrow> TA0 : L <: T'" using c11 ` \<turnstile> TA0 <: \<tau>2` by auto
have L22: "\<turnstile> ty \<rightarrow> \<tau>2 : L <: T'" using c11 by auto
have L3:"(Lam[a:ty].body)[x'::=e''] = (Lam[a:ty].(body[x'::=e'']))" using Lam by auto
have L4:"\<turnstile> eff.TT <e: F'" using `F' = TT` by auto
thm Lam
have L5:"!! Env a ty body T S x. Env \<turnstile> (Lam [a:ty].body) : T ; TE S x \<Longrightarrow> False"
proof -
fix Env a ty body T S x
assume "Env \<turnstile> (Lam [a:ty].body) : T ; TE S x"
have " Env \<turnstile> (Lam [a:ty].body) : T ; TE S x \<Longrightarrow> False"
by (ind_cases " Env \<turnstile> (Lam [a:ty].body) : T ; TE S x")
thus False using prems by auto
qed
from L11 L12 L21 L22 L3 L4 L5[of \<Gamma>' a _ ty ] c13
show ?case by auto
next
case (Iff t1 t2 t3 \<Gamma>' x' e'' T' T0' T1' F' G')
let ?\<Gamma> = "(x', T1') # \<Gamma>'"
have A:"(\<exists> T1 T2 T3 F1 F2 F3.
(?\<Gamma> \<turnstile> t1 : T1 ; F1) \<and> ?\<Gamma> |+ F1 \<turnstile> t2 : T2 ; F2 \<and> ?\<Gamma> |- F1 \<turnstile> t3 : T3 ; F3 \<and> \<turnstile> T2 <: T' \<and> \<turnstile> T3 <: T' \<and> F' = NE)
\<or>
(\<exists> T1 T3 F3. (?\<Gamma> \<turnstile> t1 : T1 ; FF) \<and> ?\<Gamma> \<turnstile> t3 : T3 ; F3 \<and> \<turnstile> T3 <: T' \<and> F' = NE)
\<or>
(\<exists> T1 T2 F2. (?\<Gamma> \<turnstile> t1 : T1 ; TT) \<and> ?\<Gamma> \<turnstile> t2 : T2 ; F2 \<and> \<turnstile> T2 <: T' \<and> F' = NE)" using Iff if_ty_elim by auto
thus ?case
proof -
{
assume "(\<exists> T1 T2 T3 F1 F2 F3.
(?\<Gamma> \<turnstile> t1 : T1 ; F1) \<and> ?\<Gamma> |+ F1 \<turnstile> t2 : T2 ; F2 \<and> ?\<Gamma> |- F1 \<turnstile> t3 : T3 ; F3 \<and> \<turnstile> T2 <: T' \<and> \<turnstile> T3 <: T' \<and> F' = NE)"
then obtain T1 T2 T3 F1 F2 F3 where
"?\<Gamma> \<turnstile> t1 : T1 ; F1 "" ?\<Gamma> |+ F1 \<turnstile> t2 : T2 ; F2 "" ?\<Gamma> |- F1 \<turnstile> t3 : T3 ; F3 "" \<turnstile> T2 <: T'""\<turnstile> T3 <: T'""F' = NE"
by auto
hence ?thesis
proof (nominal_induct F1 rule: eff.induct)
case NE
from NE have "\<exists>S1 G1. \<Gamma>' \<turnstile> t1[x'::=e''] : S1 ; G1 \<and> \<turnstile> S1 <: T1 \<and> \<turnstile> G1 <e: NE" using Iff by auto
then obtain S1 G1 where A:"\<Gamma>' \<turnstile> t1[x'::=e''] : S1 ; G1 "" \<turnstile> S1 <: T1 "" \<turnstile> G1 <e: NE" by auto
have simple:"simple_eff G1" using `\<turnstile> G1 <e: NE` below_ne_simple by auto
have p1:"(?\<Gamma> \<turnstile> t2 : T2 ; F2)" using prems by auto
have p2:"(?\<Gamma> \<turnstile> t3 : T3 ; F3)" using prems by auto
from p1 have "\<exists>S2 G2. \<Gamma>' \<turnstile> t2[x'::=e''] : S2 ; G2 \<and> \<turnstile> S2 <: T2 \<and> \<turnstile> G2 <e: F2" using Iff by auto
then obtain S2 G2 where B:"\<Gamma>' \<turnstile> t2[x'::=e''] : S2 ; G2 "" \<turnstile> S2 <: T2 "" \<turnstile> G2 <e: F2" by auto
from p2 have "\<exists>S3 G3. \<Gamma>' \<turnstile> t3[x'::=e''] : S3 ; G3 \<and> \<turnstile> S3 <: T3 \<and> \<turnstile> G3 <e: F3" using Iff by auto
then obtain S3 G3 where C:"\<Gamma>' \<turnstile> t3[x'::=e''] : S3 ; G3 "" \<turnstile> S3 <: T3 "" \<turnstile> G3 <e: F3" by auto
have B':"\<Gamma>' |+ G1 \<turnstile> t2[x'::=e''] : S2 ; G2" using B simple by auto
have C':"\<Gamma>' |- G1 \<turnstile> t3[x'::=e''] : S3 ; G3" using C simple by auto
have D:"\<turnstile> S2 <: T'" using prems B by auto
have E:"\<turnstile> S3 <: T'" using prems C by auto
from A B' C' D E have " \<Gamma>' \<turnstile> Iff t1 t2 t3[x'::=e''] : T' ; comb_eff G1 G2 G3" by (auto simp del: comb_eff.simps)
thus ?case using `F' = NE` by auto
next
case TT
from TT have "\<exists>S1 G1. \<Gamma>' \<turnstile> t1[x'::=e''] : S1 ; G1 \<and> \<turnstile> S1 <: T1 \<and> \<turnstile> G1 <e: TT" using Iff by auto
then obtain S1 G1 where A:"\<Gamma>' \<turnstile> t1[x'::=e''] : S1 ; G1 "" \<turnstile> S1 <: T1 "" \<turnstile> G1 <e: TT" by auto
have simple:"G1 = TT" using A no_sub_TT by blast
have p1:"(?\<Gamma> \<turnstile> t2 : T2 ; F2)" using prems by auto
have p2:"(?\<Gamma> \<turnstile> t3 : T3 ; F3)" using prems by auto
from p1 have "\<exists>S2 G2. \<Gamma>' \<turnstile> t2[x'::=e''] : S2 ; G2 \<and> \<turnstile> S2 <: T2 \<and> \<turnstile> G2 <e: F2" using Iff by auto
then obtain S2 G2 where B:"\<Gamma>' \<turnstile> t2[x'::=e''] : S2 ; G2 "" \<turnstile> S2 <: T2 "" \<turnstile> G2 <e: F2" by auto
from p2 have "\<exists>S3 G3. \<Gamma>' \<turnstile> t3[x'::=e''] : S3 ; G3 \<and> \<turnstile> S3 <: T3 \<and> \<turnstile> G3 <e: F3" using Iff by auto
then obtain S3 G3 where C:"\<Gamma>' \<turnstile> t3[x'::=e''] : S3 ; G3 "" \<turnstile> S3 <: T3 "" \<turnstile> G3 <e: F3" by auto
have B':"\<Gamma>' |+ G1 \<turnstile> t2[x'::=e''] : S2 ; G2" using B simple by auto
have C':"\<Gamma>' |- G1 \<turnstile> t3[x'::=e''] : S3 ; G3" using C simple by auto
have D:"\<turnstile> S2 <: T'" using prems B by auto
have E:"\<turnstile> S3 <: T'" using prems C by auto
from A B' C' D E have " \<Gamma>' \<turnstile> Iff t1 t2 t3[x'::=e''] : T' ; comb_eff G1 G2 G3" by (auto simp del: comb_eff.simps)
thus ?case using `F' = NE` by auto
next
case FF
from FF have "\<exists>S1 G1. \<Gamma>' \<turnstile> t1[x'::=e''] : S1 ; G1 \<and> \<turnstile> S1 <: T1 \<and> \<turnstile> G1 <e: FF" using Iff by auto
then obtain S1 G1 where A:"\<Gamma>' \<turnstile> t1[x'::=e''] : S1 ; G1 "" \<turnstile> S1 <: T1 "" \<turnstile> G1 <e: FF" by auto
have simple:"G1 = FF" using A no_sub_FF by blast
have p1:"(?\<Gamma> \<turnstile> t2 : T2 ; F2)" using prems by auto
have p2:"(?\<Gamma> \<turnstile> t3 : T3 ; F3)" using prems by auto
from p1 have "\<exists>S2 G2. \<Gamma>' \<turnstile> t2[x'::=e''] : S2 ; G2 \<and> \<turnstile> S2 <: T2 \<and> \<turnstile> G2 <e: F2" using Iff by auto
then obtain S2 G2 where B:"\<Gamma>' \<turnstile> t2[x'::=e''] : S2 ; G2 "" \<turnstile> S2 <: T2 "" \<turnstile> G2 <e: F2" by auto
from p2 have "\<exists>S3 G3. \<Gamma>' \<turnstile> t3[x'::=e''] : S3 ; G3 \<and> \<turnstile> S3 <: T3 \<and> \<turnstile> G3 <e: F3" using Iff by auto
then obtain S3 G3 where C:"\<Gamma>' \<turnstile> t3[x'::=e''] : S3 ; G3 "" \<turnstile> S3 <: T3 "" \<turnstile> G3 <e: F3" by auto
have B':"\<Gamma>' |+ G1 \<turnstile> t2[x'::=e''] : S2 ; G2" using B simple by auto
have C':"\<Gamma>' |- G1 \<turnstile> t3[x'::=e''] : S3 ; G3" using C simple by auto
have D:"\<turnstile> S2 <: T'" using prems B by auto
have E:"\<turnstile> S3 <: T'" using prems C by auto
from A B' C' D E have " \<Gamma>' \<turnstile> Iff t1 t2 t3[x'::=e''] : T' ; comb_eff G1 G2 G3" by (auto simp del: comb_eff.simps)
thus ?case using `F' = NE` by auto
next
case (VE z)
hence A:"t1 = (Var z) " "?\<Gamma> \<turnstile> Var z : T1 ; VE z"
using ve_ty_elim[OF `?\<Gamma> \<turnstile> t1 : T1; VE z`] using eff.inject by auto
have size1:"(Var z\<guillemotleft>Iff t1 t2 t3)" using A by simp
note Iff(1)[of "Var z"]
hence ih_f:"!! c \<sigma> \<Gamma> T F e' T0 F0 .
(c,\<sigma>)#\<Gamma> \<turnstile> (Var z) : T ; F \<Longrightarrow> \<Gamma> \<turnstile> e' : T0 ; F0 \<Longrightarrow> \<turnstile> T0 <: \<sigma> \<Longrightarrow> valid ((c,\<sigma>)#\<Gamma>) \<Longrightarrow> closed e' \<Longrightarrow> e' : values
\<Longrightarrow> EX T' F' . \<Gamma> \<turnstile> (Var z)[c::=e'] : T' ; F' \<and> \<turnstile> T' <: T \<and> \<turnstile> F' <e: F" using size1 by auto
have "EX A' Fn' . \<Gamma>' \<turnstile> (Var z)[x'::=e''] : A' ; Fn' \<and> \<turnstile> A' <: T1 \<and> \<turnstile> Fn' <e: VE z"
using ih_f A Iff by auto
then obtain A' Fn' where B:"\<Gamma>' \<turnstile> (Var z)[x'::=e''] : A' ; Fn' \<and> \<turnstile> A' <:T1" by auto
let ?mapfun = "(%f. (% (v,ty). (if (z = v) then (v,f ty.FF ty) else (v,ty))))"
let ?\<Gamma>1 = "(map (?mapfun remove) \<Gamma>')"
let ?\<Gamma>2 = "(map (?mapfun replace) \<Gamma>')"
have "valid \<Gamma>'" using `valid ?\<Gamma>` using valid_elim[of x' T1' \<Gamma>'] by auto
show ?case
proof (cases "x' = z")
case True
from A True have "(Var z)[x'::=e''] = e''" by auto
hence D:"\<Gamma>' \<turnstile> (Var z)[x'::=e''] : T0' ; G'" "closed ((Var z)[x'::=e''])" "((Var z)[x'::=e'']) : values"
using Iff by auto
have "\<turnstile> T0' <: T1'" .
note var_ty_elim[of ?\<Gamma> z _ "VE z"]
hence "(x', T1') : set ?\<Gamma>" using A True by auto
have "?\<Gamma> \<turnstile> (Var x') : T1' ; VE x'" using `valid ?\<Gamma>` by auto
have "simple_ty T0'" using `\<Gamma>' \<turnstile> e'' : T0' ; G'` `e'' : values` value_simple_type by auto
let ?mapfun = "(%f. (% (v,ty). (if (z = v) then (v,f ty.FF ty) else (v,ty))))"
let ?\<Gamma>1 = "(map (?mapfun remove) \<Gamma>')"
let ?\<Gamma>2 = "(map (?mapfun replace) \<Gamma>')"
have "?\<Gamma>1 = envop remove z ty.FF \<Gamma>'" by auto
have "?\<Gamma>2 = envop replace z ty.FF \<Gamma>'" by auto
have "x' \<sharp> \<Gamma>'" using Iff valid_elim[of x' T1' \<Gamma>'] by auto
hence "?\<Gamma>1 = \<Gamma>'" using True envop_forget `valid \<Gamma>'` by auto
hence GA:"?\<Gamma> |+ VE z = (x',remove ty.FF T1') # \<Gamma>'" using True by auto
hence G1:"\<dots> \<turnstile> t2 : T2; F2" using `(?\<Gamma> |+ VE z)\<turnstile> t2 : T2 ; F2` by auto
have "?\<Gamma>2 = \<Gamma>'" using `x' \<sharp> \<Gamma>'` True envop_forget `valid \<Gamma>'` by auto
hence "?\<Gamma> |- VE z = (x',replace ty.FF T1') # \<Gamma>'" using True by auto
hence GB:"?\<Gamma> |- VE z = (x',ty.FF) # \<Gamma>'" by auto
hence G2:"\<dots> \<turnstile> t3 : T3; F3" using `(?\<Gamma> |- VE z)\<turnstile> t3 : T3 ; F3` by auto
have "valid (?\<Gamma> |+ VE z)" using `valid ?\<Gamma>` envplus_valid[of ?\<Gamma> "VE z"] by auto
hence G3:"valid ((x',remove ty.FF T1') # \<Gamma>')" using GA by auto
have "valid (?\<Gamma> |- VE z)" using `valid ?\<Gamma>` envminus_valid[of ?\<Gamma> "VE z"] by auto
hence G4:"valid ((x',ty.FF) # \<Gamma>')" using GB by auto
show ?thesis
proof (cases "e'' = Bool False")
case True
hence "(Var z)[x'::=e''] = Bool False" using `x' = z` by auto
hence "t1[x'::=e''] = Bool False" using `t1 = Var z` by auto
hence X1:"?\<Gamma> \<turnstile> t1[x'::=e''] : ty.FF ; FF" using `valid ?\<Gamma>` by auto
have "\<Gamma>' \<turnstile> e'' : ty.FF ; FF" using True `valid \<Gamma>'` by auto
note `?\<Gamma> |- VE z = (x', ty.FF) # \<Gamma>'`
hence "valid ((x', ty.FF) # \<Gamma>')" using G4 by auto
have X2:"(x', ty.FF) # \<Gamma>' \<turnstile> t3 : T3 ; F3" using VE `?\<Gamma> |- VE z = (x', ty.FF) # \<Gamma>'` by auto
note Iff(4)[ OF X2 `\<Gamma>' \<turnstile> e'' : ty.FF ; FF ` _ `valid ((x', ty.FF) # \<Gamma>')`]
then obtain T'' F'' where X3:"\<Gamma>' \<turnstile> t3[x'::=e''] : T'' ; F'' " and X4:" \<turnstile> T'' <: T3 "" \<turnstile> F'' <e: F3"
using `closed e''` `e'' : values` by auto
hence "\<turnstile> T'' <: T'" using `\<turnstile> T3 <: T'` by auto
hence "\<Gamma>' \<turnstile> Iff (Bool False) (t2[x'::=e'']) (t3[x'::=e'']) : T'' ; NE" using `valid \<Gamma>'` X3 by auto
hence "\<Gamma>' \<turnstile> (Iff t1 t2 t3)[x'::=e''] : T'' ; NE" using ` t1[x'::=e''] = Bool False` by auto
thus ?thesis using `\<turnstile> T'' <: T'` `F' = NE` by auto
next
case False
hence "(Var z)[x'::=e''] = e''" using `x' = z` by auto
hence "t1[x'::=e''] = e''" using `t1 = Var z` by auto
hence X1:"\<Gamma>' \<turnstile> t1[x'::=e''] : T0' ; G'" by auto
have "\<Gamma>' \<turnstile> e'' : T0' ; G'" .
hence "G' = TT" using value_effect_tt_or_ff[OF `e'' : values` `\<Gamma>' \<turnstile> e'' : T0' ; G'`] False by auto
hence X2:"\<Gamma>' \<turnstile> t1[x'::=e''] : T0' ; TT" using X1 by auto
have "\<turnstile> T0' <: T1'" .
have X3:"\<not> \<turnstile> T0' <: ty.FF"
proof (rule ccontr)
assume "\<not>\<not> \<turnstile> T0' <: ty.FF"
hence "\<turnstile> T0' <: ty.FF" by simp
hence "\<turnstile> T0' <: BoolTy" using BoolTy_def by auto
hence "EX b. e'' = Bool b" using bool_value `e'' : values ` `\<Gamma>' \<turnstile> e'' : T0' ; G'` by auto
then obtain b where A:"e'' = Bool b" by auto
thus False
proof (cases b)
case False
thus ?thesis using A `e'' ~= Bool False` by auto
next
case True
hence "T0' = ty.TT" using `\<Gamma>' \<turnstile> e'' : T0' ; G'` A true_ty_elim by auto
thus ?thesis using `\<turnstile> T0' <: ty.FF` tt_sub_ff by auto
qed
qed
let ?rty = "remove ty.FF T1'"
note `?\<Gamma> |+ VE z = (x', ?rty) # \<Gamma>'`
hence "valid ((x', ?rty) # \<Gamma>')" using G3 by auto
have X2:"(x', ?rty) # \<Gamma>' \<turnstile> t2 : T2 ; F2" using VE `?\<Gamma> |+ VE z = (x', ?rty) # \<Gamma>'` by auto
note Iff(3)[ OF X2 `\<Gamma>' \<turnstile> e'' : T0' ; G' ` _ `valid ((x', ?rty) # \<Gamma>')`]
then obtain T'' F'' where X3:"\<Gamma>' \<turnstile> t2[x'::=e''] : T'' ; F'' " and X4:" \<turnstile> T'' <: T2 "" \<turnstile> F'' <e: F2"
using `closed e''` `e'' : values` remove_soundness[OF `\<turnstile> T0' <: T1'` X3 `simple_ty T0'`] by auto
hence "\<turnstile> T'' <: T'" using `\<turnstile> T2 <: T'` by auto
hence "\<Gamma>' \<turnstile> Iff e'' (t2[x'::=e'']) (t3[x'::=e'']) : T'' ; NE" using `valid \<Gamma>'` X3 `\<Gamma>' \<turnstile> e'' : T0' ; G' `
`G' = TT` by auto
hence "\<Gamma>' \<turnstile> (Iff t1 t2 t3)[x'::=e''] : T'' ; NE" using ` t1[x'::=e''] = e''` by auto
thus ?thesis using `\<turnstile> T'' <: T'` `F' = NE` by auto
qed
next
case False
from A False have "(Var z)[x'::=e''] = (Var z)" by auto
hence D:"\<Gamma>' \<turnstile> (Var z)[x'::=e''] : T1 ; VE z" using False A
proof -
have q1:"?\<Gamma> \<turnstile> Var z : T1 ; VE z" using A by auto
have "x' \<sharp> Var z" using trm.fresh False fresh_atm by auto
hence "\<Gamma>' \<turnstile> Var z : T1 ; VE z" using q1 fresh_weakening_cons `valid ((x',T1')# \<Gamma>')` by auto
thus ?thesis using `(Var z)[x'::=e''] = Var z` by auto
qed
hence typetst: "\<Gamma>' \<turnstile> t1[x'::=e''] : T1 ; VE z" using A by auto
have F:"?\<Gamma> |+ VE z = (x',T1') # ?\<Gamma>1" using False by auto
hence H:"(x',T1') # ?\<Gamma>1 \<turnstile> t2 : T2 ; F2" using `?\<Gamma> |+ VE z \<turnstile> t2 : T2 ; F2` by auto
hence K:"valid ?\<Gamma>1" using envop_valid `valid \<Gamma>'` by auto
have J:"?\<Gamma>1 \<turnstile> e'' : T0' ; G'" using K `valid \<Gamma>'` closed_any_env `closed e''` Iff by blast
have "x' \<sharp> ?\<Gamma>1" using Iff valid_elim[of x' T1' \<Gamma>'] envop_fresh[of x' \<Gamma>' remove] `valid \<Gamma>'` by auto
hence "valid ((x',T1')#?\<Gamma>1)" using `valid ?\<Gamma>1` by auto
hence ex1:"\<exists>S2 G2. ?\<Gamma>1 \<turnstile> t2[x'::=e''] : S2 ; G2 \<and> \<turnstile> S2 <: T2 \<and> \<turnstile> G2 <e: F2"
using H J K Iff by auto
have G:"?\<Gamma> |- VE z = (x',T1') # ?\<Gamma>2" using False by auto
hence H:"(x',T1') # ?\<Gamma>2 \<turnstile> t3 : T3 ; F3" using `?\<Gamma> |- VE z \<turnstile> t3 : T3 ; F3` by auto
hence K:"valid ?\<Gamma>2" using envop_valid `valid \<Gamma>'` by auto
have J:"?\<Gamma>2 \<turnstile> e'' : T0' ; G'" using K `valid \<Gamma>'` closed_any_env `closed e''` Iff by blast
have "x' \<sharp> ?\<Gamma>2" using Iff valid_elim[of x' T1' \<Gamma>'] envop_fresh[of x' \<Gamma>' _ z _] `valid \<Gamma>'` by auto
hence "valid ((x',T1')#?\<Gamma>2)" using `valid ?\<Gamma>2` by auto
hence ex2:"\<exists>S3 G3. ?\<Gamma>2 \<turnstile> t3[x'::=e''] : S3 ; G3 \<and> \<turnstile> S3 <: T3 \<and> \<turnstile> G3 <e: F3"
using H J K Iff by auto
from ex1 obtain S2 G2 where 1:"?\<Gamma>1 \<turnstile> t2[x'::=e''] : S2 ; G2"" \<turnstile> S2 <: T'" using `\<turnstile> T2 <: T'` by auto
from ex2 obtain S3 G3 where 2:"?\<Gamma>2 \<turnstile> t3[x'::=e''] : S3 ; G3"" \<turnstile> S3 <: T'" using `\<turnstile> T3 <: T'` by auto
have 4:"?\<Gamma>1 = \<Gamma>' |+ (VE z)" by auto
have 5:"?\<Gamma>2 = \<Gamma>' |- (VE z)" by auto
have X:"!! G G' e T F. G = G' \<Longrightarrow> G \<turnstile> e : T ; F \<Longrightarrow> G' \<turnstile> e : T ; F" by auto
from 1 4 have 6:"\<Gamma>' |+ (VE z) \<turnstile> t2[x'::=e''] : S2 ; G2" using X[of ?\<Gamma>1 "\<Gamma>' |+ (VE z)" " t2[x'::=e'']" S2 G2]
by blast
from 2 5 have 7:"\<Gamma>' |- (VE z) \<turnstile> t3[x'::=e''] : S3 ; G3" using X[of ?\<Gamma>2 "\<Gamma>' |- (VE z)" " t3[x'::=e'']" S3 G3]
by blast
from typetst 1 2 6 7 have "\<Gamma>' \<turnstile> (Iff t1 t2 t3)[x'::=e''] : T' ; comb_eff (VE z) G2 G3" by (auto simp del: comb_eff.simps)
thus ?thesis using `F' = NE` by auto
qed
next
case (TE U z)
have "EX f A A1 Fn B. t1 = (App f (Var z)) \<and> (x', T1') # \<Gamma>' \<turnstile> f : B ; Fn \<and> \<turnstile> B <: A1 \<rightarrow> T1 : Latent U \<and>
(x', T1') # \<Gamma>' \<turnstile> (Var z) : A ; VE z \<and> \<turnstile> A <: A1"
using TE te_ty_elim[of ?\<Gamma> t1 T1 U z] by auto
then obtain f A1 A Fn B where A:"t1 = (App f (Var z)) "" (x', T1') # \<Gamma>' \<turnstile> f : B ; Fn" "\<turnstile> B <: A1 \<rightarrow> T1 : Latent U"
"(x', T1') # \<Gamma>' \<turnstile> (Var z) : A ; VE z "" \<turnstile> A <: A1" by auto
have size1:"(f\<guillemotleft>Iff t1 t2 t3)" using A(1) by (simp )
note Iff(1)[of f]
hence ih_f:"!! c \<sigma> \<Gamma> T F e' T0 F0 .
(c,\<sigma>)#\<Gamma> \<turnstile> f : T ; F \<Longrightarrow> \<Gamma> \<turnstile> e' : T0 ; F0 \<Longrightarrow> \<turnstile> T0 <: \<sigma> \<Longrightarrow> valid ((c,\<sigma>)#\<Gamma>) \<Longrightarrow> closed e' \<Longrightarrow> e' : values
\<Longrightarrow> EX T' F' . \<Gamma> \<turnstile> f[c::=e'] : T' ; F' \<and> \<turnstile> T' <: T \<and> \<turnstile> F' <e: F" using size1 by auto
have "EX A' Fn' . \<Gamma>' \<turnstile> f[x'::=e''] : A' ; Fn' \<and> \<turnstile> A' <: B \<and> \<turnstile> Fn' <e: Fn"
using ih_f A Iff by auto
then obtain A' Fn' where B:"\<Gamma>' \<turnstile> f[x'::=e''] : A' ; Fn' \<and> \<turnstile> A' <:B" by auto
let ?mapfun = "(%f. (% (v,ty). (if (z = v) then (v,f U ty) else (v,ty))))"
let ?\<Gamma>1 = "(map (?mapfun restrict) \<Gamma>')"
let ?\<Gamma>2 = "(map (?mapfun remove) \<Gamma>')"
have "valid \<Gamma>'" using `valid ?\<Gamma>` using valid_elim[of x' T1' \<Gamma>'] by auto
show ?case
proof (cases "x' = z")
case True
from A True have "(Var z)[x'::=e''] = e''" by auto
hence D:"\<Gamma>' \<turnstile> (Var z)[x'::=e''] : T0' ; G'" "closed ((Var z)[x'::=e''])" "((Var z)[x'::=e'']) : values"
using Iff by auto
have "\<turnstile> T0' <: T1'" .
note var_ty_elim[of ?\<Gamma> z A "VE z"]
hence "(x', A) : set ?\<Gamma>" using A True by auto
have "?\<Gamma> \<turnstile> (Var x') : T1' ; VE x'" using `valid ?\<Gamma>` by auto
hence "T1' = A" using A unique_var_typing[of ] True by auto
have "\<turnstile> T0' <: T1'" .
hence "\<turnstile> T0' <: A" using `T1' = A` by simp
have "simple_ty T0'" using `\<Gamma>' \<turnstile> e'' : T0' ; G'` `e'' : values` value_simple_type by auto
have or:"
(\<turnstile> T0' <: U \<and> \<turnstile> T0' <: restrict U T1') \<or>
(~ (\<turnstile> T0' <: U) \<and> \<turnstile> T0' <: remove U T1')"
using `\<Gamma>' \<turnstile> e'' : T0' ; G'` `e'' : values` `\<turnstile> T0' <: T1'` `closed e''` `simple_ty T0'`
restrict_remove_soundness
by auto
have "?\<Gamma>1 = envop restrict z U \<Gamma>'" by auto
have "?\<Gamma>2 = envop remove z U \<Gamma>'" by auto
have "x' \<sharp> \<Gamma>'" using Iff valid_elim[of x' T1' \<Gamma>'] by auto
hence "?\<Gamma>1 = \<Gamma>'" using True envop_forget `valid \<Gamma>'` by auto
hence GA:"?\<Gamma> |+ TE U z = (x',restrict U T1') # \<Gamma>'" using True by auto
hence G1:"\<dots> \<turnstile> t2 : T2; F2" using `(?\<Gamma> |+ TE U z)\<turnstile> t2 : T2 ; F2` by auto
have "?\<Gamma>2 = \<Gamma>'" using `x' \<sharp> \<Gamma>'` True envop_forget `valid \<Gamma>'` by auto
hence GB:"?\<Gamma> |- TE U z = (x',remove U T1') # \<Gamma>'" using True by auto
hence G2:"\<dots> \<turnstile> t3 : T3; F3" using `(?\<Gamma> |- TE U z)\<turnstile> t3 : T3 ; F3` by auto
have "valid (?\<Gamma> |+ TE U z)" using `valid ?\<Gamma>` envplus_valid[of ?\<Gamma> "TE U z"] by auto
hence G3:"valid ((x',restrict U T1') # \<Gamma>')" using GA by auto
have "valid (?\<Gamma> |- TE U z)" using `valid ?\<Gamma>` envminus_valid[of ?\<Gamma> "TE U z"] by auto
hence G4:"valid ((x',remove U T1') # \<Gamma>')" using GB by auto
show ?thesis
proof -
{
assume "\<turnstile> T0' <: U "" \<turnstile> T0' <: restrict U T1'"
have 2:"(x', restrict U T1') # \<Gamma>' \<turnstile> t2 : T2 ; F2 " using `?\<Gamma> |+ TE U z \<turnstile> t2 : T2 ; F2` GA by auto
note Iff(2)[of x' "restrict U T1'" \<Gamma>' T2 F2 e'' T0' G']
hence "\<exists>S2 G2. \<Gamma>' \<turnstile> t2[x'::=e''] : S2 ; G2 \<and> \<turnstile> S2 <: T2 \<and> \<turnstile> G2 <e: F2" using G3 prems `closed e''` 2 by auto
then obtain S2 G2 where L1:"\<Gamma>'|+ eff.TT \<turnstile> t2[x'::=e''] : S2 ; G2 "" \<turnstile> S2 <: T2 "" \<turnstile> G2 <e: F2" by auto
have "\<turnstile> T0' <: A1" "\<turnstile> A' <: A1 \<rightarrow> T1 : Latent U" using A B D `\<turnstile> T0' <: A` by auto
hence "\<Gamma>' \<turnstile> (App f (Var z))[x'::=e''] : T1 ; eff.TT" using A B D `\<turnstile> T0' <: A` `\<turnstile> T0' <: U`
using T_AppPredTrue[of \<Gamma>' _ A' Fn' A1 T1 U _ T0' G'] by auto
hence L3:"\<Gamma>' \<turnstile> t1[x'::=e''] : T1 ; eff.TT" using `t1 = App f (Var z)` by auto
have "\<turnstile> S2 <: T'" using L1 `\<turnstile> T2 <: T'` by auto
hence "\<Gamma>'\<turnstile> (Iff t1 t2 t3)[x'::=e''] : T' ; eff.NE"
using L3 ` \<Gamma>'|+eff.TT \<turnstile> t2[x'::=e''] : S2 ; G2` by auto
hence ?thesis using `F' = NE` by auto
}
moreover
{
assume "~ (\<turnstile> T0' <: U) "" \<turnstile> T0' <: remove U T1'"
have 3:"(x', remove U T1') # \<Gamma>' \<turnstile> t3 : T3 ; F3 " using `?\<Gamma> |- TE U z \<turnstile> t3 : T3 ; F3` GB by auto
note Iff(3)[of x' "remove U T1'" \<Gamma>' T3 F3 e'' T0' G']
hence "\<exists>S3 G3. \<Gamma>' \<turnstile> t3[x'::=e''] : S3 ; G3 \<and> \<turnstile> S3 <: T3 \<and> \<turnstile> G3 <e: F3" using G4 prems `closed e''` 3 by auto
then obtain S3 G3 where L1:"\<Gamma>'|+ eff.FF \<turnstile> t3[x'::=e''] : S3 ; G3 "" \<turnstile> S3 <: T3 "" \<turnstile> G3 <e: F3" by auto
have "\<turnstile> T0' <: A1" using A B D `\<turnstile> T0' <: A` by auto
hence "\<Gamma>' \<turnstile> (App f (Var z))[x'::=e''] : T1 ; eff.FF" using A B D `\<turnstile> T0' <: A` `~ (\<turnstile> T0' <: U)`
using T_AppPredFalse[of \<Gamma>' _ A' Fn' A1 T1 U _ T0' G'] by auto
hence L3:"\<Gamma>' \<turnstile> t1[x'::=e''] : T1 ; eff.FF" using `t1 = App f (Var z)` by auto
have "\<turnstile> S3 <: T'" using L1 `\<turnstile> T3 <: T'` by auto
hence "\<Gamma>'\<turnstile> (Iff t1 t2 t3)[x'::=e''] : T' ; eff.NE"
using L3 ` \<Gamma>'|+eff.FF \<turnstile> t3[x'::=e''] : S3 ; G3` by auto
hence ?thesis using `F' = NE` by auto
}
ultimately show ?thesis using or by auto
qed
next
case False
from A False have "(Var z)[x'::=e''] = (Var z)" by auto
hence D:"\<Gamma>' \<turnstile> (Var z)[x'::=e''] : A ; VE z" using False A
proof -
have q1:"?\<Gamma> \<turnstile> Var z : A ; VE z" .
have "x' \<sharp> Var z" using trm.fresh False fresh_atm by auto
hence "\<Gamma>' \<turnstile> Var z : A ; VE z" using q1 fresh_weakening_cons `valid ((x',T1')# \<Gamma>')` by auto
thus ?thesis using `(Var z)[x'::=e''] = Var z` by auto
qed
from A B D have "\<Gamma>' \<turnstile> App (f[x'::=e'']) ((Var z)[x'::=e'']) : T1 ; TE U z" by auto
hence typetst: "\<Gamma>' \<turnstile> t1[x'::=e''] : T1 ; TE U z" using A by auto
have F:"?\<Gamma> |+ TE U z = (x',T1') # ?\<Gamma>1" using False by auto
hence H:"(x',T1') # ?\<Gamma>1 \<turnstile> t2 : T2 ; F2" using `?\<Gamma> |+ TE U z \<turnstile> t2 : T2 ; F2` by auto
hence K:"valid ?\<Gamma>1" using envop_valid `valid \<Gamma>'` by auto
have J:"?\<Gamma>1 \<turnstile> e'' : T0' ; G'" using K `valid \<Gamma>'` closed_any_env `closed e''` Iff by blast
have "x' \<sharp> ?\<Gamma>1" using Iff valid_elim[of x' T1' \<Gamma>'] envop_fresh[of x' \<Gamma>' restrict z U] `valid \<Gamma>'` by auto
hence "valid ((x',T1')#?\<Gamma>1)" using `valid ?\<Gamma>1` by auto
hence ex1:"\<exists>S2 G2. ?\<Gamma>1 \<turnstile> t2[x'::=e''] : S2 ; G2 \<and> \<turnstile> S2 <: T2 \<and> \<turnstile> G2 <e: F2"
using H J K Iff by auto
have G:"?\<Gamma> |- TE U z = (x',T1') # ?\<Gamma>2" using False by auto
hence H:"(x',T1') # ?\<Gamma>2 \<turnstile> t3 : T3 ; F3" using `?\<Gamma> |- TE U z \<turnstile> t3 : T3 ; F3` by auto
hence K:"valid ?\<Gamma>2" using envop_valid `valid \<Gamma>'` by auto
have J:"?\<Gamma>2 \<turnstile> e'' : T0' ; G'" using K `valid \<Gamma>'` closed_any_env `closed e''` Iff by blast
have "x' \<sharp> ?\<Gamma>2" using Iff valid_elim[of x' T1' \<Gamma>'] envop_fresh[of x' \<Gamma>' remove z U] `valid \<Gamma>'` by auto
hence "valid ((x',T1')#?\<Gamma>2)" using `valid ?\<Gamma>2` by auto
hence ex2:"\<exists>S3 G3. ?\<Gamma>2 \<turnstile> t3[x'::=e''] : S3 ; G3 \<and> \<turnstile> S3 <: T3 \<and> \<turnstile> G3 <e: F3"
using H J K Iff by auto
from ex1 obtain S2 G2 where 1:"?\<Gamma>1 \<turnstile> t2[x'::=e''] : S2 ; G2"" \<turnstile> S2 <: T'" using `\<turnstile> T2 <: T'` by auto
from ex2 obtain S3 G3 where 2:"?\<Gamma>2 \<turnstile> t3[x'::=e''] : S3 ; G3"" \<turnstile> S3 <: T'" using `\<turnstile> T3 <: T'` by auto
have 4:"?\<Gamma>1 = \<Gamma>' |+ (TE U z)" by auto
have 5:"?\<Gamma>2 = \<Gamma>' |- (TE U z)" by auto
have X:"!! G G' e T F. G = G' \<Longrightarrow> G \<turnstile> e : T ; F \<Longrightarrow> G' \<turnstile> e : T ; F" by auto
from 1 4 have 6:"\<Gamma>' |+ (TE U z) \<turnstile> t2[x'::=e''] : S2 ; G2" using X[of ?\<Gamma>1 "\<Gamma>' |+ (TE U z)" " t2[x'::=e'']" S2 G2]
by blast
from 2 5 have 7:"\<Gamma>' |- (TE U z) \<turnstile> t3[x'::=e''] : S3 ; G3" using X[of ?\<Gamma>2 "\<Gamma>' |- (TE U z)" " t3[x'::=e'']" S3 G3]
by blast
from typetst 1 2 6 7 have "\<Gamma>' \<turnstile> (Iff t1 t2 t3)[x'::=e''] : T' ; comb_eff (TE U z) G2 G3" by (auto simp del: comb_eff.simps)
thus ?thesis using `F' = NE` by auto
qed
qed
}
moreover
{
assume "\<exists> T1 T3 F3. (?\<Gamma> \<turnstile> t1 : T1 ; FF) \<and> ?\<Gamma> \<turnstile> t3 : T3 ; F3 \<and> \<turnstile> T3 <: T' \<and> F' = NE"
then obtain T1 T3 F3 where "?\<Gamma> \<turnstile> t1 : T1 ; FF" "?\<Gamma> \<turnstile> t3 : T3 ; F3" "\<turnstile> T3 <: T'" "F' = NE"
by auto
hence "\<exists>S1 G1. \<Gamma>' \<turnstile> t1[x'::=e''] : S1 ; G1 \<and> \<turnstile> S1 <: T1 \<and> \<turnstile> G1 <e: FF" using Iff by auto
then obtain S1 G1 where B:"\<Gamma>' \<turnstile> t1[x'::=e''] : S1 ; G1 "" \<turnstile> S1 <: T1 "" \<turnstile> G1 <e: FF" by auto
hence C:"\<Gamma>' \<turnstile> t1[x'::=e''] : S1 ; FF " using B no_sub_FF by auto
from prems have "\<exists>S3 G3. \<Gamma>' \<turnstile> t3[x'::=e''] : S3 ; G3 \<and> \<turnstile> S3 <: T3 \<and> \<turnstile> G3 <e: F3" using Iff by auto
then obtain S3 G3 where D:"\<Gamma>' \<turnstile> t3[x'::=e''] : S3 ; G3 ""\<turnstile> S3 <: T3" by auto
from B C D have "\<Gamma>' \<turnstile> (Iff (t1[x'::=e'']) (t2[x'::=e'']) (t3[x'::=e''])) : S3 ; eff.NE" by auto
hence ?thesis using `\<turnstile> T3 <: T'` `\<turnstile> S3 <: T3` `F' = NE` by auto
}
moreover
{
assume "\<exists> T1 T2 F2. (?\<Gamma> \<turnstile> t1 : T1 ; TT) \<and> ?\<Gamma> \<turnstile> t2 : T2 ; F2 \<and> \<turnstile> T2 <: T' \<and> F' = NE"
then obtain T1 T2 F2 where "?\<Gamma> \<turnstile> t1 : T1 ; TT" "?\<Gamma> \<turnstile> t2 : T2 ; F2" "\<turnstile> T2 <: T'" "F' = NE"
by auto
hence "\<exists>S1 G1. \<Gamma>' \<turnstile> t1[x'::=e''] : S1 ; G1 \<and> \<turnstile> S1 <: T1 \<and> \<turnstile> G1 <e: TT" using Iff by auto
then obtain S1 G1 where B:"\<Gamma>' \<turnstile> t1[x'::=e''] : S1 ; G1 "" \<turnstile> S1 <: T1 "" \<turnstile> G1 <e: TT" by auto
hence C:"\<Gamma>' \<turnstile> t1[x'::=e''] : S1 ; TT " using B no_sub_TT by auto
from prems have "\<exists>S2 G2. \<Gamma>' \<turnstile> t2[x'::=e''] : S2 ; G2 \<and> \<turnstile> S2 <: T2 \<and> \<turnstile> G2 <e: F2" using Iff by auto
then obtain S2 G2 where D:"\<Gamma>' \<turnstile> t2[x'::=e''] : S2 ; G2 ""\<turnstile> S2 <: T2" by auto
from B C D have "\<Gamma>' \<turnstile> (Iff (t1[x'::=e'']) (t2[x'::=e'']) (t3[x'::=e''])) : S2 ; eff.NE" by auto
hence ?thesis using `\<turnstile> T2 <: T'` `\<turnstile> S2 <: T2` `F' = NE` by auto
}
ultimately show ?thesis using A by blast
qed
qed
lemma subst_produces_TT:
assumes ty:"(x,T0)#\<Gamma> \<turnstile> e : T ; TE S x"
and vty:"\<Gamma> \<turnstile> v : T0' ; F"
and A:"\<turnstile> T0' <: T0"
and B:"valid ((x,T0)#\<Gamma>)"
and C:"closed v" and D:"v : values"
and E:"\<turnstile> T0' <: S"
shows "EX T'. \<Gamma> \<turnstile> e[x::=v] : T' ; TT \<and> \<turnstile> T' <: T"
proof -
obtain f A A1 Fn Sa B
where
eq:"e = App f (Var x)" and fty:"(x, T0) # \<Gamma> \<turnstile> f : B ; Fn "
and bsub:" \<turnstile> B <: A1 \<rightarrow> T : Latent S " and xty:" (x, T0) # \<Gamma> \<turnstile> Var x : A ; VE x "
and asub:" \<turnstile> A <: A1"
using te_ty_elim[OF ty] by auto
note preserve_subst[OF fty vty A B C D]
then obtain T' F' where
X1:"\<Gamma> \<turnstile> f[x::=v] : T' ; F' " and " \<turnstile> T' <: B "" \<turnstile> F' <e: Fn"
by auto
hence X2:"\<turnstile> T' <: A1 \<rightarrow> T : Latent S" using bsub by auto
have "(Var x)[x::=v] = v" by simp
hence X3:"\<Gamma> \<turnstile> (Var x)[x::=v] : T0' ; F" using vty by auto
have "(x, T0) # \<Gamma> \<turnstile> Var x : T0 ; VE x" using `valid ((x, T0) # \<Gamma>)` by auto
hence "T0 = A" using xty unique_var_typing by auto
hence "\<turnstile> T0' <: A1" using A asub by auto
from X1 X2 X3 show ?thesis using T_AppPredTrue[OF X1 X2 X3 `\<turnstile> T0' <: A1` E] using asub E eq
by auto
qed
lemma subst_produces_FF:
assumes ty:"(x,T0)#\<Gamma> \<turnstile> e : T ; TE S x"
and vty:"\<Gamma> \<turnstile> v : T0' ; F"
and A:"\<turnstile> T0' <: T0"
and B:"valid ((x,T0)#\<Gamma>)"
and C:"closed v" and D:"v : values"
and E:"~ \<turnstile> T0' <: S"
shows "EX T'. \<Gamma> \<turnstile> e[x::=v] : T' ; FF \<and> \<turnstile> T' <: T"
proof -
obtain f A A1 Fn Sa B
where
eq:"e = App f (Var x)" and fty:"(x, T0) # \<Gamma> \<turnstile> f : B ; Fn "
and bsub:" \<turnstile> B <: A1 \<rightarrow> T : Latent S " and xty:" (x, T0) # \<Gamma> \<turnstile> Var x : A ; VE x "
and asub:" \<turnstile> A <: A1"
using te_ty_elim[OF ty] by auto
note preserve_subst[OF fty vty A B C D]
then obtain T' F' where
X1:"\<Gamma> \<turnstile> f[x::=v] : T' ; F' " and " \<turnstile> T' <: B "" \<turnstile> F' <e: Fn"
by auto
hence X2:"\<turnstile> T' <: A1 \<rightarrow> T : Latent S" using bsub by auto
have veq:"(Var x)[x::=v] = v" by simp
hence X3:"\<Gamma> \<turnstile> (Var x)[x::=v] : T0' ; F" using vty by auto
have "(x, T0) # \<Gamma> \<turnstile> Var x : T0 ; VE x" using `valid ((x, T0) # \<Gamma>)` by auto
hence "T0 = A" using xty unique_var_typing by auto
hence "\<turnstile> T0' <: A1" using A asub by auto
from X1 X2 X3 show ?thesis using T_AppPredFalse[OF X1 X2 X3 `\<turnstile> T0' <: A1` E] using asub E eq C D veq
by auto
qed
inductive_cases beta_cases:"App (Abs x b T) v \<hookrightarrow> e "
inductive_cases beta_TT_cases:"\<Gamma> \<turnstile> App (Abs x b T) v : T' ; TT"
inductive_cases beta_FF_cases:"\<Gamma> \<turnstile> App (Abs x b T) v : T' ; FF"
lemma preserve_red:
assumes typed:"\<Gamma> \<turnstile> e : t ; eff" and cl:"closed e"
and red:"e \<hookrightarrow> e'" and val:"valid \<Gamma>"
shows "EX t' eff'. \<Gamma> \<turnstile> e' : t' ; eff' \<and> \<turnstile> t' <: t \<and> \<turnstile> eff' <e: eff "
using red typed cl val red
proof (nominal_induct e e' avoiding: \<Gamma> t rule: reduce.strong_induct)
case (e_delta v' p v \<Gamma> T)
thm app_ty_elim[of \<Gamma> "(BI p)" v' T eff]
hence "\<exists>T0 T0' T1 le eff' eff'' U. \<Gamma> \<turnstile> BI p : U ; eff' \<and> \<Gamma> \<turnstile> v' : T0' ; eff'' \<and> \<turnstile> U <: T0 \<rightarrow> T1 : le
\<and> \<turnstile> T0' <: T0 \<and> T1 = T"
using app_ty_elim[of \<Gamma> "(BI p)" v' T eff] by simp
then obtain T0 T0' T1 le eff' eff'' U where
A1:" \<Gamma> \<turnstile> BI p : U ; eff'" and A2:"\<Gamma> \<turnstile> v' : T0' ; eff''" and A3:"\<turnstile> T0' <: T0"
and A4:"T1 = T" and A5:"\<turnstile> U <: T0 \<rightarrow> T1 : le"
by auto
hence "U = \<Delta>\<^isub>\<tau> p" using e_delta typing_bi[of \<Gamma> p _ eff'] by simp
then obtain A0 A1 LA where "\<Delta>\<^isub>\<tau> p = A0 \<rightarrow> A1 : LA" "U = A0 \<rightarrow> A1 : LA" by (nominal_induct p rule: builtin.induct) auto
hence "\<turnstile> A0 \<rightarrow> A1 : LA <: T0 \<rightarrow> T1 : le" using `\<turnstile> U <: T0 \<rightarrow> T1 : le` by auto
hence B:"le = LA \<or> le = latent_eff.NE" "\<turnstile> T0 <: A0" "\<turnstile> A1 <: T1" using arr_sub_arr_cases[of A0 A1 LA T0 T1 le] by auto
have C1:" \<Gamma> \<turnstile> App (BI p) v' : T1 ; eff" using prems `T1 = T` by auto
have C2:"\<turnstile> T0' <: A0" and C3:"\<turnstile> A1 <: T " using B A3 A4 by auto
have C4:"valid \<Gamma>" .
note delta_soundness[OF `\<Delta>\<^isub>\<tau> p = A0 \<rightarrow> A1 : LA` `v' : values` `\<Gamma> \<turnstile> v' : T0' ; eff''` C2 e_delta(3) C3 `\<Delta> p v' = Some v` C4]
then obtain A1' eff' where "\<Gamma> \<turnstile> v : A1' ; eff' "" \<turnstile> eff' <e: eff" "\<turnstile> A1' <: A1" by auto
thus ?case using C3 by auto
next
case (e_if_false thn els \<Gamma>' t')
have "eff = NE" using if_false_ty_elim[of _ _ _ _ eff] e_if_false by auto
have " \<exists>T0 eff'. \<Gamma>' \<turnstile> els : T0 ; eff' \<and> \<turnstile> T0 <: t' " using if_false_ty_elim[of \<Gamma>' thn els t' eff] e_if_false by auto
then obtain T0 eff' where f:"\<Gamma>' \<turnstile> els : T0 ; eff'" and g:"\<turnstile> T0 <: t'" by auto
have "closed els" using e_if_false closed_def trm.supp by auto
hence "simple_eff eff'" using closed_eff f by auto
hence h:"\<turnstile> eff' <e: eff" using simple_eff_below_ne `eff = NE` by auto
thus ?case using f g by auto
next
case (e_if_true v thn els \<Gamma>' t')
have "eff = NE" using if_true_ty_elim[of \<Gamma>' v thn els _ eff] e_if_true by auto
have " \<exists>T0 eff'. \<Gamma>' \<turnstile> thn : T0 ; eff' \<and> \<turnstile> T0 <: t' " using if_true_ty_elim[of \<Gamma>' v thn els t' eff] e_if_true by auto
then obtain T0 eff' where f:"\<Gamma>' \<turnstile> thn : T0 ; eff'" and g:"\<turnstile> T0 <: t'" by auto
have "closed thn" using e_if_true closed_def trm.supp by auto
hence "simple_eff eff'" using closed_eff f by auto
hence h:"\<turnstile> eff' <e: eff" using `eff = NE` by auto
thus ?case using f g by auto
next
case (e_beta v x T b \<Gamma>' T')
hence "simple_eff eff" using closed_eff by auto
thm app_ty_elim[of \<Gamma>' "(Lam[x:T].b)" v t eff]
(* hence "eff = NE" using app_abs_ty_elim_eff by auto *)
from e_beta have "\<exists>T0 T0' T1 le eff' eff'' U. \<Gamma>' \<turnstile> Abs x b T : U ; eff' \<and> \<Gamma>' \<turnstile> v : T0' ; eff''
\<and> \<turnstile> T0' <: T0 \<and> T1 = T' \<and> \<turnstile> U <: T0 \<rightarrow> T1 : le"
using app_ty_elim[of \<Gamma>' "Abs x b T" v T' eff] by blast
then obtain T0 T0' T1 le eff' eff'' U where " \<Gamma>' \<turnstile> Lam[x:T].b :U; eff'" and "\<Gamma>' \<turnstile> v : T0' ; eff''"
and "\<turnstile> T0' <: T0" and "T1 = T'" and usub:"\<turnstile> U <: T0 \<rightarrow> T1 : le " by auto
hence "\<exists>T1a eff2 L S. (x,T)#\<Gamma>' \<turnstile> b : T1a ; eff2 \<and> U = T \<rightarrow> T1a : L \<and> (L = Latent S \<and> eff2 = TE S x \<or> L = latent_eff.NE)"
using abs_ty_elim[of \<Gamma>' x b T "U" eff'] e_beta `x \<sharp> \<Gamma>'` by auto
then obtain T1a eff2 L S where bty:"(x,T)#\<Gamma>' \<turnstile> b : T1a ; eff2" and ueq:"U = T \<rightarrow> T1a : L"
and "(L = Latent S \<and> eff2 = TE S x \<or> L = latent_eff.NE)"
by auto
have "closed v" using e_beta closed_def trm.supp by auto
have "v : values" using e_beta beta_cases[of _ _ _ v _ "v : values"] trm.inject by auto
have "\<turnstile> T0 <: T" using usub ueq arr_sub_arr_cases[of T T1a L T0 T1 le] by auto
have "\<turnstile> T1a <: T1" using usub ueq arr_sub_arr_cases[of T T1a L T0 T1 le] by auto
hence "\<turnstile> T1a <: T'" using `T1 = T'` by simp
have "\<turnstile> T0' <: T" using ` \<turnstile> T0' <: T0` `\<turnstile>T0<:T` by auto
have " \<exists>T'a F'. \<Gamma>' \<turnstile> b[x::=v] : T'a ; F' \<and> \<turnstile> T'a <: T1a"
using preserve_subst[of x T \<Gamma>' b T1a eff2 v T0' eff''] `\<Gamma>' \<turnstile> v : T0' ; eff''` bty `\<turnstile> T0' <: T` `x \<sharp> \<Gamma>'` `valid \<Gamma>'`
`closed v` `v : values`
by auto
then obtain T'a F' where a:"\<Gamma>' \<turnstile> b[x::=v] : T'a ; F'" and b:"\<turnstile> T'a <: T1a" by auto
have "closed (b[x::=v])" using e_beta reduce_closed by blast
hence c:"simple_eff F'" using a closed_eff by auto
have ?case using `simple_eff eff` e_beta a b
proof (induct eff rule: simple_eff_cases)
case NE thus ?case using simple_eff_below_ne[of F'] c a b `\<turnstile> T1a <: T'` by auto
next
case TT
obtain U T0 Ta S eff1 eff2 where X1:"\<Gamma>' \<turnstile> (Lam [x:T].b) : U ; eff1 " and X2:"\<turnstile> U <: T0 \<rightarrow> T' : Latent S" and
X3:" \<Gamma>' \<turnstile> v : Ta ; eff2 " "\<turnstile> Ta <: T0"" \<turnstile> Ta <: S"
using trm.inject beta_TT_cases[OF TT(5), of thesis]
by auto
note abs_ty_elim[OF X1 `x \<sharp> \<Gamma>'`]
then obtain T1' eff' L S' where f:
"(x, T) # \<Gamma>' \<turnstile> b : T1' ; eff' "
" U = T \<rightarrow> T1' : L "
" eff1 = eff.TT "
" (eff' = TE S' x \<and> L = Latent S' \<or> L = latent_eff.NE)"
by auto
hence "eff' = TE S x" "\<turnstile> T0 <: T" "\<turnstile> T1' <: T'"using `U = T \<rightarrow> T1' : L` X2 using arr_sub_arr_cases[of T T1' L T0 T' "Latent S"]
by auto
hence X4:"(x, T) # \<Gamma>' \<turnstile> b : T1' ; TE S x" using f by auto
have valcons:"valid ((x,T)#\<Gamma>')" using `valid \<Gamma>'` `x \<sharp> \<Gamma>'` by auto
have "\<turnstile> Ta <: T" using `\<turnstile> Ta <: T0``\<turnstile> T0 <: T` by auto
have "EX T2'. \<Gamma>' \<turnstile> b[x::=v] : T2' ; TT \<and> \<turnstile> T2' <: T1'" using X3
using subst_produces_TT[OF X4 `\<Gamma>' \<turnstile> v : Ta ; eff2` `\<turnstile> Ta <: T` valcons ` closed v`` v \<in> values` `\<turnstile> Ta <: S`]
by auto
thus ?case using `\<turnstile> T1' <: T'` by auto
next
case FF
obtain U T0 Ta S eff1 eff2 where X1:"\<Gamma>' \<turnstile> (Lam [x:T].b) : U ; eff1 " and X2:"\<turnstile> U <: T0 \<rightarrow> T' : Latent S" and
X3:" \<Gamma>' \<turnstile> v : Ta ; eff2 " "\<turnstile> Ta <: T0""~ \<turnstile> Ta <: S"
using trm.inject beta_FF_cases[OF FF(5), of thesis]
by auto
note abs_ty_elim[OF X1 `x \<sharp> \<Gamma>'`]
then obtain T1' eff' L S' where f:
"(x, T) # \<Gamma>' \<turnstile> b : T1' ; eff' "
" U = T \<rightarrow> T1' : L "
" eff1 = eff.TT "
" (eff' = TE S' x \<and> L = Latent S' \<or> L = latent_eff.NE)"
by auto
hence "eff' = TE S x" "\<turnstile> T0 <: T" "\<turnstile> T1' <: T'" using `U = T \<rightarrow> T1' : L` X2 using arr_sub_arr_cases[of T T1' L T0 T' "Latent S"]
by auto
hence X4:"(x, T) # \<Gamma>' \<turnstile> b : T1' ; TE S x" using f by auto
have valcons:"valid ((x,T)#\<Gamma>')" using `valid \<Gamma>'` `x \<sharp> \<Gamma>'` by auto
have "\<turnstile> Ta <: T" using `\<turnstile> Ta <: T0``\<turnstile> T0 <: T` by auto
hence "EX T2'. \<Gamma>' \<turnstile> b[x::=v] : T2' ; FF \<and> \<turnstile> T2' <: T1'" using X3
using subst_produces_FF[OF X4 `\<Gamma>' \<turnstile> v : Ta ; eff2` `\<turnstile> Ta <: T` valcons ` closed v`` v \<in> values` _]
by auto
thus ?case using `\<turnstile> T1' <: T'` by auto
qed
thus ?case .
qed
lemma value_no_ctxt:
assumes "v : values" and "v = E t" and "E : ctxt"
shows "E = (% t . t)"
using prems
proof (induct)
case bi_value show ?case using `E : ctxt` bi_value
by (induct E rule: ctxt.induct) (auto simp add: trm.inject)
next
case num_value show ?case using `E : ctxt` num_value
by (induct E rule: ctxt.induct) (auto simp add: trm.inject)
next
case abs_value show ?case using `E : ctxt` abs_value
by (induct E rule: ctxt.induct) (auto simp add: trm.inject)
next
case bool_value show ?case using `E : ctxt` bool_value
by (induct E rule: ctxt.induct) (auto simp add: trm.inject)
qed
lemma subst_in_ctxt_preserves_type:
assumes a:"\<Gamma> \<turnstile> u : T ; F"
and b:"C : ctxt"
and c:"u = C e"
and "~ (e : values)"
and "closed (C e)" and "closed (C e')"
and "!! T0 F0 . \<Gamma> \<turnstile> e : T0 ; F0 \<Longrightarrow> EX T1 F1. \<Gamma> \<turnstile> e' : T1 ; F1 \<and> \<turnstile> T1 <: T0 \<and> \<turnstile> F1 <e: F0"
shows "EX S G. \<Gamma> \<turnstile> C e' : S ; G \<and> \<turnstile> S <: T \<and> \<turnstile> G <e: F"
using b prems
proof (induct C arbitrary: u e e' T F rule: ctxt.induct)
case C_Hole
hence "\<Gamma> \<turnstile> e : T ; F" using C_Hole by simp
hence "EX S G. \<Gamma> \<turnstile> e' : S; G \<and> \<turnstile> S <: T \<and> \<turnstile> G <e: F" using C_Hole by auto
thus ?case by simp
next
case (C_App1 E arg u' t t' T' F')
have A:"closed (E t)" and B:"closed (E t')" using C_App1 closed_def trm.supp by auto
have C:"\<Gamma> \<turnstile> App (E t) arg : T' ; F'" using C_App1 by auto
hence D:"simple_eff F'" using C_App1 closed_eff by auto
thus ?case using C_App1 A B C
proof (induct rule: simple_eff_cases)
case NE
hence "EX T0 T0' T1 le eff' eff'' U. \<Gamma> \<turnstile> E t :U ; eff' \<and> \<Gamma> \<turnstile> arg : T0' ; eff'' \<and> \<turnstile> U <: T0 \<rightarrow> T1 : le
\<and> \<turnstile> T0' <: T0 \<and> T1 = T'"
using app_ty_elim by auto
then obtain T0 T0' le eff' eff'' U
where a:"\<Gamma> \<turnstile> E t : U ; eff'" and b:"\<Gamma> \<turnstile> arg : T0' ; eff''" and c:"\<turnstile> T0' <: T0" and d:"\<turnstile> U <: T0 \<rightarrow> T' : le"
by auto
have "\<exists>S G. \<Gamma> \<turnstile> E t' : S ; G \<and> \<turnstile> S <: U \<and> \<turnstile> G <e: eff'"
using C_App1(2)[of "E t" _ eff' t t'] `E : ctxt` `closed (E t)` `closed (E t')` C_App1(8) a
`t \<notin> values` C_App1 by auto
then obtain S G where et'ty:"\<Gamma> \<turnstile> E t' : S ; G " and subarr:" \<turnstile> S <: U " and "\<turnstile> G <e: eff'" by auto
hence "\<Gamma> \<turnstile> App (E t') arg : T' ; NE" using b c d by auto
thus ?case by auto
next
case FF
have "EX S T0 T0' le F1 F2 U. \<Gamma> \<turnstile> E t : U ; F1 \<and> \<Gamma> \<turnstile> arg : T0' ; F2 \<and> \<turnstile> T0' <: T0 \<and> le = Latent S \<and>
~ (\<turnstile> T0' <: S) \<and> arg : values \<and> closed arg \<and> \<turnstile> U <: T0 \<rightarrow> T' : le"
using `\<Gamma> \<turnstile> App (E t) arg : T' ; FF` app_ty_ff_elim[of \<Gamma> "E t" arg T'] by blast
then obtain S T0 T0' F1 F2 U where a:"\<Gamma> \<turnstile> E t :U ; F1" and b:"\<Gamma> \<turnstile> arg : T0' ; F2 "
and c:"\<turnstile> T0' <: T0 " and d:" ~ (\<turnstile> T0' <: S)" "closed arg" "arg : values" " \<turnstile> U <: T0 \<rightarrow> T' : Latent S"
by auto
have "\<exists>S' G. \<Gamma> \<turnstile> E t' : S' ; G \<and> \<turnstile> S' <: U \<and> \<turnstile> G <e: F1"
using C_App1(2)[of "E t" U F1 t t'] `E : ctxt` `closed (E t)` `closed (E t')` C_App1(8) a C_App1 by auto
then obtain S' G where et'ty:"\<Gamma> \<turnstile> E t' : S' ; G " and subarr:" \<turnstile> S' <: U" and "\<turnstile> G <e: F1" by auto
hence "\<Gamma> \<turnstile> App (E t') arg : T' ; FF" using b c d by auto
thus ?case by auto
next
case TT
have "EX S T0 T0' le F1 F2 U. \<Gamma> \<turnstile> E t : U ; F1 \<and> \<Gamma> \<turnstile> arg : T0' ; F2 \<and> \<turnstile> T0' <: T0 \<and>
le = Latent S \<and> \<turnstile> T0' <: S \<and> \<turnstile> U <: T0 \<rightarrow> T' : le"
using `\<Gamma> \<turnstile> App (E t) arg : T' ; TT` app_ty_tt_elim[of \<Gamma> "E t" arg T'] by blast
then obtain S T0 T0' F1 F2 U where a:"\<Gamma> \<turnstile> E t : U ; F1" and b:"\<Gamma> \<turnstile> arg : T0' ; F2 "
and c:"\<turnstile> T0' <: T0 " and d:"\<turnstile> T0' <: S" "\<turnstile> U <: T0 \<rightarrow> T' : Latent S"
by auto
have "\<exists>S' G. \<Gamma> \<turnstile> E t' : S' ; G \<and> \<turnstile> S' <: U \<and> \<turnstile> G <e: F1"
using C_App1(2)[of "E t" U F1 t t'] `E : ctxt` `closed (E t)` `closed (E t')` C_App1 a by auto
then obtain S' G where et'ty:"\<Gamma> \<turnstile> E t' : S' ; G " and subarr:" \<turnstile> S' <: U " and "\<turnstile> G <e: F1" by auto
hence "\<Gamma> \<turnstile> App (E t') arg : T' ; TT" using b c d by auto
thus ?case by auto
qed
next
case (C_App2 E v u' t t' T' F')
have A:"closed (E t)" and B:"closed (E t')" using C_App2 closed_def trm.supp by auto
have C:"\<Gamma> \<turnstile> App v (E t) : T' ; F'" using C_App2 by auto
hence D:"simple_eff F'" using C_App2 closed_eff by auto
thus ?case using C_App2 A B C
proof (induct rule: simple_eff_cases)
case NE
have "\<exists>T0 T0' T1 le eff' eff'' U. \<Gamma> \<turnstile> v : U ; eff' \<and> \<Gamma> \<turnstile> E t : T0' ; eff'' \<and> \<turnstile> T0' <: T0
\<and> T1 = T' \<and> \<turnstile> U <: T0 \<rightarrow> T1 : le"
using app_ty_elim[of \<Gamma> v "E t" T' F'] `\<Gamma> \<turnstile> App v (E t) : T' ; F'` by blast
then obtain T0 T0' le eff' eff'' U
where a:"\<Gamma> \<turnstile> v : U ; eff'" " \<Gamma> \<turnstile> E t : T0' ; eff'' " "\<turnstile> T0' <: T0" "\<turnstile> U <: T0 \<rightarrow> T' : le" by auto
hence "\<exists>S G. \<Gamma> \<turnstile> E t' : S ; G \<and> \<turnstile> S <: T0' \<and> \<turnstile> G <e: eff''" using NE(2)[of "E t" T0' eff'' t t'] NE by auto
then obtain S G where "\<Gamma> \<turnstile> E t' : S ; G "" \<turnstile> S <: T0'" by auto
hence "\<Gamma> \<turnstile> App v (E t') : T' ; eff.NE" using a `\<turnstile> T0' <: T0` by auto
thus ?case by auto
next
case FF
have "\<exists>S T0 T0' le eff' eff'' U. \<Gamma> \<turnstile> v : U ; eff' \<and> \<Gamma> \<turnstile> E t : T0' ; eff'' \<and> \<turnstile> T0' <: T0 \<and> le = Latent S \<and> ~ (\<turnstile> T0' <: S) \<and> E t : values \<and> closed (E t) \<and> \<turnstile> U <: T0 \<rightarrow> T' : le"
using app_ty_ff_elim[of \<Gamma> v "E t" T'] `\<Gamma> \<turnstile> App v (E t) : T' ; FF` by blast
then obtain S T0 T0' le eff' eff'' U
where "\<Gamma> \<turnstile> v : U ; eff' "" \<Gamma> \<turnstile> E t : T0' ; eff'' "" \<turnstile> T0' <: T0 " " ~ (\<turnstile> T0' <: S) "
" E t : values "" closed (E t)"
by auto
hence "E = (% t. t)" using value_no_ctxt[of "E t" E t] `E : ctxt` by simp
hence "t : values" using `E t : values` by simp
thus ?case using `t \<notin> values` by auto
next
case TT
have "\<exists>S T0 T0' le eff' eff'' U. \<Gamma> \<turnstile> v : U ; eff' \<and> \<Gamma> \<turnstile> E t : T0' ; eff'' \<and> \<turnstile> T0' <: T0 \<and>
le = Latent S \<and> \<turnstile> T0' <: S \<and> \<turnstile> U <: T0 \<rightarrow> T' : le"
using app_ty_tt_elim[of \<Gamma> v "E t" T'] `\<Gamma> \<turnstile> App v (E t) : T' ; TT` by blast
then obtain S T0 T0' le eff' eff'' U
where a:"\<Gamma> \<turnstile> v : U ; eff' "" \<Gamma> \<turnstile> E t : T0' ; eff'' "" \<turnstile> T0' <: T0 " " \<turnstile> T0' <: S" "\<turnstile> U <: T0 \<rightarrow> T' : Latent S"
by auto
hence "\<exists>S' G. \<Gamma> \<turnstile> E t' : S' ; G \<and> \<turnstile> S' <: T0' \<and> \<turnstile> G <e: eff''" using TT(2)[of "E t" T0' eff'' t t'] TT by auto
then obtain S' G where b:"\<Gamma> \<turnstile> E t' : S' ; G "" \<turnstile> S' <: T0'" by auto
have "\<turnstile> S' <: S" using ` \<turnstile> S' <: T0'` `\<turnstile> T0' <: S` by auto
have "\<turnstile> S' <: T0" using `\<turnstile> S' <: T0'` `\<turnstile> T0' <: T0` by auto
hence "\<Gamma> \<turnstile> App v (E t') : T' ; TT" using b T_AppPredTrue[OF a(1) a(5) b(1) `\<turnstile> S' <: T0` ] using `\<turnstile> S' <: S` by auto
thus ?case by auto
qed
next
case (C_Iff E thn els u' t t' T' F')
have A:"closed (E t)" and B:"closed (E t')" using C_Iff closed_def trm.supp by auto
have C:"\<Gamma> \<turnstile> Iff (E t) thn els: T' ; F'" using C_Iff by auto
hence
bigor:
"(\<exists>T1 T2 T3 F1 F2 F3. \<Gamma> \<turnstile> E t : T1 ; F1 \<and> \<Gamma> |+ F1 \<turnstile> thn : T2 ; F2 \<and> \<Gamma> |- F1 \<turnstile> els : T3 ; F3 \<and> \<turnstile> T2 <: T' \<and> \<turnstile> T3 <: T' \<and> F' = eff.NE) \<or>
(\<exists>T1 T3 F3. \<Gamma> \<turnstile> E t : T1 ; FF \<and> \<Gamma> \<turnstile> els : T3 ; F3 \<and> \<turnstile> T3 <: T' \<and> F' = eff.NE) \<or>
(\<exists>T1 T2 F2. \<Gamma> \<turnstile> E t : T1 ; TT \<and> \<Gamma> \<turnstile> thn : T2 ; F2 \<and> \<turnstile> T2 <: T' \<and> F' = eff.NE)"
using if_ty_elim[of \<Gamma> "(E t)" thn els T' F'] by auto
thus ?case
proof -
{
assume "(\<exists>T1 T2 T3 F1 F2 F3. \<Gamma> \<turnstile> E t : T1 ; F1 \<and> \<Gamma> |+ F1 \<turnstile> thn : T2 ; F2 \<and> \<Gamma> |- F1 \<turnstile> els : T3 ; F3 \<and> \<turnstile> T2 <: T' \<and> \<turnstile> T3 <: T' \<and> F' = eff.NE)"
then obtain T1 T2 T3 F1 F2 F3 where
P:"\<Gamma> \<turnstile> E t : T1 ; F1""\<Gamma> |+ F1 \<turnstile> thn : T2 ; F2""\<Gamma> |- F1 \<turnstile> els : T3 ; F3""\<turnstile> T2 <: T'""\<turnstile> T3 <: T'""F' = eff.NE"
by auto
have "closed (E t)" and "closed (E t')" using prems trm.supp closed_def by auto
hence "EX T1' F1'. \<Gamma> \<turnstile> E t' : T1' ; F1' \<and> \<turnstile> T1' <: T1 \<and> \<turnstile> F1' <e: F1"
using C_Iff(2)[of "E t" T1 F1 t t'] C_Iff P by auto
then obtain T1' F1' where Q:"\<Gamma> \<turnstile> E t' : T1' ; F1' "" \<turnstile> T1' <: T1 "" \<turnstile> F1' <e: F1" by auto
have "simple_eff F1'" and "simple_eff F1" using `closed (E t)` `closed (E t')` P Q closed_eff by auto
hence "\<Gamma> |+ F1 = \<Gamma>" "\<Gamma> |- F1 = \<Gamma>" "\<Gamma> |+ F1' = \<Gamma>" "\<Gamma> |- F1' = \<Gamma>" by (auto simp add: env_plus_simple_eff)
hence "\<Gamma> |+ F1' \<turnstile> thn : T2 ; F2 " "\<Gamma> |- F1' \<turnstile> els : T3 ; F3" using P by auto
hence "\<Gamma> \<turnstile> Iff (E t') thn els : T'; comb_eff F1' F2 F3" using `\<Gamma> \<turnstile> E t' : T1' ; F1'` ` \<turnstile> T2 <: T' `` \<turnstile> T3 <: T'`
by (auto simp del: comb_eff.simps)
hence ?thesis using `F' = NE` by auto
}
moreover
{
assume "(\<exists>T1 T3 F3. \<Gamma> \<turnstile> E t : T1 ; FF \<and> \<Gamma> \<turnstile> els : T3 ; F3 \<and> \<turnstile> T3 <: T' \<and> F' = eff.NE)"
then obtain T1 T3 F3 where P:"\<Gamma> \<turnstile> E t : T1 ; FF "" \<Gamma> \<turnstile> els : T3 ; F3 "" \<turnstile> T3 <: T'"" F' = eff.NE"
by auto
have "closed (E t)" and "closed (E t')" using prems trm.supp closed_def by auto
hence "EX T1' F1'. \<Gamma> \<turnstile> E t' : T1' ; F1' \<and> \<turnstile> T1' <: T1 \<and> \<turnstile> F1' <e: FF"
using C_Iff(2)[of "E t" T1 FF t t'] C_Iff P by auto
then obtain T1' F1' where Q:"\<Gamma> \<turnstile> E t' : T1' ; F1' "" \<turnstile> T1' <: T1 "" \<turnstile> F1' <e: FF" by auto
have "F1' = FF" using Q no_sub_FF[of F1' FF] by simp
hence "\<Gamma> \<turnstile> E t' : T1' ; FF " using Q by auto
hence ?thesis using P by auto
}
moreover
{
assume "(\<exists>T1 T2 F2. \<Gamma> \<turnstile> E t : T1 ; TT \<and> \<Gamma> \<turnstile> thn : T2 ; F2 \<and> \<turnstile> T2 <: T' \<and> F' = eff.NE)"
then obtain T1 T2 F2 where P:"\<Gamma> \<turnstile> E t : T1 ; TT "" \<Gamma> \<turnstile> thn : T2 ; F2 "" \<turnstile> T2 <: T'"" F' = eff.NE"
by auto
have "closed (E t)" and "closed (E t')" using prems trm.supp closed_def by auto
hence "EX T1' F1'. \<Gamma> \<turnstile> E t' : T1' ; F1' \<and> \<turnstile> T1' <: T1 \<and> \<turnstile> F1' <e: TT"
using C_Iff(2)[of "E t" T1 TT t t'] C_Iff P by auto
then obtain T1' F1' where Q:"\<Gamma> \<turnstile> E t' : T1' ; F1' "" \<turnstile> T1' <: T1 "" \<turnstile> F1' <e: TT" by auto
have "F1' = TT" using Q no_sub_TT[of F1' TT] by simp
hence "\<Gamma> \<turnstile> E t' : T1' ; TT " using Q by auto
hence ?thesis using P by auto
}
ultimately show ?thesis using bigor by blast
qed
qed
lemma typing_ctxt:
assumes a:"\<Gamma> \<turnstile> C L : T ; eff"
and b:"C : ctxt"
shows "EX T' eff'. \<Gamma> \<turnstile> L : T' ; eff'"
using b a
proof(induct C arbitrary: T eff rule: ctxt.induct )
case C_Hole thus ?case by auto
next
case (C_App1 C' arg S)
hence ih: "!! T0 eff. \<Gamma> \<turnstile> C' L : T0 ; eff \<Longrightarrow> \<exists>T' a. \<Gamma> \<turnstile> L : T' ; a" by simp
obtain T0 T0' T1 le eff' eff'' U where "\<Gamma> \<turnstile> C' L : U ; eff'" "\<Gamma> \<turnstile> arg : T0' ; eff''" "\<turnstile> T0' <: T0 \<and> T1 = S"
"\<turnstile> U <: T0 \<rightarrow> T1 : le"
using app_ty_elim[of \<Gamma> "C' L" arg S eff] ` \<Gamma> \<turnstile> App (C' L) arg : S ; eff` by blast
thus ?case using ih by auto
next
case (C_App2 C' rator S F)
hence ih: "!! T0 eff. \<Gamma> \<turnstile> C' L : T0 ; eff \<Longrightarrow> \<exists>T' a. \<Gamma> \<turnstile> L : T' ; a" by simp
obtain T0 T0' T1 le eff' eff'' U where "\<Gamma> \<turnstile> rator : U ; eff'" "\<Gamma> \<turnstile> C' L : T0' ; eff''" "\<turnstile> T0' <: T0 \<and> T1 = S"
"\<turnstile> U <: T0 \<rightarrow> T1 : le"
using app_ty_elim[of \<Gamma> rator "C' L" S F] ` \<Gamma> \<turnstile> App rator (C' L) : S ; F` by blast
thus ?case using ih by auto
next
case (C_Iff C' thn els S F)
hence ih: "!! T0 eff. \<Gamma> \<turnstile> C' L : T0 ; eff \<Longrightarrow> \<exists>T' a. \<Gamma> \<turnstile> L : T' ; a" by simp
obtain T0 eff' where "\<Gamma> \<turnstile> C' L : T0 ; eff'"
using if_ty_elim[of \<Gamma> "C' L" thn els S F] ` \<Gamma> \<turnstile> Iff (C' L) thn els : S ; F` by auto
thus ?case using ih by auto
qed
inductive_cases step_cases: "(e::trm) \<longrightarrow> e'"
inductive_cases bi_reduce:"BI b \<hookrightarrow> x"
inductive_cases bool_reduce:"Bool b \<hookrightarrow> x"
inductive_cases abs_reduce:"(Lam[a:T].b) \<hookrightarrow> x"
inductive_cases num_reduce:"Num n \<hookrightarrow> x"
lemma value_reduce_step:
assumes A:"v : values" and B:"v \<longrightarrow> (v'::trm)"
shows "v \<hookrightarrow> v'"
using B A
proof(induct)
fix E L R
assume "E : ctxt" "L \<hookrightarrow> R" "E L \<in> values"
hence "E L = L" and "E R = R" using value_no_ctxt by auto
thus "E L \<hookrightarrow> E R" using prems by auto
qed
lemma value_not_step:
assumes "v : values"
shows "~ (EX v'. v \<hookrightarrow> v')"
proof(rule ccontr, simp)
assume "\<exists>v'. v \<hookrightarrow> v'"
then obtain v' where A:"v \<hookrightarrow> v'" by auto
show False using `v : values` A
proof (induct v rule: values.induct)
case (bi_value b) thus ?case using bi_reduce by auto
next
case num_value thus ?case using num_reduce by auto
next
case abs_value thus ?case using abs_reduce by blast
next
case bool_value thus ?case using bool_reduce by auto
qed
qed
lemma value_not_reduce:
fixes v v' :: trm
assumes "v : values"
shows "~ (EX v'. v \<longrightarrow> v')"
proof (rule ccontr)
assume "\<not> \<not> (\<exists>v'. v \<longrightarrow> v')"
then obtain v' where "v \<longrightarrow> v'" by auto
hence A:"v \<hookrightarrow> v'" using value_reduce_step prems by auto
show False using `v : values` A value_not_step by auto
qed
theorem preservation:
fixes e e' :: trm
assumes typed:"\<Gamma> \<turnstile> e : t ; eff" and cl:"closed e"
and red:"e \<longrightarrow> e'"
shows "EX t' eff'. \<Gamma> \<turnstile> e' : t' ; eff' \<and> \<turnstile> t' <: t \<and> \<turnstile> eff' <e: eff"
using red typed cl
proof -
have val:"valid \<Gamma>" using typing_valid typed by auto
obtain C L R where "e = C L" "e' = C R" and "L \<hookrightarrow> R" and "C : ctxt" using red step_cases[of e e' thesis] by auto
hence f:"EX T F. \<Gamma> \<turnstile> L : T ; F" using typed typing_ctxt by auto
have "L \<notin> values" using `L \<hookrightarrow> R` value_not_step by auto
have "closed L" and "closed_ctxt C" using closed_in_ctxt_closed_ctxt[of e C L] `C : ctxt` cl `e = C L` by auto
hence "closed R" using reduce_closed[of L R] `L \<hookrightarrow> R` by auto
hence "closed (C R)" and "closed (C L)" using `closed_ctxt C` ctxt_closed[of C L] ctxt_closed[of C R] `closed L` by auto
have " \<And>T0 F0. \<Gamma> \<turnstile> L : T0 ; F0 \<Longrightarrow> \<exists>T1 F1. \<Gamma> \<turnstile> R : T1 ; F1 \<and> \<turnstile> T1 <: T0 \<and> \<turnstile> F1 <e: F0"
proof -
fix T0 F0
show "\<Gamma> \<turnstile> L : T0 ; F0 \<Longrightarrow> (\<exists>T1 F1. \<Gamma> \<turnstile> R : T1 ; F1 \<and> \<turnstile> T1 <: T0 \<and> \<turnstile> F1 <e: F0)"
using `e = C L` `C : ctxt` `L \<hookrightarrow> R` closed_in_ctxt[of C L] cl preserve_red[of \<Gamma> L T0 F0 R] `closed L` val by auto
qed
hence "\<exists>S G. \<Gamma> \<turnstile> C R : S ; G \<and> \<turnstile> S <: t \<and> \<turnstile> G <e: eff"
using `C : ctxt` subst_in_ctxt_preserves_type[of \<Gamma> e t eff C L R] typed `e = C L` `closed (C L)` `closed (C R)`
`L \<notin> values`by auto
thus ?thesis using `e' = C R` by auto
qed
text {* soundness *}
lemma soundness_finite:
fixes e e' e'' :: trm
assumes A:"\<Gamma> \<turnstile> e : T ; F" and B:"e \<longrightarrow>\<^sup>* e'" and C:"~ (EX e''. e' \<longrightarrow> e'')" and E:"closed e"
shows "EX T' F'. (e' : values \<and> \<Gamma> \<turnstile> e' : T' ; F' \<and> \<turnstile> T' <: T \<and> \<turnstile> F' <e: F)"
using B prems
proof (induct arbitrary: \<Gamma> T F rule: step_multi.induct)
case (sm_refl v)
have "v : values" using sm_refl progress[of \<Gamma> v T F] by auto
thus ?case using sm_refl by auto
next
case (sm_trans a b c)
have "closed b" "closed c" using `closed a` `b \<longrightarrow>\<^sup>* c` `a \<longrightarrow> b` step_closed[of a b] multi_step_closed[of b c] by auto
then obtain T' F' where 1:"\<Gamma> \<turnstile> b : T' ; F'" "\<turnstile> T' <: T" "\<turnstile> F' <e: F"
using preservation[of \<Gamma> a T F b] sm_trans by auto
then obtain T'' F'' where 2:"\<Gamma> \<turnstile> c : T'' ; F''" "\<turnstile> T'' <: T'" "\<turnstile> F'' <e: F'" "c : values"
using sm_trans(3)[of \<Gamma> T' F'] sm_trans `closed b` by blast
have "\<turnstile> T'' <: T" using 1 2 by auto
have 3:"simple_eff F" using prems closed_eff by auto
have 4:"simple_eff F'" using 1 prems closed_eff `closed b` by auto
have 5:"simple_eff F''" using prems closed_eff `closed c` by auto
from 3 4 5 have "\<turnstile> F'' <e: F" using SE_Trans[of F'' F' F] 1 2 by auto
thus ?case using 2 `\<turnstile> T'' <: T` by auto
qed
text
{*
interesting fact:
let e = (Iff True 3 x)
then [] \<turnstile> e : Int ; NE
but e is not closed
*}
theorem soundness:
assumes A:"\<Gamma> \<turnstile> e : T ; F" and E:"closed e"
shows "reduce_forever e \<or> (EX v T' F'. (v : values \<and> e \<longrightarrow>\<^sup>* v \<and> \<Gamma> \<turnstile> v : T' ; F' \<and> \<turnstile> T' <: T \<and> \<turnstile> F' <e: F))"
proof -
{
assume "~(reduce_forever e)"
hence "EX e'. (e \<longrightarrow>\<^sup>* e') \<and> ~(EX e''. e' \<longrightarrow> e'')" by (auto simp add: reduce_forever_def)
then obtain e'::trm where B:"e \<longrightarrow>\<^sup>* e'" and C:"~ (EX e''. e' \<longrightarrow> e'')" by auto
hence ?thesis using soundness_finite[OF A B C E] by auto
}
moreover
{
assume "reduce_forever e"
hence ?thesis by simp
}
ultimately show ?thesis by auto
qed
text {* simpler type system, without silly rules *}
inductive
typing2 :: "varEnv \<Rightarrow> trm \<Rightarrow> ty \<Rightarrow> eff \<Rightarrow> bool" (" _ \<turnstile>\<^isub>2 _ : _ ; _ " [60,60,60,60] 60)
where
T2_Var[intro]: "\<lbrakk>valid \<Gamma>; (v,T)\<in>set \<Gamma>\<rbrakk>\<Longrightarrow> \<Gamma> \<turnstile>\<^isub>2 Var v : T ; VE v"
| T2_Const[intro]: "valid \<Gamma> \<Longrightarrow> \<Delta>\<^isub>\<tau> b = T \<Longrightarrow> \<Gamma> \<turnstile>\<^isub>2 (BI b) : T ; TT"
| T2_Num[intro]: "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile>\<^isub>2 (Num n) : ty.Int ; TT"
| T2_True[intro]: "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile>\<^isub>2 (Bool True) : ty.TT ; TT"
| T2_False[intro]: "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile>\<^isub>2 (Bool False) : ty.FF ; FF"
| T2_Abs[intro]: "\<lbrakk>x \<sharp> \<Gamma>; ((x,T1)#\<Gamma>) \<turnstile>\<^isub>2 b : T2; eff\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile>\<^isub>2 Lam [x:T1].b : (T1\<rightarrow>T2 : latent_eff.NE) ; TT"
| T2_App[intro]: "\<lbrakk>\<Gamma> \<turnstile>\<^isub>2 e1 : U ; eff1 ; \<turnstile> U <: (T0 \<rightarrow> T1 : le); \<Gamma> \<turnstile>\<^isub>2 e2 : T; eff2 ; \<turnstile> T <: T0\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile>\<^isub>2 App e1 e2 : T1 ; NE"
| T2_AppPred[intro]: "\<lbrakk>\<Gamma> \<turnstile>\<^isub>2 e1 : U; eff1; \<turnstile> U <: (T0 \<rightarrow> T1 : Latent S); \<Gamma> \<turnstile>\<^isub>2 e2 : T; VE x ; \<turnstile> T <: T0\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile>\<^isub>2 App e1 e2 : T1 ; TE S x"
| T2_If[intro]: "\<lbrakk>\<Gamma> \<turnstile>\<^isub>2 e1 : T1; eff1; (\<Gamma> |+ eff1) \<turnstile>\<^isub>2 e2 : T2; eff2; (\<Gamma> |- eff1) \<turnstile>\<^isub>2 e3 : T3; eff3; \<turnstile> T2 <: T; \<turnstile> T3 <: T\<rbrakk> \<Longrightarrow>
\<Gamma> \<turnstile>\<^isub>2 (Iff e1 e2 e3) : T ; comb_eff eff1 eff2 eff3"
| T2_AbsPred[intro]: "\<lbrakk>x \<sharp> \<Gamma>; ((x,T1)#\<Gamma>) \<turnstile>\<^isub>2 b : T2; TE S x\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile>\<^isub>2 Lam [x:T1].b : (T1\<rightarrow>T2 : Latent S) ; TT"
lemma typing2_typing:
assumes "\<Gamma> \<turnstile>\<^isub>2 e : T ; F"
shows "\<Gamma> \<turnstile> e : T ; F"
using prems
by induct (auto simp del: comb_eff.simps)
lemma typing2_soundness1:
assumes A:"\<Gamma> \<turnstile>\<^isub>2 e : T ; F" and E:"closed e"
shows "reduce_forever e \<or> (EX v T' F'. (v : values \<and> e \<longrightarrow>\<^sup>* v \<and> \<Gamma> \<turnstile> v : T' ; F' \<and> \<turnstile> T' <: T \<and> \<turnstile> F' <e: F))"
using A E soundness typing2_typing
by auto
lemma typing2_soundness_int:
assumes A:"\<Gamma> \<turnstile>\<^isub>2 e : ty.Int ; F" and E:"closed e"
shows "reduce_forever e \<or> (EX v F'. (v : values \<and> (e \<longrightarrow>\<^sup>* v) \<and> \<Gamma> \<turnstile>\<^isub>2 v : ty.Int ; F' \<and> \<turnstile> F' <e: F))"
proof -
from typing2_soundness1[OF A E]
have B:"reduce_forever e \<or> (EX v T' F'. (v : values \<and> (e \<longrightarrow>\<^sup>* v) \<and> \<Gamma> \<turnstile> v : T' ; F' \<and> \<turnstile> T' <: ty.Int \<and> \<turnstile> F' <e: F))" by auto
thus ?thesis
proof
assume "EX v T' F'. (v : values \<and> (e \<longrightarrow>\<^sup>* v) \<and> \<Gamma> \<turnstile> v : T' ; F' \<and> \<turnstile> T' <: ty.Int \<and> \<turnstile> F' <e: F)"
then guess v T' F' by auto
then obtain n where "v = Num n" using int_value by blast
hence "\<Gamma> \<turnstile>\<^isub>2 v : ty.Int ; F'" using num_ty_elim[of \<Gamma> _ T' F'] `\<Gamma> \<turnstile> v : T' ; F'` by auto
thus ?thesis using `\<turnstile> F' <e: F` `v : values` `(e \<longrightarrow>\<^sup>* v)` by auto
qed (auto)
qed
lemma typing2_soundness_help:
assumes A:"\<Gamma> \<turnstile>\<^isub>2 e : \<sigma> ; F" and E:"closed e"
and B: "((\<exists>v T' F'. v \<in> values \<and> \<Gamma> \<turnstile> v : T' ; F' \<and> \<turnstile> T' <: \<sigma> \<and> \<turnstile> F' <e: F)) \<Longrightarrow>
(reduce_forever e \<or> (\<exists>v F'. v \<in> values \<and> \<Gamma> \<turnstile>\<^isub>2 v : \<sigma> ; F' \<and> \<turnstile> F' <e: F))"
shows "(reduce_forever e \<or> (\<exists>v F'. v \<in> values \<and> \<Gamma> \<turnstile>\<^isub>2 v : \<sigma> ; F' \<and> \<turnstile> F' <e: F))"
using A B E typing2_soundness1 by blast
lemma typing2_soundness_bool:
assumes A:"\<Gamma> \<turnstile>\<^isub>2 e : T ; F" and E:"closed e" and sub:"\<turnstile> T <: BoolTy"
shows "reduce_forever e \<or> (EX v F' T'. (v : values \<and> (e \<longrightarrow>\<^sup>* v) \<and> \<Gamma> \<turnstile>\<^isub>2 v : T' ; F' \<and> \<turnstile> F' <e: F \<and> \<turnstile> T' <: T))"
proof -
from typing2_soundness1[OF A E]
have B:"reduce_forever e \<or> (EX v T' F'. (v : values \<and> (e \<longrightarrow>\<^sup>* v) \<and> \<Gamma> \<turnstile> v : T' ; F' \<and> \<turnstile> T' <: T \<and> \<turnstile> F' <e: F))"
by blast
thus ?thesis
proof
assume "EX v T' F'. (v : values \<and> (e \<longrightarrow>\<^sup>* v) \<and> \<Gamma> \<turnstile> v : T' ; F' \<and> \<turnstile> T' <: T \<and> \<turnstile> F' <e: F)"
then guess v T' F' by auto
then obtain b where "v = Bool b" using bool_value[OF `v : values` `\<Gamma> \<turnstile> v : T' ; F'`] sub by auto
hence "\<Gamma> \<turnstile>\<^isub>2 Bool b : T' ; F'" using `\<Gamma> \<turnstile> v : T' ; F'`
true_ty_elim[of \<Gamma> T' F'] false_ty_elim[of \<Gamma> T' F']
by (cases b) auto
thus ?thesis using `v = Bool b` `e \<longrightarrow>\<^sup>* v` `v : values` `\<turnstile> F' <e: F` `\<turnstile> T' <: T` by blast
qed (auto)
qed
constdefs
ground_type :: "ty \<Rightarrow> bool"
"ground_type t == t = ty.Int \<or> t = BoolTy \<or> t = ty.TT \<or> t = ty.FF"
lemma supp_env:
"(a,b) : set (\<Gamma> :: varEnv) \<Longrightarrow> a : supp \<Gamma>"
by (induct \<Gamma>) (auto simp add: supp_list_cons supp_prod supp_atm)
lemma envop_supp:
assumes "valid \<Gamma>"
shows "x : (supp (envop f n t \<Gamma>)) \<Longrightarrow> x : (supp \<Gamma> :: name set)"
proof -
assume A:"x : (supp (envop f n t \<Gamma>))"
have "!! a. a \<notin> (supp \<Gamma> :: name set) \<Longrightarrow> a \<notin> supp (envop f n t \<Gamma>)"
proof -
fix a
show "a \<notin> (supp \<Gamma> :: name set) \<Longrightarrow> a \<notin> supp (envop f n t \<Gamma>)"
using fresh_def[of a "envop f n t \<Gamma>"] envop_fresh[OF _ `valid \<Gamma>`] fresh_def[of a \<Gamma>]
by auto
qed
hence "(supp (envop f n t \<Gamma>)) <= (supp \<Gamma> :: name set)" by blast
thus ?thesis using A by auto
qed
declare envop_def[simp del]
lemma envplus_supp:
assumes "valid \<Gamma>"
shows "(supp (\<Gamma> |+ F) :: name set) <= (supp \<Gamma> :: name set)"
using prems
apply (nominal_induct F rule: eff.induct)
apply (auto simp add: envop_supp)
done
lemma envminus_supp:
assumes "valid \<Gamma>"
shows "(supp (\<Gamma> |- F) :: name set) <= (supp \<Gamma> :: name set)"
using prems
apply (nominal_induct F rule: eff.induct)
apply (auto simp add: envop_supp)
done
lemma env_supp_typing2:
assumes "\<Gamma> \<turnstile>\<^isub>2 e : T ; F"
shows "fv e <= supp \<Gamma>"
using prems
proof (induct \<Gamma> e T F rule: typing2.induct)
case T2_Var
thus ?case by (auto simp add: trm.supp supp_atm supp_env)
next
case T2_App thus ?case by (auto simp add: trm.supp)
next
case T2_AppPred thus ?case by (auto simp add: trm.supp)
next
case (T2_If \<Gamma> _ _ F)
have "valid \<Gamma>" using typing_valid typing2_typing[OF T2_If(1)] by auto
thus ?case using T2_If envminus_supp[OF `valid \<Gamma>`, of F] envplus_supp[OF `valid \<Gamma>`, of F]
by (auto simp add: trm.supp)
next
case T2_Abs thus ?case
by (auto simp add: trm.supp fv_lam abs_supp supp_list_cons supp_prod supp_latent_eff_ty supp_atm)
next
case T2_AbsPred thus ?case
by (auto simp add: trm.supp fv_lam abs_supp supp_list_cons supp_prod supp_latent_eff_ty supp_atm)
next
case (T2_Const \<Gamma> b) thus ?case
by (nominal_induct b rule: builtin.induct)
(auto simp add: trm.supp builtin.supp)
qed (auto simp add: trm.supp supp_nat supp_bool)
lemma empty_env_typing2_closed:
assumes "[] \<turnstile>\<^isub>2 e : T ; F"
shows "closed e"
using env_supp_typing2[OF prems] closed_def prems supp_list_nil
by auto
theorem ground_type_soundness:
assumes A:"[] \<turnstile>\<^isub>2 e : T ; F" and B:"ground_type T"
shows "reduce_forever e \<or> (EX v T' F'. (v : values \<and> (e \<longrightarrow>\<^sup>* v) \<and> [] \<turnstile>\<^isub>2 v : T' ; F' \<and> \<turnstile> T' <: T \<and> \<turnstile> F' <e: F))"
proof -
have E:"closed e" using empty_env_typing2_closed[OF A] by simp
{
assume "T = ty.Int"
hence "reduce_forever e \<or> (EX v F'. (v : values \<and> (e \<longrightarrow>\<^sup>* v) \<and> [] \<turnstile>\<^isub>2 v : ty.Int ; F' \<and> \<turnstile> F' <e: F))"
using A E typing2_soundness_int by auto
hence ?thesis using prems by auto
}
moreover
{
assume "T ~= ty.Int"
hence "\<turnstile> T <: BoolTy" using B by (auto simp add: ground_type_def)
hence "reduce_forever e \<or> (EX v F' T'. (v : values \<and> (e \<longrightarrow>\<^sup>* v) \<and> [] \<turnstile>\<^isub>2 v : T' ; F' \<and> \<turnstile> F' <e: F \<and> \<turnstile> T' <: T))"
using typing2_soundness_bool[OF A E] by auto
hence ?thesis using prems by auto
}
ultimately show ?thesis using B ground_type_def by auto
qed
end
lemma unique_decomposition:
assumes a:"closed e"
shows "\<lbrakk>E : ctxt; E t = e; E' : ctxt; E' t' = e\<rbrakk> \<Longrightarrow> E = E'"
using a
proof (nominal_induct e rule: trm.induct)
case (Var v)
have f1:"E = (%t. t)" using Var by cases auto
have f2:"E'= (%t. t)" using `E' : ctxt` Var by cases auto
from f1 f2 show ?case by simp
next
case (Bool c)
have f1:"E = (%t. t)" using Bool by cases auto
have f2:"E'= (%t. t)" using `E' : ctxt` Bool by cases auto
from f1 f2 show ?case by simp
next
case (Num c)
have f1:"E = (%t. t)" using Num by cases auto
have f2:"E'= (%t. t)" using `E' : ctxt` Num by cases auto
from f1 f2 show ?case by simp
next
case Abs
have f1:"E = (%t. t)" using `E : ctxt` Abs by cases auto
have f2:"E'= (%t. t)" using `E' : ctxt` Abs by cases auto
from f1 f2 show ?case by simp
next
case (Iff tst thn els)
{
assume "tst \<notin> values"
hence "EX E L R. tst = E L \<and> E \<in> ctxt \<and> L \<hookrightarrow> R" using decomposition
have f1:"E = (%t. t)" using `E : ctxt` Iff apply cases apply (auto simp add: trm.inject)
have f2:"E'= (%t. t)" using `E' : ctxt` Iff by cases auto
from f1 f2 have ?case by simp
{
oops
lemma fresh_fact:
fixes a::"name"
assumes a: "a\<sharp>t1"
and b: "a\<sharp>t2"
shows "a\<sharp>(t1[b::=t2])"
using a b
by (nominal_induct t1 avoiding: a b t2 rule: trm.induct)
(auto simp add: abs_fresh fresh_atm)
lemma id_subs: "t[x::=Var x] = t"
by (nominal_induct t avoiding: x rule: trm.induct)
(simp_all add: fresh_atm)
lemma random_eqvt[simp]:
fixes pi :: "name prm"
shows "\<forall>T. T \<in> set Ts \<longrightarrow> \<turnstile> T <: S \<and> \<turnstile> pi \<bullet> T <: pi \<bullet> S \<Longrightarrow>
\<forall>T. T \<in> set (pi \<bullet> Ts) \<longrightarrow> \<turnstile> T <: pi \<bullet> S"
proof -
assume 0:"\<forall>T. T \<in> set Ts \<longrightarrow> \<turnstile> T <: S \<and> \<turnstile> pi \<bullet> T <: pi \<bullet> S"
hence 1:"!! T. T \<in> set Ts \<Longrightarrow> \<turnstile> T <: S \<and> \<turnstile> pi \<bullet> T <: pi \<bullet> S" by auto
have A:"(pi \<bullet> Ts) = Ts" by (induct Ts) auto
have B:"pi \<bullet> S = S" by auto
have "!! T. T \<in> set (pi \<bullet> Ts) \<Longrightarrow> \<turnstile> T <: pi \<bullet> S"
proof -
fix T
assume "T \<in> set (pi \<bullet> Ts)"
hence "T : set Ts" using A by auto
hence "\<turnstile> T <: S" using 1 by auto
thus "\<turnstile> T <: pi \<bullet> S" using B by auto
qed
thus ?thesis by auto
qed
text {* complete induction on typing derivations *}
lemma typing_induct_complete[consumes 1, case_names T_Var T_Const T_Num T_True T_False T_App T_Lam T_AppPred T_If
T_AppPredTrue T_AppPredFalse T_IfTrue T_IfFalse]:
fixes P :: "'a::fs_name\<Rightarrow>(name\<times>ty) list \<Rightarrow> trm \<Rightarrow> ty \<Rightarrow> eff \<Rightarrow> bool"
and \<Gamma> :: "(name\<times>ty) list"
and t :: "trm"
and T :: "ty"
and F :: "eff"
and x :: "'a::fs_name"
assumes a: "\<Gamma> \<turnstile> t : T ; F"
and a1: "\<And>\<Gamma> (a::name) \<tau> x. valid \<Gamma> \<Longrightarrow> (a,\<tau>) \<in> set \<Gamma> \<Longrightarrow>
(!! x t T \<Gamma> F. (t\<guillemotleft>Var a) \<Longrightarrow> \<Gamma> \<turnstile> t : T ; F \<Longrightarrow> P x \<Gamma> t T F) \<Longrightarrow> valid \<Gamma> \<Longrightarrow> P x \<Gamma> (Var a) \<tau> (VE a)"
and a2: "!! \<Gamma> b T x. \<Delta>\<^isub>\<tau> b = T \<Longrightarrow>
(!! x t T \<Gamma> F. (t\<guillemotleft>BI b) \<Longrightarrow> \<Gamma> \<turnstile> t : T ; F \<Longrightarrow> P x \<Gamma> t T F) \<Longrightarrow> valid \<Gamma> \<Longrightarrow> P x \<Gamma> (BI b) T NE"
and a3: "!! \<Gamma> n x. (!! x t T \<Gamma> F. (t\<guillemotleft>Num n) \<Longrightarrow> \<Gamma> \<turnstile> t : T ; F \<Longrightarrow> P x \<Gamma> t T F) \<Longrightarrow> valid \<Gamma> \<Longrightarrow>
P x \<Gamma> (Num n) ty.Int NE"
and a4: "!! \<Gamma> x. (!! x t T \<Gamma> F. (t\<guillemotleft>Bool True) \<Longrightarrow> \<Gamma> \<turnstile> t : T ; F \<Longrightarrow> P x \<Gamma> t T F) \<Longrightarrow> valid \<Gamma> \<Longrightarrow>
P x \<Gamma> (Bool True) BoolTy TT"
and a5: "!! \<Gamma> x. (!! x t T \<Gamma> F. (t\<guillemotleft>Bool False) \<Longrightarrow> \<Gamma> \<turnstile> t : T ; F \<Longrightarrow> P x \<Gamma> t T F) \<Longrightarrow> valid \<Gamma> \<Longrightarrow>
P x \<Gamma> (Bool False) BoolTy FF"
and a6: "\<And>\<Gamma> \<tau> \<sigma> t1 t2 x F1 F2 le \<tau>0 U. (!! x t T \<Gamma> F. (t\<guillemotleft>App t1 t2) \<Longrightarrow> \<Gamma> \<turnstile> t : T ; F \<Longrightarrow> P x \<Gamma> t T F) \<Longrightarrow>
\<Gamma> \<turnstile> t1 : U ; F1 \<Longrightarrow> \<turnstile> U <: \<tau>\<rightarrow>\<sigma>:le \<Longrightarrow> (\<And>z. P z \<Gamma> t1 U F1) \<Longrightarrow> \<Gamma> \<turnstile> t2 : \<tau>0 ; F2 \<Longrightarrow> (\<And>z. P z \<Gamma> t2 \<tau>0 F2) \<Longrightarrow> \<turnstile> \<tau>0 <: \<tau>
\<Longrightarrow> P x \<Gamma> (App t1 t2) \<sigma> NE"
and a7: "\<And>a \<Gamma> \<tau> \<sigma> t x F0. a\<sharp>x \<Longrightarrow> a\<sharp>\<Gamma> \<Longrightarrow> ((a,\<tau>) # \<Gamma>) \<turnstile> t : \<sigma> ; F0 \<Longrightarrow> (\<And>z. P z ((a,\<tau>)#\<Gamma>) t \<sigma> F0) \<Longrightarrow>
(!! x t' T \<Gamma> F. (t'\<guillemotleft>Lam[a:\<tau>].t) \<Longrightarrow> \<Gamma> \<turnstile> t' : T ; F \<Longrightarrow> P x \<Gamma> t' T F)
\<Longrightarrow> P x \<Gamma> (Lam [a:\<tau>].t) (\<tau>\<rightarrow>\<sigma>:latent_eff.NE) NE"
and a8: "\<And>\<Gamma> \<tau> \<sigma> t1 t2 x F1 \<tau>0 S v U.
(!! x t T \<Gamma> F. t \<guillemotleft> App t1 t2 \<Longrightarrow> \<Gamma> \<turnstile> t : T ; F \<Longrightarrow> P x \<Gamma> t T F) \<Longrightarrow>
\<Gamma> \<turnstile> t1 : U ; F1 \<Longrightarrow> \<turnstile> U <: (\<tau>\<rightarrow>\<sigma>:Latent S) \<Longrightarrow> (\<And>z. P z \<Gamma> t1 U F1) \<Longrightarrow> \<Gamma> \<turnstile> t2 : \<tau>0 ; VE v \<Longrightarrow>
(\<And>z. P z \<Gamma> t2 \<tau>0 (VE v))
\<Longrightarrow> \<turnstile> \<tau>0 <: \<tau> \<Longrightarrow> P x \<Gamma> (App t1 t2) \<sigma> (TE S v)"
and a9: "!! \<Gamma> e1 e2 e3 T1 T2 T3 T eff1 eff2 eff3 x.
\<lbrakk>\<Gamma> \<turnstile> e1 : T1; eff1; !!z. P z \<Gamma> e1 T1 eff1; (\<Gamma> |+ eff1) \<turnstile> e2 : T2; eff2; !!z. P z (\<Gamma>|+ eff1) e2 T2 eff2;
(!! x t T \<Gamma> F. t \<guillemotleft> Iff e1 e2 e3 \<Longrightarrow> \<Gamma> \<turnstile> t : T ; F \<Longrightarrow> P x \<Gamma> t T F);
(\<Gamma> |- eff1) \<turnstile> e3 : T3; eff3; !!z. P z (\<Gamma>|- eff1) e3 T3 eff3; \<turnstile> T2 <: T; \<turnstile> T3 <: T\<rbrakk>
\<Longrightarrow> P x \<Gamma> (Iff e1 e2 e3) T NE"
and a10: "!! \<Gamma> e1 e2 T0 T1 T S eff1 eff2 x U.
\<lbrakk>\<Gamma> \<turnstile> e1 : U; eff1; \<turnstile> U <: (T0 \<rightarrow> T1 : Latent S) ; !!z. P z \<Gamma> e1 U eff1;
(!! x t T \<Gamma> F. t \<guillemotleft> App e1 e2 \<Longrightarrow> \<Gamma> \<turnstile> t : T ; F \<Longrightarrow> P x \<Gamma> t T F);
\<Gamma> \<turnstile> e2 : T; eff2 ; !! z. P z \<Gamma> e2 T eff2; \<turnstile> T <: T0; \<turnstile> T <: S\<rbrakk> \<Longrightarrow> P x \<Gamma> (App e1 e2) T1 TT"
and a11: "!! \<Gamma> e1 e2 T0 T1 T S eff1 eff2 x U.
\<lbrakk>\<Gamma> \<turnstile> e1 : U; eff1; \<turnstile> U <: (T0 \<rightarrow> T1 : Latent S) ; !!z. P z \<Gamma> e1 U eff1;
(!! x t T \<Gamma> F. t \<guillemotleft> App e1 e2 \<Longrightarrow> \<Gamma> \<turnstile> t : T ; F \<Longrightarrow> P x \<Gamma> t T F);
\<Gamma> \<turnstile> e2 : T; eff2 ; !! z. P z \<Gamma> e2 T eff2; \<turnstile> T <: T0; ~(\<turnstile> T <: S) ; e2 : values ; closed e2\<rbrakk>
\<Longrightarrow> P x \<Gamma> (App e1 e2) T1 FF"
and a12: "!! \<Gamma> e1 e2 e3 T T1 T2 eff x. \<lbrakk>\<Gamma> \<turnstile> e1 : T1 ; TT ; !! z. P z \<Gamma> e1 T1 TT;
(!! x t T \<Gamma> F. t \<guillemotleft> Iff e1 e2 e3 \<Longrightarrow> \<Gamma> \<turnstile> t : T ; F \<Longrightarrow> P x \<Gamma> t T F);
\<Gamma> \<turnstile> e2 : T2 ; eff; !!z .P z \<Gamma> e2 T2 eff; \<turnstile> T2 <: T\<rbrakk> \<Longrightarrow> P x \<Gamma> (Iff e1 e2 e3) T NE"
and a13: "!! \<Gamma> e1 e2 e3 T T1 T3 eff x. \<lbrakk>\<Gamma> \<turnstile> e1 : T1 ; FF ; !! z. P z \<Gamma> e1 T1 FF;
(!! x t T \<Gamma> F. t \<guillemotleft> Iff e1 e2 e3 \<Longrightarrow> \<Gamma> \<turnstile> t : T ; F \<Longrightarrow> P x \<Gamma> t T F);
\<Gamma> \<turnstile> e3 : T3 ; eff; !!z .P z \<Gamma> e3 T3 eff; \<turnstile> T3 <: T\<rbrakk> \<Longrightarrow> P x \<Gamma> (Iff e1 e2 e3) T NE"
shows "P x \<Gamma> t T F"
using a
proof (nominal_induct t avoiding: x \<Gamma> T F rule: trm_comp_induct)
case (Var v)
thus ?case using a1 var_ty_elim[of \<Gamma> v T F] by auto
next
case (App t1 t2 x \<Gamma> T)
show ?case using App(4)
proof (induct rule: app_ty_elim2)
case 1 thus ?thesis using a6 App trm.inject ty.inject by auto
next
case 2 thus ?thesis using a8 App trm.inject ty.inject by auto
next
case 3 thus ?thesis using a10 App trm.inject ty.inject by auto
next
case 4 thus ?thesis using a11 App trm.inject ty.inject by auto
qed
next
case Iff
show ?case using Iff(5)
proof (induct rule: iff_ty_elim2)
case 1 thus ?thesis using a9 Iff trm.inject ty.inject by auto
next
case 2 thus ?thesis using a12 Iff trm.inject ty.inject by auto
next
case 3 thus ?thesis using a13 Iff trm.inject ty.inject by auto
qed
next
case (Lam v b x \<Gamma> S1 F S2)
show ?case using Lam abs_ty_elim[of \<Gamma> v b S2 S1 F] a7 by (auto simp add: trm.inject ty.inject)
next
case (BI b) thus ?case using bi_ty_elim[of \<Gamma> b T F] trm.inject a2 by auto
next
case (Num n) thus ?case using num_ty_elim[of \<Gamma> n T F] trm.inject a3 by auto
next
case (Bool b) thus ?case using true_ty_elim[of \<Gamma> T F] false_ty_elim[of \<Gamma> T F] trm.inject a4 a5 by (cases b) auto
qed
|
Monument 27 is a carved step depicting K 'awiil Mo ' , a lord from Palenque , as an elderly prisoner , bound and lying on his back with his profile positioned in such a way as to be trodden on time and again .
|
The modulus of the complex conjugate of a complex number is equal to the modulus of the complex number. |
State Before: α : Type u_1
E : α → Type u_2
p q : ℝ≥0∞
inst✝² : (i : α) → NormedAddCommGroup (E i)
inst✝¹ : (i : α) → StarAddMonoid (E i)
inst✝ : ∀ (i : α), NormedStarGroup (E i)
f : (i : α) → E i
hf : Memℓp f p
⊢ Memℓp (star f) p State After: case inl
α : Type u_1
E : α → Type u_2
q : ℝ≥0∞
inst✝² : (i : α) → NormedAddCommGroup (E i)
inst✝¹ : (i : α) → StarAddMonoid (E i)
inst✝ : ∀ (i : α), NormedStarGroup (E i)
f : (i : α) → E i
hf : Memℓp f 0
⊢ Memℓp (star f) 0
case inr.inl
α : Type u_1
E : α → Type u_2
q : ℝ≥0∞
inst✝² : (i : α) → NormedAddCommGroup (E i)
inst✝¹ : (i : α) → StarAddMonoid (E i)
inst✝ : ∀ (i : α), NormedStarGroup (E i)
f : (i : α) → E i
hf : Memℓp f ⊤
⊢ Memℓp (star f) ⊤
case inr.inr
α : Type u_1
E : α → Type u_2
p q : ℝ≥0∞
inst✝² : (i : α) → NormedAddCommGroup (E i)
inst✝¹ : (i : α) → StarAddMonoid (E i)
inst✝ : ∀ (i : α), NormedStarGroup (E i)
f : (i : α) → E i
hf : Memℓp f p
hp : 0 < ENNReal.toReal p
⊢ Memℓp (star f) p Tactic: rcases p.trichotomy with (rfl | rfl | hp) State Before: case inl
α : Type u_1
E : α → Type u_2
q : ℝ≥0∞
inst✝² : (i : α) → NormedAddCommGroup (E i)
inst✝¹ : (i : α) → StarAddMonoid (E i)
inst✝ : ∀ (i : α), NormedStarGroup (E i)
f : (i : α) → E i
hf : Memℓp f 0
⊢ Memℓp (star f) 0 State After: case inl.hf
α : Type u_1
E : α → Type u_2
q : ℝ≥0∞
inst✝² : (i : α) → NormedAddCommGroup (E i)
inst✝¹ : (i : α) → StarAddMonoid (E i)
inst✝ : ∀ (i : α), NormedStarGroup (E i)
f : (i : α) → E i
hf : Memℓp f 0
⊢ Set.Finite {i | star f i ≠ 0} Tactic: apply memℓp_zero State Before: case inl.hf
α : Type u_1
E : α → Type u_2
q : ℝ≥0∞
inst✝² : (i : α) → NormedAddCommGroup (E i)
inst✝¹ : (i : α) → StarAddMonoid (E i)
inst✝ : ∀ (i : α), NormedStarGroup (E i)
f : (i : α) → E i
hf : Memℓp f 0
⊢ Set.Finite {i | star f i ≠ 0} State After: no goals Tactic: simp [hf.finite_dsupport] State Before: case inr.inl
α : Type u_1
E : α → Type u_2
q : ℝ≥0∞
inst✝² : (i : α) → NormedAddCommGroup (E i)
inst✝¹ : (i : α) → StarAddMonoid (E i)
inst✝ : ∀ (i : α), NormedStarGroup (E i)
f : (i : α) → E i
hf : Memℓp f ⊤
⊢ Memℓp (star f) ⊤ State After: case inr.inl.hf
α : Type u_1
E : α → Type u_2
q : ℝ≥0∞
inst✝² : (i : α) → NormedAddCommGroup (E i)
inst✝¹ : (i : α) → StarAddMonoid (E i)
inst✝ : ∀ (i : α), NormedStarGroup (E i)
f : (i : α) → E i
hf : Memℓp f ⊤
⊢ BddAbove (Set.range fun i => ‖star f i‖) Tactic: apply memℓp_infty State Before: case inr.inl.hf
α : Type u_1
E : α → Type u_2
q : ℝ≥0∞
inst✝² : (i : α) → NormedAddCommGroup (E i)
inst✝¹ : (i : α) → StarAddMonoid (E i)
inst✝ : ∀ (i : α), NormedStarGroup (E i)
f : (i : α) → E i
hf : Memℓp f ⊤
⊢ BddAbove (Set.range fun i => ‖star f i‖) State After: no goals Tactic: simpa using hf.bddAbove State Before: case inr.inr
α : Type u_1
E : α → Type u_2
p q : ℝ≥0∞
inst✝² : (i : α) → NormedAddCommGroup (E i)
inst✝¹ : (i : α) → StarAddMonoid (E i)
inst✝ : ∀ (i : α), NormedStarGroup (E i)
f : (i : α) → E i
hf : Memℓp f p
hp : 0 < ENNReal.toReal p
⊢ Memℓp (star f) p State After: case inr.inr.hf
α : Type u_1
E : α → Type u_2
p q : ℝ≥0∞
inst✝² : (i : α) → NormedAddCommGroup (E i)
inst✝¹ : (i : α) → StarAddMonoid (E i)
inst✝ : ∀ (i : α), NormedStarGroup (E i)
f : (i : α) → E i
hf : Memℓp f p
hp : 0 < ENNReal.toReal p
⊢ Summable fun i => ‖star f i‖ ^ ENNReal.toReal p Tactic: apply memℓp_gen State Before: case inr.inr.hf
α : Type u_1
E : α → Type u_2
p q : ℝ≥0∞
inst✝² : (i : α) → NormedAddCommGroup (E i)
inst✝¹ : (i : α) → StarAddMonoid (E i)
inst✝ : ∀ (i : α), NormedStarGroup (E i)
f : (i : α) → E i
hf : Memℓp f p
hp : 0 < ENNReal.toReal p
⊢ Summable fun i => ‖star f i‖ ^ ENNReal.toReal p State After: no goals Tactic: simpa using hf.summable hp |
(* This file is an automatic translation, the licence of the source can be found here: *)
(* https://github.com/herd/herdtools7/blob/master/LICENSE.txt *)
(* Translation of model Compatibility *)
From Coq Require Import Relations Ensembles String.
From RelationAlgebra Require Import lattice prop monoid rel kat.
From Catincoq.lib Require Import Cat proprel.
Section Model.
Variable c : candidate.
Definition events := events c.
Definition R := R c.
Definition W := W c.
Definition IW := IW c.
Definition FW := FW c.
Definition B := B c.
Definition RMW := RMW c.
Definition F := F c.
Definition rf := rf c.
Definition po := po c.
Definition int := int c.
Definition ext := ext c.
Definition loc := loc c.
Definition addr := addr c.
Definition data := data c.
Definition ctrl := ctrl c.
Definition amo := amo c.
Definition rmw := rmw c.
Definition unknown_set := unknown_set c.
Definition unknown_relation := unknown_relation c.
Definition M := R ⊔ W.
Definition emptyset : set events := empty.
Definition classes_loc : set events -> Ensemble (Ensemble events) := partition loc.
Definition tag2events := unknown_relation "tag2events".
Definition emptyset_0 : set events := domain 0.
Definition partition := classes_loc.
Definition tag2instrs := tag2events.
Definition po_loc := po ⊓ loc.
Definition rfe := rf ⊓ ext.
Definition rfi := rf ⊓ int.
Definition co0 := loc ⊓ ([IW] ⋅ top ⋅ [(W ⊓ !IW)] ⊔ [(W ⊓ !FW)] ⋅ top ⋅ [FW]).
Definition toid (s : set events) : relation events := [s].
Definition fencerel (B : set events) := (po ⊓ [top] ⋅ top ⋅ [B]) ⋅ po.
Definition ctrlcfence (CFENCE : set events) := (ctrl ⊓ [top] ⋅ top ⋅ [CFENCE]) ⋅ po.
Definition imply (A : relation events) (B : relation events) := !A ⊔ B.
Definition nodetour (R1 : relation events) (R2 : relation events) (R3 : relation events) := R1 ⊓ !(R2 ⋅ R3).
Definition singlestep (R : relation events) := nodetour R R R.
(* Definition of map already included in the prelude *)
Definition LKW := (*failed: try LKW with emptyset_0*) emptyset_0.
Definition A := ((*failed: try X with emptyset_0*) emptyset_0) ⊔ ((*failed: try A with emptyset_0*) emptyset_0).
Definition P := M ⊓ !A.
Definition WW r := r ⊓ [W] ⋅ top ⋅ [W].
Definition WR r := r ⊓ [W] ⋅ top ⋅ [R].
Definition RW r := r ⊓ [R] ⋅ top ⋅ [W].
Definition RR r := r ⊓ [R] ⋅ top ⋅ [R].
Definition RM r := r ⊓ [R] ⋅ top ⋅ [M].
Definition MR r := r ⊓ [M] ⋅ top ⋅ [R].
Definition WM r := r ⊓ [W] ⋅ top ⋅ [M].
Definition MW r := r ⊓ [M] ⋅ top ⋅ [W].
Definition MM r := r ⊓ [M] ⋅ top ⋅ [M].
Definition AA r := r ⊓ [A] ⋅ top ⋅ [A].
Definition AP r := r ⊓ [A] ⋅ top ⋅ [P].
Definition PA r := r ⊓ [P] ⋅ top ⋅ [A].
Definition PP r := r ⊓ [P] ⋅ top ⋅ [P].
Definition AM r := r ⊓ [A] ⋅ top ⋅ [M].
Definition MA r := r ⊓ [M] ⋅ top ⋅ [A].
Definition noid r : relation events := r ⊓ !id.
Definition atom := [A].
Definition witness_conditions := True.
Definition model_conditions := True.
End Model.
Hint Unfold events R W IW FW B RMW F rf po int ext loc addr data ctrl amo rmw unknown_set unknown_relation M emptyset classes_loc tag2events emptyset_0 partition tag2instrs po_loc rfe rfi co0 toid fencerel ctrlcfence imply nodetour singlestep LKW A P WW WR RW RR RM MR WM MW MM AA AP PA PP AM MA noid atom witness_conditions model_conditions : cat.
Definition valid (c : candidate) := True.
(* End of translation of model Compatibility *)
|
From Hammer Require Import Hammer.
Require Import FunInd.
Require Import Zwf.
From compcert Require Import Coqlib.
From compcert Require Import Maps.
From compcert Require Import Zbits.
From compcert Require Import Integers.
From compcert Require Import Floats.
From compcert Require Import Lattice.
From compcert Require Import Compopts.
From compcert Require Import AST.
From compcert Require Import Values.
From compcert Require Import Memory.
From compcert Require Import Globalenvs.
From compcert Require Import Builtins.
From compcert Require Import Events.
From compcert Require Import Registers.
From compcert Require Import RTL.
Inductive block_class : Type :=
| BCinvalid
| BCglob (id: ident)
| BCstack
| BCother.
Definition block_class_eq: forall (x y: block_class), {x=y} + {x<>y}.
Proof. hammer_hook "ValueDomain" "ValueDomain.block_class_eq". decide equality. apply peq. Defined.
Record block_classification : Type := BC {
bc_img :> block -> block_class;
bc_stack: forall b1 b2, bc_img b1 = BCstack -> bc_img b2 = BCstack -> b1 = b2;
bc_glob: forall b1 b2 id, bc_img b1 = BCglob id -> bc_img b2 = BCglob id -> b1 = b2
}.
Definition bc_below (bc: block_classification) (bound: block) : Prop :=
forall b, bc b <> BCinvalid -> Plt b bound.
Lemma bc_below_invalid:
forall b bc bound, ~Plt b bound -> bc_below bc bound -> bc b = BCinvalid.
Proof. hammer_hook "ValueDomain" "ValueDomain.bc_below_invalid".
intros. destruct (block_class_eq (bc b) BCinvalid); auto.
elim H. apply H0; auto.
Qed.
Hint Extern 2 (_ = _) => congruence : va.
Hint Extern 2 (_ <> _) => congruence : va.
Hint Extern 2 (_ < _) => xomega : va.
Hint Extern 2 (_ <= _) => xomega : va.
Hint Extern 2 (_ > _) => xomega : va.
Hint Extern 2 (_ >= _) => xomega : va.
Section MATCH.
Variable bc: block_classification.
Inductive abool :=
| Bnone
| Just (b: bool)
| Maybe (b: bool)
| Btop.
Inductive cmatch: option bool -> abool -> Prop :=
| cmatch_none: cmatch None Bnone
| cmatch_just: forall b, cmatch (Some b) (Just b)
| cmatch_maybe_none: forall b, cmatch None (Maybe b)
| cmatch_maybe_some: forall b, cmatch (Some b) (Maybe b)
| cmatch_top: forall ob, cmatch ob Btop.
Hint Constructors cmatch : va.
Definition club (x y: abool) : abool :=
match x, y with
| Bnone, Bnone => Bnone
| Bnone, (Just b | Maybe b) => Maybe b
| (Just b | Maybe b), Bnone => Maybe b
| Just b1, Just b2 => if eqb b1 b2 then x else Btop
| Maybe b1, Maybe b2 => if eqb b1 b2 then x else Btop
| Maybe b1, Just b2 => if eqb b1 b2 then x else Btop
| Just b1, Maybe b2 => if eqb b1 b2 then y else Btop
| _, _ => Btop
end.
Lemma cmatch_lub_l:
forall ob x y, cmatch ob x -> cmatch ob (club x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.cmatch_lub_l".
intros. unfold club; inv H; destruct y; try constructor;
destruct (eqb b b0) eqn:EQ; try constructor.
replace b0 with b by (apply eqb_prop; auto). constructor.
Qed.
Lemma cmatch_lub_r:
forall ob x y, cmatch ob y -> cmatch ob (club x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.cmatch_lub_r".
intros. unfold club; inv H; destruct x; try constructor;
destruct (eqb b0 b) eqn:EQ; try constructor.
replace b with b0 by (apply eqb_prop; auto). constructor.
replace b with b0 by (apply eqb_prop; auto). constructor.
replace b with b0 by (apply eqb_prop; auto). constructor.
Qed.
Definition cnot (x: abool) : abool :=
match x with
| Just b => Just (negb b)
| Maybe b => Maybe (negb b)
| _ => x
end.
Lemma cnot_sound:
forall ob x, cmatch ob x -> cmatch (option_map negb ob) (cnot x).
Proof. hammer_hook "ValueDomain" "ValueDomain.cnot_sound".
destruct 1; constructor.
Qed.
Inductive aptr : Type :=
| Pbot
| Gl (id: ident) (ofs: ptrofs)
| Glo (id: ident)
| Glob
| Stk (ofs: ptrofs)
| Stack
| Nonstack
| Ptop.
Definition eq_aptr: forall (p1 p2: aptr), {p1=p2} + {p1<>p2}.
Proof. hammer_hook "ValueDomain" "ValueDomain.eq_aptr".
intros. generalize ident_eq, Ptrofs.eq_dec; intros. decide equality.
Defined.
Inductive pmatch (b: block) (ofs: ptrofs): aptr -> Prop :=
| pmatch_gl: forall id,
bc b = BCglob id ->
pmatch b ofs (Gl id ofs)
| pmatch_glo: forall id,
bc b = BCglob id ->
pmatch b ofs (Glo id)
| pmatch_glob: forall id,
bc b = BCglob id ->
pmatch b ofs Glob
| pmatch_stk:
bc b = BCstack ->
pmatch b ofs (Stk ofs)
| pmatch_stack:
bc b = BCstack ->
pmatch b ofs Stack
| pmatch_nonstack:
bc b <> BCstack -> bc b <> BCinvalid ->
pmatch b ofs Nonstack
| pmatch_top:
bc b <> BCinvalid ->
pmatch b ofs Ptop.
Hint Constructors pmatch: va.
Inductive pge: aptr -> aptr -> Prop :=
| pge_top: forall p, pge Ptop p
| pge_bot: forall p, pge p Pbot
| pge_refl: forall p, pge p p
| pge_glo_gl: forall id ofs, pge (Glo id) (Gl id ofs)
| pge_glob_gl: forall id ofs, pge Glob (Gl id ofs)
| pge_glob_glo: forall id, pge Glob (Glo id)
| pge_ns_gl: forall id ofs, pge Nonstack (Gl id ofs)
| pge_ns_glo: forall id, pge Nonstack (Glo id)
| pge_ns_glob: pge Nonstack Glob
| pge_stack_stk: forall ofs, pge Stack (Stk ofs).
Hint Constructors pge: va.
Lemma pge_trans:
forall p q, pge p q -> forall r, pge q r -> pge p r.
Proof. hammer_hook "ValueDomain" "ValueDomain.pge_trans".
induction 1; intros r PM; inv PM; auto with va.
Qed.
Lemma pmatch_ge:
forall b ofs p q, pge p q -> pmatch b ofs q -> pmatch b ofs p.
Proof. hammer_hook "ValueDomain" "ValueDomain.pmatch_ge".
induction 1; intros PM; inv PM; eauto with va.
Qed.
Lemma pmatch_top': forall b ofs p, pmatch b ofs p -> pmatch b ofs Ptop.
Proof. hammer_hook "ValueDomain" "ValueDomain.pmatch_top'".
intros. apply pmatch_ge with p; auto with va.
Qed.
Definition plub (p q: aptr) : aptr :=
match p, q with
| Pbot, _ => q
| _, Pbot => p
| Gl id1 ofs1, Gl id2 ofs2 =>
if ident_eq id1 id2 then if Ptrofs.eq_dec ofs1 ofs2 then p else Glo id1 else Glob
| Gl id1 ofs1, Glo id2 =>
if ident_eq id1 id2 then q else Glob
| Glo id1, Gl id2 ofs2 =>
if ident_eq id1 id2 then p else Glob
| Glo id1, Glo id2 =>
if ident_eq id1 id2 then p else Glob
| (Gl _ _ | Glo _ | Glob), Glob => Glob
| Glob, (Gl _ _ | Glo _) => Glob
| (Gl _ _ | Glo _ | Glob | Nonstack), Nonstack =>
Nonstack
| Nonstack, (Gl _ _ | Glo _ | Glob) =>
Nonstack
| Stk ofs1, Stk ofs2 =>
if Ptrofs.eq_dec ofs1 ofs2 then p else Stack
| (Stk _ | Stack), Stack =>
Stack
| Stack, Stk _ =>
Stack
| _, _ => Ptop
end.
Lemma plub_comm:
forall p q, plub p q = plub q p.
Proof. hammer_hook "ValueDomain" "ValueDomain.plub_comm".
intros; unfold plub; destruct p; destruct q; auto.
destruct (ident_eq id id0). subst id0.
rewrite dec_eq_true.
destruct (Ptrofs.eq_dec ofs ofs0). subst ofs0. rewrite dec_eq_true. auto.
rewrite dec_eq_false by auto. auto.
rewrite dec_eq_false by auto. auto.
destruct (ident_eq id id0). subst id0.
rewrite dec_eq_true; auto.
rewrite dec_eq_false; auto.
destruct (ident_eq id id0). subst id0.
rewrite dec_eq_true; auto.
rewrite dec_eq_false; auto.
destruct (ident_eq id id0). subst id0.
rewrite dec_eq_true; auto.
rewrite dec_eq_false; auto.
destruct (Ptrofs.eq_dec ofs ofs0). subst ofs0. rewrite dec_eq_true; auto.
rewrite dec_eq_false; auto.
Qed.
Lemma pge_lub_l:
forall p q, pge (plub p q) p.
Proof. hammer_hook "ValueDomain" "ValueDomain.pge_lub_l".
unfold plub; destruct p, q; auto with va.
- destruct (ident_eq id id0).
destruct (Ptrofs.eq_dec ofs ofs0); subst; constructor.
constructor.
- destruct (ident_eq id id0); subst; constructor.
- destruct (ident_eq id id0); subst; constructor.
- destruct (ident_eq id id0); subst; constructor.
- destruct (Ptrofs.eq_dec ofs ofs0); subst; constructor.
Qed.
Lemma pge_lub_r:
forall p q, pge (plub p q) q.
Proof. hammer_hook "ValueDomain" "ValueDomain.pge_lub_r".
intros. rewrite plub_comm. apply pge_lub_l.
Qed.
Lemma pmatch_lub_l:
forall b ofs p q, pmatch b ofs p -> pmatch b ofs (plub p q).
Proof. hammer_hook "ValueDomain" "ValueDomain.pmatch_lub_l".
intros. eapply pmatch_ge; eauto. apply pge_lub_l.
Qed.
Lemma pmatch_lub_r:
forall b ofs p q, pmatch b ofs q -> pmatch b ofs (plub p q).
Proof. hammer_hook "ValueDomain" "ValueDomain.pmatch_lub_r".
intros. eapply pmatch_ge; eauto. apply pge_lub_r.
Qed.
Lemma plub_least:
forall r p q, pge r p -> pge r q -> pge r (plub p q).
Proof. hammer_hook "ValueDomain" "ValueDomain.plub_least".
intros. inv H; inv H0; simpl; try constructor.
- destruct p; constructor.
- unfold plub; destruct q; repeat rewrite dec_eq_true; constructor.
- rewrite dec_eq_true; constructor.
- rewrite dec_eq_true; constructor.
- rewrite dec_eq_true. destruct (Ptrofs.eq_dec ofs ofs0); constructor.
- destruct (ident_eq id id0). destruct (Ptrofs.eq_dec ofs ofs0); constructor. constructor.
- destruct (ident_eq id id0); constructor.
- destruct (ident_eq id id0); constructor.
- destruct (ident_eq id id0); constructor.
- destruct (ident_eq id id0). destruct (Ptrofs.eq_dec ofs ofs0); constructor. constructor.
- destruct (ident_eq id id0); constructor.
- destruct (ident_eq id id0); constructor.
- destruct (ident_eq id id0); constructor.
- destruct (Ptrofs.eq_dec ofs ofs0); constructor.
Qed.
Definition pincl (p q: aptr) : bool :=
match p, q with
| Pbot, _ => true
| Gl id1 ofs1, Gl id2 ofs2 => peq id1 id2 && Ptrofs.eq_dec ofs1 ofs2
| Gl id1 ofs1, Glo id2 => peq id1 id2
| Glo id1, Glo id2 => peq id1 id2
| (Gl _ _ | Glo _ | Glob), Glob => true
| (Gl _ _ | Glo _ | Glob | Nonstack), Nonstack => true
| Stk ofs1, Stk ofs2 => Ptrofs.eq_dec ofs1 ofs2
| Stk ofs1, Stack => true
| Stack, Stack => true
| _, Ptop => true
| _, _ => false
end.
Lemma pincl_ge: forall p q, pincl p q = true -> pge q p.
Proof. hammer_hook "ValueDomain" "ValueDomain.pincl_ge".
unfold pincl; destruct p, q; intros; try discriminate; auto with va;
InvBooleans; subst; auto with va.
Qed.
Lemma pincl_ge_2: forall p q, pge p q -> pincl q p = true.
Proof. hammer_hook "ValueDomain" "ValueDomain.pincl_ge_2".
destruct 1; simpl; auto.
- destruct p; auto.
- destruct p; simpl; auto; rewrite ! proj_sumbool_is_true; auto.
- rewrite ! proj_sumbool_is_true; auto.
Qed.
Lemma pincl_sound:
forall b ofs p q,
pincl p q = true -> pmatch b ofs p -> pmatch b ofs q.
Proof. hammer_hook "ValueDomain" "ValueDomain.pincl_sound".
intros. eapply pmatch_ge; eauto. apply pincl_ge; auto.
Qed.
Definition padd (p: aptr) (n: ptrofs) : aptr :=
match p with
| Gl id ofs => Gl id (Ptrofs.add ofs n)
| Stk ofs => Stk (Ptrofs.add ofs n)
| _ => p
end.
Lemma padd_sound:
forall b ofs p delta,
pmatch b ofs p ->
pmatch b (Ptrofs.add ofs delta) (padd p delta).
Proof. hammer_hook "ValueDomain" "ValueDomain.padd_sound".
intros. inv H; simpl padd; eauto with va.
Qed.
Definition psub (p: aptr) (n: ptrofs) : aptr :=
match p with
| Gl id ofs => Gl id (Ptrofs.sub ofs n)
| Stk ofs => Stk (Ptrofs.sub ofs n)
| _ => p
end.
Lemma psub_sound:
forall b ofs p delta,
pmatch b ofs p ->
pmatch b (Ptrofs.sub ofs delta) (psub p delta).
Proof. hammer_hook "ValueDomain" "ValueDomain.psub_sound".
intros. inv H; simpl psub; eauto with va.
Qed.
Definition poffset (p: aptr) : aptr :=
match p with
| Gl id ofs => Glo id
| Stk ofs => Stack
| _ => p
end.
Lemma poffset_sound:
forall b ofs1 ofs2 p,
pmatch b ofs1 p ->
pmatch b ofs2 (poffset p).
Proof. hammer_hook "ValueDomain" "ValueDomain.poffset_sound".
intros. inv H; simpl poffset; eauto with va.
Qed.
Definition cmp_different_blocks (c: comparison) : abool :=
match c with
| Ceq => Maybe false
| Cne => Maybe true
| _ => Bnone
end.
Lemma cmp_different_blocks_none:
forall c, cmatch None (cmp_different_blocks c).
Proof. hammer_hook "ValueDomain" "ValueDomain.cmp_different_blocks_none".
intros; destruct c; constructor.
Qed.
Lemma cmp_different_blocks_sound:
forall c, cmatch (Val.cmp_different_blocks c) (cmp_different_blocks c).
Proof. hammer_hook "ValueDomain" "ValueDomain.cmp_different_blocks_sound".
intros; destruct c; constructor.
Qed.
Definition pcmp (c: comparison) (p1 p2: aptr) : abool :=
match p1, p2 with
| Pbot, _ | _, Pbot => Bnone
| Gl id1 ofs1, Gl id2 ofs2 =>
if peq id1 id2 then Maybe (Ptrofs.cmpu c ofs1 ofs2)
else cmp_different_blocks c
| Gl id1 ofs1, Glo id2 =>
if peq id1 id2 then Btop else cmp_different_blocks c
| Glo id1, Gl id2 ofs2 =>
if peq id1 id2 then Btop else cmp_different_blocks c
| Glo id1, Glo id2 =>
if peq id1 id2 then Btop else cmp_different_blocks c
| Stk ofs1, Stk ofs2 => Maybe (Ptrofs.cmpu c ofs1 ofs2)
| (Gl _ _ | Glo _ | Glob | Nonstack), (Stk _ | Stack) => cmp_different_blocks c
| (Stk _ | Stack), (Gl _ _ | Glo _ | Glob | Nonstack) => cmp_different_blocks c
| _, _ => Btop
end.
Lemma pcmp_sound:
forall valid c b1 ofs1 p1 b2 ofs2 p2,
pmatch b1 ofs1 p1 -> pmatch b2 ofs2 p2 ->
cmatch (Val.cmpu_bool valid c (Vptr b1 ofs1) (Vptr b2 ofs2)) (pcmp c p1 p2).
Proof. hammer_hook "ValueDomain" "ValueDomain.pcmp_sound".
intros.
assert (DIFF: b1 <> b2 ->
cmatch (Val.cmpu_bool valid c (Vptr b1 ofs1) (Vptr b2 ofs2))
(cmp_different_blocks c)).
{
intros. simpl. rewrite dec_eq_false by assumption.
destruct Archi.ptr64.
apply cmp_different_blocks_none.
destruct (valid b1 (Ptrofs.unsigned ofs1) && valid b2 (Ptrofs.unsigned ofs2)); simpl.
apply cmp_different_blocks_sound.
apply cmp_different_blocks_none.
}
assert (SAME: b1 = b2 ->
cmatch (Val.cmpu_bool valid c (Vptr b1 ofs1) (Vptr b2 ofs2))
(Maybe (Ptrofs.cmpu c ofs1 ofs2))).
{
intros. subst b2. simpl. destruct Archi.ptr64.
constructor.
rewrite dec_eq_true.
destruct ((valid b1 (Ptrofs.unsigned ofs1) || valid b1 (Ptrofs.unsigned ofs1 - 1)) &&
(valid b1 (Ptrofs.unsigned ofs2) || valid b1 (Ptrofs.unsigned ofs2 - 1))); simpl.
constructor.
constructor.
}
unfold pcmp; inv H; inv H0; (apply cmatch_top || (apply DIFF; congruence) || idtac).
- destruct (peq id id0). subst id0. apply SAME. eapply bc_glob; eauto.
auto with va.
- destruct (peq id id0); auto with va.
- destruct (peq id id0); auto with va.
- destruct (peq id id0); auto with va.
- apply SAME. eapply bc_stack; eauto.
Qed.
Lemma pcmp_sound_64:
forall valid c b1 ofs1 p1 b2 ofs2 p2,
pmatch b1 ofs1 p1 -> pmatch b2 ofs2 p2 ->
cmatch (Val.cmplu_bool valid c (Vptr b1 ofs1) (Vptr b2 ofs2)) (pcmp c p1 p2).
Proof. hammer_hook "ValueDomain" "ValueDomain.pcmp_sound_64".
intros.
assert (DIFF: b1 <> b2 ->
cmatch (Val.cmplu_bool valid c (Vptr b1 ofs1) (Vptr b2 ofs2))
(cmp_different_blocks c)).
{
intros. simpl. rewrite dec_eq_false by assumption.
destruct Archi.ptr64; simpl.
destruct (valid b1 (Ptrofs.unsigned ofs1) && valid b2 (Ptrofs.unsigned ofs2)); simpl.
apply cmp_different_blocks_sound.
apply cmp_different_blocks_none.
apply cmp_different_blocks_none.
}
assert (SAME: b1 = b2 ->
cmatch (Val.cmplu_bool valid c (Vptr b1 ofs1) (Vptr b2 ofs2))
(Maybe (Ptrofs.cmpu c ofs1 ofs2))).
{
intros. subst b2. simpl. destruct Archi.ptr64.
rewrite dec_eq_true.
destruct ((valid b1 (Ptrofs.unsigned ofs1) || valid b1 (Ptrofs.unsigned ofs1 - 1)) &&
(valid b1 (Ptrofs.unsigned ofs2) || valid b1 (Ptrofs.unsigned ofs2 - 1))); simpl.
constructor.
constructor.
constructor.
}
unfold pcmp; inv H; inv H0; (apply cmatch_top || (apply DIFF; congruence) || idtac).
- destruct (peq id id0). subst id0. apply SAME. eapply bc_glob; eauto.
auto with va.
- destruct (peq id id0); auto with va.
- destruct (peq id id0); auto with va.
- destruct (peq id id0); auto with va.
- apply SAME. eapply bc_stack; eauto.
Qed.
Lemma pcmp_none:
forall c p1 p2, cmatch None (pcmp c p1 p2).
Proof. hammer_hook "ValueDomain" "ValueDomain.pcmp_none".
intros.
unfold pcmp; destruct p1; try constructor; destruct p2;
try (destruct (peq id id0)); try constructor; try (apply cmp_different_blocks_none).
Qed.
Definition pdisjoint (p1: aptr) (sz1: Z) (p2: aptr) (sz2: Z) : bool :=
match p1, p2 with
| Pbot, _ => true
| _, Pbot => true
| Gl id1 ofs1, Gl id2 ofs2 =>
if peq id1 id2
then zle (Ptrofs.unsigned ofs1 + sz1) (Ptrofs.unsigned ofs2)
|| zle (Ptrofs.unsigned ofs2 + sz2) (Ptrofs.unsigned ofs1)
else true
| Gl id1 ofs1, Glo id2 => negb(peq id1 id2)
| Glo id1, Gl id2 ofs2 => negb(peq id1 id2)
| Glo id1, Glo id2 => negb(peq id1 id2)
| Stk ofs1, Stk ofs2 =>
zle (Ptrofs.unsigned ofs1 + sz1) (Ptrofs.unsigned ofs2)
|| zle (Ptrofs.unsigned ofs2 + sz2) (Ptrofs.unsigned ofs1)
| (Gl _ _ | Glo _ | Glob | Nonstack), (Stk _ | Stack) => true
| (Stk _ | Stack), (Gl _ _ | Glo _ | Glob | Nonstack) => true
| _, _ => false
end.
Lemma pdisjoint_sound:
forall sz1 b1 ofs1 p1 sz2 b2 ofs2 p2,
pdisjoint p1 sz1 p2 sz2 = true ->
pmatch b1 ofs1 p1 -> pmatch b2 ofs2 p2 ->
b1 <> b2 \/ Ptrofs.unsigned ofs1 + sz1 <= Ptrofs.unsigned ofs2 \/ Ptrofs.unsigned ofs2 + sz2 <= Ptrofs.unsigned ofs1.
Proof. hammer_hook "ValueDomain" "ValueDomain.pdisjoint_sound".
intros. inv H0; inv H1; simpl in H; try discriminate; try (left; congruence).
- destruct (peq id id0). subst id0. destruct (orb_true_elim _ _ H); InvBooleans; auto.
left; congruence.
- destruct (peq id id0); try discriminate. left; congruence.
- destruct (peq id id0); try discriminate. left; congruence.
- destruct (peq id id0); try discriminate. left; congruence.
- destruct (orb_true_elim _ _ H); InvBooleans; auto.
Qed.
Inductive aval : Type :=
| Vbot
| I (n: int)
| Uns (p: aptr) (n: Z)
| Sgn (p: aptr) (n: Z)
| L (n: int64)
| F (f: float)
| FS (f: float32)
| Ptr (p: aptr)
| Ifptr (p: aptr).
Definition Vtop := Ifptr Ptop.
Definition eq_aval: forall (v1 v2: aval), {v1=v2} + {v1<>v2}.
Proof. hammer_hook "ValueDomain" "ValueDomain.eq_aval".
intros. generalize zeq Int.eq_dec Int64.eq_dec Float.eq_dec Float32.eq_dec eq_aptr; intros.
decide equality.
Defined.
Definition is_uns (n: Z) (i: int) : Prop :=
forall m, 0 <= m < Int.zwordsize -> m >= n -> Int.testbit i m = false.
Definition is_sgn (n: Z) (i: int) : Prop :=
forall m, 0 <= m < Int.zwordsize -> m >= n - 1 -> Int.testbit i m = Int.testbit i (Int.zwordsize - 1).
Inductive vmatch : val -> aval -> Prop :=
| vmatch_i: forall i, vmatch (Vint i) (I i)
| vmatch_Uns: forall p i n, 0 <= n -> is_uns n i -> vmatch (Vint i) (Uns p n)
| vmatch_Uns_undef: forall p n, vmatch Vundef (Uns p n)
| vmatch_Sgn: forall p i n, 0 < n -> is_sgn n i -> vmatch (Vint i) (Sgn p n)
| vmatch_Sgn_undef: forall p n, vmatch Vundef (Sgn p n)
| vmatch_l: forall i, vmatch (Vlong i) (L i)
| vmatch_f: forall f, vmatch (Vfloat f) (F f)
| vmatch_s: forall f, vmatch (Vsingle f) (FS f)
| vmatch_ptr: forall b ofs p, pmatch b ofs p -> vmatch (Vptr b ofs) (Ptr p)
| vmatch_ptr_undef: forall p, vmatch Vundef (Ptr p)
| vmatch_ifptr_undef: forall p, vmatch Vundef (Ifptr p)
| vmatch_ifptr_i: forall i p, vmatch (Vint i) (Ifptr p)
| vmatch_ifptr_l: forall i p, vmatch (Vlong i) (Ifptr p)
| vmatch_ifptr_f: forall f p, vmatch (Vfloat f) (Ifptr p)
| vmatch_ifptr_s: forall f p, vmatch (Vsingle f) (Ifptr p)
| vmatch_ifptr_p: forall b ofs p, pmatch b ofs p -> vmatch (Vptr b ofs) (Ifptr p).
Lemma vmatch_ifptr:
forall v p,
(forall b ofs, v = Vptr b ofs -> pmatch b ofs p) ->
vmatch v (Ifptr p).
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_ifptr".
intros. destruct v; constructor; auto.
Qed.
Lemma vmatch_top: forall v x, vmatch v x -> vmatch v Vtop.
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_top".
intros. apply vmatch_ifptr. intros. subst v. inv H; eapply pmatch_top'; eauto.
Qed.
Hint Extern 1 (vmatch _ _) => constructor : va.
Lemma is_uns_mon: forall n1 n2 i, is_uns n1 i -> n1 <= n2 -> is_uns n2 i.
Proof. hammer_hook "ValueDomain" "ValueDomain.is_uns_mon".
intros; red; intros. apply H; omega.
Qed.
Lemma is_sgn_mon: forall n1 n2 i, is_sgn n1 i -> n1 <= n2 -> is_sgn n2 i.
Proof. hammer_hook "ValueDomain" "ValueDomain.is_sgn_mon".
intros; red; intros. apply H; omega.
Qed.
Lemma is_uns_sgn: forall n1 n2 i, is_uns n1 i -> n1 < n2 -> is_sgn n2 i.
Proof. hammer_hook "ValueDomain" "ValueDomain.is_uns_sgn".
intros; red; intros. rewrite ! H by omega. auto.
Qed.
Definition usize := Int.size.
Definition ssize (i: int) := Int.size (if Int.lt i Int.zero then Int.not i else i) + 1.
Lemma is_uns_usize:
forall i, is_uns (usize i) i.
Proof. hammer_hook "ValueDomain" "ValueDomain.is_uns_usize".
unfold usize; intros; red; intros.
apply Int.bits_size_2. omega.
Qed.
Lemma is_sgn_ssize:
forall i, is_sgn (ssize i) i.
Proof. hammer_hook "ValueDomain" "ValueDomain.is_sgn_ssize".
unfold ssize; intros; red; intros.
destruct (Int.lt i Int.zero) eqn:LT.
- rewrite <- (negb_involutive (Int.testbit i m)).
rewrite <- (negb_involutive (Int.testbit i (Int.zwordsize - 1))).
f_equal.
generalize (Int.size_range (Int.not i)); intros RANGE.
rewrite <- ! Int.bits_not by omega.
rewrite ! Int.bits_size_2 by omega.
auto.
- rewrite ! Int.bits_size_2 by omega.
auto.
Qed.
Lemma is_uns_zero_ext:
forall n i, is_uns n i <-> Int.zero_ext n i = i.
Proof. hammer_hook "ValueDomain" "ValueDomain.is_uns_zero_ext".
intros; split; intros.
Int.bit_solve. destruct (zlt i0 n); auto. symmetry; apply H; auto. omega.
rewrite <- H. red; intros. rewrite Int.bits_zero_ext by omega. rewrite zlt_false by omega. auto.
Qed.
Lemma is_sgn_sign_ext:
forall n i, 0 < n -> (is_sgn n i <-> Int.sign_ext n i = i).
Proof. hammer_hook "ValueDomain" "ValueDomain.is_sgn_sign_ext".
intros; split; intros.
Int.bit_solve. destruct (zlt i0 n); auto.
transitivity (Int.testbit i (Int.zwordsize - 1)).
apply H0; omega. symmetry; apply H0; omega.
rewrite <- H0. red; intros. rewrite ! Int.bits_sign_ext by omega.
f_equal. transitivity (n-1). destruct (zlt m n); omega.
destruct (zlt (Int.zwordsize - 1) n); omega.
Qed.
Lemma is_zero_ext_uns:
forall i n m,
is_uns m i \/ n <= m -> is_uns m (Int.zero_ext n i).
Proof. hammer_hook "ValueDomain" "ValueDomain.is_zero_ext_uns".
intros. red; intros. rewrite Int.bits_zero_ext by omega.
destruct (zlt m0 n); auto. destruct H. apply H; omega. omegaContradiction.
Qed.
Lemma is_zero_ext_sgn:
forall i n m,
n < m ->
is_sgn m (Int.zero_ext n i).
Proof. hammer_hook "ValueDomain" "ValueDomain.is_zero_ext_sgn".
intros. red; intros. rewrite ! Int.bits_zero_ext by omega.
transitivity false. apply zlt_false; omega.
symmetry; apply zlt_false; omega.
Qed.
Lemma is_sign_ext_uns:
forall i n m,
0 <= m < n ->
is_uns m i ->
is_uns m (Int.sign_ext n i).
Proof. hammer_hook "ValueDomain" "ValueDomain.is_sign_ext_uns".
intros; red; intros. rewrite Int.bits_sign_ext by omega.
apply H0. destruct (zlt m0 n); omega. destruct (zlt m0 n); omega.
Qed.
Lemma is_sign_ext_sgn:
forall i n m,
0 < n -> 0 < m ->
is_sgn m i \/ n <= m -> is_sgn m (Int.sign_ext n i).
Proof. hammer_hook "ValueDomain" "ValueDomain.is_sign_ext_sgn".
intros. apply is_sgn_sign_ext; auto.
destruct (zlt m n). destruct H1. apply is_sgn_sign_ext in H1; auto.
rewrite <- H1. rewrite (Int.sign_ext_widen i) by omega. apply Int.sign_ext_idem; auto.
omegaContradiction.
apply Int.sign_ext_widen; omega.
Qed.
Hint Resolve is_uns_mon is_sgn_mon is_uns_sgn is_uns_usize is_sgn_ssize : va.
Lemma is_uns_1:
forall n, is_uns 1 n -> n = Int.zero \/ n = Int.one.
Proof. hammer_hook "ValueDomain" "ValueDomain.is_uns_1".
intros. destruct (Int.testbit n 0) eqn:B0; [right|left]; apply Int.same_bits_eq; intros.
rewrite Int.bits_one. destruct (zeq i 0). subst i; auto. apply H; omega.
rewrite Int.bits_zero. destruct (zeq i 0). subst i; auto. apply H; omega.
Qed.
Definition provenance (x: aval) : aptr :=
if va_strict tt then Pbot else
match x with
| Ptr p | Ifptr p | Uns p _ | Sgn p _ => poffset p
| _ => Pbot
end.
Definition ntop : aval := Ifptr Pbot.
Definition ntop1 (x: aval) : aval := Ifptr (provenance x).
Definition ntop2 (x y: aval) : aval := Ifptr (plub (provenance x) (provenance y)).
Definition uns (p: aptr) (n: Z) : aval :=
if zle n 1 then Uns p 1
else if zle n 7 then Uns p 7
else if zle n 8 then Uns p 8
else if zle n 15 then Uns p 15
else if zle n 16 then Uns p 16
else Ifptr p.
Definition sgn (p: aptr) (n: Z) : aval :=
if zle n 8 then Sgn p 8 else if zle n 16 then Sgn p 16 else Ifptr p.
Lemma vmatch_uns':
forall p i n, is_uns (Z.max 0 n) i -> vmatch (Vint i) (uns p n).
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_uns'".
intros.
assert (A: forall n', n' >= 0 -> n' >= n -> is_uns n' i) by (eauto with va).
unfold uns.
destruct (zle n 1). auto with va.
destruct (zle n 7). auto with va.
destruct (zle n 8). auto with va.
destruct (zle n 15). auto with va.
destruct (zle n 16). auto with va.
auto with va.
Qed.
Lemma vmatch_uns:
forall p i n, is_uns n i -> vmatch (Vint i) (uns p n).
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_uns".
intros. apply vmatch_uns'. eauto with va.
Qed.
Lemma vmatch_uns_undef: forall p n, vmatch Vundef (uns p n).
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_uns_undef".
intros. unfold uns.
destruct (zle n 1). auto with va.
destruct (zle n 7). auto with va.
destruct (zle n 8). auto with va.
destruct (zle n 15). auto with va.
destruct (zle n 16); auto with va.
Qed.
Lemma vmatch_sgn':
forall p i n, is_sgn (Z.max 1 n) i -> vmatch (Vint i) (sgn p n).
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_sgn'".
intros.
assert (A: forall n', n' >= 1 -> n' >= n -> is_sgn n' i) by (eauto with va).
unfold sgn.
destruct (zle n 8). auto with va.
destruct (zle n 16); auto with va.
Qed.
Lemma vmatch_sgn:
forall p i n, is_sgn n i -> vmatch (Vint i) (sgn p n).
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_sgn".
intros. apply vmatch_sgn'. eauto with va.
Qed.
Lemma vmatch_sgn_undef: forall p n, vmatch Vundef (sgn p n).
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_sgn_undef".
intros. unfold sgn.
destruct (zle n 8). auto with va.
destruct (zle n 16); auto with va.
Qed.
Hint Resolve vmatch_uns vmatch_uns_undef vmatch_sgn vmatch_sgn_undef : va.
Lemma vmatch_Uns_1:
forall p v, vmatch v (Uns p 1) -> v = Vundef \/ v = Vint Int.zero \/ v = Vint Int.one.
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_Uns_1".
intros. inv H; auto. right. exploit is_uns_1; eauto. intuition congruence.
Qed.
Inductive vge: aval -> aval -> Prop :=
| vge_bot: forall v, vge v Vbot
| vge_i: forall i, vge (I i) (I i)
| vge_l: forall i, vge (L i) (L i)
| vge_f: forall f, vge (F f) (F f)
| vge_s: forall f, vge (FS f) (FS f)
| vge_uns_i: forall p n i, 0 <= n -> is_uns n i -> vge (Uns p n) (I i)
| vge_uns_uns: forall p1 n1 p2 n2, n1 >= n2 -> pge p1 p2 -> vge (Uns p1 n1) (Uns p2 n2)
| vge_sgn_i: forall p n i, 0 < n -> is_sgn n i -> vge (Sgn p n) (I i)
| vge_sgn_sgn: forall p1 n1 p2 n2, n1 >= n2 -> pge p1 p2 -> vge (Sgn p1 n1) (Sgn p2 n2)
| vge_sgn_uns: forall p1 n1 p2 n2, n1 > n2 -> pge p1 p2 -> vge (Sgn p1 n1) (Uns p2 n2)
| vge_p_p: forall p q, pge p q -> vge (Ptr p) (Ptr q)
| vge_ip_p: forall p q, pge p q -> vge (Ifptr p) (Ptr q)
| vge_ip_ip: forall p q, pge p q -> vge (Ifptr p) (Ifptr q)
| vge_ip_i: forall p i, vge (Ifptr p) (I i)
| vge_ip_l: forall p i, vge (Ifptr p) (L i)
| vge_ip_f: forall p f, vge (Ifptr p) (F f)
| vge_ip_s: forall p f, vge (Ifptr p) (FS f)
| vge_ip_uns: forall p q n, pge p q -> vge (Ifptr p) (Uns q n)
| vge_ip_sgn: forall p q n, pge p q -> vge (Ifptr p) (Sgn q n).
Hint Constructors vge : va.
Lemma vge_top: forall v, vge Vtop v.
Proof. hammer_hook "ValueDomain" "ValueDomain.vge_top".
destruct v; constructor; constructor.
Qed.
Hint Resolve vge_top : va.
Lemma vge_refl: forall v, vge v v.
Proof. hammer_hook "ValueDomain" "ValueDomain.vge_refl".
destruct v; auto with va.
Qed.
Lemma vge_trans: forall u v, vge u v -> forall w, vge v w -> vge u w.
Proof. hammer_hook "ValueDomain" "ValueDomain.vge_trans".
induction 1; intros w V; inv V; eauto using pge_trans with va.
Qed.
Lemma vmatch_ge:
forall v x y, vge x y -> vmatch v y -> vmatch v x.
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_ge".
induction 1; intros V; inv V; eauto using pmatch_ge with va.
Qed.
Definition vlub (v w: aval) : aval :=
match v, w with
| Vbot, _ => w
| _, Vbot => v
| I i1, I i2 =>
if Int.eq i1 i2 then v else
if Int.lt i1 Int.zero || Int.lt i2 Int.zero
then sgn Pbot (Z.max (ssize i1) (ssize i2))
else uns Pbot (Z.max (usize i1) (usize i2))
| I i, Uns p n | Uns p n, I i =>
if Int.lt i Int.zero
then sgn p (Z.max (ssize i) (n + 1))
else uns p (Z.max (usize i) n)
| I i, Sgn p n | Sgn p n, I i =>
sgn p (Z.max (ssize i) n)
| I i, (Ptr p | Ifptr p) | (Ptr p | Ifptr p), I i =>
if va_strict tt || Int.eq i Int.zero then Ifptr p else Vtop
| Uns p1 n1, Uns p2 n2 => Uns (plub p1 p2) (Z.max n1 n2)
| Uns p1 n1, Sgn p2 n2 => sgn (plub p1 p2) (Z.max (n1 + 1) n2)
| Sgn p1 n1, Uns p2 n2 => sgn (plub p1 p2) (Z.max n1 (n2 + 1))
| Sgn p1 n1, Sgn p2 n2 => sgn (plub p1 p2) (Z.max n1 n2)
| F f1, F f2 =>
if Float.eq_dec f1 f2 then v else ntop
| FS f1, FS f2 =>
if Float32.eq_dec f1 f2 then v else ntop
| L i1, L i2 =>
if Int64.eq i1 i2 then v else ntop
| Ptr p1, Ptr p2 => Ptr(plub p1 p2)
| Ptr p1, Ifptr p2 => Ifptr(plub p1 p2)
| Ifptr p1, Ptr p2 => Ifptr(plub p1 p2)
| Ifptr p1, Ifptr p2 => Ifptr(plub p1 p2)
| (Ptr p1 | Ifptr p1), (Uns p2 _ | Sgn p2 _) => Ifptr(plub p1 p2)
| (Uns p1 _ | Sgn p1 _), (Ptr p2 | Ifptr p2) => Ifptr(plub p1 p2)
| _, (Ptr p | Ifptr p) | (Ptr p | Ifptr p), _ => if va_strict tt then Ifptr p else Vtop
| _, _ => Vtop
end.
Lemma vlub_comm:
forall v w, vlub v w = vlub w v.
Proof. hammer_hook "ValueDomain" "ValueDomain.vlub_comm".
intros. unfold vlub; destruct v; destruct w; auto.
- rewrite Int.eq_sym. predSpec Int.eq Int.eq_spec n0 n.
congruence.
rewrite orb_comm.
destruct (Int.lt n0 Int.zero || Int.lt n Int.zero); f_equal; apply Z.max_comm.
- f_equal. apply plub_comm. apply Z.max_comm.
- f_equal. apply plub_comm. apply Z.max_comm.
- f_equal; apply plub_comm.
- f_equal; apply plub_comm.
- f_equal. apply plub_comm. apply Z.max_comm.
- f_equal. apply plub_comm. apply Z.max_comm.
- f_equal; apply plub_comm.
- f_equal; apply plub_comm.
- rewrite Int64.eq_sym. predSpec Int64.eq Int64.eq_spec n0 n; congruence.
- rewrite dec_eq_sym. destruct (Float.eq_dec f0 f). congruence. auto.
- rewrite dec_eq_sym. destruct (Float32.eq_dec f0 f). congruence. auto.
- f_equal; apply plub_comm.
- f_equal; apply plub_comm.
- f_equal; apply plub_comm.
- f_equal; apply plub_comm.
- f_equal; apply plub_comm.
- f_equal; apply plub_comm.
- f_equal; apply plub_comm.
- f_equal; apply plub_comm.
Qed.
Lemma vge_uns_uns': forall p n, vge (uns p n) (Uns p n).
Proof. hammer_hook "ValueDomain" "ValueDomain.vge_uns_uns'".
unfold uns; intros.
destruct (zle n 1). auto with va.
destruct (zle n 7). auto with va.
destruct (zle n 8). auto with va.
destruct (zle n 15). auto with va.
destruct (zle n 16); auto with va.
Qed.
Lemma vge_uns_i': forall p n i, 0 <= n -> is_uns n i -> vge (uns p n) (I i).
Proof. hammer_hook "ValueDomain" "ValueDomain.vge_uns_i'".
intros. apply vge_trans with (Uns p n). apply vge_uns_uns'. auto with va.
Qed.
Lemma vge_sgn_sgn': forall p n, vge (sgn p n) (Sgn p n).
Proof. hammer_hook "ValueDomain" "ValueDomain.vge_sgn_sgn'".
unfold sgn; intros.
destruct (zle n 8). auto with va.
destruct (zle n 16); auto with va.
Qed.
Lemma vge_sgn_i': forall p n i, 0 < n -> is_sgn n i -> vge (sgn p n) (I i).
Proof. hammer_hook "ValueDomain" "ValueDomain.vge_sgn_i'".
intros. apply vge_trans with (Sgn p n). apply vge_sgn_sgn'. auto with va.
Qed.
Hint Resolve vge_uns_uns' vge_uns_i' vge_sgn_sgn' vge_sgn_i' : va.
Lemma usize_pos: forall n, 0 <= usize n.
Proof. hammer_hook "ValueDomain" "ValueDomain.usize_pos".
unfold usize; intros. generalize (Int.size_range n); omega.
Qed.
Lemma ssize_pos: forall n, 0 < ssize n.
Proof. hammer_hook "ValueDomain" "ValueDomain.ssize_pos".
unfold ssize; intros.
generalize (Int.size_range (if Int.lt n Int.zero then Int.not n else n)); omega.
Qed.
Lemma vge_lub_l:
forall x y, vge (vlub x y) x.
Proof. hammer_hook "ValueDomain" "ValueDomain.vge_lub_l".
assert (IFSTRICT: forall (cond: bool) x1 x2 y, vge x1 y -> vge x2 y -> vge (if cond then x1 else x2) y).
{ destruct cond; auto with va. }
unfold vlub; destruct x, y; eauto using pge_lub_l with va.
- predSpec Int.eq Int.eq_spec n n0. auto with va.
destruct (Int.lt n Int.zero || Int.lt n0 Int.zero).
apply vge_sgn_i'. generalize (ssize_pos n); xomega. eauto with va.
apply vge_uns_i'. generalize (usize_pos n); xomega. eauto with va.
- destruct (Int.lt n Int.zero).
apply vge_sgn_i'. generalize (ssize_pos n); xomega. eauto with va.
apply vge_uns_i'. generalize (usize_pos n); xomega. eauto with va.
- apply vge_sgn_i'. generalize (ssize_pos n); xomega. eauto with va.
- destruct (Int.lt n0 Int.zero).
eapply vge_trans. apply vge_sgn_sgn'.
apply vge_trans with (Sgn p (n + 1)); eauto with va.
eapply vge_trans. apply vge_uns_uns'. eauto with va.
- eapply vge_trans. apply vge_sgn_sgn'.
apply vge_trans with (Sgn p (n + 1)); eauto using pge_lub_l with va.
- eapply vge_trans. apply vge_sgn_sgn'. eauto with va.
- eapply vge_trans. apply vge_sgn_sgn'. eauto using pge_lub_l with va.
- eapply vge_trans. apply vge_sgn_sgn'. eauto using pge_lub_l with va.
- destruct (Int64.eq n n0); constructor.
- destruct (Float.eq_dec f f0); constructor.
- destruct (Float32.eq_dec f f0); constructor.
Qed.
Lemma vge_lub_r:
forall x y, vge (vlub x y) y.
Proof. hammer_hook "ValueDomain" "ValueDomain.vge_lub_r".
intros. rewrite vlub_comm. apply vge_lub_l.
Qed.
Lemma vmatch_lub_l:
forall v x y, vmatch v x -> vmatch v (vlub x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_lub_l".
intros. eapply vmatch_ge; eauto. apply vge_lub_l.
Qed.
Lemma vmatch_lub_r:
forall v x y, vmatch v y -> vmatch v (vlub x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_lub_r".
intros. rewrite vlub_comm. apply vmatch_lub_l; auto.
Qed.
Definition aptr_of_aval (v: aval) : aptr :=
match v with
| Ptr p => p
| Ifptr p => p
| _ => if va_strict tt then Pbot else Nonstack
end.
Lemma match_aptr_of_aval:
forall b ofs av,
vmatch (Vptr b ofs) av -> pmatch b ofs (aptr_of_aval av).
Proof. hammer_hook "ValueDomain" "ValueDomain.match_aptr_of_aval".
unfold aptr_of_aval; intros. inv H; auto.
Qed.
Definition vplub (v: aval) (p: aptr) : aptr :=
match v with
| Ptr q => plub q p
| Ifptr q => plub q p
| _ => p
end.
Lemma vmatch_vplub_l:
forall v x p, vmatch v x -> vmatch v (Ifptr (vplub x p)).
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_vplub_l".
intros. unfold vplub; inv H; auto with va; constructor; eapply pmatch_lub_l; eauto.
Qed.
Lemma pmatch_vplub:
forall b ofs x p, pmatch b ofs p -> pmatch b ofs (vplub x p).
Proof. hammer_hook "ValueDomain" "ValueDomain.pmatch_vplub".
intros.
assert (DFL: pmatch b ofs (if va_strict tt then p else Ptop)).
{ destruct (va_strict tt); auto. eapply pmatch_top'; eauto. }
unfold vplub; destruct x; auto; apply pmatch_lub_r; auto.
Qed.
Lemma vmatch_vplub_r:
forall v x p, vmatch v (Ifptr p) -> vmatch v (Ifptr (vplub x p)).
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_vplub_r".
intros. apply vmatch_ifptr; intros; subst v. inv H. apply pmatch_vplub; auto.
Qed.
Definition vpincl (v: aval) (p: aptr) : bool :=
match v with
| Ptr q | Ifptr q | Uns q _ | Sgn q _ => pincl q p
| _ => true
end.
Lemma vpincl_ge:
forall x p, vpincl x p = true -> vge (Ifptr p) x.
Proof. hammer_hook "ValueDomain" "ValueDomain.vpincl_ge".
unfold vpincl; intros. destruct x; constructor; apply pincl_ge; auto.
Qed.
Lemma vpincl_sound:
forall v x p, vpincl x p = true -> vmatch v x -> vmatch v (Ifptr p).
Proof. hammer_hook "ValueDomain" "ValueDomain.vpincl_sound".
intros. apply vmatch_ge with x; auto. apply vpincl_ge; auto.
Qed.
Definition vincl (v w: aval) : bool :=
match v, w with
| Vbot, _ => true
| I i, I j => Int.eq_dec i j
| I i, Uns p n => Int.eq_dec (Int.zero_ext n i) i && zle 0 n
| I i, Sgn p n => Int.eq_dec (Int.sign_ext n i) i && zlt 0 n
| Uns p n, Uns q m => zle n m && pincl p q
| Uns p n, Sgn q m => zlt n m && pincl p q
| Sgn p n, Sgn q m => zle n m && pincl p q
| L i, L j => Int64.eq_dec i j
| F i, F j => Float.eq_dec i j
| FS i, FS j => Float32.eq_dec i j
| Ptr p, Ptr q => pincl p q
| (Ptr p | Ifptr p | Uns p _ | Sgn p _), Ifptr q => pincl p q
| _, Ifptr _ => true
| _, _ => false
end.
Lemma vincl_ge: forall v w, vincl v w = true -> vge w v.
Proof. hammer_hook "ValueDomain" "ValueDomain.vincl_ge".
unfold vincl; destruct v; destruct w;
intros; try discriminate; try InvBooleans; try subst; auto using pincl_ge with va.
- constructor; auto. rewrite is_uns_zero_ext; auto.
- constructor; auto. rewrite is_sgn_sign_ext; auto.
Qed.
Definition genv_match (ge: genv) : Prop :=
(forall id b, Genv.find_symbol ge id = Some b <-> bc b = BCglob id)
/\(forall b, Plt b (Genv.genv_next ge) -> bc b <> BCinvalid /\ bc b <> BCstack).
Lemma symbol_address_sound:
forall ge id ofs,
genv_match ge ->
vmatch (Genv.symbol_address ge id ofs) (Ptr (Gl id ofs)).
Proof. hammer_hook "ValueDomain" "ValueDomain.symbol_address_sound".
intros. unfold Genv.symbol_address. destruct (Genv.find_symbol ge id) as [b|] eqn:F.
constructor. constructor. apply H; auto.
constructor.
Qed.
Lemma vmatch_ptr_gl:
forall ge v id ofs,
genv_match ge ->
vmatch v (Ptr (Gl id ofs)) ->
Val.lessdef v (Genv.symbol_address ge id ofs).
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_ptr_gl".
intros. unfold Genv.symbol_address. inv H0.
- inv H3. replace (Genv.find_symbol ge id) with (Some b). constructor.
symmetry. apply H; auto.
- constructor.
Qed.
Lemma vmatch_ptr_stk:
forall v ofs sp,
vmatch v (Ptr(Stk ofs)) ->
bc sp = BCstack ->
Val.lessdef v (Vptr sp ofs).
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_ptr_stk".
intros. inv H.
- inv H3. replace b with sp by (eapply bc_stack; eauto). constructor.
- constructor.
Qed.
Definition unop_int (sem: int -> int) (x: aval) :=
match x with I n => I (sem n) | _ => ntop1 x end.
Lemma unop_int_sound:
forall sem v x,
vmatch v x ->
vmatch (match v with Vint i => Vint(sem i) | _ => Vundef end) (unop_int sem x).
Proof. hammer_hook "ValueDomain" "ValueDomain.unop_int_sound".
intros. unfold unop_int; inv H; auto with va.
Qed.
Definition binop_int (sem: int -> int -> int) (x y: aval) :=
match x, y with I n, I m => I (sem n m) | _, _ => ntop2 x y end.
Lemma binop_int_sound:
forall sem v x w y,
vmatch v x -> vmatch w y ->
vmatch (match v, w with Vint i, Vint j => Vint(sem i j) | _, _ => Vundef end) (binop_int sem x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.binop_int_sound".
intros. unfold binop_int; inv H; auto with va; inv H0; auto with va.
Qed.
Definition unop_long (sem: int64 -> int64) (x: aval) :=
match x with L n => L (sem n) | _ => ntop1 x end.
Lemma unop_long_sound:
forall sem v x,
vmatch v x ->
vmatch (match v with Vlong i => Vlong(sem i) | _ => Vundef end) (unop_long sem x).
Proof. hammer_hook "ValueDomain" "ValueDomain.unop_long_sound".
intros. unfold unop_long; inv H; auto with va.
Qed.
Definition binop_long (sem: int64 -> int64 -> int64) (x y: aval) :=
match x, y with L n, L m => L (sem n m) | _, _ => ntop2 x y end.
Lemma binop_long_sound:
forall sem v x w y,
vmatch v x -> vmatch w y ->
vmatch (match v, w with Vlong i, Vlong j => Vlong(sem i j) | _, _ => Vundef end) (binop_long sem x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.binop_long_sound".
intros. unfold binop_long; inv H; auto with va; inv H0; auto with va.
Qed.
Definition unop_float (sem: float -> float) (x: aval) :=
match x with F n => F (sem n) | _ => ntop1 x end.
Lemma unop_float_sound:
forall sem v x,
vmatch v x ->
vmatch (match v with Vfloat i => Vfloat(sem i) | _ => Vundef end) (unop_float sem x).
Proof. hammer_hook "ValueDomain" "ValueDomain.unop_float_sound".
intros. unfold unop_float; inv H; auto with va.
Qed.
Definition binop_float (sem: float -> float -> float) (x y: aval) :=
match x, y with F n, F m => F (sem n m) | _, _ => ntop2 x y end.
Lemma binop_float_sound:
forall sem v x w y,
vmatch v x -> vmatch w y ->
vmatch (match v, w with Vfloat i, Vfloat j => Vfloat(sem i j) | _, _ => Vundef end) (binop_float sem x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.binop_float_sound".
intros. unfold binop_float; inv H; auto with va; inv H0; auto with va.
Qed.
Definition unop_single (sem: float32 -> float32) (x: aval) :=
match x with FS n => FS (sem n) | _ => ntop1 x end.
Lemma unop_single_sound:
forall sem v x,
vmatch v x ->
vmatch (match v with Vsingle i => Vsingle(sem i) | _ => Vundef end) (unop_single sem x).
Proof. hammer_hook "ValueDomain" "ValueDomain.unop_single_sound".
intros. unfold unop_single; inv H; auto with va.
Qed.
Definition binop_single (sem: float32 -> float32 -> float32) (x y: aval) :=
match x, y with FS n, FS m => FS (sem n m) | _, _ => ntop2 x y end.
Lemma binop_single_sound:
forall sem v x w y,
vmatch v x -> vmatch w y ->
vmatch (match v, w with Vsingle i, Vsingle j => Vsingle(sem i j) | _, _ => Vundef end) (binop_single sem x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.binop_single_sound".
intros. unfold binop_single; inv H; auto with va; inv H0; auto with va.
Qed.
Definition shl (v w: aval) :=
match w with
| I amount =>
if Int.ltu amount Int.iwordsize then
match v with
| I i => I (Int.shl i amount)
| Uns p n => uns p (n + Int.unsigned amount)
| Sgn p n => sgn p (n + Int.unsigned amount)
| _ => ntop1 v
end
else ntop1 v
| _ => ntop1 v
end.
Lemma shl_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.shl v w) (shl x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.shl_sound".
intros.
assert (DEFAULT: vmatch (Val.shl v w) (ntop1 x)).
{
destruct v; destruct w; simpl; try constructor.
destruct (Int.ltu i0 Int.iwordsize); constructor.
}
destruct y; auto. simpl. inv H0. unfold Val.shl.
destruct (Int.ltu n Int.iwordsize) eqn:LTU; auto.
exploit Int.ltu_inv; eauto. intros RANGE.
inv H; auto with va.
- apply vmatch_uns'. red; intros. rewrite Int.bits_shl by omega.
destruct (zlt m (Int.unsigned n)). auto. apply H1; xomega.
- apply vmatch_sgn'. red; intros. zify.
rewrite ! Int.bits_shl by omega.
rewrite ! zlt_false by omega.
rewrite H1 by omega. symmetry. rewrite H1 by omega. auto.
- destruct v; constructor.
Qed.
Definition shru (v w: aval) :=
match w with
| I amount =>
if Int.ltu amount Int.iwordsize then
match v with
| I i => I (Int.shru i amount)
| Uns p n => uns p (n - Int.unsigned amount)
| _ => uns (provenance v) (Int.zwordsize - Int.unsigned amount)
end
else ntop1 v
| _ => ntop1 v
end.
Lemma shru_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.shru v w) (shru x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.shru_sound".
intros.
assert (DEFAULT: vmatch (Val.shru v w) (ntop1 x)).
{
destruct v; destruct w; simpl; try constructor.
destruct (Int.ltu i0 Int.iwordsize); constructor.
}
destruct y; auto. inv H0. unfold shru, Val.shru.
destruct (Int.ltu n Int.iwordsize) eqn:LTU; auto.
exploit Int.ltu_inv; eauto. intros RANGE. change (Int.unsigned Int.iwordsize) with Int.zwordsize in RANGE.
assert (DEFAULT2: forall i, vmatch (Vint (Int.shru i n)) (uns (provenance x) (Int.zwordsize - Int.unsigned n))).
{
intros. apply vmatch_uns. red; intros.
rewrite Int.bits_shru by omega. apply zlt_false. omega.
}
inv H; auto with va.
- apply vmatch_uns'. red; intros. zify.
rewrite Int.bits_shru by omega.
destruct (zlt (m + Int.unsigned n) Int.zwordsize); auto.
apply H1; omega.
- destruct v; constructor.
Qed.
Definition shr (v w: aval) :=
match w with
| I amount =>
if Int.ltu amount Int.iwordsize then
match v with
| I i => I (Int.shr i amount)
| Uns p n => sgn p (n + 1 - Int.unsigned amount)
| Sgn p n => sgn p (n - Int.unsigned amount)
| _ => sgn (provenance v) (Int.zwordsize - Int.unsigned amount)
end
else ntop1 v
| _ => ntop1 v
end.
Lemma shr_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.shr v w) (shr x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.shr_sound".
intros.
assert (DEFAULT: vmatch (Val.shr v w) (ntop1 x)).
{
destruct v; destruct w; simpl; try constructor.
destruct (Int.ltu i0 Int.iwordsize); constructor.
}
destruct y; auto. inv H0. unfold shr, Val.shr.
destruct (Int.ltu n Int.iwordsize) eqn:LTU; auto.
exploit Int.ltu_inv; eauto. intros RANGE. change (Int.unsigned Int.iwordsize) with Int.zwordsize in RANGE.
assert (DEFAULT2: forall i, vmatch (Vint (Int.shr i n)) (sgn (provenance x) (Int.zwordsize - Int.unsigned n))).
{
intros. apply vmatch_sgn. red; intros.
rewrite ! Int.bits_shr by omega. f_equal.
destruct (zlt (m + Int.unsigned n) Int.zwordsize);
destruct (zlt (Int.zwordsize - 1 + Int.unsigned n) Int.zwordsize);
omega.
}
assert (SGN: forall q i p, is_sgn p i -> 0 < p -> vmatch (Vint (Int.shr i n)) (sgn q (p - Int.unsigned n))).
{
intros. apply vmatch_sgn'. red; intros. zify.
rewrite ! Int.bits_shr by omega.
transitivity (Int.testbit i (Int.zwordsize - 1)).
destruct (zlt (m + Int.unsigned n) Int.zwordsize).
apply H0; omega.
auto.
symmetry.
destruct (zlt (Int.zwordsize - 1 + Int.unsigned n) Int.zwordsize).
apply H0; omega.
auto.
}
inv H; eauto with va.
- destruct v; constructor.
Qed.
Definition and (v w: aval) :=
match v, w with
| I i1, I i2 => I (Int.and i1 i2)
| I i, Uns p n | Uns p n, I i => uns p (Z.min n (usize i))
| I i, x | x, I i => uns (provenance x) (usize i)
| Uns p1 n1, Uns p2 n2 => uns (plub p1 p2) (Z.min n1 n2)
| Uns p n, _ => uns (plub p (provenance w)) n
| _, Uns p n => uns (plub (provenance v) p) n
| Sgn p1 n1, Sgn p2 n2 => sgn (plub p1 p2) (Z.max n1 n2)
| _, _ => ntop2 v w
end.
Lemma and_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.and v w) (and x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.and_sound".
assert (UNS_l: forall i j n, is_uns n i -> is_uns n (Int.and i j)).
{
intros; red; intros. rewrite Int.bits_and by auto. rewrite (H m) by auto.
apply andb_false_l.
}
assert (UNS_r: forall i j n, is_uns n i -> is_uns n (Int.and j i)).
{
intros. rewrite Int.and_commut. eauto.
}
assert (UNS: forall i j n m, is_uns n i -> is_uns m j -> is_uns (Z.min n m) (Int.and i j)).
{
intros. apply Z.min_case; auto.
}
assert (SGN: forall i j n m, is_sgn n i -> is_sgn m j -> is_sgn (Z.max n m) (Int.and i j)).
{
intros; red; intros. rewrite ! Int.bits_and by auto with va.
rewrite H by auto with va. rewrite H0 by auto with va. auto.
}
intros. unfold and, Val.and; inv H; eauto with va; inv H0; eauto with va.
Qed.
Definition or (v w: aval) :=
match v, w with
| I i1, I i2 => I (Int.or i1 i2)
| I i, Uns p n | Uns p n, I i => uns p (Z.max n (usize i))
| Uns p1 n1, Uns p2 n2 => uns (plub p1 p2) (Z.max n1 n2)
| Sgn p1 n1, Sgn p2 n2 => sgn (plub p1 p2) (Z.max n1 n2)
| _, _ => ntop2 v w
end.
Lemma or_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.or v w) (or x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.or_sound".
assert (UNS: forall i j n m, is_uns n i -> is_uns m j -> is_uns (Z.max n m) (Int.or i j)).
{
intros; red; intros. rewrite Int.bits_or by auto.
rewrite H by xomega. rewrite H0 by xomega. auto.
}
assert (SGN: forall i j n m, is_sgn n i -> is_sgn m j -> is_sgn (Z.max n m) (Int.or i j)).
{
intros; red; intros. rewrite ! Int.bits_or by xomega.
rewrite H by xomega. rewrite H0 by xomega. auto.
}
intros. unfold or, Val.or; inv H; eauto with va; inv H0; eauto with va.
Qed.
Definition xor (v w: aval) :=
match v, w with
| I i1, I i2 => I (Int.xor i1 i2)
| I i, Uns p n | Uns p n, I i => uns p (Z.max n (usize i))
| Uns p1 n1, Uns p2 n2 => uns (plub p1 p2) (Z.max n1 n2)
| Sgn p1 n1, Sgn p2 n2 => sgn (plub p1 p2) (Z.max n1 n2)
| _, _ => ntop2 v w
end.
Lemma xor_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.xor v w) (xor x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.xor_sound".
assert (UNS: forall i j n m, is_uns n i -> is_uns m j -> is_uns (Z.max n m) (Int.xor i j)).
{
intros; red; intros. rewrite Int.bits_xor by auto.
rewrite H by xomega. rewrite H0 by xomega. auto.
}
assert (SGN: forall i j n m, is_sgn n i -> is_sgn m j -> is_sgn (Z.max n m) (Int.xor i j)).
{
intros; red; intros. rewrite ! Int.bits_xor by xomega.
rewrite H by xomega. rewrite H0 by xomega. auto.
}
intros. unfold xor, Val.xor; inv H; eauto with va; inv H0; eauto with va.
Qed.
Definition notint (v: aval) :=
match v with
| I i => I (Int.not i)
| Uns p n => sgn p (n + 1)
| Sgn p n => Sgn p n
| _ => ntop1 v
end.
Lemma notint_sound:
forall v x, vmatch v x -> vmatch (Val.notint v) (notint x).
Proof. hammer_hook "ValueDomain" "ValueDomain.notint_sound".
assert (SGN: forall n i, is_sgn n i -> is_sgn n (Int.not i)).
{
intros; red; intros. rewrite ! Int.bits_not by omega.
f_equal. apply H; auto.
}
intros. unfold Val.notint, notint; inv H; eauto with va.
Qed.
Definition rol (x y: aval) :=
match y, x with
| I j, I i => I(Int.rol i j)
| I j, Uns p n => uns p (n + Int.unsigned j)
| I j, Sgn p n => if zlt n Int.zwordsize then sgn p (n + Int.unsigned j) else ntop1 x
| _, _ => ntop1 x
end.
Lemma rol_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.rol v w) (rol x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.rol_sound".
intros.
assert (DEFAULT: forall p, vmatch (Val.rol v w) (Ifptr p)).
{
destruct v; destruct w; simpl; constructor.
}
unfold rol; destruct y; try apply DEFAULT; auto. inv H0. unfold Val.rol.
inv H; auto with va.
- apply vmatch_uns. red; intros. rewrite Int.bits_rol by auto.
generalize (Int.unsigned_range n); intros.
rewrite Z.mod_small by omega.
apply H1. omega. omega.
- destruct (zlt n0 Int.zwordsize); auto with va.
apply vmatch_sgn. red; intros. rewrite ! Int.bits_rol by omega.
generalize (Int.unsigned_range n); intros.
rewrite ! Z.mod_small by omega.
rewrite H1 by omega. symmetry. rewrite H1 by omega. auto.
- destruct (zlt n0 Int.zwordsize); auto with va.
Qed.
Definition ror (x y: aval) :=
match y, x with
| I j, I i => I(Int.ror i j)
| _, _ => ntop1 x
end.
Lemma ror_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.ror v w) (ror x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.ror_sound".
intros.
assert (DEFAULT: forall p, vmatch (Val.ror v w) (Ifptr p)).
{
destruct v; destruct w; simpl; constructor.
}
unfold ror; destruct y; try apply DEFAULT; auto. inv H0. unfold Val.ror.
inv H; auto with va.
Qed.
Definition rolm (x: aval) (amount mask: int) :=
and (rol x (I amount)) (I mask).
Lemma rolm_sound:
forall v x amount mask,
vmatch v x -> vmatch (Val.rolm v amount mask) (rolm x amount mask).
Proof. hammer_hook "ValueDomain" "ValueDomain.rolm_sound".
intros.
replace (Val.rolm v amount mask) with (Val.and (Val.rol v (Vint amount)) (Vint mask)).
apply and_sound. apply rol_sound. auto. constructor. constructor.
destruct v; auto.
Qed.
Definition neg := unop_int Int.neg.
Lemma neg_sound:
forall v x, vmatch v x -> vmatch (Val.neg v) (neg x).
Proof. hammer_hook "ValueDomain" "ValueDomain.neg_sound". exact ((unop_int_sound Int.neg)). Qed.
Definition add (x y: aval) :=
match x, y with
| I i, I j => I (Int.add i j)
| Ptr p, I i | I i, Ptr p => Ptr (if Archi.ptr64 then poffset p else padd p (Ptrofs.of_int i))
| Ptr p, _ | _, Ptr p => Ptr (poffset p)
| Ifptr p, I i | I i, Ifptr p => Ifptr (if Archi.ptr64 then poffset p else padd p (Ptrofs.of_int i))
| Ifptr p, Ifptr q => Ifptr (plub (poffset p) (poffset q))
| Ifptr p, _ | _, Ifptr p => Ifptr (poffset p)
| _, _ => ntop2 x y
end.
Lemma add_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.add v w) (add x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.add_sound".
intros. unfold Val.add, add. destruct Archi.ptr64.
- inv H; inv H0; constructor.
- inv H; inv H0; constructor;
((apply padd_sound; assumption) || (eapply poffset_sound; eassumption) || idtac).
apply pmatch_lub_r. eapply poffset_sound; eauto.
apply pmatch_lub_l. eapply poffset_sound; eauto.
Qed.
Definition sub (v w: aval) :=
match v, w with
| I i1, I i2 => I (Int.sub i1 i2)
| Ptr p, I i => if Archi.ptr64 then Ifptr (poffset p) else Ptr (psub p (Ptrofs.of_int i))
| Ptr p, _ => Ifptr (poffset p)
| Ifptr p, I i => if Archi.ptr64 then Ifptr (plub (poffset p) (provenance w)) else Ifptr (psub p (Ptrofs.of_int i))
| Ifptr p, _ => Ifptr (plub (poffset p) (provenance w))
| _, _ => ntop2 v w
end.
Lemma sub_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.sub v w) (sub x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.sub_sound".
intros. unfold Val.sub, sub. destruct Archi.ptr64.
- inv H; inv H0; eauto with va.
- inv H; inv H0; try (destruct (eq_block b b0)); eauto using psub_sound, poffset_sound, pmatch_lub_l with va.
Qed.
Definition mul := binop_int Int.mul.
Lemma mul_sound:
forall v x w y, vmatch v x -> vmatch w y -> vmatch (Val.mul v w) (mul x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.mul_sound". exact ((binop_int_sound Int.mul)). Qed.
Definition mulhs := binop_int Int.mulhs.
Lemma mulhs_sound:
forall v x w y, vmatch v x -> vmatch w y -> vmatch (Val.mulhs v w) (mulhs x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.mulhs_sound". exact ((binop_int_sound Int.mulhs)). Qed.
Definition mulhu := binop_int Int.mulhu.
Lemma mulhu_sound:
forall v x w y, vmatch v x -> vmatch w y -> vmatch (Val.mulhu v w) (mulhu x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.mulhu_sound". exact ((binop_int_sound Int.mulhu)). Qed.
Definition divs (v w: aval) :=
match w, v with
| I i2, I i1 =>
if Int.eq i2 Int.zero
|| Int.eq i1 (Int.repr Int.min_signed) && Int.eq i2 Int.mone
then if va_strict tt then Vbot else ntop
else I (Int.divs i1 i2)
| _, _ => ntop2 v w
end.
Lemma divs_sound:
forall v w u x y, vmatch v x -> vmatch w y -> Val.divs v w = Some u -> vmatch u (divs x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.divs_sound".
intros. destruct v; destruct w; try discriminate; simpl in H1.
destruct (Int.eq i0 Int.zero
|| Int.eq i (Int.repr Int.min_signed) && Int.eq i0 Int.mone) eqn:E; inv H1.
inv H; inv H0; auto with va. simpl. rewrite E. constructor.
Qed.
Definition divu (v w: aval) :=
match w, v with
| I i2, I i1 =>
if Int.eq i2 Int.zero
then if va_strict tt then Vbot else ntop
else I (Int.divu i1 i2)
| _, _ => ntop2 v w
end.
Lemma divu_sound:
forall v w u x y, vmatch v x -> vmatch w y -> Val.divu v w = Some u -> vmatch u (divu x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.divu_sound".
intros. destruct v; destruct w; try discriminate; simpl in H1.
destruct (Int.eq i0 Int.zero) eqn:E; inv H1.
inv H; inv H0; auto with va. simpl. rewrite E. constructor.
Qed.
Definition mods (v w: aval) :=
match w, v with
| I i2, I i1 =>
if Int.eq i2 Int.zero
|| Int.eq i1 (Int.repr Int.min_signed) && Int.eq i2 Int.mone
then if va_strict tt then Vbot else ntop
else I (Int.mods i1 i2)
| _, _ => ntop2 v w
end.
Lemma mods_sound:
forall v w u x y, vmatch v x -> vmatch w y -> Val.mods v w = Some u -> vmatch u (mods x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.mods_sound".
intros. destruct v; destruct w; try discriminate; simpl in H1.
destruct (Int.eq i0 Int.zero
|| Int.eq i (Int.repr Int.min_signed) && Int.eq i0 Int.mone) eqn:E; inv H1.
inv H; inv H0; auto with va. simpl. rewrite E. constructor.
Qed.
Definition modu (v w: aval) :=
match w, v with
| I i2, I i1 =>
if Int.eq i2 Int.zero
then if va_strict tt then Vbot else ntop
else I (Int.modu i1 i2)
| I i2, _ => uns (provenance v) (usize i2)
| _, _ => ntop2 v w
end.
Lemma modu_sound:
forall v w u x y, vmatch v x -> vmatch w y -> Val.modu v w = Some u -> vmatch u (modu x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.modu_sound".
assert (UNS: forall i j, j <> Int.zero -> is_uns (usize j) (Int.modu i j)).
{
intros. apply is_uns_mon with (usize (Int.modu i j)); auto with va.
unfold usize, Int.size. apply Zsize_monotone.
generalize (Int.unsigned_range_2 j); intros RANGE.
assert (Int.unsigned j <> 0).
{ red; intros; elim H. rewrite <- (Int.repr_unsigned j). rewrite H0. auto. }
exploit (Z_mod_lt (Int.unsigned i) (Int.unsigned j)). omega. intros MOD.
unfold Int.modu. rewrite Int.unsigned_repr. omega. omega.
}
intros. destruct v; destruct w; try discriminate; simpl in H1.
destruct (Int.eq i0 Int.zero) eqn:Z; inv H1.
assert (i0 <> Int.zero) by (generalize (Int.eq_spec i0 Int.zero); rewrite Z; auto).
unfold modu. inv H; inv H0; auto with va. rewrite Z. constructor.
Qed.
Definition shrx (v w: aval) :=
match v, w with
| I i, I j => if Int.ltu j (Int.repr 31) then I(Int.shrx i j) else ntop
| _, _ => ntop1 v
end.
Lemma shrx_sound:
forall v w u x y, vmatch v x -> vmatch w y -> Val.shrx v w = Some u -> vmatch u (shrx x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.shrx_sound".
intros.
destruct v; destruct w; try discriminate; simpl in H1.
destruct (Int.ltu i0 (Int.repr 31)) eqn:LTU; inv H1.
unfold shrx; inv H; auto with va; inv H0; auto with va.
rewrite LTU; auto with va.
Qed.
Definition shift_long (sem: int64 -> int -> int64) (v w: aval) :=
match w with
| I amount =>
if Int.ltu amount Int64.iwordsize' then
match v with
| L i => L (sem i amount)
| _ => ntop1 v
end
else ntop1 v
| _ => ntop1 v
end.
Lemma shift_long_sound:
forall sem v w x y,
vmatch v x -> vmatch w y ->
vmatch (match v, w with
| Vlong i, Vint j => if Int.ltu j Int64.iwordsize'
then Vlong (sem i j) else Vundef
| _, _ => Vundef end)
(shift_long sem x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.shift_long_sound".
intros.
assert (DEFAULT:
vmatch (match v, w with
| Vlong i, Vint j => if Int.ltu j Int64.iwordsize'
then Vlong (sem i j) else Vundef
| _, _ => Vundef end)
(ntop1 x)).
{ destruct v; try constructor; destruct w; try constructor.
destruct (Int.ltu i0 Int64.iwordsize'); constructor. }
unfold shift_long. destruct y; auto.
destruct (Int.ltu n Int64.iwordsize') eqn:LT; auto.
destruct x; auto.
inv H; inv H0. rewrite LT. constructor.
Qed.
Definition shll := shift_long Int64.shl'.
Lemma shll_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.shll v w) (shll x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.shll_sound". exact ((shift_long_sound Int64.shl')). Qed.
Definition shrl := shift_long Int64.shr'.
Lemma shrl_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.shrl v w) (shrl x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.shrl_sound". exact ((shift_long_sound Int64.shr')). Qed.
Definition shrlu := shift_long Int64.shru'.
Lemma shrlu_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.shrlu v w) (shrlu x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.shrlu_sound". exact ((shift_long_sound Int64.shru')). Qed.
Definition andl := binop_long Int64.and.
Lemma andl_sound:
forall v x w y, vmatch v x -> vmatch w y -> vmatch (Val.andl v w) (andl x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.andl_sound". exact ((binop_long_sound Int64.and)). Qed.
Definition orl := binop_long Int64.or.
Lemma orl_sound:
forall v x w y, vmatch v x -> vmatch w y -> vmatch (Val.orl v w) (orl x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.orl_sound". exact ((binop_long_sound Int64.or)). Qed.
Definition xorl := binop_long Int64.xor.
Lemma xorl_sound:
forall v x w y, vmatch v x -> vmatch w y -> vmatch (Val.xorl v w) (xorl x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.xorl_sound". exact ((binop_long_sound Int64.xor)). Qed.
Definition notl := unop_long Int64.not.
Lemma notl_sound:
forall v x, vmatch v x -> vmatch (Val.notl v) (notl x).
Proof. hammer_hook "ValueDomain" "ValueDomain.notl_sound". exact ((unop_long_sound Int64.not)). Qed.
Definition rotate_long (sem: int64 -> int64 -> int64) (v w: aval) :=
match v, w with
| L i, I amount => L (sem i (Int64.repr (Int.unsigned amount)))
| _, _ => ntop1 v
end.
Lemma rotate_long_sound:
forall sem v w x y,
vmatch v x -> vmatch w y ->
vmatch (match v, w with
| Vlong i, Vint j => Vlong (sem i (Int64.repr (Int.unsigned j)))
| _, _ => Vundef end)
(rotate_long sem x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.rotate_long_sound".
intros.
assert (DEFAULT:
vmatch (match v, w with
| Vlong i, Vint j => Vlong (sem i (Int64.repr (Int.unsigned j)))
| _, _ => Vundef end)
(ntop1 x)).
{ destruct v; try constructor. destruct w; constructor. }
unfold rotate_long. destruct x; auto. destruct y; auto. inv H; inv H0. constructor.
Qed.
Definition roll := rotate_long Int64.rol.
Lemma roll_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.roll v w) (roll x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.roll_sound". exact ((rotate_long_sound Int64.rol)). Qed.
Definition rorl := rotate_long Int64.ror.
Lemma rorl_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.rorl v w) (rorl x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.rorl_sound". exact ((rotate_long_sound Int64.ror)). Qed.
Definition negl := unop_long Int64.neg.
Lemma negl_sound:
forall v x, vmatch v x -> vmatch (Val.negl v) (negl x).
Proof. hammer_hook "ValueDomain" "ValueDomain.negl_sound". exact ((unop_long_sound Int64.neg)). Qed.
Definition addl (x y: aval) :=
match x, y with
| L i, L j => L (Int64.add i j)
| Ptr p, L i | L i, Ptr p => Ptr (if Archi.ptr64 then padd p (Ptrofs.of_int64 i) else poffset p)
| Ptr p, _ | _, Ptr p => Ptr (poffset p)
| Ifptr p, L i | L i, Ifptr p => Ifptr (if Archi.ptr64 then padd p (Ptrofs.of_int64 i) else poffset p)
| Ifptr p, Ifptr q => Ifptr (plub (poffset p) (poffset q))
| Ifptr p, _ | _, Ifptr p => Ifptr (poffset p)
| _, _ => ntop2 x y
end.
Lemma addl_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.addl v w) (addl x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.addl_sound".
intros. unfold Val.addl, addl. destruct Archi.ptr64.
- inv H; inv H0; constructor;
((apply padd_sound; assumption) || (eapply poffset_sound; eassumption) || idtac).
apply pmatch_lub_r. eapply poffset_sound; eauto.
apply pmatch_lub_l. eapply poffset_sound; eauto.
- inv H; inv H0; constructor.
Qed.
Definition subl (v w: aval) :=
match v, w with
| L i1, L i2 => L (Int64.sub i1 i2)
| Ptr p, L i => if Archi.ptr64 then Ptr (psub p (Ptrofs.of_int64 i)) else Ifptr (poffset p)
| Ptr p, _ => Ifptr (poffset p)
| Ifptr p, L i => if Archi.ptr64 then Ifptr (psub p (Ptrofs.of_int64 i)) else Ifptr (plub (poffset p) (provenance w))
| Ifptr p, _ => Ifptr (plub (poffset p) (provenance w))
| _, _ => ntop2 v w
end.
Lemma subl_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.subl v w) (subl x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.subl_sound".
intros. unfold Val.subl, subl. destruct Archi.ptr64.
- inv H; inv H0; try (destruct (eq_block b b0)); eauto using psub_sound, poffset_sound, pmatch_lub_l with va.
- inv H; inv H0; eauto with va.
Qed.
Definition mull := binop_long Int64.mul.
Lemma mull_sound:
forall v x w y, vmatch v x -> vmatch w y -> vmatch (Val.mull v w) (mull x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.mull_sound". exact ((binop_long_sound Int64.mul)). Qed.
Definition mullhs := binop_long Int64.mulhs.
Lemma mullhs_sound:
forall v x w y, vmatch v x -> vmatch w y -> vmatch (Val.mullhs v w) (mullhs x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.mullhs_sound". exact ((binop_long_sound Int64.mulhs)). Qed.
Definition mullhu := binop_long Int64.mulhu.
Lemma mullhu_sound:
forall v x w y, vmatch v x -> vmatch w y -> vmatch (Val.mullhu v w) (mullhu x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.mullhu_sound". exact ((binop_long_sound Int64.mulhu)). Qed.
Definition divls (v w: aval) :=
match w, v with
| L i2, L i1 =>
if Int64.eq i2 Int64.zero
|| Int64.eq i1 (Int64.repr Int64.min_signed) && Int64.eq i2 Int64.mone
then if va_strict tt then Vbot else ntop
else L (Int64.divs i1 i2)
| _, _ => ntop2 v w
end.
Lemma divls_sound:
forall v w u x y, vmatch v x -> vmatch w y -> Val.divls v w = Some u -> vmatch u (divls x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.divls_sound".
intros. destruct v; destruct w; try discriminate; simpl in H1.
destruct (Int64.eq i0 Int64.zero
|| Int64.eq i (Int64.repr Int64.min_signed) && Int64.eq i0 Int64.mone) eqn:E; inv H1.
inv H; inv H0; auto with va. simpl. rewrite E. constructor.
Qed.
Definition divlu (v w: aval) :=
match w, v with
| L i2, L i1 =>
if Int64.eq i2 Int64.zero
then if va_strict tt then Vbot else ntop
else L (Int64.divu i1 i2)
| _, _ => ntop2 v w
end.
Lemma divlu_sound:
forall v w u x y, vmatch v x -> vmatch w y -> Val.divlu v w = Some u -> vmatch u (divlu x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.divlu_sound".
intros. destruct v; destruct w; try discriminate; simpl in H1.
destruct (Int64.eq i0 Int64.zero) eqn:E; inv H1.
inv H; inv H0; auto with va. simpl. rewrite E. constructor.
Qed.
Definition modls (v w: aval) :=
match w, v with
| L i2, L i1 =>
if Int64.eq i2 Int64.zero
|| Int64.eq i1 (Int64.repr Int64.min_signed) && Int64.eq i2 Int64.mone
then if va_strict tt then Vbot else ntop
else L (Int64.mods i1 i2)
| _, _ => ntop2 v w
end.
Lemma modls_sound:
forall v w u x y, vmatch v x -> vmatch w y -> Val.modls v w = Some u -> vmatch u (modls x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.modls_sound".
intros. destruct v; destruct w; try discriminate; simpl in H1.
destruct (Int64.eq i0 Int64.zero
|| Int64.eq i (Int64.repr Int64.min_signed) && Int64.eq i0 Int64.mone) eqn:E; inv H1.
inv H; inv H0; auto with va. simpl. rewrite E. constructor.
Qed.
Definition modlu (v w: aval) :=
match w, v with
| L i2, L i1 =>
if Int64.eq i2 Int64.zero
then if va_strict tt then Vbot else ntop
else L (Int64.modu i1 i2)
| _, _ => ntop2 v w
end.
Lemma modlu_sound:
forall v w u x y, vmatch v x -> vmatch w y -> Val.modlu v w = Some u -> vmatch u (modlu x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.modlu_sound".
intros. destruct v; destruct w; try discriminate; simpl in H1.
destruct (Int64.eq i0 Int64.zero) eqn:E; inv H1.
inv H; inv H0; auto with va. simpl. rewrite E. constructor.
Qed.
Definition shrxl (v w: aval) :=
match v, w with
| L i, I j => if Int.ltu j (Int.repr 63) then L(Int64.shrx' i j) else ntop
| _, _ => ntop1 v
end.
Lemma shrxl_sound:
forall v w u x y, vmatch v x -> vmatch w y -> Val.shrxl v w = Some u -> vmatch u (shrxl x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.shrxl_sound".
intros.
destruct v; destruct w; try discriminate; simpl in H1.
destruct (Int.ltu i0 (Int.repr 63)) eqn:LTU; inv H1.
unfold shrxl; inv H; auto with va; inv H0; auto with va.
rewrite LTU; auto with va.
Qed.
Definition rolml (x: aval) (amount: int) (mask: int64) :=
andl (roll x (I amount)) (L mask).
Lemma rolml_sound:
forall v x amount mask,
vmatch v x -> vmatch (Val.rolml v amount mask) (rolml x amount mask).
Proof. hammer_hook "ValueDomain" "ValueDomain.rolml_sound".
intros.
replace (Val.rolml v amount mask) with (Val.andl (Val.roll v (Vint amount)) (Vlong mask)).
apply andl_sound. apply roll_sound. auto. constructor. constructor.
destruct v; auto.
Qed.
Definition offset_ptr (v: aval) (n: ptrofs) :=
match v with
| Ptr p => Ptr (padd p n)
| Ifptr p => Ifptr (padd p n)
| _ => ntop1 v
end.
Lemma offset_ptr_sound:
forall v x n, vmatch v x -> vmatch (Val.offset_ptr v n) (offset_ptr x n).
Proof. hammer_hook "ValueDomain" "ValueDomain.offset_ptr_sound".
intros. unfold Val.offset_ptr, offset_ptr.
inv H; constructor; apply padd_sound; assumption.
Qed.
Definition negf := unop_float Float.neg.
Lemma negf_sound:
forall v x, vmatch v x -> vmatch (Val.negf v) (negf x).
Proof. hammer_hook "ValueDomain" "ValueDomain.negf_sound". exact ((unop_float_sound Float.neg)). Qed.
Definition absf := unop_float Float.abs.
Lemma absf_sound:
forall v x, vmatch v x -> vmatch (Val.absf v) (absf x).
Proof. hammer_hook "ValueDomain" "ValueDomain.absf_sound". exact ((unop_float_sound Float.abs)). Qed.
Definition addf := binop_float Float.add.
Lemma addf_sound:
forall v x w y, vmatch v x -> vmatch w y -> vmatch (Val.addf v w) (addf x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.addf_sound". exact ((binop_float_sound Float.add)). Qed.
Definition subf := binop_float Float.sub.
Lemma subf_sound:
forall v x w y, vmatch v x -> vmatch w y -> vmatch (Val.subf v w) (subf x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.subf_sound". exact ((binop_float_sound Float.sub)). Qed.
Definition mulf := binop_float Float.mul.
Lemma mulf_sound:
forall v x w y, vmatch v x -> vmatch w y -> vmatch (Val.mulf v w) (mulf x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.mulf_sound". exact ((binop_float_sound Float.mul)). Qed.
Definition divf := binop_float Float.div.
Lemma divf_sound:
forall v x w y, vmatch v x -> vmatch w y -> vmatch (Val.divf v w) (divf x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.divf_sound". exact ((binop_float_sound Float.div)). Qed.
Definition negfs := unop_single Float32.neg.
Lemma negfs_sound:
forall v x, vmatch v x -> vmatch (Val.negfs v) (negfs x).
Proof. hammer_hook "ValueDomain" "ValueDomain.negfs_sound". exact ((unop_single_sound Float32.neg)). Qed.
Definition absfs := unop_single Float32.abs.
Lemma absfs_sound:
forall v x, vmatch v x -> vmatch (Val.absfs v) (absfs x).
Proof. hammer_hook "ValueDomain" "ValueDomain.absfs_sound". exact ((unop_single_sound Float32.abs)). Qed.
Definition addfs := binop_single Float32.add.
Lemma addfs_sound:
forall v x w y, vmatch v x -> vmatch w y -> vmatch (Val.addfs v w) (addfs x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.addfs_sound". exact ((binop_single_sound Float32.add)). Qed.
Definition subfs := binop_single Float32.sub.
Lemma subfs_sound:
forall v x w y, vmatch v x -> vmatch w y -> vmatch (Val.subfs v w) (subfs x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.subfs_sound". exact ((binop_single_sound Float32.sub)). Qed.
Definition mulfs := binop_single Float32.mul.
Lemma mulfs_sound:
forall v x w y, vmatch v x -> vmatch w y -> vmatch (Val.mulfs v w) (mulfs x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.mulfs_sound". exact ((binop_single_sound Float32.mul)). Qed.
Definition divfs := binop_single Float32.div.
Lemma divfs_sound:
forall v x w y, vmatch v x -> vmatch w y -> vmatch (Val.divfs v w) (divfs x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.divfs_sound". exact ((binop_single_sound Float32.div)). Qed.
Definition zero_ext (nbits: Z) (v: aval) :=
match v with
| I i => I (Int.zero_ext nbits i)
| Uns p n => uns p (Z.min n nbits)
| _ => uns (provenance v) nbits
end.
Lemma zero_ext_sound:
forall nbits v x, vmatch v x -> vmatch (Val.zero_ext nbits v) (zero_ext nbits x).
Proof. hammer_hook "ValueDomain" "ValueDomain.zero_ext_sound".
assert (DFL: forall nbits i, is_uns nbits (Int.zero_ext nbits i)).
{
intros; red; intros. rewrite Int.bits_zero_ext by omega. apply zlt_false; auto.
}
intros. inv H; simpl; auto with va. apply vmatch_uns.
red; intros. zify.
rewrite Int.bits_zero_ext by omega.
destruct (zlt m nbits); auto. apply H1; omega.
Qed.
Definition sign_ext (nbits: Z) (v: aval) :=
if zle nbits 0 then Uns (provenance v) 0 else
match v with
| I i => I (Int.sign_ext nbits i)
| Uns p n => if zlt n nbits then Uns p n else sgn p nbits
| Sgn p n => sgn p (Z.min n nbits)
| _ => sgn (provenance v) nbits
end.
Lemma sign_ext_sound:
forall nbits v x, vmatch v x -> vmatch (Val.sign_ext nbits v) (sign_ext nbits x).
Proof. hammer_hook "ValueDomain" "ValueDomain.sign_ext_sound".
assert (DFL: forall p nbits i, 0 < nbits -> vmatch (Vint (Int.sign_ext nbits i)) (sgn p nbits)).
{
intros. apply vmatch_sgn. apply is_sign_ext_sgn; auto with va.
}
intros. unfold sign_ext. destruct (zle nbits 0).
- destruct v; simpl; auto with va. constructor. omega.
rewrite Int.sign_ext_below by auto. red; intros; apply Int.bits_zero.
- inv H; simpl; auto with va.
+ destruct (zlt n nbits); eauto with va.
constructor; auto. eapply is_sign_ext_uns; eauto with va.
+ destruct (zlt n nbits); auto with va.
+ apply vmatch_sgn. apply is_sign_ext_sgn; auto with va.
apply Z.min_case; auto with va.
Qed.
Definition zero_ext_l (s: Z) := unop_long (Int64.zero_ext s).
Lemma zero_ext_l_sound:
forall s v x, vmatch v x -> vmatch (Val.zero_ext_l s v) (zero_ext_l s x).
Proof. hammer_hook "ValueDomain" "ValueDomain.zero_ext_l_sound".
intros s. exact (unop_long_sound (Int64.zero_ext s)).
Qed.
Definition sign_ext_l (s: Z) := unop_long (Int64.sign_ext s).
Lemma sign_ext_l_sound:
forall s v x, vmatch v x -> vmatch (Val.sign_ext_l s v) (sign_ext_l s x).
Proof. hammer_hook "ValueDomain" "ValueDomain.sign_ext_l_sound".
intros s. exact (unop_long_sound (Int64.sign_ext s)).
Qed.
Definition longofint (v: aval) :=
match v with
| I i => L (Int64.repr (Int.signed i))
| _ => ntop1 v
end.
Lemma longofint_sound:
forall v x, vmatch v x -> vmatch (Val.longofint v) (longofint x).
Proof. hammer_hook "ValueDomain" "ValueDomain.longofint_sound".
unfold Val.longofint, longofint; intros; inv H; auto with va.
Qed.
Definition longofintu (v: aval) :=
match v with
| I i => L (Int64.repr (Int.unsigned i))
| _ => ntop1 v
end.
Lemma longofintu_sound:
forall v x, vmatch v x -> vmatch (Val.longofintu v) (longofintu x).
Proof. hammer_hook "ValueDomain" "ValueDomain.longofintu_sound".
unfold Val.longofintu, longofintu; intros; inv H; auto with va.
Qed.
Definition singleoffloat (v: aval) :=
match v with
| F f => FS (Float.to_single f)
| _ => ntop1 v
end.
Lemma singleoffloat_sound:
forall v x, vmatch v x -> vmatch (Val.singleoffloat v) (singleoffloat x).
Proof. hammer_hook "ValueDomain" "ValueDomain.singleoffloat_sound".
intros.
assert (DEFAULT: vmatch (Val.singleoffloat v) (ntop1 x)).
{ destruct v; constructor. }
destruct x; auto. inv H. constructor.
Qed.
Definition floatofsingle (v: aval) :=
match v with
| FS f => F (Float.of_single f)
| _ => ntop1 v
end.
Lemma floatofsingle_sound:
forall v x, vmatch v x -> vmatch (Val.floatofsingle v) (floatofsingle x).
Proof. hammer_hook "ValueDomain" "ValueDomain.floatofsingle_sound".
intros.
assert (DEFAULT: vmatch (Val.floatofsingle v) (ntop1 x)).
{ destruct v; constructor. }
destruct x; auto. inv H. constructor.
Qed.
Definition intoffloat (x: aval) :=
match x with
| F f =>
match Float.to_int f with
| Some i => I i
| None => if va_strict tt then Vbot else ntop
end
| _ => ntop1 x
end.
Lemma intoffloat_sound:
forall v x w, vmatch v x -> Val.intoffloat v = Some w -> vmatch w (intoffloat x).
Proof. hammer_hook "ValueDomain" "ValueDomain.intoffloat_sound".
unfold Val.intoffloat; intros. destruct v; try discriminate.
destruct (Float.to_int f) as [i|] eqn:E; simpl in H0; inv H0.
inv H; simpl; auto with va. rewrite E; constructor.
Qed.
Definition intuoffloat (x: aval) :=
match x with
| F f =>
match Float.to_intu f with
| Some i => I i
| None => if va_strict tt then Vbot else ntop
end
| _ => ntop1 x
end.
Lemma intuoffloat_sound:
forall v x w, vmatch v x -> Val.intuoffloat v = Some w -> vmatch w (intuoffloat x).
Proof. hammer_hook "ValueDomain" "ValueDomain.intuoffloat_sound".
unfold Val.intuoffloat; intros. destruct v; try discriminate.
destruct (Float.to_intu f) as [i|] eqn:E; simpl in H0; inv H0.
inv H; simpl; auto with va. rewrite E; constructor.
Qed.
Definition floatofint (x: aval) :=
match x with
| I i => F(Float.of_int i)
| _ => ntop1 x
end.
Lemma floatofint_sound:
forall v x w, vmatch v x -> Val.floatofint v = Some w -> vmatch w (floatofint x).
Proof. hammer_hook "ValueDomain" "ValueDomain.floatofint_sound".
unfold Val.floatofint; intros. destruct v; inv H0.
inv H; simpl; auto with va.
Qed.
Definition floatofintu (x: aval) :=
match x with
| I i => F(Float.of_intu i)
| _ => ntop1 x
end.
Lemma floatofintu_sound:
forall v x w, vmatch v x -> Val.floatofintu v = Some w -> vmatch w (floatofintu x).
Proof. hammer_hook "ValueDomain" "ValueDomain.floatofintu_sound".
unfold Val.floatofintu; intros. destruct v; inv H0.
inv H; simpl; auto with va.
Qed.
Definition intofsingle (x: aval) :=
match x with
| FS f =>
match Float32.to_int f with
| Some i => I i
| None => if va_strict tt then Vbot else ntop
end
| _ => ntop1 x
end.
Lemma intofsingle_sound:
forall v x w, vmatch v x -> Val.intofsingle v = Some w -> vmatch w (intofsingle x).
Proof. hammer_hook "ValueDomain" "ValueDomain.intofsingle_sound".
unfold Val.intofsingle; intros. destruct v; try discriminate.
destruct (Float32.to_int f) as [i|] eqn:E; simpl in H0; inv H0.
inv H; simpl; auto with va. rewrite E; constructor.
Qed.
Definition intuofsingle (x: aval) :=
match x with
| FS f =>
match Float32.to_intu f with
| Some i => I i
| None => if va_strict tt then Vbot else ntop
end
| _ => ntop1 x
end.
Lemma intuofsingle_sound:
forall v x w, vmatch v x -> Val.intuofsingle v = Some w -> vmatch w (intuofsingle x).
Proof. hammer_hook "ValueDomain" "ValueDomain.intuofsingle_sound".
unfold Val.intuofsingle; intros. destruct v; try discriminate.
destruct (Float32.to_intu f) as [i|] eqn:E; simpl in H0; inv H0.
inv H; simpl; auto with va. rewrite E; constructor.
Qed.
Definition singleofint (x: aval) :=
match x with
| I i => FS(Float32.of_int i)
| _ => ntop1 x
end.
Lemma singleofint_sound:
forall v x w, vmatch v x -> Val.singleofint v = Some w -> vmatch w (singleofint x).
Proof. hammer_hook "ValueDomain" "ValueDomain.singleofint_sound".
unfold Val.singleofint; intros. destruct v; inv H0.
inv H; simpl; auto with va.
Qed.
Definition singleofintu (x: aval) :=
match x with
| I i => FS(Float32.of_intu i)
| _ => ntop1 x
end.
Lemma singleofintu_sound:
forall v x w, vmatch v x -> Val.singleofintu v = Some w -> vmatch w (singleofintu x).
Proof. hammer_hook "ValueDomain" "ValueDomain.singleofintu_sound".
unfold Val.singleofintu; intros. destruct v; inv H0.
inv H; simpl; auto with va.
Qed.
Definition longoffloat (x: aval) :=
match x with
| F f =>
match Float.to_long f with
| Some i => L i
| None => if va_strict tt then Vbot else ntop
end
| _ => ntop1 x
end.
Lemma longoffloat_sound:
forall v x w, vmatch v x -> Val.longoffloat v = Some w -> vmatch w (longoffloat x).
Proof. hammer_hook "ValueDomain" "ValueDomain.longoffloat_sound".
unfold Val.longoffloat; intros. destruct v; try discriminate.
destruct (Float.to_long f) as [i|] eqn:E; simpl in H0; inv H0.
inv H; simpl; auto with va. rewrite E; constructor.
Qed.
Definition longuoffloat (x: aval) :=
match x with
| F f =>
match Float.to_longu f with
| Some i => L i
| None => if va_strict tt then Vbot else ntop
end
| _ => ntop1 x
end.
Lemma longuoffloat_sound:
forall v x w, vmatch v x -> Val.longuoffloat v = Some w -> vmatch w (longuoffloat x).
Proof. hammer_hook "ValueDomain" "ValueDomain.longuoffloat_sound".
unfold Val.longuoffloat; intros. destruct v; try discriminate.
destruct (Float.to_longu f) as [i|] eqn:E; simpl in H0; inv H0.
inv H; simpl; auto with va. rewrite E; constructor.
Qed.
Definition floatoflong (x: aval) :=
match x with
| L i => F(Float.of_long i)
| _ => ntop1 x
end.
Lemma floatoflong_sound:
forall v x w, vmatch v x -> Val.floatoflong v = Some w -> vmatch w (floatoflong x).
Proof. hammer_hook "ValueDomain" "ValueDomain.floatoflong_sound".
unfold Val.floatoflong; intros. destruct v; inv H0.
inv H; simpl; auto with va.
Qed.
Definition floatoflongu (x: aval) :=
match x with
| L i => F(Float.of_longu i)
| _ => ntop1 x
end.
Lemma floatoflongu_sound:
forall v x w, vmatch v x -> Val.floatoflongu v = Some w -> vmatch w (floatoflongu x).
Proof. hammer_hook "ValueDomain" "ValueDomain.floatoflongu_sound".
unfold Val.floatoflongu; intros. destruct v; inv H0.
inv H; simpl; auto with va.
Qed.
Definition longofsingle (x: aval) :=
match x with
| FS f =>
match Float32.to_long f with
| Some i => L i
| None => if va_strict tt then Vbot else ntop
end
| _ => ntop1 x
end.
Lemma longofsingle_sound:
forall v x w, vmatch v x -> Val.longofsingle v = Some w -> vmatch w (longofsingle x).
Proof. hammer_hook "ValueDomain" "ValueDomain.longofsingle_sound".
unfold Val.longofsingle; intros. destruct v; try discriminate.
destruct (Float32.to_long f) as [i|] eqn:E; simpl in H0; inv H0.
inv H; simpl; auto with va. rewrite E; constructor.
Qed.
Definition longuofsingle (x: aval) :=
match x with
| FS f =>
match Float32.to_longu f with
| Some i => L i
| None => if va_strict tt then Vbot else ntop
end
| _ => ntop1 x
end.
Lemma longuofsingle_sound:
forall v x w, vmatch v x -> Val.longuofsingle v = Some w -> vmatch w (longuofsingle x).
Proof. hammer_hook "ValueDomain" "ValueDomain.longuofsingle_sound".
unfold Val.longuofsingle; intros. destruct v; try discriminate.
destruct (Float32.to_longu f) as [i|] eqn:E; simpl in H0; inv H0.
inv H; simpl; auto with va. rewrite E; constructor.
Qed.
Definition singleoflong (x: aval) :=
match x with
| L i => FS(Float32.of_long i)
| _ => ntop1 x
end.
Lemma singleoflong_sound:
forall v x w, vmatch v x -> Val.singleoflong v = Some w -> vmatch w (singleoflong x).
Proof. hammer_hook "ValueDomain" "ValueDomain.singleoflong_sound".
unfold Val.singleoflong; intros. destruct v; inv H0.
inv H; simpl; auto with va.
Qed.
Definition singleoflongu (x: aval) :=
match x with
| L i => FS(Float32.of_longu i)
| _ => ntop1 x
end.
Lemma singleoflongu_sound:
forall v x w, vmatch v x -> Val.singleoflongu v = Some w -> vmatch w (singleoflongu x).
Proof. hammer_hook "ValueDomain" "ValueDomain.singleoflongu_sound".
unfold Val.singleoflongu; intros. destruct v; inv H0.
inv H; simpl; auto with va.
Qed.
Definition floatofwords (x y: aval) :=
match x, y with
| I i, I j => F(Float.from_words i j)
| _, _ => ntop2 x y
end.
Lemma floatofwords_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.floatofwords v w) (floatofwords x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.floatofwords_sound".
intros. unfold floatofwords; inv H; simpl; auto with va; inv H0; auto with va.
Qed.
Definition longofwords (x y: aval) :=
match y, x with
| I j, I i => L(Int64.ofwords i j)
| _, _ => ntop2 x y
end.
Lemma longofwords_sound:
forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.longofwords v w) (longofwords x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.longofwords_sound".
intros. unfold longofwords; inv H0; inv H; simpl; auto with va.
Qed.
Definition loword (x: aval) :=
match x with
| L i => I(Int64.loword i)
| _ => ntop1 x
end.
Lemma loword_sound: forall v x, vmatch v x -> vmatch (Val.loword v) (loword x).
Proof. hammer_hook "ValueDomain" "ValueDomain.loword_sound".
destruct 1; simpl; auto with va.
Qed.
Definition hiword (x: aval) :=
match x with
| L i => I(Int64.hiword i)
| _ => ntop1 x
end.
Lemma hiword_sound: forall v x, vmatch v x -> vmatch (Val.hiword v) (hiword x).
Proof. hammer_hook "ValueDomain" "ValueDomain.hiword_sound".
destruct 1; simpl; auto with va.
Qed.
Definition cmp_intv (c: comparison) (i: Z * Z) (n: Z) : abool :=
let (lo, hi) := i in
match c with
| Ceq => if zlt n lo || zlt hi n then Maybe false else Btop
| Cne => Btop
| Clt => if zlt hi n then Maybe true else if zle n lo then Maybe false else Btop
| Cle => if zle hi n then Maybe true else if zlt n lo then Maybe false else Btop
| Cgt => if zlt n lo then Maybe true else if zle hi n then Maybe false else Btop
| Cge => if zle n lo then Maybe true else if zlt hi n then Maybe false else Btop
end.
Definition zcmp (c: comparison) (n1 n2: Z) : bool :=
match c with
| Ceq => zeq n1 n2
| Cne => negb (zeq n1 n2)
| Clt => zlt n1 n2
| Cle => zle n1 n2
| Cgt => zlt n2 n1
| Cge => zle n2 n1
end.
Lemma zcmp_intv_sound:
forall c i x n,
fst i <= x <= snd i ->
cmatch (Some (zcmp c x n)) (cmp_intv c i n).
Proof. hammer_hook "ValueDomain" "ValueDomain.zcmp_intv_sound".
intros c [lo hi] x n; simpl; intros R.
destruct c; unfold zcmp, proj_sumbool.
-
destruct (zlt n lo). rewrite zeq_false by omega. constructor.
destruct (zlt hi n). rewrite zeq_false by omega. constructor.
constructor.
-
constructor.
-
destruct (zlt hi n). rewrite zlt_true by omega. constructor.
destruct (zle n lo). rewrite zlt_false by omega. constructor.
constructor.
-
destruct (zle hi n). rewrite zle_true by omega. constructor.
destruct (zlt n lo). rewrite zle_false by omega. constructor.
constructor.
-
destruct (zlt n lo). rewrite zlt_true by omega. constructor.
destruct (zle hi n). rewrite zlt_false by omega. constructor.
constructor.
-
destruct (zle n lo). rewrite zle_true by omega. constructor.
destruct (zlt hi n). rewrite zle_false by omega. constructor.
constructor.
Qed.
Lemma cmp_intv_None:
forall c i n, cmatch None (cmp_intv c i n).
Proof. hammer_hook "ValueDomain" "ValueDomain.cmp_intv_None".
unfold cmp_intv; intros. destruct i as [lo hi].
destruct c.
-
destruct (zlt n lo). constructor. destruct (zlt hi n); constructor.
-
constructor.
-
destruct (zlt hi n). constructor. destruct (zle n lo); constructor.
-
destruct (zle hi n). constructor. destruct (zlt n lo); constructor.
-
destruct (zlt n lo). constructor. destruct (zle hi n); constructor.
-
destruct (zle n lo). constructor. destruct (zlt hi n); constructor.
Qed.
Definition uintv (v: aval) : Z * Z :=
match v with
| I n => (Int.unsigned n, Int.unsigned n)
| Uns _ n => if zlt n Int.zwordsize then (0, two_p n - 1) else (0, Int.max_unsigned)
| _ => (0, Int.max_unsigned)
end.
Lemma uintv_sound:
forall n v, vmatch (Vint n) v -> fst (uintv v) <= Int.unsigned n <= snd (uintv v).
Proof. hammer_hook "ValueDomain" "ValueDomain.uintv_sound".
intros. inv H; simpl; try (apply Int.unsigned_range_2).
- omega.
- destruct (zlt n0 Int.zwordsize); simpl.
+ rewrite is_uns_zero_ext in H2. rewrite <- H2. rewrite Int.zero_ext_mod by omega.
exploit (Z_mod_lt (Int.unsigned n) (two_p n0)). apply two_p_gt_ZERO; auto. omega.
+ apply Int.unsigned_range_2.
Qed.
Lemma cmpu_intv_sound:
forall valid c n1 v1 n2,
vmatch (Vint n1) v1 ->
cmatch (Val.cmpu_bool valid c (Vint n1) (Vint n2)) (cmp_intv c (uintv v1) (Int.unsigned n2)).
Proof. hammer_hook "ValueDomain" "ValueDomain.cmpu_intv_sound".
intros. simpl. replace (Int.cmpu c n1 n2) with (zcmp c (Int.unsigned n1) (Int.unsigned n2)).
apply zcmp_intv_sound; apply uintv_sound; auto.
destruct c; simpl; auto.
unfold Int.ltu. destruct (zle (Int.unsigned n1) (Int.unsigned n2)); [rewrite zlt_false|rewrite zlt_true]; auto; omega.
unfold Int.ltu. destruct (zle (Int.unsigned n2) (Int.unsigned n1)); [rewrite zlt_false|rewrite zlt_true]; auto; omega.
Qed.
Lemma cmpu_intv_sound_2:
forall valid c n1 v1 n2,
vmatch (Vint n1) v1 ->
cmatch (Val.cmpu_bool valid c (Vint n2) (Vint n1)) (cmp_intv (swap_comparison c) (uintv v1) (Int.unsigned n2)).
Proof. hammer_hook "ValueDomain" "ValueDomain.cmpu_intv_sound_2".
intros. rewrite <- Val.swap_cmpu_bool. apply cmpu_intv_sound; auto.
Qed.
Definition sintv (v: aval) : Z * Z :=
match v with
| I n => (Int.signed n, Int.signed n)
| Uns _ n =>
if zlt n Int.zwordsize then (0, two_p n - 1) else (Int.min_signed, Int.max_signed)
| Sgn _ n =>
if zlt n Int.zwordsize
then (let x := two_p (n-1) in (-x, x-1))
else (Int.min_signed, Int.max_signed)
| _ => (Int.min_signed, Int.max_signed)
end.
Lemma sintv_sound:
forall n v, vmatch (Vint n) v -> fst (sintv v) <= Int.signed n <= snd (sintv v).
Proof. hammer_hook "ValueDomain" "ValueDomain.sintv_sound".
intros. inv H; simpl; try (apply Int.signed_range).
- omega.
- destruct (zlt n0 Int.zwordsize); simpl.
+ rewrite is_uns_zero_ext in H2. rewrite <- H2.
assert (Int.unsigned (Int.zero_ext n0 n) = Int.unsigned n mod two_p n0) by (apply Int.zero_ext_mod; omega).
exploit (Z_mod_lt (Int.unsigned n) (two_p n0)). apply two_p_gt_ZERO; auto. intros.
replace (Int.signed (Int.zero_ext n0 n)) with (Int.unsigned (Int.zero_ext n0 n)).
rewrite H. omega.
unfold Int.signed. rewrite zlt_true. auto.
assert (two_p n0 <= Int.half_modulus).
{ change Int.half_modulus with (two_p (Int.zwordsize - 1)).
apply two_p_monotone. omega. }
omega.
+ apply Int.signed_range.
- destruct (zlt n0 (Int.zwordsize)); simpl.
+ rewrite is_sgn_sign_ext in H2 by auto. rewrite <- H2.
exploit (Int.sign_ext_range n0 n). omega. omega.
+ apply Int.signed_range.
Qed.
Lemma cmp_intv_sound:
forall c n1 v1 n2,
vmatch (Vint n1) v1 ->
cmatch (Val.cmp_bool c (Vint n1) (Vint n2)) (cmp_intv c (sintv v1) (Int.signed n2)).
Proof. hammer_hook "ValueDomain" "ValueDomain.cmp_intv_sound".
intros. simpl. replace (Int.cmp c n1 n2) with (zcmp c (Int.signed n1) (Int.signed n2)).
apply zcmp_intv_sound; apply sintv_sound; auto.
destruct c; simpl; rewrite ? Int.eq_signed; auto.
unfold Int.lt. destruct (zle (Int.signed n1) (Int.signed n2)); [rewrite zlt_false|rewrite zlt_true]; auto; omega.
unfold Int.lt. destruct (zle (Int.signed n2) (Int.signed n1)); [rewrite zlt_false|rewrite zlt_true]; auto; omega.
Qed.
Lemma cmp_intv_sound_2:
forall c n1 v1 n2,
vmatch (Vint n1) v1 ->
cmatch (Val.cmp_bool c (Vint n2) (Vint n1)) (cmp_intv (swap_comparison c) (sintv v1) (Int.signed n2)).
Proof. hammer_hook "ValueDomain" "ValueDomain.cmp_intv_sound_2".
intros. rewrite <- Val.swap_cmp_bool. apply cmp_intv_sound; auto.
Qed.
Definition cmpu_bool (c: comparison) (v w: aval) : abool :=
match v, w with
| I i1, I i2 => Just (Int.cmpu c i1 i2)
| Ptr _, I i => if Int.eq i Int.zero then cmp_different_blocks c else Btop
| I i, Ptr _ => if Int.eq i Int.zero then cmp_different_blocks c else Btop
| Ptr p1, Ptr p2 => pcmp c p1 p2
| _, I i => club (cmp_intv c (uintv v) (Int.unsigned i)) (cmp_different_blocks c)
| I i, _ => club (cmp_intv (swap_comparison c) (uintv w) (Int.unsigned i)) (cmp_different_blocks c)
| _, _ => Btop
end.
Lemma cmpu_bool_sound:
forall valid c v w x y, vmatch v x -> vmatch w y -> cmatch (Val.cmpu_bool valid c v w) (cmpu_bool c x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.cmpu_bool_sound".
intros.
assert (IP: forall i b ofs,
cmatch (Val.cmpu_bool valid c (Vint i) (Vptr b ofs)) (cmp_different_blocks c)).
{
intros. simpl. destruct Archi.ptr64.
apply cmp_different_blocks_none.
destruct (Int.eq i Int.zero && (valid b (Ptrofs.unsigned ofs) || valid b (Ptrofs.unsigned ofs - 1))).
apply cmp_different_blocks_sound. apply cmp_different_blocks_none.
}
assert (PI: forall i b ofs,
cmatch (Val.cmpu_bool valid c (Vptr b ofs) (Vint i)) (cmp_different_blocks c)).
{
intros. simpl. destruct Archi.ptr64.
apply cmp_different_blocks_none.
destruct (Int.eq i Int.zero && (valid b (Ptrofs.unsigned ofs) || valid b (Ptrofs.unsigned ofs - 1))).
apply cmp_different_blocks_sound. apply cmp_different_blocks_none.
}
unfold cmpu_bool; inversion H; subst; inversion H0; subst;
auto using cmatch_top, cmp_different_blocks_none, pcmp_none,
cmatch_lub_l, cmatch_lub_r, pcmp_sound,
cmpu_intv_sound, cmpu_intv_sound_2, cmp_intv_None.
- constructor.
- destruct (Int.eq i Int.zero); auto using cmatch_top.
- simpl; destruct (Int.eq i Int.zero); auto using cmatch_top, cmp_different_blocks_none.
- destruct (Int.eq i Int.zero); auto using cmatch_top.
- simpl; destruct (Int.eq i Int.zero); auto using cmatch_top, cmp_different_blocks_none.
Qed.
Definition cmp_bool (c: comparison) (v w: aval) : abool :=
match v, w with
| I i1, I i2 => Just (Int.cmp c i1 i2)
| _, I i => cmp_intv c (sintv v) (Int.signed i)
| I i, _ => cmp_intv (swap_comparison c) (sintv w) (Int.signed i)
| _, _ => Btop
end.
Lemma cmp_bool_sound:
forall c v w x y, vmatch v x -> vmatch w y -> cmatch (Val.cmp_bool c v w) (cmp_bool c x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.cmp_bool_sound".
intros.
unfold cmp_bool; inversion H; subst; inversion H0; subst;
auto using cmatch_top, cmp_intv_sound, cmp_intv_sound_2, cmp_intv_None.
- constructor.
Qed.
Definition cmplu_bool (c: comparison) (v w: aval) : abool :=
match v, w with
| L i1, L i2 => Just (Int64.cmpu c i1 i2)
| Ptr _, L i => if Int64.eq i Int64.zero then cmp_different_blocks c else Btop
| L i, Ptr _ => if Int64.eq i Int64.zero then cmp_different_blocks c else Btop
| Ptr p1, Ptr p2 => pcmp c p1 p2
| _, _ => Btop
end.
Lemma cmplu_bool_sound:
forall valid c v w x y, vmatch v x -> vmatch w y -> cmatch (Val.cmplu_bool valid c v w) (cmplu_bool c x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.cmplu_bool_sound".
intros.
assert (IP: forall i b ofs,
cmatch (Val.cmplu_bool valid c (Vlong i) (Vptr b ofs)) (cmp_different_blocks c)).
{
intros. simpl. destruct Archi.ptr64; simpl.
destruct (Int64.eq i Int64.zero && (valid b (Ptrofs.unsigned ofs) || valid b (Ptrofs.unsigned ofs - 1))).
apply cmp_different_blocks_sound. apply cmp_different_blocks_none.
apply cmp_different_blocks_none.
}
assert (PI: forall i b ofs,
cmatch (Val.cmplu_bool valid c (Vptr b ofs) (Vlong i)) (cmp_different_blocks c)).
{
intros. simpl. destruct Archi.ptr64; simpl.
destruct (Int64.eq i Int64.zero && (valid b (Ptrofs.unsigned ofs) || valid b (Ptrofs.unsigned ofs - 1))).
apply cmp_different_blocks_sound. apply cmp_different_blocks_none.
apply cmp_different_blocks_none.
}
unfold cmplu_bool; inversion H; subst; inversion H0; subst;
auto using cmatch_top, cmp_different_blocks_none, pcmp_none,
cmatch_lub_l, cmatch_lub_r, pcmp_sound_64.
- constructor.
- destruct (Int64.eq i Int64.zero); auto using cmatch_top.
- simpl; destruct (Int64.eq i Int64.zero); auto using cmatch_top, cmp_different_blocks_none.
- destruct (Int64.eq i Int64.zero); auto using cmatch_top.
- simpl; destruct (Int64.eq i Int64.zero); auto using cmatch_top, cmp_different_blocks_none.
Qed.
Definition cmpl_bool (c: comparison) (v w: aval) : abool :=
match v, w with
| L i1, L i2 => Just (Int64.cmp c i1 i2)
| _, _ => Btop
end.
Lemma cmpl_bool_sound:
forall c v w x y, vmatch v x -> vmatch w y -> cmatch (Val.cmpl_bool c v w) (cmpl_bool c x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.cmpl_bool_sound".
intros.
unfold cmpl_bool; inversion H; subst; inversion H0; subst;
auto using cmatch_top.
- constructor.
Qed.
Definition cmpf_bool (c: comparison) (v w: aval) : abool :=
match v, w with
| F f1, F f2 => Just (Float.cmp c f1 f2)
| _, _ => Btop
end.
Lemma cmpf_bool_sound:
forall c v w x y, vmatch v x -> vmatch w y -> cmatch (Val.cmpf_bool c v w) (cmpf_bool c x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.cmpf_bool_sound".
intros. inv H; try constructor; inv H0; constructor.
Qed.
Definition cmpfs_bool (c: comparison) (v w: aval) : abool :=
match v, w with
| FS f1, FS f2 => Just (Float32.cmp c f1 f2)
| _, _ => Btop
end.
Lemma cmpfs_bool_sound:
forall c v w x y, vmatch v x -> vmatch w y -> cmatch (Val.cmpfs_bool c v w) (cmpfs_bool c x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.cmpfs_bool_sound".
intros. inv H; try constructor; inv H0; constructor.
Qed.
Definition maskzero (x: aval) (mask: int) : abool :=
match x with
| I i => Just (Int.eq (Int.and i mask) Int.zero)
| Uns p n => if Int.eq (Int.zero_ext n mask) Int.zero then Maybe true else Btop
| _ => Btop
end.
Lemma maskzero_sound:
forall mask v x,
vmatch v x ->
cmatch (Val.maskzero_bool v mask) (maskzero x mask).
Proof. hammer_hook "ValueDomain" "ValueDomain.maskzero_sound".
intros. inv H; simpl; auto with va.
predSpec Int.eq Int.eq_spec (Int.zero_ext n mask) Int.zero; auto with va.
replace (Int.and i mask) with Int.zero.
rewrite Int.eq_true. constructor.
rewrite is_uns_zero_ext in H1. rewrite Int.zero_ext_and in * by auto.
rewrite <- H1. rewrite Int.and_assoc. rewrite Int.and_commut in H. rewrite H.
rewrite Int.and_zero; auto.
destruct (Int.eq (Int.zero_ext n mask) Int.zero); constructor.
Qed.
Definition of_optbool (ab: abool) : aval :=
match ab with
| Just b => I (if b then Int.one else Int.zero)
| _ => Uns Pbot 1
end.
Lemma of_optbool_sound:
forall ob ab, cmatch ob ab -> vmatch (Val.of_optbool ob) (of_optbool ab).
Proof. hammer_hook "ValueDomain" "ValueDomain.of_optbool_sound".
intros.
assert (DEFAULT: vmatch (Val.of_optbool ob) (Uns Pbot 1)).
{
destruct ob; simpl; auto with va.
destruct b; constructor; try omega.
change 1 with (usize Int.one). apply is_uns_usize.
red; intros. apply Int.bits_zero.
}
inv H; auto. simpl. destruct b; constructor.
Qed.
Definition resolve_branch (ab: abool) : option bool :=
match ab with
| Just b => Some b
| Maybe b => Some b
| _ => None
end.
Lemma resolve_branch_sound:
forall b ab b',
cmatch (Some b) ab -> resolve_branch ab = Some b' -> b' = b.
Proof. hammer_hook "ValueDomain" "ValueDomain.resolve_branch_sound".
intros. inv H; simpl in H0; congruence.
Qed.
Definition add_undef (x: aval) :=
match x with
| Vbot => ntop
| I i =>
if Int.lt i Int.zero
then sgn Pbot (ssize i)
else uns Pbot (usize i)
| L _ | F _ | FS _ => ntop
| _ => x
end.
Lemma add_undef_sound:
forall v x, vmatch v x -> vmatch v (add_undef x).
Proof. hammer_hook "ValueDomain" "ValueDomain.add_undef_sound".
destruct 1; simpl; auto with va.
destruct (Int.lt i Int.zero).
apply vmatch_sgn; apply is_sgn_ssize.
apply vmatch_uns; apply is_uns_usize.
Qed.
Lemma add_undef_undef:
forall x, vmatch Vundef (add_undef x).
Proof. hammer_hook "ValueDomain" "ValueDomain.add_undef_undef".
destruct x; simpl; auto with va.
destruct (Int.lt n Int.zero); auto with va.
Qed.
Lemma add_undef_normalize:
forall v x ty, vmatch v x -> vmatch (Val.normalize v ty) (add_undef x).
Proof. hammer_hook "ValueDomain" "ValueDomain.add_undef_normalize".
intros. destruct (Val.lessdef_normalize v ty);
auto using add_undef_sound, add_undef_undef.
Qed.
Definition select (ab: abool) (x y: aval) :=
match ab with
| Bnone => ntop
| Just b | Maybe b => add_undef (if b then x else y)
| Btop => add_undef (vlub x y)
end.
Lemma select_sound:
forall ob v w ab x y ty,
cmatch ob ab -> vmatch v x -> vmatch w y ->
vmatch (Val.select ob v w ty) (select ab x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.select_sound".
unfold Val.select, select; intros. inv H.
- auto with va.
- apply add_undef_normalize; destruct b; auto.
- apply add_undef_undef.
- apply add_undef_normalize; destruct b; auto.
- destruct ob as [b|].
+ apply add_undef_normalize. destruct b; [apply vmatch_lub_l|apply vmatch_lub_r]; auto.
+ apply add_undef_undef.
Qed.
Definition vnormalize (chunk: memory_chunk) (v: aval) :=
match chunk, v with
| _, Vbot => Vbot
| Mint8signed, I i => I (Int.sign_ext 8 i)
| Mint8signed, Uns p n => if zlt n 8 then Uns (provenance v) n else Sgn (provenance v) 8
| Mint8signed, Sgn p n => Sgn (provenance v) (Z.min n 8)
| Mint8signed, _ => Sgn (provenance v) 8
| Mint8unsigned, I i => I (Int.zero_ext 8 i)
| Mint8unsigned, Uns p n => Uns (provenance v) (Z.min n 8)
| Mint8unsigned, _ => Uns (provenance v) 8
| Mint16signed, I i => I (Int.sign_ext 16 i)
| Mint16signed, Uns p n => if zlt n 16 then Uns (provenance v) n else Sgn (provenance v) 16
| Mint16signed, Sgn p n => Sgn (provenance v) (Z.min n 16)
| Mint16signed, _ => Sgn (provenance v) 16
| Mint16unsigned, I i => I (Int.zero_ext 16 i)
| Mint16unsigned, Uns p n => Uns (provenance v) (Z.min n 16)
| Mint16unsigned, _ => Uns (provenance v) 16
| Mint32, (I _ | Uns _ _ | Sgn _ _ | Ifptr _) => v
| Mint32, Ptr p => if Archi.ptr64 then Ifptr p else v
| Mint64, (L _ | Ifptr _) => v
| Mint64, (Uns p _ | Sgn p _) => Ifptr p
| Mint64, Ptr p => if Archi.ptr64 then v else Ifptr p
| Mfloat32, FS f => v
| Mfloat64, F f => v
| Many32, (I _ | Uns _ _ | Sgn _ _ | FS _ | Ifptr _) => v
| Many32, Ptr p => if Archi.ptr64 then Ifptr p else v
| Many64, _ => v
| _, _ => Ifptr (provenance v)
end.
Lemma vnormalize_sound:
forall chunk v x, vmatch v x -> vmatch (Val.load_result chunk v) (vnormalize chunk x).
Proof. hammer_hook "ValueDomain" "ValueDomain.vnormalize_sound".
unfold Val.load_result, vnormalize; generalize Archi.ptr64; intros ptr64;
induction 1; destruct chunk; auto with va.
- destruct (zlt n 8); constructor; auto with va.
apply is_sign_ext_uns; auto.
apply is_sign_ext_sgn; auto with va.
- constructor. xomega. apply is_zero_ext_uns. apply Z.min_case; auto with va.
- destruct (zlt n 16); constructor; auto with va.
apply is_sign_ext_uns; auto.
apply is_sign_ext_sgn; auto with va.
- constructor. xomega. apply is_zero_ext_uns. apply Z.min_case; auto with va.
- destruct (zlt n 8); auto with va.
- destruct (zlt n 16); auto with va.
- constructor. xomega. apply is_sign_ext_sgn; auto with va. apply Z.min_case; auto with va.
- constructor. omega. apply is_zero_ext_uns; auto with va.
- constructor. xomega. apply is_sign_ext_sgn; auto with va. apply Z.min_case; auto with va.
- constructor. omega. apply is_zero_ext_uns; auto with va.
- destruct ptr64; auto with va.
- destruct ptr64; auto with va.
- destruct ptr64; auto with va.
- destruct ptr64; auto with va.
- destruct ptr64; auto with va.
- destruct ptr64; auto with va.
- constructor. omega. apply is_sign_ext_sgn; auto with va.
- constructor. omega. apply is_zero_ext_uns; auto with va.
- constructor. omega. apply is_sign_ext_sgn; auto with va.
- constructor. omega. apply is_zero_ext_uns; auto with va.
- destruct ptr64; auto with va.
- destruct ptr64; auto with va.
- destruct ptr64; auto with va.
Qed.
Lemma vnormalize_cast:
forall chunk m b ofs v p,
Mem.load chunk m b ofs = Some v ->
vmatch v (Ifptr p) ->
vmatch v (vnormalize chunk (Ifptr p)).
Proof. hammer_hook "ValueDomain" "ValueDomain.vnormalize_cast".
intros. exploit Mem.load_cast; eauto. exploit Mem.load_type; eauto.
destruct chunk; simpl; intros.
-
rewrite H2. destruct v; simpl; constructor. omega. apply is_sign_ext_sgn; auto with va.
-
rewrite H2. destruct v; simpl; constructor. omega. apply is_zero_ext_uns; auto with va.
-
rewrite H2. destruct v; simpl; constructor. omega. apply is_sign_ext_sgn; auto with va.
-
rewrite H2. destruct v; simpl; constructor. omega. apply is_zero_ext_uns; auto with va.
-
auto.
-
auto.
-
destruct v; try contradiction; constructor.
-
destruct v; try contradiction; constructor.
-
destruct Archi.ptr64; auto.
-
auto.
Qed.
Remark poffset_monotone:
forall p q, pge p q -> pge (poffset p) (poffset q).
Proof. hammer_hook "ValueDomain" "ValueDomain.poffset_monotone".
destruct 1; simpl; auto with va.
Qed.
Remark provenance_monotone:
forall x y, vge x y -> pge (provenance x) (provenance y).
Proof. hammer_hook "ValueDomain" "ValueDomain.provenance_monotone".
unfold provenance; intros. destruct (va_strict tt). constructor.
inv H; auto using poffset_monotone with va.
Qed.
Lemma vnormalize_monotone:
forall chunk x y,
vge x y -> vge (vnormalize chunk x) (vnormalize chunk y).
Proof with (auto using provenance_monotone with va). hammer_hook "ValueDomain" "ValueDomain.vnormalize_monotone".
intros chunk x y V; unfold vnormalize; generalize Archi.ptr64; intro ptr64; inversion V; subst; destruct chunk eqn:C; simpl...
- destruct (zlt n 8); constructor...
apply is_sign_ext_uns...
apply is_sign_ext_sgn...
- constructor... apply is_zero_ext_uns... apply Z.min_case...
- destruct (zlt n 16); constructor...
apply is_sign_ext_uns...
apply is_sign_ext_sgn...
- constructor... apply is_zero_ext_uns... apply Z.min_case...
- unfold provenance; destruct (va_strict tt)...
- destruct (zlt n1 8). rewrite zlt_true by omega...
destruct (zlt n2 8)...
- destruct (zlt n1 16). rewrite zlt_true by omega...
destruct (zlt n2 16)...
- constructor... apply is_sign_ext_sgn... apply Z.min_case...
- constructor... apply is_zero_ext_uns...
- constructor... apply is_sign_ext_sgn... apply Z.min_case...
- constructor... apply is_zero_ext_uns...
- unfold provenance; destruct (va_strict tt)...
- destruct (zlt n2 8); constructor...
- destruct (zlt n2 16); constructor...
- destruct ptr64...
- destruct ptr64...
- destruct ptr64...
- destruct ptr64...
- destruct ptr64...
- destruct ptr64...
- constructor... apply is_sign_ext_sgn...
- constructor... apply is_zero_ext_uns...
- constructor... apply is_sign_ext_sgn...
- constructor... apply is_zero_ext_uns...
- unfold provenance; destruct (va_strict tt)...
- unfold provenance; destruct (va_strict tt)...
- unfold provenance; destruct (va_strict tt)...
- unfold provenance; destruct (va_strict tt)...
- unfold provenance; destruct (va_strict tt)...
- unfold provenance; destruct (va_strict tt)...
- unfold provenance; destruct (va_strict tt)...
- unfold provenance; destruct (va_strict tt)...
- destruct (zlt n 8)...
- destruct (zlt n 16)...
Qed.
Definition val_of_aval (a: aval) : val :=
match a with
| I n => Vint n
| L n => Vlong n
| F f => Vfloat f
| FS f => Vsingle f
| _ => Vundef
end.
Definition aval_of_val (v: val) : option aval :=
match v with
| Vint n => Some (I n)
| Vlong n => Some (L n)
| Vfloat f => Some (F f)
| Vsingle f => Some (FS f)
| _ => None
end.
Lemma val_of_aval_sound:
forall v a, vmatch v a -> Val.lessdef (val_of_aval a) v.
Proof. hammer_hook "ValueDomain" "ValueDomain.val_of_aval_sound".
destruct 1; simpl; auto.
Qed.
Corollary list_val_of_aval_sound:
forall vl al, list_forall2 vmatch vl al -> Val.lessdef_list (map val_of_aval al) vl.
Proof. hammer_hook "ValueDomain" "ValueDomain.list_val_of_aval_sound".
induction 1; simpl; constructor; auto using val_of_aval_sound.
Qed.
Lemma aval_of_val_sound:
forall v a, aval_of_val v = Some a -> vmatch v a.
Proof. hammer_hook "ValueDomain" "ValueDomain.aval_of_val_sound".
intros v a E; destruct v; simpl in E; inv E; constructor.
Qed.
Inductive acontent : Type :=
| ACval (chunk: memory_chunk) (av: aval).
Definition eq_acontent : forall (c1 c2: acontent), {c1=c2} + {c1<>c2}.
Proof. hammer_hook "ValueDomain" "ValueDomain.eq_acontent".
intros. generalize chunk_eq eq_aval. decide equality.
Defined.
Record ablock : Type := ABlock {
ab_contents: ZTree.t acontent;
ab_summary: aptr
}.
Local Notation "a ## b" := (ZTree.get b a) (at level 1).
Definition ablock_init (p: aptr) : ablock :=
{| ab_contents := ZTree.empty _; ab_summary := p |}.
Definition chunk_compat (chunk chunk': memory_chunk) : bool :=
match chunk, chunk' with
| (Mint8signed | Mint8unsigned), (Mint8signed | Mint8unsigned) => true
| (Mint16signed | Mint16unsigned), (Mint16signed | Mint16unsigned) => true
| Mint32, Mint32 => true
| Mfloat32, Mfloat32 => true
| Mint64, Mint64 => true
| Mfloat64, Mfloat64 => true
| Many32, Many32 => true
| Many64, Many64 => true
| _, _ => false
end.
Definition ablock_load (chunk: memory_chunk) (ab: ablock) (i: Z) : aval :=
match ab.(ab_contents)##i with
| None => vnormalize chunk (Ifptr ab.(ab_summary))
| Some (ACval chunk' av) =>
if chunk_compat chunk chunk'
then vnormalize chunk av
else vnormalize chunk (Ifptr ab.(ab_summary))
end.
Definition ablock_load_anywhere (chunk: memory_chunk) (ab: ablock) : aval :=
vnormalize chunk (Ifptr ab.(ab_summary)).
Function inval_after (lo: Z) (hi: Z) (c: ZTree.t acontent) { wf (Zwf lo) hi } : ZTree.t acontent :=
if zle lo hi
then inval_after lo (hi - 1) (ZTree.remove hi c)
else c.
Proof. hammer_hook "ValueDomain" "ValueDomain.ablock_load_anywhere".
intros; red; omega.
apply Zwf_well_founded.
Qed.
Definition inval_if (hi: Z) (lo: Z) (c: ZTree.t acontent) :=
match c##lo with
| None => c
| Some (ACval chunk av) => if zle (lo + size_chunk chunk) hi then c else ZTree.remove lo c
end.
Function inval_before (hi: Z) (lo: Z) (c: ZTree.t acontent) { wf (Zwf_up hi) lo } : ZTree.t acontent :=
if zlt lo hi
then inval_before hi (lo + 1) (inval_if hi lo c)
else c.
Proof. hammer_hook "ValueDomain" "ValueDomain.inval_if".
intros; red; omega.
apply Zwf_up_well_founded.
Qed.
Definition ablock_store (chunk: memory_chunk) (ab: ablock) (i: Z) (av: aval) : ablock :=
{| ab_contents :=
ZTree.set i (ACval chunk av)
(inval_before i (i - 7)
(inval_after (i + 1) (i + size_chunk chunk - 1) ab.(ab_contents)));
ab_summary :=
vplub av ab.(ab_summary) |}.
Definition ablock_store_anywhere (chunk: memory_chunk) (ab: ablock) (av: aval) : ablock :=
ablock_init (vplub av ab.(ab_summary)).
Definition ablock_loadbytes (ab: ablock) : aptr := ab.(ab_summary).
Definition ablock_storebytes (ab: ablock) (p: aptr) (ofs: Z) (sz: Z) :=
{| ab_contents :=
inval_before ofs (ofs - 7)
(inval_after ofs (ofs + sz - 1) ab.(ab_contents));
ab_summary :=
plub p ab.(ab_summary) |}.
Definition ablock_storebytes_anywhere (ab: ablock) (p: aptr) :=
ablock_init (plub p ab.(ab_summary)).
Definition smatch (m: mem) (b: block) (p: aptr) : Prop :=
(forall chunk ofs v, Mem.load chunk m b ofs = Some v -> vmatch v (Ifptr p))
/\(forall ofs b' ofs' q i, Mem.loadbytes m b ofs 1 = Some (Fragment (Vptr b' ofs') q i :: nil) -> pmatch b' ofs' p).
Remark loadbytes_load_ext:
forall b m m',
(forall ofs n bytes, Mem.loadbytes m' b ofs n = Some bytes -> n >= 0 -> Mem.loadbytes m b ofs n = Some bytes) ->
forall chunk ofs v, Mem.load chunk m' b ofs = Some v -> Mem.load chunk m b ofs = Some v.
Proof. hammer_hook "ValueDomain" "ValueDomain.loadbytes_load_ext".
intros. exploit Mem.load_loadbytes; eauto. intros [bytes [A B]].
exploit Mem.load_valid_access; eauto. intros [C D].
subst v. apply Mem.loadbytes_load; auto. apply H; auto. generalize (size_chunk_pos chunk); omega.
Qed.
Lemma smatch_ext:
forall m b p m',
smatch m b p ->
(forall ofs n bytes, Mem.loadbytes m' b ofs n = Some bytes -> n >= 0 -> Mem.loadbytes m b ofs n = Some bytes) ->
smatch m' b p.
Proof. hammer_hook "ValueDomain" "ValueDomain.smatch_ext".
intros. destruct H. split; intros.
eapply H; eauto. eapply loadbytes_load_ext; eauto.
eapply H1; eauto. apply H0; eauto. omega.
Qed.
Lemma smatch_inv:
forall m b p m',
smatch m b p ->
(forall ofs n, n >= 0 -> Mem.loadbytes m' b ofs n = Mem.loadbytes m b ofs n) ->
smatch m' b p.
Proof. hammer_hook "ValueDomain" "ValueDomain.smatch_inv".
intros. eapply smatch_ext; eauto.
intros. rewrite <- H0; eauto.
Qed.
Lemma smatch_ge:
forall m b p q, smatch m b p -> pge q p -> smatch m b q.
Proof. hammer_hook "ValueDomain" "ValueDomain.smatch_ge".
intros. destruct H as [A B]. split; intros.
apply vmatch_ge with (Ifptr p); eauto with va.
apply pmatch_ge with p; eauto with va.
Qed.
Lemma In_loadbytes:
forall m b byte n ofs bytes,
Mem.loadbytes m b ofs n = Some bytes ->
In byte bytes ->
exists ofs', ofs <= ofs' < ofs + n /\ Mem.loadbytes m b ofs' 1 = Some(byte :: nil).
Proof. hammer_hook "ValueDomain" "ValueDomain.In_loadbytes".
intros until n. pattern n.
apply well_founded_ind with (R := Zwf 0).
- apply Zwf_well_founded.
- intros sz REC ofs bytes LOAD IN.
destruct (zle sz 0).
+ rewrite (Mem.loadbytes_empty m b ofs sz) in LOAD by auto.
inv LOAD. contradiction.
+ exploit (Mem.loadbytes_split m b ofs 1 (sz - 1) bytes).
replace (1 + (sz - 1)) with sz by omega. auto.
omega.
omega.
intros (bytes1 & bytes2 & LOAD1 & LOAD2 & CONCAT).
subst bytes.
exploit Mem.loadbytes_length. eexact LOAD1. change (Z.to_nat 1) with 1%nat. intros LENGTH1.
rewrite in_app_iff in IN. destruct IN.
* destruct bytes1; try discriminate. destruct bytes1; try discriminate.
simpl in H. destruct H; try contradiction. subst m0.
exists ofs; split. omega. auto.
* exploit (REC (sz - 1)). red; omega. eexact LOAD2. auto.
intros (ofs' & A & B).
exists ofs'; split. omega. auto.
Qed.
Lemma smatch_loadbytes:
forall m b p b' ofs' q i n ofs bytes,
Mem.loadbytes m b ofs n = Some bytes ->
smatch m b p ->
In (Fragment (Vptr b' ofs') q i) bytes ->
pmatch b' ofs' p.
Proof. hammer_hook "ValueDomain" "ValueDomain.smatch_loadbytes".
intros. exploit In_loadbytes; eauto. intros (ofs1 & A & B).
eapply H0; eauto.
Qed.
Lemma loadbytes_provenance:
forall m b ofs' byte n ofs bytes,
Mem.loadbytes m b ofs n = Some bytes ->
Mem.loadbytes m b ofs' 1 = Some (byte :: nil) ->
ofs <= ofs' < ofs + n ->
In byte bytes.
Proof. hammer_hook "ValueDomain" "ValueDomain.loadbytes_provenance".
intros until n. pattern n.
apply well_founded_ind with (R := Zwf 0).
- apply Zwf_well_founded.
- intros sz REC ofs bytes LOAD LOAD1 IN.
exploit (Mem.loadbytes_split m b ofs 1 (sz - 1) bytes).
replace (1 + (sz - 1)) with sz by omega. auto.
omega.
omega.
intros (bytes1 & bytes2 & LOAD3 & LOAD4 & CONCAT). subst bytes. rewrite in_app_iff.
destruct (zeq ofs ofs').
+ subst ofs'. rewrite LOAD1 in LOAD3; inv LOAD3. left; simpl; auto.
+ right. eapply (REC (sz - 1)). red; omega. eexact LOAD4. auto. omega.
Qed.
Lemma storebytes_provenance:
forall m b ofs bytes m' b' ofs' b'' ofs'' q i,
Mem.storebytes m b ofs bytes = Some m' ->
Mem.loadbytes m' b' ofs' 1 = Some (Fragment (Vptr b'' ofs'') q i :: nil) ->
In (Fragment (Vptr b'' ofs'') q i) bytes
\/ Mem.loadbytes m b' ofs' 1 = Some (Fragment (Vptr b'' ofs'') q i :: nil).
Proof. hammer_hook "ValueDomain" "ValueDomain.storebytes_provenance".
intros.
assert (EITHER:
(b' <> b \/ ofs' + 1 <= ofs \/ ofs + Z.of_nat (length bytes) <= ofs')
\/ (b' = b /\ ofs <= ofs' < ofs + Z.of_nat (length bytes))).
{
destruct (eq_block b' b); auto.
destruct (zle (ofs' + 1) ofs); auto.
destruct (zle (ofs + Z.of_nat (length bytes)) ofs'); auto.
right. split. auto. omega.
}
destruct EITHER as [A | (A & B)].
- right. rewrite <- H0. symmetry. eapply Mem.loadbytes_storebytes_other; eauto. omega.
- subst b'. left.
eapply loadbytes_provenance; eauto.
eapply Mem.loadbytes_storebytes_same; eauto.
Qed.
Lemma store_provenance:
forall chunk m b ofs v m' b' ofs' b'' ofs'' q i,
Mem.store chunk m b ofs v = Some m' ->
Mem.loadbytes m' b' ofs' 1 = Some (Fragment (Vptr b'' ofs'') q i :: nil) ->
v = Vptr b'' ofs'' /\ (chunk = Mint32 \/ chunk = Many32 \/ chunk = Mint64 \/ chunk = Many64)
\/ Mem.loadbytes m b' ofs' 1 = Some (Fragment (Vptr b'' ofs'') q i :: nil).
Proof. hammer_hook "ValueDomain" "ValueDomain.store_provenance".
intros. exploit storebytes_provenance; eauto. eapply Mem.store_storebytes; eauto.
intros [A|A]; auto. left.
generalize (encode_val_shape chunk v). intros ENC; inv ENC.
- split; auto. rewrite <- H1 in A; destruct A.
+ congruence.
+ exploit H5; eauto. intros (j & P & Q); congruence.
- rewrite <- H1 in A; destruct A.
+ congruence.
+ exploit H3; eauto. intros [byte P]; congruence.
- rewrite <- H1 in A; destruct A.
+ congruence.
+ exploit H2; eauto. congruence.
Qed.
Lemma smatch_store:
forall chunk m b ofs v m' b' p av,
Mem.store chunk m b ofs v = Some m' ->
smatch m b' p ->
vmatch v av ->
smatch m' b' (vplub av p).
Proof. hammer_hook "ValueDomain" "ValueDomain.smatch_store".
intros. destruct H0 as [A B]. split.
- intros chunk' ofs' v' LOAD. destruct v'; auto with va.
exploit Mem.load_pointer_store; eauto.
intros [(P & Q & R & S) | DISJ].
+ subst. apply vmatch_vplub_l. auto.
+ apply vmatch_vplub_r. apply A with (chunk := chunk') (ofs := ofs').
rewrite <- LOAD. symmetry. eapply Mem.load_store_other; eauto.
- intros. exploit store_provenance; eauto. intros [[P Q] | P].
+ subst.
assert (V: vmatch (Vptr b'0 ofs') (Ifptr (vplub av p))).
{
apply vmatch_vplub_l. auto.
}
inv V; auto.
+ apply pmatch_vplub. eapply B; eauto.
Qed.
Lemma smatch_storebytes:
forall m b ofs bytes m' b' p p',
Mem.storebytes m b ofs bytes = Some m' ->
smatch m b' p ->
(forall b' ofs' q i, In (Fragment (Vptr b' ofs') q i) bytes -> pmatch b' ofs' p') ->
smatch m' b' (plub p' p).
Proof. hammer_hook "ValueDomain" "ValueDomain.smatch_storebytes".
intros. destruct H0 as [A B]. split.
- intros. apply vmatch_ifptr. intros bx ofsx EQ; subst v.
exploit Mem.load_loadbytes; eauto. intros (bytes' & P & Q).
destruct bytes' as [ | byte1' bytes'].
exploit Mem.loadbytes_length; eauto. intros. destruct chunk; discriminate.
generalize (decode_val_shape chunk byte1' bytes'). rewrite <- Q.
intros DEC; inv DEC; try contradiction.
assert (v = Vptr bx ofsx).
{ destruct H5 as [E|[E|[E|E]]]; rewrite E in H4; destruct v; simpl in H4;
try congruence; destruct Archi.ptr64; congruence. }
exploit In_loadbytes; eauto. eauto with coqlib.
intros (ofs' & X & Y). subst v.
exploit storebytes_provenance; eauto. intros [Z | Z].
apply pmatch_lub_l. eauto.
apply pmatch_lub_r. eauto.
- intros. exploit storebytes_provenance; eauto. intros [Z | Z].
apply pmatch_lub_l. eauto.
apply pmatch_lub_r. eauto.
Qed.
Definition bmatch (m: mem) (b: block) (ab: ablock) : Prop :=
smatch m b ab.(ab_summary) /\
forall chunk ofs v, Mem.load chunk m b ofs = Some v -> vmatch v (ablock_load chunk ab ofs).
Lemma bmatch_ext:
forall m b ab m',
bmatch m b ab ->
(forall ofs n bytes, Mem.loadbytes m' b ofs n = Some bytes -> n >= 0 -> Mem.loadbytes m b ofs n = Some bytes) ->
bmatch m' b ab.
Proof. hammer_hook "ValueDomain" "ValueDomain.bmatch_ext".
intros. destruct H as [A B]. split; intros.
apply smatch_ext with m; auto.
eapply B; eauto. eapply loadbytes_load_ext; eauto.
Qed.
Lemma bmatch_inv:
forall m b ab m',
bmatch m b ab ->
(forall ofs n, n >= 0 -> Mem.loadbytes m' b ofs n = Mem.loadbytes m b ofs n) ->
bmatch m' b ab.
Proof. hammer_hook "ValueDomain" "ValueDomain.bmatch_inv".
intros. eapply bmatch_ext; eauto.
intros. rewrite <- H0; eauto.
Qed.
Lemma ablock_load_sound:
forall chunk m b ofs v ab,
Mem.load chunk m b ofs = Some v ->
bmatch m b ab ->
vmatch v (ablock_load chunk ab ofs).
Proof. hammer_hook "ValueDomain" "ValueDomain.ablock_load_sound".
intros. destruct H0. eauto.
Qed.
Lemma ablock_load_anywhere_sound:
forall chunk m b ofs v ab,
Mem.load chunk m b ofs = Some v ->
bmatch m b ab ->
vmatch v (ablock_load_anywhere chunk ab).
Proof. hammer_hook "ValueDomain" "ValueDomain.ablock_load_anywhere_sound".
intros. destruct H0. destruct H0. unfold ablock_load_anywhere.
eapply vnormalize_cast; eauto.
Qed.
Lemma ablock_init_sound:
forall m b p, smatch m b p -> bmatch m b (ablock_init p).
Proof. hammer_hook "ValueDomain" "ValueDomain.ablock_init_sound".
intros; split; auto; intros.
unfold ablock_load, ablock_init; simpl. rewrite ZTree.gempty.
eapply vnormalize_cast; eauto. eapply H; eauto.
Qed.
Lemma ablock_store_anywhere_sound:
forall chunk m b ofs v m' b' ab av,
Mem.store chunk m b ofs v = Some m' ->
bmatch m b' ab ->
vmatch v av ->
bmatch m' b' (ablock_store_anywhere chunk ab av).
Proof. hammer_hook "ValueDomain" "ValueDomain.ablock_store_anywhere_sound".
intros. destruct H0 as [A B]. unfold ablock_store_anywhere.
apply ablock_init_sound. eapply smatch_store; eauto.
Qed.
Remark inval_after_outside:
forall i lo hi c, i < lo \/ i > hi -> (inval_after lo hi c)##i = c##i.
Proof. hammer_hook "ValueDomain" "ValueDomain.inval_after_outside".
intros until c. functional induction (inval_after lo hi c); intros.
rewrite IHt by omega. apply ZTree.gro. unfold ZTree.elt, ZIndexed.t; omega.
auto.
Qed.
Remark inval_after_contents:
forall chunk av i lo hi c,
(inval_after lo hi c)##i = Some (ACval chunk av) ->
c##i = Some (ACval chunk av) /\ (i < lo \/ i > hi).
Proof. hammer_hook "ValueDomain" "ValueDomain.inval_after_contents".
intros until c. functional induction (inval_after lo hi c); intros.
destruct (zeq i hi).
subst i. rewrite inval_after_outside in H by omega. rewrite ZTree.grs in H. discriminate.
exploit IHt; eauto. intros [A B]. rewrite ZTree.gro in A by auto. split. auto. omega.
split. auto. omega.
Qed.
Remark inval_before_outside:
forall i hi lo c, i < lo \/ i >= hi -> (inval_before hi lo c)##i = c##i.
Proof. hammer_hook "ValueDomain" "ValueDomain.inval_before_outside".
intros until c. functional induction (inval_before hi lo c); intros.
rewrite IHt by omega. unfold inval_if. destruct (c##lo) as [[chunk av]|]; auto.
destruct (zle (lo + size_chunk chunk) hi); auto.
apply ZTree.gro. unfold ZTree.elt, ZIndexed.t; omega.
auto.
Qed.
Remark inval_before_contents_1:
forall i chunk av lo hi c,
lo <= i < hi -> (inval_before hi lo c)##i = Some(ACval chunk av) ->
c##i = Some(ACval chunk av) /\ i + size_chunk chunk <= hi.
Proof. hammer_hook "ValueDomain" "ValueDomain.inval_before_contents_1".
intros until c. functional induction (inval_before hi lo c); intros.
- destruct (zeq lo i).
+ subst i. rewrite inval_before_outside in H0 by omega.
unfold inval_if in H0. destruct (c##lo) as [[chunk0 v0]|] eqn:C; try congruence.
destruct (zle (lo + size_chunk chunk0) hi).
rewrite C in H0; inv H0. auto.
rewrite ZTree.grs in H0. congruence.
+ exploit IHt. omega. auto. intros [A B]; split; auto.
unfold inval_if in A. destruct (c##lo) as [[chunk0 v0]|] eqn:C; auto.
destruct (zle (lo + size_chunk chunk0) hi); auto.
rewrite ZTree.gro in A; auto.
- omegaContradiction.
Qed.
Lemma max_size_chunk: forall chunk, size_chunk chunk <= 8.
Proof. hammer_hook "ValueDomain" "ValueDomain.max_size_chunk".
destruct chunk; simpl; omega.
Qed.
Remark inval_before_contents:
forall i c chunk' av' j,
(inval_before i (i - 7) c)##j = Some (ACval chunk' av') ->
c##j = Some (ACval chunk' av') /\ (j + size_chunk chunk' <= i \/ i <= j).
Proof. hammer_hook "ValueDomain" "ValueDomain.inval_before_contents".
intros. destruct (zlt j (i - 7)).
rewrite inval_before_outside in H by omega.
split. auto. left. generalize (max_size_chunk chunk'); omega.
destruct (zlt j i).
exploit inval_before_contents_1; eauto. omega. tauto.
rewrite inval_before_outside in H by omega.
split. auto. omega.
Qed.
Lemma ablock_store_contents:
forall chunk ab i av j chunk' av',
(ablock_store chunk ab i av).(ab_contents)##j = Some(ACval chunk' av') ->
(i = j /\ chunk' = chunk /\ av' = av)
\/ (ab.(ab_contents)##j = Some(ACval chunk' av')
/\ (j + size_chunk chunk' <= i \/ i + size_chunk chunk <= j)).
Proof. hammer_hook "ValueDomain" "ValueDomain.ablock_store_contents".
unfold ablock_store; simpl; intros.
destruct (zeq i j).
subst j. rewrite ZTree.gss in H. inv H; auto.
right. rewrite ZTree.gso in H by auto.
exploit inval_before_contents; eauto. intros [A B].
exploit inval_after_contents; eauto. intros [C D].
split. auto. omega.
Qed.
Lemma chunk_compat_true:
forall c c',
chunk_compat c c' = true ->
size_chunk c = size_chunk c' /\ align_chunk c <= align_chunk c' /\ type_of_chunk c = type_of_chunk c'.
Proof. hammer_hook "ValueDomain" "ValueDomain.chunk_compat_true".
destruct c, c'; intros; try discriminate; simpl; auto with va.
Qed.
Lemma ablock_store_sound:
forall chunk m b ofs v m' ab av,
Mem.store chunk m b ofs v = Some m' ->
bmatch m b ab ->
vmatch v av ->
bmatch m' b (ablock_store chunk ab ofs av).
Proof. hammer_hook "ValueDomain" "ValueDomain.ablock_store_sound".
intros until av; intros STORE BIN VIN. destruct BIN as [BIN1 BIN2]. split.
eapply smatch_store; eauto.
intros chunk' ofs' v' LOAD.
assert (SUMMARY: vmatch v' (vnormalize chunk' (Ifptr (vplub av ab.(ab_summary))))).
{ exploit smatch_store; eauto. intros [A B]. eapply vnormalize_cast; eauto. }
unfold ablock_load.
destruct ((ab_contents (ablock_store chunk ab ofs av)) ## ofs') as [[chunk1 av1]|] eqn:C; auto.
destruct (chunk_compat chunk' chunk1) eqn:COMPAT; auto.
exploit chunk_compat_true; eauto. intros (U & V & W).
exploit ablock_store_contents; eauto. intros [(P & Q & R) | (P & Q)].
-
subst.
assert (v' = Val.load_result chunk' v).
{ exploit Mem.load_store_similar_2; eauto. congruence. }
subst v'. apply vnormalize_sound; auto.
-
assert (Mem.load chunk' m b ofs' = Some v').
{ rewrite <- LOAD. symmetry. eapply Mem.load_store_other; eauto.
rewrite U. auto. }
exploit BIN2; eauto. unfold ablock_load. rewrite P. rewrite COMPAT. auto.
Qed.
Lemma ablock_loadbytes_sound:
forall m b ab b' ofs' q i n ofs bytes,
Mem.loadbytes m b ofs n = Some bytes ->
bmatch m b ab ->
In (Fragment (Vptr b' ofs') q i) bytes ->
pmatch b' ofs' (ablock_loadbytes ab).
Proof. hammer_hook "ValueDomain" "ValueDomain.ablock_loadbytes_sound".
intros. destruct H0. eapply smatch_loadbytes; eauto.
Qed.
Lemma ablock_storebytes_anywhere_sound:
forall m b ofs bytes p m' b' ab,
Mem.storebytes m b ofs bytes = Some m' ->
(forall b' ofs' q i, In (Fragment (Vptr b' ofs') q i) bytes -> pmatch b' ofs' p) ->
bmatch m b' ab ->
bmatch m' b' (ablock_storebytes_anywhere ab p).
Proof. hammer_hook "ValueDomain" "ValueDomain.ablock_storebytes_anywhere_sound".
intros. destruct H1 as [A B]. apply ablock_init_sound.
eapply smatch_storebytes; eauto.
Qed.
Lemma ablock_storebytes_contents:
forall ab p i sz j chunk' av',
(ablock_storebytes ab p i sz).(ab_contents)##j = Some(ACval chunk' av') ->
ab.(ab_contents)##j = Some (ACval chunk' av')
/\ (j + size_chunk chunk' <= i \/ i + Z.max sz 0 <= j).
Proof. hammer_hook "ValueDomain" "ValueDomain.ablock_storebytes_contents".
unfold ablock_storebytes; simpl; intros.
exploit inval_before_contents; eauto. clear H. intros [A B].
exploit inval_after_contents; eauto. clear A. intros [C D].
split. auto. xomega.
Qed.
Lemma ablock_storebytes_sound:
forall m b ofs bytes m' p ab sz,
Mem.storebytes m b ofs bytes = Some m' ->
length bytes = Z.to_nat sz ->
(forall b' ofs' q i, In (Fragment (Vptr b' ofs') q i) bytes -> pmatch b' ofs' p) ->
bmatch m b ab ->
bmatch m' b (ablock_storebytes ab p ofs sz).
Proof. hammer_hook "ValueDomain" "ValueDomain.ablock_storebytes_sound".
intros until sz; intros STORE LENGTH CONTENTS BM. destruct BM as [BM1 BM2]. split.
eapply smatch_storebytes; eauto.
intros chunk' ofs' v' LOAD'.
assert (SUMMARY: vmatch v' (vnormalize chunk' (Ifptr (plub p ab.(ab_summary))))).
{ exploit smatch_storebytes; eauto. intros [A B]. eapply vnormalize_cast; eauto. }
unfold ablock_load.
destruct (ab_contents (ablock_storebytes ab p ofs sz))##ofs' as [[chunk av]|] eqn:C; auto.
destruct (chunk_compat chunk' chunk) eqn:COMPAT; auto.
exploit chunk_compat_true; eauto. intros (U & V & W).
exploit ablock_storebytes_contents; eauto. intros [A B].
assert (Mem.load chunk' m b ofs' = Some v').
{ rewrite <- LOAD'; symmetry. eapply Mem.load_storebytes_other; eauto.
rewrite U. rewrite LENGTH. rewrite Z_to_nat_max. right; omega. }
exploit BM2; eauto. unfold ablock_load. rewrite A. rewrite COMPAT. auto.
Qed.
Definition bbeq (ab1 ab2: ablock) : bool :=
eq_aptr ab1.(ab_summary) ab2.(ab_summary) &&
ZTree.beq (fun c1 c2 => proj_sumbool (eq_acontent c1 c2)) ab1.(ab_contents) ab2.(ab_contents).
Lemma bbeq_load:
forall ab1 ab2,
bbeq ab1 ab2 = true ->
ab1.(ab_summary) = ab2.(ab_summary)
/\ (forall chunk i, ablock_load chunk ab1 i = ablock_load chunk ab2 i).
Proof. hammer_hook "ValueDomain" "ValueDomain.bbeq_load".
unfold bbeq; intros. InvBooleans. split.
- unfold ablock_load_anywhere; intros; congruence.
- assert (A: forall i, ZTree.get i (ab_contents ab1) = ZTree.get i (ab_contents ab2)).
{
intros. exploit ZTree.beq_sound; eauto. instantiate (1 := i).
destruct (ab_contents ab1)##i, (ab_contents ab2)##i; intros; try contradiction.
InvBooleans; subst; auto.
auto. }
intros. unfold ablock_load. rewrite A, H.
destruct (ab_contents ab2)##i; auto.
Qed.
Lemma bbeq_sound:
forall ab1 ab2,
bbeq ab1 ab2 = true ->
forall m b, bmatch m b ab1 <-> bmatch m b ab2.
Proof. hammer_hook "ValueDomain" "ValueDomain.bbeq_sound".
intros. exploit bbeq_load; eauto. intros [A B].
unfold bmatch. rewrite A. intuition. rewrite <- B; eauto. rewrite B; eauto.
Qed.
Definition combine_acontents (c1 c2: option acontent) : option acontent :=
match c1, c2 with
| Some (ACval chunk1 v1), Some (ACval chunk2 v2) =>
if chunk_eq chunk1 chunk2 then Some(ACval chunk1 (vlub v1 v2)) else None
| _, _ =>
None
end.
Definition blub (ab1 ab2: ablock) : ablock :=
{| ab_contents := ZTree.combine combine_acontents ab1.(ab_contents) ab2.(ab_contents);
ab_summary := plub ab1.(ab_summary) ab2.(ab_summary) |}.
Lemma smatch_lub_l:
forall m b p q, smatch m b p -> smatch m b (plub p q).
Proof. hammer_hook "ValueDomain" "ValueDomain.smatch_lub_l".
intros. destruct H as [A B]. split; intros.
change (vmatch v (vlub (Ifptr p) (Ifptr q))). apply vmatch_lub_l. eapply A; eauto.
apply pmatch_lub_l. eapply B; eauto.
Qed.
Lemma smatch_lub_r:
forall m b p q, smatch m b q -> smatch m b (plub p q).
Proof. hammer_hook "ValueDomain" "ValueDomain.smatch_lub_r".
intros. destruct H as [A B]. split; intros.
change (vmatch v (vlub (Ifptr p) (Ifptr q))). apply vmatch_lub_r. eapply A; eauto.
apply pmatch_lub_r. eapply B; eauto.
Qed.
Lemma bmatch_lub_l:
forall m b x y, bmatch m b x -> bmatch m b (blub x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.bmatch_lub_l".
intros. destruct H as [BM1 BM2]. split; unfold blub; simpl.
- apply smatch_lub_l; auto.
- intros.
assert (SUMMARY: vmatch v (vnormalize chunk (Ifptr (plub (ab_summary x) (ab_summary y))))
).
{ exploit smatch_lub_l; eauto. instantiate (1 := ab_summary y).
intros [SUMM _]. eapply vnormalize_cast; eauto. }
exploit BM2; eauto.
unfold ablock_load; simpl. rewrite ZTree.gcombine by auto.
unfold combine_acontents;
destruct (ab_contents x)##ofs as [[chunkx avx]|], (ab_contents y)##ofs as [[chunky avy]|]; auto.
destruct (chunk_eq chunkx chunky); auto. subst chunky.
destruct (chunk_compat chunk chunkx); auto.
intros. eapply vmatch_ge; eauto. apply vnormalize_monotone. apply vge_lub_l.
Qed.
Lemma bmatch_lub_r:
forall m b x y, bmatch m b y -> bmatch m b (blub x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.bmatch_lub_r".
intros. destruct H as [BM1 BM2]. split; unfold blub; simpl.
- apply smatch_lub_r; auto.
- intros.
assert (SUMMARY: vmatch v (vnormalize chunk (Ifptr (plub (ab_summary x) (ab_summary y))))
).
{ exploit smatch_lub_r; eauto. instantiate (1 := ab_summary x).
intros [SUMM _]. eapply vnormalize_cast; eauto. }
exploit BM2; eauto.
unfold ablock_load; simpl. rewrite ZTree.gcombine by auto.
unfold combine_acontents;
destruct (ab_contents x)##ofs as [[chunkx avx]|], (ab_contents y)##ofs as [[chunky avy]|]; auto.
destruct (chunk_eq chunkx chunky); auto. subst chunky.
destruct (chunk_compat chunk chunkx); auto.
intros. eapply vmatch_ge; eauto. apply vnormalize_monotone. apply vge_lub_r.
Qed.
Definition romem := PTree.t ablock.
Definition romatch (m: mem) (rm: romem) : Prop :=
forall b id ab,
bc b = BCglob id ->
rm!id = Some ab ->
pge Glob ab.(ab_summary)
/\ bmatch m b ab
/\ forall ofs, ~Mem.perm m b ofs Max Writable.
Lemma romatch_store:
forall chunk m b ofs v m' rm,
Mem.store chunk m b ofs v = Some m' ->
romatch m rm ->
romatch m' rm.
Proof. hammer_hook "ValueDomain" "ValueDomain.romatch_store".
intros; red; intros. exploit H0; eauto. intros (A & B & C). split; auto. split.
- exploit Mem.store_valid_access_3; eauto. intros [P _].
apply bmatch_inv with m; auto.
+ intros. eapply Mem.loadbytes_store_other; eauto.
left. red; intros; subst b0. elim (C ofs). apply Mem.perm_cur_max.
apply P. generalize (size_chunk_pos chunk); omega.
- intros; red; intros; elim (C ofs0). eauto with mem.
Qed.
Lemma romatch_storebytes:
forall m b ofs bytes m' rm,
Mem.storebytes m b ofs bytes = Some m' ->
romatch m rm ->
romatch m' rm.
Proof. hammer_hook "ValueDomain" "ValueDomain.romatch_storebytes".
intros; red; intros. exploit H0; eauto. intros (A & B & C). split; auto. split.
- apply bmatch_inv with m; auto.
intros. eapply Mem.loadbytes_storebytes_disjoint; eauto.
destruct (eq_block b0 b); auto. subst b0. right; red; unfold Intv.In; simpl; red; intros.
elim (C x). apply Mem.perm_cur_max. eapply Mem.storebytes_range_perm; eauto.
- intros; red; intros; elim (C ofs0). eauto with mem.
Qed.
Lemma romatch_ext:
forall m rm m',
romatch m rm ->
(forall b id ofs n bytes, bc b = BCglob id -> Mem.loadbytes m' b ofs n = Some bytes -> Mem.loadbytes m b ofs n = Some bytes) ->
(forall b id ofs p, bc b = BCglob id -> Mem.perm m' b ofs Max p -> Mem.perm m b ofs Max p) ->
romatch m' rm.
Proof. hammer_hook "ValueDomain" "ValueDomain.romatch_ext".
intros; red; intros. exploit H; eauto. intros (A & B & C).
split. auto.
split. apply bmatch_ext with m; auto. intros. eapply H0; eauto.
intros; red; intros. elim (C ofs). eapply H1; eauto.
Qed.
Lemma romatch_free:
forall m b lo hi m' rm,
Mem.free m b lo hi = Some m' ->
romatch m rm ->
romatch m' rm.
Proof. hammer_hook "ValueDomain" "ValueDomain.romatch_free".
intros. apply romatch_ext with m; auto.
intros. eapply Mem.loadbytes_free_2; eauto.
intros. eauto with mem.
Qed.
Lemma romatch_alloc:
forall m b lo hi m' rm,
Mem.alloc m lo hi = (m', b) ->
bc_below bc (Mem.nextblock m) ->
romatch m rm ->
romatch m' rm.
Proof. hammer_hook "ValueDomain" "ValueDomain.romatch_alloc".
intros. apply romatch_ext with m; auto.
intros. rewrite <- H3; symmetry. eapply Mem.loadbytes_alloc_unchanged; eauto.
apply H0. congruence.
intros. eapply Mem.perm_alloc_4; eauto. apply Mem.valid_not_valid_diff with m; eauto with mem.
apply H0. congruence.
Qed.
Record amem : Type := AMem {
am_stack: ablock;
am_glob: PTree.t ablock;
am_nonstack: aptr;
am_top: aptr
}.
Record mmatch (m: mem) (am: amem) : Prop := mk_mem_match {
mmatch_stack: forall b,
bc b = BCstack ->
bmatch m b am.(am_stack);
mmatch_glob: forall id ab b,
bc b = BCglob id ->
am.(am_glob)!id = Some ab ->
bmatch m b ab;
mmatch_nonstack: forall b,
bc b <> BCstack -> bc b <> BCinvalid ->
smatch m b am.(am_nonstack);
mmatch_top: forall b,
bc b <> BCinvalid ->
smatch m b am.(am_top);
mmatch_below:
bc_below bc (Mem.nextblock m)
}.
Definition minit (p: aptr) :=
{| am_stack := ablock_init p;
am_glob := PTree.empty _;
am_nonstack := p;
am_top := p |}.
Definition mbot := minit Pbot.
Definition mtop := minit Ptop.
Definition load (chunk: memory_chunk) (rm: romem) (m: amem) (p: aptr) : aval :=
match p with
| Pbot => if va_strict tt then Vbot else Vtop
| Gl id ofs =>
match rm!id with
| Some ab => ablock_load chunk ab (Ptrofs.unsigned ofs)
| None =>
match m.(am_glob)!id with
| Some ab => ablock_load chunk ab (Ptrofs.unsigned ofs)
| None => vnormalize chunk (Ifptr m.(am_nonstack))
end
end
| Glo id =>
match rm!id with
| Some ab => ablock_load_anywhere chunk ab
| None =>
match m.(am_glob)!id with
| Some ab => ablock_load_anywhere chunk ab
| None => vnormalize chunk (Ifptr m.(am_nonstack))
end
end
| Stk ofs => ablock_load chunk m.(am_stack) (Ptrofs.unsigned ofs)
| Stack => ablock_load_anywhere chunk m.(am_stack)
| Glob | Nonstack => vnormalize chunk (Ifptr m.(am_nonstack))
| Ptop => vnormalize chunk (Ifptr m.(am_top))
end.
Definition loadv (chunk: memory_chunk) (rm: romem) (m: amem) (addr: aval) : aval :=
load chunk rm m (aptr_of_aval addr).
Definition store (chunk: memory_chunk) (m: amem) (p: aptr) (av: aval) : amem :=
{| am_stack :=
match p with
| Stk ofs => ablock_store chunk m.(am_stack) (Ptrofs.unsigned ofs) av
| Stack | Ptop => ablock_store_anywhere chunk m.(am_stack) av
| _ => m.(am_stack)
end;
am_glob :=
match p with
| Gl id ofs =>
let ab := match m.(am_glob)!id with Some ab => ab | None => ablock_init m.(am_nonstack) end in
PTree.set id (ablock_store chunk ab (Ptrofs.unsigned ofs) av) m.(am_glob)
| Glo id =>
let ab := match m.(am_glob)!id with Some ab => ab | None => ablock_init m.(am_nonstack) end in
PTree.set id (ablock_store_anywhere chunk ab av) m.(am_glob)
| Glob | Nonstack | Ptop => PTree.empty _
| _ => m.(am_glob)
end;
am_nonstack :=
match p with
| Gl _ _ | Glo _ | Glob | Nonstack | Ptop => vplub av m.(am_nonstack)
| _ => m.(am_nonstack)
end;
am_top := vplub av m.(am_top)
|}.
Definition storev (chunk: memory_chunk) (m: amem) (addr: aval) (v: aval): amem :=
store chunk m (aptr_of_aval addr) v.
Definition loadbytes (m: amem) (rm: romem) (p: aptr) : aptr :=
match p with
| Pbot => if va_strict tt then Pbot else Ptop
| Gl id _ | Glo id =>
match rm!id with
| Some ab => ablock_loadbytes ab
| None =>
match m.(am_glob)!id with
| Some ab => ablock_loadbytes ab
| None => m.(am_nonstack)
end
end
| Stk _ | Stack => ablock_loadbytes m.(am_stack)
| Glob | Nonstack => m.(am_nonstack)
| Ptop => m.(am_top)
end.
Definition storebytes (m: amem) (dst: aptr) (sz: Z) (p: aptr) : amem :=
{| am_stack :=
match dst with
| Stk ofs => ablock_storebytes m.(am_stack) p (Ptrofs.unsigned ofs) sz
| Stack | Ptop => ablock_storebytes_anywhere m.(am_stack) p
| _ => m.(am_stack)
end;
am_glob :=
match dst with
| Gl id ofs =>
let ab := match m.(am_glob)!id with Some ab => ab | None => ablock_init m.(am_nonstack) end in
PTree.set id (ablock_storebytes ab p (Ptrofs.unsigned ofs) sz) m.(am_glob)
| Glo id =>
let ab := match m.(am_glob)!id with Some ab => ab | None => ablock_init m.(am_nonstack) end in
PTree.set id (ablock_storebytes_anywhere ab p) m.(am_glob)
| Glob | Nonstack | Ptop => PTree.empty _
| _ => m.(am_glob)
end;
am_nonstack :=
match dst with
| Gl _ _ | Glo _ | Glob | Nonstack | Ptop => plub p m.(am_nonstack)
| _ => m.(am_nonstack)
end;
am_top := plub p m.(am_top)
|}.
Theorem load_sound:
forall chunk m b ofs v rm am p,
Mem.load chunk m b (Ptrofs.unsigned ofs) = Some v ->
romatch m rm ->
mmatch m am ->
pmatch b ofs p ->
vmatch v (load chunk rm am p).
Proof. hammer_hook "ValueDomain" "ValueDomain.load_sound".
intros. unfold load. inv H2.
-
destruct (rm!id) as [ab|] eqn:RM.
eapply ablock_load_sound; eauto. eapply H0; eauto.
destruct (am_glob am)!id as [ab|] eqn:AM.
eapply ablock_load_sound; eauto. eapply mmatch_glob; eauto.
eapply vnormalize_cast; eauto. eapply mmatch_nonstack; eauto; congruence.
-
destruct (rm!id) as [ab|] eqn:RM.
eapply ablock_load_anywhere_sound; eauto. eapply H0; eauto.
destruct (am_glob am)!id as [ab|] eqn:AM.
eapply ablock_load_anywhere_sound; eauto. eapply mmatch_glob; eauto.
eapply vnormalize_cast; eauto. eapply mmatch_nonstack; eauto; congruence.
-
eapply vnormalize_cast; eauto. eapply mmatch_nonstack; eauto. congruence. congruence.
-
eapply ablock_load_sound; eauto. eapply mmatch_stack; eauto.
-
eapply ablock_load_anywhere_sound; eauto. eapply mmatch_stack; eauto.
-
eapply vnormalize_cast; eauto. eapply mmatch_nonstack; eauto.
-
eapply vnormalize_cast; eauto. eapply mmatch_top; eauto.
Qed.
Theorem loadv_sound:
forall chunk m addr v rm am aaddr,
Mem.loadv chunk m addr = Some v ->
romatch m rm ->
mmatch m am ->
vmatch addr aaddr ->
vmatch v (loadv chunk rm am aaddr).
Proof. hammer_hook "ValueDomain" "ValueDomain.loadv_sound".
intros. destruct addr; simpl in H; try discriminate.
eapply load_sound; eauto. apply match_aptr_of_aval; auto.
Qed.
Theorem store_sound:
forall chunk m b ofs v m' am p av,
Mem.store chunk m b (Ptrofs.unsigned ofs) v = Some m' ->
mmatch m am ->
pmatch b ofs p ->
vmatch v av ->
mmatch m' (store chunk am p av).
Proof. hammer_hook "ValueDomain" "ValueDomain.store_sound".
intros until av; intros STORE MM PM VM.
unfold store; constructor; simpl; intros.
-
assert (DFL: bc b <> BCstack -> bmatch m' b0 (am_stack am)).
{ intros. apply bmatch_inv with m. eapply mmatch_stack; eauto.
intros. eapply Mem.loadbytes_store_other; eauto. left; congruence. }
inv PM; try (apply DFL; congruence).
+ assert (b0 = b) by (eapply bc_stack; eauto). subst b0.
eapply ablock_store_sound; eauto. eapply mmatch_stack; eauto.
+ assert (b0 = b) by (eapply bc_stack; eauto). subst b0.
eapply ablock_store_anywhere_sound; eauto. eapply mmatch_stack; eauto.
+ eapply ablock_store_anywhere_sound; eauto. eapply mmatch_stack; eauto.
-
rename b0 into b'.
assert (DFL: bc b <> BCglob id -> (am_glob am)!id = Some ab ->
bmatch m' b' ab).
{ intros. apply bmatch_inv with m. eapply mmatch_glob; eauto.
intros. eapply Mem.loadbytes_store_other; eauto. left; congruence. }
inv PM.
+ rewrite PTree.gsspec in H0. destruct (peq id id0).
subst id0; inv H0.
assert (b' = b) by (eapply bc_glob; eauto). subst b'.
eapply ablock_store_sound; eauto.
destruct (am_glob am)!id as [ab0|] eqn:GL.
eapply mmatch_glob; eauto.
apply ablock_init_sound. eapply mmatch_nonstack; eauto; congruence.
eapply DFL; eauto. congruence.
+ rewrite PTree.gsspec in H0. destruct (peq id id0).
subst id0; inv H0.
assert (b' = b) by (eapply bc_glob; eauto). subst b'.
eapply ablock_store_anywhere_sound; eauto.
destruct (am_glob am)!id as [ab0|] eqn:GL.
eapply mmatch_glob; eauto.
apply ablock_init_sound. eapply mmatch_nonstack; eauto; congruence.
eapply DFL; eauto. congruence.
+ rewrite PTree.gempty in H0; congruence.
+ eapply DFL; eauto. congruence.
+ eapply DFL; eauto. congruence.
+ rewrite PTree.gempty in H0; congruence.
+ rewrite PTree.gempty in H0; congruence.
-
assert (DFL: smatch m' b0 (vplub av (am_nonstack am))).
{ eapply smatch_store; eauto. eapply mmatch_nonstack; eauto. }
assert (STK: bc b = BCstack -> smatch m' b0 (am_nonstack am)).
{ intros. apply smatch_inv with m. eapply mmatch_nonstack; eauto; congruence.
intros. eapply Mem.loadbytes_store_other; eauto. left. congruence.
}
inv PM; (apply DFL || apply STK; congruence).
-
eapply smatch_store; eauto. eapply mmatch_top; eauto.
-
erewrite Mem.nextblock_store by eauto. eapply mmatch_below; eauto.
Qed.
Theorem storev_sound:
forall chunk m addr v m' am aaddr av,
Mem.storev chunk m addr v = Some m' ->
mmatch m am ->
vmatch addr aaddr ->
vmatch v av ->
mmatch m' (storev chunk am aaddr av).
Proof. hammer_hook "ValueDomain" "ValueDomain.storev_sound".
intros. destruct addr; simpl in H; try discriminate.
eapply store_sound; eauto. apply match_aptr_of_aval; auto.
Qed.
Theorem loadbytes_sound:
forall m b ofs sz bytes am rm p,
Mem.loadbytes m b (Ptrofs.unsigned ofs) sz = Some bytes ->
romatch m rm ->
mmatch m am ->
pmatch b ofs p ->
forall b' ofs' q i, In (Fragment (Vptr b' ofs') q i) bytes -> pmatch b' ofs' (loadbytes am rm p).
Proof. hammer_hook "ValueDomain" "ValueDomain.loadbytes_sound".
intros. unfold loadbytes; inv H2.
-
destruct (rm!id) as [ab|] eqn:RM.
exploit H0; eauto. intros (A & B & C). eapply ablock_loadbytes_sound; eauto.
destruct (am_glob am)!id as [ab|] eqn:GL.
eapply ablock_loadbytes_sound; eauto. eapply mmatch_glob; eauto.
eapply smatch_loadbytes; eauto. eapply mmatch_nonstack; eauto with va.
-
destruct (rm!id) as [ab|] eqn:RM.
exploit H0; eauto. intros (A & B & C). eapply ablock_loadbytes_sound; eauto.
destruct (am_glob am)!id as [ab|] eqn:GL.
eapply ablock_loadbytes_sound; eauto. eapply mmatch_glob; eauto.
eapply smatch_loadbytes; eauto. eapply mmatch_nonstack; eauto with va.
-
eapply smatch_loadbytes; eauto. eapply mmatch_nonstack; eauto with va.
-
eapply ablock_loadbytes_sound; eauto. eapply mmatch_stack; eauto.
-
eapply ablock_loadbytes_sound; eauto. eapply mmatch_stack; eauto.
-
eapply smatch_loadbytes; eauto. eapply mmatch_nonstack; eauto with va.
-
eapply smatch_loadbytes; eauto. eapply mmatch_top; eauto with va.
Qed.
Theorem storebytes_sound:
forall m b ofs bytes m' am p sz q,
Mem.storebytes m b (Ptrofs.unsigned ofs) bytes = Some m' ->
mmatch m am ->
pmatch b ofs p ->
length bytes = Z.to_nat sz ->
(forall b' ofs' qt i, In (Fragment (Vptr b' ofs') qt i) bytes -> pmatch b' ofs' q) ->
mmatch m' (storebytes am p sz q).
Proof. hammer_hook "ValueDomain" "ValueDomain.storebytes_sound".
intros until q; intros STORE MM PM LENGTH BYTES.
unfold storebytes; constructor; simpl; intros.
-
assert (DFL: bc b <> BCstack -> bmatch m' b0 (am_stack am)).
{ intros. apply bmatch_inv with m. eapply mmatch_stack; eauto.
intros. eapply Mem.loadbytes_storebytes_other; eauto. left; congruence. }
inv PM; try (apply DFL; congruence).
+ assert (b0 = b) by (eapply bc_stack; eauto). subst b0.
eapply ablock_storebytes_sound; eauto. eapply mmatch_stack; eauto.
+ assert (b0 = b) by (eapply bc_stack; eauto). subst b0.
eapply ablock_storebytes_anywhere_sound; eauto. eapply mmatch_stack; eauto.
+ eapply ablock_storebytes_anywhere_sound; eauto. eapply mmatch_stack; eauto.
-
rename b0 into b'.
assert (DFL: bc b <> BCglob id -> (am_glob am)!id = Some ab ->
bmatch m' b' ab).
{ intros. apply bmatch_inv with m. eapply mmatch_glob; eauto.
intros. eapply Mem.loadbytes_storebytes_other; eauto. left; congruence. }
inv PM.
+ rewrite PTree.gsspec in H0. destruct (peq id id0).
subst id0; inv H0.
assert (b' = b) by (eapply bc_glob; eauto). subst b'.
eapply ablock_storebytes_sound; eauto.
destruct (am_glob am)!id as [ab0|] eqn:GL.
eapply mmatch_glob; eauto.
apply ablock_init_sound. eapply mmatch_nonstack; eauto; congruence.
eapply DFL; eauto. congruence.
+ rewrite PTree.gsspec in H0. destruct (peq id id0).
subst id0; inv H0.
assert (b' = b) by (eapply bc_glob; eauto). subst b'.
eapply ablock_storebytes_anywhere_sound; eauto.
destruct (am_glob am)!id as [ab0|] eqn:GL.
eapply mmatch_glob; eauto.
apply ablock_init_sound. eapply mmatch_nonstack; eauto; congruence.
eapply DFL; eauto. congruence.
+ rewrite PTree.gempty in H0; congruence.
+ eapply DFL; eauto. congruence.
+ eapply DFL; eauto. congruence.
+ rewrite PTree.gempty in H0; congruence.
+ rewrite PTree.gempty in H0; congruence.
-
assert (DFL: smatch m' b0 (plub q (am_nonstack am))).
{ eapply smatch_storebytes; eauto. eapply mmatch_nonstack; eauto. }
assert (STK: bc b = BCstack -> smatch m' b0 (am_nonstack am)).
{ intros. apply smatch_inv with m. eapply mmatch_nonstack; eauto; congruence.
intros. eapply Mem.loadbytes_storebytes_other; eauto. left. congruence.
}
inv PM; (apply DFL || apply STK; congruence).
-
eapply smatch_storebytes; eauto. eapply mmatch_top; eauto.
-
erewrite Mem.nextblock_storebytes by eauto. eapply mmatch_below; eauto.
Qed.
Lemma mmatch_ext:
forall m am m',
mmatch m am ->
(forall b ofs n bytes, bc b <> BCinvalid -> n >= 0 -> Mem.loadbytes m' b ofs n = Some bytes -> Mem.loadbytes m b ofs n = Some bytes) ->
Ple (Mem.nextblock m) (Mem.nextblock m') ->
mmatch m' am.
Proof. hammer_hook "ValueDomain" "ValueDomain.mmatch_ext".
intros. inv H. constructor; intros.
- apply bmatch_ext with m; auto with va.
- apply bmatch_ext with m; eauto with va.
- apply smatch_ext with m; auto with va.
- apply smatch_ext with m; auto with va.
- red; intros. exploit mmatch_below0; eauto. xomega.
Qed.
Lemma mmatch_free:
forall m b lo hi m' am,
Mem.free m b lo hi = Some m' ->
mmatch m am ->
mmatch m' am.
Proof. hammer_hook "ValueDomain" "ValueDomain.mmatch_free".
intros. apply mmatch_ext with m; auto.
intros. eapply Mem.loadbytes_free_2; eauto.
erewrite <- Mem.nextblock_free by eauto. xomega.
Qed.
Lemma mmatch_top':
forall m am, mmatch m am -> mmatch m mtop.
Proof. hammer_hook "ValueDomain" "ValueDomain.mmatch_top'".
intros. constructor; simpl; intros.
- apply ablock_init_sound. apply smatch_ge with (ab_summary (am_stack am)).
eapply mmatch_stack; eauto. constructor.
- rewrite PTree.gempty in H1; discriminate.
- eapply smatch_ge. eapply mmatch_nonstack; eauto. constructor.
- eapply smatch_ge. eapply mmatch_top; eauto. constructor.
- eapply mmatch_below; eauto.
Qed.
Definition mbeq (m1 m2: amem) : bool :=
eq_aptr m1.(am_top) m2.(am_top)
&& eq_aptr m1.(am_nonstack) m2.(am_nonstack)
&& bbeq m1.(am_stack) m2.(am_stack)
&& PTree.beq bbeq m1.(am_glob) m2.(am_glob).
Lemma mbeq_sound:
forall m1 m2, mbeq m1 m2 = true -> forall m, mmatch m m1 <-> mmatch m m2.
Proof. hammer_hook "ValueDomain" "ValueDomain.mbeq_sound".
unfold mbeq; intros. InvBooleans. rewrite PTree.beq_correct in H1.
split; intros M; inv M; constructor; intros.
- erewrite <- bbeq_sound; eauto.
- specialize (H1 id). rewrite H4 in H1. destruct (am_glob m1)!id eqn:G; try contradiction.
erewrite <- bbeq_sound; eauto.
- rewrite <- H; eauto.
- rewrite <- H0; eauto.
- auto.
- erewrite bbeq_sound; eauto.
- specialize (H1 id). rewrite H4 in H1. destruct (am_glob m2)!id eqn:G; try contradiction.
erewrite bbeq_sound; eauto.
- rewrite H; eauto.
- rewrite H0; eauto.
- auto.
Qed.
Definition combine_ablock (ob1 ob2: option ablock) : option ablock :=
match ob1, ob2 with
| Some b1, Some b2 => Some (blub b1 b2)
| _, _ => None
end.
Definition mlub (m1 m2: amem) : amem :=
{| am_stack := blub m1.(am_stack) m2.(am_stack);
am_glob := PTree.combine combine_ablock m1.(am_glob) m2.(am_glob);
am_nonstack := plub m1.(am_nonstack) m2.(am_nonstack);
am_top := plub m1.(am_top) m2.(am_top) |}.
Lemma mmatch_lub_l:
forall m x y, mmatch m x -> mmatch m (mlub x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.mmatch_lub_l".
intros. inv H. constructor; simpl; intros.
- apply bmatch_lub_l; auto.
- rewrite PTree.gcombine in H0 by auto. unfold combine_ablock in H0.
destruct (am_glob x)!id as [b1|] eqn:G1;
destruct (am_glob y)!id as [b2|] eqn:G2;
inv H0.
apply bmatch_lub_l; eauto.
- apply smatch_lub_l; auto.
- apply smatch_lub_l; auto.
- auto.
Qed.
Lemma mmatch_lub_r:
forall m x y, mmatch m y -> mmatch m (mlub x y).
Proof. hammer_hook "ValueDomain" "ValueDomain.mmatch_lub_r".
intros. inv H. constructor; simpl; intros.
- apply bmatch_lub_r; auto.
- rewrite PTree.gcombine in H0 by auto. unfold combine_ablock in H0.
destruct (am_glob x)!id as [b1|] eqn:G1;
destruct (am_glob y)!id as [b2|] eqn:G2;
inv H0.
apply bmatch_lub_r; eauto.
- apply smatch_lub_r; auto.
- apply smatch_lub_r; auto.
- auto.
Qed.
End MATCH.
Lemma genv_match_exten:
forall ge (bc1 bc2: block_classification),
genv_match bc1 ge ->
(forall b id, bc1 b = BCglob id <-> bc2 b = BCglob id) ->
(forall b, bc1 b = BCother -> bc2 b = BCother) ->
genv_match bc2 ge.
Proof. hammer_hook "ValueDomain" "ValueDomain.genv_match_exten".
intros. destruct H as [A B]. split; intros.
- rewrite <- H0. eauto.
- exploit B; eauto. destruct (bc1 b) eqn:BC1.
+ intuition congruence.
+ rewrite H0 in BC1. intuition congruence.
+ intuition congruence.
+ erewrite H1 by eauto. intuition congruence.
Qed.
Lemma romatch_exten:
forall (bc1 bc2: block_classification) m rm,
romatch bc1 m rm ->
(forall b id, bc2 b = BCglob id <-> bc1 b = BCglob id) ->
romatch bc2 m rm.
Proof. hammer_hook "ValueDomain" "ValueDomain.romatch_exten".
intros; red; intros. rewrite H0 in H1. exploit H; eauto. intros (A & B & C).
split; auto. split; auto.
assert (PM: forall b ofs p, pmatch bc1 b ofs p -> pmatch bc1 b ofs (ab_summary ab) -> pmatch bc2 b ofs p).
{
intros.
assert (pmatch bc1 b0 ofs Glob) by (eapply pmatch_ge; eauto).
inv H5.
assert (bc2 b0 = BCglob id0) by (rewrite H0; auto).
inv H3; econstructor; eauto with va.
}
assert (VM: forall v x, vmatch bc1 v x -> vmatch bc1 v (Ifptr (ab_summary ab)) -> vmatch bc2 v x).
{
intros. inv H3; constructor; auto; inv H4; eapply PM; eauto.
}
destruct B as [[B1 B2] B3]. split. split.
- intros. apply VM; eauto.
- intros. apply PM; eauto.
- intros. apply VM; eauto.
Qed.
Definition bc_incr (bc1 bc2: block_classification) : Prop :=
forall b, bc1 b <> BCinvalid -> bc2 b = bc1 b.
Section MATCH_INCR.
Variables bc1 bc2: block_classification.
Hypothesis INCR: bc_incr bc1 bc2.
Lemma pmatch_incr: forall b ofs p, pmatch bc1 b ofs p -> pmatch bc2 b ofs p.
Proof. hammer_hook "ValueDomain" "ValueDomain.pmatch_incr".
induction 1;
assert (bc2 b = bc1 b) by (apply INCR; congruence);
econstructor; eauto with va. rewrite H0; eauto.
Qed.
Lemma vmatch_incr: forall v x, vmatch bc1 v x -> vmatch bc2 v x.
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_incr".
induction 1; constructor; auto; apply pmatch_incr; auto.
Qed.
Lemma smatch_incr: forall m b p, smatch bc1 m b p -> smatch bc2 m b p.
Proof. hammer_hook "ValueDomain" "ValueDomain.smatch_incr".
intros. destruct H as [A B]. split; intros.
apply vmatch_incr; eauto.
apply pmatch_incr; eauto.
Qed.
Lemma bmatch_incr: forall m b ab, bmatch bc1 m b ab -> bmatch bc2 m b ab.
Proof. hammer_hook "ValueDomain" "ValueDomain.bmatch_incr".
intros. destruct H as [B1 B2]. split.
apply smatch_incr; auto.
intros. apply vmatch_incr; eauto.
Qed.
End MATCH_INCR.
Definition inj_of_bc (bc: block_classification) : meminj :=
fun b => match bc b with BCinvalid => None | _ => Some(b, 0) end.
Lemma inj_of_bc_valid:
forall (bc: block_classification) b, bc b <> BCinvalid -> inj_of_bc bc b = Some(b, 0).
Proof. hammer_hook "ValueDomain" "ValueDomain.inj_of_bc_valid".
intros. unfold inj_of_bc. destruct (bc b); congruence.
Qed.
Lemma inj_of_bc_inv:
forall (bc: block_classification) b b' delta,
inj_of_bc bc b = Some(b', delta) -> bc b <> BCinvalid /\ b' = b /\ delta = 0.
Proof. hammer_hook "ValueDomain" "ValueDomain.inj_of_bc_inv".
unfold inj_of_bc; intros. destruct (bc b); intuition congruence.
Qed.
Lemma pmatch_inj:
forall bc b ofs p, pmatch bc b ofs p -> inj_of_bc bc b = Some(b, 0).
Proof. hammer_hook "ValueDomain" "ValueDomain.pmatch_inj".
intros. apply inj_of_bc_valid. inv H; congruence.
Qed.
Lemma vmatch_inj:
forall bc v x, vmatch bc v x -> Val.inject (inj_of_bc bc) v v.
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_inj".
induction 1; econstructor.
eapply pmatch_inj; eauto. rewrite Ptrofs.add_zero; auto.
eapply pmatch_inj; eauto. rewrite Ptrofs.add_zero; auto.
Qed.
Lemma vmatch_list_inj:
forall bc vl xl, list_forall2 (vmatch bc) vl xl -> Val.inject_list (inj_of_bc bc) vl vl.
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_list_inj".
induction 1; constructor. eapply vmatch_inj; eauto. auto.
Qed.
Lemma mmatch_inj:
forall bc m am, mmatch bc m am -> bc_below bc (Mem.nextblock m) -> Mem.inject (inj_of_bc bc) m m.
Proof. hammer_hook "ValueDomain" "ValueDomain.mmatch_inj".
intros. constructor. constructor.
-
intros. exploit inj_of_bc_inv; eauto. intros (A & B & C); subst.
rewrite Z.add_0_r. auto.
-
intros. exploit inj_of_bc_inv; eauto. intros (A & B & C); subst.
apply Z.divide_0_r.
-
intros. exploit inj_of_bc_inv; eauto. intros (A & B & C); subst.
rewrite Z.add_0_r.
set (mv := ZMap.get ofs (PMap.get b1 (Mem.mem_contents m))).
assert (Mem.loadbytes m b1 ofs 1 = Some (mv :: nil)).
{
Local Transparent Mem.loadbytes.
unfold Mem.loadbytes. rewrite pred_dec_true. reflexivity.
red; intros. replace ofs0 with ofs by omega. auto.
}
destruct mv; econstructor. destruct v; econstructor.
apply inj_of_bc_valid.
assert (PM: pmatch bc b i Ptop).
{ exploit mmatch_top; eauto. intros [P Q].
eapply pmatch_top'. eapply Q; eauto. }
inv PM; auto.
rewrite Ptrofs.add_zero; auto.
-
intros. unfold inj_of_bc. erewrite bc_below_invalid; eauto.
-
intros. exploit inj_of_bc_inv; eauto. intros (A & B & C); subst.
apply H0; auto.
-
red; intros.
exploit inj_of_bc_inv. eexact H2. intros (A1 & B & C); subst.
exploit inj_of_bc_inv. eexact H3. intros (A2 & B & C); subst.
auto.
-
intros. exploit inj_of_bc_inv; eauto. intros (A & B & C); subst.
rewrite Z.add_0_r. split. omega. apply Ptrofs.unsigned_range_2.
-
intros. exploit inj_of_bc_inv; eauto. intros (A & B & C); subst.
rewrite Z.add_0_r in H2. auto.
Qed.
Lemma inj_of_bc_preserves_globals:
forall bc ge, genv_match bc ge -> meminj_preserves_globals ge (inj_of_bc bc).
Proof. hammer_hook "ValueDomain" "ValueDomain.inj_of_bc_preserves_globals".
intros. destruct H as [A B].
split. intros. apply inj_of_bc_valid. rewrite A in H. congruence.
split. intros. apply inj_of_bc_valid. apply B.
rewrite Genv.find_var_info_iff in H. eapply Genv.genv_defs_range; eauto.
intros. exploit inj_of_bc_inv; eauto. intros (P & Q & R). auto.
Qed.
Lemma pmatch_inj_top:
forall bc b b' delta ofs, inj_of_bc bc b = Some(b', delta) -> pmatch bc b ofs Ptop.
Proof. hammer_hook "ValueDomain" "ValueDomain.pmatch_inj_top".
intros. exploit inj_of_bc_inv; eauto. intros (A & B & C). constructor; auto.
Qed.
Lemma vmatch_inj_top:
forall bc v v', Val.inject (inj_of_bc bc) v v' -> vmatch bc v Vtop.
Proof. hammer_hook "ValueDomain" "ValueDomain.vmatch_inj_top".
intros. inv H; constructor. eapply pmatch_inj_top; eauto.
Qed.
Lemma mmatch_inj_top:
forall bc m m', Mem.inject (inj_of_bc bc) m m' -> mmatch bc m mtop.
Proof. hammer_hook "ValueDomain" "ValueDomain.mmatch_inj_top".
intros.
assert (SM: forall b, bc b <> BCinvalid -> smatch bc m b Ptop).
{
intros; split; intros.
- exploit Mem.load_inject. eauto. eauto. apply inj_of_bc_valid; auto.
intros (v' & A & B). eapply vmatch_inj_top; eauto.
- exploit Mem.loadbytes_inject. eauto. eauto. apply inj_of_bc_valid; auto.
intros (bytes' & A & B). inv B. inv H4. inv H8. eapply pmatch_inj_top; eauto.
}
constructor; simpl; intros.
- apply ablock_init_sound. apply SM. congruence.
- rewrite PTree.gempty in H1; discriminate.
- apply SM; auto.
- apply SM; auto.
- red; intros. eapply Mem.valid_block_inject_1. eapply inj_of_bc_valid; eauto. eauto.
Qed.
Module AVal <: SEMILATTICE_WITH_TOP.
Definition t := aval.
Definition eq (x y: t) := (x = y).
Definition eq_refl: forall x, eq x x := (@eq_refl t).
Definition eq_sym: forall x y, eq x y -> eq y x := (@eq_sym t).
Definition eq_trans: forall x y z, eq x y -> eq y z -> eq x z := (@eq_trans t).
Definition beq (x y: t) : bool := proj_sumbool (eq_aval x y).
Lemma beq_correct: forall x y, beq x y = true -> eq x y.
Proof. hammer_hook "ValueDomain" "ValueDomain.AVal.beq_correct". unfold beq; intros. InvBooleans. auto. Qed.
Definition ge := vge.
Lemma ge_refl: forall x y, eq x y -> ge x y.
Proof. hammer_hook "ValueDomain" "ValueDomain.AVal.ge_refl". unfold eq, ge; intros. subst y. apply vge_refl. Qed.
Lemma ge_trans: forall x y z, ge x y -> ge y z -> ge x z.
Proof. hammer_hook "ValueDomain" "ValueDomain.AVal.ge_trans". unfold ge; intros. eapply vge_trans; eauto. Qed.
Definition bot : t := Vbot.
Lemma ge_bot: forall x, ge x bot.
Proof. hammer_hook "ValueDomain" "ValueDomain.AVal.ge_bot". intros. constructor. Qed.
Definition top : t := Vtop.
Lemma ge_top: forall x, ge top x.
Proof. hammer_hook "ValueDomain" "ValueDomain.AVal.ge_top". intros. apply vge_top. Qed.
Definition lub := vlub.
Lemma ge_lub_left: forall x y, ge (lub x y) x.
Proof. hammer_hook "ValueDomain" "ValueDomain.AVal.ge_lub_left". exact (vge_lub_l). Qed.
Lemma ge_lub_right: forall x y, ge (lub x y) y.
Proof. hammer_hook "ValueDomain" "ValueDomain.AVal.ge_lub_right". exact (vge_lub_r). Qed.
End AVal.
Module AE := LPMap(AVal).
Definition aenv := AE.t.
Section MATCHENV.
Variable bc: block_classification.
Definition ematch (e: regset) (ae: aenv) : Prop :=
forall r, vmatch bc e#r (AE.get r ae).
Lemma ematch_ge:
forall e ae1 ae2,
ematch e ae1 -> AE.ge ae2 ae1 -> ematch e ae2.
Proof. hammer_hook "ValueDomain" "ValueDomain.ematch_ge".
intros; red; intros. apply vmatch_ge with (AE.get r ae1); auto. apply H0.
Qed.
Lemma ematch_update:
forall e ae v av r,
ematch e ae -> vmatch bc v av -> ematch (e#r <- v) (AE.set r av ae).
Proof. hammer_hook "ValueDomain" "ValueDomain.ematch_update".
intros; red; intros. rewrite AE.gsspec. rewrite PMap.gsspec.
destruct (peq r0 r); auto.
red; intros. specialize (H xH). subst ae. simpl in H. inv H.
unfold AVal.eq; red; intros. subst av. inv H0.
Qed.
Fixpoint einit_regs (rl: list reg) : aenv :=
match rl with
| r1 :: rs => AE.set r1 (Ifptr Nonstack) (einit_regs rs)
| nil => AE.top
end.
Lemma ematch_init:
forall rl vl,
(forall v, In v vl -> vmatch bc v (Ifptr Nonstack)) ->
ematch (init_regs vl rl) (einit_regs rl).
Proof. hammer_hook "ValueDomain" "ValueDomain.ematch_init".
induction rl; simpl; intros.
- red; intros. rewrite Regmap.gi. simpl AE.get. rewrite PTree.gempty.
constructor.
- destruct vl as [ | v1 vs ].
+ assert (ematch (init_regs nil rl) (einit_regs rl)).
{ apply IHrl. simpl; tauto. }
replace (init_regs nil rl) with (Regmap.init Vundef) in H0 by (destruct rl; auto).
red; intros. rewrite AE.gsspec. destruct (peq r a).
rewrite Regmap.gi. constructor.
apply H0.
red; intros EQ; rewrite EQ in H0. specialize (H0 xH). simpl in H0. inv H0.
unfold AVal.eq, AVal.bot. congruence.
+ assert (ematch (init_regs vs rl) (einit_regs rl)).
{ apply IHrl. eauto with coqlib. }
red; intros. rewrite Regmap.gsspec. rewrite AE.gsspec. destruct (peq r a).
auto with coqlib.
apply H0.
red; intros EQ; rewrite EQ in H0. specialize (H0 xH). simpl in H0. inv H0.
unfold AVal.eq, AVal.bot. congruence.
Qed.
Fixpoint eforget (rl: list reg) (ae: aenv) {struct rl} : aenv :=
match rl with
| nil => ae
| r1 :: rs => eforget rs (AE.set r1 Vtop ae)
end.
Lemma eforget_ge:
forall rl ae, AE.ge (eforget rl ae) ae.
Proof. hammer_hook "ValueDomain" "ValueDomain.eforget_ge".
unfold AE.ge; intros. revert rl ae; induction rl; intros; simpl.
apply AVal.ge_refl. apply AVal.eq_refl.
destruct ae. unfold AE.get at 2. apply AVal.ge_bot.
eapply AVal.ge_trans. apply IHrl. rewrite AE.gsspec.
destruct (peq p a). apply AVal.ge_top. apply AVal.ge_refl. apply AVal.eq_refl.
congruence.
unfold AVal.eq, Vtop, AVal.bot. congruence.
Qed.
Lemma ematch_forget:
forall e rl ae, ematch e ae -> ematch e (eforget rl ae).
Proof. hammer_hook "ValueDomain" "ValueDomain.ematch_forget".
intros. eapply ematch_ge; eauto. apply eforget_ge.
Qed.
End MATCHENV.
Lemma ematch_incr:
forall bc bc' e ae, ematch bc e ae -> bc_incr bc bc' -> ematch bc' e ae.
Proof. hammer_hook "ValueDomain" "ValueDomain.ematch_incr".
intros; red; intros. apply vmatch_incr with bc; auto.
Qed.
Module VA <: SEMILATTICE.
Inductive t' := Bot | State (ae: aenv) (am: amem).
Definition t := t'.
Definition eq (x y: t) :=
match x, y with
| Bot, Bot => True
| State ae1 am1, State ae2 am2 =>
AE.eq ae1 ae2 /\ forall bc m, mmatch bc m am1 <-> mmatch bc m am2
| _, _ => False
end.
Lemma eq_refl: forall x, eq x x.
Proof. hammer_hook "ValueDomain" "ValueDomain.AVal.eq_refl".
destruct x; simpl. auto. split. apply AE.eq_refl. tauto.
Qed.
Lemma eq_sym: forall x y, eq x y -> eq y x.
Proof. hammer_hook "ValueDomain" "ValueDomain.AVal.eq_sym".
destruct x, y; simpl; auto. intros [A B].
split. apply AE.eq_sym; auto. intros. rewrite B. tauto.
Qed.
Lemma eq_trans: forall x y z, eq x y -> eq y z -> eq x z.
Proof. hammer_hook "ValueDomain" "ValueDomain.AVal.eq_trans".
destruct x, y, z; simpl; try tauto. intros [A B] [C D]; split.
eapply AE.eq_trans; eauto.
intros. rewrite B; auto.
Qed.
Definition beq (x y: t) : bool :=
match x, y with
| Bot, Bot => true
| State ae1 am1, State ae2 am2 => AE.beq ae1 ae2 && mbeq am1 am2
| _, _ => false
end.
Lemma beq_correct: forall x y, beq x y = true -> eq x y.
Proof. hammer_hook "ValueDomain" "ValueDomain.VA.beq_correct".
destruct x, y; simpl; intros.
auto.
congruence.
congruence.
InvBooleans; split.
apply AE.beq_correct; auto.
intros. apply mbeq_sound; auto.
Qed.
Definition ge (x y: t) : Prop :=
match x, y with
| _, Bot => True
| Bot, _ => False
| State ae1 am1, State ae2 am2 => AE.ge ae1 ae2 /\ forall bc m, mmatch bc m am2 -> mmatch bc m am1
end.
Lemma ge_refl: forall x y, eq x y -> ge x y.
Proof. hammer_hook "ValueDomain" "ValueDomain.VA.ge_refl".
destruct x, y; simpl; try tauto. intros [A B]; split.
apply AE.ge_refl; auto.
intros. rewrite B; auto.
Qed.
Lemma ge_trans: forall x y z, ge x y -> ge y z -> ge x z.
Proof. hammer_hook "ValueDomain" "ValueDomain.VA.ge_trans".
destruct x, y, z; simpl; try tauto. intros [A B] [C D]; split.
eapply AE.ge_trans; eauto.
eauto.
Qed.
Definition bot : t := Bot.
Lemma ge_bot: forall x, ge x bot.
Proof. hammer_hook "ValueDomain" "ValueDomain.VA.ge_bot".
destruct x; simpl; auto.
Qed.
Definition lub (x y: t) : t :=
match x, y with
| Bot, _ => y
| _, Bot => x
| State ae1 am1, State ae2 am2 => State (AE.lub ae1 ae2) (mlub am1 am2)
end.
Lemma ge_lub_left: forall x y, ge (lub x y) x.
Proof. hammer_hook "ValueDomain" "ValueDomain.VA.ge_lub_left".
destruct x, y.
apply ge_refl; apply eq_refl.
simpl. auto.
apply ge_refl; apply eq_refl.
simpl. split. apply AE.ge_lub_left. intros; apply mmatch_lub_l; auto.
Qed.
Lemma ge_lub_right: forall x y, ge (lub x y) y.
Proof. hammer_hook "ValueDomain" "ValueDomain.VA.ge_lub_right".
destruct x, y.
apply ge_refl; apply eq_refl.
apply ge_refl; apply eq_refl.
simpl. auto.
simpl. split. apply AE.ge_lub_right. intros; apply mmatch_lub_r; auto.
Qed.
End VA.
Hint Constructors cmatch : va.
Hint Constructors pmatch: va.
Hint Constructors vmatch: va.
Hint Resolve cnot_sound symbol_address_sound
shl_sound shru_sound shr_sound
and_sound or_sound xor_sound notint_sound
ror_sound rolm_sound
neg_sound add_sound sub_sound
mul_sound mulhs_sound mulhu_sound
divs_sound divu_sound mods_sound modu_sound shrx_sound
shll_sound shrl_sound shrlu_sound
andl_sound orl_sound xorl_sound notl_sound roll_sound rorl_sound
negl_sound addl_sound subl_sound
mull_sound mullhs_sound mullhu_sound
divls_sound divlu_sound modls_sound modlu_sound shrxl_sound
offset_ptr_sound
negf_sound absf_sound
addf_sound subf_sound mulf_sound divf_sound
negfs_sound absfs_sound
addfs_sound subfs_sound mulfs_sound divfs_sound
zero_ext_sound sign_ext_sound longofint_sound longofintu_sound
zero_ext_l_sound sign_ext_l_sound
singleoffloat_sound floatofsingle_sound
intoffloat_sound intuoffloat_sound floatofint_sound floatofintu_sound
intofsingle_sound intuofsingle_sound singleofint_sound singleofintu_sound
longoffloat_sound longuoffloat_sound floatoflong_sound floatoflongu_sound
longofsingle_sound longuofsingle_sound singleoflong_sound singleoflongu_sound
longofwords_sound loword_sound hiword_sound
cmpu_bool_sound cmp_bool_sound cmplu_bool_sound cmpl_bool_sound
cmpf_bool_sound cmpfs_bool_sound
maskzero_sound : va.
|
The frontier of the intersection of two sets is a subset of the union of the frontiers of the two sets. |
inductive Foo : Bool → Type
| Z : Foo false
| O : Foo false → Foo true
| E : Foo true → Foo false
open Foo
def toNat : {b : Bool} → Foo b → Nat
| _, Z => 0
| _, O n => toNat n + 1
| _, E n => toNat n + 1
example : toNat (E (O Z)) = 2 :=
rfl
example : toNat Z = 0 :=
rfl
example (a : Foo false) : toNat (O a) = toNat a + 1 :=
rfl
example (a : Foo true) : toNat (E a) = toNat a + 1 :=
rfl
|
State Before: M : Type ?u.97023
α : Type ?u.97026
β : Type ?u.97029
G₀ : Type u_2
inst✝⁹ : TopologicalSpace α
inst✝⁸ : GroupWithZero G₀
inst✝⁷ : MulAction G₀ α
inst✝⁶ : ContinuousConstSMul G₀ α
inst✝⁵ : TopologicalSpace β
f : β → α
b : β
c✝ : G₀
s✝ : Set β
E : Type u_1
inst✝⁴ : Zero E
inst✝³ : MulActionWithZero G₀ E
inst✝² : TopologicalSpace E
inst✝¹ : T1Space E
inst✝ : ContinuousConstSMul G₀ E
c : G₀
s : Set E
⊢ closure (c • s) = c • closure s State After: case inl
M : Type ?u.97023
α : Type ?u.97026
β : Type ?u.97029
G₀ : Type u_2
inst✝⁹ : TopologicalSpace α
inst✝⁸ : GroupWithZero G₀
inst✝⁷ : MulAction G₀ α
inst✝⁶ : ContinuousConstSMul G₀ α
inst✝⁵ : TopologicalSpace β
f : β → α
b : β
c : G₀
s✝ : Set β
E : Type u_1
inst✝⁴ : Zero E
inst✝³ : MulActionWithZero G₀ E
inst✝² : TopologicalSpace E
inst✝¹ : T1Space E
inst✝ : ContinuousConstSMul G₀ E
s : Set E
⊢ closure (0 • s) = 0 • closure s
case inr
M : Type ?u.97023
α : Type ?u.97026
β : Type ?u.97029
G₀ : Type u_2
inst✝⁹ : TopologicalSpace α
inst✝⁸ : GroupWithZero G₀
inst✝⁷ : MulAction G₀ α
inst✝⁶ : ContinuousConstSMul G₀ α
inst✝⁵ : TopologicalSpace β
f : β → α
b : β
c✝ : G₀
s✝ : Set β
E : Type u_1
inst✝⁴ : Zero E
inst✝³ : MulActionWithZero G₀ E
inst✝² : TopologicalSpace E
inst✝¹ : T1Space E
inst✝ : ContinuousConstSMul G₀ E
c : G₀
s : Set E
hc : c ≠ 0
⊢ closure (c • s) = c • closure s Tactic: rcases eq_or_ne c 0 with (rfl | hc) State Before: case inl
M : Type ?u.97023
α : Type ?u.97026
β : Type ?u.97029
G₀ : Type u_2
inst✝⁹ : TopologicalSpace α
inst✝⁸ : GroupWithZero G₀
inst✝⁷ : MulAction G₀ α
inst✝⁶ : ContinuousConstSMul G₀ α
inst✝⁵ : TopologicalSpace β
f : β → α
b : β
c : G₀
s✝ : Set β
E : Type u_1
inst✝⁴ : Zero E
inst✝³ : MulActionWithZero G₀ E
inst✝² : TopologicalSpace E
inst✝¹ : T1Space E
inst✝ : ContinuousConstSMul G₀ E
s : Set E
⊢ closure (0 • s) = 0 • closure s State After: case inl.inl
M : Type ?u.97023
α : Type ?u.97026
β : Type ?u.97029
G₀ : Type u_2
inst✝⁹ : TopologicalSpace α
inst✝⁸ : GroupWithZero G₀
inst✝⁷ : MulAction G₀ α
inst✝⁶ : ContinuousConstSMul G₀ α
inst✝⁵ : TopologicalSpace β
f : β → α
b : β
c : G₀
s : Set β
E : Type u_1
inst✝⁴ : Zero E
inst✝³ : MulActionWithZero G₀ E
inst✝² : TopologicalSpace E
inst✝¹ : T1Space E
inst✝ : ContinuousConstSMul G₀ E
⊢ closure (0 • ∅) = 0 • closure ∅
case inl.inr
M : Type ?u.97023
α : Type ?u.97026
β : Type ?u.97029
G₀ : Type u_2
inst✝⁹ : TopologicalSpace α
inst✝⁸ : GroupWithZero G₀
inst✝⁷ : MulAction G₀ α
inst✝⁶ : ContinuousConstSMul G₀ α
inst✝⁵ : TopologicalSpace β
f : β → α
b : β
c : G₀
s✝ : Set β
E : Type u_1
inst✝⁴ : Zero E
inst✝³ : MulActionWithZero G₀ E
inst✝² : TopologicalSpace E
inst✝¹ : T1Space E
inst✝ : ContinuousConstSMul G₀ E
s : Set E
hs : Set.Nonempty s
⊢ closure (0 • s) = 0 • closure s Tactic: rcases eq_empty_or_nonempty s with (rfl | hs) State Before: case inl.inl
M : Type ?u.97023
α : Type ?u.97026
β : Type ?u.97029
G₀ : Type u_2
inst✝⁹ : TopologicalSpace α
inst✝⁸ : GroupWithZero G₀
inst✝⁷ : MulAction G₀ α
inst✝⁶ : ContinuousConstSMul G₀ α
inst✝⁵ : TopologicalSpace β
f : β → α
b : β
c : G₀
s : Set β
E : Type u_1
inst✝⁴ : Zero E
inst✝³ : MulActionWithZero G₀ E
inst✝² : TopologicalSpace E
inst✝¹ : T1Space E
inst✝ : ContinuousConstSMul G₀ E
⊢ closure (0 • ∅) = 0 • closure ∅ State After: no goals Tactic: simp State Before: case inl.inr
M : Type ?u.97023
α : Type ?u.97026
β : Type ?u.97029
G₀ : Type u_2
inst✝⁹ : TopologicalSpace α
inst✝⁸ : GroupWithZero G₀
inst✝⁷ : MulAction G₀ α
inst✝⁶ : ContinuousConstSMul G₀ α
inst✝⁵ : TopologicalSpace β
f : β → α
b : β
c : G₀
s✝ : Set β
E : Type u_1
inst✝⁴ : Zero E
inst✝³ : MulActionWithZero G₀ E
inst✝² : TopologicalSpace E
inst✝¹ : T1Space E
inst✝ : ContinuousConstSMul G₀ E
s : Set E
hs : Set.Nonempty s
⊢ closure (0 • s) = 0 • closure s State After: case inl.inr
M : Type ?u.97023
α : Type ?u.97026
β : Type ?u.97029
G₀ : Type u_2
inst✝⁹ : TopologicalSpace α
inst✝⁸ : GroupWithZero G₀
inst✝⁷ : MulAction G₀ α
inst✝⁶ : ContinuousConstSMul G₀ α
inst✝⁵ : TopologicalSpace β
f : β → α
b : β
c : G₀
s✝ : Set β
E : Type u_1
inst✝⁴ : Zero E
inst✝³ : MulActionWithZero G₀ E
inst✝² : TopologicalSpace E
inst✝¹ : T1Space E
inst✝ : ContinuousConstSMul G₀ E
s : Set E
hs : Set.Nonempty s
⊢ closure 0 = 0 Tactic: rw [zero_smul_set hs, zero_smul_set hs.closure] State Before: case inl.inr
M : Type ?u.97023
α : Type ?u.97026
β : Type ?u.97029
G₀ : Type u_2
inst✝⁹ : TopologicalSpace α
inst✝⁸ : GroupWithZero G₀
inst✝⁷ : MulAction G₀ α
inst✝⁶ : ContinuousConstSMul G₀ α
inst✝⁵ : TopologicalSpace β
f : β → α
b : β
c : G₀
s✝ : Set β
E : Type u_1
inst✝⁴ : Zero E
inst✝³ : MulActionWithZero G₀ E
inst✝² : TopologicalSpace E
inst✝¹ : T1Space E
inst✝ : ContinuousConstSMul G₀ E
s : Set E
hs : Set.Nonempty s
⊢ closure 0 = 0 State After: no goals Tactic: exact closure_singleton State Before: case inr
M : Type ?u.97023
α : Type ?u.97026
β : Type ?u.97029
G₀ : Type u_2
inst✝⁹ : TopologicalSpace α
inst✝⁸ : GroupWithZero G₀
inst✝⁷ : MulAction G₀ α
inst✝⁶ : ContinuousConstSMul G₀ α
inst✝⁵ : TopologicalSpace β
f : β → α
b : β
c✝ : G₀
s✝ : Set β
E : Type u_1
inst✝⁴ : Zero E
inst✝³ : MulActionWithZero G₀ E
inst✝² : TopologicalSpace E
inst✝¹ : T1Space E
inst✝ : ContinuousConstSMul G₀ E
c : G₀
s : Set E
hc : c ≠ 0
⊢ closure (c • s) = c • closure s State After: no goals Tactic: exact ((Homeomorph.smulOfNeZero c hc).image_closure s).symm |
If $f$ and $g$ converge to $a$ and $b$, respectively, then $f \cdot g$ converges to $a \cdot b$. |
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
{-
This file shows that the property of the natural numbers being a homotopy-initial algebra of
the functor (1 + _) is equivalent to fulfilling a closely related inductive elimination principle.
Proofing the latter is trivial, since the typechecker does the work for us.
For details see the paper [Homotopy-initial algebras in type theory](https://arxiv.org/abs/1504.05531)
by Steve Awodey, Nicola Gambino and Kristina Sojakova.
-}
module Cubical.Data.Nat.Algebra where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Path
open import Cubical.Foundations.Isomorphism
hiding (section)
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence
open import Cubical.Reflection.StrictEquiv
open import Cubical.Data.Nat.Base
private
variable
ℓ ℓ' : Level
record NatAlgebra ℓ : Type (ℓ-suc ℓ) where
field
Carrier : Type ℓ
alg-zero : Carrier
alg-suc : Carrier → Carrier
record NatMorphism (A : NatAlgebra ℓ) (B : NatAlgebra ℓ') : Type (ℓ-max ℓ ℓ') where
open NatAlgebra
field
morph : A .Carrier → B .Carrier
comm-zero : morph (A .alg-zero) ≡ B .alg-zero
comm-suc : morph ∘ A .alg-suc ≡ B .alg-suc ∘ morph
record NatFiber (N : NatAlgebra ℓ') ℓ : Type (ℓ-max ℓ' (ℓ-suc ℓ)) where
open NatAlgebra N
field
Fiber : Carrier → Type ℓ
fib-zero : Fiber alg-zero
fib-suc : ∀ {n} → Fiber n → Fiber (alg-suc n)
record NatSection {N : NatAlgebra ℓ'} (F : NatFiber N ℓ) : Type (ℓ-max ℓ' ℓ) where
open NatAlgebra N
open NatFiber F
field
section : ∀ n → Fiber n
sec-comm-zero : section alg-zero ≡ fib-zero
sec-comm-suc : ∀ n → section (alg-suc n) ≡ fib-suc (section n)
isNatHInitial : NatAlgebra ℓ' → (ℓ : Level) → Type (ℓ-max ℓ' (ℓ-suc ℓ))
isNatHInitial N ℓ = (M : NatAlgebra ℓ) → isContr (NatMorphism N M)
isNatInductive : NatAlgebra ℓ' → (ℓ : Level) → Type (ℓ-max ℓ' (ℓ-suc ℓ))
isNatInductive N ℓ = (S : NatFiber N ℓ) → NatSection S
module AlgebraPropositionality {N : NatAlgebra ℓ'} where
open NatAlgebra N
isPropIsNatHInitial : isProp (isNatHInitial N ℓ)
isPropIsNatHInitial = isPropΠ (λ _ → isPropIsContr)
-- under the assumption that some shape is nat-inductive, the type of sections over any fiber
-- is propositional
module SectionProp (ind : isNatInductive N ℓ) {F : NatFiber N ℓ} (S T : NatSection F) where
open NatFiber
open NatSection
ConnectingFiber : NatFiber N ℓ
Fiber ConnectingFiber n = S .section n ≡ T .section n
fib-zero ConnectingFiber = S .sec-comm-zero ∙∙ refl ∙∙ sym (T .sec-comm-zero)
fib-suc ConnectingFiber {n} sntn = S .sec-comm-suc n ∙∙ (λ i → F .fib-suc (sntn i)) ∙∙ sym (T .sec-comm-suc n)
open NatSection (ind ConnectingFiber)
renaming (section to α ; sec-comm-zero to ζ ; sec-comm-suc to σ)
squeezeSquare : ∀{a}{A : Type a}{w x y z : A} (p : w ≡ x) {q : x ≡ y} (r : z ≡ y)
→ (P : w ≡ z) → (sq : P ≡ p ∙∙ q ∙∙ sym r) → I → I → A
squeezeSquare p {q} r P sq i j = transport (sym (PathP≡doubleCompPathʳ p P q r)) sq i j
S≡T : S ≡ T
section (S≡T i) n = α n i
sec-comm-zero (S≡T i) j = squeezeSquare (S .sec-comm-zero) (T .sec-comm-zero) (α alg-zero) ζ j i
sec-comm-suc (S≡T i) n j = squeezeSquare (S .sec-comm-suc n) (T .sec-comm-suc n) (α (alg-suc n)) (σ n) j i
isPropIsNatInductive : isProp (isNatInductive N ℓ)
isPropIsNatInductive a b i F = SectionProp.S≡T a (a F) (b F) i
module AlgebraHInd→HInit {N : NatAlgebra ℓ'} (ind : isNatInductive N ℓ) (M : NatAlgebra ℓ) where
open NatAlgebra
open NatFiber
ConstFiberM : NatFiber N ℓ
Fiber ConstFiberM _ = M .Carrier
fib-zero ConstFiberM = M .alg-zero
fib-suc ConstFiberM = M .alg-suc
morph→section : NatMorphism N M → NatSection ConstFiberM
morph→section x = record { section = morph ; sec-comm-zero = comm-zero ; sec-comm-suc = λ i n → comm-suc n i }
where open NatMorphism x
section→morph : NatSection ConstFiberM → NatMorphism N M
section→morph x = record { morph = section ; comm-zero = sec-comm-zero ; comm-suc = λ n i → sec-comm-suc i n }
where open NatSection x
Morph≡Section : NatSection ConstFiberM ≡ NatMorphism N M
Morph≡Section = ua e
where
unquoteDecl e = declStrictEquiv e section→morph morph→section
isContrMorph : isContr (NatMorphism N M)
isContrMorph = subst isContr Morph≡Section (inhProp→isContr (ind ConstFiberM) (AlgebraPropositionality.SectionProp.S≡T ind))
open NatAlgebra
open NatFiber
open NatSection
open NatMorphism
module AlgebraHInit→Ind (N : NatAlgebra ℓ') ℓ (hinit : isNatHInitial N (ℓ-max ℓ' ℓ)) (F : NatFiber N (ℓ-max ℓ' ℓ)) where
ΣAlgebra : NatAlgebra (ℓ-max ℓ' ℓ)
Carrier ΣAlgebra = Σ (N .Carrier) (F .Fiber)
alg-zero ΣAlgebra = N .alg-zero , F .fib-zero
alg-suc ΣAlgebra (n , fn) = N .alg-suc n , F .fib-suc fn
-- the fact that we have to lift the Carrier obstructs readability a bit
-- this is the same algebra as N, but lifted into the correct universe
LiftN : NatAlgebra (ℓ-max ℓ' ℓ)
Carrier LiftN = Lift {_} {ℓ} (N .Carrier)
alg-zero LiftN = lift (N .alg-zero)
alg-suc LiftN = lift ∘ N .alg-suc ∘ lower
_!_ : ∀ {x y} → x ≡ y → F .Fiber x → F .Fiber y
_!_ = subst (F .Fiber)
-- from homotopy initiality of N we get
-- 1) an algebra morphism μ from N → Σ N F together with proofs of commutativity with the algebras
-- 2) projecting out the first component after μ, called α, will turn out to be the identity function
-- 3) witnesses that μ respects the definitions given in ΣAlgebra
-- a) at zero the witnesses are ζ and ζ-h
-- b) at suc the witnesses are σ and σ-h
open NatMorphism (hinit ΣAlgebra .fst) renaming (morph to μ ; comm-zero to μ-zc ; comm-suc to μ-sc)
module _ n where open Σ (μ n) public renaming (fst to α ; snd to α-h)
-- module _ i where open Σ (μ-zc i) public renaming (fst to ζ ; snd to ζ-h)
ζ : α (N .alg-zero) ≡ N .alg-zero
ζ i = μ-zc i .fst
ζ-h : PathP (λ i → F .Fiber (ζ i)) (α-h (N .alg-zero)) (F .fib-zero)
ζ-h i = μ-zc i .snd
-- module _ n i where open Σ (μ-sc i n) public renaming (fst to σ ; snd to σ-h)
σ : ∀ n → α (N .alg-suc n) ≡ N .alg-suc (α n)
σ n i = μ-sc i n .fst
σ-h : ∀ n → PathP (λ i → F .Fiber (σ n i)) (α-h (N .alg-suc n)) (F .fib-suc (α-h n))
σ-h n i = μ-sc i n .snd
-- liftMorph would be the identity morphism if it weren't for size issues
liftMorph : NatMorphism N LiftN
liftMorph = record { morph = lift ; comm-zero = refl ; comm-suc = refl }
-- instead of abstractly defining morphism composition and a projection algebra morphism
-- from Σ N F → N, define the composite directly. comm-zero and comm-suc thus are
-- defined without path composition
fst∘μ : NatMorphism N LiftN
morph fst∘μ = lift ∘ α
comm-zero fst∘μ i = lift (ζ i)
comm-suc fst∘μ i n = lift (σ n i)
fst∘μ≡id : fst∘μ ≡ liftMorph
fst∘μ≡id = isContr→isProp (hinit LiftN) _ _
-- we get a proof that the index is preserved uniformly
P : ∀ n → α n ≡ n
P n i = lower (fst∘μ≡id i .morph n)
-- we also have proofs that α cancels after the algebra of N
Q-zero : α (N .alg-zero) ≡ N .alg-zero
Q-zero = ζ
Q-suc : ∀ n → α (N .alg-suc n) ≡ N .alg-suc n
Q-suc n = σ n ∙ cong (N .alg-suc) (P n)
-- but P and Q are the same up to homotopy
P-zero : P (N .alg-zero) ≡ Q-zero
P-zero i j = hcomp (λ k → λ where
(i = i0) → lower (fst∘μ≡id j .comm-zero (~ k))
(i = i1) → ζ (j ∨ ~ k)
(j = i0) → ζ (~ k)
(j = i1) → N .alg-zero
) (N .alg-zero)
P-suc : ∀ n → P (N .alg-suc n) ≡ Q-suc n
P-suc n i j = hcomp (λ k → λ where
(i = i0) → lower (fst∘μ≡id j .comm-suc (~ k) n)
(i = i1) → compPath-filler' (σ n) (cong (N .alg-suc) (P n)) k j
(j = i0) → σ n (~ k)
(j = i1) → N .alg-suc n
) (N .alg-suc (P n j))
Fsection : NatSection F
section Fsection n = P n ! α-h n
sec-comm-zero Fsection =
P (N .alg-zero) ! α-h (N .alg-zero)
≡[ i ]⟨ P-zero i ! α-h _ ⟩
Q-zero ! α-h (N .alg-zero)
≡⟨ fromPathP ζ-h ⟩
F .fib-zero
∎
sec-comm-suc Fsection n =
P (N .alg-suc n) ! α-h (N .alg-suc n)
≡[ i ]⟨ P-suc n i ! α-h _ ⟩
Q-suc n ! α-h (N .alg-suc n)
≡⟨ substComposite (F .Fiber) (σ n) (cong (N .alg-suc) (P n)) _ ⟩
cong (N .alg-suc) (P n) ! (σ n ! α-h (N .alg-suc n))
≡[ i ]⟨ cong (N .alg-suc) (P n) ! fromPathP (σ-h n) i ⟩
cong (N .alg-suc) (P n) ! (F .fib-suc (α-h n))
≡⟨ substCommSlice (F .Fiber) (F .Fiber ∘ N .alg-suc) (λ _ → F .fib-suc) (P n) (α-h n) ⟩
F .fib-suc (P n ! α-h n)
∎
isNatInductive≡isNatHInitial : {N : NatAlgebra ℓ'} (ℓ : Level)
→ isNatInductive N (ℓ-max ℓ' ℓ) ≡ isNatHInitial N (ℓ-max ℓ' ℓ)
isNatInductive≡isNatHInitial {_} {N} ℓ = hPropExt isPropIsNatInductive isPropIsNatHInitial ind→init init→ind where
open AlgebraPropositionality
open AlgebraHInit→Ind N ℓ renaming (Fsection to init→ind)
open AlgebraHInd→HInit renaming (isContrMorph to ind→init)
-- given two homotopy initial algebras there is a path between the algebras
-- this implies moreover that the carrier types are isomorphic
-- according to 5.16 in the paper this could be strengthened to isContr (N ≡ M)
isNatHInitial→algebraPath : {N M : NatAlgebra ℓ}
→ (hinitN : isNatHInitial N ℓ) (hinitM : isNatHInitial M ℓ)
→ N ≡ M
isNatHInitial→algebraPath {N = N} {M} hinitN hinitM = N≡M where
open Σ (hinitN M) renaming (fst to N→M)
open Σ (hinitM N) renaming (fst to M→N)
idN : NatMorphism N N
idN = record { morph = λ x → x ; comm-zero = refl ; comm-suc = refl }
idM : NatMorphism M M
idM = record { morph = λ x → x ; comm-zero = refl ; comm-suc = refl }
N→M→N : NatMorphism N N
morph N→M→N = morph M→N ∘ morph N→M
comm-zero N→M→N = (λ i → morph M→N (comm-zero N→M i)) ∙ comm-zero M→N
comm-suc N→M→N = (λ i → morph M→N ∘ comm-suc N→M i) ∙ (λ i → comm-suc M→N i ∘ morph N→M)
nmn≡idn : N→M→N ≡ idN
nmn≡idn = isContr→isProp (hinitN N) _ _
M→N→M : NatMorphism M M
morph M→N→M = morph N→M ∘ morph M→N
comm-zero M→N→M = (λ i → morph N→M (comm-zero M→N i)) ∙ comm-zero N→M
comm-suc M→N→M = (λ i → morph N→M ∘ comm-suc M→N i) ∙ (λ i → comm-suc N→M i ∘ morph M→N)
mnm≡idm : M→N→M ≡ idM
mnm≡idm = isContr→isProp (hinitM M) _ _
carrier≡ : N .Carrier ≡ M .Carrier
carrier≡ = isoToPath (iso (N→M .morph) (M→N .morph) (λ x i → mnm≡idm i .morph x) (λ x i → nmn≡idn i .morph x))
zero≡ : PathP (λ i → carrier≡ i) (N .alg-zero) (M .alg-zero)
zero≡ = toPathP λ i → transportRefl (N→M .comm-zero i) i
suc≡ : PathP (λ i → carrier≡ i → carrier≡ i) (N .alg-suc) (M .alg-suc)
suc≡ = toPathP (
transport refl ∘ N→M .morph ∘ N .alg-suc ∘ M→N .morph ∘ transport refl
≡[ i ]⟨ transportReflF i ∘ N→M .morph ∘ N .alg-suc ∘ M→N .morph ∘ transportReflF i ⟩
N→M .morph ∘ N .alg-suc ∘ M→N .morph
≡[ i ]⟨ N→M .comm-suc i ∘ M→N .morph ⟩
M .alg-suc ∘ N→M .morph ∘ M→N .morph
≡[ i ]⟨ M .alg-suc ∘ mnm≡idm i .morph ⟩
M .alg-suc
∎) where
transportReflF : transport refl ≡ (λ x → x)
transportReflF = funExt transportRefl
N≡M : N ≡ M
Carrier (N≡M i) = carrier≡ i
alg-zero (N≡M i) = zero≡ i
alg-suc (N≡M i) = suc≡ i
-- the payoff, it is straight forward to define the algebra and show inductiveness of ℕ
NatAlgebraℕ : NatAlgebra ℓ-zero
Carrier NatAlgebraℕ = ℕ
alg-zero NatAlgebraℕ = zero
alg-suc NatAlgebraℕ = suc
isNatInductiveℕ : isNatInductive NatAlgebraℕ ℓ
section (isNatInductiveℕ F) = nat-sec where
nat-sec : ∀ n → F .Fiber n
nat-sec zero = F .fib-zero
nat-sec (suc n) = F .fib-suc (nat-sec n)
sec-comm-zero (isNatInductiveℕ F) = refl
sec-comm-suc (isNatInductiveℕ F) n = refl
isNatHInitialℕ : isNatHInitial NatAlgebraℕ ℓ
isNatHInitialℕ = transport (isNatInductive≡isNatHInitial _) isNatInductiveℕ
|
#ifndef PROJECTION_HPP
#define PROJECTION_HPP
#include <Eigen/Core>
class Projection {
public:
Eigen::Matrix4d getTransformation();
double getLeft();
double getRight();
double getBottom();
double getTop();
double getNear();
double getFar();
protected:
virtual void generateTransformation() = 0;
Eigen::Matrix4d transformation;
double left;
double right;
double bottom;
double top;
double near;
double far;
};
#endif // PROJECTION_HPP
|
module OutsideIn.Prelude where
open import Data.Nat public
open import Relation.Binary.PropositionalEquality public renaming ([_] to iC)
open import Relation.Nullary public
open import Function public hiding (case_of_)
cong₃ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d}
(f : A → B → C → D) {x y u v x′ y′} → x ≡ y → u ≡ v → x′ ≡ y′
→ f x u x′ ≡ f y v y′
cong₃ f refl refl refl = refl
cong₄ : ∀ {a b c d e} {A : Set a} {B : Set b} {C : Set c} {D : Set d} {E : Set e}
(f : A → B → C → D → E) {x y u v x′ y′ u′ v′} → x ≡ y → u ≡ v → x′ ≡ y′ → u′ ≡ v′
→ f x u x′ u′ ≡ f y v y′ v′
cong₄ f refl refl refl refl = refl
import Level
postulate extensionality : Extensionality Level.zero Level.zero
module Shapes where
-- Used throughout to show structure preserving operations preserve structure,
-- in order to maintain structural recursion.
data Shape : Set where
Nullary : Shape
Unary : Shape → Shape
Binary : Shape → Shape → Shape
module Functors where
import Data.Vec as V
open V using (_∷_; Vec; [])
isIdentity : ∀ {A} → (A → A) → Set
isIdentity {A} f = ∀ {x} → f x ≡ x
id-is-id : ∀ {A} → isIdentity {A} id
id-is-id = refl
record Functor (X : Set → Set) : Set₁ where
field map : ∀ {A B} → (A → B) → X A → X B
_<$>_ : ∀ {A B} → (A → B) → X A → X B
_<$>_ = map
field identity : ∀ {A : Set}{f : A → A} → isIdentity f → isIdentity (map f)
field composite : ∀ {A B C : Set} {f : A → B} {g : B → C}
→ {x : X A} → ( (g ∘ f) <$> x ≡ g <$> (f <$> x))
Pointed : (Set → Set) → Set₁
Pointed X = ∀ {a} → a → X a
id-is-functor : Functor id
id-is-functor = record { map = id; identity = id; composite = refl }
vec-is-functor : ∀ {n} → Functor (λ A → Vec A n)
vec-is-functor {n} = record { map = V.map; identity = ident {n} ; composite = composite }
where ident : {n : ℕ}{A : Set} {f : A → A} → isIdentity f →{x : Vec A n} → V.map f x ≡ x
ident isid {[]} = refl
ident isid {x ∷ xs} = cong₂ _∷_ isid (ident isid)
composite : {A B C : Set}{n : ℕ} {f : A → B} {g : B → C} {x : Vec A n}
→ V.map (g ∘ f) x ≡ V.map g (V.map f x)
composite {x = []} = refl
composite {x = x ∷ xs} = cong₂ _∷_ refl composite
private
module F = Functor ⦃ ... ⦄
combine-composite′ : {X Y : Set → Set}{A B C : Set} ⦃ F2 : Functor Y ⦄
{V : X (Y A)}{f : A → B}{g : B → C}
→ (f1map : ∀ {a b} → (a → b) → (X a → X b))
→ (f1comp : f1map (F.map g ∘ F.map f) V
≡ f1map (F.map g) (f1map (F.map f) V))
→ f1map (F.map ⦃ F2 ⦄ (g ∘ f)) V
≡ f1map (F.map ⦃ F2 ⦄ g) (f1map (F.map ⦃ F2 ⦄ f) V)
combine-composite′ ⦃ F2 ⦄ {V} f1map f1comp = trans (cong (λ t → f1map t V)
(extensionality (λ x → F.composite ⦃ F2 ⦄)))
f1comp
combine-composite : {X Y : Set → Set}{A B C : Set} ⦃ F1 : Functor X ⦄ ⦃ F2 : Functor Y ⦄
{V : X (Y A)}{f : A → B}{g : B → C}
→ F.map ⦃ F1 ⦄ (F.map ⦃ F2 ⦄ (g ∘ f)) V
≡ F.map ⦃ F1 ⦄ (F.map ⦃ F2 ⦄ g) (F.map ⦃ F1 ⦄ (F.map ⦃ F2 ⦄ f) V)
combine-composite {X}{Y} ⦃ F1 ⦄ ⦃ F2 ⦄ {V} = combine-composite′ {X}{Y}
(F.map ⦃ F1 ⦄)
(F.composite ⦃ F1 ⦄)
infixr 6 _∘f_
_∘f_ : {X Y : Set → Set} → ( F1 : Functor X )( F2 : Functor Y )
→ Functor (X ∘ Y)
F1 ∘f F2 = record { map = F.map ⦃ F1 ⦄ ∘ F.map ⦃ F2 ⦄
; composite = combine-composite ⦃ F1 ⦄ ⦃ F2 ⦄
; identity = F.identity ⦃ F1 ⦄ ∘ F.identity ⦃ F2 ⦄
}
module StupidEquality where
open import Data.Bool public using (Bool; true; false)
-- This equality doesn't place any proof demands
-- because we don't actually care what equality is used.
-- This is just for the initial base of type variables, where the user provides
-- their own type equality relation. We don't care if it says Int ∼ Bool - this just
-- provides a way for users to get some equality information threaded through the
-- simplifier
Eq : Set → Set
Eq X = ∀ (a b : X) → Bool
module Monads where
open Functors
record Monad (X : Set → Set) : Set₁ where
field ⦃ is-functor ⦄ : Functor X
field ⦃ point ⦄ : Pointed X
open Functor is-functor
field join : ∀ {a} → X (X a) → X a
unit : ∀ {a} → a → X a
unit = point
_>>=_ : ∀ {a b} → X a → (a → X b) → X b
_>>=_ a b = join (b <$> a)
_>>_ : ∀ {a b} → X a → X b → X b
_>>_ a b = a >>= λ _ → b
_>=>_ : ∀ {a b c : Set} → (b → X c) → (a → X b) → (a → X c)
_>=>_ a b = λ v → b v >>= a
field is-left-ident : ∀ {a b}{x : a → X b}{v} → (point >=> x) v ≡ x v
field is-right-ident : ∀ {a b}{x : a → X b}{v} → (x >=> point) v ≡ x v
field >=>-assoc : ∀{p}{q}{r}{s}{a : r → X s}{b : q → X r} {c : p → X q}{v}
→ (a >=> (b >=> c)) v ≡ ((a >=> b) >=> c) v
abstract
<$>-unit : ∀ {A B}{g : A → B}{x} → g <$> (unit x) ≡ unit (g x)
<$>-unit {A}{B}{g}{x} = begin
g <$> (unit x) ≡⟨ sym (is-left-ident {x = _<$>_ g}) ⟩
join (unit <$> (g <$> (unit x))) ≡⟨ cong join (sym (composite)) ⟩
join ((λ x → unit (g x)) <$> (unit x)) ≡⟨ is-right-ident ⟩
unit (g x) ∎
where open ≡-Reasoning
abstract
<$>-bind : ∀ {A B C}{f : A → B}{g : B → X C}{x : X A}
→ (f <$> x) >>= g ≡ x >>= (λ z → g (f z))
<$>-bind = cong join (sym (composite))
natural-trans : ∀ {A B}{f : A → B}{x : X( X A)} → f <$> (join x) ≡ join ((_<$>_ f) <$> x)
natural-trans {A}{B}{f}{x} = begin
f <$> (join x) ≡⟨ sym (is-left-ident {x = _<$>_ f}) ⟩
join (unit <$> (f <$> (join x))) ≡⟨ † ⟩
join (unit <$> (f <$> (join (id <$> x)))) ≡⟨ <$>-bind ⟩
join ((λ v → unit (f v)) <$> (join (id <$> x))) ≡⟨ >=>-assoc { c = λ _ → x}{0} ⟩
join ((λ x → join ((unit ∘ f) <$> x)) <$> x ) ≡⟨ sym (<$>-bind) ⟩
((_<$>_ (λ y → unit (f y))) <$> x ) >>= join ≡⟨ <$>-bind ⟩
x >>= (λ x → x >>= (λ y → unit (f y))) ≡⟨ * ⟩
join ((_<$>_ f) <$> x) ∎
where open ≡-Reasoning
† : join (unit <$> (f <$> (join x))) ≡ join (unit <$> (f <$> (join (id <$> x))))
† = cong (λ t → join (unit <$> (f <$> join t))) (sym (identity id-is-id ))
* : x >>= (λ x → x >>= (λ y → unit (f y))) ≡ join ((_<$>_ f) <$> x)
* = cong (_>>=_ x)
(extensionality (λ y → trans (sym <$>-bind)
(is-left-ident {x = _<$>_ f}{v = y})))
id-is-monad : Monad id
id-is-monad = record { is-functor = id-is-functor
; point = id
; join = id
; >=>-assoc = refl
; is-left-ident = refl
; is-right-ident = refl
}
record MonadHomomorphism {M₁ M₂ : Set → Set}(h : ∀ {x : Set} → M₁ x → M₂ x)
⦃ M₁-m : Monad M₁ ⦄ ⦃ M₂-m : Monad M₂ ⦄ : Set₁ where
open Monad M₁-m using () renaming (unit to unit₁; join to join₁; is-functor to is-functor₁)
open Monad M₂-m using () renaming (unit to unit₂; join to join₂; is-functor to is-functor₂)
open Functor is-functor₁ using () renaming (map to map₁)
open Functor is-functor₂ using () renaming (map to map₂)
field h-return : ∀ {A}{x : A} → h (unit₁ x) ≡ unit₂ x
field h-fmap : {A B : Set} {f : A → B} {x : M₁ A}
→ h (map₁ f x) ≡ map₂ f (h x)
field h-join : ∀{τ}{x : M₁ (M₁ τ)} → h (join₁ x) ≡ join₂ (h (map₁ h x))
record MonadTrans (X : (Set → Set) → Set → Set) : Set₁ where
field produces-monad : ∀ {m} → Monad m → Monad (X m)
field lift : ∀ {m}⦃ mm : Monad m ⦄{a} → m a → X m a
field is-homomorphism : ∀ {m} → (mm : Monad m)
→ MonadHomomorphism {m} {X m} (lift {m}) ⦃ mm ⦄ ⦃ produces-monad mm ⦄
module Ⓢ-Type where
open Functors
open Monads
open StupidEquality
data Ⓢ (τ : Set) : Set where
suc : τ → Ⓢ τ
zero : Ⓢ τ
cata-Ⓢ : {a b : Set} → b → (a → b) → Ⓢ a → b
cata-Ⓢ nil something zero = nil
cata-Ⓢ nil something (suc n) = something n
sequence-Ⓢ : ∀ {m}{b} → ⦃ monad : Monad m ⦄ → Ⓢ (m b) → m (Ⓢ b)
sequence-Ⓢ ⦃ m ⦄ (suc n) = map suc n
where open Functor (Monad.is-functor m)
sequence-Ⓢ ⦃ m ⦄ (zero) = unit zero
where open Monad (m)
private
fmap-Ⓢ : ∀ {a b} → (a → b) → Ⓢ a → Ⓢ b
fmap-Ⓢ f zero = zero
fmap-Ⓢ f (suc n) = suc (f n)
abstract
fmap-Ⓢ-id : ∀ {A} → {f : A → A}
→ isIdentity f → isIdentity (fmap-Ⓢ f)
fmap-Ⓢ-id isid {zero} = refl
fmap-Ⓢ-id isid {suc x} = cong suc isid
fmap-Ⓢ-comp : ∀ {A B C : Set} {f : A → B} {g : B → C} → ∀ {x}
→ fmap-Ⓢ (g ∘ f) x ≡ fmap-Ⓢ g (fmap-Ⓢ f x)
fmap-Ⓢ-comp {x = zero} = refl
fmap-Ⓢ-comp {x = suc n} = refl
Ⓢ-is-functor : Functor Ⓢ
Ⓢ-is-functor = record { map = fmap-Ⓢ
; identity = fmap-Ⓢ-id
; composite = fmap-Ⓢ-comp
}
Ⓢ-eq : ∀ {x} → Eq x → Eq (Ⓢ x)
Ⓢ-eq x zero zero = true
Ⓢ-eq x (suc n) zero = false
Ⓢ-eq x zero (suc m) = false
Ⓢ-eq x (suc n) (suc m) = x n m
private
join-Ⓢ : ∀ {x} → Ⓢ (Ⓢ x) → Ⓢ x
join-Ⓢ (zero) = zero
join-Ⓢ (suc τ) = τ
test-join : ∀ {A B}{f : A → B}{x : Ⓢ( Ⓢ A)}
→ fmap-Ⓢ f (join-Ⓢ x) ≡ join-Ⓢ (fmap-Ⓢ (fmap-Ⓢ f) x)
test-join {x = zero} = refl
test-join {x = suc n} = refl
Ⓢ-is-monad : Monad Ⓢ
Ⓢ-is-monad = record { is-functor = Ⓢ-is-functor
; point = suc
; join = join-Ⓢ
; is-left-ident = left-id
; is-right-ident = refl
; >=>-assoc = λ { {c = c}{v} → assoc {τ = c v} }
}
where
left-id : ∀ {τ : Set}{v : Ⓢ τ} → join-Ⓢ (fmap-Ⓢ suc v) ≡ v
left-id {v = zero } = refl
left-id {v = suc v} = refl
assoc : ∀ {q r s : Set} {a : r → Ⓢ s} {b : q → Ⓢ r}{τ : Ⓢ q}
→ join-Ⓢ (fmap-Ⓢ a (join-Ⓢ (fmap-Ⓢ b τ)))
≡ join-Ⓢ (fmap-Ⓢ (λ v′ → join-Ⓢ (fmap-Ⓢ a (b v′))) τ)
assoc {τ = zero} = refl
assoc {τ = suc v} = refl
Ⓢ-Trans : (Set → Set) → Set → Set
Ⓢ-Trans m x = m (Ⓢ x)
private
lift : ∀ {m : Set → Set}⦃ mm : Monad m ⦄{x} → m x → m (Ⓢ x)
lift {m}⦃ mm ⦄{x} v = suc <$> v
where open Monad mm
open Functor is-functor
module MonadProofs {m : Set → Set}⦃ mm : Monad m ⦄ where
open Monad mm
open Functor is-functor
functor : Functor (Ⓢ-Trans m)
functor = record { map = λ f v → (fmap-Ⓢ f) <$> v
; identity = λ p → identity (fmap-Ⓢ-id p)
; composite = λ { {x = x} → trans (cong (λ t → t <$> x)
(extensionality ext)) composite }
}
where open ≡-Reasoning
ext : ∀ {A B C : Set} {f : A → B} {g : B → C} → (x' : Ⓢ A)
→ fmap-Ⓢ (g ∘ f) x' ≡ (fmap-Ⓢ g ∘ fmap-Ⓢ f) x'
ext (zero) = refl
ext (suc n) = refl
module Trans = Functor functor
private
cata-Ⓢ-u0 : ∀ {a b} → (a → m (Ⓢ b)) → Ⓢ a → m (Ⓢ b)
cata-Ⓢ-u0 = cata-Ⓢ (unit zero)
abstract
right-id : {a b : Set} {x : a → Ⓢ-Trans m b} {v : a}
→ Trans.map x (lift {m} (unit v)) >>= cata-Ⓢ-u0 id ≡ x v
right-id {a}{b}{x}{v} = begin
Trans.map x (suc <$> (unit v)) >>= cata-Ⓢ-u0 id ≡⟨ * ⟩
(fmap-Ⓢ x <$> (unit (suc v))) >>= cata-Ⓢ-u0 id ≡⟨ † ⟩
join (cata-Ⓢ-u0 id <$> (unit (suc (x v)))) ≡⟨ cong join <$>-unit ⟩
join (unit (x v)) ≡⟨ cong join (sym(identity id-is-id)) ⟩
join (id <$> unit (x v)) ≡⟨ is-right-ident {x = id} ⟩
x v ∎
where open ≡-Reasoning
* : Trans.map x (suc <$> (unit v)) >>= cata-Ⓢ-u0 id
≡ (fmap-Ⓢ x <$> (unit (suc v))) >>= cata-Ⓢ-u0 id
* = cong (λ t → Trans.map x t >>= cata-Ⓢ-u0 id) <$>-unit
† : (fmap-Ⓢ x <$> (unit (suc v))) >>= cata-Ⓢ-u0 id
≡ join (cata-Ⓢ-u0 id <$> (unit (suc (x v))))
† = cong (λ x → x >>= cata-Ⓢ-u0 id) <$>-unit
left-id : {b : Set} {t : Ⓢ-Trans m b}
→ Trans.map (λ x' → lift {m} (unit x')) t >>= cata-Ⓢ-u0 id ≡ t
left-id {b}{t} = trans <$>-bind (subst (λ q → t >>= q ≡ t)
(sym (extensionality h≗unit))
(is-left-ident {x = λ _ → t} {v = 0}))
where h : ∀ {A} → Ⓢ A → m (Ⓢ A)
h x = cata-Ⓢ-u0 id (fmap-Ⓢ (λ x' → suc <$> (unit x')) x)
h≗unit : ∀ {A} → h {A} ≗ unit
h≗unit zero = refl
h≗unit (suc y) = <$>-unit
assoc : ∀ {p q r s : Set}
{a : r → Ⓢ-Trans m s}{b : q → Ⓢ-Trans m r}{c : p → Ⓢ-Trans m q}
{v : p}
→ Trans.map a (Trans.map b (c v) >>= cata-Ⓢ-u0 id) >>= cata-Ⓢ-u0 id
≡ Trans.map (λ v' → Trans.map a (b v') >>= cata-Ⓢ-u0 id) (c v) >>= cata-Ⓢ-u0 id
assoc {p}{q}{r}{s}{a}{b}{c}{v}
= let
†₀ = cata-fmap
†₁ = cong (λ x → x >>= cata-Ⓢ (unit zero) a) cata-fmap
†₂ = >=>-assoc {c = λ _ → c v} {v = 0}
†₃ = cong (_>>=_ (c v)) (extensionality ext)
†₄ = cong (λ x → c v >>= cata-Ⓢ (unit zero) x)
(extensionality (λ x → sym cata-fmap))
†₅ = sym (cata-fmap)
in begin
Trans.map a (Trans.map b (c v) >>= cata-Ⓢ-u0 id) >>= cata-Ⓢ-u0 id ≡⟨ †₀ ⟩
((fmap-Ⓢ b <$> c v) >>= cata-Ⓢ-u0 id) >>= cata-Ⓢ-u0 a ≡⟨ †₁ ⟩
(c v >>= cata-Ⓢ-u0 b) >>= cata-Ⓢ-u0 a ≡⟨ †₂ ⟩
c v >>= (λ cv → cata-Ⓢ-u0 b cv >>= cata-Ⓢ-u0 a) ≡⟨ †₃ ⟩
c v >>= cata-Ⓢ-u0 (λ v' → b v' >>= cata-Ⓢ-u0 a) ≡⟨ †₄ ⟩
c v >>= cata-Ⓢ-u0 (λ v' → (fmap-Ⓢ a <$> b v') >>= cata-Ⓢ-u0 id) ≡⟨ †₅ ⟩
Trans.map (λ v' → Trans.map a (b v') >>= cata-Ⓢ-u0 id) (c v) >>= cata-Ⓢ-u0 id ∎
where open ≡-Reasoning
ext : (x : Ⓢ q) → cata-Ⓢ-u0 b x >>= cata-Ⓢ-u0 a
≡ cata-Ⓢ-u0 (λ v' → b v' >>= cata-Ⓢ-u0 a) x
ext zero = begin
join ((cata-Ⓢ-u0 a) <$> unit zero) ≡⟨ cong join <$>-unit ⟩
join (unit (unit zero)) ≡⟨ cong join (sym (identity id-is-id)) ⟩
join (id <$> unit (unit zero)) ≡⟨ is-right-ident ⟩
unit zero ∎
ext (suc n) = refl
cata-fmap : ∀{A B C}{a : A → B}{x : m (Ⓢ A)}{n : m C}{j : B → m C}
→ (fmap-Ⓢ a <$> x) >>= cata-Ⓢ n j ≡ x >>= cata-Ⓢ n (λ x → j ( a x))
cata-fmap {A}{B}{C}{a}{x}{n}{j} = trans <$>-bind
(cong (_>>=_ x) (extensionality ext′))
where ext′ : (x' : Ⓢ A) → cata-Ⓢ n j (fmap-Ⓢ a x')
≡ cata-Ⓢ n (λ x0 → j (a x0)) x'
ext′ zero = refl
ext′ (suc n) = refl
produces-monad = record { point = λ x → lift ⦃ mm ⦄ (unit x)
; is-functor = functor
; join = λ v → v >>= cata-Ⓢ (unit zero) id
; is-left-ident = left-id
; is-right-ident = right-id
; >=>-assoc = λ {_}{_}{_}{_}{a}{b}{c}{v}
→ assoc {a = a}{b}{c}{v}
}
module HomomorphismProofs {m : Set → Set}⦃ mm : Monad m ⦄ where
open Monad mm
open Functor is-functor
open ≡-Reasoning
cata-Ⓢ-u0 : ∀ {a b} → (a → m (Ⓢ b)) → Ⓢ a → m (Ⓢ b)
cata-Ⓢ-u0 = cata-Ⓢ (unit zero)
fmap-p : ∀ {A B : Set} {f : A → B} {x}
→ lift {m} (f <$> x) ≡ (fmap-Ⓢ f) <$> (lift {m} x)
fmap-p {A}{B}{f}{x} = begin
suc <$> (f <$> x) ≡⟨ sym (composite) ⟩
(λ t → suc (f t)) <$> x ≡⟨ refl ⟩
(λ t → fmap-Ⓢ f (suc t)) <$> x ≡⟨ composite ⟩
(fmap-Ⓢ f) <$> (suc <$> x) ∎
join-p : ∀{τ}{x : m (m (τ))}
→ suc <$> (join x) ≡ (suc <$> (_<$>_ suc <$> x)) >>= cata-Ⓢ-u0 id
join-p {_}{x} = begin
suc <$> (join x) ≡⟨ natural-trans ⟩
join ((_<$>_ suc) <$> x) ≡⟨ refl ⟩
x >>= (λ z → cata-Ⓢ-u0 id (suc (suc <$> z))) ≡⟨ sym (<$>-bind) ⟩
((λ z → suc (suc <$> z)) <$> x) >>= cata-Ⓢ-u0 id ≡⟨ † ⟩
(suc <$> (_<$>_ suc <$> x)) >>= cata-Ⓢ-u0 id ∎
where † = cong (λ x → x >>= cata-Ⓢ-u0 id) (composite)
is-homomorphism : MonadHomomorphism (lift {m}) ⦃ mm ⦄ ⦃ MonadProofs.produces-monad ⦃ mm ⦄ ⦄
is-homomorphism = record { h-return = refl
; h-fmap = fmap-p
; h-join = join-p
}
Ⓢ-Trans-is-trans : MonadTrans (Ⓢ-Trans)
Ⓢ-Trans-is-trans = record { produces-monad = λ mm → MonadProofs.produces-monad ⦃ mm ⦄
; lift = λ{m} → lift {m}
; is-homomorphism = λ mm → HomomorphismProofs.is-homomorphism ⦃ mm ⦄
}
module PlusN-Type where
open Ⓢ-Type
open Monads
open Functors
open StupidEquality
PlusN : (n : ℕ) → Set → Set
PlusN zero = id
PlusN (suc n) = Ⓢ-Trans (PlusN n)
PlusN-eq : ∀ {n}{x} → Eq x → Eq (PlusN n x)
PlusN-eq {zero} eq = eq
PlusN-eq {suc n} eq = PlusN-eq {n} (Ⓢ-eq eq)
PlusN-is-monad : ∀ {n} → Monad (PlusN n)
PlusN-is-monad {zero} = id-is-monad
PlusN-is-monad {suc n} = MonadTrans.produces-monad Ⓢ-Trans-is-trans (PlusN-is-monad {n})
_⨁_ = flip PlusN
sequence-PlusN : ∀ {m}{n}{b} → ⦃ monad : Monad m ⦄ → (m b) ⨁ n → m (b ⨁ n)
sequence-PlusN {n = zero} x = x
sequence-PlusN {n = suc n} ⦃ m ⦄ x = sequence-PlusN {n = n}⦃ m ⦄
(PlusN-f.map (sequence-Ⓢ ⦃ m ⦄) x)
where module PlusN-f = Functor (Monad.is-functor (PlusN-is-monad {n}))
PlusN-collect : ∀ {n}{a b} → n ⨁ (a + b) ≡ (n ⨁ a) ⨁ b
PlusN-collect {n}{zero} = refl
PlusN-collect {n}{suc a}{b} = PlusN-collect {Ⓢ n}{a}{b}
open Ⓢ-Type public
open PlusN-Type public
open Functors public
open Monads public
open Shapes public
open StupidEquality public
|
= = = Cold War = = =
|
!-------------------------------------------------------------------------------
!
!+ Dynamical step
!
!-------------------------------------------------------------------------------
module mod_dynstep
!-----------------------------------------------------------------------------
!
!++ Description:
! This module is for the dynamical step
!
!
!++ Current Corresponding Author : H.Tomita
!
!++ History:
! Version Date Comment
! -----------------------------------------------------------------------
! 0.00 04-02-17 Imported from igdc-4.34
! 06-04-17 Add IN_LARGE_STEP2
! 06-08-11 Add the option for tracer advection.
! 07-01-26 Add flag [rayleigh_damp_only_w]
! in numfilter_rayleigh_damping.
! 07-05-08 H.Tomita : Change the treatment of I_TKE.
! 08-01-24 Y.Niwa: add revised MIURA2004 for tracer advection
! old: 'MIURA2004OLD', revised: 'MIURA2004'
! 08-01-30 Y.Niwa: add rho_pl = 0.D0
! 08-04-12 T.Mitsui save memory(prgvar, frcvar, rhog0xxxx)
! 08-05-24 T.Mitsui fix miss-conditioning for frcvar
! 08-09-09 Y.Niwa move nudging routine here
! 08-10-05 T.Mitsui all_phystep_post is already needless
! 09-09-08 S.Iga frhog and frhog_pl in ndg are deleted ( suggested by ES staff)
! 10-05-06 M.Satoh: define QV_conv only if CP_TYPE='TDK' .or. 'KUO'
! 10-07-16 A.T.Noda: bug fix for TDK
! 10-08-16 A.T.Noda: Bug fix (Qconv not diveded by density)
! 10-08-20 A.T.Noda: Bug fix (Qconv should be TEND, and not be multiplied by DT)
! 10-11-29 A.T.Noda: Introduce the Smagorinsky model
! 11-08-16 M.Satoh: bug fix for TDK: conv => TEND
! qv_dyn_tend = v grad q
! = ( div(rho v q) - div(rho v)*q )/rho
! 11-08-16 M.Satoh: move codes related to CP_TYPE below the tracer calculation
! 11-11-28 Y.Yamada: Merge Terai-san timer into the original code.
! 12-03-09 S.Iga: tuned (phase4-1)
! 12-04-06 T.yamaura: optimized for K
! 12-05-30 T.Yashiro: Change arguments from character to index/switch
! 12-10-22 R.Yoshida : add papi instructions
! 13-06-13 R.Yoshida : add tracer advection mode
! -----------------------------------------------------------------------
!
!-----------------------------------------------------------------------------
!
!++ Used modules
!
use mod_debug
use mod_adm, only: &
ADM_LOG_FID
!-----------------------------------------------------------------------------
implicit none
private
!-----------------------------------------------------------------------------
!
!++ Public procedure
!
public :: dynstep
!-----------------------------------------------------------------------------
!
!++ Public parameters & variables
!
!-----------------------------------------------------------------------------
!
!++ Private procedures
!
!-----------------------------------------------------------------------------
!
!++ Private parameters & variables
!
integer, private, parameter :: I_RHOG = 1 ! Density x G^{1/2} x gamma^2
integer, private, parameter :: I_RHOGVX = 2 ! Density x G^{1/2} x gamma^2 x Horizontal velocity (X-direction)
integer, private, parameter :: I_RHOGVY = 3 ! Density x G^{1/2} x gamma^2 x Horizontal velocity (Y-direction)
integer, private, parameter :: I_RHOGVZ = 4 ! Density x G^{1/2} x gamma^2 x Horizontal velocity (Z-direction)
integer, private, parameter :: I_RHOGW = 5 ! Density x G^{1/2} x gamma^2 x Vertical velocity
integer, private, parameter :: I_RHOGE = 6 ! Density x G^{1/2} x gamma^2 x Internal Energy
integer, private, parameter :: I_RHOGETOT = 7 ! Density x G^{1/2} x gamma^2 x Total Energy
!-----------------------------------------------------------------------------
contains
!-----------------------------------------------------------------------------
subroutine dynstep
use mod_debug
use mod_adm, only: &
ADM_prc_me, &
ADM_prc_pl, &
ADM_gall, &
ADM_gall_pl, &
ADM_lall, &
ADM_lall_pl, &
ADM_kall, &
ADM_gall_1d, &
ADM_gmax, &
ADM_gmin, &
ADM_kmax, &
ADM_kmin, &
ADM_log_fid, & ! R.Yoshida 13/06/13 [add]
ADM_proc_stop ! R.Yoshida 13/06/13 [add]
use mod_cnst, only: &
CNST_RAIR, &
CNST_RVAP, &
CNST_CV
use mod_time, only: &
TIME_INTEG_TYPE, &
TIME_SSTEP_MAX, &
TIME_DTL, &
TIME_DTS, &
TIME_SPLIT
use mod_grd, only: &
GRD_afac, &
GRD_bfac
use mod_vmtr, only: &
VMTR_GSGAM2, &
VMTR_GSGAM2_pl, &
VMTR_GSGAM2H, &
VMTR_GSGAM2H_pl, &
VMTR_GZXH, &
VMTR_GZXH_pl, &
VMTR_GZYH, &
VMTR_GZYH_pl, &
VMTR_GZZH, &
VMTR_GZZH_pl, &
VMTR_PHI, &
VMTR_PHI_pl, &
VMTR_C2Wfact, &
VMTR_C2Wfact_pl
use mod_comm, only: &
COMM_data_transfer
use mod_runconf, only: &
TRC_VMAX, &
I_QV, &
I_TKE, &
NQW_STR, &
NQW_END, &
CVW, &
NDIFF_LOCATION, &
TRC_ADV_TYPE, &
FLAG_NUDGING, & ! Y.Niwa add 08/09/09
CP_TYPE, & ! 2010.5.11 M.Satoh [add]
TB_TYPE, & ! [add] 10/11/29 A.Noda
THUBURN_LIM ! R.Yoshida 13/06/13 [add]
use mod_bsstate, only: &
pre_bs, pre_bs_pl, &
tem_bs, tem_bs_pl, &
rho_bs, rho_bs_pl
use mod_bndcnd, only: &
bndcnd_all
use mod_prgvar, only: &
prgvar_set, &
prgvar_get, &
prgvar_get_noq
use mod_diagvar, only: &
diagvar, &
diagvar_pl, &
I_RHOGQV_CONV, &
I_QV_DYN_TEND ! 2011.08.16 M.Satoh
use mod_thrmdyn, only: &
thrmdyn_th, &
thrmdyn_eth
use mod_src, only: &
src_advection_convergence_momentum, &
src_advection_convergence, &
I_SRC_default
use mod_vi, only : &
vi_small_step
use mod_trcadv_thuburn, only: &
src_update_tracer
use mod_numfilter, only: &
NUMFILTER_DOrayleigh, & ! [add] H.Yashiro 20120530
NUMFILTER_DOverticaldiff, & ! [add] H.Yashiro 20120530
numfilter_rayleigh_damping, &
numfilter_hdiffusion, &
numfilter_vdiffusion
!cx remove nudging function
!cx use mod_ndg, only: & ! Y.Niwa add 08/09/09
!cx ndg_nudging_uvtp, &
!cx ndg_update_var
!cx remove tb_smg_driver
!cx use mod_tb_smg, only: & ! [add] 10/11/29 A.Noda
!cx tb_smg_driver
use mod_forcing_driver, only: &
updating ! R.Yoshida 13/06/13 [add]
implicit none
integer, parameter :: nmax_TEND = 7
integer, parameter :: nmax_PROG = 6
integer, parameter :: nmax_v_mean_c = 5
real(8) :: g_TEND (ADM_gall, ADM_kall,ADM_lall, nmax_TEND) !--- tendency
real(8) :: g_TEND_pl (ADM_gall_pl,ADM_kall,ADM_lall_pl,nmax_TEND)
real(8) :: g_TENDq (ADM_gall, ADM_kall,ADM_lall, TRC_VMAX) !--- tendency of q
real(8) :: g_TENDq_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl,TRC_VMAX)
real(8) :: f_TEND (ADM_gall, ADM_kall,ADM_lall, nmax_TEND) !--- forcing tendency
real(8) :: f_TEND_pl (ADM_gall_pl,ADM_kall,ADM_lall_pl,nmax_TEND)
real(8) :: f_TENDq (ADM_gall, ADM_kall,ADM_lall, TRC_VMAX) !--- forcing tendency of q
real(8) :: f_TENDq_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl,TRC_VMAX)
real(8) :: PROG0 (ADM_gall, ADM_kall,ADM_lall, nmax_PROG) !--- prognostic variables (save)
real(8) :: PROG0_pl (ADM_gall_pl,ADM_kall,ADM_lall_pl,nmax_PROG)
real(8) :: PROGq0 (ADM_gall, ADM_kall,ADM_lall, TRC_VMAX) !--- tracer variables (save)
real(8) :: PROGq0_pl (ADM_gall_pl,ADM_kall,ADM_lall_pl,TRC_VMAX)
real(8) :: PROG (ADM_gall, ADM_kall,ADM_lall, nmax_PROG) !--- prognostic variables
real(8) :: PROG_pl (ADM_gall_pl,ADM_kall,ADM_lall_pl,nmax_PROG)
real(8) :: PROGq (ADM_gall, ADM_kall,ADM_lall, TRC_VMAX) !--- tracer variables
real(8) :: PROGq_pl (ADM_gall_pl,ADM_kall,ADM_lall_pl,TRC_VMAX)
real(8) :: PROG_split (ADM_gall, ADM_kall,ADM_lall, nmax_PROG) !--- prognostic variables (split)
real(8) :: PROG_split_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl,nmax_PROG)
real(8) :: v_mean_c (ADM_gall, ADM_kall,ADM_lall ,nmax_v_mean_c)
real(8) :: v_mean_c_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl,nmax_v_mean_c)
!--- density ( physical )
real(8) :: rho (ADM_gall, ADM_kall,ADM_lall )
real(8) :: rho_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl)
!--- horizontal velocity_x ( physical )
real(8) :: vx (ADM_gall, ADM_kall,ADM_lall )
real(8) :: vx_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl)
!--- horizontal velocity_y ( physical )
real(8) :: vy (ADM_gall, ADM_kall,ADM_lall )
real(8) :: vy_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl)
!--- horizontal velocity_z ( physical )
real(8) :: vz (ADM_gall, ADM_kall,ADM_lall )
real(8) :: vz_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl)
!--- vertical velocity ( physical )
real(8) :: w (ADM_gall, ADM_kall,ADM_lall )
real(8) :: w_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl)
!--- [IN]ternal energy ( physical )
real(8) :: ein (ADM_gall, ADM_kall,ADM_lall )
real(8) :: ein_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl)
!--- mass concentration of water substance ( physical )
real(8) :: q (ADM_gall, ADM_kall,ADM_lall, TRC_VMAX)
real(8) :: q_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl,TRC_VMAX)
!--- enthalpy ( physical )
real(8) :: eth (ADM_gall, ADM_kall,ADM_lall )
real(8) :: eth_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl)
!--- pressure ( physical )
real(8) :: pre (ADM_gall, ADM_kall,ADM_lall )
real(8) :: pre_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl)
!--- temperature ( physical )
real(8) :: tem (ADM_gall, ADM_kall,ADM_lall )
real(8) :: tem_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl)
!--- potential temperature ( physical )
real(8) :: th (ADM_gall, ADM_kall,ADM_lall )
real(8) :: th_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl)
!--- density deviation from the base state ( G^{1/2} X gamma2 )
real(8) :: rhogd (ADM_gall, ADM_kall,ADM_lall )
real(8) :: rhogd_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl)
!--- pressure deviation from the base state ( G^{1/2} X gamma2 )
real(8) :: pregd (ADM_gall, ADM_kall,ADM_lall )
real(8) :: pregd_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl)
!--- temperature deviation from the base state ( physical )
real(8) :: temd (ADM_gall, ADM_kall,ADM_lall )
real(8) :: temd_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl)
!--- temporary variables
real(8) :: qd (ADM_gall, ADM_kall,ADM_lall )
real(8) :: qd_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl)
real(8) :: cv (ADM_gall, ADM_kall,ADM_lall )
real(8) :: cv_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl)
real(8), parameter :: TKE_MIN = 0.D0
real(8) :: TKEg_corr
integer :: small_step_ite
real(8) :: small_step_dt
logical :: ndg_TEND_out
logical, save :: iflag = .true.
integer, save :: num_of_iteration_lstep ! number of large steps ( 2-4 )
integer, save :: num_of_iteration_sstep(4) ! number of small steps in each of large steps
integer :: g, k ,l, nq, nl
integer :: i, j, suf
suf(i,j) = ADM_gall_1d * ((j)-1) + (i)
!---------------------------------------------------------------------------
#ifdef PAPI_OPS
! <-- [add] PAPI R.Yoshida 20121022
!call PAPIF_flips( PAPI_real_time_i, PAPI_proc_time_i, PAPI_flpins, PAPI_mflins, PAPI_check )
call PAPIF_flops( PAPI_real_time_o, PAPI_proc_time_o, PAPI_flpops, PAPI_mflops, PAPI_check )
#endif
call DEBUG_rapstart('++Dynamics')
if ( iflag ) then
iflag = .false.
select case(trim(TIME_INTEG_TYPE))
case('RK2')
num_of_iteration_lstep = 2
num_of_iteration_sstep(1) = TIME_SSTEP_MAX / 2
num_of_iteration_sstep(2) = TIME_SSTEP_MAX
case('RK3')
num_of_iteration_lstep = 3
num_of_iteration_sstep(1) = TIME_SSTEP_MAX / 3
num_of_iteration_sstep(2) = TIME_SSTEP_MAX / 2
num_of_iteration_sstep(3) = TIME_SSTEP_MAX
case('RK4')
num_of_iteration_lstep = 4
num_of_iteration_sstep(1) = TIME_SSTEP_MAX / 4
num_of_iteration_sstep(2) = TIME_SSTEP_MAX / 3
num_of_iteration_sstep(3) = TIME_SSTEP_MAX / 2
num_of_iteration_sstep(4) = TIME_SSTEP_MAX
case('TRCADV') ! R.Yoshida 13/06/13 [add]
num_of_iteration_lstep = 1
num_of_iteration_sstep(1) = 1
num_of_iteration_sstep(2) = 1
case default
write(*,*) 'Msg : Sub[sub_dynstep]'
write(*,*) ' --- Error : invalid TIME_INTEG_TYPE=', TIME_INTEG_TYPE
endselect
endif
!--- get from prg0
call prgvar_get( PROG(:,:,:,I_RHOG), PROG_pl(:,:,:,I_RHOG), & !--- [OUT]
PROG(:,:,:,I_RHOGVX), PROG_pl(:,:,:,I_RHOGVX), & !--- [OUT]
PROG(:,:,:,I_RHOGVY), PROG_pl(:,:,:,I_RHOGVY), & !--- [OUT]
PROG(:,:,:,I_RHOGVZ), PROG_pl(:,:,:,I_RHOGVZ), & !--- [OUT]
PROG(:,:,:,I_RHOGW), PROG_pl(:,:,:,I_RHOGW), & !--- [OUT]
PROG(:,:,:,I_RHOGE), PROG_pl(:,:,:,I_RHOGE), & !--- [OUT]
PROGq(:,:,:,:), PROGq_pl(:,:,:,:), & !--- [OUT]
0 ) !--- [IN]
!--- save
PROG0 (:,:,:,:) = PROG (:,:,:,:)
PROG0_pl(:,:,:,:) = PROG_pl(:,:,:,:)
if ( TRC_ADV_TYPE == 'DEFAULT' ) then
if ( trim(TIME_INTEG_TYPE) == 'TRCADV' ) then
write(ADM_LOG_FID,*) 'Tracer Advection Test Mode'
write(ADM_LOG_FID,*) 'does not support current setting. STOP.'
call ADM_proc_stop
endif
PROGq0 (:,:,:,:) = PROGq (:,:,:,:)
PROGq0_pl(:,:,:,:) = PROGq_pl(:,:,:,:)
endif
!---------------------------------------------------------------------------
!
!> Start large time step integration
!
!---------------------------------------------------------------------------
do nl = 1, num_of_iteration_lstep
if ( trim(TIME_INTEG_TYPE) /= 'TRCADV' ) then ! TRC-ADV Test Bifurcation
!---< Generate diagnostic values and set the boudary conditions
rho(:,:,:) = PROG(:,:,:,I_RHOG ) / VMTR_GSGAM2(:,:,:)
vx (:,:,:) = PROG(:,:,:,I_RHOGVX) / PROG(:,:,:,I_RHOG)
vy (:,:,:) = PROG(:,:,:,I_RHOGVY) / PROG(:,:,:,I_RHOG)
vz (:,:,:) = PROG(:,:,:,I_RHOGVZ) / PROG(:,:,:,I_RHOG)
ein(:,:,:) = PROG(:,:,:,I_RHOGE ) / PROG(:,:,:,I_RHOG)
do nq = 1, TRC_VMAX
q(:,:,:,nq) = PROGq(:,:,:,nq) / PROG(:,:,:,I_RHOG)
enddo
cv(:,:,:) = 0.D0
qd(:,:,:) = 1.D0
do nq = NQW_STR, NQW_END
cv(:,:,:) = cv(:,:,:) + q(:,:,:,nq) * CVW(nq)
qd(:,:,:) = qd(:,:,:) - q(:,:,:,nq)
enddo
cv(:,:,:) = cv(:,:,:) + qd(:,:,:) * CNST_CV
tem(:,:,:) = ein(:,:,:) / cv(:,:,:)
pre(:,:,:) = rho(:,:,:) * tem(:,:,:) * ( qd(:,:,:)*CNST_RAIR + q(:,:,:,I_QV)*CNST_RVAP )
do l = 1, ADM_lall
do k = ADM_kmin+1, ADM_kmax
do g = 1, ADM_gall
w(g,k,l) = PROG(g,k,l,I_RHOGW) &
/ ( VMTR_GSGAM2H(g,k,l) * 0.5D0 * ( GRD_afac(k) * rho(g,k ,l) &
+ GRD_bfac(k) * rho(g,k-1,l) ) )
enddo
enddo
!--- boundary conditions
call bndcnd_all( ADM_gall, & !--- [IN]
rho (:,:,l), & !--- [INOUT]
vx (:,:,l), & !--- [INOUT]
vy (:,:,l), & !--- [INOUT]
vz (:,:,l), & !--- [INOUT]
w (:,:,l), & !--- [INOUT]
ein (:,:,l), & !--- [INOUT]
tem (:,:,l), & !--- [INOUT]
pre (:,:,l), & !--- [INOUT]
PROG(:,:,l,I_RHOG), & !--- [INOUT]
PROG(:,:,l,I_RHOGVX), & !--- [INOUT]
PROG(:,:,l,I_RHOGVY), & !--- [INOUT]
PROG(:,:,l,I_RHOGVZ), & !--- [INOUT]
PROG(:,:,l,I_RHOGW), & !--- [INOUT]
PROG(:,:,l,I_RHOGE), & !--- [INOUT]
VMTR_GSGAM2 (:,:,l), & !--- [IN]
VMTR_GSGAM2H(:,:,l), & !--- [IN]
VMTR_PHI (:,:,l), & !--- [IN]
VMTR_C2Wfact(:,:,:,l) ) !--- [IN]
call thrmdyn_th( ADM_gall, th(:,:,l), tem(:,:,l), pre(:,:,l) )
call thrmdyn_eth( ADM_gall, eth(:,:,l), ein(:,:,l), pre(:,:,l), rho(:,:,l) )
enddo ! region LOOP
!--- perturbations ( pred, rhod, temd )
pregd(:,:,:) = ( pre(:,:,:) - pre_bs(:,:,:) ) * VMTR_GSGAM2(:,:,:)
rhogd(:,:,:) = ( rho(:,:,:) - rho_bs(:,:,:) ) * VMTR_GSGAM2(:,:,:)
temd (:,:,:) = tem(:,:,:) - tem_bs(:,:,:)
if ( ADM_prc_me == ADM_prc_pl ) then
rho_pl(:,:,:) = PROG_pl(:,:,:,I_RHOG ) / VMTR_GSGAM2_pl(:,:,:)
vx_pl (:,:,:) = PROG_pl(:,:,:,I_RHOGVX) / PROG_pl(:,:,:,I_RHOG)
vy_pl (:,:,:) = PROG_pl(:,:,:,I_RHOGVY) / PROG_pl(:,:,:,I_RHOG)
vz_pl (:,:,:) = PROG_pl(:,:,:,I_RHOGVZ) / PROG_pl(:,:,:,I_RHOG)
ein_pl(:,:,:) = PROG_pl(:,:,:,I_RHOGE ) / PROG_pl(:,:,:,I_RHOG)
do nq = 1, TRC_VMAX
q_pl(:,:,:,nq) = PROGq_pl(:,:,:,nq) / PROG_pl(:,:,:,I_RHOG)
enddo
cv_pl(:,:,:) = 0.D0
qd_pl(:,:,:) = 1.D0
do nq = NQW_STR, NQW_END
cv_pl(:,:,:) = cv_pl(:,:,:) + q_pl(:,:,:,nq) * CVW(nq)
qd_pl(:,:,:) = qd_pl(:,:,:) - q_pl(:,:,:,nq)
enddo
cv_pl(:,:,:) = cv_pl(:,:,:) + qd_pl(:,:,:) * CNST_CV
tem_pl(:,:,:) = ein_pl(:,:,:) / cv_pl(:,:,:)
pre_pl(:,:,:) = rho_pl(:,:,:) * tem_pl(:,:,:) * ( qd_pl(:,:,:)*CNST_RAIR + q_pl(:,:,:,I_QV)*CNST_RVAP )
do l = 1, ADM_lall_pl
do k = ADM_kmin+1, ADM_kmax
do g = 1, ADM_gall_pl
w_pl(g,k,l) = PROG_pl(g,k,l,I_RHOGW) &
/ ( VMTR_GSGAM2H_pl(g,k,l) * 0.5D0 * ( GRD_afac(k) * rho_pl(g,k ,l) &
+ GRD_bfac(k) * rho_pl(g,k-1,l) ) )
enddo
enddo
!--- boundary conditions
call bndcnd_all( ADM_gall_pl, & !--- [IN]
rho_pl (:,:,l), & !--- [INOUT]
vx_pl (:,:,l), & !--- [INOUT]
vy_pl (:,:,l), & !--- [INOUT]
vz_pl (:,:,l), & !--- [INOUT]
w_pl (:,:,l), & !--- [INOUT]
ein_pl (:,:,l), & !--- [INOUT]
tem_pl (:,:,l), & !--- [INOUT]
pre_pl (:,:,l), & !--- [INOUT]
PROG_pl(:,:,l,I_RHOG), & !--- [INOUT]
PROG_pl(:,:,l,I_RHOGVX), & !--- [INOUT]
PROG_pl(:,:,l,I_RHOGVY), & !--- [INOUT]
PROG_pl(:,:,l,I_RHOGVZ), & !--- [INOUT]
PROG_pl(:,:,l,I_RHOGW), & !--- [INOUT]
PROG_pl(:,:,l,I_RHOGE), & !--- [INOUT]
VMTR_GSGAM2_pl (:,:,l), & !--- [IN]
VMTR_GSGAM2H_pl(:,:,l), & !--- [IN]
VMTR_PHI_pl (:,:,l), & !--- [IN]
VMTR_C2Wfact_pl(:,:,:,l) ) !--- [IN]
call thrmdyn_th( ADM_gall_pl, th_pl(:,:,l), tem_pl(:,:,l), pre_pl(:,:,l) )
call thrmdyn_eth( ADM_gall_pl, eth_pl(:,:,l), ein_pl(:,:,l), pre_pl(:,:,l), rho_pl(:,:,l) )
enddo
pregd_pl(:,:,:) = ( pre_pl(:,:,:) - pre_bs_pl(:,:,:) ) * VMTR_GSGAM2_pl(:,:,:)
rhogd_pl(:,:,:) = ( rho_pl(:,:,:) - rho_bs_pl(:,:,:) ) * VMTR_GSGAM2_pl(:,:,:)
temd_pl (:,:,:) = tem_pl(:,:,:) - tem_bs_pl(:,:,:)
else
rho_pl(:,:,:) = 0.D0
vx_pl (:,:,:) = 0.D0
vy_pl (:,:,:) = 0.D0
vz_pl (:,:,:) = 0.D0
w_pl (:,:,:) = 0.D0
ein_pl(:,:,:) = 0.D0
q_pl (:,:,:,:) = 0.D0
tem_pl(:,:,:) = 0.D0
pre_pl(:,:,:) = 0.D0
th_pl (:,:,:) = 0.D0
eth_pl(:,:,:) = 0.D0
pregd_pl(:,:,:) = 0.D0
rhogd_pl(:,:,:) = 0.D0
temd_pl (:,:,:) = 0.D0
endif
!------------------------------------------------------------------------
!> LARGE step
!------------------------------------------------------------------------
call DEBUG_rapstart('+++Large step')
!--- calculation of advection tendency including Coriolis force
call src_advection_convergence_momentum( vx, vx_pl, & !--- [IN]
vy, vy_pl, & !--- [IN]
vz, vz_pl, & !--- [IN]
w, w_pl, & !--- [IN]
PROG (:,:,:,I_RHOG ), PROG_pl (:,:,:,I_RHOG ), & !--- [IN]
PROG (:,:,:,I_RHOGVX), PROG_pl (:,:,:,I_RHOGVX), & !--- [IN]
PROG (:,:,:,I_RHOGVY), PROG_pl (:,:,:,I_RHOGVY), & !--- [IN]
PROG (:,:,:,I_RHOGVZ), PROG_pl (:,:,:,I_RHOGVZ), & !--- [IN]
PROG (:,:,:,I_RHOGW ), PROG_pl (:,:,:,I_RHOGW ), & !--- [IN]
g_TEND(:,:,:,I_RHOGVX), g_TEND_pl(:,:,:,I_RHOGVX), & !--- [OUT]
g_TEND(:,:,:,I_RHOGVY), g_TEND_pl(:,:,:,I_RHOGVY), & !--- [OUT]
g_TEND(:,:,:,I_RHOGVZ), g_TEND_pl(:,:,:,I_RHOGVZ), & !--- [OUT]
g_TEND(:,:,:,I_RHOGW ), g_TEND_pl(:,:,:,I_RHOGW ) ) !--- [OUT]
g_TEND (:,:,:,I_RHOG) = 0.D0
g_TEND (:,:,:,I_RHOGE) = 0.D0
g_TEND (:,:,:,I_RHOGETOT) = 0.D0
g_TEND_pl(:,:,:,I_RHOG) = 0.D0
g_TEND_pl(:,:,:,I_RHOGE) = 0.D0
g_TEND_pl(:,:,:,I_RHOGETOT) = 0.D0
!---< numerical diffusion term
if ( NDIFF_LOCATION == 'IN_LARGE_STEP' ) then
if ( nl == 1 ) then ! only first step
f_TEND (:,:,:,:) = 0.D0
f_TEND_pl (:,:,:,:) = 0.D0
f_TENDq (:,:,:,:) = 0.D0
f_TENDq_pl(:,:,:,:) = 0.D0
!------ numerical diffusion
call numfilter_hdiffusion( rho, rho_pl, & !--- [IN]
vx, vx_pl, & !--- [IN]
vy, vy_pl, & !--- [IN]
vz, vz_pl, & !--- [IN]
w, w_pl, & !--- [IN]
temd, temd_pl, & !--- [IN]
q, q_pl, & !--- [IN]
f_TEND (:,:,:,I_RHOG ), f_TEND_pl (:,:,:,I_RHOG ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGVX ), f_TEND_pl (:,:,:,I_RHOGVX ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGVY ), f_TEND_pl (:,:,:,I_RHOGVY ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGVZ ), f_TEND_pl (:,:,:,I_RHOGVZ ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGW ), f_TEND_pl (:,:,:,I_RHOGW ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGE ), f_TEND_pl (:,:,:,I_RHOGE ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGETOT), f_TEND_pl (:,:,:,I_RHOGETOT), & !--- [INOUT]
f_TENDq(:,:,:,:), f_TENDq_pl(:,:,:,:) ) !--- [INOUT]
if ( NUMFILTER_DOverticaldiff ) then ! numerical diffusion (vertical)
call numfilter_vdiffusion( rho, rho_pl, & !--- [IN]
vx, vx_pl, & !--- [IN]
vy, vy_pl, & !--- [IN]
vz, vz_pl, & !--- [IN]
w, w_pl, & !--- [IN]
temd, temd_pl, & !--- [IN]
q, q_pl, & !--- [IN]
f_TEND (:,:,:,I_RHOG ), f_TEND_pl (:,:,:,I_RHOG ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGVX ), f_TEND_pl (:,:,:,I_RHOGVX ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGVY ), f_TEND_pl (:,:,:,I_RHOGVY ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGVZ ), f_TEND_pl (:,:,:,I_RHOGVZ ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGW ), f_TEND_pl (:,:,:,I_RHOGW ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGE ), f_TEND_pl (:,:,:,I_RHOGE ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGETOT), f_TEND_pl (:,:,:,I_RHOGETOT), & !--- [INOUT]
f_TENDq(:,:,:,:), f_TENDq_pl(:,:,:,:) ) !--- [INOUT]
endif
if ( NUMFILTER_DOrayleigh ) then ! rayleigh damping
call numfilter_rayleigh_damping( rho, rho_pl, & !--- [IN]
vx, vx_pl, & !--- [IN]
vy, vy_pl, & !--- [IN]
vz, vz_pl, & !--- [IN]
w, w_pl, & !--- [IN]
f_TEND (:,:,:,I_RHOGVX ), f_TEND_pl (:,:,:,I_RHOGVX ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGVY ), f_TEND_pl (:,:,:,I_RHOGVY ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGVZ ), f_TEND_pl (:,:,:,I_RHOGVZ ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGW ), f_TEND_pl (:,:,:,I_RHOGW ) ) !--- [INOUT]
endif
endif
elseif( NDIFF_LOCATION == 'IN_LARGE_STEP2' ) then
f_TEND (:,:,:,:) = 0.D0
f_TEND_pl (:,:,:,:) = 0.D0
f_TENDq (:,:,:,:) = 0.D0
f_TENDq_pl(:,:,:,:) = 0.D0
!------ numerical diffusion
call numfilter_hdiffusion( rho, rho_pl, & !--- [IN]
vx, vx_pl, & !--- [IN]
vy, vy_pl, & !--- [IN]
vz, vz_pl, & !--- [IN]
w, w_pl, & !--- [IN]
temd, temd_pl, & !--- [IN]
q, q_pl, & !--- [IN]
f_TEND (:,:,:,I_RHOG ), f_TEND_pl (:,:,:,I_RHOG ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGVX ), f_TEND_pl (:,:,:,I_RHOGVX ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGVY ), f_TEND_pl (:,:,:,I_RHOGVY ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGVZ ), f_TEND_pl (:,:,:,I_RHOGVZ ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGW ), f_TEND_pl (:,:,:,I_RHOGW ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGE ), f_TEND_pl (:,:,:,I_RHOGE ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGETOT), f_TEND_pl (:,:,:,I_RHOGETOT), & !--- [INOUT]
f_TENDq(:,:,:,:), f_TENDq_pl(:,:,:,:) ) !--- [INOUT]
if ( NUMFILTER_DOverticaldiff ) then ! numerical diffusion (vertical)
call numfilter_vdiffusion( rho, rho_pl, & !--- [IN]
vx, vx_pl, & !--- [IN]
vy, vy_pl, & !--- [IN]
vz, vz_pl, & !--- [IN]
w, w_pl, & !--- [IN]
temd, temd_pl, & !--- [IN]
q, q_pl, & !--- [IN]
f_TEND (:,:,:,I_RHOG ), f_TEND_pl (:,:,:,I_RHOG ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGVX ), f_TEND_pl (:,:,:,I_RHOGVX ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGVY ), f_TEND_pl (:,:,:,I_RHOGVY ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGVZ ), f_TEND_pl (:,:,:,I_RHOGVZ ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGW ), f_TEND_pl (:,:,:,I_RHOGW ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGE ), f_TEND_pl (:,:,:,I_RHOGE ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGETOT), f_TEND_pl (:,:,:,I_RHOGETOT), & !--- [INOUT]
f_TENDq(:,:,:,:), f_TENDq_pl(:,:,:,:) ) !--- [INOUT]
endif
if ( NUMFILTER_DOrayleigh ) then ! rayleigh damping
call numfilter_rayleigh_damping( rho, rho_pl, & !--- [IN]
vx, vx_pl, & !--- [IN]
vy, vy_pl, & !--- [IN]
vz, vz_pl, & !--- [IN]
w, w_pl, & !--- [IN]
f_TEND (:,:,:,I_RHOGVX ), f_TEND_pl (:,:,:,I_RHOGVX ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGVY ), f_TEND_pl (:,:,:,I_RHOGVY ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGVZ ), f_TEND_pl (:,:,:,I_RHOGVZ ), & !--- [INOUT]
f_TEND (:,:,:,I_RHOGW ), f_TEND_pl (:,:,:,I_RHOGW ) ) !--- [INOUT]
endif
endif
! Smagorinksy-type SGS model [add] A.Noda 10/11/29
if ( TB_TYPE == 'SMG' ) then
!cx
write(0,'(a)') "*** Error. Smagorinksy model was removed in mini-version."
stop
!cx
endif
!--- Nudging routines [add] Y.Niwa 08/09/09
if ( FLAG_NUDGING ) then
!cx
write(0,'(a)') "*** Error. Nudging function was removed in mini-version."
stop
!cx
endif
!--- sum the large step TEND ( advection + coriolis + num.diff.,SGS,nudge )
g_TEND (:,:,:,:) = g_TEND (:,:,:,:) + f_TEND (:,:,:,:)
g_TEND_pl(:,:,:,:) = g_TEND_pl(:,:,:,:) + f_TEND_pl(:,:,:,:)
call DEBUG_rapend ('+++Large step')
!------------------------------------------------------------------------
!> SMALL step
!------------------------------------------------------------------------
call DEBUG_rapstart('+++Small step')
if ( nl /= 1 ) then ! update split values
PROG_split (:,:,:,:) = PROG0 (:,:,:,:) - PROG (:,:,:,:)
PROG_split_pl(:,:,:,:) = PROG0_pl(:,:,:,:) - PROG_pl(:,:,:,:)
else
PROG_split (:,:,:,:) = 0.D0
PROG_split_pl(:,:,:,:) = 0.D0
endif
!------ Core routine for small step
!------ 1. By this subroutine, prognostic variables
!------ ( rho,.., rhoge ) are calculated through
!------ the 'num_of_iteration_sstep(nl)'-th times small step.
!------ 2. grho, grhogvx, ..., and grhoge has the large step
!------ tendencies initially, however,
!------ they are re-used in this subroutine.
!------
if ( TIME_SPLIT ) then
small_step_ite = num_of_iteration_sstep(nl)
small_step_dt = TIME_DTS
else
small_step_ite = 1
small_step_dt = TIME_DTL / (num_of_iteration_lstep+1-nl)
endif
call vi_small_step( PROG(:,:,:,I_RHOG ), PROG_pl(:,:,:,I_RHOG ), & !--- [INOUT] prognostic variables
PROG(:,:,:,I_RHOGVX), PROG_pl(:,:,:,I_RHOGVX), & !--- [INOUT]
PROG(:,:,:,I_RHOGVY), PROG_pl(:,:,:,I_RHOGVY), & !--- [INOUT]
PROG(:,:,:,I_RHOGVZ), PROG_pl(:,:,:,I_RHOGVZ), & !--- [INOUT]
PROG(:,:,:,I_RHOGW ), PROG_pl(:,:,:,I_RHOGW ), & !--- [INOUT]
PROG(:,:,:,I_RHOGE ), PROG_pl(:,:,:,I_RHOGE ), & !--- [INOUT]
vx, vx_pl, & !--- [IN] diagnostic value
vy, vy_pl, & !--- [IN]
vz, vz_pl, & !--- [IN]
eth, eth_pl, & !--- [IN]
rhogd, rhogd_pl, & !--- [IN]
pregd, pregd_pl, & !--- [IN]
g_TEND(:,:,:,I_RHOG ), g_TEND_pl(:,:,:,I_RHOG ), & !--- [IN] large step TEND
g_TEND(:,:,:,I_RHOGVX ), g_TEND_pl(:,:,:,I_RHOGVX ), & !--- [IN]
g_TEND(:,:,:,I_RHOGVY ), g_TEND_pl(:,:,:,I_RHOGVY ), & !--- [IN]
g_TEND(:,:,:,I_RHOGVZ ), g_TEND_pl(:,:,:,I_RHOGVZ ), & !--- [IN]
g_TEND(:,:,:,I_RHOGW ), g_TEND_pl(:,:,:,I_RHOGW ), & !--- [IN]
g_TEND(:,:,:,I_RHOGE ), g_TEND_pl(:,:,:,I_RHOGE ), & !--- [IN]
g_TEND(:,:,:,I_RHOGETOT), g_TEND_pl(:,:,:,I_RHOGETOT), & !--- [IN]
PROG_split(:,:,:,I_RHOG ), PROG_split_pl(:,:,:,I_RHOG ), & !--- [INOUT] split value
PROG_split(:,:,:,I_RHOGVX), PROG_split_pl(:,:,:,I_RHOGVX), & !--- [INOUT]
PROG_split(:,:,:,I_RHOGVY), PROG_split_pl(:,:,:,I_RHOGVY), & !--- [INOUT]
PROG_split(:,:,:,I_RHOGVZ), PROG_split_pl(:,:,:,I_RHOGVZ), & !--- [INOUT]
PROG_split(:,:,:,I_RHOGW ), PROG_split_pl(:,:,:,I_RHOGW ), & !--- [INOUT]
PROG_split(:,:,:,I_RHOGE ), PROG_split_pl(:,:,:,I_RHOGE ), & !--- [INOUT]
v_mean_c, v_mean_c_pl, & !--- [OUT] mean value
small_step_ite, & !--- [IN]
small_step_dt ) !--- [IN]
call DEBUG_rapend ('+++Small step')
else ! TRC-ADV Test Bifurcation
!--- Make v_mean_c ![add] 20130613 R.Yoshida
!--- save point(old) is mean here (although it is not exactly valid for rho)
v_mean_c(:,:,:,I_rhog) = PROG0(:,:,:,I_rhog); v_mean_c_pl(:,:,:,I_rhog) = PROG0_pl(:,:,:,I_rhog)
v_mean_c(:,:,:,I_rhogvx)= PROG0(:,:,:,I_rhogvx); v_mean_c_pl(:,:,:,I_rhogvx)= PROG0_pl(:,:,:,I_rhogvx)
v_mean_c(:,:,:,I_rhogvy)= PROG0(:,:,:,I_rhogvy); v_mean_c_pl(:,:,:,I_rhogvy)= PROG0_pl(:,:,:,I_rhogvy)
v_mean_c(:,:,:,I_rhogvz)= PROG0(:,:,:,I_rhogvz); v_mean_c_pl(:,:,:,I_rhogvz)= PROG0_pl(:,:,:,I_rhogvz)
v_mean_c(:,:,:,I_rhogw) = PROG0(:,:,:,I_rhogw); v_mean_c_pl(:,:,:,I_rhogw) = PROG0_pl(:,:,:,I_rhogw)
endif ! TRC-ADV Test Bifurcation
!------------------------------------------------------------------------
!> Tracer advection
!------------------------------------------------------------------------
call DEBUG_rapstart('+++Tracer Advection')
if ( TRC_ADV_TYPE == 'MIURA2004' ) then
if ( nl == num_of_iteration_lstep ) then
call src_update_tracer( TRC_VMAX, & !--- [IN]
PROGq(:,:,:,:), PROGq_pl(:,:,:,:), & !--- [INOUT]
PROG0(:,:,:,I_RHOG), PROG0_pl(:,:,:,I_RHOG), & !--- [IN]
v_mean_c(:,:,:,I_rhog), v_mean_c_pl(:,:,:,I_rhog), & !--- [IN]
v_mean_c(:,:,:,I_rhogvx), v_mean_c_pl(:,:,:,I_rhogvx), & !--- [IN]
v_mean_c(:,:,:,I_rhogvy), v_mean_c_pl(:,:,:,I_rhogvy), & !--- [IN]
v_mean_c(:,:,:,I_rhogvz), v_mean_c_pl(:,:,:,I_rhogvz), & !--- [IN]
v_mean_c(:,:,:,I_rhogw), v_mean_c_pl(:,:,:,I_rhogw), & !--- [IN]
f_TEND (:,:,:,I_RHOG), f_TEND_pl (:,:,:,I_RHOG), & !--- [IN]
TIME_DTL, & !--- [IN]
THUBURN_LIM ) !--- [IN] ![add] 20130613 R.Yoshida
if( TIME_INTEG_TYPE /= 'TRCADV' ) PROGq(:,:,:,:) = PROGq(:,:,:,:) + TIME_DTL * f_TENDq(:,:,:,:) ! update rhogq by viscosity
PROGq(:,ADM_kmin-1,:,:) = 0.D0
PROGq(:,ADM_kmax+1,:,:) = 0.D0
if ( ADM_prc_pl == ADM_prc_me ) then
if( TIME_INTEG_TYPE /= 'TRCADV' ) PROGq_pl(:,:,:,:) = PROGq_pl(:,:,:,:) + TIME_DTL * f_TENDq_pl(:,:,:,:)
PROGq_pl(:,ADM_kmin-1,:,:) = 0.D0
PROGq_pl(:,ADM_kmax+1,:,:) = 0.D0
endif
! [comment] H.Tomita: I don't recommend adding the hyperviscosity term because of numerical instability in this case.
endif ! Last large step only
elseif( TRC_ADV_TYPE == 'DEFAULT' ) then
!This scheme isn't supported in TRC-ADV Test (20130612 R.Yoshida)
do nq = 1, TRC_VMAX
call src_advection_convergence( v_mean_c(:,:,:,I_rhogvx), v_mean_c_pl(:,:,:,I_rhogvx), & !--- [IN]
v_mean_c(:,:,:,I_rhogvy), v_mean_c_pl(:,:,:,I_rhogvy), & !--- [IN]
v_mean_c(:,:,:,I_rhogvz), v_mean_c_pl(:,:,:,I_rhogvz), & !--- [IN]
v_mean_c(:,:,:,I_rhogw), v_mean_c_pl(:,:,:,I_rhogw), & !--- [IN]
q(:,:,:,nq), q_pl(:,:,:,nq), & !--- [IN]
g_TENDq(:,:,:,nq), g_TENDq_pl(:,:,:,nq), & !--- [OUT]
I_SRC_default ) !--- [IN] [mod] H.Yashiro 20120530
PROGq(:,:,:,:) = PROGq0(:,:,:,:) &
+ ( num_of_iteration_sstep(nl) * TIME_DTS ) * ( g_TENDq(:,:,:,:) + f_TENDq(:,:,:,:) )
PROGq(:,ADM_kmin-1,:,:) = 0.D0
PROGq(:,ADM_kmax+1,:,:) = 0.D0
if ( ADM_prc_pl == ADM_prc_me ) then
PROGq_pl(:,:,:,:) = PROGq0_pl(:,:,:,:) &
+ ( num_of_iteration_sstep(nl) * TIME_DTS ) &
* ( g_TENDq_pl(:,:,:,:) + f_TENDq_pl(:,:,:,:) )
PROGq_pl(:,ADM_kmin-1,:,:) = 0.D0
PROGq_pl(:,ADM_kmax+1,:,:) = 0.D0
endif
enddo ! tracer LOOP
endif
call DEBUG_rapend ('+++Tracer Advection')
if ( trim(TIME_INTEG_TYPE) /= 'TRCADV' ) then ! TRC-ADV Test Bifurcation
!--- TKE fixer ( TKE >= 0.D0 )
! 2011/08/16 M.Satoh [comment] need this fixer for every small time steps
if ( I_TKE >= 0 ) then
if ( TRC_ADV_TYPE == 'DEFAULT' .OR. nl == num_of_iteration_lstep ) then
do l = 1, ADM_lall
do k = 1, ADM_kall
do g = 1, ADM_gall
TKEg_corr = TKE_MIN * VMTR_GSGAM2(g,k,l) - PROGq(g,k,l,I_TKE)
if ( TKEg_corr >= 0.D0 ) then
PROG (g,k,l,I_RHOGE) = PROG (g,k,l,I_RHOGE) - TKEg_corr
PROGq(g,k,l,I_TKE) = PROGq(g,k,l,I_TKE) + TKEg_corr
endif
enddo
enddo
enddo
if ( ADM_prc_pl == ADM_prc_me ) then
do l = 1, ADM_lall_pl
do k = 1, ADM_kall
do g = 1, ADM_gall_pl
TKEg_corr = TKE_MIN * VMTR_GSGAM2_pl(g,k,l) - PROGq_pl(g,k,l,I_TKE)
if ( TKEg_corr >= 0.D0 ) then
PROG_pl (g,k,l,I_RHOGE) = PROG_pl (g,k,l,I_RHOGE) - TKEg_corr
PROGq_pl(g,k,l,I_TKE) = PROGq_pl(g,k,l,I_TKE) + TKEg_corr
endif
enddo
enddo
enddo
endif
endif
endif
!------ Update
if ( nl /= num_of_iteration_lstep ) then
! communication
call COMM_data_transfer( PROG, PROG_pl )
PROG(suf(ADM_gall_1d,1),:,:,:) = PROG(suf(ADM_gmax+1,ADM_gmin),:,:,:)
PROG(suf(1,ADM_gall_1d),:,:,:) = PROG(suf(ADM_gmin,ADM_gmax+1),:,:,:)
endif
endif ! TRC-ADV Test Bifurcation
enddo !--- large step
if ( trim(TIME_INTEG_TYPE) == 'TRCADV' ) then
call updating( PROG0(:,:,:,:), PROG0_pl(:,:,:,:), & !--- [IN]
PROG (:,:,:,:), PROG_pl (:,:,:,:) ) !--- [INOUT]
endif
call prgvar_set( PROG(:,:,:,I_RHOG), PROG_pl(:,:,:,I_RHOG), & !--- [IN]
PROG(:,:,:,I_RHOGVX), PROG_pl(:,:,:,I_RHOGVX), & !--- [IN]
PROG(:,:,:,I_RHOGVY), PROG_pl(:,:,:,I_RHOGVY), & !--- [IN]
PROG(:,:,:,I_RHOGVZ), PROG_pl(:,:,:,I_RHOGVZ), & !--- [IN]
PROG(:,:,:,I_RHOGW), PROG_pl(:,:,:,I_RHOGW), & !--- [IN]
PROG(:,:,:,I_RHOGE), PROG_pl(:,:,:,I_RHOGE), & !--- [IN]
PROGq(:,:,:,:), PROGq_pl(:,:,:,:), & !--- [IN]
0 ) !--- [IN]
call DEBUG_rapend ('++Dynamics')
#ifdef PAPI_OPS
! <-- [add] PAPI R.Yoshida 20121022
!call PAPIF_flips( PAPI_real_time_i, PAPI_proc_time_i, PAPI_flpins, PAPI_mflins, PAPI_check )
call PAPIF_flops( PAPI_real_time_o, PAPI_proc_time_o, PAPI_flpops, PAPI_mflops, PAPI_check )
#endif
return
end subroutine dynstep
end module mod_dynstep
|
Formal statement is: lemma translation_galois: fixes a :: "'a::ab_group_add" shows "T = ((\<lambda>x. a + x) ` S) \<longleftrightarrow> S = ((\<lambda>x. (- a) + x) ` T)" Informal statement is: For any set $S$ and any element $a$, the set $T = \{a + x \mid x \in S\}$ is equal to the set $\{-a + x \mid x \in S\}$. |
#' Compute metacell using a native implementation of a graph cover k-means-like approach
#'
#' @param mc_id id of metacell object to be added
#' @param graph_id a knn graph object id into scdb
#' @param mat_id a matrix object id
#' @param min_mc_size target minimum metacell size. This is only an approximation and smaller MC may be returned by the algorithm
#'
mcell_add_mc_from_graph = function(mc_id, graph_id, mat_id, min_mc_size)
{
old_seed = .set_seed(get_param("mc_rseed"))
tgs_clust_cool = get_param("scm_tgs_clust_cool")
tgs_clust_burn = get_param("scm_tgs_clust_burn_in")
graph = scdb_cgraph(graph_id)
if(is.null(graph)) {
stop("MC-ERR: cell graph id ", graph_id, " is missing when running add_mc_from_graph")
}
mat = scdb_mat(mat_id)
if(is.null(mat)) {
stop("MC-ERR: mat id ", mat_id, " is missing when running add_mc_from_graph")
}
message("running graph clustering now - one iteration no bootstrap")
edges = graph@edges
colnames(edges) = c("col1", "col2", "weight")
node_clust = tgs_graph_cover(edges, min_mc_size, cooling = tgs_clust_cool, burn_in = tgs_clust_burn)
f_outlier = (node_clust$cluster == 0)
outliers = colnames(mat@mat)[node_clust$node[f_outlier]]
mc = as.integer(as.factor(node_clust$cluster[!f_outlier]))
names(mc) = colnames(mat@mat)[!f_outlier]
message("building metacell object, #mc ", max(mc))
cell_names = colnames(mat@mat)
scdb_add_mc(mc_id, tgMCCov(mc, outliers, mat))
message("reordering metacells by hclust and most variable two markers")
.restore_seed(old_seed)
mcell_mc_reorder_hc(mc_id)
}
|
[STATEMENT]
lemma fresh_subst:
fixes z::"name"
assumes a: "z\<sharp>t\<^sub>1" "z\<sharp>t\<^sub>2"
shows "z\<sharp>t\<^sub>1[y::=t\<^sub>2]"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. z \<sharp> t\<^sub>1[y::=t\<^sub>2]
[PROOF STEP]
using a
[PROOF STATE]
proof (prove)
using this:
z \<sharp> t\<^sub>1
z \<sharp> t\<^sub>2
goal (1 subgoal):
1. z \<sharp> t\<^sub>1[y::=t\<^sub>2]
[PROOF STEP]
by (auto simp add: fresh_subst' abs_fresh) |
\chapter{Project Management}
\label{chap:final-project-management}
In this chapter, we evaluate the overall project management during the thesis. Indeed, as defined in the initial specifications, the milestones were meant to be adjustable based on the project iterations. Our primary constraint for the Master's Thesis was the time: indeed, the project is formally framed to start on the 17th of September 2019 and end on 7th of February 2020, for a total of amount of 900 hours. To evaluate the project management, we plan three steps; first, we take a high-level overview and comment on the two project phases, the \glsfirst{sota} research and GraphQA as our research contribution. Secondly, we will review and reflect on the initial specification, and finally conclude on the overall management.
\section{High-Level Overview}
Initially defined as \textit{Back to Level} and \textit{Diving into the Subject}, the two phases had the same meaning overall to, what we believe to be, our academic vision defined as Research and Contribution. In this chapter, we take a step back to visualize the entire work done as a whole to summarise the exciting adventure of our first academic research.
\subsection{State-of-the-Art Research}
Our first step to avoid being overwhelmed with knowledge from the most advanced \gls{nlp} papers in the field of \gls{qa} systems and \glspl{gs} was to plan the research. As we did not have the tools to understand the papers properly, we decided to define a workflow to gather valuable information, such as the initial tools to get started with more complicated techniques. The listing below shows our procedure.
\begin{itemize}
\setlength\itemsep{0em}
\item Get up to date with the \gls{nlp} technologies used at our lab, \textit{iCoSys}.
\item Explore community-made curated lists\footnote{\textit{Awesome} NLP lists from \url{github.com}}.
\item Subscribe to various specilized social medias to stay informed of the latest \gls{nlp} breakthroughs \footnote{Examples from \url{reddit.com} /r/MachineLearning, /r/LanguageTechnology, /r/deeplearning}.
\item Read reviews and article summarises of recent papers\footnote{Particularly from community based \url{medium.com} articles}.
\item Deeply analyse the latest breakthrough papers and read all the mentioned paper.
\item Filter and read the latest preprints \footnote{Most of the articles are coming from \url{arxiv.com} and \url{aclweb.org}}.
\end{itemize}
Using this workflow, we could in 6 weeks read about 40 papers and gently examine 40 others, which we believe gave us an approximately fair overview of the \gls{nlp} field, and particularly of the \gls{qa} systems and \glspl{gs}.
\subsection{Research Contribution}
Based on the accumulated knowledge from the \gls{sota} research, we could analyze the current techniques used and their applications in the field of \gls{nlp}, in particular, for \gls{qa} systems and \glspl{gs}. Which helped us define a scope for the project that would make sense in the scope of a Master's Thesis to contribute to \gls{nlp}. Gladly, our constraint to use \gls{wikidata} \gls{kb} could sharpen the possible contributions. As stated in our analysis \ref{chap:analysis}, we went through multiple brainstorming and project iterations to get to GraphQA. From a management point of view, it appears that we respected the initial planning and honored the objectives defined in the initial project specification. Finally, we believe that our work could contribute to \gls{nlp}, making the second phase as a success.
\section{Specification Review}
In this section, we review the original specifications by adding comments as a retrospective approach. We keep the structure and often paraphrase the original content. To improve reading, when content is reused or paraphrased, we set it in \textit{italic} and in \textbf{bold} for comments. Additionally, for use the \checkmark and $\times$ bullets to mark items as realized or not realized.
\subsection{Intrinsic Objectives}
\subsubsection{Primaries}
In this section we presented the tasks that we believed to be essential to get started with the master's thesis.
\begin{itemize}[noitemsep]
\item[\checkmark] \textit{Propose a project specification and planning.} %\textbf{We added the initial brainstormed tasks to the annexes.}
\item[\checkmark] \textit{Analyze the \gls{sota} of existing technologies and technics of \gls{qa} systems and \gls{generative} \gls{ai}.}
\item[\checkmark] \textit{Overview digital transformation in journalism} \textbf{Even if we did the study, we did not include the search as the project shifted toward chatbots and \gls{nlp}.}
\item[\checkmark] \textit{Review the current status of the AI-News project.}
\item[\checkmark] \textit{Document the study and write the thesis.}
\end{itemize}
%\todo{add the annexes numbering to for the brainstormed tasks}
\subsection{Fact-based Question-Answering Chatbot Objectives}
\textit{The first objective is to make, based on the \glsfirst{sota}, an algorithm that takes a question as input and outputs a response, as illustrated on Figure~\ref{fig:management_qa}}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=2.1cm,keepaspectratio=true]{intro_qa}
\caption{Suggested \gls{qa} diagram}
\label{fig:management_qa}
\end{figure}
\subsubsection{Primaries}
\begin{itemize}[noitemsep]
\item[\checkmark] \textit{Select existing papers and projects treating the subject as a starting point.}
\item[\checkmark] \textit{Identify relevant datasets.}
\item[\checkmark] \textit{Develop one or more \gls{poc}.}
\item[\checkmark] \textit{Test and evaluate solutions.}
\item[\checkmark] \textit{Suggest improvements, possible continuation, and future outcomes.}
\end{itemize}
\subsubsection{Secondaries}
\begin{itemize}[noitemsep]
\item[$\times$] \textit{Extend the \gls{qa} chatbot using "tailored" knowledge, e.g., \gls{model-ft} with press content.} \textbf{As mentioned in the final notes from the GraphQA chapter \ref{chap:graphqa}, this item can be extrapolated to GraphQA by adding a fine-tuned pretrain language model for a multi-brains approach to reach a consensus-based answer.}
\end{itemize}
\subsection{Natural Language Question Answering Chatbot Objectives}
\textit{The second objective was to extend the output from the \gls{qa} system, from the first objective, by enhancing the answers and generate human-like sentences from the enhanced answers. The initial vision for this objective is as illustrated in Figure~\ref{fig:planning_qa_gen}, a two parts system. The \textit{Enricher} enriches the answer from the \gls{qa} system, e.g. using a knowledge base\footnote{Wikidata.org, a Freebase-based \autocite{paper:bollacker2008} knowledge base or Google's Knowledge Graphs \autocite{blog:intro_knowledge_graph}}. The \textit{Generator} aims at creating readable text from the enriched answer. Besides, we could also use user profiles\footnote{Fictive profiles in the context of the thesis} as input to those two parts.}
\begin{figure}[ht!]
\centering
\includegraphics[width=\textwidth,keepaspectratio=true]{intro_qa_gen}
\caption{Suggested \gls{generative} \gls{qa} diagram}
\label{fig:planning_qa_gen}
\end{figure}
\paragraph{Primaries}
\begin{itemize}[noitemsep]
\item[\checkmark] \textit{Investigate a rule-based system for keyword enrichment.}
\item[\checkmark] \textit{Generate sentences with keywords.}
\item[\checkmark] \textit{Identify relevant datasets.}
\item[\checkmark] \textit{Develop one or more \gls{poc}.}
\item[\checkmark] \textit{Test and evaluate solutions.}
\item[\checkmark] \textit{Suggest improvements, possible continuation, and future outcomes.}
\end{itemize}
\paragraph{Secondaries}
\begin{itemize}[noitemsep]
\item[\checkmark] \textit{Use advanced strategies to enrich keywords.}
\item[\checkmark] \textit{Use advanced text generation technics such as GTP-2\footnote{OpenAI's GTP-2 Algorithm \autocite{papers:gpt2}}.}
\item[$\times$] \textit{Use user profiles to customize the outputs.} \textbf{This item is mentioned in the final notes from the GraphQA chapter \ref{chap:graphqa}. GraphQA could build long-term context graphs for each user to hold their preferences. It could hold particular interests (entities), injected for the user each time a new Sub-Knowledge Graph is generated. The result would be that GraphQA will try to find a path to the answer using the users injected interests.}
\end{itemize}
\subsection{Objectives Retrospective}
For the objectives, we indeed honored the primary functions and even could add secondary functions to the GraphQA. Even if initial planned, we did not build two distinct \glspl{poc}. Indeed, we started with an hybrid model combining the required features into a single \gls{poc} (see Figure \ref{fig:fig_planning_qa_gen_hybrid}).
\subsection{Methodologies}
\textit{For consistency, the project was separated into two methodological parts. In the first third, as the project targets information gathering and self-study, we used a standard sequential project management methodology. For the next two-thirds of the project, we used an agile methodology to perform incremental progress while exploring.}
\subsubsection{Back to level Milestones}
\textit{First third of the study, from 16.09.19 to 25.10.19 (6 weeks).}
\begin{enumerate}
\setlength\itemsep{0em}
\item[\checkmark M1.] \textit{Initial \gls{mt} plan and project specification}
\item[\checkmark M2.] \textit{Review the \gls{sota} for the \gls{nlp} and \gls{nlu} technologies and refine the plan if needed.}
\end{enumerate}
\subsubsection{Diving into the subject Milestones}
\textit{From 28.10.19 to 07.02.20 (13 weeks), the following two-third of the work is composed of 6 sprints of two weeks each and one week to finalize the thesis.}
\begin{itemize}
\setlength\itemsep{0em}
\item[\checkmark M3.] \textit{Basic \gls{qa} Chatbot}
\item[\checkmark M4.] \textit{Evaluation of basic \gls{qa} Chatbot}
\item[\checkmark M5.] \textit{Basic generative \gls{qa} Chatbot}
\item[\checkmark M6.] \textit{Evaluation of basic generative \gls{qa} Chatbot}
\end{itemize}
\subsection{Initial Gantt}
\textit{The Figure~\ref{fig:gantt-initial} represents the chart for the initial plan.}
\subsection{Methologies Retrospective}
The two phases split were respected from a methodological and temporal point of view; however, the objectives hybridization (see Figure \ref{fig:fig_planning_qa_gen_hybrid}) made the milestones slightly altered as the evaluation milestones M4 and M6 are combined.
\section{Management Conclusion}
We believe that it is important to note that even if the objectives and the results are positives, it is difficult from a management point of view to validate the statement that the end results justify the means, which we think happened in the scope of our master's thesis. Indeed, even if we enjoyed every minute, we did massive overtime for the project to reach our objectives, which means that either the initial project scope or the post-analysis redefined scope was too large for our time constraint. We blame the rescoping as the project shifted toward an understudied field of \gls{nlp} and \gls{qa} systems, which made us notice that we could define a potential new field of the \gls{nlp} research. On a final management note, even if from an industrial point of view, the current overtime would not be easily accepted. In our case; however, from an academic point of view, we justify our overflow as passionate dedication and as a fair attitude to contribute to research.
\subsection{Final Milestones}
\begin{itemize}
\setlength\itemsep{0em}
\item[M1.] Initial \gls{mt} plan and project specification
\item[M2.] Review the \gls{sota} for the \gls{nlp} and \gls{nlu} technologies and refine the plan if needed.
\item[M3.] GraphQA 1 (see Chapter \ref{graphqa:graphqa1})
\item[M4.] GraphQA 2 (see Chapter \ref{graphqa:graphqa2})
\item[M5.] GraphQA 3 (see Chapter \ref{graphqa:graphqa3})
\item[M6.] Evaluation of basic generative \gls{qa} Chatbot
\item[M7.] Turn in Master's Thesis
\end{itemize}
\subsection{Effective Gantt}
The Figure~\ref{fig:gantt-final} represents the chart for for the effective plan.
\begin{figure}
\centering
\includegraphics[width=\textwidth,keepaspectratio=true]{fig_planning_qa_gen_hybrid}
\caption{Suggested \gls{generative} \gls{qa} diagram}
\label{fig:fig_planning_qa_gen_hybrid}
\end{figure}
\newganttchartelement*{project-milestone}{
project-milestone/.style={
shape=isosceles triangle,
inner sep=0pt,
draw=cyan,
top color=white,
bottom color=cyan!50
},
project-milestone incomplete/.style={
/pgfgantt/project-milestone,
draw=yellow,
bottom color=yellow!50
},
project-milestone label font=\slshape,
project-milestone left shift=0pt,
project-milestone right shift=0pt
}
\newgantttimeslotformat{stardate}{
\def\decomposestardate##1.##2\relax{
\def\stardateyear{##1}\def\stardateday{##2}
}
\decomposestardate#1\relax
\pgfcalendardatetojulian{\stardateyear-01-01}{#2}
\advance#2 by-1\relax
\advance#2 by\stardateday\relax
}
\begin{figure}%[h]%[htbp]
\centering
\begin{ganttchart}[vgrid, hgrid]{1}{19}
\gantttitle{Sep}{2}
\gantttitle{Oct}{5}
\gantttitle{Nov}{4}
\gantttitle{Dec}{3}
\gantttitle{Jan}{4}
\gantttitle{Feb}{1}\\
\gantttitlelist{1,...,19}{1}\\
%part 1
\ganttgroup{Back to level}{1}{6} \\
\ganttmilestone{M1, M2}{3}
\ganttmilestone{}{6}\\
%part 2
\ganttgroup{Diving}{7}{18} \\
\ganttbar{Sprint 1}{7}{8} \\
\ganttbar{Sprint 2}{9}{10} \\
\ganttmilestone{M3}{10}\\
\ganttbar{Sprint 3}{11}{12} \\
\ganttmilestone{M4}{12}\\
\ganttbar{Sprint 4}{13}{14} \\
\ganttbar{Sprint 5}{15}{16} \\
\ganttmilestone{M5}{16}\\
\ganttbar{Sprint 6}{17}{18} \\
\ganttmilestone{M6}{18}\\
%\ganttlink{elem6}{elem7}
%\ganttlink{elem8}{elem9}
%part 3
\ganttgroup{Wrap up}{19}{19} \\
\end{ganttchart}
\caption{Initial Gantt Chart}
\label{fig:gantt-initial}
\end{figure}
\begin{figure}%[h]%[htbp]
\centering
\begin{ganttchart}[vgrid, hgrid]{1}{19}
\gantttitle{Sep}{2}
\gantttitle{Oct}{5}
\gantttitle{Nov}{4}
\gantttitle{Dec}{3}
\gantttitle{Jan}{4}
\gantttitle{Feb}{1}\\
\gantttitlelist{1,...,19}{1}\\
%part 1
\ganttgroup{State-of-the-Art Research}{1}{6} \\
\ganttmilestone{M1, M2}{3}
\ganttmilestone{}{6}\\
%part 2
\ganttgroup{Research Contribution}{7}{19} \\
\ganttbar{Sprint 1}{7}{8} \\
\ganttbar{Sprint 2}{9}{10} \\
\ganttmilestone{M3}{10}\\
\ganttbar{Sprint 3}{11}{12} \\
\ganttmilestone{M4}{12}\\
\ganttbar{Sprint 4}{13}{14} \\
\ganttbar{Sprint 5}{15}{16} \\
\ganttmilestone{M5}{16}\\
\ganttbar{Sprint 6}{17}{18} \\
\ganttmilestone{M6}{18}\\
\ganttmilestone{M7}{19}\\
%\ganttlink{elem6}{elem7}
%\ganttlink{elem8}{elem9}
%part 3
\ganttgroup{Writing Thesis}{18}{19} \\
\end{ganttchart}
\caption{Effective Gantt Chart}
\label{fig:gantt-final}
\end{figure}
|
C *********************************************************
C * *
C * TEST NUMBER: 04.02.05.04/02 *
C * TEST TITLE : Setting entries of various kinds *
C * *
C * PHIGS Validation Tests, produced by NIST *
C * *
C *********************************************************
COMMON /GLOBNU/ CTLHND, ERRSIG, ERRFIL, IERRCT, UNERR,
1 TESTCT, IFLERR, PASSSW, ERRSW, MAXLIN,
2 CONID, MEMUN, WKID, WTYPE, GLBLUN, INDLUN,
3 DUMINT, DUMRL
INTEGER CTLHND, ERRSIG, ERRFIL, IERRCT, UNERR,
1 TESTCT, IFLERR, PASSSW, ERRSW, MAXLIN,
2 CONID, MEMUN, WKID, WTYPE, GLBLUN, INDLUN,
3 DUMINT(20), ERRIND
REAL DUMRL(20)
COMMON /GLOBCH/ PIDENT, GLBERR, TSTMSG, FUNCID,
1 DUMCH
CHARACTER PIDENT*40, GLBERR*60, TSTMSG*900, FUNCID*80,
1 DUMCH(20)*20
INTEGER MAXPL
C define a number greater than the number of initialized pattern entries
PARAMETER (MAXPL=300)
C PHIGS parameter types
INTEGER MPAI, PAI, DIMX, DIMY, ISC, ISR, DX, DY, DX2, DY2
PARAMETER (DIMX = 100, DIMY = 100)
INTEGER COLIA(DIMX,DIMY), COLIA2(DIMX, DIMY)
INTEGER IDUM1, IDUM2, IDUM3, IDUM4, IDUM5, IDUM6, IDUM7
C interior style
INTEGER PHOLLO, PSOLID, PPATTR, PHATCH, PISEMP
PARAMETER (PHOLLO=0, PSOLID=1, PPATTR=2, PHATCH=3, PISEMP=4)
C type of returned value
INTEGER PSET, PREALI
PARAMETER (PSET = 0, PREALI = 1)
LOGICAL ARREQ, PATAVL
C used to control tests
INTEGER NIE, AII, LISTEL, LISTOT, DEFI(MAXPL)
INTEGER LUI, DPI, CNDE, NNDE, I, J
CHARACTER MSG*300
C parameters for <inquire workstation connection and type>
INTEGER SPECWT, SPECON
DATA DEFI / MAXPL*0 /
CALL INITGL ('04.02.05.04/02')
C open PHIGS
CALL XPOPPH (ERRFIL, MEMUN)
C open workstation
CALL POPWK (WKID, CONID, WTYPE)
CALL PQWKC (WKID, ERRIND, SPECON, SPECWT)
CALL CHKINQ ('pqwkc', ERRIND)
IF (.NOT. PATAVL(SPECWT)) THEN
CALL INMSG ('Skipping all tests because pattern interior ' //
1 'style is not supported on this workstation.')
GOTO 666
ENDIF
C determine mpai = max # pattern entries
CALL PQWKSL (SPECWT, ERRIND, IDUM1, IDUM2, IDUM3, IDUM4,
1 IDUM5, MPAI, IDUM6, IDUM7)
CALL CHKINQ ('pqwksl', ERRIND)
C *** *** *** *** *** initialized entries *** *** *** *** ***
C There should be at least 1 predefined pattern -
C This statement is NOT meant to test the requirement of
C 1 predefined pattern; that is done elsewhere.
CALL SETMSG ('3', '<Inquire list of pattern indices> should ' //
1 'return initialized indices.')
C nie = number of initialized pattern entries
C aii = an initialized index (the first)
CALL PQEPAI (WKID, 1, ERRIND, NIE, AII)
IF (ERRIND .NE. 0) THEN
CALL FAIL
GOTO 200
ELSE
CALL PASS
ENDIF
C get initialized attributes
CALL PQPAR (WKID, AII, PSET, DIMX, DIMY, ERRIND, DX, DY, COLIA)
C check errind for overflow
IF (ERRIND .EQ. 2001) THEN
WRITE (MSG, '(A,A,2I5,A)') 'PQPAR returned Fortran error ',
1 '2001: declared array size of (', DIMX, DIMY,
2 ') insufficient.'
CALL INMSG (MSG)
GOTO 200
ENDIF
CALL CHKINQ ('pqpar', ERRIND)
C set different values for attributes
DO 80 I = 1, DX
DO 75 J = 1, DY
COLIA2(I,J) = COLIA(I,J) +1
75 CONTINUE
80 CONTINUE
ISC = 1
ISR = 1
DX2 = DX
DY2 = DY
CALL PSPAR (WKID, AII, DIMX, DIMY, ISC, ISR, DX2, DY2, COLIA2)
C get current number of defined entries
CALL PQEPAI (WKID, 0, ERRIND, CNDE, IDUM1)
CALL CHKINQ ('pqepai', ERRIND)
CALL SETMSG ('1 3', 'Redefining a system-initialized entry ' //
1 'should not change the number of defined entries.')
CALL IFPF (CNDE .EQ. NIE)
C check that aii is still among defined entries
CALL SETMSG ('1 3', 'Initialized table entry should be ' //
1 'reported as defined after being set.')
DO 150 LISTEL = 1, NIE
CALL PQEPAI (WKID, LISTEL, ERRIND, IDUM1, PAI)
CALL CHKINQ ('pqepai', ERRIND)
IF (PAI .EQ. AII) THEN
CALL PASS
GOTO 160
ENDIF
150 CONTINUE
CALL FAIL
GOTO 200
160 CONTINUE
CALL PQPAR (WKID, AII, PSET, DIMX, DIMY, ERRIND, DX, DY, COLIA)
CALL CHKINQ ('pqpar', ERRIND)
CALL SETMSG ('2 5', 'New values should be set for ' //
1 'initialized table entry.')
CALL IFPF (DX2 .EQ. DX .AND.
1 DY2 .EQ. DY .AND.
2 ARREQ(DIMX, DIMY, ISC, ISR, DX2, DY2, COLIA2, COLIA))
C *** *** *** *** *** undefined entries *** *** *** *** ***
200 CONTINUE
C get lowest undefined index
C get current number defined entries
CALL PQEPAI (WKID, 0, ERRIND, CNDE, IDUM1)
CALL CHKINQ ('pqepai', ERRIND)
C defi is originally an array of zeros
DO 250 LISTEL = 1, CNDE
CALL PQEPAI (WKID, LISTEL, ERRIND, IDUM1, PAI)
CALL CHKINQ ('pqepai', ERRIND)
C mark as defined any index .le. cnde+1
C This will leave at least one UNmarked
IF (PAI .LE. CNDE+1) DEFI (PAI) = 1
250 CONTINUE
C first remaining zero indicates undefined entry
DO 260 PAI = 1, CNDE+1
IF (DEFI (PAI) .EQ. 0) THEN
C determine lowest undefined index (not in defined list) = lui
LUI = PAI
GOTO 270
ENDIF
260 CONTINUE
CALL UNMSG
1 ('Cannot find undefined index - error in test algorithm.')
C established lui as lowest undefined index
270 CONTINUE
C inquire undefined table entry as REALIZED
CALL PQPAR (WKID, LUI, PREALI, DIMX, DIMY, ERRIND, DX, DY, COLIA)
C check errind for overflow
IF (ERRIND .EQ. 2001) THEN
WRITE (MSG, '(A,A,2I5,A)') 'PQPAR returned Fortran error ',
1 '2001: declared array size of (', DIMX, DIMY,
2 ') insufficient.'
CALL INMSG (MSG)
GOTO 350
ENDIF
CALL CHKINQ ('pqpar', ERRIND)
C inquire pattern index #1 as REALIZED
CALL PQPAR (WKID, 1, PREALI, DIMX, DIMY, ERRIND, DX2,DY2, COLIA2)
C check errind for overflow
IF (ERRIND .EQ. 2001) THEN
WRITE (MSG, '(A,A,2I5,A)') 'PQPAR returned Fortran error ',
1 '2001: declared array size of (', DIMX, DIMY,
2 ') insufficient.'
CALL INMSG (MSG)
GOTO 350
ENDIF
CALL CHKINQ ('pqpar', ERRIND)
CALL SETMSG ('3 7', '<Inquire pattern representation> ' //
1 'should return attributes for pattern index #1 ' //
2 'when inquiring an undefined entry as REALIZED.')
C should have same attributes
CALL IFPF (DX2 .EQ. DX .AND.
1 DY2 .EQ. DY .AND.
2 ARREQ(DIMX, DIMY, 1,1, DX, DY, COLIA, COLIA2))
350 CONTINUE
C If number of initialized entries >= implementation max then skip test
C of setting undefined entry - goto redefined_test.
IF (NIE .GE. MPAI) THEN
CALL INMSG ('Skipping undefined-test because all pattern ' //
1 'table entries are initialized.')
GOTO 400
ENDIF
C Check that program allows enough room
IF (NIE .GE. MAXPL) THEN
CALL INMSG ('Skipping undefined-test because number ' //
1 'of initialized entries exceed program limits.')
GOTO 400
ENDIF
C set values for attributes
ISC = 4
ISR = 5
DX2 = 2
DY2 = 2
COLIA2(4,5) = 33
COLIA2(5,5) = 53
COLIA2(4,6) = 32
COLIA2(5,6) = 48
CALL PSPAR (WKID, LUI, DIMX, DIMY, ISC, ISR, DX2, DY2, COLIA2)
CALL PQEPAI (WKID, 0, ERRIND, LISTOT, IDUM1)
CALL CHKINQ ('pqepai', ERRIND)
CALL SETMSG ('1 3', 'Defining an undefined entry should ' //
1 'increment the number of defined entries.')
CALL IFPF (LISTOT .EQ. CNDE + 1)
C check that lui is now among defined entries
CALL SETMSG ('1 3', 'Undefined table entry should be ' //
1 'reported as defined after set.')
DO 380 LISTEL = 1, LISTOT
CALL PQEPAI (WKID, LISTEL, ERRIND, IDUM1, PAI)
CALL CHKINQ ('pqepai', ERRIND)
IF (PAI .EQ. LUI) THEN
CALL PASS
GOTO 390
ENDIF
380 CONTINUE
CALL FAIL
GOTO 400
390 CONTINUE
CALL PQPAR (WKID, LUI, PSET, DIMX, DIMY, ERRIND, DX, DY, COLIA)
CALL CHKINQ ('pqpar', ERRIND)
CALL SETMSG ('2 5', 'New values should be set for ' //
1 'undefined table entry.')
CALL IFPF (DX .EQ. DX2 .AND.
1 DY .EQ. DY2 .AND.
2 ARREQ(DIMX, DIMY, ISC, ISR, DX2, DY2, COLIA2, COLIA))
C *** *** *** *** *** redefined entries *** *** *** *** ***
400 CONTINUE
C get current number defined entries
CALL PQEPAI (WKID, 0, ERRIND, CNDE, IDUM1)
CALL CHKINQ ('pqepai', ERRIND)
C let dpi = a defined pattern index from middle of list
CALL PQEPAI (WKID, (CNDE+1)/2, ERRIND, IDUM1, DPI)
CALL CHKINQ ('pqepai', ERRIND)
C set to first set of values
ISC = 1
ISR = 1
DX = 3
DY = 2
COLIA(1,1) = 8
COLIA(2,1) = 22
COLIA(3,1) = 36
COLIA(1,2) = 19
COLIA(2,2) = 53
COLIA(3,2) = 89
CALL PSPAR (WKID, DPI, DIMX, DIMY, ISC, ISR, DX, DY, COLIA)
C re-set to different values
DX2 = 2
DY2 = 2
COLIA2(1,1) = 3
COLIA2(2,1) = 19
COLIA2(1,2) = 9
COLIA2(2,2) = 47
CALL PSPAR (WKID, DPI, DIMX, DIMY, ISC, ISR, DX2, DY2, COLIA2)
C get list size - nnde = new number of defined entries
CALL PQEPAI (WKID, 0, ERRIND, NNDE, IDUM1)
CALL CHKINQ ('pqepai', ERRIND)
CALL SETMSG ('1 3', 'Redefining a user-defined entry should ' //
1 'not change number of defined entries.')
CALL IFPF (NNDE .EQ. CNDE)
C check that dpi is among defined entries
CALL SETMSG ('1 3', 'Redefined table entry should be ' //
1 'reported as defined after set.')
DO 420 LISTEL = 1, NNDE
CALL PQEPAI (WKID, LISTEL, ERRIND, IDUM1, PAI)
CALL CHKINQ ('pqepai', ERRIND)
IF (PAI .EQ. DPI) THEN
CALL PASS
GOTO 430
ENDIF
420 CONTINUE
CALL FAIL
GOTO 499
430 CONTINUE
CALL PQPAR (WKID, DPI, PSET, DIMX, DIMY, ERRIND, DX, DY, COLIA)
CALL CHKINQ ('pqpar', ERRIND)
CALL SETMSG ('2 5', 'New values should be set for ' //
1 'redefined table entry.')
CALL IFPF (DX .EQ. DX2 .AND.
1 DY .EQ. DY2 .AND.
2 ARREQ(DIMX, DIMY, ISC, ISR, DX2, DY2, COLIA2, COLIA))
499 CONTINUE
C *** *** *** *** *** access all defined entries *** *** *** *** ***
CALL SETMSG ('3 4', '<Inquire list of pattern indices> and ' //
1 '<inquire pattern representation> should detect ' //
2 'all defined entries.')
C get listel-th element of defined pattern indices
DO 510 LISTEL = 1, NNDE
CALL PQEPAI (WKID, LISTEL, ERRIND, IDUM1, PAI)
IF (ERRIND .NE. 0) THEN
CALL FAIL
GOTO 515
ENDIF
CALL PQPAR (WKID, PAI, PSET, DIMX, DIMY, ERRIND, DX, DY, COLIA)
C check errind for overflow
IF (ERRIND .EQ. 2001 .OR. ERRIND .EQ. 0) THEN
C OK so far
ELSE
CALL FAIL
GOTO 515
ENDIF
510 CONTINUE
CALL PASS
515 CONTINUE
666 CONTINUE
CALL ENDIT
END
|
section "Tries via Search Trees"
theory Trie_Map
imports
RBT_Map
Trie_Fun
begin
text \<open>An implementation of tries based on maps implemented by red-black trees.
Works for any kind of search tree.\<close>
text \<open>Implementation of map:\<close>
type_synonym 'a mapi = "'a rbt"
datatype 'a trie_map = Nd bool "('a * 'a trie_map) mapi"
text \<open>In principle one should be able to given an implementation of tries
once and for all for any map implementation and not just for a specific one (RBT) as done here.
But because the map (@{typ "'a rbt"}) is used in a datatype, the HOL type system does not support this.
However, the development below works verbatim for any map implementation, eg \<open>Tree_Map\<close>,
and not just \<open>RBT_Map\<close>, except for the termination lemma \<open>lookup_size\<close>.\<close>
term size_tree
lemma lookup_size[termination_simp]:
fixes t :: "('a::linorder * 'a trie_map) rbt"
shows "lookup t a = Some b \<Longrightarrow> size b < Suc (size_tree (\<lambda>ab. Suc(Suc (size (snd(fst ab))))) t)"
apply(induction t a rule: lookup.induct)
apply(auto split: if_splits)
done
definition empty :: "'a trie_map" where
[simp]: "empty = Nd False Leaf"
fun isin :: "('a::linorder) trie_map \<Rightarrow> 'a list \<Rightarrow> bool" where
"isin (Nd b m) [] = b" |
"isin (Nd b m) (x # xs) = (case lookup m x of None \<Rightarrow> False | Some t \<Rightarrow> isin t xs)"
fun insert :: "('a::linorder) list \<Rightarrow> 'a trie_map \<Rightarrow> 'a trie_map" where
"insert [] (Nd b m) = Nd True m" |
"insert (x#xs) (Nd b m) =
Nd b (update x (insert xs (case lookup m x of None \<Rightarrow> empty | Some t \<Rightarrow> t)) m)"
fun delete :: "('a::linorder) list \<Rightarrow> 'a trie_map \<Rightarrow> 'a trie_map" where
"delete [] (Nd b m) = Nd False m" |
"delete (x#xs) (Nd b m) = Nd b
(case lookup m x of
None \<Rightarrow> m |
Some t \<Rightarrow> update x (delete xs t) m)"
subsection "Correctness"
text \<open>Proof by stepwise refinement. First abstract to type @{typ "'a trie"}.\<close>
fun abs :: "'a::linorder trie_map \<Rightarrow> 'a trie" where
"abs (Nd b t) = Trie_Fun.Nd b (\<lambda>a. map_option abs (lookup t a))"
fun invar :: "('a::linorder)trie_map \<Rightarrow> bool" where
"invar (Nd b m) = (M.invar m \<and> (\<forall>a t. lookup m a = Some t \<longrightarrow> invar t))"
lemma isin_abs: "isin t xs = Trie_Fun.isin (abs t) xs"
apply(induction t xs rule: isin.induct)
apply(auto split: option.split)
done
lemma abs_insert: "invar t \<Longrightarrow> abs(insert xs t) = Trie_Fun.insert xs (abs t)"
apply(induction xs t rule: insert.induct)
apply(auto simp: M.map_specs RBT_Set.empty_def[symmetric] split: option.split)
done
lemma abs_delete: "invar t \<Longrightarrow> abs(delete xs t) = Trie_Fun.delete xs (abs t)"
apply(induction xs t rule: delete.induct)
apply(auto simp: M.map_specs split: option.split)
done
lemma invar_insert: "invar t \<Longrightarrow> invar (insert xs t)"
apply(induction xs t rule: insert.induct)
apply(auto simp: M.map_specs RBT_Set.empty_def[symmetric] split: option.split)
done
lemma invar_delete: "invar t \<Longrightarrow> invar (delete xs t)"
apply(induction xs t rule: delete.induct)
apply(auto simp: M.map_specs split: option.split)
done
text \<open>Overall correctness w.r.t. the \<open>Set\<close> ADT:\<close>
interpretation S2: Set
where empty = empty and isin = isin and insert = insert and delete = delete
and set = "set o abs" and invar = invar
proof (standard, goal_cases)
case 1 show ?case by (simp add: isin_case split: list.split)
next
case 2 thus ?case by (simp add: isin_abs)
next
case 3 thus ?case by (simp add: set_insert abs_insert del: set_def)
next
case 4 thus ?case by (simp add: set_delete abs_delete del: set_def)
next
case 5 thus ?case by (simp add: M.map_specs RBT_Set.empty_def[symmetric])
next
case 6 thus ?case by (simp add: invar_insert)
next
case 7 thus ?case by (simp add: invar_delete)
qed
end
|
$ifndef _CLASSIFY_HOLDER_
$define _CLASSIFY_HOLDER_
$include "Utils.mpl"
ClassifyHolder:=module()
local ieqCode,sols,unsolvedSols;
export reset, # 重置状态
addSol, # 新增解
getSols, # 获取解
addUnsolvedSol,
getUnsolvedSols,
getIeqCode; # 获取不变量方程的编号
reset:=proc()
ieqCode:=0;
sols:={};
unsolvedSols:={};
return;
end proc:
addSol:=proc(s::InvSol)
flogf[1]("添加代表元");
flog[1](s:-rep);
sols:=sols union {s};
return;
end proc:
getSols:=proc()
local res:=sols;
res:=uniqueObj(res,InvSol:-uniqueKey);
res:=sort(res,'key'=(x->x:-ieqCode));
return res;
end proc:
getIeqCode:=proc()
ieqCode:=ieqCode+1;
return ieqCode;
end proc:
addUnsolvedSol:=proc(s)
unsolvedSols:=unsolvedSols union {s};
return;
end proc:
getUnsolvedSols:=proc()
return unsolvedSols;
end proc:
end module:
$endif
|
\chapter{Introduction}
Hey Everyone! Thanks for checking out the wikibook-project. This project is very much still in beta but has been released to everyone, so we can iterate on it this semester and fill in any gaps for the coming semesters. A few things to note
\begin{enumerate}
\item You'll be responsible for learning everything in the original wikibook. This is meant as a supplement for that to understand concepts and read more as a book
\item This book strives for being more readable than compatible with the lectures, meaning that one lecture can go over many different sections of the book at various levels of resolution. The book is meant to be read through and make sense on a read through.
\item This is still a wikibook, if you have thoughts, comments, suggestions, and fixes: please let us know!
\end{enumerate} |
If $f$ converges to $l$ and $f$ is eventually within $e$ of $a$, then $l$ is within $e$ of $a$. |
```python
import holoviews as hv
hv.extension('bokeh')
hv.opts.defaults(hv.opts.Curve(width=500),
hv.opts.Points(width=500),
hv.opts.Image(width=500, colorbar=True, cmap='Viridis'))
```
```python
import numpy as np
import scipy.signal
import scipy.linalg
```
# Estimadores adaptivos parte I
Hasta ahora hemos estudiando sistemas lineales donde:
- sus coeficientes quedan fijos luego del diseño y son constantes en el tiempo
- hacen supuestos sobre los estadísticos de la señal/ruido
¿Qué podemos hacer si
- no podemos hacer supuestos sobre los estadísticos?
- los estadísticos de la señal/ruido cambian en el tiempo?
- estamos en un escenario donde los datos llegan continuamente (data streaming)?
Cuando los estadísticos cambian en el tiempo decimos que la señal es **no estacionaria**.
En estos casos necesitamos un estimador de tipo **adaptivo**, es decir sistemas y filtros cuyos coeficientes se pueden **adaptar** a medida que llegan nuevos datos. Estos estimadores se diseñan de acuerdo a un método de optimización que es *online*
La siguiente figura muestra algunos ejemplos de aplicaciones de sistemas adaptivos
El método de optimización online que utilizaremos principalmente en este curso es el gradiente descendente estocástico. Revisemos a continuación los fundamentos.
## Gradiente descendente
Sea un vector de pesos $w$ de largo $L+1$ que guarda los coeficientes de un estimador
Sea ahora una función de costo que mapea el vector de pesos a un número real
$$
J(w): \mathbb{R}^{L+1} \to \mathbb{R}
$$
La función de costo debe ser tal que a menor $J$ menor sea el error del estimador
Para entrenar un estimador o filtro adaptivo se tienen los siguientes pasos conceptuales
1. Partimos de una solución inicial $w_0$
1. Modificamos iterativamente $w$ tal que $J(w_{t+1}) < J(w_t)$
1. Nos detenemos al cumplir un cierto criterio
Para modificar iterativamete y eficientemente los pesos utilizaremos la regla del **gradiente descendente** (GD)
$$
w_{t+1} = w_t - \mu \frac{dJ(w)}{dw},
$$
donde $\mu$ se conoce como tasa de aprendizaje o "paso"
- Imaginemos $J$ como una superficie de $L+1$ dimensiones
- En cada punto el gradiente negativo de $J$ nos indica hacia donde está el descenso más abrupto
- La tasa $\mu$ nos da el largo del salto entre $w_t$ y $w_{t+1}$
Observando la **expansión de Taylor de primer orden** de $J$ en $w_{t}$
$$
\begin{align}
J(w_{t+1}) &= J(w_t) + \frac{dJ(w_t)}{dw} (w_{t+1} - w_{t}) \nonumber \\
&= J(w_t) -\mu \left \| \frac{dJ(w_t)}{dw} \right \|^2 \leq J(w_t) \nonumber
\end{align}
$$
es decir que usando la regla GD con $\mu>0$ y asumiendo que $J$ es convexo entonces se cumple que $J$ siempre decrece monotónicamente.
La siguiente gráficas interactivas muestran una superficie de costo no convexa para un parámetro unidimensional. Cada punto representa una solución que parte desde una posición inicial distinta. Las flechas corresponden a la derivada multiplicada por la tasa de aprendizaje.
Estudie la evolución de las tres soluciones en cada caso. En primer lugar se utiliza $\mu=0.05$
```python
J = lambda w : (w-1)**2 + 0.2*np.sin(2*np.pi*w) # Función de costo
gradJ = lambda w : 2*(w-1) + 0.2*2*np.pi*np.cos(2*np.pi*w) # Gradiente
mu = 0.05 # Tasa de aprendizaje
iteraciones = 15
wt = np.zeros(shape=(iteraciones, 3))
wt[0, :] = np.array([0.05, 0.4, 1.9]) # Solución inicial
w_plot = np.linspace(0, 2, num=100)
for k in range(1, iteraciones):
wt[k, :] = wt[k-1, :] - mu*gradJ(wt[k-1, :])
```
```python
loss_surface = hv.Curve((w_plot, J(w_plot)), 'w', 'J')
hMap = hv.HoloMap(kdims='Iteración')
for k in range(iteraciones):
dots = hv.Points((wt[k, :], J(wt[k, :]))).opts(size=10, color='k')
mag = mu*gradJ(wt[k, :])
angle = np.pi/2 - np.sign(-mag)*np.pi/2
mag = np.abs(mag)
arrows = hv.VectorField((wt[k, :], J(wt[k, :]), angle, mag)).opts(pivot='tail',
magnitude=hv.dim('Magnitude'),
rescale_lengths=False)
hMap[k] = dots * arrows
loss_surface * hMap
```
:::{warning}
Dependiendo de donde partimos la solución final es distinta. El gradiente descedente puede quedarse "atorado" en un mínimo local o en un punto silla
:::
Ahora observe como evolucionan las tres soluciones con $\mu=0.5$, es decir 10 veces más grande que el caso anterior
```python
J = lambda w : (w-1)**2 + 0.2*np.sin(2*np.pi*w) # Función de costo
gradJ = lambda w : 2*(w-1) + 0.2*2*np.pi*np.cos(2*np.pi*w) # Gradiente
mu = 0.5 # Tasa de aprendizaje
iteraciones = 15
wt = np.zeros(shape=(iteraciones, 3))
wt[0, :] = np.array([0.05, 0.4, 1.9]) # Solución inicial
w_plot = np.linspace(0, 2, num=100)
for k in range(1, iteraciones):
wt[k, :] = wt[k-1, :] - mu*gradJ(wt[k-1, :])
```
```python
loss_surface = hv.Curve((w_plot, J(w_plot)), 'w', 'J')
hMap = hv.HoloMap(kdims='Iteración')
for k in range(iteraciones):
dots = hv.Points((wt[k, :], J(wt[k, :]))).opts(size=10, color='k')
mag = mu*gradJ(wt[k, :])
angle = np.pi/2 - np.sign(-mag)*np.pi/2
mag = np.abs(mag)
arrows = hv.VectorField((wt[k, :], J(wt[k, :]), angle, mag)).opts(pivot='tail',
magnitude=hv.dim('Magnitude'),
rescale_lengths=False)
hMap[k] = dots * arrows
loss_surface * hMap
```
:::{warning}
Si la tasa de aprendizaje es muy alta, los pasos son muy largos y podríamos no converger a un punto estacionario
:::
Los ejemplos anteriores nos han mostrado algunas de las limitaciones del algoritmo de gradiente descendente. Es importante tenerlas en cuenta cuando lo utilicemos en nuestras aplicaciones
## Gradiente descendente en el filtro de Wiener
Para el filtro de Wiener teníamos que
$$
J(h) = \sigma_d^2 - 2 \textbf{h}^T R_{ud} + \textbf{h}^T R_{uu} \textbf{h},
$$
por ende
$$
\frac{dJ(h)}{dh} = -2 R_{ud} + 2 R_{uu} \textbf{h}
$$
y finalmente
$$
\textbf{h}_{t+1} = \textbf{h}_{t} (I - 2 \mu R_{uu}) + 2\mu R_{ud}
$$
En este caso la condición para una convergencia estable es
$$
0 < \mu < \frac{1}{\lambda_{\text{max}}},
$$
donde $\lambda_{\text{max}}$ es valor propio más grande de $R_{uu}$
(La prueba de esto puede encontrarse en *Haykin, "Adaptive filter theory", Sección 4.3*)
## Gradiente descendente estocástico (SGD)
El filtro de Wiener es óptimo pero no adaptivo:
- Requiere de $N$ muestras de $u$ y $d$ para estimar $R_{ud}$ y $R_{uu}$
- Los pesos se adaptan luego de haber presentado las $N$ muestras: Es una estrategia de tipo **batch**
- Asume que la señal es estacionaria
Si nuestros son no estacionarios significa que debemos adaptar el filtro a medida que nuevas muestras son observadas
. Para lograr esto podemos usar la versión estocástica del GD: SGD
En SGD:
- los pesos se adaptan luego de haber presentado una sola muestra o un conjunto pequeño de muestras (mini-batch)
- no hay garantía de llegar al óptimo en un problema convexo, pero es más eficiente computacionalmente que GD
El siguiente esquema muestra una comparación entre la trayectoria de $w$ cuando se usa GD (negro) y SGD (rojo). En general la trayectoria de SGD será más ruidosa y también podría requerir más pasos, pero cada paso es mucho más económico
## Algoritmo Least Mean Square (LMS)
Podemos extender el filtro de Wiener al caso no-estacionario usando SGD, el resultado es un algoritmo simple que además es robusto: **El algoritmo LMS**
- Fue fue inventado en 1960 por [Bernard Widrow](https://en.wikipedia.org/wiki/Bernard_Widrow) y Ted Hoff
- A diferencia del filtro de Wiener no se requiere conocimiento estadístico del proceso. Tampoco se requiere calcular e invertir la matriz de correlación
- El algoritmo LMS se ajusta o entrena de manera recursiva y online
Consideremos la función de costo **estocástica** para la arquitectura FIR que utilizamos para el filtro de Wiener
$$
\begin{align}
J^s_n(\textbf{w}) &= e_n^2 \nonumber \\
&= (d_n - y_n)^2 \nonumber \\
&= (d_n - \textbf{w}^T \textbf{u}_n )^2 \nonumber \\
&= (d_n - \sum_{k=0}^{L} w_{n, k} u_{n-k} )^2 \nonumber
\end{align}
$$
donde definimos $\textbf{u}_n = [u_n, u_{n-1}, \ldots, u_{n-L}]$.
:::{note}
A diferencia del filtro de Wiener no aplicamos el valor esperado al error cuadrático. Se usa el error cuadrático instantaneo
:::
Para continuar calculamos el gradiente en función del peso $w_{n, k}$
$$
\frac{d J^s_n (\textbf{w})}{d w_{n, k}} = - 2 e_n u_{n-k}
$$
Luego, usando la regla SGD llegamos a
$$
w_{n+1, k} = w_{n, k} + 2 \mu e_n u_{n-k}, k=0, 1, \ldots, L
$$
y que en forma matricial es
$$
\begin{align}
\textbf{w}_{n+1} &= \textbf{w}_{n} + 2 \mu e_n \textbf{u}_{n}\nonumber \\
&= \textbf{w}_{n} + 2 \mu (d_n - \textbf{w}_{n}^T \textbf{u}_{n}) \textbf{u}_{n}, \nonumber
\end{align}
$$
que se conoce como la regla de **Widrow-Hoff**
:::{important}
El algoritmo LMS estima el error instantaneo y actualiza los pesos recursivamente
:::
La complejidad de este algoritmo es $L+1$.
### Convergencia del algoritmo LMS (Haykin 6.5)
El algoritmo LMS tiende en la media al valor óptimo
$$
\mathbb{E}[\textbf{w}_n] \to \textbf{w}^*
$$
para $n\to \infty$
Además convergence en la media cuadrada: La varianza de $\textbf{w}_n - \textbf{w}^*$ tiene al valor mínimo de $J$ para $n\to \infty$
Esto se cumple si
$$
0 < \mu < \frac{2}{\text{Tr}[R_{uu}]}
$$
donde $R_{uu} = \mathbb{E}[\textbf{u}_n \textbf{u}_n^T ]$ es la matriz de autocorrelación y $\text{Tr}[]$ el operador que calcula la traza de una matriz
### Algoritmo Normalized LMS (NLMS)
Tenemos la siguiente regla iterativa
$$
\begin{align}
\textbf{w}_{n+1} &= \textbf{w}_{n} + 2 \mu (d_n - \textbf{w}_{n}^T \textbf{u}_{n}) \textbf{u}_{n} \nonumber \\
& = \textbf{w}_{n} + \Delta \textbf{w}_n \nonumber
\end{align}
$$
que se puede interpretar graficamente como
(donde $\textbf{x}(k)$ y $\textbf{w}(k)$ corresponden a $\textbf{u}_n$ y $\textbf{w}_n$ en nuestra notación, respectivamente)
:::{note}
Los cambios en el vector de peso $\Delta \textbf{w}_n$ son paralelos a $\textbf{u}_{n}$. Además estos cambios podrían estar dominados por
$$
\max \textbf{u}_{n} = [u_n, u_{n-1}, \ldots, u_{n-L}]
$$
:::
El algoritmo **Normalized LMS** (NLMS) corrige este problema ponderando por la varianza de $\textbf{u}_{n}$
$$
\textbf{w}_{n+1} = \textbf{w}_{n} + 2 \mu (d_n - \textbf{w}_{n}^T \textbf{u}_{n}) \frac{\textbf{u}_{n}}{\left(\|\textbf{u}_{n}\|^2 + \delta\right)}
$$
donde la constante $\delta$ es un valor pequeño que se usa para evitar divisiones por cero. En lo que sigue usaremos NLMS para revisar algunas aplicaciones
## Implementación del filtro NLMS en Python
Podemos implementar las ecuaciones del filtro NLMS como se muestra a continuación
```python
class Filtro_NLMS:
def __init__(self, L, mu, delta=1e-6, winit=None):
self.L = L
self.w = np.zeros(shape=(L+1, ))
self.mu = mu
self.delta = delta
def update(self, un, dn):
# Asumiendo que un = [u[n], u[n-1], ..., u[n-L]]
unorm = np.dot(un, un) + self.delta
yn = np.dot(self.w, un)
self.w += 2*self.mu*(dn - yn)*(un/unorm)
return yn
```
- El filtro recibe como entrada el orden $L$ y la tasa de aprendizaje $\mu$
- Se asume un vector cero para los pesos iniciales, pero también en la práctica podemos partir de una solución anterior si esta existiera
- Para actualizar el vector de pesos es necesario entregar el vector $\textbf{u}_n \in \mathbb{R}^{L+1}$ y la salida deseada $d_n \in \mathbb{R}$. La función `update` retorna la salida predicha por el filtro $y_n = w_n^T \textbf{u}_n
$
A continuación probaremos este filtro con una aplicación conocida como **Adaptive line enhancement** (ALE). ALE se refiere a un sistema adaptivo para eliminar ruido blanco aditivo de una señal. El sistema aprende un filtro pasabanda en torno a la frecuencia de interés
En ALE usamos como señal deseada
$$
d_n = u_n = \textbf{u}_n[0]
$$
El valor predicho por el filtro será la señal $u$ pero libre de ruido blanco. Esto se debe a que el ruido blanco no tiene correlación y por ende el filtro adaptivo no lo puede predecir
```python
# Digamos que u = s + n
# El objetivo es limpiar u para obtener s
# s es una señal determínista y n es ruido blanco
Fs, f0 = 100, 5
t = np.arange(0, 4, 1/Fs)
s = np.sin(2.0*np.pi*t*f0)
n = 0.5*np.random.randn(len(t))
s[t>2.0] += 5 # Simulemos un cambio abrupto en la media de la señal
#s += s*(0.5 + 0.5*np.cos(2.0*np.pi*t/2)) # Tremolo (AM)
u = s + n
```
A diferencia de un filtro estático (como el filtro de Wiener) es posible filtrar incluso ante cambios bruscos en la señal.
Estudie como cambia el resultado del filtro con distintos valores de $\mu$
```python
L = 20
u_preds = {}
for mu in np.logspace(-2, 0, num=10):
myfilter = Filtro_NLMS(L=L, mu=mu)
u_preds[mu] = np.zeros(shape=(len(u),))
for k in range(L+1, len(u)):
u_preds[mu][k] = myfilter.update(u[k-L-1:k][::-1], u[k])
```
```python
hMap = hv.HoloMap(kdims='mu')
for mu, u_pred in u_preds.items():
s1 = hv.Curve((t, s), 'Tiempo', 'Señal', label='Limpia')
s2 = hv.Scatter((t, u), 'Tiempo', 'Señal', label='Contaminada')
s3 = hv.Curve((t, u_pred), 'Tiempo', 'Señal', label='Filtrada')
hMap[mu] = hv.Overlay([s1, s2, s3]).opts(hv.opts.Overlay(legend_position='top'),
hv.opts.Curve(ylim=(-5, 10), height=350))
hMap
```
:::{important}
La tasa de aprendizaje $\mu$ controla la velocidad de adaptación. Pero una tasa demasiado grande provoca que el filtro sea inestable. En general el valor óptimo de $\mu$ depende del problema y del valor de $L$
:::
La siguiente figura muestra la respuesta en frecuencia del filtro en función del tiempo para $\mu=0.02$
Observe como a medida que se adapta el filtro se concentra en la frecuencia fundamental de la señal, que en este caso es 5 Hz
```python
L = 20
u_preds = {}
myfilter = Filtro_NLMS(L=L, mu=0.02)
H_history = np.zeros(shape=(512, len(u)))
for k in range(L+1, len(u)):
myfilter.update(u[k-L-1:k][::-1], u[k])
fk, Hk = scipy.signal.freqz(b=myfilter.w, a=1, fs=Fs)
H_history[:, k] = np.abs(Hk)
```
```python
hv.Image((t, fk, H_history), kdims=['Tiempo [s]', 'Frecuencia [Hz]']).opts(cmap='Blues')
```
## Comparación entre Filtro de Wiener/GD y algoritmo LMS/SGD
- **Supuestos**: Wiener requiere un ambiente estacionario lo cual nos permite calcular $R_{uu}$ y $R_{ud}$. En LMS la señal puede ser no estacionaria.
- **Aprendizaje:** En el filtro de Wiener el aprendizaje es determinista. En LMS el aprendizaje viene **promediando** a nivel de los estimadores de $w$. En LMS el aprendizaje es estadístico.
- **Optimalidad:** Wiener es óptimo en cambio LMS es sub-óptimo (localmente óptimo). LMS tiende a la solución de Wiener
- **Costo:** LMS se actualiza online y tiene costo $L$. Wiener se entrena offline y tiene costo $L^2$
A continuación se muestra un diagrama que compara el filtro de Wiener y el algoritmo LMS
```python
```
|
[STATEMENT]
lemma floorlog_leD:
"floorlog b x \<le> w \<Longrightarrow> b > 1 \<Longrightarrow> x < b ^ w"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<lbrakk>floorlog b x \<le> w; 1 < b\<rbrakk> \<Longrightarrow> x < b ^ w
[PROOF STEP]
by (metis floorlog_bounds leD linorder_neqE_nat order.strict_trans power_strict_increasing_iff
zero_less_one zero_less_power) |
module Main
import Data.Strings
data MyEither a b = MyLeft a | MyRight b
data MyDecEq : Type -> Type where
MyYes : a -> MyDecEq a
MyNo : (a -> Void) -> MyDecEq a
myDec1 : MyDecEq Char
myDec1 = MyYes 'a'
myDec2 : MyDecEq Char
myDec2 = MyNo ?absurd
test : Int
test = ?test1
test3 : Int -> Int -> Int
test3 x y = x
data MyStream : Type -> Type where
MkMyStream : Lazy a -> Inf (MyStream a) -> MyStream a
mkStream : a -> MyStream a
mkStream x = MkMyStream x (mkStream x)
headS : MyStream a -> a
headS (MkMyStream x _) = x
tailS : MyStream a -> MyStream a
tailS (MkMyStream _ xs) = xs
data MyStream2 : Type -> Type where
MkMyStream2 : a -> MyStream2 a -> MyStream2 a
MkMyStream2N : MyStream2 a
myStream2 : a -> MyStream2 a
myStream2 x = MkMyStream2 x (myStream2 x)
heads2 : MyStream2 a -> Maybe a
heads2 MkMyStream2N = Nothing
heads2 (MkMyStream2 x _) = Just x
%foreign "stg:prim__consoleLog = base:Prelude.putStrLn"
prim__consoleLog : String -> PrimIO ()
export
consoleLog : HasIO io => String -> io ()
consoleLog x = primIO $ prim__consoleLog x
%foreign "stg:prim__applyFnIO = base:Prelude.somewhat"
prim__applyFnIO : String -> Int -> (String -> Int -> PrimIO String) ->
PrimIO String
applyFnIO : HasIO io =>
String -> Int -> (String -> Int -> IO String) -> io String
applyFnIO c i f = primIO $ prim__applyFnIO c i (\s, i => toPrim $ f s i)
data MyBuffer : Type -> Type where [external]
%foreign "stg:prim__myBuffer = base:Prelude.myBuffer"
prim__myBuffer : PrimIO (MyBuffer Int)
myBuffer : HasIO io => io (MyBuffer Int)
myBuffer = primIO prim__myBuffer
data ThreadID1 : Type where [external]
%foreign "stg:prim__fork = base:Something.something"
prim__fork : (1 prog : PrimIO ()) -> PrimIO ThreadID1
fork : (1 prog : IO ()) -> IO ThreadID1
fork act = fromPrim (prim__fork (toPrim act))
partial
main : IO ()
main = do
name <- getLine
let nm1 = the (MyEither String String) (MyLeft name)
let md1 = the (MyDecEq Char) (MyYes 'a')
putStrLn $ strTail $ "!Hello " ++ name
case nm1 of
MyLeft n => printLn $ fastUnpack n
MyRight n => printLn $ fastUnpack n
case md1 of
MyYes a => printLn $ show a
MyNo _ => printLn $ "Noooo!"
printLn $ test3 1 test
consoleLog "BLAH!"
str <- applyFnIO "hello" 1 (\s, i => do { printLn (s,i); pure s})
bfr <- myBuffer
tid <- Main.fork (putStrLn "Hello Fork!")
printLn $ headS $ tailS $ mkStream 4
printLn $ heads2 $ myStream2 5
pure ()
{-
Main.prim__applyFnIO = Foreign call ["stg:prim__applyFnIO = base:Prelude.somewhat"] [String, Int, String -> Int -> %World -> IORes String, %World] -> IORes
Main.{applyFnIO:1} = [0, 1, 2, 3, 4, 5, 6, 7]: %let v8 = (<Main.{applyFnIO:0} underapp 2>(v7, v0, v1, v2, v3, v4, v5, v6)) in (Main.prim__applyFnIO(v4, v5, v8, v7))
Main.applyFnIO = [0, 1, 2, 3, 4]: %case v1 of { %conalt Prelude.IO.HasIO at Prelude/IO.idr:33:1--35:32(v5, v6) => %let v7 = (v6 @ ([__])) in (%let v8 = (<Main.{applyFnIO:1} underapp 1>(v5, v6, v0, v1, v2, v3, v4)) in (v7 @ (v8))) Nothing }
-}
|
module Relation.Path where
open import Relation.Path.Operation
|
(* Title: ZF/UNITY/GenPrefix.thy
Author: Sidi O Ehmety, Cambridge University Computer Laboratory
Copyright 2001 University of Cambridge
\<langle>xs,ys\<rangle>:gen_prefix(r)
if ys = xs' @ zs where length(xs) = length(xs')
and corresponding elements of xs, xs' are pairwise related by r
Based on Lex/Prefix
*)
section\<open>Charpentier's Generalized Prefix Relation\<close>
theory GenPrefix
imports ZF
begin
definition (*really belongs in ZF/Trancl*)
part_order :: "[i, i] \<Rightarrow> o" where
"part_order(A, r) \<equiv> refl(A,r) \<and> trans[A](r) \<and> antisym(r)"
consts
gen_prefix :: "[i, i] \<Rightarrow> i"
inductive
(* Parameter A is the domain of zs's elements *)
domains "gen_prefix(A, r)" \<subseteq> "list(A)*list(A)"
intros
Nil: "<[],[]>:gen_prefix(A, r)"
prepend: "\<lbrakk>\<langle>xs,ys\<rangle>:gen_prefix(A, r); \<langle>x,y\<rangle>:r; x \<in> A; y \<in> A\<rbrakk>
\<Longrightarrow> <Cons(x,xs), Cons(y,ys)>: gen_prefix(A, r)"
append: "\<lbrakk>\<langle>xs,ys\<rangle>:gen_prefix(A, r); zs:list(A)\<rbrakk>
\<Longrightarrow> <xs, ys@zs>:gen_prefix(A, r)"
type_intros app_type list.Nil list.Cons
definition
prefix :: "i\<Rightarrow>i" where
"prefix(A) \<equiv> gen_prefix(A, id(A))"
definition
strict_prefix :: "i\<Rightarrow>i" where
"strict_prefix(A) \<equiv> prefix(A) - id(list(A))"
(* less or equal and greater or equal over prefixes *)
abbreviation
pfixLe :: "[i, i] \<Rightarrow> o" (infixl \<open>pfixLe\<close> 50) where
"xs pfixLe ys \<equiv> \<langle>xs, ys\<rangle>:gen_prefix(nat, Le)"
abbreviation
pfixGe :: "[i, i] \<Rightarrow> o" (infixl \<open>pfixGe\<close> 50) where
"xs pfixGe ys \<equiv> \<langle>xs, ys\<rangle>:gen_prefix(nat, Ge)"
lemma reflD:
"\<lbrakk>refl(A, r); x \<in> A\<rbrakk> \<Longrightarrow> \<langle>x,x\<rangle>:r"
apply (unfold refl_def, auto)
done
(*** preliminary lemmas ***)
lemma Nil_gen_prefix: "xs \<in> list(A) \<Longrightarrow> <[], xs> \<in> gen_prefix(A, r)"
by (drule gen_prefix.append [OF gen_prefix.Nil], simp)
declare Nil_gen_prefix [simp]
lemma gen_prefix_length_le: "\<langle>xs,ys\<rangle> \<in> gen_prefix(A, r) \<Longrightarrow> length(xs) \<le> length(ys)"
apply (erule gen_prefix.induct)
apply (subgoal_tac [3] "ys \<in> list (A) ")
apply (auto dest: gen_prefix.dom_subset [THEN subsetD]
intro: le_trans simp add: length_app)
done
lemma Cons_gen_prefix_aux:
"\<lbrakk><xs', ys'> \<in> gen_prefix(A, r)\<rbrakk>
\<Longrightarrow> (\<forall>x xs. x \<in> A \<longrightarrow> xs'= Cons(x,xs) \<longrightarrow>
(\<exists>y ys. y \<in> A \<and> ys' = Cons(y,ys) \<and>
\<langle>x,y\<rangle>:r \<and> \<langle>xs, ys\<rangle> \<in> gen_prefix(A, r)))"
apply (erule gen_prefix.induct)
prefer 3 apply (force intro: gen_prefix.append, auto)
done
lemma Cons_gen_prefixE:
"\<lbrakk><Cons(x,xs), zs> \<in> gen_prefix(A, r);
\<And>y ys. \<lbrakk>zs = Cons(y, ys); y \<in> A; x \<in> A; \<langle>x,y\<rangle>:r;
\<langle>xs,ys\<rangle> \<in> gen_prefix(A, r)\<rbrakk> \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
apply (frule gen_prefix.dom_subset [THEN subsetD], auto)
apply (blast dest: Cons_gen_prefix_aux)
done
declare Cons_gen_prefixE [elim!]
lemma Cons_gen_prefix_Cons:
"(<Cons(x,xs),Cons(y,ys)> \<in> gen_prefix(A, r))
\<longleftrightarrow> (x \<in> A \<and> y \<in> A \<and> \<langle>x,y\<rangle>:r \<and> \<langle>xs,ys\<rangle> \<in> gen_prefix(A, r))"
apply (auto intro: gen_prefix.prepend)
done
declare Cons_gen_prefix_Cons [iff]
(** Monotonicity of gen_prefix **)
lemma gen_prefix_mono2: "r<=s \<Longrightarrow> gen_prefix(A, r) \<subseteq> gen_prefix(A, s)"
apply clarify
apply (frule gen_prefix.dom_subset [THEN subsetD], clarify)
apply (erule rev_mp)
apply (erule gen_prefix.induct)
apply (auto intro: gen_prefix.append)
done
lemma gen_prefix_mono1: "A<=B \<Longrightarrow>gen_prefix(A, r) \<subseteq> gen_prefix(B, r)"
apply clarify
apply (frule gen_prefix.dom_subset [THEN subsetD], clarify)
apply (erule rev_mp)
apply (erule_tac P = "y \<in> list (A) " in rev_mp)
apply (erule_tac P = "xa \<in> list (A) " in rev_mp)
apply (erule gen_prefix.induct)
apply (simp (no_asm_simp))
apply clarify
apply (erule ConsE)+
apply (auto dest: gen_prefix.dom_subset [THEN subsetD]
intro: gen_prefix.append list_mono [THEN subsetD])
done
lemma gen_prefix_mono: "\<lbrakk>A \<subseteq> B; r \<subseteq> s\<rbrakk> \<Longrightarrow> gen_prefix(A, r) \<subseteq> gen_prefix(B, s)"
apply (rule subset_trans)
apply (rule gen_prefix_mono1)
apply (rule_tac [2] gen_prefix_mono2, auto)
done
(*** gen_prefix order ***)
(* reflexivity *)
lemma refl_gen_prefix: "refl(A, r) \<Longrightarrow> refl(list(A), gen_prefix(A, r))"
apply (unfold refl_def, auto)
apply (induct_tac "x", auto)
done
declare refl_gen_prefix [THEN reflD, simp]
(* Transitivity *)
(* A lemma for proving gen_prefix_trans_comp *)
lemma append_gen_prefix [rule_format (no_asm)]: "xs \<in> list(A) \<Longrightarrow>
\<forall>zs. <xs @ ys, zs> \<in> gen_prefix(A, r) \<longrightarrow> \<langle>xs, zs\<rangle>: gen_prefix(A, r)"
apply (erule list.induct)
apply (auto dest: gen_prefix.dom_subset [THEN subsetD])
done
(* Lemma proving transitivity and more*)
lemma gen_prefix_trans_comp [rule_format (no_asm)]:
"\<langle>x, y\<rangle>: gen_prefix(A, r) \<Longrightarrow>
(\<forall>z \<in> list(A). \<langle>y,z\<rangle> \<in> gen_prefix(A, s)\<longrightarrow>\<langle>x, z\<rangle> \<in> gen_prefix(A, s O r))"
apply (erule gen_prefix.induct)
apply (auto elim: ConsE simp add: Nil_gen_prefix)
apply (subgoal_tac "ys \<in> list (A) ")
prefer 2 apply (blast dest: gen_prefix.dom_subset [THEN subsetD])
apply (drule_tac xs = ys and r = s in append_gen_prefix, auto)
done
lemma trans_comp_subset: "trans(r) \<Longrightarrow> r O r \<subseteq> r"
by (auto dest: transD)
lemma trans_gen_prefix: "trans(r) \<Longrightarrow> trans(gen_prefix(A,r))"
apply (simp (no_asm) add: trans_def)
apply clarify
apply (rule trans_comp_subset [THEN gen_prefix_mono2, THEN subsetD], assumption)
apply (rule gen_prefix_trans_comp)
apply (auto dest: gen_prefix.dom_subset [THEN subsetD])
done
lemma trans_on_gen_prefix:
"trans(r) \<Longrightarrow> trans[list(A)](gen_prefix(A, r))"
apply (drule_tac A = A in trans_gen_prefix)
apply (unfold trans_def trans_on_def, blast)
done
lemma prefix_gen_prefix_trans:
"\<lbrakk>\<langle>x,y\<rangle> \<in> prefix(A); \<langle>y, z\<rangle> \<in> gen_prefix(A, r); r<=A*A\<rbrakk>
\<Longrightarrow> \<langle>x, z\<rangle> \<in> gen_prefix(A, r)"
unfolding prefix_def
apply (rule_tac P = "\<lambda>r. \<langle>x,z\<rangle> \<in> gen_prefix (A, r) " in right_comp_id [THEN subst])
apply (blast dest: gen_prefix_trans_comp gen_prefix.dom_subset [THEN subsetD])+
done
lemma gen_prefix_prefix_trans:
"\<lbrakk>\<langle>x,y\<rangle> \<in> gen_prefix(A,r); \<langle>y, z\<rangle> \<in> prefix(A); r<=A*A\<rbrakk>
\<Longrightarrow> \<langle>x, z\<rangle> \<in> gen_prefix(A, r)"
unfolding prefix_def
apply (rule_tac P = "\<lambda>r. \<langle>x,z\<rangle> \<in> gen_prefix (A, r) " in left_comp_id [THEN subst])
apply (blast dest: gen_prefix_trans_comp gen_prefix.dom_subset [THEN subsetD])+
done
(** Antisymmetry **)
lemma nat_le_lemma [rule_format]: "n \<in> nat \<Longrightarrow> \<forall>b \<in> nat. n #+ b \<le> n \<longrightarrow> b = 0"
by (induct_tac "n", auto)
lemma antisym_gen_prefix: "antisym(r) \<Longrightarrow> antisym(gen_prefix(A, r))"
apply (simp (no_asm) add: antisym_def)
apply (rule impI [THEN allI, THEN allI])
apply (erule gen_prefix.induct, blast)
apply (simp add: antisym_def, blast)
txt\<open>append case is hardest\<close>
apply clarify
apply (subgoal_tac "length (zs) = 0")
apply (subgoal_tac "ys \<in> list (A) ")
prefer 2 apply (blast dest: gen_prefix.dom_subset [THEN subsetD])
apply (drule_tac psi = "<ys @ zs, xs> \<in> gen_prefix (A,r) " in asm_rl)
apply simp
apply (subgoal_tac "length (ys @ zs) = length (ys) #+ length (zs) \<and>ys \<in> list (A) \<and>xs \<in> list (A) ")
prefer 2 apply (blast intro: length_app dest: gen_prefix.dom_subset [THEN subsetD])
apply (drule gen_prefix_length_le)+
apply clarify
apply simp
apply (drule_tac j = "length (xs) " in le_trans)
apply blast
apply (auto intro: nat_le_lemma)
done
(*** recursion equations ***)
lemma gen_prefix_Nil: "xs \<in> list(A) \<Longrightarrow> <xs, []> \<in> gen_prefix(A,r) \<longleftrightarrow> (xs = [])"
by (induct_tac "xs", auto)
declare gen_prefix_Nil [simp]
lemma same_gen_prefix_gen_prefix:
"\<lbrakk>refl(A, r); xs \<in> list(A)\<rbrakk> \<Longrightarrow>
<xs@ys, xs@zs>: gen_prefix(A, r) \<longleftrightarrow> \<langle>ys,zs\<rangle> \<in> gen_prefix(A, r)"
unfolding refl_def
apply (induct_tac "xs")
apply (simp_all (no_asm_simp))
done
declare same_gen_prefix_gen_prefix [simp]
lemma gen_prefix_Cons: "\<lbrakk>xs \<in> list(A); ys \<in> list(A); y \<in> A\<rbrakk> \<Longrightarrow>
<xs, Cons(y,ys)> \<in> gen_prefix(A,r) \<longleftrightarrow>
(xs=[] | (\<exists>z zs. xs=Cons(z,zs) \<and> z \<in> A \<and> \<langle>z,y\<rangle>:r \<and> \<langle>zs,ys\<rangle> \<in> gen_prefix(A,r)))"
apply (induct_tac "xs", auto)
done
lemma gen_prefix_take_append: "\<lbrakk>refl(A,r); \<langle>xs,ys\<rangle> \<in> gen_prefix(A, r); zs \<in> list(A)\<rbrakk>
\<Longrightarrow> <xs@zs, take(length(xs), ys) @ zs> \<in> gen_prefix(A, r)"
apply (erule gen_prefix.induct)
apply (simp (no_asm_simp))
apply (frule_tac [!] gen_prefix.dom_subset [THEN subsetD], auto)
apply (frule gen_prefix_length_le)
apply (subgoal_tac "take (length (xs), ys) \<in> list (A) ")
apply (simp_all (no_asm_simp) add: diff_is_0_iff [THEN iffD2] take_type)
done
lemma gen_prefix_append_both: "\<lbrakk>refl(A, r); \<langle>xs,ys\<rangle> \<in> gen_prefix(A,r);
length(xs) = length(ys); zs \<in> list(A)\<rbrakk>
\<Longrightarrow> <xs@zs, ys @ zs> \<in> gen_prefix(A, r)"
apply (drule_tac zs = zs in gen_prefix_take_append, assumption+)
apply (subgoal_tac "take (length (xs), ys) =ys")
apply (auto intro!: take_all dest: gen_prefix.dom_subset [THEN subsetD])
done
(*NOT suitable for rewriting since [y] has the form y#ys*)
lemma append_cons_conv: "xs \<in> list(A) \<Longrightarrow> xs @ Cons(y, ys) = (xs @ [y]) @ ys"
by (auto simp add: app_assoc)
lemma append_one_gen_prefix_lemma [rule_format]:
"\<lbrakk>\<langle>xs,ys\<rangle> \<in> gen_prefix(A, r); refl(A, r)\<rbrakk>
\<Longrightarrow> length(xs) < length(ys) \<longrightarrow>
<xs @ [nth(length(xs), ys)], ys> \<in> gen_prefix(A, r)"
apply (erule gen_prefix.induct, blast)
apply (frule gen_prefix.dom_subset [THEN subsetD], clarify)
apply (simp_all add: length_type)
(* Append case is hardest *)
apply (frule gen_prefix_length_le [THEN le_iff [THEN iffD1]])
apply (frule gen_prefix.dom_subset [THEN subsetD], clarify)
apply (subgoal_tac "length (xs) :nat\<and>length (ys) :nat \<and>length (zs) :nat")
prefer 2 apply (blast intro: length_type, clarify)
apply (simp_all add: nth_append length_type length_app)
apply (rule conjI)
apply (blast intro: gen_prefix.append)
apply (erule_tac V = "length (xs) < length (ys) \<longrightarrow>u" for u in thin_rl)
apply (erule_tac a = zs in list.cases, auto)
apply (rule_tac P1 = "\<lambda>x. <u(x), v>:w" for u v w in nat_diff_split [THEN iffD2])
apply auto
apply (simplesubst append_cons_conv)
apply (rule_tac [2] gen_prefix.append)
apply (auto elim: ConsE simp add: gen_prefix_append_both)
done
lemma append_one_gen_prefix: "\<lbrakk>\<langle>xs,ys\<rangle>: gen_prefix(A, r); length(xs) < length(ys); refl(A, r)\<rbrakk>
\<Longrightarrow> <xs @ [nth(length(xs), ys)], ys> \<in> gen_prefix(A, r)"
apply (blast intro: append_one_gen_prefix_lemma)
done
(** Proving the equivalence with Charpentier's definition **)
lemma gen_prefix_imp_nth_lemma [rule_format]: "xs \<in> list(A) \<Longrightarrow>
\<forall>ys \<in> list(A). \<forall>i \<in> nat. i < length(xs)
\<longrightarrow> \<langle>xs, ys\<rangle>: gen_prefix(A, r) \<longrightarrow> <nth(i, xs), nth(i, ys)>:r"
apply (induct_tac "xs", simp, clarify)
apply simp
apply (erule natE, auto)
done
lemma gen_prefix_imp_nth: "\<lbrakk>\<langle>xs,ys\<rangle> \<in> gen_prefix(A,r); i < length(xs)\<rbrakk>
\<Longrightarrow> <nth(i, xs), nth(i, ys)>:r"
apply (cut_tac A = A in gen_prefix.dom_subset)
apply (rule gen_prefix_imp_nth_lemma)
apply (auto simp add: lt_nat_in_nat)
done
lemma nth_imp_gen_prefix [rule_format]: "xs \<in> list(A) \<Longrightarrow>
\<forall>ys \<in> list(A). length(xs) \<le> length(ys)
\<longrightarrow> (\<forall>i. i < length(xs) \<longrightarrow> <nth(i, xs), nth(i,ys)>:r)
\<longrightarrow> \<langle>xs, ys\<rangle> \<in> gen_prefix(A, r)"
apply (induct_tac "xs")
apply (simp_all (no_asm_simp))
apply clarify
apply (erule_tac a = ys in list.cases, simp)
apply (force intro!: nat_0_le simp add: lt_nat_in_nat)
done
lemma gen_prefix_iff_nth: "(\<langle>xs,ys\<rangle> \<in> gen_prefix(A,r)) \<longleftrightarrow>
(xs \<in> list(A) \<and> ys \<in> list(A) \<and> length(xs) \<le> length(ys) \<and>
(\<forall>i. i < length(xs) \<longrightarrow> <nth(i,xs), nth(i, ys)>: r))"
apply (rule iffI)
apply (frule gen_prefix.dom_subset [THEN subsetD])
apply (frule gen_prefix_length_le, auto)
apply (rule_tac [2] nth_imp_gen_prefix)
apply (drule gen_prefix_imp_nth)
apply (auto simp add: lt_nat_in_nat)
done
(** prefix is a partial order: **)
lemma refl_prefix: "refl(list(A), prefix(A))"
unfolding prefix_def
apply (rule refl_gen_prefix)
apply (auto simp add: refl_def)
done
declare refl_prefix [THEN reflD, simp]
lemma trans_prefix: "trans(prefix(A))"
unfolding prefix_def
apply (rule trans_gen_prefix)
apply (auto simp add: trans_def)
done
lemmas prefix_trans = trans_prefix [THEN transD]
lemma trans_on_prefix: "trans[list(A)](prefix(A))"
unfolding prefix_def
apply (rule trans_on_gen_prefix)
apply (auto simp add: trans_def)
done
lemmas prefix_trans_on = trans_on_prefix [THEN trans_onD]
(* Monotonicity of "set" operator WRT prefix *)
lemma set_of_list_prefix_mono:
"\<langle>xs,ys\<rangle> \<in> prefix(A) \<Longrightarrow> set_of_list(xs) \<subseteq> set_of_list(ys)"
unfolding prefix_def
apply (erule gen_prefix.induct)
apply (subgoal_tac [3] "xs \<in> list (A) \<and>ys \<in> list (A) ")
prefer 4 apply (blast dest: gen_prefix.dom_subset [THEN subsetD])
apply (auto simp add: set_of_list_append)
done
(** recursion equations **)
lemma Nil_prefix: "xs \<in> list(A) \<Longrightarrow> <[],xs> \<in> prefix(A)"
unfolding prefix_def
apply (simp (no_asm_simp) add: Nil_gen_prefix)
done
declare Nil_prefix [simp]
lemma prefix_Nil: "<xs, []> \<in> prefix(A) \<longleftrightarrow> (xs = [])"
apply (unfold prefix_def, auto)
apply (frule gen_prefix.dom_subset [THEN subsetD])
apply (drule_tac psi = "<xs, []> \<in> gen_prefix (A, id (A))" in asm_rl)
apply (simp add: gen_prefix_Nil)
done
declare prefix_Nil [iff]
lemma Cons_prefix_Cons:
"<Cons(x,xs), Cons(y,ys)> \<in> prefix(A) \<longleftrightarrow> (x=y \<and> \<langle>xs,ys\<rangle> \<in> prefix(A) \<and> y \<in> A)"
apply (unfold prefix_def, auto)
done
declare Cons_prefix_Cons [iff]
lemma same_prefix_prefix:
"xs \<in> list(A)\<Longrightarrow> <xs@ys,xs@zs> \<in> prefix(A) \<longleftrightarrow> (\<langle>ys,zs\<rangle> \<in> prefix(A))"
unfolding prefix_def
apply (subgoal_tac "refl (A,id (A))")
apply (simp (no_asm_simp))
apply (auto simp add: refl_def)
done
declare same_prefix_prefix [simp]
lemma same_prefix_prefix_Nil: "xs \<in> list(A) \<Longrightarrow> <xs@ys,xs> \<in> prefix(A) \<longleftrightarrow> (<ys,[]> \<in> prefix(A))"
apply (rule_tac P = "\<lambda>x. \<langle>u, x\<rangle>:v \<longleftrightarrow> w(x)" for u v w in app_right_Nil [THEN subst])
apply (rule_tac [2] same_prefix_prefix, auto)
done
declare same_prefix_prefix_Nil [simp]
lemma prefix_appendI:
"\<lbrakk>\<langle>xs,ys\<rangle> \<in> prefix(A); zs \<in> list(A)\<rbrakk> \<Longrightarrow> <xs,ys@zs> \<in> prefix(A)"
unfolding prefix_def
apply (erule gen_prefix.append, assumption)
done
declare prefix_appendI [simp]
lemma prefix_Cons:
"\<lbrakk>xs \<in> list(A); ys \<in> list(A); y \<in> A\<rbrakk> \<Longrightarrow>
<xs,Cons(y,ys)> \<in> prefix(A) \<longleftrightarrow>
(xs=[] | (\<exists>zs. xs=Cons(y,zs) \<and> \<langle>zs,ys\<rangle> \<in> prefix(A)))"
unfolding prefix_def
apply (auto simp add: gen_prefix_Cons)
done
lemma append_one_prefix:
"\<lbrakk>\<langle>xs,ys\<rangle> \<in> prefix(A); length(xs) < length(ys)\<rbrakk>
\<Longrightarrow> <xs @ [nth(length(xs),ys)], ys> \<in> prefix(A)"
unfolding prefix_def
apply (subgoal_tac "refl (A, id (A))")
apply (simp (no_asm_simp) add: append_one_gen_prefix)
apply (auto simp add: refl_def)
done
lemma prefix_length_le:
"\<langle>xs,ys\<rangle> \<in> prefix(A) \<Longrightarrow> length(xs) \<le> length(ys)"
unfolding prefix_def
apply (blast dest: gen_prefix_length_le)
done
lemma prefix_type: "prefix(A)<=list(A)*list(A)"
unfolding prefix_def
apply (blast intro!: gen_prefix.dom_subset)
done
lemma strict_prefix_type:
"strict_prefix(A) \<subseteq> list(A)*list(A)"
unfolding strict_prefix_def
apply (blast intro!: prefix_type [THEN subsetD])
done
lemma strict_prefix_length_lt_aux:
"\<langle>xs,ys\<rangle> \<in> prefix(A) \<Longrightarrow> xs\<noteq>ys \<longrightarrow> length(xs) < length(ys)"
unfolding prefix_def
apply (erule gen_prefix.induct, clarify)
apply (subgoal_tac [!] "ys \<in> list(A) \<and> xs \<in> list(A)")
apply (auto dest: gen_prefix.dom_subset [THEN subsetD]
simp add: length_type)
apply (subgoal_tac "length (zs) =0")
apply (drule_tac [2] not_lt_imp_le)
apply (rule_tac [5] j = "length (ys) " in lt_trans2)
apply auto
done
lemma strict_prefix_length_lt:
"\<langle>xs,ys\<rangle>:strict_prefix(A) \<Longrightarrow> length(xs) < length(ys)"
unfolding strict_prefix_def
apply (rule strict_prefix_length_lt_aux [THEN mp])
apply (auto dest: prefix_type [THEN subsetD])
done
(*Equivalence to the definition used in Lex/Prefix.thy*)
lemma prefix_iff:
"\<langle>xs,zs\<rangle> \<in> prefix(A) \<longleftrightarrow> (\<exists>ys \<in> list(A). zs = xs@ys) \<and> xs \<in> list(A)"
unfolding prefix_def
apply (auto simp add: gen_prefix_iff_nth lt_nat_in_nat nth_append nth_type app_type length_app)
apply (subgoal_tac "drop (length (xs), zs) \<in> list (A) ")
apply (rule_tac x = "drop (length (xs), zs) " in bexI)
apply safe
prefer 2 apply (simp add: length_type drop_type)
apply (rule nth_equalityI)
apply (simp_all (no_asm_simp) add: nth_append app_type drop_type length_app length_drop)
apply (rule nat_diff_split [THEN iffD2], simp_all, clarify)
apply (drule_tac i = "length (zs) " in leI)
apply (force simp add: le_subset_iff, safe)
apply (subgoal_tac "length (xs) #+ (i #- length (xs)) = i")
apply (subst nth_drop)
apply (simp_all (no_asm_simp) add: leI split: nat_diff_split)
done
lemma prefix_snoc:
"\<lbrakk>xs \<in> list(A); ys \<in> list(A); y \<in> A\<rbrakk> \<Longrightarrow>
<xs, ys@[y]> \<in> prefix(A) \<longleftrightarrow> (xs = ys@[y] | \<langle>xs,ys\<rangle> \<in> prefix(A))"
apply (simp (no_asm) add: prefix_iff)
apply (rule iffI, clarify)
apply (erule_tac xs = ysa in rev_list_elim, simp)
apply (simp add: app_type app_assoc [symmetric])
apply (auto simp add: app_assoc app_type)
done
declare prefix_snoc [simp]
lemma prefix_append_iff [rule_format]: "zs \<in> list(A) \<Longrightarrow> \<forall>xs \<in> list(A). \<forall>ys \<in> list(A).
(<xs, ys@zs> \<in> prefix(A)) \<longleftrightarrow>
(\<langle>xs,ys\<rangle> \<in> prefix(A) | (\<exists>us. xs = ys@us \<and> \<langle>us,zs\<rangle> \<in> prefix(A)))"
apply (erule list_append_induct, force, clarify)
apply (rule iffI)
apply (simp add: add: app_assoc [symmetric])
apply (erule disjE)
apply (rule disjI2)
apply (rule_tac x = "y @ [x]" in exI)
apply (simp add: add: app_assoc [symmetric], force+)
done
(*Although the prefix ordering is not linear, the prefixes of a list
are linearly ordered.*)
lemma common_prefix_linear_lemma [rule_format]: "\<lbrakk>zs \<in> list(A); xs \<in> list(A); ys \<in> list(A)\<rbrakk>
\<Longrightarrow> \<langle>xs, zs\<rangle> \<in> prefix(A) \<longrightarrow> \<langle>ys,zs\<rangle> \<in> prefix(A)
\<longrightarrow>\<langle>xs,ys\<rangle> \<in> prefix(A) | \<langle>ys,xs\<rangle> \<in> prefix(A)"
apply (erule list_append_induct, auto)
done
lemma common_prefix_linear: "\<lbrakk>\<langle>xs, zs\<rangle> \<in> prefix(A); \<langle>ys,zs\<rangle> \<in> prefix(A)\<rbrakk>
\<Longrightarrow> \<langle>xs,ys\<rangle> \<in> prefix(A) | \<langle>ys,xs\<rangle> \<in> prefix(A)"
apply (cut_tac prefix_type)
apply (blast del: disjCI intro: common_prefix_linear_lemma)
done
(*** pfixLe, pfixGe \<in> properties inherited from the translations ***)
(** pfixLe **)
lemma refl_Le: "refl(nat,Le)"
apply (unfold refl_def, auto)
done
declare refl_Le [simp]
lemma antisym_Le: "antisym(Le)"
unfolding antisym_def
apply (auto intro: le_anti_sym)
done
declare antisym_Le [simp]
lemma trans_on_Le: "trans[nat](Le)"
apply (unfold trans_on_def, auto)
apply (blast intro: le_trans)
done
declare trans_on_Le [simp]
lemma trans_Le: "trans(Le)"
apply (unfold trans_def, auto)
apply (blast intro: le_trans)
done
declare trans_Le [simp]
lemma part_order_Le: "part_order(nat,Le)"
by (unfold part_order_def, auto)
declare part_order_Le [simp]
lemma pfixLe_refl: "x \<in> list(nat) \<Longrightarrow> x pfixLe x"
by (blast intro: refl_gen_prefix [THEN reflD] refl_Le)
declare pfixLe_refl [simp]
lemma pfixLe_trans: "\<lbrakk>x pfixLe y; y pfixLe z\<rbrakk> \<Longrightarrow> x pfixLe z"
by (blast intro: trans_gen_prefix [THEN transD] trans_Le)
lemma pfixLe_antisym: "\<lbrakk>x pfixLe y; y pfixLe x\<rbrakk> \<Longrightarrow> x = y"
by (blast intro: antisym_gen_prefix [THEN antisymE] antisym_Le)
lemma prefix_imp_pfixLe:
"\<langle>xs,ys\<rangle>:prefix(nat)\<Longrightarrow> xs pfixLe ys"
unfolding prefix_def
apply (rule gen_prefix_mono [THEN subsetD], auto)
done
lemma refl_Ge: "refl(nat, Ge)"
by (unfold refl_def Ge_def, auto)
declare refl_Ge [iff]
lemma antisym_Ge: "antisym(Ge)"
unfolding antisym_def Ge_def
apply (auto intro: le_anti_sym)
done
declare antisym_Ge [iff]
lemma trans_Ge: "trans(Ge)"
unfolding trans_def Ge_def
apply (auto intro: le_trans)
done
declare trans_Ge [iff]
lemma pfixGe_refl: "x \<in> list(nat) \<Longrightarrow> x pfixGe x"
by (blast intro: refl_gen_prefix [THEN reflD])
declare pfixGe_refl [simp]
lemma pfixGe_trans: "\<lbrakk>x pfixGe y; y pfixGe z\<rbrakk> \<Longrightarrow> x pfixGe z"
by (blast intro: trans_gen_prefix [THEN transD])
lemma pfixGe_antisym: "\<lbrakk>x pfixGe y; y pfixGe x\<rbrakk> \<Longrightarrow> x = y"
by (blast intro: antisym_gen_prefix [THEN antisymE])
lemma prefix_imp_pfixGe:
"\<langle>xs,ys\<rangle>:prefix(nat) \<Longrightarrow> xs pfixGe ys"
unfolding prefix_def Ge_def
apply (rule gen_prefix_mono [THEN subsetD], auto)
done
(* Added by Sidi \<in> prefix and take *)
lemma prefix_imp_take:
"\<langle>xs, ys\<rangle> \<in> prefix(A) \<Longrightarrow> xs = take(length(xs), ys)"
unfolding prefix_def
apply (erule gen_prefix.induct)
apply (subgoal_tac [3] "length (xs) :nat")
apply (auto dest: gen_prefix.dom_subset [THEN subsetD] simp add: length_type)
apply (frule gen_prefix.dom_subset [THEN subsetD])
apply (frule gen_prefix_length_le)
apply (auto simp add: take_append)
apply (subgoal_tac "length (xs) #- length (ys) =0")
apply (simp_all (no_asm_simp) add: diff_is_0_iff)
done
lemma prefix_length_equal: "\<lbrakk>\<langle>xs,ys\<rangle> \<in> prefix(A); length(xs)=length(ys)\<rbrakk> \<Longrightarrow> xs = ys"
apply (cut_tac A = A in prefix_type)
apply (drule subsetD, auto)
apply (drule prefix_imp_take)
apply (erule trans, simp)
done
lemma prefix_length_le_equal: "\<lbrakk>\<langle>xs,ys\<rangle> \<in> prefix(A); length(ys) \<le> length(xs)\<rbrakk> \<Longrightarrow> xs = ys"
by (blast intro: prefix_length_equal le_anti_sym prefix_length_le)
lemma take_prefix [rule_format]: "xs \<in> list(A) \<Longrightarrow> \<forall>n \<in> nat. <take(n, xs), xs> \<in> prefix(A)"
unfolding prefix_def
apply (erule list.induct, simp, clarify)
apply (erule natE, auto)
done
lemma prefix_take_iff: "\<langle>xs,ys\<rangle> \<in> prefix(A) \<longleftrightarrow> (xs=take(length(xs), ys) \<and> xs \<in> list(A) \<and> ys \<in> list(A))"
apply (rule iffI)
apply (frule prefix_type [THEN subsetD])
apply (blast intro: prefix_imp_take, clarify)
apply (erule ssubst)
apply (blast intro: take_prefix length_type)
done
lemma prefix_imp_nth: "\<lbrakk>\<langle>xs,ys\<rangle> \<in> prefix(A); i < length(xs)\<rbrakk> \<Longrightarrow> nth(i,xs) = nth(i,ys)"
by (auto dest!: gen_prefix_imp_nth simp add: prefix_def)
lemma nth_imp_prefix:
"\<lbrakk>xs \<in> list(A); ys \<in> list(A); length(xs) \<le> length(ys);
\<And>i. i < length(xs) \<Longrightarrow> nth(i, xs) = nth(i,ys)\<rbrakk>
\<Longrightarrow> \<langle>xs,ys\<rangle> \<in> prefix(A)"
apply (auto simp add: prefix_def nth_imp_gen_prefix)
apply (auto intro!: nth_imp_gen_prefix simp add: prefix_def)
apply (blast intro: nth_type lt_trans2)
done
lemma length_le_prefix_imp_prefix: "\<lbrakk>length(xs) \<le> length(ys);
\<langle>xs,zs\<rangle> \<in> prefix(A); \<langle>ys,zs\<rangle> \<in> prefix(A)\<rbrakk> \<Longrightarrow> \<langle>xs,ys\<rangle> \<in> prefix(A)"
apply (cut_tac A = A in prefix_type)
apply (rule nth_imp_prefix, blast, blast)
apply assumption
apply (rule_tac b = "nth (i,zs)" in trans)
apply (blast intro: prefix_imp_nth)
apply (blast intro: sym prefix_imp_nth prefix_length_le lt_trans2)
done
end
|
[STATEMENT]
lemma ide_exp:
assumes "ide b" and "ide c"
shows "ide (exp b c)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. ide (exp b c)
[PROOF STEP]
using assms exp_def hf_to_ide_mapsto ide_to_hf_mapsto
[PROOF STATE]
proof (prove)
using this:
ide b
ide c
exp ?b ?c = hf_to_ide (hexp (ide_to_hf ?b) (ide_to_hf ?c))
hf_to_ide \<in> UNIV \<rightarrow> Collect ide
ide_to_hf \<in> Collect ide \<rightarrow> UNIV
goal (1 subgoal):
1. ide (exp b c)
[PROOF STEP]
by auto |
[STATEMENT]
lemma c_smj_symm: "symmetric (c_smj cf f)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. symmetric (c_smj cf f)
[PROOF STEP]
by (simp add: symmetric_def) |
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ bound a * ‖x - x₀‖
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
⊢ Integrable F' ∧ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
have x₀_in : x₀ ∈ ball x₀ ε := mem_ball_self ε_pos
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ bound a * ‖x - x₀‖
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
⊢ Integrable F' ∧ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
have nneg : ∀ x, 0 ≤ ‖x - x₀‖⁻¹ := fun x => inv_nonneg.mpr (norm_nonneg _)
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ bound a * ‖x - x₀‖
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
⊢ Integrable F' ∧ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
set b : α → ℝ := fun a => |bound a|
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ bound a * ‖x - x₀‖
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
⊢ Integrable F' ∧ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
have b_int : Integrable b μ := bound_integrable.norm
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ bound a * ‖x - x₀‖
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
⊢ Integrable F' ∧ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
have b_nonneg : ∀ a, 0 ≤ b a := fun a => abs_nonneg _
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ bound a * ‖x - x₀‖
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
⊢ Integrable F' ∧ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
replace h_lipsch : ∀ᵐ a ∂μ, ∀ x ∈ ball x₀ ε, ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
[GOAL]
case h_lipsch
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ bound a * ‖x - x₀‖
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
⊢ ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ Integrable F' ∧ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
exact h_lipsch.mono fun a ha x hx => (ha x hx).trans <| mul_le_mul_of_nonneg_right (le_abs_self _) (norm_nonneg _)
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ Integrable F' ∧ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
have hF_int' : ∀ x ∈ ball x₀ ε, Integrable (F x) μ := fun x x_in ↦
by
have : ∀ᵐ a ∂μ, ‖F x₀ a - F x a‖ ≤ ε * b a :=
by
simp only [norm_sub_rev (F x₀ _)]
refine' h_lipsch.mono fun a ha => (ha x x_in).trans _
rw [mul_comm ε]
rw [mem_ball, dist_eq_norm] at x_in
exact mul_le_mul_of_nonneg_left x_in.le (b_nonneg _)
exact integrable_of_norm_sub_le (hF_meas x x_in) hF_int (bound_integrable.norm.const_mul ε) this
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
x : H
x_in : x ∈ ball x₀ ε
⊢ Integrable (F x)
[PROOFSTEP]
have : ∀ᵐ a ∂μ, ‖F x₀ a - F x a‖ ≤ ε * b a :=
by
simp only [norm_sub_rev (F x₀ _)]
refine' h_lipsch.mono fun a ha => (ha x x_in).trans _
rw [mul_comm ε]
rw [mem_ball, dist_eq_norm] at x_in
exact mul_le_mul_of_nonneg_left x_in.le (b_nonneg _)
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
x : H
x_in : x ∈ ball x₀ ε
⊢ ∀ᵐ (a : α) ∂μ, ‖F x₀ a - F x a‖ ≤ ε * b a
[PROOFSTEP]
simp only [norm_sub_rev (F x₀ _)]
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
x : H
x_in : x ∈ ball x₀ ε
⊢ ∀ᵐ (a : α) ∂μ, ‖F x a - F x₀ a‖ ≤ ε * |bound a|
[PROOFSTEP]
refine' h_lipsch.mono fun a ha => (ha x x_in).trans _
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
x : H
x_in : x ∈ ball x₀ ε
a : α
ha : ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ b a * ‖x - x₀‖ ≤ ε * |bound a|
[PROOFSTEP]
rw [mul_comm ε]
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
x : H
x_in : x ∈ ball x₀ ε
a : α
ha : ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ b a * ‖x - x₀‖ ≤ |bound a| * ε
[PROOFSTEP]
rw [mem_ball, dist_eq_norm] at x_in
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
x : H
x_in : ‖x - x₀‖ < ε
a : α
ha : ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ b a * ‖x - x₀‖ ≤ |bound a| * ε
[PROOFSTEP]
exact mul_le_mul_of_nonneg_left x_in.le (b_nonneg _)
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
x : H
x_in : x ∈ ball x₀ ε
this : ∀ᵐ (a : α) ∂μ, ‖F x₀ a - F x a‖ ≤ ε * b a
⊢ Integrable (F x)
[PROOFSTEP]
exact integrable_of_norm_sub_le (hF_meas x x_in) hF_int (bound_integrable.norm.const_mul ε) this
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
⊢ Integrable F' ∧ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
have hF'_int : Integrable F' μ :=
have : ∀ᵐ a ∂μ, ‖F' a‖ ≤ b a := by
apply (h_diff.and h_lipsch).mono
rintro a ⟨ha_diff, ha_lip⟩
refine' ha_diff.le_of_lip' (b_nonneg a) (mem_of_superset (ball_mem_nhds _ ε_pos) <| ha_lip)
b_int.mono' hF'_meas this
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
⊢ ∀ᵐ (a : α) ∂μ, ‖F' a‖ ≤ b a
[PROOFSTEP]
apply (h_diff.and h_lipsch).mono
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
⊢ ∀ (x : α),
(HasFDerivAt (fun x_1 => F x_1 x) (F' x) x₀ ∧
∀ (x_1 : H), x_1 ∈ ball x₀ ε → ‖F x_1 x - F x₀ x‖ ≤ b x * ‖x_1 - x₀‖) →
‖F' x‖ ≤ b x
[PROOFSTEP]
rintro a ⟨ha_diff, ha_lip⟩
[GOAL]
case intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
a : α
ha_diff : HasFDerivAt (fun x => F x a) (F' a) x₀
ha_lip : ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ ‖F' a‖ ≤ b a
[PROOFSTEP]
refine' ha_diff.le_of_lip' (b_nonneg a) (mem_of_superset (ball_mem_nhds _ ε_pos) <| ha_lip)
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
⊢ Integrable F' ∧ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
refine' ⟨hF'_int, _⟩
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
⊢ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
have h_ball : ball x₀ ε ∈ 𝓝 x₀ := ball_mem_nhds x₀ ε_pos
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
⊢ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
have :
∀ᶠ x in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖((∫ a, F x a ∂μ) - ∫ a, F x₀ a ∂μ) - (∫ a, F' a ∂μ) (x - x₀)‖ =
‖∫ a, ‖x - x₀‖⁻¹ • (F x a - F x₀ a - F' a (x - x₀)) ∂μ‖ :=
by
apply mem_of_superset (ball_mem_nhds _ ε_pos)
intro x x_in; simp only
rw [Set.mem_setOf_eq, ← norm_smul_of_nonneg (nneg _), integral_smul, integral_sub, integral_sub, ←
ContinuousLinearMap.integral_apply hF'_int]
exacts [hF_int' x x_in, hF_int, (hF_int' x x_in).sub hF_int, hF'_int.apply_continuousLinearMap _]
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
⊢ ∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
[PROOFSTEP]
apply mem_of_superset (ball_mem_nhds _ ε_pos)
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
⊢ ball x₀ ε ⊆
{x |
(fun x =>
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖)
x}
[PROOFSTEP]
intro x x_in
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
x : H
x_in : x ∈ ball x₀ ε
⊢ x ∈
{x |
(fun x =>
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖)
x}
[PROOFSTEP]
simp only
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
x : H
x_in : x ∈ ball x₀ ε
⊢ x ∈
{x |
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖}
[PROOFSTEP]
rw [Set.mem_setOf_eq, ← norm_smul_of_nonneg (nneg _), integral_smul, integral_sub, integral_sub, ←
ContinuousLinearMap.integral_apply hF'_int]
[GOAL]
case hf
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
x : H
x_in : x ∈ ball x₀ ε
⊢ Integrable fun a => F x a
case hg
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
x : H
x_in : x ∈ ball x₀ ε
⊢ Integrable fun a => F x₀ a
case hf
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
x : H
x_in : x ∈ ball x₀ ε
⊢ Integrable fun a => F x a - F x₀ a
case hg
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
x : H
x_in : x ∈ ball x₀ ε
⊢ Integrable fun a => ↑(F' a) (x - x₀)
[PROOFSTEP]
exacts [hF_int' x x_in, hF_int, (hF_int' x x_in).sub hF_int, hF'_int.apply_continuousLinearMap _]
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
⊢ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
rw [hasFDerivAt_iff_tendsto, tendsto_congr' this, ← tendsto_zero_iff_norm_tendsto_zero, ←
show (∫ a : α, ‖x₀ - x₀‖⁻¹ • (F x₀ a - F x₀ a - (F' a) (x₀ - x₀)) ∂μ) = 0 by simp]
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
⊢ ∫ (a : α), ‖x₀ - x₀‖⁻¹ • (F x₀ a - F x₀ a - ↑(F' a) (x₀ - x₀)) ∂μ = 0
[PROOFSTEP]
simp
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
⊢ Tendsto (fun x => ∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ) (𝓝 x₀)
(𝓝 (∫ (a : α), ‖x₀ - x₀‖⁻¹ • (F x₀ a - F x₀ a - ↑(F' a) (x₀ - x₀)) ∂μ))
[PROOFSTEP]
apply tendsto_integral_filter_of_dominated_convergence
[GOAL]
case hF_meas
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
⊢ ∀ᶠ (n : H) in 𝓝 x₀, AEStronglyMeasurable (fun a => ‖n - x₀‖⁻¹ • (F n a - F x₀ a - ↑(F' a) (n - x₀))) μ
[PROOFSTEP]
filter_upwards [h_ball] with _ x_in
[GOAL]
case h
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
a✝ : H
x_in : a✝ ∈ ball x₀ ε
⊢ AEStronglyMeasurable (fun a => ‖a✝ - x₀‖⁻¹ • (F a✝ a - F x₀ a - ↑(F' a) (a✝ - x₀))) μ
[PROOFSTEP]
apply AEStronglyMeasurable.const_smul
[GOAL]
case h.hf
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
a✝ : H
x_in : a✝ ∈ ball x₀ ε
⊢ AEStronglyMeasurable (fun a => F a✝ a - F x₀ a - ↑(F' a) (a✝ - x₀)) μ
[PROOFSTEP]
exact ((hF_meas _ x_in).sub (hF_meas _ x₀_in)).sub (hF'_meas.apply_continuousLinearMap _)
[GOAL]
case h_bound
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
⊢ ∀ᶠ (n : H) in 𝓝 x₀, ∀ᵐ (a : α) ∂μ, ‖‖n - x₀‖⁻¹ • (F n a - F x₀ a - ↑(F' a) (n - x₀))‖ ≤ ?bound a
[PROOFSTEP]
refine mem_of_superset h_ball fun x hx ↦ ?_
[GOAL]
case h_bound
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
⊢ x ∈ {x | (fun n => ∀ᵐ (a : α) ∂μ, ‖‖n - x₀‖⁻¹ • (F n a - F x₀ a - ↑(F' a) (n - x₀))‖ ≤ ?bound a) x}
[PROOFSTEP]
apply (h_diff.and h_lipsch).mono
[GOAL]
case h_bound
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
⊢ ∀ (x_1 : α),
(HasFDerivAt (fun x => F x x_1) (F' x_1) x₀ ∧ ∀ (x : H), x ∈ ball x₀ ε → ‖F x x_1 - F x₀ x_1‖ ≤ b x_1 * ‖x - x₀‖) →
‖‖x - x₀‖⁻¹ • (F x x_1 - F x₀ x_1 - ↑(F' x_1) (x - x₀))‖ ≤ ?bound x_1
case bound
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
⊢ α → ℝ
[PROOFSTEP]
rintro a ⟨-, ha_bound⟩
[GOAL]
case h_bound.intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ ‖‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀))‖ ≤ ?bound a
case bound
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
⊢ α → ℝ
[PROOFSTEP]
show ‖‖x - x₀‖⁻¹ • (F x a - F x₀ a - F' a (x - x₀))‖ ≤ b a + ‖F' a‖
[GOAL]
case h_bound.intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ ‖‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀))‖ ≤ b a + ‖F' a‖
[PROOFSTEP]
replace ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖ := ha_bound x hx
[GOAL]
case h_bound.intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ ‖‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀))‖ ≤ b a + ‖F' a‖
[PROOFSTEP]
calc
‖‖x - x₀‖⁻¹ • (F x a - F x₀ a - F' a (x - x₀))‖ = ‖‖x - x₀‖⁻¹ • (F x a - F x₀ a) - ‖x - x₀‖⁻¹ • F' a (x - x₀)‖ := by
rw [smul_sub]
_ ≤ ‖‖x - x₀‖⁻¹ • (F x a - F x₀ a)‖ + ‖‖x - x₀‖⁻¹ • F' a (x - x₀)‖ := (norm_sub_le _ _)
_ = ‖x - x₀‖⁻¹ * ‖F x a - F x₀ a‖ + ‖x - x₀‖⁻¹ * ‖F' a (x - x₀)‖ := by
rw [norm_smul_of_nonneg, norm_smul_of_nonneg] <;> exact nneg _
_ ≤ ‖x - x₀‖⁻¹ * (b a * ‖x - x₀‖) + ‖x - x₀‖⁻¹ * (‖F' a‖ * ‖x - x₀‖) := by gcongr; exact (F' a).le_op_norm _
_ ≤ b a + ‖F' a‖ := ?_
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ ‖‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀))‖ = ‖‖x - x₀‖⁻¹ • (F x a - F x₀ a) - ‖x - x₀‖⁻¹ • ↑(F' a) (x - x₀)‖
[PROOFSTEP]
rw [smul_sub]
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ ‖‖x - x₀‖⁻¹ • (F x a - F x₀ a)‖ + ‖‖x - x₀‖⁻¹ • ↑(F' a) (x - x₀)‖ =
‖x - x₀‖⁻¹ * ‖F x a - F x₀ a‖ + ‖x - x₀‖⁻¹ * ‖↑(F' a) (x - x₀)‖
[PROOFSTEP]
rw [norm_smul_of_nonneg, norm_smul_of_nonneg]
[GOAL]
case ht
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ 0 ≤ ‖x - x₀‖⁻¹
[PROOFSTEP]
exact nneg _
[GOAL]
case ht
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ 0 ≤ ‖x - x₀‖⁻¹
[PROOFSTEP]
exact nneg _
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ ‖x - x₀‖⁻¹ * ‖F x a - F x₀ a‖ + ‖x - x₀‖⁻¹ * ‖↑(F' a) (x - x₀)‖ ≤
‖x - x₀‖⁻¹ * (b a * ‖x - x₀‖) + ‖x - x₀‖⁻¹ * (‖F' a‖ * ‖x - x₀‖)
[PROOFSTEP]
gcongr
[GOAL]
case h₂.h
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ ‖↑(F' a) (x - x₀)‖ ≤ ‖F' a‖ * ‖x - x₀‖
[PROOFSTEP]
exact (F' a).le_op_norm _
[GOAL]
case h_bound.intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ ‖x - x₀‖⁻¹ * (b a * ‖x - x₀‖) + ‖x - x₀‖⁻¹ * (‖F' a‖ * ‖x - x₀‖) ≤ b a + ‖F' a‖
[PROOFSTEP]
simp only [← div_eq_inv_mul]
[GOAL]
case h_bound.intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ |bound a| * ‖x - x₀‖ / ‖x - x₀‖ + ‖F' a‖ * ‖x - x₀‖ / ‖x - x₀‖ ≤ |bound a| + ‖F' a‖
[PROOFSTEP]
apply_rules [add_le_add, div_le_of_nonneg_of_le_mul]
[GOAL]
case h_bound.intro.h₁.hb
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ 0 ≤ ‖x - x₀‖
[PROOFSTEP]
first
| rfl
| positivity
[GOAL]
case h_bound.intro.h₁.hb
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ 0 ≤ ‖x - x₀‖
[PROOFSTEP]
rfl
[GOAL]
case h_bound.intro.h₁.hb
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ 0 ≤ ‖x - x₀‖
[PROOFSTEP]
positivity
[GOAL]
case h_bound.intro.h₁.h
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ |bound a| * ‖x - x₀‖ ≤ |bound a| * ‖x - x₀‖
[PROOFSTEP]
first
| rfl
| positivity
[GOAL]
case h_bound.intro.h₁.h
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ |bound a| * ‖x - x₀‖ ≤ |bound a| * ‖x - x₀‖
[PROOFSTEP]
rfl
[GOAL]
case h_bound.intro.h₂.hb
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ 0 ≤ ‖x - x₀‖
[PROOFSTEP]
first
| rfl
| positivity
[GOAL]
case h_bound.intro.h₂.hb
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ 0 ≤ ‖x - x₀‖
[PROOFSTEP]
rfl
[GOAL]
case h_bound.intro.h₂.hb
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ 0 ≤ ‖x - x₀‖
[PROOFSTEP]
positivity
[GOAL]
case h_bound.intro.h₂.hc
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ 0 ≤ ‖F' a‖
[PROOFSTEP]
first
| rfl
| positivity
[GOAL]
case h_bound.intro.h₂.hc
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ 0 ≤ ‖F' a‖
[PROOFSTEP]
rfl
[GOAL]
case h_bound.intro.h₂.hc
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ 0 ≤ ‖F' a‖
[PROOFSTEP]
positivity
[GOAL]
case h_bound.intro.h₂.h
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ ‖F' a‖ * ‖x - x₀‖ ≤ ‖F' a‖ * ‖x - x₀‖
[PROOFSTEP]
first
| rfl
| positivity
[GOAL]
case h_bound.intro.h₂.h
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
x : H
hx : x ∈ ball x₀ ε
a : α
ha_bound : ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
⊢ ‖F' a‖ * ‖x - x₀‖ ≤ ‖F' a‖ * ‖x - x₀‖
[PROOFSTEP]
rfl
[GOAL]
case bound_integrable
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
⊢ Integrable fun a => b a + ‖F' a‖
[PROOFSTEP]
exact b_int.add hF'_int.norm
[GOAL]
case h_lim
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
⊢ ∀ᵐ (a : α) ∂μ,
Tendsto (fun n => ‖n - x₀‖⁻¹ • (F n a - F x₀ a - ↑(F' a) (n - x₀))) (𝓝 x₀)
(𝓝 (‖x₀ - x₀‖⁻¹ • (F x₀ a - F x₀ a - ↑(F' a) (x₀ - x₀))))
[PROOFSTEP]
apply h_diff.mono
[GOAL]
case h_lim
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
⊢ ∀ (x : α),
HasFDerivAt (fun x_1 => F x_1 x) (F' x) x₀ →
Tendsto (fun n => ‖n - x₀‖⁻¹ • (F n x - F x₀ x - ↑(F' x) (n - x₀))) (𝓝 x₀)
(𝓝 (‖x₀ - x₀‖⁻¹ • (F x₀ x - F x₀ x - ↑(F' x) (x₀ - x₀))))
[PROOFSTEP]
intro a ha
[GOAL]
case h_lim
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
a : α
ha : HasFDerivAt (fun x => F x a) (F' a) x₀
⊢ Tendsto (fun n => ‖n - x₀‖⁻¹ • (F n a - F x₀ a - ↑(F' a) (n - x₀))) (𝓝 x₀)
(𝓝 (‖x₀ - x₀‖⁻¹ • (F x₀ a - F x₀ a - ↑(F' a) (x₀ - x₀))))
[PROOFSTEP]
suffices Tendsto (fun x => ‖x - x₀‖⁻¹ • (F x a - F x₀ a - F' a (x - x₀))) (𝓝 x₀) (𝓝 0) by simpa
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this✝ :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
a : α
ha : HasFDerivAt (fun x => F x a) (F' a) x₀
this : Tendsto (fun x => ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀))) (𝓝 x₀) (𝓝 0)
⊢ Tendsto (fun n => ‖n - x₀‖⁻¹ • (F n a - F x₀ a - ↑(F' a) (n - x₀))) (𝓝 x₀)
(𝓝 (‖x₀ - x₀‖⁻¹ • (F x₀ a - F x₀ a - ↑(F' a) (x₀ - x₀))))
[PROOFSTEP]
simpa
[GOAL]
case h_lim
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
a : α
ha : HasFDerivAt (fun x => F x a) (F' a) x₀
⊢ Tendsto (fun x => ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀))) (𝓝 x₀) (𝓝 0)
[PROOFSTEP]
rw [tendsto_zero_iff_norm_tendsto_zero]
[GOAL]
case h_lim
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
a : α
ha : HasFDerivAt (fun x => F x a) (F' a) x₀
⊢ Tendsto (fun e => ‖‖e - x₀‖⁻¹ • (F e a - F x₀ a - ↑(F' a) (e - x₀))‖) (𝓝 x₀) (𝓝 0)
[PROOFSTEP]
have :
(fun x => ‖x - x₀‖⁻¹ * ‖F x a - F x₀ a - F' a (x - x₀)‖) = fun x => ‖‖x - x₀‖⁻¹ • (F x a - F x₀ a - F' a (x - x₀))‖ :=
by
ext x
rw [norm_smul_of_nonneg (nneg _)]
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
a : α
ha : HasFDerivAt (fun x => F x a) (F' a) x₀
⊢ (fun x => ‖x - x₀‖⁻¹ * ‖F x a - F x₀ a - ↑(F' a) (x - x₀)‖) = fun x =>
‖‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀))‖
[PROOFSTEP]
ext x
[GOAL]
case h
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
a : α
ha : HasFDerivAt (fun x => F x a) (F' a) x₀
x : H
⊢ ‖x - x₀‖⁻¹ * ‖F x a - F x₀ a - ↑(F' a) (x - x₀)‖ = ‖‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀))‖
[PROOFSTEP]
rw [norm_smul_of_nonneg (nneg _)]
[GOAL]
case h_lim
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ (x : H), x ∈ ball x₀ ε → AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
x₀_in : x₀ ∈ ball x₀ ε
nneg : ∀ (x : H), 0 ≤ ‖x - x₀‖⁻¹
b : α → ℝ := fun a => |bound a|
b_int : Integrable b
b_nonneg : ∀ (a : α), 0 ≤ b a
h_lipsch : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F x a - F x₀ a‖ ≤ b a * ‖x - x₀‖
hF_int' : ∀ (x : H), x ∈ ball x₀ ε → Integrable (F x)
hF'_int : Integrable F'
h_ball : ball x₀ ε ∈ 𝓝 x₀
this✝ :
∀ᶠ (x : H) in 𝓝 x₀,
‖x - x₀‖⁻¹ * ‖∫ (a : α), F x a ∂μ - ∫ (a : α), F x₀ a ∂μ - ↑(∫ (a : α), F' a ∂μ) (x - x₀)‖ =
‖∫ (a : α), ‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀)) ∂μ‖
a : α
ha : HasFDerivAt (fun x => F x a) (F' a) x₀
this :
(fun x => ‖x - x₀‖⁻¹ * ‖F x a - F x₀ a - ↑(F' a) (x - x₀)‖) = fun x =>
‖‖x - x₀‖⁻¹ • (F x a - F x₀ a - ↑(F' a) (x - x₀))‖
⊢ Tendsto (fun e => ‖‖e - x₀‖⁻¹ • (F e a - F x₀ a - ↑(F' a) (e - x₀))‖) (𝓝 x₀) (𝓝 0)
[PROOFSTEP]
rwa [hasFDerivAt_iff_tendsto, this] at ha
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_lip : ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
⊢ Integrable F' ∧ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
obtain ⟨δ, δ_pos, hδ⟩ : ∃ δ > 0, ∀ x ∈ ball x₀ δ, AEStronglyMeasurable (F x) μ ∧ x ∈ ball x₀ ε
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_lip : ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
⊢ ∃ δ, δ > 0 ∧ ∀ (x : H), x ∈ ball x₀ δ → AEStronglyMeasurable (F x) μ ∧ x ∈ ball x₀ ε
case intro.intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_lip : ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
δ : ℝ
δ_pos : δ > 0
hδ : ∀ (x : H), x ∈ ball x₀ δ → AEStronglyMeasurable (F x) μ ∧ x ∈ ball x₀ ε
⊢ Integrable F' ∧ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
exact eventually_nhds_iff_ball.mp (hF_meas.and (ball_mem_nhds x₀ ε_pos))
[GOAL]
case intro.intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_lip : ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
δ : ℝ
δ_pos : δ > 0
hδ : ∀ (x : H), x ∈ ball x₀ δ → AEStronglyMeasurable (F x) μ ∧ x ∈ ball x₀ ε
⊢ Integrable F' ∧ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
choose hδ_meas hδε using hδ
[GOAL]
case intro.intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_lip : ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
δ : ℝ
δ_pos : δ > 0
hδ_meas : ∀ (x : H), x ∈ ball x₀ δ → AEStronglyMeasurable (F x) μ
hδε : ∀ (x : H), x ∈ ball x₀ δ → x ∈ ball x₀ ε
⊢ Integrable F' ∧ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
replace h_lip : ∀ᵐ a : α ∂μ, ∀ x ∈ ball x₀ δ, ‖F x a - F x₀ a‖ ≤ |bound a| * ‖x - x₀‖
[GOAL]
case h_lip
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_lip : ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
δ : ℝ
δ_pos : δ > 0
hδ_meas : ∀ (x : H), x ∈ ball x₀ δ → AEStronglyMeasurable (F x) μ
hδε : ∀ (x : H), x ∈ ball x₀ δ → x ∈ ball x₀ ε
⊢ ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ δ → ‖F x a - F x₀ a‖ ≤ |bound a| * ‖x - x₀‖
case intro.intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
δ : ℝ
δ_pos : δ > 0
hδ_meas : ∀ (x : H), x ∈ ball x₀ δ → AEStronglyMeasurable (F x) μ
hδε : ∀ (x : H), x ∈ ball x₀ δ → x ∈ ball x₀ ε
h_lip : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ δ → ‖F x a - F x₀ a‖ ≤ |bound a| * ‖x - x₀‖
⊢ Integrable F' ∧ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
exact h_lip.mono fun a lip x hx => lip.norm_sub_le (hδε x hx) (mem_ball_self ε_pos)
[GOAL]
case intro.intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
δ : ℝ
δ_pos : δ > 0
hδ_meas : ∀ (x : H), x ∈ ball x₀ δ → AEStronglyMeasurable (F x) μ
hδε : ∀ (x : H), x ∈ ball x₀ δ → x ∈ ball x₀ ε
h_lip : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ δ → ‖F x a - F x₀ a‖ ≤ |bound a| * ‖x - x₀‖
⊢ Integrable F' ∧ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
replace bound_integrable := bound_integrable.norm
[GOAL]
case intro.intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
δ : ℝ
δ_pos : δ > 0
hδ_meas : ∀ (x : H), x ∈ ball x₀ δ → AEStronglyMeasurable (F x) μ
hδε : ∀ (x : H), x ∈ ball x₀ δ → x ∈ ball x₀ ε
h_lip : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ δ → ‖F x a - F x₀ a‖ ≤ |bound a| * ‖x - x₀‖
bound_integrable : Integrable fun a => ‖bound a‖
⊢ Integrable F' ∧ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
apply hasFDerivAt_integral_of_dominated_loc_of_lip' δ_pos
[GOAL]
case intro.intro.hF_meas
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
δ : ℝ
δ_pos : δ > 0
hδ_meas : ∀ (x : H), x ∈ ball x₀ δ → AEStronglyMeasurable (F x) μ
hδε : ∀ (x : H), x ∈ ball x₀ δ → x ∈ ball x₀ ε
h_lip : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ δ → ‖F x a - F x₀ a‖ ≤ |bound a| * ‖x - x₀‖
bound_integrable : Integrable fun a => ‖bound a‖
⊢ ∀ (x : H), x ∈ ball x₀ δ → AEStronglyMeasurable (fun a => F x a) μ
[PROOFSTEP]
assumption
[GOAL]
case intro.intro.hF_int
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
δ : ℝ
δ_pos : δ > 0
hδ_meas : ∀ (x : H), x ∈ ball x₀ δ → AEStronglyMeasurable (F x) μ
hδε : ∀ (x : H), x ∈ ball x₀ δ → x ∈ ball x₀ ε
h_lip : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ δ → ‖F x a - F x₀ a‖ ≤ |bound a| * ‖x - x₀‖
bound_integrable : Integrable fun a => ‖bound a‖
⊢ Integrable fun a => F x₀ a
[PROOFSTEP]
assumption
[GOAL]
case intro.intro.hF'_meas
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
δ : ℝ
δ_pos : δ > 0
hδ_meas : ∀ (x : H), x ∈ ball x₀ δ → AEStronglyMeasurable (F x) μ
hδε : ∀ (x : H), x ∈ ball x₀ δ → x ∈ ball x₀ ε
h_lip : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ δ → ‖F x a - F x₀ a‖ ≤ |bound a| * ‖x - x₀‖
bound_integrable : Integrable fun a => ‖bound a‖
⊢ AEStronglyMeasurable F' μ
[PROOFSTEP]
assumption
[GOAL]
case intro.intro.h_lipsch
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
δ : ℝ
δ_pos : δ > 0
hδ_meas : ∀ (x : H), x ∈ ball x₀ δ → AEStronglyMeasurable (F x) μ
hδε : ∀ (x : H), x ∈ ball x₀ δ → x ∈ ball x₀ ε
h_lip : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ δ → ‖F x a - F x₀ a‖ ≤ |bound a| * ‖x - x₀‖
bound_integrable : Integrable fun a => ‖bound a‖
⊢ ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ δ → ‖F x a - F x₀ a‖ ≤ ?m.181944 a * ‖x - x₀‖
[PROOFSTEP]
assumption
[GOAL]
case intro.intro.bound_integrable
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
δ : ℝ
δ_pos : δ > 0
hδ_meas : ∀ (x : H), x ∈ ball x₀ δ → AEStronglyMeasurable (F x) μ
hδε : ∀ (x : H), x ∈ ball x₀ δ → x ∈ ball x₀ ε
h_lip : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ δ → ‖F x a - F x₀ a‖ ≤ |bound a| * ‖x - x₀‖
bound_integrable : Integrable fun a => ‖bound a‖
⊢ Integrable fun a => |bound a|
[PROOFSTEP]
assumption
[GOAL]
case intro.intro.h_diff
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
δ : ℝ
δ_pos : δ > 0
hδ_meas : ∀ (x : H), x ∈ ball x₀ δ → AEStronglyMeasurable (F x) μ
hδε : ∀ (x : H), x ∈ ball x₀ δ → x ∈ ball x₀ ε
h_lip : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ δ → ‖F x a - F x₀ a‖ ≤ |bound a| * ‖x - x₀‖
bound_integrable : Integrable fun a => ‖bound a‖
⊢ ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' a) x₀
[PROOFSTEP]
assumption
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : H → α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → HasFDerivAt (fun x => F x a) (F' x a) x
⊢ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' x₀ a ∂μ) x₀
[PROOFSTEP]
letI : NormedSpace ℝ H := NormedSpace.restrictScalars ℝ 𝕜 H
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : H → α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → HasFDerivAt (fun x => F x a) (F' x a) x
this : NormedSpace ℝ H := NormedSpace.restrictScalars ℝ 𝕜 H
⊢ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' x₀ a ∂μ) x₀
[PROOFSTEP]
have x₀_in : x₀ ∈ ball x₀ ε := mem_ball_self ε_pos
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : H → α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → HasFDerivAt (fun x => F x a) (F' x a) x
this : NormedSpace ℝ H := NormedSpace.restrictScalars ℝ 𝕜 H
x₀_in : x₀ ∈ ball x₀ ε
⊢ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' x₀ a ∂μ) x₀
[PROOFSTEP]
have diff_x₀ : ∀ᵐ a ∂μ, HasFDerivAt (fun x => F x a) (F' x₀ a) x₀ := h_diff.mono fun a ha => ha x₀ x₀_in
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : H → α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → HasFDerivAt (fun x => F x a) (F' x a) x
this : NormedSpace ℝ H := NormedSpace.restrictScalars ℝ 𝕜 H
x₀_in : x₀ ∈ ball x₀ ε
diff_x₀ : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' x₀ a) x₀
⊢ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' x₀ a ∂μ) x₀
[PROOFSTEP]
have : ∀ᵐ a ∂μ, LipschitzOnWith (Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε) :=
by
apply (h_diff.and h_bound).mono
rintro a ⟨ha_deriv, ha_bound⟩
refine'
(convex_ball _ _).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x x_in => (ha_deriv x x_in).hasFDerivWithinAt)
fun x x_in => _
rw [← NNReal.coe_le_coe, coe_nnnorm, Real.coe_nnabs]
exact (ha_bound x x_in).trans (le_abs_self _)
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : H → α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → HasFDerivAt (fun x => F x a) (F' x a) x
this : NormedSpace ℝ H := NormedSpace.restrictScalars ℝ 𝕜 H
x₀_in : x₀ ∈ ball x₀ ε
diff_x₀ : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' x₀ a) x₀
⊢ ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
[PROOFSTEP]
apply (h_diff.and h_bound).mono
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : H → α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → HasFDerivAt (fun x => F x a) (F' x a) x
this : NormedSpace ℝ H := NormedSpace.restrictScalars ℝ 𝕜 H
x₀_in : x₀ ∈ ball x₀ ε
diff_x₀ : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' x₀ a) x₀
⊢ ∀ (x : α),
((∀ (x_1 : H), x_1 ∈ ball x₀ ε → HasFDerivAt (fun x_2 => F x_2 x) (F' x_1 x) x_1) ∧
∀ (x_1 : H), x_1 ∈ ball x₀ ε → ‖F' x_1 x‖ ≤ bound x) →
LipschitzOnWith (↑Real.nnabs (bound x)) (fun x_1 => F x_1 x) (ball x₀ ε)
[PROOFSTEP]
rintro a ⟨ha_deriv, ha_bound⟩
[GOAL]
case intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : H → α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → HasFDerivAt (fun x => F x a) (F' x a) x
this : NormedSpace ℝ H := NormedSpace.restrictScalars ℝ 𝕜 H
x₀_in : x₀ ∈ ball x₀ ε
diff_x₀ : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' x₀ a) x₀
a : α
ha_deriv : ∀ (x : H), x ∈ ball x₀ ε → HasFDerivAt (fun x => F x a) (F' x a) x
ha_bound : ∀ (x : H), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
⊢ LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
[PROOFSTEP]
refine'
(convex_ball _ _).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x x_in => (ha_deriv x x_in).hasFDerivWithinAt)
fun x x_in => _
[GOAL]
case intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : H → α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → HasFDerivAt (fun x => F x a) (F' x a) x
this : NormedSpace ℝ H := NormedSpace.restrictScalars ℝ 𝕜 H
x₀_in : x₀ ∈ ball x₀ ε
diff_x₀ : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' x₀ a) x₀
a : α
ha_deriv : ∀ (x : H), x ∈ ball x₀ ε → HasFDerivAt (fun x => F x a) (F' x a) x
ha_bound : ∀ (x : H), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
x : H
x_in : x ∈ ball x₀ ε
⊢ ‖F' x a‖₊ ≤ ↑Real.nnabs (bound a)
[PROOFSTEP]
rw [← NNReal.coe_le_coe, coe_nnnorm, Real.coe_nnabs]
[GOAL]
case intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : H → α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → HasFDerivAt (fun x => F x a) (F' x a) x
this : NormedSpace ℝ H := NormedSpace.restrictScalars ℝ 𝕜 H
x₀_in : x₀ ∈ ball x₀ ε
diff_x₀ : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' x₀ a) x₀
a : α
ha_deriv : ∀ (x : H), x ∈ ball x₀ ε → HasFDerivAt (fun x => F x a) (F' x a) x
ha_bound : ∀ (x : H), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
x : H
x_in : x ∈ ball x₀ ε
⊢ ‖F' x a‖ ≤ |bound a|
[PROOFSTEP]
exact (ha_bound x x_in).trans (le_abs_self _)
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : H → α → E
F' : H → α → H →L[𝕜] E
x₀ : H
bound : α → ℝ
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : H) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : H), x ∈ ball x₀ ε → HasFDerivAt (fun x => F x a) (F' x a) x
this✝ : NormedSpace ℝ H := NormedSpace.restrictScalars ℝ 𝕜 H
x₀_in : x₀ ∈ ball x₀ ε
diff_x₀ : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (F' x₀ a) x₀
this : ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
⊢ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' x₀ a ∂μ) x₀
[PROOFSTEP]
exact (hasFDerivAt_integral_of_dominated_loc_of_lip ε_pos hF_meas hF_int hF'_meas this bound_integrable diff_x₀).2
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : 𝕜 → α → E
F' : α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound : α → ℝ
h_lipsch : ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasDerivAt (fun x => F x a) (F' a) x₀
⊢ Integrable F' ∧ HasDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
set L : E →L[𝕜] 𝕜 →L[𝕜] E := ContinuousLinearMap.smulRightL 𝕜 𝕜 E 1
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : 𝕜 → α → E
F' : α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound : α → ℝ
h_lipsch : ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, HasDerivAt (fun x => F x a) (F' a) x₀
L : E →L[𝕜] 𝕜 →L[𝕜] E := ↑(ContinuousLinearMap.smulRightL 𝕜 𝕜 E) 1
⊢ Integrable F' ∧ HasDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
replace h_diff : ∀ᵐ a ∂μ, HasFDerivAt (fun x => F x a) (L (F' a)) x₀ := h_diff.mono fun x hx => hx.hasFDerivAt
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : 𝕜 → α → E
F' : α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound : α → ℝ
h_lipsch : ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
bound_integrable : Integrable bound
L : E →L[𝕜] 𝕜 →L[𝕜] E := ↑(ContinuousLinearMap.smulRightL 𝕜 𝕜 E) 1
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (↑L (F' a)) x₀
⊢ Integrable F' ∧ HasDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
have hm : AEStronglyMeasurable (L ∘ F') μ := L.continuous.comp_aestronglyMeasurable hF'_meas
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : 𝕜 → α → E
F' : α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound : α → ℝ
h_lipsch : ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
bound_integrable : Integrable bound
L : E →L[𝕜] 𝕜 →L[𝕜] E := ↑(ContinuousLinearMap.smulRightL 𝕜 𝕜 E) 1
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (↑L (F' a)) x₀
hm : AEStronglyMeasurable (↑L ∘ F') μ
⊢ Integrable F' ∧ HasDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
cases' hasFDerivAt_integral_of_dominated_loc_of_lip ε_pos hF_meas hF_int hm h_lipsch bound_integrable h_diff with
hF'_int key
[GOAL]
case intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : 𝕜 → α → E
F' : α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound : α → ℝ
h_lipsch : ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
bound_integrable : Integrable bound
L : E →L[𝕜] 𝕜 →L[𝕜] E := ↑(ContinuousLinearMap.smulRightL 𝕜 𝕜 E) 1
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (↑L (F' a)) x₀
hm : AEStronglyMeasurable (↑L ∘ F') μ
hF'_int : Integrable (↑L ∘ F')
key : HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), (↑L ∘ F') a ∂μ) x₀
⊢ Integrable F' ∧ HasDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
replace hF'_int : Integrable F' μ
[GOAL]
case hF'_int
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : 𝕜 → α → E
F' : α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound : α → ℝ
h_lipsch : ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
bound_integrable : Integrable bound
L : E →L[𝕜] 𝕜 →L[𝕜] E := ↑(ContinuousLinearMap.smulRightL 𝕜 𝕜 E) 1
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (↑L (F' a)) x₀
hm : AEStronglyMeasurable (↑L ∘ F') μ
hF'_int : Integrable (↑L ∘ F')
key : HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), (↑L ∘ F') a ∂μ) x₀
⊢ Integrable F'
[PROOFSTEP]
rw [← integrable_norm_iff hm] at hF'_int
[GOAL]
case hF'_int
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : 𝕜 → α → E
F' : α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound : α → ℝ
h_lipsch : ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
bound_integrable : Integrable bound
L : E →L[𝕜] 𝕜 →L[𝕜] E := ↑(ContinuousLinearMap.smulRightL 𝕜 𝕜 E) 1
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (↑L (F' a)) x₀
hm : AEStronglyMeasurable (↑L ∘ F') μ
hF'_int : Integrable fun a => ‖(↑L ∘ F') a‖
key : HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), (↑L ∘ F') a ∂μ) x₀
⊢ Integrable F'
[PROOFSTEP]
simpa only [(· ∘ ·), integrable_norm_iff, hF'_meas, one_mul, norm_one, ContinuousLinearMap.comp_apply,
ContinuousLinearMap.coe_restrict_scalarsL', ContinuousLinearMap.norm_restrictScalars,
ContinuousLinearMap.norm_smulRightL_apply] using hF'_int
[GOAL]
case intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : 𝕜 → α → E
F' : α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound : α → ℝ
h_lipsch : ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
bound_integrable : Integrable bound
L : E →L[𝕜] 𝕜 →L[𝕜] E := ↑(ContinuousLinearMap.smulRightL 𝕜 𝕜 E) 1
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (↑L (F' a)) x₀
hm : AEStronglyMeasurable (↑L ∘ F') μ
key : HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), (↑L ∘ F') a ∂μ) x₀
hF'_int : Integrable F'
⊢ Integrable F' ∧ HasDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
refine' ⟨hF'_int, _⟩
[GOAL]
case intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : 𝕜 → α → E
F' : α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound : α → ℝ
h_lipsch : ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
bound_integrable : Integrable bound
L : E →L[𝕜] 𝕜 →L[𝕜] E := ↑(ContinuousLinearMap.smulRightL 𝕜 𝕜 E) 1
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (↑L (F' a)) x₀
hm : AEStronglyMeasurable (↑L ∘ F') μ
key : HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), (↑L ∘ F') a ∂μ) x₀
hF'_int : Integrable F'
⊢ HasDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), F' a ∂μ) x₀
[PROOFSTEP]
simp_rw [hasDerivAt_iff_hasFDerivAt] at h_diff ⊢
[GOAL]
case intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F : 𝕜 → α → E
F' : α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable F' μ
bound : α → ℝ
h_lipsch : ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
bound_integrable : Integrable bound
L : E →L[𝕜] 𝕜 →L[𝕜] E := ↑(ContinuousLinearMap.smulRightL 𝕜 𝕜 E) 1
h_diff : ∀ᵐ (a : α) ∂μ, HasFDerivAt (fun x => F x a) (↑(↑(ContinuousLinearMap.smulRightL 𝕜 𝕜 E) 1) (F' a)) x₀
hm : AEStronglyMeasurable (↑L ∘ F') μ
key : HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (∫ (a : α), (↑L ∘ F') a ∂μ) x₀
hF'_int : Integrable F'
⊢ HasFDerivAt (fun x => ∫ (a : α), F x a ∂μ) (ContinuousLinearMap.smulRight 1 (∫ (a : α), F' a ∂μ)) x₀
[PROOFSTEP]
simpa only [(· ∘ ·), ContinuousLinearMap.integral_comp_comm _ hF'_int] using key
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F F' : 𝕜 → α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
bound : α → ℝ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : 𝕜), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : 𝕜), x ∈ ball x₀ ε → HasDerivAt (fun x => F x a) (F' x a) x
⊢ Integrable (F' x₀) ∧ HasDerivAt (fun n => ∫ (a : α), F n a ∂μ) (∫ (a : α), F' x₀ a ∂μ) x₀
[PROOFSTEP]
have x₀_in : x₀ ∈ ball x₀ ε := mem_ball_self ε_pos
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F F' : 𝕜 → α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
bound : α → ℝ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : 𝕜), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : 𝕜), x ∈ ball x₀ ε → HasDerivAt (fun x => F x a) (F' x a) x
x₀_in : x₀ ∈ ball x₀ ε
⊢ Integrable (F' x₀) ∧ HasDerivAt (fun n => ∫ (a : α), F n a ∂μ) (∫ (a : α), F' x₀ a ∂μ) x₀
[PROOFSTEP]
have diff_x₀ : ∀ᵐ a ∂μ, HasDerivAt (fun x => F x a) (F' x₀ a) x₀ := h_diff.mono fun a ha => ha x₀ x₀_in
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F F' : 𝕜 → α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
bound : α → ℝ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : 𝕜), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : 𝕜), x ∈ ball x₀ ε → HasDerivAt (fun x => F x a) (F' x a) x
x₀_in : x₀ ∈ ball x₀ ε
diff_x₀ : ∀ᵐ (a : α) ∂μ, HasDerivAt (fun x => F x a) (F' x₀ a) x₀
⊢ Integrable (F' x₀) ∧ HasDerivAt (fun n => ∫ (a : α), F n a ∂μ) (∫ (a : α), F' x₀ a ∂μ) x₀
[PROOFSTEP]
have : ∀ᵐ a ∂μ, LipschitzOnWith (Real.nnabs (bound a)) (fun x : 𝕜 => F x a) (ball x₀ ε) :=
by
apply (h_diff.and h_bound).mono
rintro a ⟨ha_deriv, ha_bound⟩
refine'
(convex_ball _ _).lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x x_in => (ha_deriv x x_in).hasDerivWithinAt)
fun x x_in => _
rw [← NNReal.coe_le_coe, coe_nnnorm, Real.coe_nnabs]
exact (ha_bound x x_in).trans (le_abs_self _)
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F F' : 𝕜 → α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
bound : α → ℝ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : 𝕜), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : 𝕜), x ∈ ball x₀ ε → HasDerivAt (fun x => F x a) (F' x a) x
x₀_in : x₀ ∈ ball x₀ ε
diff_x₀ : ∀ᵐ (a : α) ∂μ, HasDerivAt (fun x => F x a) (F' x₀ a) x₀
⊢ ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
[PROOFSTEP]
apply (h_diff.and h_bound).mono
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F F' : 𝕜 → α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
bound : α → ℝ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : 𝕜), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : 𝕜), x ∈ ball x₀ ε → HasDerivAt (fun x => F x a) (F' x a) x
x₀_in : x₀ ∈ ball x₀ ε
diff_x₀ : ∀ᵐ (a : α) ∂μ, HasDerivAt (fun x => F x a) (F' x₀ a) x₀
⊢ ∀ (x : α),
((∀ (x_1 : 𝕜), x_1 ∈ ball x₀ ε → HasDerivAt (fun x_2 => F x_2 x) (F' x_1 x) x_1) ∧
∀ (x_1 : 𝕜), x_1 ∈ ball x₀ ε → ‖F' x_1 x‖ ≤ bound x) →
LipschitzOnWith (↑Real.nnabs (bound x)) (fun x_1 => F x_1 x) (ball x₀ ε)
[PROOFSTEP]
rintro a ⟨ha_deriv, ha_bound⟩
[GOAL]
case intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F F' : 𝕜 → α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
bound : α → ℝ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : 𝕜), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : 𝕜), x ∈ ball x₀ ε → HasDerivAt (fun x => F x a) (F' x a) x
x₀_in : x₀ ∈ ball x₀ ε
diff_x₀ : ∀ᵐ (a : α) ∂μ, HasDerivAt (fun x => F x a) (F' x₀ a) x₀
a : α
ha_deriv : ∀ (x : 𝕜), x ∈ ball x₀ ε → HasDerivAt (fun x => F x a) (F' x a) x
ha_bound : ∀ (x : 𝕜), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
⊢ LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
[PROOFSTEP]
refine'
(convex_ball _ _).lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x x_in => (ha_deriv x x_in).hasDerivWithinAt)
fun x x_in => _
[GOAL]
case intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F F' : 𝕜 → α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
bound : α → ℝ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : 𝕜), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : 𝕜), x ∈ ball x₀ ε → HasDerivAt (fun x => F x a) (F' x a) x
x₀_in : x₀ ∈ ball x₀ ε
diff_x₀ : ∀ᵐ (a : α) ∂μ, HasDerivAt (fun x => F x a) (F' x₀ a) x₀
a : α
ha_deriv : ∀ (x : 𝕜), x ∈ ball x₀ ε → HasDerivAt (fun x => F x a) (F' x a) x
ha_bound : ∀ (x : 𝕜), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
x : 𝕜
x_in : x ∈ ball x₀ ε
⊢ ‖F' x a‖₊ ≤ ↑Real.nnabs (bound a)
[PROOFSTEP]
rw [← NNReal.coe_le_coe, coe_nnnorm, Real.coe_nnabs]
[GOAL]
case intro
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F F' : 𝕜 → α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
bound : α → ℝ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : 𝕜), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : 𝕜), x ∈ ball x₀ ε → HasDerivAt (fun x => F x a) (F' x a) x
x₀_in : x₀ ∈ ball x₀ ε
diff_x₀ : ∀ᵐ (a : α) ∂μ, HasDerivAt (fun x => F x a) (F' x₀ a) x₀
a : α
ha_deriv : ∀ (x : 𝕜), x ∈ ball x₀ ε → HasDerivAt (fun x => F x a) (F' x a) x
ha_bound : ∀ (x : 𝕜), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
x : 𝕜
x_in : x ∈ ball x₀ ε
⊢ ‖F' x a‖ ≤ |bound a|
[PROOFSTEP]
exact (ha_bound x x_in).trans (le_abs_self _)
[GOAL]
α : Type u_1
inst✝⁷ : MeasurableSpace α
μ : Measure α
𝕜 : Type u_2
inst✝⁶ : IsROrC 𝕜
E : Type u_3
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace ℝ E
inst✝³ : NormedSpace 𝕜 E
inst✝² : CompleteSpace E
H : Type u_4
inst✝¹ : NormedAddCommGroup H
inst✝ : NormedSpace 𝕜 H
F F' : 𝕜 → α → E
x₀ : 𝕜
ε : ℝ
ε_pos : 0 < ε
hF_meas : ∀ᶠ (x : 𝕜) in 𝓝 x₀, AEStronglyMeasurable (F x) μ
hF_int : Integrable (F x₀)
hF'_meas : AEStronglyMeasurable (F' x₀) μ
bound : α → ℝ
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (x : 𝕜), x ∈ ball x₀ ε → ‖F' x a‖ ≤ bound a
bound_integrable : Integrable bound
h_diff : ∀ᵐ (a : α) ∂μ, ∀ (x : 𝕜), x ∈ ball x₀ ε → HasDerivAt (fun x => F x a) (F' x a) x
x₀_in : x₀ ∈ ball x₀ ε
diff_x₀ : ∀ᵐ (a : α) ∂μ, HasDerivAt (fun x => F x a) (F' x₀ a) x₀
this : ∀ᵐ (a : α) ∂μ, LipschitzOnWith (↑Real.nnabs (bound a)) (fun x => F x a) (ball x₀ ε)
⊢ Integrable (F' x₀) ∧ HasDerivAt (fun n => ∫ (a : α), F n a ∂μ) (∫ (a : α), F' x₀ a ∂μ) x₀
[PROOFSTEP]
exact hasDerivAt_integral_of_dominated_loc_of_lip ε_pos hF_meas hF_int hF'_meas this bound_integrable diff_x₀
|
From Test Require Import tactic.
Section FOFProblem.
Variable Universe : Set.
Variable UniverseElement : Universe.
Variable wd_ : Universe -> Universe -> Prop.
Variable col_ : Universe -> Universe -> Universe -> Prop.
Variable col_swap1_1 : (forall A B C : Universe, (col_ A B C -> col_ B A C)).
Variable col_swap2_2 : (forall A B C : Universe, (col_ A B C -> col_ B C A)).
Variable col_triv_3 : (forall A B : Universe, col_ A B B).
Variable wd_swap_4 : (forall A B : Universe, (wd_ A B -> wd_ B A)).
Variable col_trans_5 : (forall P Q A B C : Universe, ((wd_ P Q /\ (col_ P Q A /\ (col_ P Q B /\ col_ P Q C))) -> col_ A B C)).
Theorem pipo_6 : (forall A B C P Q X : Universe, ((wd_ A B /\ (wd_ B C /\ (wd_ A C /\ (wd_ X A /\ (wd_ X C /\ (wd_ P B /\ (wd_ P C /\ (wd_ Q P /\ (wd_ A P /\ (wd_ B X /\ (wd_ X P /\ (col_ A C Q /\ (col_ X A C /\ (col_ P B C /\ col_ A C P)))))))))))))) -> col_ A B C)).
Proof.
time tac.
Qed.
End FOFProblem.
|
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
f : β → Measure α
h : ∀ (s : Set α), MeasurableSet s → Measurable fun b => ↑↑(f b) s
s : Set α
hs : MeasurableSet s
⊢ borel ℝ≥0∞ ≤ MeasurableSpace.map (fun μ => ↑↑μ s) (MeasurableSpace.map f inst✝)
[PROOFSTEP]
rw [MeasurableSpace.map_comp]
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
f : β → Measure α
h : ∀ (s : Set α), MeasurableSet s → Measurable fun b => ↑↑(f b) s
s : Set α
hs : MeasurableSet s
⊢ borel ℝ≥0∞ ≤ MeasurableSpace.map ((fun μ => ↑↑μ s) ∘ f) inst✝
[PROOFSTEP]
exact h s hs
[GOAL]
α✝ : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α✝
inst✝ : MeasurableSpace β
α : Type u_3
m : MeasurableSpace α
⊢ MeasurableAdd₂ (Measure α)
[PROOFSTEP]
refine' ⟨Measure.measurable_of_measurable_coe _ fun s hs => _⟩
[GOAL]
α✝ : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α✝
inst✝ : MeasurableSpace β
α : Type u_3
m : MeasurableSpace α
s : Set α
hs : MeasurableSet s
⊢ Measurable fun b => ↑↑(b.fst + b.snd) s
[PROOFSTEP]
simp_rw [Measure.coe_add, Pi.add_apply]
[GOAL]
α✝ : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α✝
inst✝ : MeasurableSpace β
α : Type u_3
m : MeasurableSpace α
s : Set α
hs : MeasurableSet s
⊢ Measurable fun b => ↑↑b.fst s + ↑↑b.snd s
[PROOFSTEP]
refine' Measurable.add _ _
[GOAL]
case refine'_1
α✝ : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α✝
inst✝ : MeasurableSpace β
α : Type u_3
m : MeasurableSpace α
s : Set α
hs : MeasurableSet s
⊢ Measurable fun b => ↑↑b.fst s
[PROOFSTEP]
exact (Measure.measurable_coe hs).comp measurable_fst
[GOAL]
case refine'_2
α✝ : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α✝
inst✝ : MeasurableSpace β
α : Type u_3
m : MeasurableSpace α
s : Set α
hs : MeasurableSet s
⊢ Measurable fun b => ↑↑b.snd s
[PROOFSTEP]
exact (Measure.measurable_coe hs).comp measurable_snd
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
f : α → β
hf : Measurable f
⊢ Measurable fun μ => map f μ
[PROOFSTEP]
refine' measurable_of_measurable_coe _ fun s hs => _
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
f : α → β
hf : Measurable f
s : Set β
hs : MeasurableSet s
⊢ Measurable fun b => ↑↑(map f b) s
[PROOFSTEP]
simp_rw [map_apply hf hs]
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
f : α → β
hf : Measurable f
s : Set β
hs : MeasurableSet s
⊢ Measurable fun b => ↑↑b (f ⁻¹' s)
[PROOFSTEP]
exact measurable_coe (hf hs)
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
⊢ Measurable dirac
[PROOFSTEP]
refine' measurable_of_measurable_coe _ fun s hs => _
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
s : Set α
hs : MeasurableSet s
⊢ Measurable fun b => ↑↑(dirac b) s
[PROOFSTEP]
simp_rw [dirac_apply' _ hs]
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
s : Set α
hs : MeasurableSet s
⊢ Measurable fun b => indicator s 1 b
[PROOFSTEP]
exact measurable_one.indicator hs
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
f : α → ℝ≥0∞
hf : Measurable f
⊢ Measurable fun μ => ∫⁻ (x : α), f x ∂μ
[PROOFSTEP]
simp only [lintegral_eq_iSup_eapprox_lintegral, hf, SimpleFunc.lintegral]
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
f : α → ℝ≥0∞
hf : Measurable f
⊢ Measurable fun μ =>
⨆ (n : ℕ),
∑ x in SimpleFunc.range (SimpleFunc.eapprox (fun x => f x) n),
x * ↑↑μ (↑(SimpleFunc.eapprox (fun x => f x) n) ⁻¹' {x})
[PROOFSTEP]
refine' measurable_iSup fun n => Finset.measurable_sum _ fun i _ => _
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
f : α → ℝ≥0∞
hf : Measurable f
n : ℕ
i : ℝ≥0∞
x✝ : i ∈ SimpleFunc.range (SimpleFunc.eapprox (fun x => f x) n)
⊢ Measurable fun μ => i * ↑↑μ (↑(SimpleFunc.eapprox (fun x => f x) n) ⁻¹' {i})
[PROOFSTEP]
refine' Measurable.const_mul _ _
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
f : α → ℝ≥0∞
hf : Measurable f
n : ℕ
i : ℝ≥0∞
x✝ : i ∈ SimpleFunc.range (SimpleFunc.eapprox (fun x => f x) n)
⊢ Measurable fun μ => ↑↑μ (↑(SimpleFunc.eapprox (fun x => f x) n) ⁻¹' {i})
[PROOFSTEP]
exact measurable_coe ((SimpleFunc.eapprox f n).measurableSet_preimage _)
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
⊢ (fun s x => ∫⁻ (μ : Measure α), ↑↑μ s ∂m) ∅ (_ : MeasurableSet ∅) = 0
[PROOFSTEP]
simp only [measure_empty, lintegral_const, zero_mul]
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
⊢ ∀ ⦃f : ℕ → Set α⦄ (h : ∀ (i : ℕ), MeasurableSet (f i)),
Pairwise (Disjoint on f) →
(fun s x => ∫⁻ (μ : Measure α), ↑↑μ s ∂m) (⋃ (i : ℕ), f i) (_ : MeasurableSet (⋃ (b : ℕ), f b)) =
∑' (i : ℕ), (fun s x => ∫⁻ (μ : Measure α), ↑↑μ s ∂m) (f i) (_ : MeasurableSet (f i))
[PROOFSTEP]
intro f hf h
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f : ℕ → Set α
hf : ∀ (i : ℕ), MeasurableSet (f i)
h : Pairwise (Disjoint on f)
⊢ (fun s x => ∫⁻ (μ : Measure α), ↑↑μ s ∂m) (⋃ (i : ℕ), f i) (_ : MeasurableSet (⋃ (b : ℕ), f b)) =
∑' (i : ℕ), (fun s x => ∫⁻ (μ : Measure α), ↑↑μ s ∂m) (f i) (_ : MeasurableSet (f i))
[PROOFSTEP]
simp_rw [measure_iUnion h hf]
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f : ℕ → Set α
hf : ∀ (i : ℕ), MeasurableSet (f i)
h : Pairwise (Disjoint on f)
⊢ ∫⁻ (μ : Measure α), ∑' (i : ℕ), ↑↑μ (f i) ∂m = ∑' (i : ℕ), ∫⁻ (μ : Measure α), ↑↑μ (f i) ∂m
[PROOFSTEP]
apply lintegral_tsum
[GOAL]
case hf
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f : ℕ → Set α
hf : ∀ (i : ℕ), MeasurableSet (f i)
h : Pairwise (Disjoint on f)
⊢ ∀ (i : ℕ), AEMeasurable fun a => ↑↑a (f i)
[PROOFSTEP]
intro i
[GOAL]
case hf
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f : ℕ → Set α
hf : ∀ (i : ℕ), MeasurableSet (f i)
h : Pairwise (Disjoint on f)
i : ℕ
⊢ AEMeasurable fun a => ↑↑a (f i)
[PROOFSTEP]
exact (measurable_coe (hf i)).aemeasurable
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
⊢ join 0 = 0
[PROOFSTEP]
ext1 s hs
[GOAL]
case h
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
s : Set α
hs : MeasurableSet s
⊢ ↑↑(join 0) s = ↑↑0 s
[PROOFSTEP]
simp only [hs, join_apply, lintegral_zero_measure, coe_zero, Pi.zero_apply]
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
s : Set α
hs : MeasurableSet s
⊢ Measurable fun b => ↑↑(join b) s
[PROOFSTEP]
simp only [join_apply hs]
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
s : Set α
hs : MeasurableSet s
⊢ Measurable fun b => ∫⁻ (μ : Measure α), ↑↑μ s ∂b
[PROOFSTEP]
exact measurable_lintegral (measurable_coe hs)
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f : α → ℝ≥0∞
hf : Measurable f
⊢ ∫⁻ (x : α), f x ∂join m = ∫⁻ (μ : Measure α), ∫⁻ (x : α), f x ∂μ ∂m
[PROOFSTEP]
simp_rw [lintegral_eq_iSup_eapprox_lintegral hf, SimpleFunc.lintegral,
join_apply (SimpleFunc.measurableSet_preimage _ _)]
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f : α → ℝ≥0∞
hf : Measurable f
⊢ ⨆ (n : ℕ),
∑ x in SimpleFunc.range (SimpleFunc.eapprox f n),
x * ∫⁻ (μ : Measure α), ↑↑μ (↑(SimpleFunc.eapprox f n) ⁻¹' {x}) ∂m =
∫⁻ (μ : Measure α),
⨆ (n : ℕ), ∑ x in SimpleFunc.range (SimpleFunc.eapprox f n), x * ↑↑μ (↑(SimpleFunc.eapprox f n) ⁻¹' {x}) ∂m
[PROOFSTEP]
suffices
∀ (s : ℕ → Finset ℝ≥0∞) (f : ℕ → ℝ≥0∞ → Measure α → ℝ≥0∞),
(∀ n r, Measurable (f n r)) →
Monotone (fun n μ => ∑ r in s n, r * f n r μ) →
⨆ n, ∑ r in s n, r * ∫⁻ μ, f n r μ ∂m = ∫⁻ μ, ⨆ n, ∑ r in s n, r * f n r μ ∂m
by
refine'
this (fun n => SimpleFunc.range (SimpleFunc.eapprox f n)) (fun n r μ => μ (SimpleFunc.eapprox f n ⁻¹' { r })) _ _
· exact fun n r => measurable_coe (SimpleFunc.measurableSet_preimage _ _)
· exact fun n m h μ => SimpleFunc.lintegral_mono (SimpleFunc.monotone_eapprox _ h) le_rfl
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f : α → ℝ≥0∞
hf : Measurable f
this :
∀ (s : ℕ → Finset ℝ≥0∞) (f : ℕ → ℝ≥0∞ → Measure α → ℝ≥0∞),
(∀ (n : ℕ) (r : ℝ≥0∞), Measurable (f n r)) →
(Monotone fun n μ => ∑ r in s n, r * f n r μ) →
⨆ (n : ℕ), ∑ r in s n, r * ∫⁻ (μ : Measure α), f n r μ ∂m =
∫⁻ (μ : Measure α), ⨆ (n : ℕ), ∑ r in s n, r * f n r μ ∂m
⊢ ⨆ (n : ℕ),
∑ x in SimpleFunc.range (SimpleFunc.eapprox f n),
x * ∫⁻ (μ : Measure α), ↑↑μ (↑(SimpleFunc.eapprox f n) ⁻¹' {x}) ∂m =
∫⁻ (μ : Measure α),
⨆ (n : ℕ), ∑ x in SimpleFunc.range (SimpleFunc.eapprox f n), x * ↑↑μ (↑(SimpleFunc.eapprox f n) ⁻¹' {x}) ∂m
[PROOFSTEP]
refine'
this (fun n => SimpleFunc.range (SimpleFunc.eapprox f n)) (fun n r μ => μ (SimpleFunc.eapprox f n ⁻¹' { r })) _ _
[GOAL]
case refine'_1
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f : α → ℝ≥0∞
hf : Measurable f
this :
∀ (s : ℕ → Finset ℝ≥0∞) (f : ℕ → ℝ≥0∞ → Measure α → ℝ≥0∞),
(∀ (n : ℕ) (r : ℝ≥0∞), Measurable (f n r)) →
(Monotone fun n μ => ∑ r in s n, r * f n r μ) →
⨆ (n : ℕ), ∑ r in s n, r * ∫⁻ (μ : Measure α), f n r μ ∂m =
∫⁻ (μ : Measure α), ⨆ (n : ℕ), ∑ r in s n, r * f n r μ ∂m
⊢ ∀ (n : ℕ) (r : ℝ≥0∞), Measurable ((fun n r μ => ↑↑μ (↑(SimpleFunc.eapprox f n) ⁻¹' {r})) n r)
[PROOFSTEP]
exact fun n r => measurable_coe (SimpleFunc.measurableSet_preimage _ _)
[GOAL]
case refine'_2
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f : α → ℝ≥0∞
hf : Measurable f
this :
∀ (s : ℕ → Finset ℝ≥0∞) (f : ℕ → ℝ≥0∞ → Measure α → ℝ≥0∞),
(∀ (n : ℕ) (r : ℝ≥0∞), Measurable (f n r)) →
(Monotone fun n μ => ∑ r in s n, r * f n r μ) →
⨆ (n : ℕ), ∑ r in s n, r * ∫⁻ (μ : Measure α), f n r μ ∂m =
∫⁻ (μ : Measure α), ⨆ (n : ℕ), ∑ r in s n, r * f n r μ ∂m
⊢ Monotone fun n μ =>
∑ r in (fun n => SimpleFunc.range (SimpleFunc.eapprox f n)) n,
r * (fun n r μ => ↑↑μ (↑(SimpleFunc.eapprox f n) ⁻¹' {r})) n r μ
[PROOFSTEP]
exact fun n m h μ => SimpleFunc.lintegral_mono (SimpleFunc.monotone_eapprox _ h) le_rfl
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f : α → ℝ≥0∞
hf : Measurable f
⊢ ∀ (s : ℕ → Finset ℝ≥0∞) (f : ℕ → ℝ≥0∞ → Measure α → ℝ≥0∞),
(∀ (n : ℕ) (r : ℝ≥0∞), Measurable (f n r)) →
(Monotone fun n μ => ∑ r in s n, r * f n r μ) →
⨆ (n : ℕ), ∑ r in s n, r * ∫⁻ (μ : Measure α), f n r μ ∂m =
∫⁻ (μ : Measure α), ⨆ (n : ℕ), ∑ r in s n, r * f n r μ ∂m
[PROOFSTEP]
intro s f hf hm
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f✝ : α → ℝ≥0∞
hf✝ : Measurable f✝
s : ℕ → Finset ℝ≥0∞
f : ℕ → ℝ≥0∞ → Measure α → ℝ≥0∞
hf : ∀ (n : ℕ) (r : ℝ≥0∞), Measurable (f n r)
hm : Monotone fun n μ => ∑ r in s n, r * f n r μ
⊢ ⨆ (n : ℕ), ∑ r in s n, r * ∫⁻ (μ : Measure α), f n r μ ∂m = ∫⁻ (μ : Measure α), ⨆ (n : ℕ), ∑ r in s n, r * f n r μ ∂m
[PROOFSTEP]
rw [lintegral_iSup _ hm]
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f✝ : α → ℝ≥0∞
hf✝ : Measurable f✝
s : ℕ → Finset ℝ≥0∞
f : ℕ → ℝ≥0∞ → Measure α → ℝ≥0∞
hf : ∀ (n : ℕ) (r : ℝ≥0∞), Measurable (f n r)
hm : Monotone fun n μ => ∑ r in s n, r * f n r μ
⊢ ⨆ (n : ℕ), ∑ r in s n, r * ∫⁻ (μ : Measure α), f n r μ ∂m = ⨆ (n : ℕ), ∫⁻ (a : Measure α), ∑ r in s n, r * f n r a ∂m
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f✝ : α → ℝ≥0∞
hf✝ : Measurable f✝
s : ℕ → Finset ℝ≥0∞
f : ℕ → ℝ≥0∞ → Measure α → ℝ≥0∞
hf : ∀ (n : ℕ) (r : ℝ≥0∞), Measurable (f n r)
hm : Monotone fun n μ => ∑ r in s n, r * f n r μ
⊢ ∀ (n : ℕ), Measurable fun μ => ∑ r in s n, r * f n r μ
[PROOFSTEP]
swap
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f✝ : α → ℝ≥0∞
hf✝ : Measurable f✝
s : ℕ → Finset ℝ≥0∞
f : ℕ → ℝ≥0∞ → Measure α → ℝ≥0∞
hf : ∀ (n : ℕ) (r : ℝ≥0∞), Measurable (f n r)
hm : Monotone fun n μ => ∑ r in s n, r * f n r μ
⊢ ∀ (n : ℕ), Measurable fun μ => ∑ r in s n, r * f n r μ
[PROOFSTEP]
exact fun n => Finset.measurable_sum _ fun r _ => (hf _ _).const_mul _
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f✝ : α → ℝ≥0∞
hf✝ : Measurable f✝
s : ℕ → Finset ℝ≥0∞
f : ℕ → ℝ≥0∞ → Measure α → ℝ≥0∞
hf : ∀ (n : ℕ) (r : ℝ≥0∞), Measurable (f n r)
hm : Monotone fun n μ => ∑ r in s n, r * f n r μ
⊢ ⨆ (n : ℕ), ∑ r in s n, r * ∫⁻ (μ : Measure α), f n r μ ∂m = ⨆ (n : ℕ), ∫⁻ (a : Measure α), ∑ r in s n, r * f n r a ∂m
[PROOFSTEP]
congr
[GOAL]
case e_s
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f✝ : α → ℝ≥0∞
hf✝ : Measurable f✝
s : ℕ → Finset ℝ≥0∞
f : ℕ → ℝ≥0∞ → Measure α → ℝ≥0∞
hf : ∀ (n : ℕ) (r : ℝ≥0∞), Measurable (f n r)
hm : Monotone fun n μ => ∑ r in s n, r * f n r μ
⊢ (fun n => ∑ r in s n, r * ∫⁻ (μ : Measure α), f n r μ ∂m) = fun n => ∫⁻ (a : Measure α), ∑ r in s n, r * f n r a ∂m
[PROOFSTEP]
funext n
[GOAL]
case e_s.h
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f✝ : α → ℝ≥0∞
hf✝ : Measurable f✝
s : ℕ → Finset ℝ≥0∞
f : ℕ → ℝ≥0∞ → Measure α → ℝ≥0∞
hf : ∀ (n : ℕ) (r : ℝ≥0∞), Measurable (f n r)
hm : Monotone fun n μ => ∑ r in s n, r * f n r μ
n : ℕ
⊢ ∑ r in s n, r * ∫⁻ (μ : Measure α), f n r μ ∂m = ∫⁻ (a : Measure α), ∑ r in s n, r * f n r a ∂m
[PROOFSTEP]
rw [lintegral_finset_sum (s n)]
[GOAL]
case e_s.h
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f✝ : α → ℝ≥0∞
hf✝ : Measurable f✝
s : ℕ → Finset ℝ≥0∞
f : ℕ → ℝ≥0∞ → Measure α → ℝ≥0∞
hf : ∀ (n : ℕ) (r : ℝ≥0∞), Measurable (f n r)
hm : Monotone fun n μ => ∑ r in s n, r * f n r μ
n : ℕ
⊢ ∑ r in s n, r * ∫⁻ (μ : Measure α), f n r μ ∂m = ∑ b in s n, ∫⁻ (a : Measure α), b * f n b a ∂m
[PROOFSTEP]
simp_rw [lintegral_const_mul _ (hf _ _)]
[GOAL]
case e_s.h
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure (Measure α)
f✝ : α → ℝ≥0∞
hf✝ : Measurable f✝
s : ℕ → Finset ℝ≥0∞
f : ℕ → ℝ≥0∞ → Measure α → ℝ≥0∞
hf : ∀ (n : ℕ) (r : ℝ≥0∞), Measurable (f n r)
hm : Monotone fun n μ => ∑ r in s n, r * f n r μ
n : ℕ
⊢ ∀ (b : ℝ≥0∞), b ∈ s n → Measurable fun a => b * f n b a
[PROOFSTEP]
exact fun r _ => (hf _ _).const_mul _
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
f : α → Measure β
⊢ bind 0 f = 0
[PROOFSTEP]
simp [bind]
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure α
⊢ bind m 0 = 0
[PROOFSTEP]
ext1 s hs
[GOAL]
case h
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure α
s : Set β
hs : MeasurableSet s
⊢ ↑↑(bind m 0) s = ↑↑0 s
[PROOFSTEP]
simp only [bind, hs, join_apply, coe_zero, Pi.zero_apply]
[GOAL]
case h
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure α
s : Set β
hs : MeasurableSet s
⊢ ∫⁻ (μ : Measure β), ↑↑μ s ∂map 0 m = 0
[PROOFSTEP]
rw [lintegral_map (measurable_coe hs) measurable_zero]
[GOAL]
case h
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure α
s : Set β
hs : MeasurableSet s
⊢ ∫⁻ (a : α), ↑↑(OfNat.ofNat 0 a) s ∂m = 0
[PROOFSTEP]
simp only [Pi.zero_apply, coe_zero, lintegral_const, zero_mul]
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure α
f : α → Measure β
s : Set β
hs : MeasurableSet s
hf : Measurable f
⊢ ↑↑(bind m f) s = ∫⁻ (a : α), ↑↑(f a) s ∂m
[PROOFSTEP]
rw [bind, join_apply hs, lintegral_map (measurable_coe hs) hf]
[GOAL]
α : Type u_1
β : Type u_2
inst✝² : MeasurableSpace α
inst✝¹ : MeasurableSpace β
γ : Type u_3
inst✝ : MeasurableSpace γ
m : Measure α
f : α → Measure β
g : β → Measure γ
hf : Measurable f
hg : Measurable g
⊢ bind (bind m f) g = bind m fun a => bind (f a) g
[PROOFSTEP]
ext1 s hs
[GOAL]
case h
α : Type u_1
β : Type u_2
inst✝² : MeasurableSpace α
inst✝¹ : MeasurableSpace β
γ : Type u_3
inst✝ : MeasurableSpace γ
m : Measure α
f : α → Measure β
g : β → Measure γ
hf : Measurable f
hg : Measurable g
s : Set γ
hs : MeasurableSet s
⊢ ↑↑(bind (bind m f) g) s = ↑↑(bind m fun a => bind (f a) g) s
[PROOFSTEP]
erw [bind_apply hs hg, bind_apply hs ((measurable_bind' hg).comp hf), lintegral_bind hf ((measurable_coe hs).comp hg)]
[GOAL]
case h
α : Type u_1
β : Type u_2
inst✝² : MeasurableSpace α
inst✝¹ : MeasurableSpace β
γ : Type u_3
inst✝ : MeasurableSpace γ
m : Measure α
f : α → Measure β
g : β → Measure γ
hf : Measurable f
hg : Measurable g
s : Set γ
hs : MeasurableSet s
⊢ ∫⁻ (a : α), ∫⁻ (x : β), ((fun μ => ↑↑μ s) ∘ g) x ∂f a ∂m = ∫⁻ (a : α), ↑↑(((fun m => bind m g) ∘ f) a) s ∂m
[PROOFSTEP]
conv_rhs => enter [2, a]; erw [bind_apply hs hg]
[GOAL]
α : Type u_1
β : Type u_2
inst✝² : MeasurableSpace α
inst✝¹ : MeasurableSpace β
γ : Type u_3
inst✝ : MeasurableSpace γ
m : Measure α
f : α → Measure β
g : β → Measure γ
hf : Measurable f
hg : Measurable g
s : Set γ
hs : MeasurableSet s
| ∫⁻ (a : α), ↑↑(((fun m => bind m g) ∘ f) a) s ∂m
[PROOFSTEP]
enter [2, a]; erw [bind_apply hs hg]
[GOAL]
α : Type u_1
β : Type u_2
inst✝² : MeasurableSpace α
inst✝¹ : MeasurableSpace β
γ : Type u_3
inst✝ : MeasurableSpace γ
m : Measure α
f : α → Measure β
g : β → Measure γ
hf : Measurable f
hg : Measurable g
s : Set γ
hs : MeasurableSet s
| ∫⁻ (a : α), ↑↑(((fun m => bind m g) ∘ f) a) s ∂m
[PROOFSTEP]
enter [2, a]; erw [bind_apply hs hg]
[GOAL]
α : Type u_1
β : Type u_2
inst✝² : MeasurableSpace α
inst✝¹ : MeasurableSpace β
γ : Type u_3
inst✝ : MeasurableSpace γ
m : Measure α
f : α → Measure β
g : β → Measure γ
hf : Measurable f
hg : Measurable g
s : Set γ
hs : MeasurableSet s
| ∫⁻ (a : α), ↑↑(((fun m => bind m g) ∘ f) a) s ∂m
[PROOFSTEP]
enter [2, a]
[GOAL]
case h
α : Type u_1
β : Type u_2
inst✝² : MeasurableSpace α
inst✝¹ : MeasurableSpace β
γ : Type u_3
inst✝ : MeasurableSpace γ
m : Measure α
f : α → Measure β
g : β → Measure γ
hf : Measurable f
hg : Measurable g
s : Set γ
hs : MeasurableSet s
a : α
| ↑↑(((fun m => bind m g) ∘ f) a) s
[PROOFSTEP]
erw [bind_apply hs hg]
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
f : α → Measure β
hf : Measurable f
a : α
⊢ bind (dirac a) f = f a
[PROOFSTEP]
ext1 s hs
[GOAL]
case h
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
f : α → Measure β
hf : Measurable f
a : α
s : Set β
hs : MeasurableSet s
⊢ ↑↑(bind (dirac a) f) s = ↑↑(f a) s
[PROOFSTEP]
erw [bind_apply hs hf, lintegral_dirac' a ((measurable_coe hs).comp hf)]
[GOAL]
case h
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
f : α → Measure β
hf : Measurable f
a : α
s : Set β
hs : MeasurableSet s
⊢ ((fun μ => ↑↑μ s) ∘ f) a = ↑↑(f a) s
[PROOFSTEP]
rfl
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure α
⊢ bind m dirac = m
[PROOFSTEP]
ext1 s hs
[GOAL]
case h
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
m : Measure α
s : Set α
hs : MeasurableSet s
⊢ ↑↑(bind m dirac) s = ↑↑m s
[PROOFSTEP]
simp only [bind_apply hs measurable_dirac, dirac_apply' _ hs, lintegral_indicator 1 hs, Pi.one_apply, lintegral_one,
restrict_apply, MeasurableSet.univ, univ_inter]
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
μ : Measure (Measure α)
⊢ join μ = bind μ id
[PROOFSTEP]
rw [bind, map_id]
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
f : α → β
hf : Measurable f
μ : Measure (Measure α)
⊢ join (map (map f) μ) = map f (join μ)
[PROOFSTEP]
ext1 s hs
[GOAL]
case h
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
f : α → β
hf : Measurable f
μ : Measure (Measure α)
s : Set β
hs : MeasurableSet s
⊢ ↑↑(join (map (map f) μ)) s = ↑↑(map f (join μ)) s
[PROOFSTEP]
rw [join_apply hs, map_apply hf hs, join_apply (hf hs), lintegral_map (measurable_coe hs) (measurable_map f hf)]
[GOAL]
case h
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
f : α → β
hf : Measurable f
μ : Measure (Measure α)
s : Set β
hs : MeasurableSet s
⊢ ∫⁻ (a : Measure α), ↑↑(map f a) s ∂μ = ∫⁻ (μ : Measure α), ↑↑μ (f ⁻¹' s) ∂μ
[PROOFSTEP]
simp_rw [map_apply hf hs]
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
μ : Measure (Measure (Measure α))
⊢ join (map join μ) = join (join μ)
[PROOFSTEP]
show bind μ join = join (join μ)
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
μ : Measure (Measure (Measure α))
⊢ bind μ join = join (join μ)
[PROOFSTEP]
rw [join_eq_bind, join_eq_bind, bind_bind measurable_id measurable_id]
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
μ : Measure (Measure (Measure α))
⊢ bind μ join = bind μ fun a => bind (id a) id
[PROOFSTEP]
apply congr_arg (bind μ)
[GOAL]
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
μ : Measure (Measure (Measure α))
⊢ join = fun a => bind (id a) id
[PROOFSTEP]
funext ν
[GOAL]
case h
α : Type u_1
β : Type u_2
inst✝¹ : MeasurableSpace α
inst✝ : MeasurableSpace β
μ : Measure (Measure (Measure α))
ν : Measure (Measure α)
⊢ join ν = bind (id ν) id
[PROOFSTEP]
exact join_eq_bind ν
|
\chapter{Algebraic Integers}
\setcounter{page}{1}
\pagenumbering{arabic}
\section{Integral closure and algebraic integers}
Here we present fundamental properties of algebraic integers and related theories. It is not our intention to do a treatise of commutative algebra and Galois theory, so for example there would not be the fundamental theorem of Galois theory, or the definition of Dedekind domain. However, if some theorems are explicitly useful in the future, you will still see the theorem and the proof.
\subsection{Definition and examples}
Problems in solving polynomial equations give rise to a lot of concepts in algebra and geometry. If we are specifically interested in $\mds{Z}$, we have the concept of \textbf{algebraic integers}.
\begin{definition}
A finite extension $K$ of the rational number $\mds{Q}$ is called a \textbf{number field}. The integral closure of $\mds{Z}$ in $K$ is called the ring of \textbf{algebraic integers} of $K$, and is denoted by $\OK$. To be precise, every element $x \in \OK$ is a zero of a monic polynomial $f \in \Z[X].$
\end{definition}
For this concept we have a lot of classic examples:
\begin{example}
If $K=\Q$, then $\OK$ is simply $\Z$. This is intuitive because suppose $x=a/b \in \Q$ is integral over $\Z$ where $(a,b)=1$, then
\[
x^n+c_1x^{n-1}+\cdots+c_n = 0
\]
where $c_i \in \Z$. Multiplying by $b^n$ yields
\[
a^n+c_1a^{n-1}b+\cdots+c_nb = 0
\]
Hence $b$ divides $a^n$. But we also have $(a^n,b)=1$, hence $b=\pm 1$, which is to say $x \in \Z$.
There is an more general setting. Since $\Z$ is a unique factorial domain (UFD), and UFD is integrally closed \href{https://proofwiki.org/wiki/Unique_Factorization_Domain_is_Integrally_Closed}{[proof]}, we have $\Z=\OK$.
\end{example}
\begin{example}
The Gaussian rational $\Q(i)=K$. Indeed it is natural to consider Gaussian integer $\Z[i]$ first. For any $z=m+ni \in \Z[i]$, we have
\[
z^2-2mz+m^2+n^2=0
\]
Hence $\Z[i] \subset \OK$. The converse is similar to our proof when $K=\Q$.
\end{example}
\begin{example}
Quadratic field $K=\Q(\sqrt{d})$, where $d$ is a square-free integer $>1$. This time the algebraic integer ring is different from what you may have thought: $\OK = \Z[\omega]$ where
\[
\omega = \begin{cases}
\frac{1+\sqrt{d}}{2}, &\quad d = 4k+1, \\
\sqrt{d}, &\quad \text{otherwise}.
\end{cases}
\]
\end{example}
It turns out we are studying polynomials such as
\begin{itemize}
\item $x^2+1=0$.
\item $x^2-d=0$.
\end{itemize}
It also turns out that many properties are not restricted to $\Z$, but to a specific class of rings. Hence we will investigate some properties in the sense of commutative ring theory. The next example deserves more discussion.
\subsubsection{The Cyclotomic Fields}
Let $\omega = e^{2\pi i/m}$. This is the $m$-th root of $1$. If $\lambda$ is a conjugate of $\omega$, i.e. they both are roots of the same irreducible polynomial over $\Q$, then $\lambda$ is also an $m$-th root of $1$ and is not an $n$-th root of $1$ whenever $n<m$. If we find these $\lambda$, we have a better understanding of $\Q(\omega)$, which is called the cyclotomic field. We will do this in a general setting.
\begin{definition}
Let $k$ be a field. By a \textbf{root of unity} in $k$ we shall mean an element $\xi \in k$ such that $\xi^n=1$ for some integer $n \ge 1$. Let $n$ be a integer $\ge 2$ and not divisible by the characteristic. The generator for the cyclic group $\bm{\mu}_n$ of $n$-th root of unity is called \textbf{primitive}.
\end{definition}
\begin{remark}
We shall not ignore the characteristic of $k$. Indeed, if the characteristic is $p$, then the equation
\[
X^{p^m}-1=0
\]
has only one root, namely $1$, and hence there is no $p^m$-th root of unity except $1$.
\end{remark}
\begin{remark}
$\bm{\mu}_n$ has $n$ elements. The derivative of $X^n-1$ is $nX^{n-1} \ne 0$, and the only root of the derivative is $0$, so there is no common root. In the algebraic closure of $k$, the polynomial $X^n-1$ has $n$ distinct roots, which forms $\bm{\mu}_n$.
\end{remark}
The field extension in terms of root of unity can always be characterised for $(\Z/n\Z)^\ast$ as follows:
\begin{theorem}\label{gal-cyclotomic}
Let $k$ be any field, let $n$ be not divisible by the characteristic $p$. Let $\omega$ be a primitive $n$-th root of unity in the algebraic closure $k^\mathrm{a}$, then $\gal(k(\omega)/k)$ is a subgroup of $(\Z/n\Z)^\ast$.
\end{theorem}
\begin{proof}
Let $\sigma$ be an embedding of $k(\omega)$ in $k^\mathrm{a}$ over $k$. Then
\[
(\sigma\omega)^n = \sigma(\omega^n)=1
\]
hence $\sigma\omega$ is also an $n$-th root of unity. It follows that $\sigma\omega=\omega^i$ for some $i=i(\sigma)$ as $\omega$ is primitive. $i(\sigma)$ is uniquely determined mod $n$. It follows that $\sigma$ maps $k(\omega)$ into itself, and hence $k(\omega)$ is normal over $k$. If $\tau$ is another automorphism of $k(\omega)$ over $k$, then
\[
\sigma\tau\omega = \omega^{i(\sigma)i(\tau)}.
\]
Since $\sigma$ and $\tau$ are isomorphisms, it follows that $i(\sigma)$ and $i(\tau)$ are prime to $n$ (otherwise, $\sigma\omega$ would have a period smaller than $n$). This yields a homomorphism of $\gal(k(\omega)/k)$ and is clearly injective because $i(\sigma)$ is uniquely determined by $\sigma$ mod $n$, and the effect of $\sigma$ on $k(\omega)$ is determined by its effect on $\omega$.
\end{proof}
For a specific field $k$, the question arises whether the image of $\gal(K(\omega)/K)$ in $(\Z/n\Z)^\ast$ is all of $(\Z/n\Z)^\ast$. Looking at $k=\mathds{R}$ or $k=\mathds{C}$, this is not always the case. We give an example on when it is the case.
\begin{theorem}
Let $\omega$ be a primitive $n$-th root of unity in $\Q^\mathrm{a}$, then
\[
[\Q(\omega):\Q] = \varphi(n)
\]
where $\varphi$ is the Euler function.
\end{theorem}
\begin{proof}
According to theorem \ref{gal-cyclotomic}, $[\Q(\omega):\Q] \le \varphi(n)$, hence it suffices to prove the opposite.
Let $f(X)$ be the minimal polynomial of $\omega$ over $\Q$. Then $f(X)$ divides $X^n-1$, and we can write $X^n-1=f(X)h(X)$, where both $f$ and $h$ have leading coefficient $1$. By the Gauss lemma, $f$ and $h$ have integral coefficients. We shall now prove that if $p$ is a prime number not dividing $n$, then $\omega^p$ is also a root of $f$.
Suppose $\phi^p$ is not a root of $f$, then it is a root of $h$, and $\phi$ is a root of $h(X^p)$. Hence $f$ divides $h(X^p)$ as well, so we write
\[
h(X^p)=f(X)g(X).
\]
Note $g$ has integral coefficients as well. Since $a^p \equiv a \mod p$ for any integer $a$, we have
\[
h(X^p) \equiv h(X)^p \mod p,
\]
and therefore
\[
h(X)^p \equiv f(X)g(X) \mod p.
\]
Let $\overline{f}$ and $\overline{h}$ be the canonical image of $f$ and $h$ in $\Z/p\Z[X]$, we see that $f$ and $h$ are not relatively prime, hence have common factor(s). But if follows that
\[
X^n-\overline{1}=\overline{f}(X)\overline{g}(X)
\]
has multiple rules, which contradicts the remark we have made at the beginning.
Since $\omega^p$ is also a primitive $n$-th root of unity, and any primitive $n$-th root of unity can be obtained by raising $\omega$ to a succession of prime powers with primes not dividing $n$, this implies that all primitive $n$-th roots of unity are roots of $f$, which forces the degree of $f$ to be not less than $\varphi(n).$
\end{proof}
It follows immediately that
\begin{corollary}
We have an isomorphism
\[
\gal(\Q(\omega):\Q) \cong (\Z/n\Z)^\ast.
\]
\end{corollary}
\begin{corollary}
If $n,m$ are relative prime integers $\ge 1$, then
\[
\Q(\omega_n) \cap \Q(\omega_m) = \Q.
\]
\end{corollary}
We will prove that the cyclotomic integers (i.e. the algebraic integer with respect to $\Q(\omega)/\Q$) is actually $\Z[\omega]$. This is a highly non-trivial result and we can only deliver the proof after further study on prime ideals.
% TODO: Finish this section and the study of Z[\omega]. Source can be found on Daniel A. Marcus.
\subsection{Algebraic extension and integral closure}
First of all we show that being algebraic almost implies being integral.
\begin{lemma}\label{alg-int}
Let $A$ be a domain, $K$ its quotient field, and $x$ algebraic over $K$. Then there exists an element $c \ne 0$ of $A$ such that $cx$ is integral over $A$.
\end{lemma}
\begin{proof}
Since $x$ is algebraic, we have an equation
\[
a_nx^n+\cdots+a_0=0
\]
with $a_i \in A$ and $a_n \ne 0$. Hence
\[
a_n^{n-1}(a_nx^n+\cdots+a_0)=(a_nx)^n+\cdots+a_0a_n^{n-1}=0
\]
which is to say $a_nx$ is integral over $A$.
\end{proof}
Since finite extensions are algebraic, we are always free to use this lemma for the topic of number field.
\begin{theorem}\label{closure-f-g}
Let $A$ be an integrally closed Noetherian ring. Let $L$ be a finite separable extension of its quotient field $K$. Then the integral closure of $A$ in $L$ is finitely generated over $A$.
\end{theorem}
By being integrally closed we mean the ring is integrally closed in its quotient field. Some mathematicians also say it is being normal, but I think \textit{normal} does not carry a lot of information.
\begin{proof}
Since $A$ is Noetherian, all submodules of a finitely generated module over $A$ is finitely generated. Hence it suffices to prove that the integral closure of $A$ is contained in a finitely generated $A$-module.\\
Let $w_1,\dots,w_n$ be a basis of $L$ over $K$. After multiplying each $w_i$ by some suitable element of $A$ (see lemma \ref{alg-int}), we may assume without loss of generality that the $w_i$ are integral over $A$. To study the integral closure of $A$ in $L$, we pick an arbitrary element $z = b_1w_1+\cdots+b_nw_n$ and study its coefficients. \\
Since $L/K$ is separable, the \href{https://stacks.math.columbia.edu/tag/0BIF}{field trace} form
\[
Q_{L/K}:L \times L \to K, \quad (x,y) \mapsto \tr_{L/K}(xy)
\]
is non-degenerate \href{https://stacks.math.columbia.edu/tag/0BIL}{[proof]}, so we claim that $L^\ast$ is isomorphic to $L$ under $Q_{L/K}$. Indeed, one can define a $K$-linear map
\[
d:L \to L^\ast, \quad x \mapsto (y \mapsto Q_{L/K}(x,y)=\tr(xy)).
\]
This map is injective because $Q_{L/K}$ is non-degenerate. Since $L$ and $L^\ast$ has the same dimension, $d$ has to be surjective.\\
Let $w^1,\dots,w^n$ be the dual basis of $w_1,\dots,w_n$. If we put $v_i=d^{-1}(w^i)$, we have
\[
\tr(v_i w_j) = \delta_{ij}.
\]
Let $c \ne 0$ be an element of $A$ such that $cv_i$ is integral over $A$, then $cv_iz$ is integral and so is $\tr(cv_iz)$. Since $\tr$ is a $K$-valued function, we have
\[
\tr(czv_i)=c\tr(v_iz)=c d(v_i)(z) = cb_i \in A \implies b_i \in Ac^{-1}.
\]
Hence
\[
z \in Ac^{-1}w_1+\cdots+Ac^{-1}w_n
\]
which is to say $z$ is finitely generated. Since $z$ is arbitrarily picked, the closure itself is contained in a finitely generated $A$-module, which finishes the proof.
\end{proof}
Note $Z$ is itself a Noetherian ring and integrally closed. $\Q$ is the fraction ring of $\Z$, and finite extensions of $\Q$ are always separable. It follows (non-trivially) that
\begin{corollary}
$\OK$ is finitely generated over $\Z$.
\end{corollary}
Next we study the rank of $\OK$ over $\Z$. Being finitely generated is not exactly what we want.
\begin{theorem}
Let $A$ be a principal ideal ring, and $L$ a finite separable extension of its quotient field $K$, of degree $n$. Let $B$ be the integral closure of $A$ in $L$. Then $B$ is a free module of rank $n$ over $A$.
\end{theorem}
\begin{proof}
Since $A$ is contained in $K$, $B$ is contained in $L$, whenever $ab=0$ with $a \in A$, $b \in B$, we have $a=0$ or $b=0$. Hence $B$ is torsion-free. Therefore as a finitely generated (theorem \ref{closure-f-g}) torsion-free module, $B$ is a free module over $A$ \href{http://du.ac.in/du/uploads/departments/mathematics/study-material/MMATH18-201\%20_MT_PID.pdf}{[Theorem 2.7]}. Since $L$ is a $n$-dimensional vector space over $K$, for $y \in L$ we have
\[
y = c_1e_1+\cdots+c_ne_n
\]
where $e_1,\dots,e_n$ is a basis and $c_1,\cdots,c_n \in K$. When $y \in B$, we must have $c_1,\cdots,c_n \in A$, which is to say $B$ has rank $[L:K]=n$.
\end{proof}
Hence the rank of $\OK$ over $\Z$ is determined by $[K:\Q]$.
\subsection{Localisation}
\begin{theorem}\label{int-clo-loc}
Let $A \subset B$ be rings, and $S$ a multiplicatively closed subset of $A$. If $B$ is integral over $A$, then $S^{-1}B$ is integrally closed in $S^{-1}A$. If $C$ is the integral closure of $A$ in $B$, then $S^{-1}C$ is the integral closure of $S^{-1}A$.
\end{theorem}
\begin{proof}
First we assume $B$ is integral over $A$. Pick $x/s \in S^{-1}B$ with $x \in B$ and $s \in S$. By definition we have
\[
x^n + a_1x^{n-1}+\cdots + a_n = 0
\]
with $a_i \in A$. Multiplying by $(1/s)^n$ gives
\[
(x/s)^n + (a_1/s)(x/s)^{n-1}+\cdots+a_n/s^n = 0
\]
which shows that $x/s$ is integral over $S^{-1}A$. Hence the first statement is proved. \\
Now we assume $C$ is the integral closure of $A$ in $B$. By the first statement we see $S^{-1}C$ is integral over $S^{-1}A$. Suppose $b/s \in S^{-1}B$ is integral over $S^{-1}A$, we have an equation of the form
\[
(b/s)^n+(a_1/s_1)(b/s)^{n-1}+\cdots+a_n/s_n=0.
\]
Multiplying by $(st)^n$ where $t=s_1\cdots s_n$ gives an equation of integral independence for $bt$ over $A$. Hence $bt \in C$. But $b/s = bt/st$, hence $b/s \in S^{-1}C$ and we are done.
\end{proof}
If $S$ happens to be a complement of a prime ideal $\mfk{p}$, we have a satisfying result
\begin{corollary}\label{int-loc}
If $B$ is integral over $A$, then $B_\mfk{p}$ is integral over $A_\mfk{p}$.
\end{corollary}
If $B$ is replaced by a field extension $L$ of the quotient field of $A$, and $C$ is replaced by the integral closure of $A$, we have the following corollary:
\begin{corollary}
If $B$ is the integral closure of $A$ in some field extension $L$ of the quotient field of $A$, then $S^{-1}B$ is the integral closure of $S^{-1}A$ in $L$.
\end{corollary}
Being integrally closed is also a local property. And we will use it to prove that the algebraic integers in the field $\Q(\omega)$ is $\Z[\omega]$.
\begin{corollary}
Let $A$ be an integral domain. Then the following are equivalent:
\begin{enumerate}
\item $A$ is integrally closed.
\item $A_\mfk{p}$ is integrally closed for each prime ideal $\mfk{p}$.
\item $A_\mfk{m}$ is integrally closed for each maximal ideal $\mfk{m}$.
\end{enumerate}
\end{corollary}
\begin{proof}
Let $K$ be the quotient field of $A$, let $C$ be the integral closure of $A$ in $K$, and let $f:A \to C$ be the canonical embedding. Then $A$ is integrally closed if and only if $f$ is surjective.
On the other hand, by theorem \ref{int-clo-loc}, $A_\mfk{p}$ (respectively $A_\mfk{m}$) is integrally closed if and only if $f_\mfk{p}$ (respectively $f_\mfk{m}$) is surjective.
However, a $A$-module homomorphism $\phi:M \to N$ being surjective is a local property \href{https://www.maths.usyd.edu.au/u/de/AGR/CommutativeAlgebra/pp600-610.pdf}{[proof]}. Therefore we have
\[
\begin{aligned}
A \text{ is integrally closed } &\iff f \text{ is surjective } \\
&\iff f_\mfk{p} \text{ is surjective } \iff A_\mfk{p} \text{ is integrally closed } \\
&\iff f_\mfk{m} \text{ is integrally closed } \iff A_\mfk{m} \text{ is integrally closed.}
\end{aligned}
\]
\end{proof}
% TODO: ADD SOME EXAMPLES
\subsection{Prime Ideals}
By theorem \ref{closure-f-g}, $\OK$ is a finitely-generated $\Z$-module, hence is a Noetherian domain. By transitivity of integral closures, $\OK$ is integrally closed. We are now interested in the Krull dimension of $\OK$. To do this, we investigate more of the prime ideal with respect to integral closure.
\begin{definition}
Let $B$ be a ring containing a ring $A$. Let $\mfk{p}$ be a prime ideal of $A$ and $\mfk{P}$ a prime ideal of $B$. We say that $\mfk{P}$ \textbf{lies above} $\mfk{p}$ if $\mfk{P} \cap A = \mfk{p}$ and we then write $\mfk{P}|\mfk{p}$.
\end{definition}
If $\mfk{P}|\mfk{p}$, we have a commutative diagram:
\[
\begin{tikzcd}
B \arrow[r, "\pi'"] & B/\mathfrak{P} \\
A \arrow[r, "\pi"] \arrow[u, "i"] & A/\mathfrak{p} \arrow[u, "i'"']
\end{tikzcd}
\]
where $i$ and $i'$ are inclusions, $\pi$ and $\pi'$ are canonical homomorphisms. \\
If $B$ is integral over $A$, then $B/\mfk{P}$ is integral over $A/\mfk{p}$, this is because of the following lemma if we take $\sigma$ to be $\pi$:
\begin{lemma}
Let $A \subset B$ be rings, and $\sigma:B \to C$ be a homomorphism. If $B$ is integral over $A$, then $\sigma(B)$ is integral over $\sigma(A)$.
\end{lemma}
\begin{proof}
If $B$ is integral over $A$, then for any $x \in B$ there is an equation
\[
x^n + a_{n-1}x^{n-1}+\cdots+a_0 = 0.
\]
Therefore
\[
\begin{aligned}
\sigma(x^n+a_{n-1}x^{n-1}+\cdots+a_0) &= \sigma(x^n)+\sigma(a_{n-1}x^{n-1})+\cdots+\sigma(a_0) \\
&= \sigma(x)^n + \sigma(a_{n-1})\sigma(x)^{n-1}+\cdots+\sigma(\sigma) \\
&= 0.
\end{aligned}
\]
Hence $\sigma(x)$ is integral in $\sigma(A)$.
\end{proof}
We want to show that prime ideals of $\OK$ is maximal, and they should be corresponded to prime ideals in $\Z$, which is maximal. For this reason we show the existence of lying-above prime ideals.
\begin{theorem}\label{lying-above}
Let $A$ be a ring, $\mfk{p}$ a prime ideal, and $B \supset A$ integral over $A$. Then $\mfk{p}B \ne B$, and there exists a prime ideal $\mfk{P}$ of $B$ lying above $\mfk{p}$.
\end{theorem}
\begin{proof}
We know that $B_\mfk{p}$ is integral over $A_\mfk{p}$ (corollary \ref{int-loc}) and that $A_\mfk{p}$ is local with maximal ideal $\mfk{m}_\mfk{p}=\mfk{p}A_\mfk{p}$. It follows that
\[
\mfk{p}B_\mfk{p}=\mfk{p}A_\mfk{p}B = \mfk{p}A_\mfk{p}B_\mfk{p}=\mfk{m}_\mfk{p}B_\mfk{p}.
\]
Hence it suffices to prove our assertion when $A$ is local. If $\mfk{p}B=B$, we have an equation
\[
1 = a_1b_1+\cdots+a_nb_n
\]
with $a_i \in \mfk{p}$ and $b_i \in B$. Let $B_0 = A[b_1,\cdots,b_n]$. Then $\mfk{p}B_0=B_0$ and $B_0$ is a finitely generated $A$-module. Hence by Nakayama's lemma, $B_0=0$, which is absurd.
To prove the existence of $\mfk{P}$, consider the following commutative diagram:
\[
\begin{tikzcd}
B \arrow[r] & B_\mathfrak{p} \\
A \arrow[r] \arrow[u] & A_\mathfrak{p} \arrow[u]
\end{tikzcd}
\]
where all arrows are natural inclusions. As is proved, $\mfk{m}_\mfk{p}B_\mfk{p} \ne B_\mfk{p}$. Hence $\mfk{m}_\mfk{p}B_\mfk{p}$ is contained in a maximal ideal $\mfk{M}$ of $\mfk{p}$, and therefore $\mfk{M} \cap A_\mfk{p}$ contains $\mfk{m}_\mfk{p}$. And we pick $\mfk{P}=\mfk{M} \cap B$. Then $\mfk{P}$ is a prime ideal of $B$, and taking intersection with $A$ going both ways around our diagram shows that $\mfk{M} \cap A = \mfk{p}$, so that
\[
\mfk{P} \cap A = \mfk{p},
\]
as was to be shown.
\end{proof}
Now we proceed to the crucial theorem to determine whether a prime lying above is maximal.
\begin{theorem}\label{lie-above-maximal}
Let $A$ be a subring of $B$, and assume $B$ is integral over $A$. Let $\mfk{P}$ be a prime ideal of $B$ lying over a prime ideal $\mfk{p}$ of $A$. Then $\mfk{P}$ is maximal $\iff$ $\mfk{p}$ is maximal.
\end{theorem}
\begin{proof}
$\implies$: Note $B/\mfk{P}$ is a field and is integral over the ring $A/\mfk{p}$. Were $A/\mfk{p}$ not a field, there would be a non-trivial ideal $\mfk{m}$ of it, and $B/\mfk{P}$ would have a prime ideal $\mfk{M}$ lying above $\mfk{m}$, by theorem \ref{lying-above}. A contradiction. \\
$\impliedby$: Note $A/\mfk{p}$ is a field. It suffices to prove that a ring $R$ which is integral over a field $k$ is a field. If $k$ is a field and non-zero $x \in R$ is integral over $k$, we have a minimal polynomial
\[
x^n+c_{n-1}y^{n-1}+\cdots+c_0=0
\]
with $c_i \in k$. Since $R$ is integral, we have $c_0 \ne 0$. We can clearly write
\[
x^{-1}=-c_0^{-1}(x^{n-1}+c_{n-1}y_{n-2}+\cdots+c_1) \in R,
\]
which is to say $R$ is integral, and the theorem is therefore proved.
\end{proof}
By using local properties, we can show the stability of prime ideals lying above:
\begin{corollary}
Let $A \subset B$ be rings, $B$ integral over $A$; Let $\mfk{P}$ and $\mfk{P}'$ be prime ideals of $B$ such that $\mfk{P} \subset \mfk{P}'$ and both $\mfk{P}$ and $\mfk{P}'$ lie above a prime ideal $\mfk{p}$ of $A$, then $\mfk{P}=\mfk{P}'$.
\end{corollary}
\begin{proof}
By corollary \ref{int-loc}, $B_\mfk{p}$ is integral over $A_\mfk{p}$. Let $\mfk{m}$ be the extension of $\mfk{p}$ in $A_\mfk{p}$ and $\mfk{M},\mfk{M}'$ be the extensions of $\mfk{P}$ and $\mfk{P}'$ respectively in $B_\mfk{p}$. Then $\mfk{m}$ is the maximal ideal of $A_\mfk{p}$; $\mfk{M} \subset \mfk{M}'$, and $\mfk{M}$, $\mfk{M}'$ lies above $\mfk{m}$. Hence by theorem \ref{lie-above-maximal}, $\mfk{M}$ and $\mfk{M}'$ are both maximal, hence equal. This reduces to $\mfk{P}=\mfk{P}'$.
\end{proof}
If the context is exactly localisation, we have a finer result:
\begin{theorem}\label{loc-corr}
Let $A$ be a commutative ring, $S \subset A$ be a multiplicatively closed set. We have a $1-1$-correspondence of prime ideals $\mfk{p}$ do not intersect $S$ and prime ideals of $S^{-1}A$:
\[
\mfk{p} \mapsto S^{-1}\mfk{p}, \quad \mfk{P} \mapsto \mfk{P} \cap A.
\]
\end{theorem}
\begin{proof}
To prove that $S^{-1}\mfk{p}=\mfk{P}$ is prime, suppose that $(a/s)(b/t)=ab/st = p/u \in \mfk{P}$. By definition there exists some $r \in S$ such that $r(abu-stp)=0$. It follows that $rabu=rstp \in \mfk{p}$. But $r,u$ are not in $\mfk{p}$, hence we can only have $ab \in \mfk{p}$, which gives that $a \in \mfk{p}$ or $b \in \mfk{p}$, and as a result $a/s \in \mfk{P}$ or $b/t \in \mfk{P}$. Besides we have $\mfk{p} = \mfk{P} \cap A$. $\subset$ inclusion is clear, but for the converse inclusion, note that if $p/s=a/1 \in \mfk{P} \cap A$, we have $up=uas$ for some $u \in S$, which forces $a$ to be an element of $\mfk{p}$. (Note we implicitly used the fact that $\mfk{p}$ does not intersect $S$.)
For the converse, first note that $\mfk{p}=\mfk{P} \cap A$ is indeed a prime ideal. For any $(a/1)(b/1) \in \mfk{p} \subset \mfk{P}$, we must have $a/1 \in \mfk{P}$ or $b/1 \in \mfk{P}$, but both $a/1$ and $b/1$ are in $A$. Also, $\mfk{p}$ does not intersect $S$ because if $s \in S \cap \mfk{p}$, then $(1/s)s=1\in \mfk{p}$, which is absurd. It remains to show that $\mfk{P} = S^{-1}\mfk{p}$. It is clear that $S^{-1}\mfk{p} \subset \mfk{P}$. For the converse, pick any $a/s \in \mfk{P}$, we have $a/1=(a/s)(s/1) \in \mfk{p}$, and therefore $a/s=a(1/s) \in S^{-1}\mfk{p}$.
\end{proof}
In particular, we can also study the localised ring.
\begin{corollary}
Let $\mfk{m}_\mfk{p}=\mfk{p}A_\mfk{p}$ be the maximal ideal of $A_\mfk{p}$. We have a canonical embedding
\[
A/\mfk{p} \hookrightarrow A_\mfk{p}/\mfk{m}_\mfk{p} \cong K(A/\mfk{p})
\]
where $K(B)$ is the field of fractions of $B$. In particular, if $\mfk{p}$ is maximal, one has an isomorphism for all $n \ge 1$:
\[
A/\mfk{p}^n \cong A_\mfk{p}/\mfk{m}_\mfk{p}^n.
\]
\end{corollary}
\begin{proof}
Since $\mfk{p} = \mfk{m}_\mfk{p} \cap A$, the canonical map
\[
a \mod \mfk{p} \mapsto a/1 \mod \mfk{m}_\mfk{p}
\]
is injective. $A_\mfk{p}/\mfk{m}_\mfk{p}$ can be identified as the field of fraction of $A/\mfk{p}$ because given any non-zero $a/1 \mod \mfk{m}_\mfk{p}$, we see $a \in A \setminus \mfk{p}$, hence $1/a \mod \mfk{m}_\mfk{p}$ is exactly the inverse of $a/1 \mod \mfk{m}_\mfk{p}$.
Next we assume that $\mfk{p}$ is maximal and consider the canonical map
\[
\varphi:a \mod \mfk{p}^n \mapsto a/1 \mod \mfk{m}_\mfk{p}^n.
\]
If $n=1$, then both $A/\mfk{p}$ and $A_\mfk{p}/\mfk{m}_\mfk{p}$ are fields, and the field of fractions of a field is itself. To prove it for all $n \ge 0$, we need the fact that $s \mod \mfk{p}^n$ is a unit whenever $n \ge 0$ and $s \in A \setminus \mfk{p}$, which will be shown later as a lemma.
$\varphi$ is injective because if $a/1 \in \mfk{m}_\mfk{p}^n$, i.e. $a/1 = b/s$ where $b \in \mfk{p}^n$ and $s \not \in \mfk{p}$, then there exits some $u \not\in \mfk{p}$ such that $uas = ub \in \mfk{p}^n$. Since both $ u \mod \mfk{p}^n$ and $s \mod \mfk{p}^n$ are units, we see $a \mod \mfk{p}^n$ is zero in $A/\mfk{p}^n$.
$\varphi$ is surjective because given $a/s \in A_\mfk{p}$ with $a \in A$ and $s \not\in \mfk{p}$, there exists some $a' \in A$ such that $a \equiv a's \mod \mfk{p}^n$. Indeed, let $t \mod \mfk{p}^n$ be the inverse of $s \mod \mfk{p}^n$, we can put $a' = at$. Therefore $a/s \equiv a' \mod \mfk{p}^nA_\mfk{p}$ (by theorem \ref{loc-corr}), which is equivalent to say that $a/s \mod \mfk{m}_\mfk{p}^n$ lies in the image of $\varphi$.
\end{proof}
\begin{lemma}
Let $A$ be a ring and $\mfk{p}$ is a maximal ideal. Then $\mfk{p}^n+sA=A$ for all $n \ge 1$ and $s \in A \setminus \mfk{p}$. Besides, this implies that $s \mod \mfk{p}^n$ is a unit in $A/\mfk{p}^n$.
\end{lemma}
\begin{proof}
When $n=1$, note $\mfk{p} \subsetneqq \mfk{p}+sA$, while $\mfk{p}$ is maximal, we must have $\mfk{p}+sA=A$. When $n \ge 2$, suppose it holds for $n-1$, then we have
\[
A = \mfk{p}^{n-1}+sA \implies \mfk{p}=\mfk{p}A = \mfk{p}(\mfk{p}^{n-1}+sA) \subsetneqq \mfk{p}^n+sA,
\]
which forces $\mfk{p}^n+sA$ to be $A$ itself.
Now we consider $A$-modules
\[
\mfk{p}^n+sA = A.
\]
By taking the quotient, we obtain
\[
\overline{s}A/\mfk{p}^n=A/\mfk{p}^n.
\]
It follows that $s \mod \mfk{p}^n$ is a unit in $A/\mfk{p}^n$.
\end{proof}
And now we are more than ready to prove that $\OK$ is Dedekind.
\begin{theorem}\label{o_k-dedekind}
Every prime ideal $\mfk{P}$ in $\OK$ is maximal. Hence $\OK$ is of Krull dimension $1$ and is therefore Dedekind.
\end{theorem}
\begin{proof}
Note it suffices to prove that every prime ideal $\mfk{P}$ of $\OK$ lies above some prime ideal of $\Z$, since $\Z$ has Krull dimension $1$, and the proof follows from theorem \ref{lie-above-maximal}. All we need to do is to prove that $\mfk{P} \cap \Z$ is non-zero: since the inverse image of a prime ideal is prime, we are done. For each $x \in \mfk{P}$, we have a minimal polynomial $f \in \Z[X]$ such that
\[
f(x) = x^n+c_{n-1}x^{n-1}+\cdots+c_0=0
\]
with $c_i \in \Z$ and $c_0 \ne 0$. It follows that
\[
c_0=-(x^n+c_{n-1}x^{n-1}+\cdots+c_1x) \in \mfk{P} \cap \Z,
\]
which is to say $\mfk{P} \cap \Z$ is indeed non-zero. This concludes the proof.
\end{proof}
\begin{example}
As a classic example, consider $K=\Q(\sqrt{-5})$ and $\OK = \Z[\sqrt{-5}]$. This ring is not a unique factorial domain because we have
\[
6 = 2 \cdot 3 = (1-\sqrt{-5}) \cdot (1+\sqrt{-5}).
\]
But if we view it in the sense of product of ideals, we still have some uniqueness. Let $\mfk{m}$ be the maximal ideal containing $6$, then
\[
\mfk{m} = (2,1-\sqrt{-5})(2,1+\sqrt{-5})
\]
is unique. Note two ideals on the right hand side are indeed maximal (hence prime) because
\[
\begin{aligned}
\frac{\Z[\sqrt{-5}]}{(2,1-\sqrt{-5})} &\cong \frac{\Z[X]/(X^2+5)}{(2,1-X,X^2+5)/(X^2+5)} \\
&\cong \frac{\Z[X]}{(2,1-X,X^2+5)} \cong \frac{\Z_2[X]}{(1-X,X^2-1)} \cong \frac{\Z_2[X]}{(1-X)} \cong \Z_2.
\end{aligned}
\]
Likewise,
\[
\begin{aligned}
\frac{\Z[\sqrt{-5}]}{(3,1+\sqrt{-5})} &\cong \frac{\Z[X]/(X^2+5)}{(3,1+X,X^2+5)/(X^2+5)} \\
&\cong \frac{\Z[X]}{(3,1+X,X^2+5)} \cong \frac{\Z_3[X]}{(1+X,X^2-1)} \cong \frac{\Z_3[X]}{(1+X)} \cong \Z_3.
\end{aligned}
\]
\end{example}
We will see when a Dedekind domain is UFD in the future.
\section{Galois extensions}
\subsection{Special subgroups of the Galois group}
In this subsection we study the behaviour of Galois group with respect to integral closure, which can of course help us study number field and algebraic integers if we are interested in the extension itself.
If $K$ is a Galois extension of $\Q$, then the Galois group allows us to transform amongst prime ideals in a natural way. This is because of the following theorem.
\[
\begin{tikzcd}
\mathfrak{P} \arrow[rr, "\exists \sigma \in G"] & & \mathfrak{Q} \\
& \mathfrak{p} \arrow[lu] \arrow[ru] &
\end{tikzcd}
\]
\begin{theorem}\label{galois-lie-above}
Let $A$ be a ring, integrally closed in its quotient field $K$. Let $L$ be a finite Galois extension of $K$ with group $G$. Let $\mfk{p}$ be a maximal ideal of $A$, and let $\mfk{P}$, $\mfk{Q}$ be prime ideals of the integral closure of $A$ in $L$ lying above $\mfk{p}$. Then there exists $\sigma \in G$ such that $\sigma\mfk{P} = \mfk{Q}$.
\end{theorem}
\begin{proof}
Suppose that $\mfk{P}=\sigma\mfk{Q}$ for all $\sigma \in G$. By the Chinese remainder theorem, we have some $x \in B$ such that
\[
\begin{aligned}
x &\equiv 0 \mod \mfk{P} \\
x &\equiv 1 \mod \sigma\mfk{Q}, \quad \forall \sigma \in G.
\end{aligned}
\]
Then the norm
\[
N_K^L(x) = \prod_{\sigma \in G}\sigma{x}
\]
lies in $B \cap K = A$ since $A$ is integrally closed, and lies in $\mfk{P} \cap A = \mfk{p}=\mfk{Q} \cap A \subset \mfk{Q}$. But we also have $\sigma{x} \not\in \mfk{Q}$ for all $\sigma \in G$, hence $N_K^L(x) \not \in \mfk{Q}$, a contradiction.
\end{proof}
If one localise, the consideration on whether a prime ideal is maximal is not required. Besides, if $A$ is of Krull dimension $1$, then one has no need to consider as well. Since we have shown that $\OK$ is a Dedekind domain, this theorem can be applied as well. Next we show the finiteness of prime ideals lying above.
\begin{corollary}
Let $A$ be an integrally closed domain whose field of fraction is $K$. Let $E$ be a finite separable extension of $K$, and $B$ the integral closure of $A$ in $E$. Let $\mfk{p}$ be a maximal ideal of $A$. Then there exists only a finite number of prime ideals of $B$ lying above $\mfk{p}$.
\end{corollary}
\begin{proof}
If $E$ is Galois over $K$, then by theorem \ref{galois-lie-above}, $\sigma\mfk{P}_1 = \mfk{P}_2$ for some $\sigma \in \gal(E/K)$. Suppose $\mfk{P}_1|\mfk{p}$, then the set of prime ideals lying above $\mfk{p}$ is contained in the set
\[
\{\mfk{Q} \subset B: \mfk{Q}=\sigma\mfk{P}_1,\sigma\in\gal(E/K)\},
\]
hence is finite because $\gal(E/K)$ is finite. If $E$ is not necessarily Galois, we can pick the smallest Galois extension $L/K$ containing $E$, which is a finite extension as well. Let $C$ be the integral closure of $A$ in $L$. Suppose $\mfk{P},\mfk{Q} \in \spec(B)$ are two distinct prime ideals lying above $\mfk{p}$, and $\mfk{P}',\mfk{Q}' \in \spec(C)$ lying above $\mfk{P}$ and $\mfk{Q}$ respectively. Note $\mfk{P}' \ne \mfk{Q}'$ because if not then $\mfk{P}=\mfk{Q}$, a contradiction. Therefore the distinct prime ideals of $B$ lying above $\mfk{p}$ are less than the distinct prime ideals of $C$ lying above $\mfk{p}$, which proves our assertion.
\[
\begin{tikzcd}
\mathfrak{P}' & & \mathfrak{Q}' & C \\
\mathfrak{P} \arrow[u] & & \mathfrak{Q} \arrow[u] & B \arrow[u, dashed] \\
& \mathfrak{p} \arrow[lu] \arrow[ru] & & A \arrow[u, dashed]
\end{tikzcd}
\]
\end{proof}
\begin{example}\label{gauss-int-1}
Now take $K=\Q(i)$, $\OK=\Z[i]$ and $\mfk{p}=(5)$. Since $\gal(K/\Q)=\{1,\sigma\}$ where $\sigma$ is the complex conjugation, there are at most two prime ideals lying above $\mfk{p}$. First of all $5\Z[i]$ is not prime because
\[
5+0i = (2-i)(2+i).
\]
Since $\Z[i]$ is a PID, we only need to consider Gaussian integers that divide $5$. Keeping in mind that $\Z[i]$ is also an Euclidean domain, we have two non-trivial solutions up to units in $\Z[i]$:
\[
5 = (2-i)(2+i).
\]
As ideals, we have $(2-i)=(1+2i)=(-2+i)$. Since $2-i$ is irreducible in $\Z[i]$, we have found a prime ideal $\mfk{P}=(2-i)$ lies above $\mfk{p}$, and $\mfk{P}'=\sigma\mfk{P}=(2+i)$ has to be the remaining one. Note we have also established the factorisation of $5\Z[i]$ in the Dedekind domain $\OK$.
\end{example}
This example also shows that the norm defined in theorem \ref{galois-lie-above} makes sense, because we have
\[
N_{\Q}^{K}(a+bi)=\prod_{\sigma \in \gal(K/\Q)}\sigma(a+bi) = (a+bi)(a-bi)=a^2+b^2.
\]
We will study norm extensively in the future. %TODO: add reference if it is needed.
Let $A$ be an integrally closed ring with quotient field $K$, and $B$ its integral closure in a finite Galois extension $L$. Then firstly $\sigma{B}=B$ for all $\sigma \in \gal(L/K)$ (Proof: $\sigma{B} \subset L$ is integral over $\sigma{A}=A$, hence has to be $B$ itself). Automorphisms fixing base field give rise to Galois group, and now we are interested in automorphisms that also fix ideals.
\subsubsection{Decomposition groups and fields}
\begin{definition}
Notations being above, let $\mfk{p}$ be a maximal ideal of $A$, $\mfk{P}$ maximal in $B$ lying above $\mfk{p}$. Then the subgroup
\[
G_\mfk{P} = \{\sigma \in \gal(L/K):\sigma\mfk{P}=\mfk{P}\}
\]
is called the \textbf{decomposition group} of $\mfk{P}$. Its fixed field will be denoted by $L^d$, and will be called the \textbf{decomposition field} of $\mfk{P}$.
\end{definition}
Two non-trivial examples are given, abelian and non-abelian. We will frequently return to these examples after new concepts are introduced.
% TODO: expand details of these two examples.
\begin{example}
Consider $K = \Q(\sqrt{-1},\sqrt{2},\sqrt{5})$, whose Galois group is isomorphic to $\Z/2\Z \times \Z/2\Z \times \Z/2\Z$. The decomposition field of $(5)$ is
\[
K^d = \Q(\sqrt{-1},\sqrt{2}).
\]
\end{example}
\begin{example}
Consider $K = \Q(\sqrt[3]{19},\omega)$ where $\omega = e^{2\pi i/3}$. The Galois group is $S_3$. The decomposition fields of $(3)$ are
\[
\Q(\sqrt[3]{19}),\quad \Q(\omega\sqrt[3]{19}),\quad\Q(\omega^2\sqrt[3]{19}).
\]
At this point we can only compute the field manually but after introducing ramification index things are much easier.
\end{example}
It is natural to think whether a decomposition group is normal, when the Galois group is non-abelian. For this question we have an pretty elegant result.
\begin{theorem}
Notation still being above, the decomposition group of $\sigma\mfk{P}$ where $\sigma \in \gal(L/K)$ is $\sigma G_\mfk{P}\sigma^{-1}$, i.e.
\[
G_{\sigma\mfk{P}} = \sigma G_\mfk{P}\sigma^{-1}.
\]
\end{theorem}
This theorem says, the Galois group acting on itself by conjugation yields all decomposition groups of primes of $B$ lying above a certain prime of $A$.
\begin{proof}
We can write $\gal(L/K) = \bigcup\sigma_jG_\mfk{P}$ as a coset decomposition. We claim this decomposition determines distinct prime ideals lying above $\mfk{p}$. Note
\[
\sigma\mfk{P}=\tau\mfk{P} \iff \tau^{-1}\sigma\mfk{P}=\mfk{P} \iff \tau^{-1}\sigma \in G_\mfk{P}
\]
which is equivalent to say $\tau$ and $\sigma$ lie in the same coset mod $G_\mfk{P}$.
This claim actually proves this theorem. On one hand, pick $\lambda \in G_\mfk{P}$, then
\[
\sigma\lambda\mfk{P} = \sigma\lambda\sigma^{-1}\sigma\mfk{P} = \sigma\mfk{P}
\]
Hence $\sigma G_{\mfk{P}}\sigma^{-1} \subset G_{\sigma\mfk{P}}$. Note we have used the fact that $\sigma\lambda,\sigma \in \sigma G_\mfk{P}$.
On the other hand, if $\lambda\sigma\mfk{P} = \sigma\mfk{P}$, we have $\lambda\sigma \in \sigma G_\mfk{P}$, hence $\lambda \in \sigma G_\mfk{P}\sigma^{-1}$, which is equivalent to say $G_{\sigma\mfk{P}} \subset \sigma G_\mfk{P} \sigma^{-1}$.
\end{proof}
As for the field, we have a pretty concrete result:
\begin{theorem}
Assume $L/K$ is Galois and finite. The field $L^d$ is the smallest $E$ subfield of $L$ containing $K$ such that $\mfk{P}$ is the only prime of $B$ lying above $\mfk{P} \cap E$.
\end{theorem}
\begin{proof}
Let $E$ be the smallest subfield of $L$ satisfying the property above, and write $\mfk{q} = \mfk{P} \cap E$. By the fundamental theorem of Galois theory ($L/E$ is Galois) and theorem \ref{galois-lie-above}, prime ideals of $B$ lying above $\mfk{q}$ differs by an element of $\gal(L/E)$. But by assumption there is only one such prime $\mfk{P}$, hence $H \subset G_\mfk{P}$ and therefore $E \supset L^d$.
On the other hand, let $B^d$ be the integral closure of $A$ in $L^d$ (which is Dedekind as well), and let $\mfk{Q}=\mfk{P} \cap B^d$. By theorem \ref{galois-lie-above}, $\mfk{P}$ is the only prime of $B$ lying above $\mfk{Q}$ in $B^d$. Hence $E \subset L^d$, which proves the theorem.
\end{proof}
We are not done yet: the result can be even much sharpener:
\begin{theorem}\label{residue-iso}
Notation being above, the canonical injection $\varphi:A/\mfk{p} \to B^d/\mfk{Q}$ is an isomorphism.
\end{theorem}
\begin{proof}
First of all we clarify what we mean by canonical injection:
\[
\varphi:x + \mfk{p} \mapsto x + \mfk{Q}.
\]
This is indeed injective because if if $\varphi(x+\mfk{p})=\mfk{Q}$, we have $x \in \mfk{Q}$. This gives
\[
x \in \mfk{Q} \cap A = (\mfk{P} \cap A) \cap B^d = \mfk{p} \cap B^d = \mfk{p}.
\]
It remains to prove that $\varphi$ is surjective. Given $x + \mfk{Q} \in B^d/\mfk{Q}$, we need to find an element $z \in A$ such that $\varphi(z) = x + \mfk{Q}$.
Pick $\sigma \in \gal(L/K) \setminus G_\mfk{P}$. Let
\[
\mfk{Q}_\sigma = \sigma^{-1}\mfk{P} \cap B^d.
\]
Then $\mfk{Q}_\sigma \ne \mfk{Q}$ (note $\mfk{P}$ is assumed to be maximal hence so are $\mfk{Q}$ and $\mfk{Q}_\sigma$). Let $x$ be an element of $B^d$. By Chinese remainder theorem, there exists an element $y \in B^d$ such that
\[
\begin{aligned}
y &\equiv x \mod \mfk{Q}, \\
y &\equiv 1 \mod \mfk{Q}_\sigma.
\end{aligned}
\]
Hence in particular,
\[
\begin{aligned}
y &\equiv x \mod \mfk{P}, \\
y &\equiv 1 \mod \sigma^{-1}\mfk{P}.
\end{aligned}
\]
The second congruence gives
\[
\sigma{y} \equiv 1 \mod \mfk{P}.
\]
Note this holds for all $\sigma \not \in G_\mfk{P}$. For $\lambda \in G_\mfk{P}$, we have $\sigma{y}=y \equiv x \mod \mfk{Q}$. Thus we obtain
\[
z=N_K^L(y) \equiv x \mod \mfk{P}.
\]
First of all $z \in K$ by definition of norm. Since $z$ is integral over $A$, it has to be an element in $A$. We also have % TODO: 'definition of norm' deserves more explanation.
\[
z \equiv x \mod \mfk{Q}
\]
because both $z$ and $x$ lie in $B^d$. Hence we obtain $\varphi(z) = x + \mfk{P}$ as we wanted.
\end{proof}
% TODO: examples.
\subsubsection{Inertia groups and fields}
We are concerned about the homomorphism induced by the decomposition group.
\begin{theorem}
Notation still being above, $\overline{B}=B/\mfk{P}$ is a normal extension of $\overline{A}=A/\mfk{p}$, and the map $\sigma \to \overline{\sigma}$ induces a homomorphism of $G_\mfk{P}$ onto $\gal(\overline{B}/\overline{A})$
\end{theorem}
\begin{proof}
Any element of $\overline{B}$ can be written as $\overline{x}$ for some $x \in B$. Let $\overline{x}$ generate a separable subextension of $\overline{A}$, and let $f$ be the irreducible polynomial for $x$ over $K$. The coefficient of $f$ lie in $A$ because $x$ is integral over $A$, and all the roots of $f$ are integral over $A$. Thus
\[
f(X) = \prod_{i=1}^{m}(X-x_i)
\]
splits into linear factors in $B$. Since
\[
\bar{f}(X)=\prod_{i=1}^{m}(X-\overline{x}_i)
\]
and all the $\overline{x}_i$ lie in $\overline{B}$, it follows that $\bar{f}$ splits into linear factors in $\overline{B}$. We observe that $f(x)=0 \implies \bar{f}(x)=0$. Hence $\overline{B}$ is normal over $\overline{A}$, and
\[
[\overline{A}(\overline{x}):\overline{A}] \le [K(x):K] \le [L:K].
\]
This implies that the maximal separable subextension of $\overline{A}$ in $\overline{B}$ is of finite degree over $A$ by the primitive element theorem, and in fact is always bounded by $[L:K]$.
It remains to prove that $\sigma \mapsto \overline{\sigma}$ is actually a surjective homomorphism. By theorem \ref{residue-iso}, it suffices to take $K=L^d$ and $\gal(L/K)=G_\mfk{P}$. Take a generator $\overline{x}$ of the maximal subextension of $\overline{B}$ over $\overline{A}$, for some $x \in B$. Let $f$ be the irreducible polynomial of $x$ over $K$. Any automorphism of $\overline{B}$ is determined by its effect on $\overline{x}$, and maps $\overline{x}$ to some root of $\bar{f}$. Suppose that $x=x_1$. Given any root $x_i$ of $f$, there exists an element $\sigma$ of $G_\mfk{P}$ such that $\sigma x = x_i$. Hence $\overline{\sigma}\overline{x}=\overline{x}_i$. Hence the automorphism of $\overline{B}$ over $\overline{A}$ is induced by elements of $G$ operate transitively on the root of $\bar{f}$. Hence they give us all automorphisms of the residue class field, and the proof is complete.
\end{proof}
This enables us to work on algebraic closure with some ease:
\begin{corollary}
Let $\phi:A \to A/\mfk{p}$ be the canonical homomorphism, and let $\psi_1$, $\psi_2$ be two homomorphisms of $B$ extending $\varphi$ in a given algebraic closure of $A/\mfk{p}$. Then there exists an automorphism $\sigma$ of $L$ over $K$ such that
\[
\psi_1 = \psi_2 \circ \sigma
\]
\end{corollary}
\begin{proof}
The kernels of $\psi_1$ and $\psi_2$ are prime ideals of $B$ and according to theorem \ref{galois-lie-above} they differ by an automorphism. Hence there exists $\tau \in \gal(L/K)$ such that $\psi_1$ and $\psi_2$ have the same kernel $\mfk{P}$. Hence there exists an automorphism $\omega$ of $\psi_1(B)$ onto $\psi_2(B)$ such that $\omega \circ \psi_1 = \psi_2$. There exists an element $\sigma$ of $G_\mfk{P}$ such that $\omega \circ \psi_1 = \psi_1 \circ \sigma$, which proves what we want.
\end{proof}
\begin{definition}
Let $\overline{G}_\mfk{P}$ be the automorphism group of $B/\mfk{P}$. The kernel of the map
\[
G_\mfk{P} \to \overline{G}_\mfk{P}
\]
is called the inertia group. That is, these elements induce the trivial automorphism in $B/\mfk{P}$.
\end{definition}
\subsection{Automorphisms}
\section{Dedekind domain}
\subsection{Operations of ideals}
% TODO: Daniel Chapter 3.
\subsection{Ramification index}
\subsection{The norm and trace}
We used the concept of norm and trace at the very beginning. Here is a good chance to study them extensively. Recall for $\mathds{C}$ and $\mathds{R}$ we have a natural faithful representation
\[
\begin{aligned}
\rho:\mathds{C} &\to End(\mathds{R}^2) \\
a+bi &\mapsto \begin{pmatrix} a & -b \\ b & a \end{pmatrix}.
\end{aligned}
\]
Note $|\rho(a+bi)|=a^2+b^2$, which is pretty close to the norm in analysis. It is not a good idea to take square root in the sense of algebra so we directly use the determinant. We will also be using trace of such matrices.
\begin{definition}
Let $E$ be a finite extension of $k$, which we view as a finite dimensional vector space over $k$. Each $\alpha \in E$ induces a linear map by multiplication:
\[
\begin{aligned}
m_\alpha : E &\to E \\
x &\mapsto \alpha{x}.
\end{aligned}
\]
We define the norm and trace from $E$ to $k$ by
\[
\det(m_\alpha)=N_k^E(\alpha), \quad \tr(m_\alpha)=\tr_k^E(\alpha).
\]
\end{definition}
Note this has nothing to do with norm in the sense of topology. The reason is, the norm lies in $k$, which is an arbitrary field. And a field alone has nothing to do with real numbers. Besides, consider the group field $\Q(\sqrt{2})/\Q$. In this field, the we have the matrix representation of $1+\sqrt{2}$ to be
\[
1+\sqrt{2} \mapsto \begin{pmatrix} 1 & 2 \\ 1 & 1 \end{pmatrix}
\]
whose determinant is $-1$. It makes little sense to compare this to norm in topology.
% TODO: formula of norm and trace.
% TODO: further properties.
\subsection{Discrete valuation rings}
A \textbf{discrete valuation ring} can be considered as a localisation of Dedekind domain. Indeed, if $A$ is a discrete valuation ring, then $A$ is Noetherian and of Krull dimension $1$, and is integrally closed, hence Dedekind. If $A$ is local and Dedekind, then $A$ is a discrete valuation ring. In general, a Noetherian domain $A$ of Krull dimension one is Dedekind if and only if the localisation $A_\mfk{p}$ is a discrete valuation ring for all prime $\mfk{p}$. With respect to localisation we have a natural result:
\begin{theorem}
Let $A$ be a Dedekind ring and $M,N$ two modules over $A$. If $M_\mfk{p} \subset N_\mfk{p}$ for all prime $\mfk{p}$, then $M \subset N$.
\end{theorem}
\begin{proof}
Let $a \in M$. For each $\mfk{p}$ we can find $x_\mfk{p} \in N$ and $s_\mfk{p} \in A \setminus \mfk{p}$ such that $a = x_\mfk{p}/s_\mfk{p}$. Let $\mfk{b}$ be the ideal generated by the $s_\mfk{p}$, ranging through all $\mfk{p} \in \spec(A)$. Then $\mfk{b}$ is the unit ideal $A$, and we can write
\[
1 = \sum_{\mfk{p} \in \spec(A)} y_\mfk{p}s_\mfk{p}
\]
with elements $y_\mfk{p} \in A$ all but a finite number of which are $0$. This yields
\[
a = \sum_{\mfk{p} \in \spec(A)} y_\mfk{p}s_\mfk{p}a = \sum_{\mfk{p} \in \spec(A)} y_\mfk{p}x_\mfk{p} \in N
\]
as desired.
\end{proof}
Now we study torsion-free modules over a discrete valuation ring. If $A$ is a discrete valuation ring, then in particular, $A$ is a principal ideal ring, and any finitely generated torsion-free module $M$ over $A$ is free. If its rank is $n$, and if $\mfk{p}$ is the maximal idea, then $M/\mfk{p}M$ is a free module of rank $n$. Further, we have
\begin{theorem}
Let $A$ be a local ring and $M$ a free module of rank $n$ over $A$. Let $\mfk{p}$ be the maximal ideal of $A$. Then $M/\mfk{p}M$ is a vector space of dimension $n$ over $A/\mfk{p}$.
\end{theorem}
\begin{proof}
Let $\{x_1,\dots,x_n\}$ be a basis of $M$ over $A$, then
\[
M \cong \bigoplus_{i}Ax_i
\]
and
\[
M/\mfk{p}M \cong \bigoplus_{i}(A/\mfk{p})\overline{x}_i
\]
where $\overline{x}_i$ is the residue class of $x_i$ mod $\mfk{p}$.
\end{proof}
|
If $y$ and $x$ are real numbers, then $\i y = x$ if and only if $x=0$ and $y=0$. |
% Created 2020-07-13 lun 12:51
% Intended LaTeX compiler: pdflatex
\documentclass[letterpaper,fleqn]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{khpreamble}
\usepackage{tabularx}
\usepackage{geometry}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\geometry{top=20mm, bottom=20mm, left=24mm, right=18mm}
\author{Kjartan Halvorsen}
\date{}
\title{Polynomial design (RST) exercise}
\hypersetup{
pdfauthor={Kjartan Halvorsen},
pdftitle={Polynomial design (RST) exercise},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 26.3 (Org mode 9.3.6)},
pdflang={English}}
\begin{document}
\maketitle
\section*{Determine the order of the controller}
\label{sec:org6e78179}
\begin{center}
\includegraphics[width=0.7\linewidth]{../../figures/2dof-block-explicit}
\end{center}
In each of the cases determine the order of the feedback controller \(F_{b}(z)=\frac{S(z)}{R(z)}\) and write out the \(R(z)\) and \(S(z)\) polynomials. Determine also the order of the observer polynomial \(A_o(z)\). You don't have to solve for the controller coefficients.
\subsection*{Case 1}
\label{sec:orgb815efe}
Plant is \(H(z) = \frac{b_0z+b_1}{z^3 + a_1z^2 + a_2z}\), desired response to reference signal \(H_c(z) = \frac{0.2^2}{z(z-0.8)(z-0.8)}\), observer poles in the origin.
\vspace*{27mm}
\subsection*{Case 2}
\label{sec:org6948edd}
Plant is \(H(z) = \frac{b_0z+b_1}{z^3 + a_1z^2 + a_2z}\), desired response to reference signal \(H_c(z) = \frac{0.2^2}{(z-0.8)^3}\), observer poles in the origin and integral action in the feedback controller (incremental controller).
\vspace*{27mm}
\subsection*{Case 3}
\label{sec:orgef90a48}
Plant is \(H(z) = \frac{b_0z+b_1}{z^2 + a_1z + a_2}\) and there is a delay of 2 sampling periods in the feedback path. The desired response to reference signal \(H_c(z) = \frac{0.2^2}{(z-0.8)(z-0.8)}\), observer poles in the origin and integral action in the feedback controller (incremental controller).
\end{document} |
//
// $Id: SpectrumWorkerThreads.hpp 6585 2014-08-07 22:49:28Z chambm $
//
//
// Original author: William French <william.r.frenchwr .@. vanderbilt.edu>
//
// Copyright 2014 Vanderbilt University - Nashville, TN 37232
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef _SPECTRUMWORKERTHREADS_HPP_
#define _SPECTRUMWORKERTHREADS_HPP_
#include "pwiz/data/msdata/MSData.hpp"
#include <boost/smart_ptr.hpp>
namespace pwiz {
namespace msdata {
class SpectrumWorkerThreads
{
public:
SpectrumWorkerThreads(const SpectrumList& sl);
~SpectrumWorkerThreads();
SpectrumPtr processBatch(size_t index, bool getBinaryData = true);
private:
class Impl;
boost::scoped_ptr<Impl> impl_;
};
} // namespace msdata
} // namespace pwiz
#endif // _SPECTRUMWORKERTHREADS_HPP_
|
lemma exists_component_superset: "\<lbrakk>t \<subseteq> s; s \<noteq> {}; connected t\<rbrakk> \<Longrightarrow> \<exists>c. c \<in> components s \<and> t \<subseteq> c" |
[STATEMENT]
lemma length_upto_enum_one:
fixes x :: "'a :: len word"
assumes lt1: "x < y" and lt2: "z < y" and lt3: "x \<le> z"
shows "[x , y .e. z] = [x]"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. [x , y .e. z] = [x]
[PROOF STEP]
unfolding upto_enum_step_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (if z < x then [] else map (\<lambda>xa. x + xa * (y - x)) [0 .e. (z - x) div (y - x)]) = [x]
[PROOF STEP]
proof (subst upto_enum_red, subst if_not_P [OF leD [OF lt3]], clarsimp, rule conjI)
[PROOF STATE]
proof (state)
goal (2 subgoals):
1. unat ((z - x) div (y - x)) = 0
2. (z - x) div (y - x) * (y - x) = 0
[PROOF STEP]
show "unat ((z - x) div (y - x)) = 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. unat ((z - x) div (y - x)) = 0
[PROOF STEP]
proof (subst unat_div, rule div_less)
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. unat (z - x) < unat (y - x)
[PROOF STEP]
have syx: "unat (y - x) = unat y - unat x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. unat (y - x) = unat y - unat x
[PROOF STEP]
by (rule unat_sub [OF order_less_imp_le]) fact
[PROOF STATE]
proof (state)
this:
unat (y - x) = unat y - unat x
goal (1 subgoal):
1. unat (z - x) < unat (y - x)
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
unat (y - x) = unat y - unat x
goal (1 subgoal):
1. unat (z - x) < unat (y - x)
[PROOF STEP]
have "unat (z - x) = unat z - unat x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. unat (z - x) = unat z - unat x
[PROOF STEP]
by (rule unat_sub) fact
[PROOF STATE]
proof (state)
this:
unat (z - x) = unat z - unat x
goal (1 subgoal):
1. unat (z - x) < unat (y - x)
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
unat (y - x) = unat y - unat x
unat (z - x) = unat z - unat x
[PROOF STEP]
show "unat (z - x) < unat (y - x)"
[PROOF STATE]
proof (prove)
using this:
unat (y - x) = unat y - unat x
unat (z - x) = unat z - unat x
goal (1 subgoal):
1. unat (z - x) < unat (y - x)
[PROOF STEP]
using lt2 lt3 unat_mono word_less_minus_mono_left
[PROOF STATE]
proof (prove)
using this:
unat (y - x) = unat y - unat x
unat (z - x) = unat z - unat x
z < y
x \<le> z
?a < ?b \<Longrightarrow> unat ?a < unat ?b
\<lbrakk>?y < ?z; ?x \<le> ?y\<rbrakk> \<Longrightarrow> ?y - ?x < ?z - ?x
goal (1 subgoal):
1. unat (z - x) < unat (y - x)
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
unat (z - x) < unat (y - x)
goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
unat ((z - x) div (y - x)) = 0
goal (1 subgoal):
1. (z - x) div (y - x) * (y - x) = 0
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
unat ((z - x) div (y - x)) = 0
[PROOF STEP]
show "(z - x) div (y - x) * (y - x) = 0"
[PROOF STATE]
proof (prove)
using this:
unat ((z - x) div (y - x)) = 0
goal (1 subgoal):
1. (z - x) div (y - x) * (y - x) = 0
[PROOF STEP]
by (simp add: unat_div) (simp add: word_arith_nat_defs(6))
[PROOF STATE]
proof (state)
this:
(z - x) div (y - x) * (y - x) = 0
goal:
No subgoals!
[PROOF STEP]
qed |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import analysis.special_functions.exp_log
import data.set.intervals.infinite
import algebra.quadratic_discriminant
import ring_theory.polynomial.chebyshev
import analysis.calculus.times_cont_diff
/-!
# Trigonometric functions
## Main definitions
This file contains the following definitions:
* π, arcsin, arccos, arctan
* argument of a complex number
* logarithm on complex numbers
## Main statements
Many basic inequalities on trigonometric functions are established.
The continuity and differentiability of the usual trigonometric functions are proved, and their
derivatives are computed.
* `polynomial.chebyshev.T_complex_cos`: the `n`-th Chebyshev polynomial evaluates on `complex.cos θ`
to the value `n * complex.cos θ`.
## Tags
log, sin, cos, tan, arcsin, arccos, arctan, angle, argument
-/
noncomputable theory
open_locale classical topological_space filter
open set filter
namespace complex
/-- The complex sine function is everywhere strictly differentiable, with the derivative `cos x`. -/
lemma has_strict_deriv_at_sin (x : ℂ) : has_strict_deriv_at sin (cos x) x :=
begin
simp only [cos, div_eq_mul_inv],
convert ((((has_strict_deriv_at_id x).neg.mul_const I).cexp.sub
((has_strict_deriv_at_id x).mul_const I).cexp).mul_const I).mul_const (2:ℂ)⁻¹,
simp only [function.comp, id],
rw [sub_mul, mul_assoc, mul_assoc, I_mul_I, neg_one_mul, neg_neg, mul_one, one_mul, mul_assoc,
I_mul_I, mul_neg_one, sub_neg_eq_add, add_comm]
end
/-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/
lemma has_deriv_at_sin (x : ℂ) : has_deriv_at sin (cos x) x :=
(has_strict_deriv_at_sin x).has_deriv_at
lemma times_cont_diff_sin {n} : times_cont_diff ℂ n sin :=
(((times_cont_diff_neg.mul times_cont_diff_const).cexp.sub
(times_cont_diff_id.mul times_cont_diff_const).cexp).mul times_cont_diff_const).div_const
lemma differentiable_sin : differentiable ℂ sin :=
λx, (has_deriv_at_sin x).differentiable_at
lemma differentiable_at_sin {x : ℂ} : differentiable_at ℂ sin x :=
differentiable_sin x
@[simp] lemma deriv_sin : deriv sin = cos :=
funext $ λ x, (has_deriv_at_sin x).deriv
@[continuity]
lemma continuous_sin : continuous sin :=
differentiable_sin.continuous
lemma continuous_on_sin {s : set ℂ} : continuous_on sin s := continuous_sin.continuous_on
lemma measurable_sin : measurable sin := continuous_sin.measurable
/-- The complex cosine function is everywhere strictly differentiable, with the derivative
`-sin x`. -/
lemma has_strict_deriv_at_cos (x : ℂ) : has_strict_deriv_at cos (-sin x) x :=
begin
simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul],
convert (((has_strict_deriv_at_id x).mul_const I).cexp.add
((has_strict_deriv_at_id x).neg.mul_const I).cexp).mul_const (2:ℂ)⁻¹,
simp only [function.comp, id],
ring
end
/-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/
lemma has_deriv_at_cos (x : ℂ) : has_deriv_at cos (-sin x) x :=
(has_strict_deriv_at_cos x).has_deriv_at
lemma times_cont_diff_cos {n} : times_cont_diff ℂ n cos :=
((times_cont_diff_id.mul times_cont_diff_const).cexp.add
(times_cont_diff_neg.mul times_cont_diff_const).cexp).div_const
lemma differentiable_cos : differentiable ℂ cos :=
λx, (has_deriv_at_cos x).differentiable_at
lemma differentiable_at_cos {x : ℂ} : differentiable_at ℂ cos x :=
differentiable_cos x
lemma deriv_cos {x : ℂ} : deriv cos x = -sin x :=
(has_deriv_at_cos x).deriv
@[simp] lemma deriv_cos' : deriv cos = (λ x, -sin x) :=
funext $ λ x, deriv_cos
@[continuity]
lemma continuous_cos : continuous cos :=
differentiable_cos.continuous
lemma continuous_on_cos {s : set ℂ} : continuous_on cos s := continuous_cos.continuous_on
lemma measurable_cos : measurable cos := continuous_cos.measurable
/-- The complex hyperbolic sine function is everywhere strictly differentiable, with the derivative
`cosh x`. -/
lemma has_strict_deriv_at_sinh (x : ℂ) : has_strict_deriv_at sinh (cosh x) x :=
begin
simp only [cosh, div_eq_mul_inv],
convert ((has_strict_deriv_at_exp x).sub (has_strict_deriv_at_id x).neg.cexp).mul_const (2:ℂ)⁻¹,
rw [id, mul_neg_one, sub_eq_add_neg, neg_neg]
end
/-- The complex hyperbolic sine function is everywhere differentiable, with the derivative
`cosh x`. -/
lemma has_deriv_at_sinh (x : ℂ) : has_deriv_at sinh (cosh x) x :=
(has_strict_deriv_at_sinh x).has_deriv_at
lemma times_cont_diff_sinh {n} : times_cont_diff ℂ n sinh :=
(times_cont_diff_exp.sub times_cont_diff_neg.cexp).div_const
lemma differentiable_sinh : differentiable ℂ sinh :=
λx, (has_deriv_at_sinh x).differentiable_at
lemma differentiable_at_sinh {x : ℂ} : differentiable_at ℂ sinh x :=
differentiable_sinh x
@[simp] lemma deriv_sinh : deriv sinh = cosh :=
funext $ λ x, (has_deriv_at_sinh x).deriv
@[continuity]
lemma continuous_sinh : continuous sinh :=
differentiable_sinh.continuous
lemma measurable_sinh : measurable sinh := continuous_sinh.measurable
/-- The complex hyperbolic cosine function is everywhere strictly differentiable, with the
derivative `sinh x`. -/
lemma has_strict_deriv_at_cosh (x : ℂ) : has_strict_deriv_at cosh (sinh x) x :=
begin
simp only [sinh, div_eq_mul_inv],
convert ((has_strict_deriv_at_exp x).add (has_strict_deriv_at_id x).neg.cexp).mul_const (2:ℂ)⁻¹,
rw [id, mul_neg_one, sub_eq_add_neg]
end
/-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative
`sinh x`. -/
lemma has_deriv_at_cosh (x : ℂ) : has_deriv_at cosh (sinh x) x :=
(has_strict_deriv_at_cosh x).has_deriv_at
lemma times_cont_diff_cosh {n} : times_cont_diff ℂ n cosh :=
(times_cont_diff_exp.add times_cont_diff_neg.cexp).div_const
lemma differentiable_cosh : differentiable ℂ cosh :=
λx, (has_deriv_at_cosh x).differentiable_at
lemma differentiable_at_cosh {x : ℂ} : differentiable_at ℂ cos x :=
differentiable_cos x
@[simp] lemma deriv_cosh : deriv cosh = sinh :=
funext $ λ x, (has_deriv_at_cosh x).deriv
@[continuity]
lemma continuous_cosh : continuous cosh :=
differentiable_cosh.continuous
lemma measurable_cosh : measurable cosh := continuous_cosh.measurable
end complex
section
/-! ### Simp lemmas for derivatives of `λ x, complex.cos (f x)` etc., `f : ℂ → ℂ` -/
variables {f : ℂ → ℂ} {f' x : ℂ} {s : set ℂ}
/-! #### `complex.cos` -/
lemma measurable.ccos {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) :
measurable (λ x, complex.cos (f x)) :=
complex.measurable_cos.comp hf
lemma has_strict_deriv_at.ccos (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, complex.cos (f x)) (- complex.sin (f x) * f') x :=
(complex.has_strict_deriv_at_cos (f x)).comp x hf
lemma has_deriv_at.ccos (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, complex.cos (f x)) (- complex.sin (f x) * f') x :=
(complex.has_deriv_at_cos (f x)).comp x hf
lemma has_deriv_within_at.ccos (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, complex.cos (f x)) (- complex.sin (f x) * f') s x :=
(complex.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_ccos (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
deriv_within (λx, complex.cos (f x)) s x = - complex.sin (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.ccos.deriv_within hxs
@[simp] lemma deriv_ccos (hc : differentiable_at ℂ f x) :
deriv (λx, complex.cos (f x)) x = - complex.sin (f x) * (deriv f x) :=
hc.has_deriv_at.ccos.deriv
/-! #### `complex.sin` -/
lemma measurable.csin {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) :
measurable (λ x, complex.sin (f x)) :=
complex.measurable_sin.comp hf
lemma has_strict_deriv_at.csin (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, complex.sin (f x)) (complex.cos (f x) * f') x :=
(complex.has_strict_deriv_at_sin (f x)).comp x hf
lemma has_deriv_at.csin (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, complex.sin (f x)) (complex.cos (f x) * f') x :=
(complex.has_deriv_at_sin (f x)).comp x hf
lemma has_deriv_within_at.csin (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, complex.sin (f x)) (complex.cos (f x) * f') s x :=
(complex.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_csin (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
deriv_within (λx, complex.sin (f x)) s x = complex.cos (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.csin.deriv_within hxs
@[simp] lemma deriv_csin (hc : differentiable_at ℂ f x) :
deriv (λx, complex.sin (f x)) x = complex.cos (f x) * (deriv f x) :=
hc.has_deriv_at.csin.deriv
/-! #### `complex.cosh` -/
lemma measurable.ccosh {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) :
measurable (λ x, complex.cosh (f x)) :=
complex.measurable_cosh.comp hf
lemma has_strict_deriv_at.ccosh (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, complex.cosh (f x)) (complex.sinh (f x) * f') x :=
(complex.has_strict_deriv_at_cosh (f x)).comp x hf
lemma has_deriv_at.ccosh (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, complex.cosh (f x)) (complex.sinh (f x) * f') x :=
(complex.has_deriv_at_cosh (f x)).comp x hf
lemma has_deriv_within_at.ccosh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, complex.cosh (f x)) (complex.sinh (f x) * f') s x :=
(complex.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_ccosh (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
deriv_within (λx, complex.cosh (f x)) s x = complex.sinh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.ccosh.deriv_within hxs
@[simp] lemma deriv_ccosh (hc : differentiable_at ℂ f x) :
deriv (λx, complex.cosh (f x)) x = complex.sinh (f x) * (deriv f x) :=
hc.has_deriv_at.ccosh.deriv
/-! #### `complex.sinh` -/
lemma measurable.csinh {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) :
measurable (λ x, complex.sinh (f x)) :=
complex.measurable_sinh.comp hf
lemma has_strict_deriv_at.csinh (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, complex.sinh (f x)) (complex.cosh (f x) * f') x :=
(complex.has_strict_deriv_at_sinh (f x)).comp x hf
lemma has_deriv_at.csinh (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, complex.sinh (f x)) (complex.cosh (f x) * f') x :=
(complex.has_deriv_at_sinh (f x)).comp x hf
lemma has_deriv_within_at.csinh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, complex.sinh (f x)) (complex.cosh (f x) * f') s x :=
(complex.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_csinh (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
deriv_within (λx, complex.sinh (f x)) s x = complex.cosh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.csinh.deriv_within hxs
@[simp] lemma deriv_csinh (hc : differentiable_at ℂ f x) :
deriv (λx, complex.sinh (f x)) x = complex.cosh (f x) * (deriv f x) :=
hc.has_deriv_at.csinh.deriv
end
section
/-! ### Simp lemmas for derivatives of `λ x, complex.cos (f x)` etc., `f : E → ℂ` -/
variables {E : Type*} [normed_group E] [normed_space ℂ E] {f : E → ℂ} {f' : E →L[ℂ] ℂ}
{x : E} {s : set E}
/-! #### `complex.cos` -/
lemma has_strict_fderiv_at.ccos (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, complex.cos (f x)) (- complex.sin (f x) • f') x :=
(complex.has_strict_deriv_at_cos (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.ccos (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, complex.cos (f x)) (- complex.sin (f x) • f') x :=
(complex.has_deriv_at_cos (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.ccos (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, complex.cos (f x)) (- complex.sin (f x) • f') s x :=
(complex.has_deriv_at_cos (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.ccos (hf : differentiable_within_at ℂ f s x) :
differentiable_within_at ℂ (λ x, complex.cos (f x)) s x :=
hf.has_fderiv_within_at.ccos.differentiable_within_at
@[simp] lemma differentiable_at.ccos (hc : differentiable_at ℂ f x) :
differentiable_at ℂ (λx, complex.cos (f x)) x :=
hc.has_fderiv_at.ccos.differentiable_at
lemma differentiable_on.ccos (hc : differentiable_on ℂ f s) :
differentiable_on ℂ (λx, complex.cos (f x)) s :=
λx h, (hc x h).ccos
@[simp] lemma differentiable.ccos (hc : differentiable ℂ f) :
differentiable ℂ (λx, complex.cos (f x)) :=
λx, (hc x).ccos
lemma fderiv_within_ccos (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
fderiv_within ℂ (λx, complex.cos (f x)) s x = - complex.sin (f x) • (fderiv_within ℂ f s x) :=
hf.has_fderiv_within_at.ccos.fderiv_within hxs
@[simp] lemma fderiv_ccos (hc : differentiable_at ℂ f x) :
fderiv ℂ (λx, complex.cos (f x)) x = - complex.sin (f x) • (fderiv ℂ f x) :=
hc.has_fderiv_at.ccos.fderiv
lemma times_cont_diff.ccos {n} (h : times_cont_diff ℂ n f) :
times_cont_diff ℂ n (λ x, complex.cos (f x)) :=
complex.times_cont_diff_cos.comp h
lemma times_cont_diff_at.ccos {n} (hf : times_cont_diff_at ℂ n f x) :
times_cont_diff_at ℂ n (λ x, complex.cos (f x)) x :=
complex.times_cont_diff_cos.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.ccos {n} (hf : times_cont_diff_on ℂ n f s) :
times_cont_diff_on ℂ n (λ x, complex.cos (f x)) s :=
complex.times_cont_diff_cos.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.ccos {n} (hf : times_cont_diff_within_at ℂ n f s x) :
times_cont_diff_within_at ℂ n (λ x, complex.cos (f x)) s x :=
complex.times_cont_diff_cos.times_cont_diff_at.comp_times_cont_diff_within_at x hf
/-! #### `complex.sin` -/
lemma has_strict_fderiv_at.csin (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, complex.sin (f x)) (complex.cos (f x) • f') x :=
(complex.has_strict_deriv_at_sin (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.csin (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, complex.sin (f x)) (complex.cos (f x) • f') x :=
(complex.has_deriv_at_sin (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.csin (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, complex.sin (f x)) (complex.cos (f x) • f') s x :=
(complex.has_deriv_at_sin (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.csin (hf : differentiable_within_at ℂ f s x) :
differentiable_within_at ℂ (λ x, complex.sin (f x)) s x :=
hf.has_fderiv_within_at.csin.differentiable_within_at
@[simp] lemma differentiable_at.csin (hc : differentiable_at ℂ f x) :
differentiable_at ℂ (λx, complex.sin (f x)) x :=
hc.has_fderiv_at.csin.differentiable_at
lemma differentiable_on.csin (hc : differentiable_on ℂ f s) :
differentiable_on ℂ (λx, complex.sin (f x)) s :=
λx h, (hc x h).csin
@[simp] lemma differentiable.csin (hc : differentiable ℂ f) :
differentiable ℂ (λx, complex.sin (f x)) :=
λx, (hc x).csin
lemma fderiv_within_csin (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
fderiv_within ℂ (λx, complex.sin (f x)) s x = complex.cos (f x) • (fderiv_within ℂ f s x) :=
hf.has_fderiv_within_at.csin.fderiv_within hxs
@[simp] lemma fderiv_csin (hc : differentiable_at ℂ f x) :
fderiv ℂ (λx, complex.sin (f x)) x = complex.cos (f x) • (fderiv ℂ f x) :=
hc.has_fderiv_at.csin.fderiv
lemma times_cont_diff.csin {n} (h : times_cont_diff ℂ n f) :
times_cont_diff ℂ n (λ x, complex.sin (f x)) :=
complex.times_cont_diff_sin.comp h
lemma times_cont_diff_at.csin {n} (hf : times_cont_diff_at ℂ n f x) :
times_cont_diff_at ℂ n (λ x, complex.sin (f x)) x :=
complex.times_cont_diff_sin.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.csin {n} (hf : times_cont_diff_on ℂ n f s) :
times_cont_diff_on ℂ n (λ x, complex.sin (f x)) s :=
complex.times_cont_diff_sin.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.csin {n} (hf : times_cont_diff_within_at ℂ n f s x) :
times_cont_diff_within_at ℂ n (λ x, complex.sin (f x)) s x :=
complex.times_cont_diff_sin.times_cont_diff_at.comp_times_cont_diff_within_at x hf
/-! #### `complex.cosh` -/
lemma has_strict_fderiv_at.ccosh (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, complex.cosh (f x)) (complex.sinh (f x) • f') x :=
(complex.has_strict_deriv_at_cosh (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.ccosh (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, complex.cosh (f x)) (complex.sinh (f x) • f') x :=
(complex.has_deriv_at_cosh (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.ccosh (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, complex.cosh (f x)) (complex.sinh (f x) • f') s x :=
(complex.has_deriv_at_cosh (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.ccosh (hf : differentiable_within_at ℂ f s x) :
differentiable_within_at ℂ (λ x, complex.cosh (f x)) s x :=
hf.has_fderiv_within_at.ccosh.differentiable_within_at
@[simp] lemma differentiable_at.ccosh (hc : differentiable_at ℂ f x) :
differentiable_at ℂ (λx, complex.cosh (f x)) x :=
hc.has_fderiv_at.ccosh.differentiable_at
lemma differentiable_on.ccosh (hc : differentiable_on ℂ f s) :
differentiable_on ℂ (λx, complex.cosh (f x)) s :=
λx h, (hc x h).ccosh
@[simp] lemma differentiable.ccosh (hc : differentiable ℂ f) :
differentiable ℂ (λx, complex.cosh (f x)) :=
λx, (hc x).ccosh
lemma fderiv_within_ccosh (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
fderiv_within ℂ (λx, complex.cosh (f x)) s x = complex.sinh (f x) • (fderiv_within ℂ f s x) :=
hf.has_fderiv_within_at.ccosh.fderiv_within hxs
@[simp] lemma fderiv_ccosh (hc : differentiable_at ℂ f x) :
fderiv ℂ (λx, complex.cosh (f x)) x = complex.sinh (f x) • (fderiv ℂ f x) :=
hc.has_fderiv_at.ccosh.fderiv
lemma times_cont_diff.ccosh {n} (h : times_cont_diff ℂ n f) :
times_cont_diff ℂ n (λ x, complex.cosh (f x)) :=
complex.times_cont_diff_cosh.comp h
lemma times_cont_diff_at.ccosh {n} (hf : times_cont_diff_at ℂ n f x) :
times_cont_diff_at ℂ n (λ x, complex.cosh (f x)) x :=
complex.times_cont_diff_cosh.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.ccosh {n} (hf : times_cont_diff_on ℂ n f s) :
times_cont_diff_on ℂ n (λ x, complex.cosh (f x)) s :=
complex.times_cont_diff_cosh.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.ccosh {n} (hf : times_cont_diff_within_at ℂ n f s x) :
times_cont_diff_within_at ℂ n (λ x, complex.cosh (f x)) s x :=
complex.times_cont_diff_cosh.times_cont_diff_at.comp_times_cont_diff_within_at x hf
/-! #### `complex.sinh` -/
lemma has_strict_fderiv_at.csinh (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, complex.sinh (f x)) (complex.cosh (f x) • f') x :=
(complex.has_strict_deriv_at_sinh (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.csinh (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, complex.sinh (f x)) (complex.cosh (f x) • f') x :=
(complex.has_deriv_at_sinh (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.csinh (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, complex.sinh (f x)) (complex.cosh (f x) • f') s x :=
(complex.has_deriv_at_sinh (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.csinh (hf : differentiable_within_at ℂ f s x) :
differentiable_within_at ℂ (λ x, complex.sinh (f x)) s x :=
hf.has_fderiv_within_at.csinh.differentiable_within_at
@[simp] lemma differentiable_at.csinh (hc : differentiable_at ℂ f x) :
differentiable_at ℂ (λx, complex.sinh (f x)) x :=
hc.has_fderiv_at.csinh.differentiable_at
lemma differentiable_on.csinh (hc : differentiable_on ℂ f s) :
differentiable_on ℂ (λx, complex.sinh (f x)) s :=
λx h, (hc x h).csinh
@[simp] lemma differentiable.csinh (hc : differentiable ℂ f) :
differentiable ℂ (λx, complex.sinh (f x)) :=
λx, (hc x).csinh
lemma fderiv_within_csinh (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
fderiv_within ℂ (λx, complex.sinh (f x)) s x = complex.cosh (f x) • (fderiv_within ℂ f s x) :=
hf.has_fderiv_within_at.csinh.fderiv_within hxs
@[simp] lemma fderiv_csinh (hc : differentiable_at ℂ f x) :
fderiv ℂ (λx, complex.sinh (f x)) x = complex.cosh (f x) • (fderiv ℂ f x) :=
hc.has_fderiv_at.csinh.fderiv
lemma times_cont_diff.csinh {n} (h : times_cont_diff ℂ n f) :
times_cont_diff ℂ n (λ x, complex.sinh (f x)) :=
complex.times_cont_diff_sinh.comp h
lemma times_cont_diff_at.csinh {n} (hf : times_cont_diff_at ℂ n f x) :
times_cont_diff_at ℂ n (λ x, complex.sinh (f x)) x :=
complex.times_cont_diff_sinh.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.csinh {n} (hf : times_cont_diff_on ℂ n f s) :
times_cont_diff_on ℂ n (λ x, complex.sinh (f x)) s :=
complex.times_cont_diff_sinh.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.csinh {n} (hf : times_cont_diff_within_at ℂ n f s x) :
times_cont_diff_within_at ℂ n (λ x, complex.sinh (f x)) s x :=
complex.times_cont_diff_sinh.times_cont_diff_at.comp_times_cont_diff_within_at x hf
end
namespace real
variables {x y z : ℝ}
lemma has_strict_deriv_at_sin (x : ℝ) : has_strict_deriv_at sin (cos x) x :=
(complex.has_strict_deriv_at_sin x).real_of_complex
lemma has_deriv_at_sin (x : ℝ) : has_deriv_at sin (cos x) x :=
(has_strict_deriv_at_sin x).has_deriv_at
lemma times_cont_diff_sin {n} : times_cont_diff ℝ n sin :=
complex.times_cont_diff_sin.real_of_complex
lemma differentiable_sin : differentiable ℝ sin :=
λx, (has_deriv_at_sin x).differentiable_at
lemma differentiable_at_sin : differentiable_at ℝ sin x :=
differentiable_sin x
@[simp] lemma deriv_sin : deriv sin = cos :=
funext $ λ x, (has_deriv_at_sin x).deriv
@[continuity]
lemma continuous_sin : continuous sin :=
differentiable_sin.continuous
lemma continuous_on_sin {s} : continuous_on sin s :=
continuous_sin.continuous_on
lemma measurable_sin : measurable sin := continuous_sin.measurable
lemma has_strict_deriv_at_cos (x : ℝ) : has_strict_deriv_at cos (-sin x) x :=
(complex.has_strict_deriv_at_cos x).real_of_complex
lemma has_deriv_at_cos (x : ℝ) : has_deriv_at cos (-sin x) x :=
(complex.has_deriv_at_cos x).real_of_complex
lemma times_cont_diff_cos {n} : times_cont_diff ℝ n cos :=
complex.times_cont_diff_cos.real_of_complex
lemma differentiable_cos : differentiable ℝ cos :=
λx, (has_deriv_at_cos x).differentiable_at
lemma differentiable_at_cos : differentiable_at ℝ cos x :=
differentiable_cos x
lemma deriv_cos : deriv cos x = - sin x :=
(has_deriv_at_cos x).deriv
@[simp] lemma deriv_cos' : deriv cos = (λ x, - sin x) :=
funext $ λ _, deriv_cos
@[continuity]
lemma continuous_cos : continuous cos :=
differentiable_cos.continuous
lemma continuous_on_cos {s} : continuous_on cos s := continuous_cos.continuous_on
lemma measurable_cos : measurable cos := continuous_cos.measurable
lemma has_strict_deriv_at_sinh (x : ℝ) : has_strict_deriv_at sinh (cosh x) x :=
(complex.has_strict_deriv_at_sinh x).real_of_complex
lemma has_deriv_at_sinh (x : ℝ) : has_deriv_at sinh (cosh x) x :=
(complex.has_deriv_at_sinh x).real_of_complex
lemma times_cont_diff_sinh {n} : times_cont_diff ℝ n sinh :=
complex.times_cont_diff_sinh.real_of_complex
lemma differentiable_sinh : differentiable ℝ sinh :=
λx, (has_deriv_at_sinh x).differentiable_at
lemma differentiable_at_sinh : differentiable_at ℝ sinh x :=
differentiable_sinh x
@[simp] lemma deriv_sinh : deriv sinh = cosh :=
funext $ λ x, (has_deriv_at_sinh x).deriv
@[continuity]
lemma continuous_sinh : continuous sinh :=
differentiable_sinh.continuous
lemma measurable_sinh : measurable sinh := continuous_sinh.measurable
lemma has_strict_deriv_at_cosh (x : ℝ) : has_strict_deriv_at cosh (sinh x) x :=
(complex.has_strict_deriv_at_cosh x).real_of_complex
lemma has_deriv_at_cosh (x : ℝ) : has_deriv_at cosh (sinh x) x :=
(complex.has_deriv_at_cosh x).real_of_complex
lemma times_cont_diff_cosh {n} : times_cont_diff ℝ n cosh :=
complex.times_cont_diff_cosh.real_of_complex
lemma differentiable_cosh : differentiable ℝ cosh :=
λx, (has_deriv_at_cosh x).differentiable_at
lemma differentiable_at_cosh : differentiable_at ℝ cosh x :=
differentiable_cosh x
@[simp] lemma deriv_cosh : deriv cosh = sinh :=
funext $ λ x, (has_deriv_at_cosh x).deriv
@[continuity]
lemma continuous_cosh : continuous cosh :=
differentiable_cosh.continuous
lemma measurable_cosh : measurable cosh := continuous_cosh.measurable
/-- `sinh` is strictly monotone. -/
lemma sinh_strict_mono : strict_mono sinh :=
strict_mono_of_deriv_pos differentiable_sinh (by { rw [real.deriv_sinh], exact cosh_pos })
end real
section
/-! ### Simp lemmas for derivatives of `λ x, real.cos (f x)` etc., `f : ℝ → ℝ` -/
variables {f : ℝ → ℝ} {f' x : ℝ} {s : set ℝ}
/-! #### `real.cos` -/
lemma measurable.cos {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, real.cos (f x)) :=
real.measurable_cos.comp hf
lemma has_strict_deriv_at.cos (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, real.cos (f x)) (- real.sin (f x) * f') x :=
(real.has_strict_deriv_at_cos (f x)).comp x hf
lemma has_deriv_at.cos (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.cos (f x)) (- real.sin (f x) * f') x :=
(real.has_deriv_at_cos (f x)).comp x hf
lemma has_deriv_within_at.cos (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.cos (f x)) (- real.sin (f x) * f') s x :=
(real.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_cos (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, real.cos (f x)) s x = - real.sin (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.cos.deriv_within hxs
@[simp] lemma deriv_cos (hc : differentiable_at ℝ f x) :
deriv (λx, real.cos (f x)) x = - real.sin (f x) * (deriv f x) :=
hc.has_deriv_at.cos.deriv
/-! #### `real.sin` -/
lemma measurable.sin {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, real.sin (f x)) :=
real.measurable_sin.comp hf
lemma has_strict_deriv_at.sin (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, real.sin (f x)) (real.cos (f x) * f') x :=
(real.has_strict_deriv_at_sin (f x)).comp x hf
lemma has_deriv_at.sin (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.sin (f x)) (real.cos (f x) * f') x :=
(real.has_deriv_at_sin (f x)).comp x hf
lemma has_deriv_within_at.sin (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.sin (f x)) (real.cos (f x) * f') s x :=
(real.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_sin (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, real.sin (f x)) s x = real.cos (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.sin.deriv_within hxs
@[simp] lemma deriv_sin (hc : differentiable_at ℝ f x) :
deriv (λx, real.sin (f x)) x = real.cos (f x) * (deriv f x) :=
hc.has_deriv_at.sin.deriv
/-! #### `real.cosh` -/
lemma measurable.cosh {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, real.cosh (f x)) :=
real.measurable_cosh.comp hf
lemma has_strict_deriv_at.cosh (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, real.cosh (f x)) (real.sinh (f x) * f') x :=
(real.has_strict_deriv_at_cosh (f x)).comp x hf
lemma has_deriv_at.cosh (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.cosh (f x)) (real.sinh (f x) * f') x :=
(real.has_deriv_at_cosh (f x)).comp x hf
lemma has_deriv_within_at.cosh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.cosh (f x)) (real.sinh (f x) * f') s x :=
(real.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_cosh (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, real.cosh (f x)) s x = real.sinh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.cosh.deriv_within hxs
@[simp] lemma deriv_cosh (hc : differentiable_at ℝ f x) :
deriv (λx, real.cosh (f x)) x = real.sinh (f x) * (deriv f x) :=
hc.has_deriv_at.cosh.deriv
/-! #### `real.sinh` -/
lemma measurable.sinh {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, real.sinh (f x)) :=
real.measurable_sinh.comp hf
lemma has_strict_deriv_at.sinh (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, real.sinh (f x)) (real.cosh (f x) * f') x :=
(real.has_strict_deriv_at_sinh (f x)).comp x hf
lemma has_deriv_at.sinh (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.sinh (f x)) (real.cosh (f x) * f') x :=
(real.has_deriv_at_sinh (f x)).comp x hf
lemma has_deriv_within_at.sinh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.sinh (f x)) (real.cosh (f x) * f') s x :=
(real.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_sinh (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, real.sinh (f x)) s x = real.cosh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.sinh.deriv_within hxs
@[simp] lemma deriv_sinh (hc : differentiable_at ℝ f x) :
deriv (λx, real.sinh (f x)) x = real.cosh (f x) * (deriv f x) :=
hc.has_deriv_at.sinh.deriv
end
section
/-! ### Simp lemmas for derivatives of `λ x, real.cos (f x)` etc., `f : E → ℝ` -/
variables {E : Type*} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {f' : E →L[ℝ] ℝ}
{x : E} {s : set E}
/-! #### `real.cos` -/
lemma has_strict_fderiv_at.cos (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, real.cos (f x)) (- real.sin (f x) • f') x :=
(real.has_strict_deriv_at_cos (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.cos (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, real.cos (f x)) (- real.sin (f x) • f') x :=
(real.has_deriv_at_cos (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.cos (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, real.cos (f x)) (- real.sin (f x) • f') s x :=
(real.has_deriv_at_cos (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.cos (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.cos (f x)) s x :=
hf.has_fderiv_within_at.cos.differentiable_within_at
@[simp] lemma differentiable_at.cos (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λx, real.cos (f x)) x :=
hc.has_fderiv_at.cos.differentiable_at
lemma differentiable_on.cos (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λx, real.cos (f x)) s :=
λx h, (hc x h).cos
@[simp] lemma differentiable.cos (hc : differentiable ℝ f) :
differentiable ℝ (λx, real.cos (f x)) :=
λx, (hc x).cos
lemma fderiv_within_cos (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
fderiv_within ℝ (λx, real.cos (f x)) s x = - real.sin (f x) • (fderiv_within ℝ f s x) :=
hf.has_fderiv_within_at.cos.fderiv_within hxs
@[simp] lemma fderiv_cos (hc : differentiable_at ℝ f x) :
fderiv ℝ (λx, real.cos (f x)) x = - real.sin (f x) • (fderiv ℝ f x) :=
hc.has_fderiv_at.cos.fderiv
lemma times_cont_diff.cos {n} (h : times_cont_diff ℝ n f) :
times_cont_diff ℝ n (λ x, real.cos (f x)) :=
real.times_cont_diff_cos.comp h
lemma times_cont_diff_at.cos {n} (hf : times_cont_diff_at ℝ n f x) :
times_cont_diff_at ℝ n (λ x, real.cos (f x)) x :=
real.times_cont_diff_cos.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.cos {n} (hf : times_cont_diff_on ℝ n f s) :
times_cont_diff_on ℝ n (λ x, real.cos (f x)) s :=
real.times_cont_diff_cos.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.cos {n} (hf : times_cont_diff_within_at ℝ n f s x) :
times_cont_diff_within_at ℝ n (λ x, real.cos (f x)) s x :=
real.times_cont_diff_cos.times_cont_diff_at.comp_times_cont_diff_within_at x hf
/-! #### `real.sin` -/
lemma has_strict_fderiv_at.sin (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, real.sin (f x)) (real.cos (f x) • f') x :=
(real.has_strict_deriv_at_sin (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.sin (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, real.sin (f x)) (real.cos (f x) • f') x :=
(real.has_deriv_at_sin (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.sin (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, real.sin (f x)) (real.cos (f x) • f') s x :=
(real.has_deriv_at_sin (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.sin (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.sin (f x)) s x :=
hf.has_fderiv_within_at.sin.differentiable_within_at
@[simp] lemma differentiable_at.sin (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λx, real.sin (f x)) x :=
hc.has_fderiv_at.sin.differentiable_at
lemma differentiable_on.sin (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λx, real.sin (f x)) s :=
λx h, (hc x h).sin
@[simp] lemma differentiable.sin (hc : differentiable ℝ f) :
differentiable ℝ (λx, real.sin (f x)) :=
λx, (hc x).sin
lemma fderiv_within_sin (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
fderiv_within ℝ (λx, real.sin (f x)) s x = real.cos (f x) • (fderiv_within ℝ f s x) :=
hf.has_fderiv_within_at.sin.fderiv_within hxs
@[simp] lemma fderiv_sin (hc : differentiable_at ℝ f x) :
fderiv ℝ (λx, real.sin (f x)) x = real.cos (f x) • (fderiv ℝ f x) :=
hc.has_fderiv_at.sin.fderiv
lemma times_cont_diff.sin {n} (h : times_cont_diff ℝ n f) :
times_cont_diff ℝ n (λ x, real.sin (f x)) :=
real.times_cont_diff_sin.comp h
lemma times_cont_diff_at.sin {n} (hf : times_cont_diff_at ℝ n f x) :
times_cont_diff_at ℝ n (λ x, real.sin (f x)) x :=
real.times_cont_diff_sin.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.sin {n} (hf : times_cont_diff_on ℝ n f s) :
times_cont_diff_on ℝ n (λ x, real.sin (f x)) s :=
real.times_cont_diff_sin.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.sin {n} (hf : times_cont_diff_within_at ℝ n f s x) :
times_cont_diff_within_at ℝ n (λ x, real.sin (f x)) s x :=
real.times_cont_diff_sin.times_cont_diff_at.comp_times_cont_diff_within_at x hf
/-! #### `real.cosh` -/
lemma has_strict_fderiv_at.cosh (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, real.cosh (f x)) (real.sinh (f x) • f') x :=
(real.has_strict_deriv_at_cosh (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.cosh (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, real.cosh (f x)) (real.sinh (f x) • f') x :=
(real.has_deriv_at_cosh (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.cosh (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, real.cosh (f x)) (real.sinh (f x) • f') s x :=
(real.has_deriv_at_cosh (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.cosh (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.cosh (f x)) s x :=
hf.has_fderiv_within_at.cosh.differentiable_within_at
@[simp] lemma differentiable_at.cosh (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λx, real.cosh (f x)) x :=
hc.has_fderiv_at.cosh.differentiable_at
lemma differentiable_on.cosh (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λx, real.cosh (f x)) s :=
λx h, (hc x h).cosh
@[simp] lemma differentiable.cosh (hc : differentiable ℝ f) :
differentiable ℝ (λx, real.cosh (f x)) :=
λx, (hc x).cosh
lemma fderiv_within_cosh (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
fderiv_within ℝ (λx, real.cosh (f x)) s x = real.sinh (f x) • (fderiv_within ℝ f s x) :=
hf.has_fderiv_within_at.cosh.fderiv_within hxs
@[simp] lemma fderiv_cosh (hc : differentiable_at ℝ f x) :
fderiv ℝ (λx, real.cosh (f x)) x = real.sinh (f x) • (fderiv ℝ f x) :=
hc.has_fderiv_at.cosh.fderiv
lemma times_cont_diff.cosh {n} (h : times_cont_diff ℝ n f) :
times_cont_diff ℝ n (λ x, real.cosh (f x)) :=
real.times_cont_diff_cosh.comp h
lemma times_cont_diff_at.cosh {n} (hf : times_cont_diff_at ℝ n f x) :
times_cont_diff_at ℝ n (λ x, real.cosh (f x)) x :=
real.times_cont_diff_cosh.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.cosh {n} (hf : times_cont_diff_on ℝ n f s) :
times_cont_diff_on ℝ n (λ x, real.cosh (f x)) s :=
real.times_cont_diff_cosh.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.cosh {n} (hf : times_cont_diff_within_at ℝ n f s x) :
times_cont_diff_within_at ℝ n (λ x, real.cosh (f x)) s x :=
real.times_cont_diff_cosh.times_cont_diff_at.comp_times_cont_diff_within_at x hf
/-! #### `real.sinh` -/
lemma has_strict_fderiv_at.sinh (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, real.sinh (f x)) (real.cosh (f x) • f') x :=
(real.has_strict_deriv_at_sinh (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.sinh (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, real.sinh (f x)) (real.cosh (f x) • f') x :=
(real.has_deriv_at_sinh (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.sinh (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, real.sinh (f x)) (real.cosh (f x) • f') s x :=
(real.has_deriv_at_sinh (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.sinh (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.sinh (f x)) s x :=
hf.has_fderiv_within_at.sinh.differentiable_within_at
@[simp] lemma differentiable_at.sinh (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λx, real.sinh (f x)) x :=
hc.has_fderiv_at.sinh.differentiable_at
lemma differentiable_on.sinh (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λx, real.sinh (f x)) s :=
λx h, (hc x h).sinh
@[simp] lemma differentiable.sinh (hc : differentiable ℝ f) :
differentiable ℝ (λx, real.sinh (f x)) :=
λx, (hc x).sinh
lemma fderiv_within_sinh (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
fderiv_within ℝ (λx, real.sinh (f x)) s x = real.cosh (f x) • (fderiv_within ℝ f s x) :=
hf.has_fderiv_within_at.sinh.fderiv_within hxs
@[simp] lemma fderiv_sinh (hc : differentiable_at ℝ f x) :
fderiv ℝ (λx, real.sinh (f x)) x = real.cosh (f x) • (fderiv ℝ f x) :=
hc.has_fderiv_at.sinh.fderiv
lemma times_cont_diff.sinh {n} (h : times_cont_diff ℝ n f) :
times_cont_diff ℝ n (λ x, real.sinh (f x)) :=
real.times_cont_diff_sinh.comp h
lemma times_cont_diff_at.sinh {n} (hf : times_cont_diff_at ℝ n f x) :
times_cont_diff_at ℝ n (λ x, real.sinh (f x)) x :=
real.times_cont_diff_sinh.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.sinh {n} (hf : times_cont_diff_on ℝ n f s) :
times_cont_diff_on ℝ n (λ x, real.sinh (f x)) s :=
real.times_cont_diff_sinh.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.sinh {n} (hf : times_cont_diff_within_at ℝ n f s x) :
times_cont_diff_within_at ℝ n (λ x, real.sinh (f x)) s x :=
real.times_cont_diff_sinh.times_cont_diff_at.comp_times_cont_diff_within_at x hf
end
namespace real
lemma exists_cos_eq_zero : 0 ∈ cos '' Icc (1:ℝ) 2 :=
intermediate_value_Icc' (by norm_num) continuous_on_cos
⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩
/-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from
which one can derive all its properties. For explicit bounds on π, see `data.real.pi`. -/
protected noncomputable def pi : ℝ := 2 * classical.some exists_cos_eq_zero
localized "notation `π` := real.pi" in real
@[simp] lemma cos_pi_div_two : cos (π / 2) = 0 :=
by rw [real.pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)];
exact (classical.some_spec exists_cos_eq_zero).2
lemma one_le_pi_div_two : (1 : ℝ) ≤ π / 2 :=
by rw [real.pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)];
exact (classical.some_spec exists_cos_eq_zero).1.1
lemma pi_div_two_le_two : π / 2 ≤ 2 :=
by rw [real.pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)];
exact (classical.some_spec exists_cos_eq_zero).1.2
lemma two_le_pi : (2 : ℝ) ≤ π :=
(div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1
(by rw div_self (@two_ne_zero' ℝ _ _ _); exact one_le_pi_div_two)
lemma pi_le_four : π ≤ 4 :=
(div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1
(calc π / 2 ≤ 2 : pi_div_two_le_two
... = 4 / 2 : by norm_num)
lemma pi_pos : 0 < π :=
lt_of_lt_of_le (by norm_num) two_le_pi
lemma pi_ne_zero : π ≠ 0 :=
ne_of_gt pi_pos
lemma pi_div_two_pos : 0 < π / 2 :=
half_pos pi_pos
lemma two_pi_pos : 0 < 2 * π :=
by linarith [pi_pos]
end real
namespace nnreal
open real
open_locale real nnreal
/-- `π` considered as a nonnegative real. -/
noncomputable def pi : ℝ≥0 := ⟨π, real.pi_pos.le⟩
@[simp] lemma coe_real_pi : (pi : ℝ) = π := rfl
lemma pi_pos : 0 < pi := by exact_mod_cast real.pi_pos
lemma pi_ne_zero : pi ≠ 0 := pi_pos.ne'
end nnreal
namespace real
open_locale real
@[simp] lemma sin_pi : sin π = 0 :=
by rw [← mul_div_cancel_left π (@two_ne_zero ℝ _ _), two_mul, add_div,
sin_add, cos_pi_div_two]; simp
@[simp] lemma cos_pi : cos π = -1 :=
by rw [← mul_div_cancel_left π (@two_ne_zero ℝ _ _), mul_div_assoc,
cos_two_mul, cos_pi_div_two];
simp [bit0, pow_add]
@[simp] lemma sin_two_pi : sin (2 * π) = 0 :=
by simp [two_mul, sin_add]
@[simp] lemma cos_two_pi : cos (2 * π) = 1 :=
by simp [two_mul, cos_add]
lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
by induction n; simp [add_mul, sin_add, *]
lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
by cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi]
lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
by induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi]
lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
by cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe, int.neg_succ_of_nat_coe,
int.cast_coe_nat, int.cast_neg, ← neg_mul_eq_neg_mul, cos_neg]
lemma sin_add_pi (x : ℝ) : sin (x + π) = -sin x :=
by simp [sin_add]
lemma sin_add_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x + n * (2 * π)) = sin x :=
begin
rw [sin_add, cos_int_mul_two_pi, ← mul_assoc],
rw_mod_cast sin_int_mul_pi (n*2),
simp,
end
lemma sin_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x - n * (2 * π)) = sin x :=
by simpa using sin_add_int_mul_two_pi x (-n)
lemma sin_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x + n * (2 * π)) = sin x :=
by convert sin_add_int_mul_two_pi x n
lemma sin_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x - n * (2 * π)) = sin x :=
by convert sin_sub_int_mul_two_pi x n
lemma sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x :=
by simp [sin_add]
lemma sin_sub_two_pi (x : ℝ) : sin (x - 2 * π) = sin x :=
by simp [sin_sub]
lemma cos_add_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x + n * (2 * π)) = cos x :=
begin
rw [cos_add, cos_int_mul_two_pi, ← mul_assoc],
rw_mod_cast sin_int_mul_pi (n*2),
simp,
end
lemma cos_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x - n * (2 * π)) = cos x :=
by simpa using cos_add_int_mul_two_pi x (-n)
lemma cos_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x + n * (2 * π)) = cos x :=
by convert cos_add_int_mul_two_pi x n
lemma cos_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x - n * (2 * π)) = cos x :=
by convert cos_sub_int_mul_two_pi x n
lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 :=
by simp [add_comm, cos_add_int_mul_two_pi]
lemma cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 :=
by simp [sub_eq_neg_add, cos_add_int_mul_two_pi]
lemma cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 :=
by convert cos_int_mul_two_pi_add_pi n
lemma cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 :=
by convert cos_int_mul_two_pi_sub_pi n
lemma cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x :=
by simp [cos_add]
lemma cos_sub_two_pi (x : ℝ) : cos (x - 2 * π) = cos x :=
by simp [cos_sub]
lemma sin_pi_sub (x : ℝ) : sin (π - x) = sin x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi (x : ℝ) : cos (x + π) = -cos x :=
by simp [cos_add]
lemma cos_sub_pi (x : ℝ) : cos (x - π) = -cos x :=
by simp [cos_sub]
lemma cos_pi_sub (x : ℝ) : cos (π - x) = -cos x :=
by simp [cos_sub]
lemma sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x :=
if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2
else
have (2 : ℝ) + 2 = 4, from rfl,
have π - x ≤ 2, from sub_le_iff_le_add.2
(le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _)),
sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this
lemma sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x :=
sin_pos_of_pos_of_lt_pi hx.1 hx.2
lemma sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≤ sin x :=
begin
rw ← closure_Ioo pi_pos at hx,
exact closure_lt_subset_le continuous_const continuous_sin
(closure_mono (λ y, sin_pos_of_mem_Ioo) hx)
end
lemma sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x :=
sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩
lemma sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 :=
neg_pos.1 $ sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx)
lemma sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 :=
neg_nonneg.1 $ sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx)
@[simp] lemma sin_pi_div_two : sin (π / 2) = 1 :=
have sin (π / 2) = 1 ∨ sin (π / 2) = -1 :=
by simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2),
this.resolve_right
(λ h, (show ¬(0 : ℝ) < -1, by norm_num) $
h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos))
lemma sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x :=
by simp [sin_add]
lemma sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x :=
by simp [cos_add]
lemma cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x :=
by simp [sub_eq_add_neg, cos_add]
lemma cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x :=
by rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
lemma cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : 0 < cos x :=
sin_add_pi_div_two x ▸ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩
lemma cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : 0 ≤ cos x :=
sin_add_pi_div_two x ▸ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩
lemma cos_nonneg_of_neg_pi_div_two_le_of_le {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) :
0 ≤ cos x :=
cos_nonneg_of_mem_Icc ⟨hl, hu⟩
lemma cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) : cos x < 0 :=
neg_pos.1 $ cos_pi_sub x ▸ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩
lemma cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) :
cos x ≤ 0 :=
neg_nonneg.1 $ cos_pi_sub x ▸ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩
lemma sin_eq_sqrt_one_sub_cos_sq {x : ℝ} (hl : 0 ≤ x) (hu : x ≤ π) :
sin x = sqrt (1 - cos x ^ 2) :=
by rw [← abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)]
lemma cos_eq_sqrt_one_sub_sin_sq {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) :
cos x = sqrt (1 - sin x ^ 2) :=
by rw [← abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨hl, hu⟩)]
lemma sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) :
sin x = 0 ↔ x = 0 :=
⟨λ h, le_antisymm
(le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $
calc 0 < sin x : sin_pos_of_pos_of_lt_pi h0 hx₂
... = 0 : h))
(le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $
calc 0 = sin x : h.symm
... < 0 : sin_neg_of_neg_of_neg_pi_lt h0 hx₁)),
λ h, by simp [h]⟩
lemma sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x :=
⟨λ h, ⟨⌊x / π⌋, le_antisymm (sub_nonneg.1 (sub_floor_div_mul_nonneg _ pi_pos))
(sub_nonpos.1 $ le_of_not_gt $ λ h₃,
(sin_pos_of_pos_of_lt_pi h₃ (sub_floor_div_mul_lt _ pi_pos)).ne
(by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩,
λ ⟨n, hn⟩, hn ▸ sin_int_mul_pi _⟩
lemma sin_ne_zero_iff {x : ℝ} : sin x ≠ 0 ↔ ∀ n : ℤ, (n : ℝ) * π ≠ x :=
by rw [← not_exists, not_iff_not, sin_eq_zero_iff]
lemma sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 :=
by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x,
sq, sq, ← sub_eq_iff_eq_add, sub_self];
exact ⟨λ h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ eq.symm⟩
lemma cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x :=
⟨λ h, let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (or.inl h)) in
⟨n / 2, (int.mod_two_eq_zero_or_one n).elim
(λ hn0, by rwa [← mul_assoc, ← @int.cast_two ℝ, ← int.cast_mul, int.div_mul_cancel
((int.dvd_iff_mod_eq_zero _ _).2 hn0)])
(λ hn1, by rw [← int.mod_add_div n 2, hn1, int.cast_add, int.cast_one, add_mul,
one_mul, add_comm, mul_comm (2 : ℤ), int.cast_mul, mul_assoc, int.cast_two] at hn;
rw [← hn, cos_int_mul_two_pi_add_pi] at h;
exact absurd h (by norm_num))⟩,
λ ⟨n, hn⟩, hn ▸ cos_int_mul_two_pi _⟩
lemma cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) :
cos x = 1 ↔ x = 0 :=
⟨λ h,
begin
rcases (cos_eq_one_iff _).1 h with ⟨n, rfl⟩,
rw [mul_lt_iff_lt_one_left two_pi_pos] at hx₂,
rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁,
norm_cast at hx₁ hx₂,
obtain rfl : n = 0 := le_antisymm (by linarith) (by linarith),
simp
end,
λ h, by simp [h]⟩
lemma cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2)
(hxy : x < y) :
cos y < cos x :=
begin
rw [← sub_lt_zero, cos_sub_cos],
have : 0 < sin ((y + x) / 2),
{ refine sin_pos_of_pos_of_lt_pi _ _; linarith },
have : 0 < sin ((y - x) / 2),
{ refine sin_pos_of_pos_of_lt_pi _ _; linarith },
nlinarith,
end
lemma cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) :
cos y < cos x :=
match (le_total x (π / 2) : x ≤ π / 2 ∨ π / 2 ≤ x), le_total y (π / 2) with
| or.inl hx, or.inl hy := cos_lt_cos_of_nonneg_of_le_pi_div_two hx₁ hy hxy
| or.inl hx, or.inr hy := (lt_or_eq_of_le hx).elim
(λ hx, calc cos y ≤ 0 : cos_nonpos_of_pi_div_two_le_of_le hy (by linarith [pi_pos])
... < cos x : cos_pos_of_mem_Ioo ⟨by linarith, hx⟩)
(λ hx, calc cos y < 0 : cos_neg_of_pi_div_two_lt_of_lt (by linarith) (by linarith [pi_pos])
... = cos x : by rw [hx, cos_pi_div_two])
| or.inr hx, or.inl hy := by linarith
| or.inr hx, or.inr hy := neg_lt_neg_iff.1 (by rw [← cos_pi_sub, ← cos_pi_sub];
apply cos_lt_cos_of_nonneg_of_le_pi_div_two; linarith)
end
lemma strict_mono_decr_on_cos : strict_mono_decr_on cos (Icc 0 π) :=
λ x hx y hy hxy, cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy
lemma cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x ≤ y) :
cos y ≤ cos x :=
(strict_mono_decr_on_cos.le_iff_le ⟨hx₁.trans hxy, hy₂⟩ ⟨hx₁, hxy.trans hy₂⟩).2 hxy
lemma sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x)
(hy₂ : y ≤ π / 2) (hxy : x < y) : sin x < sin y :=
by rw [← cos_sub_pi_div_two, ← cos_sub_pi_div_two, ← cos_neg (x - _), ← cos_neg (y - _)];
apply cos_lt_cos_of_nonneg_of_le_pi; linarith
lemma strict_mono_incr_on_sin : strict_mono_incr_on sin (Icc (-(π / 2)) (π / 2)) :=
λ x hx y hy hxy, sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy
lemma sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x)
(hy₂ : y ≤ π / 2) (hxy : x ≤ y) : sin x ≤ sin y :=
(strict_mono_incr_on_sin.le_iff_le ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩).2 hxy
lemma inj_on_sin : inj_on sin (Icc (-(π / 2)) (π / 2)) :=
strict_mono_incr_on_sin.inj_on
lemma inj_on_cos : inj_on cos (Icc 0 π) := strict_mono_decr_on_cos.inj_on
lemma surj_on_sin : surj_on sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) :=
by simpa only [sin_neg, sin_pi_div_two]
using intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuous_on
lemma surj_on_cos : surj_on cos (Icc 0 π) (Icc (-1) 1) :=
by simpa only [cos_zero, cos_pi]
using intermediate_value_Icc' pi_pos.le continuous_cos.continuous_on
lemma sin_mem_Icc (x : ℝ) : sin x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_sin x, sin_le_one x⟩
lemma cos_mem_Icc (x : ℝ) : cos x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_cos x, cos_le_one x⟩
lemma maps_to_sin (s : set ℝ) : maps_to sin s (Icc (-1 : ℝ) 1) := λ x _, sin_mem_Icc x
lemma maps_to_cos (s : set ℝ) : maps_to cos s (Icc (-1 : ℝ) 1) := λ x _, cos_mem_Icc x
lemma bij_on_sin : bij_on sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) :=
⟨maps_to_sin _, inj_on_sin, surj_on_sin⟩
lemma bij_on_cos : bij_on cos (Icc 0 π) (Icc (-1) 1) :=
⟨maps_to_cos _, inj_on_cos, surj_on_cos⟩
@[simp] lemma range_cos : range cos = (Icc (-1) 1 : set ℝ) :=
subset.antisymm (range_subset_iff.2 cos_mem_Icc) surj_on_cos.subset_range
@[simp] lemma range_sin : range sin = (Icc (-1) 1 : set ℝ) :=
subset.antisymm (range_subset_iff.2 sin_mem_Icc) surj_on_sin.subset_range
lemma range_cos_infinite : (range real.cos).infinite :=
by { rw real.range_cos, exact Icc.infinite (by norm_num) }
lemma range_sin_infinite : (range real.sin).infinite :=
by { rw real.range_sin, exact Icc.infinite (by norm_num) }
lemma sin_lt {x : ℝ} (h : 0 < x) : sin x < x :=
begin
cases le_or_gt x 1 with h' h',
{ have hx : abs x = x := abs_of_nonneg (le_of_lt h),
have : abs x ≤ 1, rwa [hx],
have := sin_bound this, rw [abs_le] at this,
have := this.2, rw [sub_le_iff_le_add', hx] at this,
apply lt_of_le_of_lt this, rw [sub_add], apply lt_of_lt_of_le _ (le_of_eq (sub_zero x)),
apply sub_lt_sub_left, rw [sub_pos, div_eq_mul_inv (x ^ 3)], apply mul_lt_mul',
{ rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)),
rw mul_le_mul_right, exact h', apply pow_pos h },
norm_num, norm_num, apply pow_pos h },
exact lt_of_le_of_lt (sin_le_one x) h'
end
/- note 1: this inequality is not tight, the tighter inequality is sin x > x - x ^ 3 / 6.
note 2: this is also true for x > 1, but it's nontrivial for x just above 1. -/
lemma sin_gt_sub_cube {x : ℝ} (h : 0 < x) (h' : x ≤ 1) : x - x ^ 3 / 4 < sin x :=
begin
have hx : abs x = x := abs_of_nonneg (le_of_lt h),
have : abs x ≤ 1, rwa [hx],
have := sin_bound this, rw [abs_le] at this,
have := this.1, rw [le_sub_iff_add_le, hx] at this,
refine lt_of_lt_of_le _ this,
rw [add_comm, sub_add, sub_neg_eq_add], apply sub_lt_sub_left,
apply add_lt_of_lt_sub_left,
rw (show x ^ 3 / 4 - x ^ 3 / 6 = x ^ 3 * 12⁻¹,
by simp [div_eq_mul_inv, ← mul_sub]; norm_num),
apply mul_lt_mul',
{ rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)),
rw mul_le_mul_right, exact h', apply pow_pos h },
norm_num, norm_num, apply pow_pos h
end
section cos_div_sq
variable (x : ℝ)
/-- the series `sqrt_two_add_series x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots,
starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2`
-/
@[simp, pp_nodot] noncomputable def sqrt_two_add_series (x : ℝ) : ℕ → ℝ
| 0 := x
| (n+1) := sqrt (2 + sqrt_two_add_series n)
lemma sqrt_two_add_series_zero : sqrt_two_add_series x 0 = x := by simp
lemma sqrt_two_add_series_one : sqrt_two_add_series 0 1 = sqrt 2 := by simp
lemma sqrt_two_add_series_two : sqrt_two_add_series 0 2 = sqrt (2 + sqrt 2) := by simp
lemma sqrt_two_add_series_zero_nonneg : ∀(n : ℕ), 0 ≤ sqrt_two_add_series 0 n
| 0 := le_refl 0
| (n+1) := sqrt_nonneg _
lemma sqrt_two_add_series_nonneg {x : ℝ} (h : 0 ≤ x) : ∀(n : ℕ), 0 ≤ sqrt_two_add_series x n
| 0 := h
| (n+1) := sqrt_nonneg _
lemma sqrt_two_add_series_lt_two : ∀(n : ℕ), sqrt_two_add_series 0 n < 2
| 0 := by norm_num
| (n+1) :=
begin
refine lt_of_lt_of_le _ (le_of_eq $ sqrt_sq $ le_of_lt zero_lt_two),
rw [sqrt_two_add_series, sqrt_lt, ← lt_sub_iff_add_lt'],
{ refine (sqrt_two_add_series_lt_two n).trans_le _, norm_num },
{ exact add_nonneg zero_le_two (sqrt_two_add_series_zero_nonneg n) }
end
lemma sqrt_two_add_series_succ (x : ℝ) :
∀(n : ℕ), sqrt_two_add_series x (n+1) = sqrt_two_add_series (sqrt (2 + x)) n
| 0 := rfl
| (n+1) := by rw [sqrt_two_add_series, sqrt_two_add_series_succ, sqrt_two_add_series]
lemma sqrt_two_add_series_monotone_left {x y : ℝ} (h : x ≤ y) :
∀(n : ℕ), sqrt_two_add_series x n ≤ sqrt_two_add_series y n
| 0 := h
| (n+1) :=
begin
rw [sqrt_two_add_series, sqrt_two_add_series],
exact sqrt_le_sqrt (add_le_add_left (sqrt_two_add_series_monotone_left _) _)
end
@[simp] lemma cos_pi_over_two_pow : ∀(n : ℕ), cos (π / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2
| 0 := by simp
| (n+1) :=
begin
have : (2 : ℝ) ≠ 0 := two_ne_zero,
symmetry, rw [div_eq_iff_mul_eq this], symmetry,
rw [sqrt_two_add_series, sqrt_eq_iff_sq_eq, mul_pow, cos_sq, ←mul_div_assoc,
nat.add_succ, pow_succ, mul_div_mul_left _ _ this, cos_pi_over_two_pow, add_mul],
congr, { norm_num },
rw [mul_comm, sq, mul_assoc, ←mul_div_assoc, mul_div_cancel_left, ←mul_div_assoc,
mul_div_cancel_left]; try { exact this },
apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg, norm_num,
apply le_of_lt, apply cos_pos_of_mem_Ioo ⟨_, _⟩,
{ transitivity (0 : ℝ), rw neg_lt_zero, apply pi_div_two_pos,
apply div_pos pi_pos, apply pow_pos, norm_num },
apply div_lt_div' (le_refl π) _ pi_pos _,
refine lt_of_le_of_lt (le_of_eq (pow_one _).symm) _,
apply pow_lt_pow, norm_num, apply nat.succ_lt_succ, apply nat.succ_pos, all_goals {norm_num}
end
lemma sin_sq_pi_over_two_pow (n : ℕ) :
sin (π / 2 ^ (n+1)) ^ 2 = 1 - (sqrt_two_add_series 0 n / 2) ^ 2 :=
by rw [sin_sq, cos_pi_over_two_pow]
lemma sin_sq_pi_over_two_pow_succ (n : ℕ) :
sin (π / 2 ^ (n+2)) ^ 2 = 1 / 2 - sqrt_two_add_series 0 n / 4 :=
begin
rw [sin_sq_pi_over_two_pow, sqrt_two_add_series, div_pow, sq_sqrt, add_div, ←sub_sub],
congr, norm_num, norm_num, apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg,
end
@[simp] lemma sin_pi_over_two_pow_succ (n : ℕ) :
sin (π / 2 ^ (n+2)) = sqrt (2 - sqrt_two_add_series 0 n) / 2 :=
begin
symmetry, rw [div_eq_iff_mul_eq], symmetry,
rw [sqrt_eq_iff_sq_eq, mul_pow, sin_sq_pi_over_two_pow_succ, sub_mul],
{ congr, norm_num, rw [mul_comm], convert mul_div_cancel' _ _, norm_num, norm_num },
{ rw [sub_nonneg], apply le_of_lt, apply sqrt_two_add_series_lt_two },
apply le_of_lt, apply mul_pos, apply sin_pos_of_pos_of_lt_pi,
{ apply div_pos pi_pos, apply pow_pos, norm_num },
refine lt_of_lt_of_le _ (le_of_eq (div_one _)), rw [div_lt_div_left],
refine lt_of_le_of_lt (le_of_eq (pow_zero 2).symm) _,
apply pow_lt_pow, norm_num, apply nat.succ_pos, apply pi_pos,
apply pow_pos, all_goals {norm_num}
end
@[simp] lemma cos_pi_div_four : cos (π / 4) = sqrt 2 / 2 :=
by { transitivity cos (π / 2 ^ 2), congr, norm_num, simp }
@[simp] lemma sin_pi_div_four : sin (π / 4) = sqrt 2 / 2 :=
by { transitivity sin (π / 2 ^ 2), congr, norm_num, simp }
@[simp] lemma cos_pi_div_eight : cos (π / 8) = sqrt (2 + sqrt 2) / 2 :=
by { transitivity cos (π / 2 ^ 3), congr, norm_num, simp }
@[simp] lemma sin_pi_div_eight : sin (π / 8) = sqrt (2 - sqrt 2) / 2 :=
by { transitivity sin (π / 2 ^ 3), congr, norm_num, simp }
@[simp] lemma cos_pi_div_sixteen : cos (π / 16) = sqrt (2 + sqrt (2 + sqrt 2)) / 2 :=
by { transitivity cos (π / 2 ^ 4), congr, norm_num, simp }
@[simp] lemma sin_pi_div_sixteen : sin (π / 16) = sqrt (2 - sqrt (2 + sqrt 2)) / 2 :=
by { transitivity sin (π / 2 ^ 4), congr, norm_num, simp }
@[simp] lemma cos_pi_div_thirty_two : cos (π / 32) = sqrt (2 + sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=
by { transitivity cos (π / 2 ^ 5), congr, norm_num, simp }
@[simp] lemma sin_pi_div_thirty_two : sin (π / 32) = sqrt (2 - sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=
by { transitivity sin (π / 2 ^ 5), congr, norm_num, simp }
-- This section is also a convenient location for other explicit values of `sin` and `cos`.
/-- The cosine of `π / 3` is `1 / 2`. -/
@[simp] lemma cos_pi_div_three : cos (π / 3) = 1 / 2 :=
begin
have h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0,
{ have : cos (3 * (π / 3)) = cos π := by { congr' 1, ring },
linarith [cos_pi, cos_three_mul (π / 3)] },
cases mul_eq_zero.mp h₁ with h h,
{ linarith [pow_eq_zero h] },
{ have : cos π < cos (π / 3),
{ refine cos_lt_cos_of_nonneg_of_le_pi _ rfl.ge _;
linarith [pi_pos] },
linarith [cos_pi] }
end
/-- The square of the cosine of `π / 6` is `3 / 4` (this is sometimes more convenient than the
result for cosine itself). -/
lemma sq_cos_pi_div_six : cos (π / 6) ^ 2 = 3 / 4 :=
begin
have h1 : cos (π / 6) ^ 2 = 1 / 2 + 1 / 2 / 2,
{ convert cos_sq (π / 6),
have h2 : 2 * (π / 6) = π / 3 := by cancel_denoms,
rw [h2, cos_pi_div_three] },
rw ← sub_eq_zero at h1 ⊢,
convert h1 using 1,
ring
end
/-- The cosine of `π / 6` is `√3 / 2`. -/
@[simp] lemma cos_pi_div_six : cos (π / 6) = (sqrt 3) / 2 :=
begin
suffices : sqrt 3 = cos (π / 6) * 2,
{ field_simp [(by norm_num : 0 ≠ 2)], exact this.symm },
rw sqrt_eq_iff_sq_eq,
{ have h1 := (mul_right_inj' (by norm_num : (4:ℝ) ≠ 0)).mpr sq_cos_pi_div_six,
rw ← sub_eq_zero at h1 ⊢,
convert h1 using 1,
ring },
{ norm_num },
{ have : 0 < cos (π / 6) := by { apply cos_pos_of_mem_Ioo; split; linarith [pi_pos] },
linarith },
end
/-- The sine of `π / 6` is `1 / 2`. -/
@[simp] lemma sin_pi_div_six : sin (π / 6) = 1 / 2 :=
begin
rw [← cos_pi_div_two_sub, ← cos_pi_div_three],
congr,
ring
end
/-- The square of the sine of `π / 3` is `3 / 4` (this is sometimes more convenient than the
result for cosine itself). -/
lemma sq_sin_pi_div_three : sin (π / 3) ^ 2 = 3 / 4 :=
begin
rw [← cos_pi_div_two_sub, ← sq_cos_pi_div_six],
congr,
ring
end
/-- The sine of `π / 3` is `√3 / 2`. -/
@[simp] lemma sin_pi_div_three : sin (π / 3) = (sqrt 3) / 2 :=
begin
rw [← cos_pi_div_two_sub, ← cos_pi_div_six],
congr,
ring
end
end cos_div_sq
/-- The type of angles -/
def angle : Type :=
quotient_add_group.quotient (add_subgroup.gmultiples (2 * π))
namespace angle
instance angle.add_comm_group : add_comm_group angle :=
quotient_add_group.add_comm_group _
instance : inhabited angle := ⟨0⟩
instance angle.has_coe : has_coe ℝ angle :=
⟨quotient.mk'⟩
@[simp] lemma coe_zero : ↑(0 : ℝ) = (0 : angle) := rfl
@[simp] lemma coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : angle) := rfl
@[simp] lemma coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : angle) := rfl
@[simp] lemma coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : angle) :=
by rw [sub_eq_add_neg, sub_eq_add_neg, coe_add, coe_neg]
@[simp, norm_cast] lemma coe_nat_mul_eq_nsmul (x : ℝ) (n : ℕ) :
↑((n : ℝ) * x) = n • (↑x : angle) :=
by simpa using add_monoid_hom.map_nsmul ⟨coe, coe_zero, coe_add⟩ _ _
@[simp, norm_cast] lemma coe_int_mul_eq_gsmul (x : ℝ) (n : ℤ) :
↑((n : ℝ) * x : ℝ) = n • (↑x : angle) :=
by simpa using add_monoid_hom.map_gsmul ⟨coe, coe_zero, coe_add⟩ _ _
@[simp] lemma coe_two_pi : ↑(2 * π : ℝ) = (0 : angle) :=
quotient.sound' ⟨-1, show (-1 : ℤ) • (2 * π) = _, by rw [neg_one_gsmul, add_zero]⟩
lemma angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k :=
by simp only [quotient_add_group.eq, add_subgroup.gmultiples_eq_closure,
add_subgroup.mem_closure_singleton, gsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm]
theorem cos_eq_iff_eq_or_eq_neg {θ ψ : ℝ} : cos θ = cos ψ ↔ (θ : angle) = ψ ∨ (θ : angle) = -ψ :=
begin
split,
{ intro Hcos,
rw [← sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero,
eq_false_intro two_ne_zero, false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos,
rcases Hcos with ⟨n, hn⟩ | ⟨n, hn⟩,
{ right,
rw [eq_div_iff_mul_eq (@two_ne_zero ℝ _ _), ← sub_eq_iff_eq_add] at hn,
rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc,
coe_int_mul_eq_gsmul, mul_comm, coe_two_pi, gsmul_zero] },
{ left,
rw [eq_div_iff_mul_eq (@two_ne_zero ℝ _ _), eq_sub_iff_add_eq] at hn,
rw [← hn, coe_add, mul_assoc,
coe_int_mul_eq_gsmul, mul_comm, coe_two_pi, gsmul_zero, zero_add] },
apply_instance, },
{ rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub],
rintro (⟨k, H⟩ | ⟨k, H⟩),
rw [← sub_eq_zero, cos_sub_cos, H, mul_assoc 2 π k,
mul_div_cancel_left _ (@two_ne_zero ℝ _ _), mul_comm π _, sin_int_mul_pi, mul_zero],
rw [← sub_eq_zero, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k,
mul_div_cancel_left _ (@two_ne_zero ℝ _ _), mul_comm π _, sin_int_mul_pi, mul_zero,
zero_mul] }
end
theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : ℝ} :
sin θ = sin ψ ↔ (θ : angle) = ψ ∨ (θ : angle) + ψ = π :=
begin
split,
{ intro Hsin, rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin,
cases cos_eq_iff_eq_or_eq_neg.mp Hsin with h h,
{ left, rw [coe_sub, coe_sub] at h, exact sub_right_inj.1 h },
right, rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub,
sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h,
exact h.symm },
{ rw [angle_eq_iff_two_pi_dvd_sub, ←eq_sub_iff_add_eq, ←coe_sub, angle_eq_iff_two_pi_dvd_sub],
rintro (⟨k, H⟩ | ⟨k, H⟩),
rw [← sub_eq_zero, sin_sub_sin, H, mul_assoc 2 π k,
mul_div_cancel_left _ (@two_ne_zero ℝ _ _), mul_comm π _, sin_int_mul_pi, mul_zero,
zero_mul],
have H' : θ + ψ = (2 * k) * π + π := by rwa [←sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add,
mul_assoc, mul_comm π _, ←mul_assoc] at H,
rw [← sub_eq_zero, sin_sub_sin, H', add_div, mul_assoc 2 _ π,
mul_div_cancel_left _ (@two_ne_zero ℝ _ _), cos_add_pi_div_two, sin_int_mul_pi, neg_zero,
mul_zero] }
end
theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : angle) = ψ :=
begin
cases cos_eq_iff_eq_or_eq_neg.mp Hcos with hc hc, { exact hc },
cases sin_eq_iff_eq_or_add_eq_pi.mp Hsin with hs hs, { exact hs },
rw [eq_neg_iff_add_eq_zero, hs] at hc,
cases quotient.exact' hc with n hn, change n • _ = _ at hn,
rw [← neg_one_mul, add_zero, ← sub_eq_zero, gsmul_eq_mul, ← mul_assoc, ← sub_mul,
mul_eq_zero, eq_false_intro (ne_of_gt pi_pos), or_false, sub_neg_eq_add,
← int.cast_zero, ← int.cast_one, ← int.cast_bit0, ← int.cast_mul, ← int.cast_add,
int.cast_inj] at hn,
have : (n * 2 + 1) % (2:ℤ) = 0 % (2:ℤ) := congr_arg (%(2:ℤ)) hn,
rw [add_comm, int.add_mul_mod_self] at this,
exact absurd this one_ne_zero
end
end angle
/-- `real.sin` as an `order_iso` between `[-(π / 2), π / 2]` and `[-1, 1]`. -/
def sin_order_iso : Icc (-(π / 2)) (π / 2) ≃o Icc (-1:ℝ) 1 :=
(strict_mono_incr_on_sin.order_iso _ _).trans $ order_iso.set_congr _ _ bij_on_sin.image_eq
@[simp] lemma coe_sin_order_iso_apply (x : Icc (-(π / 2)) (π / 2)) :
(sin_order_iso x : ℝ) = sin x := rfl
lemma sin_order_iso_apply (x : Icc (-(π / 2)) (π / 2)) :
sin_order_iso x = ⟨sin x, sin_mem_Icc x⟩ := rfl
/-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x ≤ π / 2`.
It defaults to `-π / 2` on `(-∞, -1)` and to `π / 2` to `(1, ∞)`. -/
@[pp_nodot] noncomputable def arcsin : ℝ → ℝ :=
coe ∘ Icc_extend (neg_le_self zero_le_one) sin_order_iso.symm
lemma arcsin_mem_Icc (x : ℝ) : arcsin x ∈ Icc (-(π / 2)) (π / 2) := subtype.coe_prop _
@[simp] lemma range_arcsin : range arcsin = Icc (-(π / 2)) (π / 2) :=
by { rw [arcsin, range_comp coe], simp [Icc] }
lemma arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 := (arcsin_mem_Icc x).2
lemma neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x := (arcsin_mem_Icc x).1
lemma arcsin_proj_Icc (x : ℝ) :
arcsin (proj_Icc (-1) 1 (neg_le_self $ @zero_le_one ℝ _) x) = arcsin x :=
by rw [arcsin, function.comp_app, Icc_extend_coe, function.comp_app, Icc_extend]
lemma sin_arcsin' {x : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) : sin (arcsin x) = x :=
by simpa [arcsin, Icc_extend_of_mem _ _ hx, -order_iso.apply_symm_apply]
using subtype.ext_iff.1 (sin_order_iso.apply_symm_apply ⟨x, hx⟩)
lemma sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x :=
sin_arcsin' ⟨hx₁, hx₂⟩
lemma arcsin_sin' {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin (sin x) = x :=
inj_on_sin (arcsin_mem_Icc _) hx $ by rw [sin_arcsin (neg_one_le_sin _) (sin_le_one _)]
lemma arcsin_sin {x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x :=
arcsin_sin' ⟨hx₁, hx₂⟩
lemma strict_mono_incr_on_arcsin : strict_mono_incr_on arcsin (Icc (-1) 1) :=
(subtype.strict_mono_coe _).comp_strict_mono_incr_on $
sin_order_iso.symm.strict_mono.strict_mono_incr_on_Icc_extend _
lemma monotone_arcsin : monotone arcsin :=
(subtype.mono_coe _).comp $ sin_order_iso.symm.monotone.Icc_extend _
lemma inj_on_arcsin : inj_on arcsin (Icc (-1) 1) := strict_mono_incr_on_arcsin.inj_on
lemma arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) :
arcsin x = arcsin y ↔ x = y :=
inj_on_arcsin.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩
@[continuity]
lemma continuous_arcsin : continuous arcsin :=
continuous_subtype_coe.comp sin_order_iso.symm.continuous.Icc_extend
lemma continuous_at_arcsin {x : ℝ} : continuous_at arcsin x :=
continuous_arcsin.continuous_at
lemma arcsin_eq_of_sin_eq {x y : ℝ} (h₁ : sin x = y) (h₂ : x ∈ Icc (-(π / 2)) (π / 2)) :
arcsin y = x :=
begin
subst y,
exact inj_on_sin (arcsin_mem_Icc _) h₂ (sin_arcsin' (sin_mem_Icc x))
end
@[simp] lemma arcsin_zero : arcsin 0 = 0 :=
arcsin_eq_of_sin_eq sin_zero ⟨neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le⟩
@[simp] lemma arcsin_one : arcsin 1 = π / 2 :=
arcsin_eq_of_sin_eq sin_pi_div_two $ right_mem_Icc.2 (neg_le_self pi_div_two_pos.le)
lemma arcsin_of_one_le {x : ℝ} (hx : 1 ≤ x) : arcsin x = π / 2 :=
by rw [← arcsin_proj_Icc, proj_Icc_of_right_le _ hx, subtype.coe_mk, arcsin_one]
lemma arcsin_neg_one : arcsin (-1) = -(π / 2) :=
arcsin_eq_of_sin_eq (by rw [sin_neg, sin_pi_div_two]) $
left_mem_Icc.2 (neg_le_self pi_div_two_pos.le)
lemma arcsin_of_le_neg_one {x : ℝ} (hx : x ≤ -1) : arcsin x = -(π / 2) :=
by rw [← arcsin_proj_Icc, proj_Icc_of_le_left _ hx, subtype.coe_mk, arcsin_neg_one]
@[simp] lemma arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x :=
begin
cases le_total x (-1) with hx₁ hx₁,
{ rw [arcsin_of_le_neg_one hx₁, neg_neg, arcsin_of_one_le (le_neg.2 hx₁)] },
cases le_total 1 x with hx₂ hx₂,
{ rw [arcsin_of_one_le hx₂, arcsin_of_le_neg_one (neg_le_neg hx₂)] },
refine arcsin_eq_of_sin_eq _ _,
{ rw [sin_neg, sin_arcsin hx₁ hx₂] },
{ exact ⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)⟩ }
end
lemma arcsin_le_iff_le_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) :
arcsin x ≤ y ↔ x ≤ sin y :=
by rw [← arcsin_sin' hy, strict_mono_incr_on_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy]
lemma arcsin_le_iff_le_sin' {x y : ℝ} (hy : y ∈ Ico (-(π / 2)) (π / 2)) :
arcsin x ≤ y ↔ x ≤ sin y :=
begin
cases le_total x (-1) with hx₁ hx₁,
{ simp [arcsin_of_le_neg_one hx₁, hy.1, hx₁.trans (neg_one_le_sin _)] },
cases lt_or_le 1 x with hx₂ hx₂,
{ simp [arcsin_of_one_le hx₂.le, hy.2.not_le, (sin_le_one y).trans_lt hx₂] },
exact arcsin_le_iff_le_sin ⟨hx₁, hx₂⟩ (mem_Icc_of_Ico hy)
end
lemma le_arcsin_iff_sin_le {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) :
x ≤ arcsin y ↔ sin x ≤ y :=
by rw [← neg_le_neg_iff, ← arcsin_neg,
arcsin_le_iff_le_sin ⟨neg_le_neg hy.2, neg_le.2 hy.1⟩ ⟨neg_le_neg hx.2, neg_le.2 hx.1⟩,
sin_neg, neg_le_neg_iff]
lemma le_arcsin_iff_sin_le' {x y : ℝ} (hx : x ∈ Ioc (-(π / 2)) (π / 2)) :
x ≤ arcsin y ↔ sin x ≤ y :=
by rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin' ⟨neg_le_neg hx.2, neg_lt.2 hx.1⟩,
sin_neg, neg_le_neg_iff]
lemma arcsin_lt_iff_lt_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) :
arcsin x < y ↔ x < sin y :=
not_le.symm.trans $ (not_congr $ le_arcsin_iff_sin_le hy hx).trans not_le
lemma arcsin_lt_iff_lt_sin' {x y : ℝ} (hy : y ∈ Ioc (-(π / 2)) (π / 2)) :
arcsin x < y ↔ x < sin y :=
not_le.symm.trans $ (not_congr $ le_arcsin_iff_sin_le' hy).trans not_le
lemma lt_arcsin_iff_sin_lt {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) :
x < arcsin y ↔ sin x < y :=
not_le.symm.trans $ (not_congr $ arcsin_le_iff_le_sin hy hx).trans not_le
lemma lt_arcsin_iff_sin_lt' {x y : ℝ} (hx : x ∈ Ico (-(π / 2)) (π / 2)) :
x < arcsin y ↔ sin x < y :=
not_le.symm.trans $ (not_congr $ arcsin_le_iff_le_sin' hx).trans not_le
lemma arcsin_eq_iff_eq_sin {x y : ℝ} (hy : y ∈ Ioo (-(π / 2)) (π / 2)) :
arcsin x = y ↔ x = sin y :=
by simp only [le_antisymm_iff, arcsin_le_iff_le_sin' (mem_Ico_of_Ioo hy),
le_arcsin_iff_sin_le' (mem_Ioc_of_Ioo hy)]
@[simp] lemma arcsin_nonneg {x : ℝ} : 0 ≤ arcsin x ↔ 0 ≤ x :=
(le_arcsin_iff_sin_le' ⟨neg_lt_zero.2 pi_div_two_pos, pi_div_two_pos.le⟩).trans $ by rw [sin_zero]
@[simp] lemma arcsin_nonpos {x : ℝ} : arcsin x ≤ 0 ↔ x ≤ 0 :=
neg_nonneg.symm.trans $ arcsin_neg x ▸ arcsin_nonneg.trans neg_nonneg
@[simp] lemma arcsin_eq_zero_iff {x : ℝ} : arcsin x = 0 ↔ x = 0 :=
by simp [le_antisymm_iff]
@[simp] lemma zero_eq_arcsin_iff {x} : 0 = arcsin x ↔ x = 0 :=
eq_comm.trans arcsin_eq_zero_iff
@[simp] lemma arcsin_pos {x : ℝ} : 0 < arcsin x ↔ 0 < x :=
lt_iff_lt_of_le_iff_le arcsin_nonpos
@[simp] lemma arcsin_lt_zero {x : ℝ} : arcsin x < 0 ↔ x < 0 :=
lt_iff_lt_of_le_iff_le arcsin_nonneg
@[simp] lemma arcsin_lt_pi_div_two {x : ℝ} : arcsin x < π / 2 ↔ x < 1 :=
(arcsin_lt_iff_lt_sin' (right_mem_Ioc.2 $ neg_lt_self pi_div_two_pos)).trans $
by rw sin_pi_div_two
@[simp] lemma neg_pi_div_two_lt_arcsin {x : ℝ} : -(π / 2) < arcsin x ↔ -1 < x :=
(lt_arcsin_iff_sin_lt' $ left_mem_Ico.2 $ neg_lt_self pi_div_two_pos).trans $
by rw [sin_neg, sin_pi_div_two]
@[simp] lemma arcsin_eq_pi_div_two {x : ℝ} : arcsin x = π / 2 ↔ 1 ≤ x :=
⟨λ h, not_lt.1 $ λ h', (arcsin_lt_pi_div_two.2 h').ne h, arcsin_of_one_le⟩
@[simp] lemma pi_div_two_eq_arcsin {x} : π / 2 = arcsin x ↔ 1 ≤ x :=
eq_comm.trans arcsin_eq_pi_div_two
@[simp] lemma pi_div_two_le_arcsin {x} : π / 2 ≤ arcsin x ↔ 1 ≤ x :=
(arcsin_le_pi_div_two x).le_iff_eq.trans pi_div_two_eq_arcsin
@[simp] lemma arcsin_eq_neg_pi_div_two {x : ℝ} : arcsin x = -(π / 2) ↔ x ≤ -1 :=
⟨λ h, not_lt.1 $ λ h', (neg_pi_div_two_lt_arcsin.2 h').ne' h, arcsin_of_le_neg_one⟩
@[simp] lemma neg_pi_div_two_eq_arcsin {x} : -(π / 2) = arcsin x ↔ x ≤ -1 :=
eq_comm.trans arcsin_eq_neg_pi_div_two
@[simp] lemma arcsin_le_neg_pi_div_two {x} : arcsin x ≤ -(π / 2) ↔ x ≤ -1 :=
(neg_pi_div_two_le_arcsin x).le_iff_eq.trans arcsin_eq_neg_pi_div_two
lemma maps_to_sin_Ioo : maps_to sin (Ioo (-(π / 2)) (π / 2)) (Ioo (-1) 1) :=
λ x h, by rwa [mem_Ioo, ← arcsin_lt_pi_div_two, ← neg_pi_div_two_lt_arcsin,
arcsin_sin h.1.le h.2.le]
/-- `real.sin` as a `local_homeomorph` between `(-π / 2, π / 2)` and `(-1, 1)`. -/
@[simp] def sin_local_homeomorph : local_homeomorph ℝ ℝ :=
{ to_fun := sin,
inv_fun := arcsin,
source := Ioo (-(π / 2)) (π / 2),
target := Ioo (-1) 1,
map_source' := maps_to_sin_Ioo,
map_target' := λ y hy, ⟨neg_pi_div_two_lt_arcsin.2 hy.1, arcsin_lt_pi_div_two.2 hy.2⟩,
left_inv' := λ x hx, arcsin_sin hx.1.le hx.2.le,
right_inv' := λ y hy, sin_arcsin hy.1.le hy.2.le,
open_source := is_open_Ioo,
open_target := is_open_Ioo,
continuous_to_fun := continuous_sin.continuous_on,
continuous_inv_fun := continuous_arcsin.continuous_on }
lemma cos_arcsin_nonneg (x : ℝ) : 0 ≤ cos (arcsin x) :=
cos_nonneg_of_mem_Icc ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩
lemma cos_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arcsin x) = sqrt (1 - x ^ 2) :=
have sin (arcsin x) ^ 2 + cos (arcsin x) ^ 2 = 1 := sin_sq_add_cos_sq (arcsin x),
begin
rw [← eq_sub_iff_add_eq', ← sqrt_inj (sq_nonneg _) (sub_nonneg.2 (sin_sq_le_one (arcsin x))),
sq, sqrt_mul_self (cos_arcsin_nonneg _)] at this,
rw [this, sin_arcsin hx₁ hx₂],
end
lemma deriv_arcsin_aux {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
has_strict_deriv_at arcsin (1 / sqrt (1 - x ^ 2)) x ∧ times_cont_diff_at ℝ ⊤ arcsin x :=
begin
cases h₁.lt_or_lt with h₁ h₁,
{ have : 1 - x ^ 2 < 0, by nlinarith [h₁],
rw [sqrt_eq_zero'.2 this.le, div_zero],
have : arcsin =ᶠ[𝓝 x] λ _, -(π / 2) :=
(gt_mem_nhds h₁).mono (λ y hy, arcsin_of_le_neg_one hy.le),
exact ⟨(has_strict_deriv_at_const _ _).congr_of_eventually_eq this.symm,
times_cont_diff_at_const.congr_of_eventually_eq this⟩ },
cases h₂.lt_or_lt with h₂ h₂,
{ have : 0 < sqrt (1 - x ^ 2) := sqrt_pos.2 (by nlinarith [h₁, h₂]),
simp only [← cos_arcsin h₁.le h₂.le, one_div] at this ⊢,
exact ⟨sin_local_homeomorph.has_strict_deriv_at_symm ⟨h₁, h₂⟩ this.ne'
(has_strict_deriv_at_sin _),
sin_local_homeomorph.times_cont_diff_at_symm_deriv this.ne' ⟨h₁, h₂⟩
(has_deriv_at_sin _) times_cont_diff_sin.times_cont_diff_at⟩ },
{ have : 1 - x ^ 2 < 0, by nlinarith [h₂],
rw [sqrt_eq_zero'.2 this.le, div_zero],
have : arcsin =ᶠ[𝓝 x] λ _, π / 2 := (lt_mem_nhds h₂).mono (λ y hy, arcsin_of_one_le hy.le),
exact ⟨(has_strict_deriv_at_const _ _).congr_of_eventually_eq this.symm,
times_cont_diff_at_const.congr_of_eventually_eq this⟩ }
end
lemma has_strict_deriv_at_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
has_strict_deriv_at arcsin (1 / sqrt (1 - x ^ 2)) x :=
(deriv_arcsin_aux h₁ h₂).1
lemma has_deriv_at_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
has_deriv_at arcsin (1 / sqrt (1 - x ^ 2)) x :=
(has_strict_deriv_at_arcsin h₁ h₂).has_deriv_at
lemma times_cont_diff_at_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) {n : with_top ℕ} :
times_cont_diff_at ℝ n arcsin x :=
(deriv_arcsin_aux h₁ h₂).2.of_le le_top
lemma has_deriv_within_at_arcsin_Ici {x : ℝ} (h : x ≠ -1) :
has_deriv_within_at arcsin (1 / sqrt (1 - x ^ 2)) (Ici x) x :=
begin
rcases em (x = 1) with (rfl|h'),
{ convert (has_deriv_within_at_const _ _ (π / 2)).congr _ _;
simp [arcsin_of_one_le] { contextual := tt } },
{ exact (has_deriv_at_arcsin h h').has_deriv_within_at }
end
lemma has_deriv_within_at_arcsin_Iic {x : ℝ} (h : x ≠ 1) :
has_deriv_within_at arcsin (1 / sqrt (1 - x ^ 2)) (Iic x) x :=
begin
rcases em (x = -1) with (rfl|h'),
{ convert (has_deriv_within_at_const _ _ (-(π / 2))).congr _ _;
simp [arcsin_of_le_neg_one] { contextual := tt } },
{ exact (has_deriv_at_arcsin h' h).has_deriv_within_at }
end
lemma differentiable_within_at_arcsin_Ici {x : ℝ} :
differentiable_within_at ℝ arcsin (Ici x) x ↔ x ≠ -1 :=
begin
refine ⟨_, λ h, (has_deriv_within_at_arcsin_Ici h).differentiable_within_at⟩,
rintro h rfl,
have : sin ∘ arcsin =ᶠ[𝓝[Ici (-1:ℝ)] (-1)] id,
{ filter_upwards [Icc_mem_nhds_within_Ici ⟨le_rfl, neg_lt_self (@zero_lt_one ℝ _ _)⟩],
exact λ x, sin_arcsin' },
have := h.has_deriv_within_at.sin.congr_of_eventually_eq this.symm (by simp),
simpa using (unique_diff_on_Ici _ _ left_mem_Ici).eq_deriv _ this (has_deriv_within_at_id _ _)
end
lemma differentiable_within_at_arcsin_Iic {x : ℝ} :
differentiable_within_at ℝ arcsin (Iic x) x ↔ x ≠ 1 :=
begin
refine ⟨λ h, _, λ h, (has_deriv_within_at_arcsin_Iic h).differentiable_within_at⟩,
rw [← neg_neg x, ← image_neg_Ici] at h,
have := (h.comp (-x) differentiable_within_at_id.neg (maps_to_image _ _)).neg,
simpa [(∘), differentiable_within_at_arcsin_Ici] using this
end
lemma differentiable_at_arcsin {x : ℝ} :
differentiable_at ℝ arcsin x ↔ x ≠ -1 ∧ x ≠ 1 :=
⟨λ h, ⟨differentiable_within_at_arcsin_Ici.1 h.differentiable_within_at,
differentiable_within_at_arcsin_Iic.1 h.differentiable_within_at⟩,
λ h, (has_deriv_at_arcsin h.1 h.2).differentiable_at⟩
@[simp] lemma deriv_arcsin : deriv arcsin = λ x, 1 / sqrt (1 - x ^ 2) :=
begin
funext x,
by_cases h : x ≠ -1 ∧ x ≠ 1,
{ exact (has_deriv_at_arcsin h.1 h.2).deriv },
{ rw [deriv_zero_of_not_differentiable_at (mt differentiable_at_arcsin.1 h)],
simp only [not_and_distrib, ne.def, not_not] at h,
rcases h with (rfl|rfl); simp }
end
lemma differentiable_on_arcsin : differentiable_on ℝ arcsin {-1, 1}ᶜ :=
λ x hx, (differentiable_at_arcsin.2
⟨λ h, hx (or.inl h), λ h, hx (or.inr h)⟩).differentiable_within_at
lemma times_cont_diff_on_arcsin {n : with_top ℕ} :
times_cont_diff_on ℝ n arcsin {-1, 1}ᶜ :=
λ x hx, (times_cont_diff_at_arcsin (mt or.inl hx) (mt or.inr hx)).times_cont_diff_within_at
lemma times_cont_diff_at_arcsin_iff {x : ℝ} {n : with_top ℕ} :
times_cont_diff_at ℝ n arcsin x ↔ n = 0 ∨ (x ≠ -1 ∧ x ≠ 1) :=
⟨λ h, or_iff_not_imp_left.2 $ λ hn, differentiable_at_arcsin.1 $ h.differentiable_at $
with_top.one_le_iff_pos.2 (pos_iff_ne_zero.2 hn),
λ h, h.elim (λ hn, hn.symm ▸ (times_cont_diff_zero.2 continuous_arcsin).times_cont_diff_at) $
λ hx, times_cont_diff_at_arcsin hx.1 hx.2⟩
lemma measurable_arcsin : measurable arcsin := continuous_arcsin.measurable
/-- Inverse of the `cos` function, returns values in the range `0 ≤ arccos x` and `arccos x ≤ π`.
If the argument is not between `-1` and `1` it defaults to `π / 2` -/
@[pp_nodot] noncomputable def arccos (x : ℝ) : ℝ :=
π / 2 - arcsin x
lemma arccos_eq_pi_div_two_sub_arcsin (x : ℝ) : arccos x = π / 2 - arcsin x := rfl
lemma arcsin_eq_pi_div_two_sub_arccos (x : ℝ) : arcsin x = π / 2 - arccos x :=
by simp [arccos]
lemma arccos_le_pi (x : ℝ) : arccos x ≤ π :=
by unfold arccos; linarith [neg_pi_div_two_le_arcsin x]
lemma arccos_nonneg (x : ℝ) : 0 ≤ arccos x :=
by unfold arccos; linarith [arcsin_le_pi_div_two x]
lemma cos_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arccos x) = x :=
by rw [arccos, cos_pi_div_two_sub, sin_arcsin hx₁ hx₂]
lemma arccos_cos {x : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) : arccos (cos x) = x :=
by rw [arccos, ← sin_pi_div_two_sub, arcsin_sin]; simp [sub_eq_add_neg]; linarith
lemma strict_mono_decr_on_arccos : strict_mono_decr_on arccos (Icc (-1) 1) :=
λ x hx y hy h, sub_lt_sub_left (strict_mono_incr_on_arcsin hx hy h) _
lemma arccos_inj_on : inj_on arccos (Icc (-1) 1) := strict_mono_decr_on_arccos.inj_on
lemma arccos_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) :
arccos x = arccos y ↔ x = y :=
arccos_inj_on.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩
@[simp] lemma arccos_zero : arccos 0 = π / 2 := by simp [arccos]
@[simp] lemma arccos_one : arccos 1 = 0 := by simp [arccos]
@[simp] lemma arccos_neg_one : arccos (-1) = π := by simp [arccos, add_halves]
@[simp] lemma arccos_eq_zero {x} : arccos x = 0 ↔ 1 ≤ x :=
by simp [arccos, sub_eq_zero]
@[simp] lemma arccos_eq_pi_div_two {x} : arccos x = π / 2 ↔ x = 0 :=
by simp [arccos, sub_eq_iff_eq_add]
@[simp] lemma arccos_eq_pi {x} : arccos x = π ↔ x ≤ -1 :=
by rw [arccos, sub_eq_iff_eq_add, ← sub_eq_iff_eq_add', div_two_sub_self, neg_pi_div_two_eq_arcsin]
lemma arccos_neg (x : ℝ) : arccos (-x) = π - arccos x :=
by rw [← add_halves π, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self, sub_neg_eq_add]
lemma sin_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arccos x) = sqrt (1 - x ^ 2) :=
by rw [arccos_eq_pi_div_two_sub_arcsin, sin_pi_div_two_sub, cos_arcsin hx₁ hx₂]
@[continuity]
lemma continuous_arccos : continuous arccos := continuous_const.sub continuous_arcsin
lemma has_strict_deriv_at_arccos {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
has_strict_deriv_at arccos (-(1 / sqrt (1 - x ^ 2))) x :=
(has_strict_deriv_at_arcsin h₁ h₂).const_sub (π / 2)
lemma has_deriv_at_arccos {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
has_deriv_at arccos (-(1 / sqrt (1 - x ^ 2))) x :=
(has_deriv_at_arcsin h₁ h₂).const_sub (π / 2)
lemma times_cont_diff_at_arccos {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) {n : with_top ℕ} :
times_cont_diff_at ℝ n arccos x :=
times_cont_diff_at_const.sub (times_cont_diff_at_arcsin h₁ h₂)
lemma has_deriv_within_at_arccos_Ici {x : ℝ} (h : x ≠ -1) :
has_deriv_within_at arccos (-(1 / sqrt (1 - x ^ 2))) (Ici x) x :=
(has_deriv_within_at_arcsin_Ici h).const_sub _
lemma has_deriv_within_at_arccos_Iic {x : ℝ} (h : x ≠ 1) :
has_deriv_within_at arccos (-(1 / sqrt (1 - x ^ 2))) (Iic x) x :=
(has_deriv_within_at_arcsin_Iic h).const_sub _
lemma differentiable_within_at_arccos_Ici {x : ℝ} :
differentiable_within_at ℝ arccos (Ici x) x ↔ x ≠ -1 :=
(differentiable_within_at_const_sub_iff _).trans differentiable_within_at_arcsin_Ici
lemma differentiable_within_at_arccos_Iic {x : ℝ} :
differentiable_within_at ℝ arccos (Iic x) x ↔ x ≠ 1 :=
(differentiable_within_at_const_sub_iff _).trans differentiable_within_at_arcsin_Iic
lemma differentiable_at_arccos {x : ℝ} :
differentiable_at ℝ arccos x ↔ x ≠ -1 ∧ x ≠ 1 :=
(differentiable_at_const_sub_iff _).trans differentiable_at_arcsin
@[simp] lemma deriv_arccos : deriv arccos = λ x, -(1 / sqrt (1 - x ^ 2)) :=
funext $ λ x, (deriv_const_sub _).trans $ by simp only [deriv_arcsin]
lemma differentiable_on_arccos : differentiable_on ℝ arccos {-1, 1}ᶜ :=
differentiable_on_arcsin.const_sub _
lemma times_cont_diff_on_arccos {n : with_top ℕ} :
times_cont_diff_on ℝ n arccos {-1, 1}ᶜ :=
times_cont_diff_on_const.sub times_cont_diff_on_arcsin
lemma times_cont_diff_at_arccos_iff {x : ℝ} {n : with_top ℕ} :
times_cont_diff_at ℝ n arccos x ↔ n = 0 ∨ (x ≠ -1 ∧ x ≠ 1) :=
by refine iff.trans ⟨λ h, _, λ h, _⟩ times_cont_diff_at_arcsin_iff;
simpa [arccos] using (@times_cont_diff_at_const _ _ _ _ _ _ _ _ _ _ (π / 2)).sub h
lemma measurable_arccos : measurable arccos := continuous_arccos.measurable
@[simp] lemma tan_pi_div_four : tan (π / 4) = 1 :=
begin
rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four],
have h : (sqrt 2) / 2 > 0 := by cancel_denoms,
exact div_self (ne_of_gt h),
end
@[simp] lemma tan_pi_div_two : tan (π / 2) = 0 := by simp [tan_eq_sin_div_cos]
lemma tan_pos_of_pos_of_lt_pi_div_two {x : ℝ} (h0x : 0 < x) (hxp : x < π / 2) : 0 < tan x :=
by rw tan_eq_sin_div_cos; exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith))
(cos_pos_of_mem_Ioo ⟨by linarith, hxp⟩)
lemma tan_nonneg_of_nonneg_of_le_pi_div_two {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π / 2) : 0 ≤ tan x :=
match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with
| or.inl hx0, or.inl hxp := le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp)
| or.inl hx0, or.inr hxp := by simp [hxp, tan_eq_sin_div_cos]
| or.inr hx0, _ := by simp [hx0.symm]
end
lemma tan_neg_of_neg_of_pi_div_two_lt {x : ℝ} (hx0 : x < 0) (hpx : -(π / 2) < x) : tan x < 0 :=
neg_pos.1 (tan_neg x ▸ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos]))
lemma tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -(π / 2) ≤ x) :
tan x ≤ 0 :=
neg_nonneg.1 (tan_neg x ▸ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith))
lemma tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : ℝ}
(hx₁ : 0 ≤ x) (hy₂ : y < π / 2) (hxy : x < y) :
tan x < tan y :=
begin
rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos],
exact div_lt_div
(sin_lt_sin_of_lt_of_le_pi_div_two (by linarith) (le_of_lt hy₂) hxy)
(cos_le_cos_of_nonneg_of_le_pi hx₁ (by linarith) (le_of_lt hxy))
(sin_nonneg_of_nonneg_of_le_pi (by linarith) (by linarith))
(cos_pos_of_mem_Ioo ⟨by linarith, hy₂⟩)
end
lemma tan_lt_tan_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x)
(hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y :=
match le_total x 0, le_total y 0 with
| or.inl hx0, or.inl hy0 := neg_lt_neg_iff.1 $ by rw [← tan_neg, ← tan_neg]; exact
tan_lt_tan_of_nonneg_of_lt_pi_div_two (neg_nonneg.2 hy0)
(neg_lt.2 hx₁) (neg_lt_neg hxy)
| or.inl hx0, or.inr hy0 := (lt_or_eq_of_le hy0).elim
(λ hy0, calc tan x ≤ 0 : tan_nonpos_of_nonpos_of_neg_pi_div_two_le hx0 (le_of_lt hx₁)
... < tan y : tan_pos_of_pos_of_lt_pi_div_two hy0 hy₂)
(λ hy0, by rw [← hy0, tan_zero]; exact
tan_neg_of_neg_of_pi_div_two_lt (hy0.symm ▸ hxy) hx₁)
| or.inr hx0, or.inl hy0 := by linarith
| or.inr hx0, or.inr hy0 := tan_lt_tan_of_nonneg_of_lt_pi_div_two hx0 hy₂ hxy
end
lemma strict_mono_incr_on_tan : strict_mono_incr_on tan (Ioo (-(π / 2)) (π / 2)) :=
λ x hx y hy, tan_lt_tan_of_lt_of_lt_pi_div_two hx.1 hy.2
lemma inj_on_tan : inj_on tan (Ioo (-(π / 2)) (π / 2)) :=
strict_mono_incr_on_tan.inj_on
lemma tan_inj_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2)
(hy₁ : -(π / 2) < y) (hy₂ : y < π / 2) (hxy : tan x = tan y) : x = y :=
inj_on_tan ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ hxy
end real
namespace complex
open_locale real
/-- `arg` returns values in the range (-π, π], such that for `x ≠ 0`,
`sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,
`arg 0` defaults to `0` -/
noncomputable def arg (x : ℂ) : ℝ :=
if 0 ≤ x.re
then real.arcsin (x.im / x.abs)
else if 0 ≤ x.im
then real.arcsin ((-x).im / x.abs) + π
else real.arcsin ((-x).im / x.abs) - π
lemma measurable_arg : measurable arg :=
have A : measurable (λ x : ℂ, real.arcsin (x.im / x.abs)),
from real.measurable_arcsin.comp (measurable_im.div measurable_norm),
have B : measurable (λ x : ℂ, real.arcsin ((-x).im / x.abs)),
from real.measurable_arcsin.comp ((measurable_im.comp measurable_neg).div measurable_norm),
measurable.ite (is_closed_le continuous_const continuous_re).measurable_set A $
measurable.ite (is_closed_le continuous_const continuous_im).measurable_set
(B.add_const _) (B.sub_const _)
lemma arg_le_pi (x : ℂ) : arg x ≤ π :=
if hx₁ : 0 ≤ x.re
then by rw [arg, if_pos hx₁];
exact le_trans (real.arcsin_le_pi_div_two _) (le_of_lt (half_lt_self real.pi_pos))
else
if hx₂ : 0 ≤ x.im
then by rw [arg, if_neg hx₁, if_pos hx₂, ← le_sub_iff_add_le, sub_self, real.arcsin_nonpos,
neg_im, neg_div, neg_nonpos];
exact div_nonneg hx₂ (abs_nonneg _)
else by rw [arg, if_neg hx₁, if_neg hx₂];
exact sub_le_iff_le_add.2 (le_trans (real.arcsin_le_pi_div_two _)
(by linarith [real.pi_pos]))
lemma neg_pi_lt_arg (x : ℂ) : -π < arg x :=
if hx₁ : 0 ≤ x.re
then by rw [arg, if_pos hx₁];
exact lt_of_lt_of_le (neg_lt_neg (half_lt_self real.pi_pos)) (real.neg_pi_div_two_le_arcsin _)
else
have hx : x ≠ 0, from λ h, by simpa [h, lt_irrefl] using hx₁,
if hx₂ : 0 ≤ x.im
then by rw [arg, if_neg hx₁, if_pos hx₂, ← sub_lt_iff_lt_add];
exact (lt_of_lt_of_le (by linarith [real.pi_pos]) (real.neg_pi_div_two_le_arcsin _))
else by rw [arg, if_neg hx₁, if_neg hx₂, lt_sub_iff_add_lt, neg_add_self, real.arcsin_pos,
neg_im];
exact div_pos (neg_pos.2 (lt_of_not_ge hx₂)) (abs_pos.2 hx)
lemma arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg {x : ℂ} (hxr : x.re < 0) (hxi : 0 ≤ x.im) :
arg x = arg (-x) + π :=
have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos],
by rw [arg, arg, if_neg (not_le.2 hxr), if_pos this, if_pos hxi, abs_neg]
lemma arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg {x : ℂ} (hxr : x.re < 0) (hxi : x.im < 0) :
arg x = arg (-x) - π :=
have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos],
by rw [arg, arg, if_neg (not_le.2 hxr), if_neg (not_le.2 hxi), if_pos this, abs_neg]
@[simp] lemma arg_zero : arg 0 = 0 :=
by simp [arg, le_refl]
@[simp] lemma arg_one : arg 1 = 0 :=
by simp [arg, zero_le_one]
@[simp] lemma arg_neg_one : arg (-1) = π :=
by simp [arg, le_refl, not_le.2 (@zero_lt_one ℝ _ _)]
@[simp] lemma arg_I : arg I = π / 2 :=
by simp [arg, le_refl]
@[simp] lemma arg_neg_I : arg (-I) = -(π / 2) :=
by simp [arg, le_refl]
lemma sin_arg (x : ℂ) : real.sin (arg x) = x.im / x.abs :=
by unfold arg; split_ifs;
simp [sub_eq_add_neg, arg, real.sin_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1
(abs_le.1 (abs_im_div_abs_le_one x)).2, real.sin_add, neg_div, real.arcsin_neg,
real.sin_neg]
private lemma cos_arg_of_re_nonneg {x : ℂ} (hx : x ≠ 0) (hxr : 0 ≤ x.re) :
real.cos (arg x) = x.re / x.abs :=
have 0 ≤ 1 - (x.im / abs x) ^ 2,
from sub_nonneg.2 $ by rw [sq, ← _root_.abs_mul_self, _root_.abs_mul, ← sq];
exact pow_le_one _ (_root_.abs_nonneg _) (abs_im_div_abs_le_one _),
by rw [eq_div_iff_mul_eq (mt abs_eq_zero.1 hx), ← real.mul_self_sqrt (abs_nonneg x),
arg, if_pos hxr, real.cos_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1
(abs_le.1 (abs_im_div_abs_le_one x)).2, ← real.sqrt_mul (abs_nonneg _), ← real.sqrt_mul this,
sub_mul, div_pow, ← sq, div_mul_cancel _ (pow_ne_zero 2 (mt abs_eq_zero.1 hx)),
one_mul, sq, mul_self_abs, norm_sq_apply, sq, add_sub_cancel, real.sqrt_mul_self hxr]
lemma cos_arg {x : ℂ} (hx : x ≠ 0) : real.cos (arg x) = x.re / x.abs :=
if hxr : 0 ≤ x.re then cos_arg_of_re_nonneg hx hxr
else
have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr,
if hxi : 0 ≤ x.im
then have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr,
by rw [arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg (not_le.1 hxr) hxi, real.cos_add_pi,
cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this];
simp [neg_div]
else by rw [arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg (not_le.1 hxr) (not_le.1 hxi)];
simp [sub_eq_add_neg, real.cos_add, neg_div, cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this]
lemma tan_arg {x : ℂ} : real.tan (arg x) = x.im / x.re :=
begin
by_cases h : x = 0,
{ simp only [h, zero_div, complex.zero_im, complex.arg_zero, real.tan_zero, complex.zero_re] },
rw [real.tan_eq_sin_div_cos, sin_arg, cos_arg h,
div_div_div_cancel_right _ (mt abs_eq_zero.1 h)]
end
lemma arg_cos_add_sin_mul_I {x : ℝ} (hx₁ : -π < x) (hx₂ : x ≤ π) :
arg (cos x + sin x * I) = x :=
if hx₃ : -(π / 2) ≤ x ∧ x ≤ π / 2
then
have hx₄ : 0 ≤ (cos x + sin x * I).re,
by simp; exact real.cos_nonneg_of_mem_Icc hx₃,
by rw [arg, if_pos hx₄];
simp [abs_cos_add_sin_mul_I, sin_of_real_re, real.arcsin_sin hx₃.1 hx₃.2]
else if hx₄ : x < -(π / 2)
then
have hx₅ : ¬0 ≤ (cos x + sin x * I).re :=
suffices ¬ 0 ≤ real.cos x, by simpa,
not_le.2 $ by rw ← real.cos_neg;
apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith,
have hx₆ : ¬0 ≤ (cos ↑x + sin ↑x * I).im :=
suffices real.sin x < 0, by simpa,
by apply real.sin_neg_of_neg_of_neg_pi_lt; linarith,
suffices -π + -real.arcsin (real.sin x) = x,
by rw [arg, if_neg hx₅, if_neg hx₆];
simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re],
by rw [← real.arcsin_neg, ← real.sin_add_pi, real.arcsin_sin]; try {simp [add_left_comm]};
linarith
else
have hx₅ : π / 2 < x, by cases not_and_distrib.1 hx₃; linarith,
have hx₆ : ¬0 ≤ (cos x + sin x * I).re :=
suffices ¬0 ≤ real.cos x, by simpa,
not_le.2 $ by apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith,
have hx₇ : 0 ≤ (cos x + sin x * I).im :=
suffices 0 ≤ real.sin x, by simpa,
by apply real.sin_nonneg_of_nonneg_of_le_pi; linarith,
suffices π - real.arcsin (real.sin x) = x,
by rw [arg, if_neg hx₆, if_pos hx₇];
simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re],
by rw [← real.sin_pi_sub, real.arcsin_sin]; simp [sub_eq_add_neg]; linarith
lemma arg_eq_arg_iff {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) :
arg x = arg y ↔ (abs y / abs x : ℂ) * x = y :=
have hax : abs x ≠ 0, from (mt abs_eq_zero.1 hx),
have hay : abs y ≠ 0, from (mt abs_eq_zero.1 hy),
⟨λ h,
begin
have hcos := congr_arg real.cos h,
rw [cos_arg hx, cos_arg hy, div_eq_div_iff hax hay] at hcos,
have hsin := congr_arg real.sin h,
rw [sin_arg, sin_arg, div_eq_div_iff hax hay] at hsin,
apply complex.ext,
{ rw [mul_re, ← of_real_div, of_real_re, of_real_im, zero_mul, sub_zero, mul_comm,
← mul_div_assoc, hcos, mul_div_cancel _ hax] },
{ rw [mul_im, ← of_real_div, of_real_re, of_real_im, zero_mul, add_zero,
mul_comm, ← mul_div_assoc, hsin, mul_div_cancel _ hax] }
end,
λ h,
have hre : abs (y / x) * x.re = y.re,
by rw ← of_real_div at h;
simpa [-of_real_div, -is_R_or_C.of_real_div] using congr_arg re h,
have hre' : abs (x / y) * y.re = x.re,
by rw [← hre, abs_div, abs_div, ← mul_assoc, div_mul_div,
mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul],
have him : abs (y / x) * x.im = y.im,
by rw ← of_real_div at h;
simpa [-of_real_div, -is_R_or_C.of_real_div] using congr_arg im h,
have him' : abs (x / y) * y.im = x.im,
by rw [← him, abs_div, abs_div, ← mul_assoc, div_mul_div,
mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul],
have hxya : x.im / abs x = y.im / abs y,
by rw [← him, abs_div, mul_comm, ← mul_div_comm, mul_div_cancel_left _ hay],
have hnxya : (-x).im / abs x = (-y).im / abs y,
by rw [neg_im, neg_im, neg_div, neg_div, hxya],
if hxr : 0 ≤ x.re
then
have hyr : 0 ≤ y.re, from hre ▸ mul_nonneg (abs_nonneg _) hxr,
by simp [arg, *] at *
else
have hyr : ¬ 0 ≤ y.re, from λ hyr, hxr $ hre' ▸ mul_nonneg (abs_nonneg _) hyr,
if hxi : 0 ≤ x.im
then
have hyi : 0 ≤ y.im, from him ▸ mul_nonneg (abs_nonneg _) hxi,
by simp [arg, *] at *
else
have hyi : ¬ 0 ≤ y.im, from λ hyi, hxi $ him' ▸ mul_nonneg (abs_nonneg _) hyi,
by simp [arg, *] at *⟩
lemma arg_real_mul (x : ℂ) {r : ℝ} (hr : 0 < r) : arg (r * x) = arg x :=
if hx : x = 0 then by simp [hx]
else (arg_eq_arg_iff (mul_ne_zero (of_real_ne_zero.2 (ne_of_lt hr).symm) hx) hx).2 $
by rw [abs_mul, abs_of_nonneg (le_of_lt hr), ← mul_assoc,
of_real_mul, mul_comm (r : ℂ), ← div_div_eq_div_mul,
div_mul_cancel _ (of_real_ne_zero.2 (ne_of_lt hr).symm),
div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), one_mul]
lemma ext_abs_arg {x y : ℂ} (h₁ : x.abs = y.abs) (h₂ : x.arg = y.arg) : x = y :=
if hy : y = 0 then by simp * at *
else have hx : x ≠ 0, from λ hx, by simp [*, eq_comm] at *,
by rwa [arg_eq_arg_iff hx hy, h₁, div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hy)), one_mul]
at h₂
lemma arg_of_real_of_nonneg {x : ℝ} (hx : 0 ≤ x) : arg x = 0 :=
by simp [arg, hx]
lemma arg_eq_pi_iff {z : ℂ} : arg z = π ↔ z.re < 0 ∧ z.im = 0 :=
begin
by_cases h₀ : z = 0, { simp [h₀, lt_irrefl, real.pi_ne_zero.symm] },
have h₀' : (abs z : ℂ) ≠ 0, by simpa,
rw [← arg_neg_one, arg_eq_arg_iff h₀ (neg_ne_zero.2 one_ne_zero), abs_neg, abs_one,
of_real_one, one_div, ← div_eq_inv_mul, div_eq_iff_mul_eq h₀', neg_one_mul,
ext_iff, neg_im, of_real_im, neg_zero, @eq_comm _ z.im, and.congr_left_iff],
rcases z with ⟨x, y⟩, simp only,
rintro rfl,
simp only [← of_real_def, of_real_eq_zero] at *,
simp [← ne.le_iff_lt h₀, @neg_eq_iff_neg_eq _ _ _ x, @eq_comm _ (-x)]
end
lemma arg_of_real_of_neg {x : ℝ} (hx : x < 0) : arg x = π :=
arg_eq_pi_iff.2 ⟨hx, rfl⟩
/-- Inverse of the `exp` function. Returns values such that `(log x).im > - π` and `(log x).im ≤ π`.
`log 0 = 0`-/
@[pp_nodot] noncomputable def log (x : ℂ) : ℂ := x.abs.log + arg x * I
lemma measurable_log : measurable log :=
(measurable_of_real.comp $ real.measurable_log.comp measurable_norm).add $
(measurable_of_real.comp measurable_arg).mul_const I
lemma log_re (x : ℂ) : x.log.re = x.abs.log := by simp [log]
lemma log_im (x : ℂ) : x.log.im = x.arg := by simp [log]
lemma neg_pi_lt_log_im (x : ℂ) : -π < (log x).im := by simp only [log_im, neg_pi_lt_arg]
lemma log_im_le_pi (x : ℂ) : (log x).im ≤ π := by simp only [log_im, arg_le_pi]
lemma exp_log {x : ℂ} (hx : x ≠ 0) : exp (log x) = x :=
by rw [log, exp_add_mul_I, ← of_real_sin, sin_arg, ← of_real_cos, cos_arg hx,
← of_real_exp, real.exp_log (abs_pos.2 hx), mul_add, of_real_div, of_real_div,
mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), ← mul_assoc,
mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), re_add_im]
lemma range_exp : range exp = {x | x ≠ 0} :=
set.ext $ λ x, ⟨by { rintro ⟨x, rfl⟩, exact exp_ne_zero x }, λ hx, ⟨log x, exp_log hx⟩⟩
lemma exp_inj_of_neg_pi_lt_of_le_pi {x y : ℂ} (hx₁ : -π < x.im) (hx₂ : x.im ≤ π)
(hy₁ : - π < y.im) (hy₂ : y.im ≤ π) (hxy : exp x = exp y) : x = y :=
by rw [exp_eq_exp_re_mul_sin_add_cos, exp_eq_exp_re_mul_sin_add_cos y] at hxy;
exact complex.ext
(real.exp_injective $
by simpa [abs_mul, abs_cos_add_sin_mul_I] using congr_arg complex.abs hxy)
(by simpa [(of_real_exp _).symm, - of_real_exp, arg_real_mul _ (real.exp_pos _),
arg_cos_add_sin_mul_I hx₁ hx₂, arg_cos_add_sin_mul_I hy₁ hy₂] using congr_arg arg hxy)
lemma log_exp {x : ℂ} (hx₁ : -π < x.im) (hx₂: x.im ≤ π) : log (exp x) = x :=
exp_inj_of_neg_pi_lt_of_le_pi
(by rw log_im; exact neg_pi_lt_arg _)
(by rw log_im; exact arg_le_pi _)
hx₁ hx₂ (by rw [exp_log (exp_ne_zero _)])
lemma of_real_log {x : ℝ} (hx : 0 ≤ x) : (x.log : ℂ) = log x :=
complex.ext
(by rw [log_re, of_real_re, abs_of_nonneg hx])
(by rw [of_real_im, log_im, arg_of_real_of_nonneg hx])
lemma log_of_real_re (x : ℝ) : (log (x : ℂ)).re = real.log x := by simp [log_re]
@[simp] lemma log_zero : log 0 = 0 := by simp [log]
@[simp] lemma log_one : log 1 = 0 := by simp [log]
lemma log_neg_one : log (-1) = π * I := by simp [log]
lemma log_I : log I = π / 2 * I := by simp [log]
lemma log_neg_I : log (-I) = -(π / 2) * I := by simp [log]
lemma exists_pow_nat_eq (x : ℂ) {n : ℕ} (hn : 0 < n) : ∃ z, z ^ n = x :=
begin
by_cases hx : x = 0,
{ use 0, simp only [hx, zero_pow_eq_zero, hn] },
{ use exp (log x / n),
rw [← exp_nat_mul, mul_div_cancel', exp_log hx],
exact_mod_cast (pos_iff_ne_zero.mp hn) }
end
lemma exists_eq_mul_self (x : ℂ) : ∃ z, x = z * z :=
begin
obtain ⟨z, rfl⟩ := exists_pow_nat_eq x zero_lt_two,
exact ⟨z, sq z⟩
end
lemma two_pi_I_ne_zero : (2 * π * I : ℂ) ≠ 0 :=
by norm_num [real.pi_ne_zero, I_ne_zero]
lemma exp_eq_one_iff {x : ℂ} : exp x = 1 ↔ ∃ n : ℤ, x = n * ((2 * π) * I) :=
have real.exp (x.re) * real.cos (x.im) = 1 → real.cos x.im ≠ -1,
from λ h₁ h₂, begin
rw [h₂, mul_neg_eq_neg_mul_symm, mul_one, neg_eq_iff_neg_eq] at h₁,
have := real.exp_pos x.re,
rw ← h₁ at this,
exact absurd this (by norm_num)
end,
calc exp x = 1 ↔ (exp x).re = 1 ∧ (exp x).im = 0 : by simp [complex.ext_iff]
... ↔ real.cos x.im = 1 ∧ real.sin x.im = 0 ∧ x.re = 0 :
begin
rw exp_eq_exp_re_mul_sin_add_cos,
simp [complex.ext_iff, cos_of_real_re, sin_of_real_re, exp_of_real_re,
real.exp_ne_zero],
split; finish [real.sin_eq_zero_iff_cos_eq]
end
... ↔ (∃ n : ℤ, ↑n * (2 * π) = x.im) ∧ (∃ n : ℤ, ↑n * π = x.im) ∧ x.re = 0 :
by rw [real.sin_eq_zero_iff, real.cos_eq_one_iff]
... ↔ ∃ n : ℤ, x = n * ((2 * π) * I) :
⟨λ ⟨⟨n, hn⟩, ⟨m, hm⟩, h⟩, ⟨n, by simp [complex.ext_iff, hn.symm, h]⟩,
λ ⟨n, hn⟩, ⟨⟨n, by simp [hn]⟩, ⟨2 * n, by simp [hn, mul_comm, mul_assoc, mul_left_comm]⟩,
by simp [hn]⟩⟩
lemma exp_eq_exp_iff_exp_sub_eq_one {x y : ℂ} : exp x = exp y ↔ exp (x - y) = 1 :=
by rw [exp_sub, div_eq_one_iff_eq (exp_ne_zero _)]
lemma exp_eq_exp_iff_exists_int {x y : ℂ} : exp x = exp y ↔ ∃ n : ℤ, x = y + n * ((2 * π) * I) :=
by simp only [exp_eq_exp_iff_exp_sub_eq_one, exp_eq_one_iff, sub_eq_iff_eq_add']
/-- `complex.exp` as a `local_homeomorph` with `source = {z | -π < im z < π}` and
`target = {z | 0 < re z} ∪ {z | im z ≠ 0}`. This definition is used to prove that `complex.log`
is complex differentiable at all points but the negative real semi-axis. -/
def exp_local_homeomorph : local_homeomorph ℂ ℂ :=
local_homeomorph.of_continuous_open
{ to_fun := exp,
inv_fun := log,
source := {z : ℂ | z.im ∈ Ioo (- π) π},
target := {z : ℂ | 0 < z.re} ∪ {z : ℂ | z.im ≠ 0},
map_source' :=
begin
rintro ⟨x, y⟩ ⟨h₁ : -π < y, h₂ : y < π⟩,
refine (not_or_of_imp $ λ hz, _).symm,
obtain rfl : y = 0,
{ rw exp_im at hz,
simpa [(real.exp_pos _).ne', real.sin_eq_zero_iff_of_lt_of_lt h₁ h₂] using hz },
rw [mem_set_of_eq, ← of_real_def, exp_of_real_re],
exact real.exp_pos x
end,
map_target' := λ z h,
suffices 0 ≤ z.re ∨ z.im ≠ 0,
by simpa [log_im, neg_pi_lt_arg, (arg_le_pi _).lt_iff_ne, arg_eq_pi_iff, not_and_distrib],
h.imp (λ h, le_of_lt h) id,
left_inv' := λ x hx, log_exp hx.1 (le_of_lt hx.2),
right_inv' := λ x hx, exp_log $ by { rintro rfl, simpa [lt_irrefl] using hx } }
continuous_exp.continuous_on is_open_map_exp (is_open_Ioo.preimage continuous_im)
lemma has_strict_deriv_at_log {x : ℂ} (h : 0 < x.re ∨ x.im ≠ 0) :
has_strict_deriv_at log x⁻¹ x :=
have h0 : x ≠ 0, by { rintro rfl, simpa [lt_irrefl] using h },
exp_local_homeomorph.has_strict_deriv_at_symm h h0 $
by simpa [exp_log h0] using has_strict_deriv_at_exp (log x)
lemma times_cont_diff_at_log {x : ℂ} (h : 0 < x.re ∨ x.im ≠ 0) {n : with_top ℕ} :
times_cont_diff_at ℂ n log x :=
exp_local_homeomorph.times_cont_diff_at_symm_deriv (exp_ne_zero $ log x) h
(has_deriv_at_exp _) times_cont_diff_exp.times_cont_diff_at
@[simp] lemma cos_pi_div_two : cos (π / 2) = 0 :=
calc cos (π / 2) = real.cos (π / 2) : by rw [of_real_cos]; simp
... = 0 : by simp
@[simp] lemma sin_pi_div_two : sin (π / 2) = 1 :=
calc sin (π / 2) = real.sin (π / 2) : by rw [of_real_sin]; simp
... = 1 : by simp
@[simp] lemma sin_pi : sin π = 0 :=
by rw [← of_real_sin, real.sin_pi]; simp
@[simp] lemma cos_pi : cos π = -1 :=
by rw [← of_real_cos, real.cos_pi]; simp
@[simp] lemma sin_two_pi : sin (2 * π) = 0 :=
by simp [two_mul, sin_add]
@[simp] lemma cos_two_pi : cos (2 * π) = 1 :=
by simp [two_mul, cos_add]
lemma sin_add_pi (x : ℂ) : sin (x + π) = -sin x :=
by simp [sin_add]
lemma sin_add_two_pi (x : ℂ) : sin (x + 2 * π) = sin x :=
by simp [sin_add]
lemma cos_add_two_pi (x : ℂ) : cos (x + 2 * π) = cos x :=
by simp [cos_add]
lemma sin_pi_sub (x : ℂ) : sin (π - x) = sin x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi (x : ℂ) : cos (x + π) = -cos x :=
by simp [cos_add]
lemma cos_pi_sub (x : ℂ) : cos (π - x) = -cos x :=
by simp [sub_eq_add_neg, cos_add]
lemma sin_add_pi_div_two (x : ℂ) : sin (x + π / 2) = cos x :=
by simp [sin_add]
lemma sin_sub_pi_div_two (x : ℂ) : sin (x - π / 2) = -cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma sin_pi_div_two_sub (x : ℂ) : sin (π / 2 - x) = cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi_div_two (x : ℂ) : cos (x + π / 2) = -sin x :=
by simp [cos_add]
lemma cos_sub_pi_div_two (x : ℂ) : cos (x - π / 2) = sin x :=
by simp [sub_eq_add_neg, cos_add]
lemma cos_pi_div_two_sub (x : ℂ) : cos (π / 2 - x) = sin x :=
by rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
by induction n; simp [add_mul, sin_add, *]
lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
by cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi]
lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
by induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi]
lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
by cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe,
int.neg_succ_of_nat_coe, int.cast_coe_nat, int.cast_neg,
(neg_mul_eq_neg_mul _ _).symm, cos_neg]
lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 :=
by simp [cos_add, sin_add, cos_int_mul_two_pi]
lemma exp_pi_mul_I : exp (π * I) = -1 :=
by rw exp_mul_I; simp
theorem cos_eq_zero_iff {θ : ℂ} : cos θ = 0 ↔ ∃ k : ℤ, θ = (2 * k + 1) * π / 2 :=
begin
have h : (exp (θ * I) + exp (-θ * I)) / 2 = 0 ↔ exp (2 * θ * I) = -1,
{ rw [@div_eq_iff _ _ (exp (θ * I) + exp (-θ * I)) 2 0 two_ne_zero', zero_mul,
add_eq_zero_iff_eq_neg, neg_eq_neg_one_mul, ← div_eq_iff (exp_ne_zero _), ← exp_sub],
field_simp only, congr' 3, ring },
rw [cos, h, ← exp_pi_mul_I, exp_eq_exp_iff_exists_int, mul_right_comm],
refine exists_congr (λ x, _),
refine (iff_of_eq $ congr_arg _ _).trans (mul_right_inj' $ mul_ne_zero two_ne_zero' I_ne_zero),
ring,
end
theorem cos_ne_zero_iff {θ : ℂ} : cos θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ (2 * k + 1) * π / 2 :=
by rw [← not_exists, not_iff_not, cos_eq_zero_iff]
theorem sin_eq_zero_iff {θ : ℂ} : sin θ = 0 ↔ ∃ k : ℤ, θ = k * π :=
begin
rw [← complex.cos_sub_pi_div_two, cos_eq_zero_iff],
split,
{ rintros ⟨k, hk⟩,
use k + 1,
field_simp [eq_add_of_sub_eq hk],
ring },
{ rintros ⟨k, rfl⟩,
use k - 1,
field_simp,
ring }
end
theorem sin_ne_zero_iff {θ : ℂ} : sin θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ k * π :=
by rw [← not_exists, not_iff_not, sin_eq_zero_iff]
lemma sin_eq_zero_iff_cos_eq {z : ℂ} : sin z = 0 ↔ cos z = 1 ∨ cos z = -1 :=
by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq, sq, sq, ← sub_eq_iff_eq_add, sub_self];
exact ⟨λ h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ eq.symm⟩
lemma tan_eq_zero_iff {θ : ℂ} : tan θ = 0 ↔ ∃ k : ℤ, θ = k * π / 2 :=
begin
have h := (sin_two_mul θ).symm,
rw mul_assoc at h,
rw [tan, div_eq_zero_iff, ← mul_eq_zero, ← zero_mul ((1/2):ℂ), mul_one_div,
cancel_factors.cancel_factors_eq_div h two_ne_zero', mul_comm],
simpa only [zero_div, zero_mul, ne.def, not_false_iff] with field_simps using sin_eq_zero_iff,
end
lemma tan_ne_zero_iff {θ : ℂ} : tan θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ k * π / 2 :=
by rw [← not_exists, not_iff_not, tan_eq_zero_iff]
lemma tan_int_mul_pi_div_two (n : ℤ) : tan (n * π/2) = 0 :=
tan_eq_zero_iff.mpr (by use n)
lemma tan_int_mul_pi (n : ℤ) : tan (n * π) = 0 :=
by simp [tan, add_mul, sin_add, sin_int_mul_pi]
lemma cos_eq_cos_iff {x y : ℂ} :
cos x = cos y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x :=
calc cos x = cos y ↔ cos x - cos y = 0 : sub_eq_zero.symm
... ↔ -2 * sin((x + y)/2) * sin((x - y)/2) = 0 : by rw cos_sub_cos
... ↔ sin((x + y)/2) = 0 ∨ sin((x - y)/2) = 0 : by simp [(by norm_num : (2:ℂ) ≠ 0)]
... ↔ sin((x - y)/2) = 0 ∨ sin((x + y)/2) = 0 : or.comm
... ↔ (∃ k : ℤ, y = 2 * k * π + x) ∨ (∃ k :ℤ, y = 2 * k * π - x) :
begin
apply or_congr;
field_simp [sin_eq_zero_iff, (by norm_num : -(2:ℂ) ≠ 0), eq_sub_iff_add_eq',
sub_eq_iff_eq_add, mul_comm (2:ℂ), mul_right_comm _ (2:ℂ)],
split; { rintros ⟨k, rfl⟩, use -k, simp, },
end
... ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x : exists_or_distrib.symm
lemma sin_eq_sin_iff {x y : ℂ} :
sin x = sin y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = (2 * k + 1) * π - x :=
begin
simp only [← complex.cos_sub_pi_div_two, cos_eq_cos_iff, sub_eq_iff_eq_add],
refine exists_congr (λ k, or_congr _ _); refine eq.congr rfl _; field_simp; ring
end
lemma tan_add {x y : ℂ}
(h : ((∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2)
∨ ((∃ k : ℤ, x = (2 * k + 1) * π / 2) ∧ ∃ l : ℤ, y = (2 * l + 1) * π / 2)) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=
begin
rcases h with ⟨h1, h2⟩ | ⟨⟨k, rfl⟩, ⟨l, rfl⟩⟩,
{ rw [tan, sin_add, cos_add,
← div_div_div_cancel_right (sin x * cos y + cos x * sin y)
(mul_ne_zero (cos_ne_zero_iff.mpr h1) (cos_ne_zero_iff.mpr h2)),
add_div, sub_div],
simp only [←div_mul_div, ←tan, mul_one, one_mul,
div_self (cos_ne_zero_iff.mpr h1), div_self (cos_ne_zero_iff.mpr h2)] },
{ obtain ⟨t, hx, hy, hxy⟩ := ⟨tan_int_mul_pi_div_two, t (2*k+1), t (2*l+1), t (2*k+1+(2*l+1))⟩,
simp only [int.cast_add, int.cast_bit0, int.cast_mul, int.cast_one, hx, hy] at hx hy hxy,
rw [hx, hy, add_zero, zero_div,
mul_div_assoc, mul_div_assoc, ← add_mul (2*(k:ℂ)+1) (2*l+1) (π/2), ← mul_div_assoc, hxy] },
end
lemma tan_add' {x y : ℂ}
(h : ((∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2)) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=
tan_add (or.inl h)
lemma tan_two_mul {z : ℂ} : tan (2 * z) = 2 * tan z / (1 - tan z ^ 2) :=
begin
by_cases h : ∀ k : ℤ, z ≠ (2 * k + 1) * π / 2,
{ rw [two_mul, two_mul, sq, tan_add (or.inl ⟨h, h⟩)] },
{ rw not_forall_not at h,
rw [two_mul, two_mul, sq, tan_add (or.inr ⟨h, h⟩)] },
end
lemma tan_add_mul_I {x y : ℂ}
(h : ((∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y * I ≠ (2 * l + 1) * π / 2)
∨ ((∃ k : ℤ, x = (2 * k + 1) * π / 2) ∧ ∃ l : ℤ, y * I = (2 * l + 1) * π / 2)) :
tan (x + y*I) = (tan x + tanh y * I) / (1 - tan x * tanh y * I) :=
by rw [tan_add h, tan_mul_I, mul_assoc]
lemma tan_eq {z : ℂ}
(h : ((∀ k : ℤ, (z.re:ℂ) ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, (z.im:ℂ) * I ≠ (2 * l + 1) * π / 2)
∨ ((∃ k : ℤ, (z.re:ℂ) = (2 * k + 1) * π / 2) ∧ ∃ l : ℤ, (z.im:ℂ) * I = (2 * l + 1) * π / 2)) :
tan z = (tan z.re + tanh z.im * I) / (1 - tan z.re * tanh z.im * I) :=
by convert tan_add_mul_I h; exact (re_add_im z).symm
lemma has_strict_deriv_at_tan {x : ℂ} (h : cos x ≠ 0) :
has_strict_deriv_at tan (1 / (cos x)^2) x :=
begin
convert (has_strict_deriv_at_sin x).div (has_strict_deriv_at_cos x) h,
rw ← sin_sq_add_cos_sq x,
ring,
end
lemma has_deriv_at_tan {x : ℂ} (h : cos x ≠ 0) :
has_deriv_at tan (1 / (cos x)^2) x :=
(has_strict_deriv_at_tan h).has_deriv_at
lemma tendsto_abs_tan_of_cos_eq_zero {x : ℂ} (hx : cos x = 0) :
tendsto (λ x, abs (tan x)) (𝓝[{x}ᶜ] x) at_top :=
begin
simp only [tan_eq_sin_div_cos, ← norm_eq_abs, normed_field.norm_div],
have A : sin x ≠ 0 := λ h, by simpa [*, sq] using sin_sq_add_cos_sq x,
have B : tendsto cos (𝓝[{x}ᶜ] (x)) (𝓝[{0}ᶜ] 0),
{ refine tendsto_inf.2 ⟨tendsto.mono_left _ inf_le_left, tendsto_principal.2 _⟩,
exacts [continuous_cos.tendsto' x 0 hx,
hx ▸ (has_deriv_at_cos _).eventually_ne (neg_ne_zero.2 A)] },
exact continuous_sin.continuous_within_at.norm.mul_at_top (norm_pos_iff.2 A)
(tendsto_norm_nhds_within_zero.comp B).inv_tendsto_zero,
end
lemma tendsto_abs_tan_at_top (k : ℤ) :
tendsto (λ x, abs (tan x)) (𝓝[{(2 * k + 1) * π / 2}ᶜ] ((2 * k + 1) * π / 2)) at_top :=
tendsto_abs_tan_of_cos_eq_zero $ cos_eq_zero_iff.2 ⟨k, rfl⟩
@[simp] lemma continuous_at_tan {x : ℂ} : continuous_at tan x ↔ cos x ≠ 0 :=
begin
refine ⟨λ hc h₀, _, λ h, (has_deriv_at_tan h).continuous_at⟩,
exact not_tendsto_nhds_of_tendsto_at_top (tendsto_abs_tan_of_cos_eq_zero h₀) _
(hc.norm.tendsto.mono_left inf_le_left)
end
@[simp] lemma differentiable_at_tan {x : ℂ} : differentiable_at ℂ tan x ↔ cos x ≠ 0:=
⟨λ h, continuous_at_tan.1 h.continuous_at, λ h, (has_deriv_at_tan h).differentiable_at⟩
@[simp] lemma deriv_tan (x : ℂ) : deriv tan x = 1 / (cos x)^2 :=
if h : cos x = 0 then
have ¬differentiable_at ℂ tan x := mt differentiable_at_tan.1 (not_not.2 h),
by simp [deriv_zero_of_not_differentiable_at this, h, sq]
else (has_deriv_at_tan h).deriv
lemma continuous_on_tan : continuous_on tan {x | cos x ≠ 0} :=
continuous_on_sin.div continuous_on_cos $ λ x, id
@[continuity]
lemma continuous_tan : continuous (λ x : {x | cos x ≠ 0}, tan x) :=
continuous_on_iff_continuous_restrict.1 continuous_on_tan
@[simp] lemma times_cont_diff_at_tan {x : ℂ} {n : with_top ℕ} :
times_cont_diff_at ℂ n tan x ↔ cos x ≠ 0 :=
⟨λ h, continuous_at_tan.1 h.continuous_at,
times_cont_diff_sin.times_cont_diff_at.div times_cont_diff_cos.times_cont_diff_at⟩
lemma cos_eq_iff_quadratic {z w : ℂ} :
cos z = w ↔ (exp (z * I)) ^ 2 - 2 * w * exp (z * I) + 1 = 0 :=
begin
rw ← sub_eq_zero,
field_simp [cos, exp_neg, exp_ne_zero],
refine eq.congr _ rfl,
ring
end
lemma cos_surjective : function.surjective cos :=
begin
intro x,
obtain ⟨w, w₀, hw⟩ : ∃ w ≠ 0, 1 * w * w + (-2 * x) * w + 1 = 0,
{ rcases exists_quadratic_eq_zero one_ne_zero (exists_eq_mul_self _) with ⟨w, hw⟩,
refine ⟨w, _, hw⟩,
rintro rfl,
simpa only [zero_add, one_ne_zero, mul_zero] using hw },
refine ⟨log w / I, cos_eq_iff_quadratic.2 _⟩,
rw [div_mul_cancel _ I_ne_zero, exp_log w₀],
convert hw,
ring
end
@[simp] lemma range_cos : range cos = set.univ :=
cos_surjective.range_eq
lemma sin_surjective : function.surjective sin :=
begin
intro x,
rcases cos_surjective x with ⟨z, rfl⟩,
exact ⟨z + π / 2, sin_add_pi_div_two z⟩
end
@[simp] lemma range_sin : range sin = set.univ :=
sin_surjective.range_eq
end complex
section log_deriv
open complex
variables {α : Type*}
lemma measurable.carg [measurable_space α] {f : α → ℂ} (h : measurable f) :
measurable (λ x, arg (f x)) :=
measurable_arg.comp h
lemma measurable.clog [measurable_space α] {f : α → ℂ} (h : measurable f) :
measurable (λ x, log (f x)) :=
measurable_log.comp h
lemma filter.tendsto.clog {l : filter α} {f : α → ℂ} {x : ℂ} (h : tendsto f l (𝓝 x))
(hx : 0 < x.re ∨ x.im ≠ 0) :
tendsto (λ t, log (f t)) l (𝓝 $ log x) :=
(has_strict_deriv_at_log hx).continuous_at.tendsto.comp h
variables [topological_space α]
lemma continuous_at.clog {f : α → ℂ} {x : α} (h₁ : continuous_at f x)
(h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
continuous_at (λ t, log (f t)) x :=
h₁.clog h₂
lemma continuous_within_at.clog {f : α → ℂ} {s : set α} {x : α} (h₁ : continuous_within_at f s x)
(h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
continuous_within_at (λ t, log (f t)) s x :=
h₁.clog h₂
lemma continuous_on.clog {f : α → ℂ} {s : set α} (h₁ : continuous_on f s)
(h₂ : ∀ x ∈ s, 0 < (f x).re ∨ (f x).im ≠ 0) :
continuous_on (λ t, log (f t)) s :=
λ x hx, (h₁ x hx).clog (h₂ x hx)
lemma continuous.clog {f : α → ℂ} (h₁ : continuous f) (h₂ : ∀ x, 0 < (f x).re ∨ (f x).im ≠ 0) :
continuous (λ t, log (f t)) :=
continuous_iff_continuous_at.2 $ λ x, h₁.continuous_at.clog (h₂ x)
variables {E : Type*} [normed_group E] [normed_space ℂ E]
lemma has_strict_fderiv_at.clog {f : E → ℂ} {f' : E →L[ℂ] ℂ} {x : E}
(h₁ : has_strict_fderiv_at f f' x) (h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_strict_fderiv_at (λ t, log (f t)) ((f x)⁻¹ • f') x :=
(has_strict_deriv_at_log h₂).comp_has_strict_fderiv_at x h₁
lemma has_strict_deriv_at.clog {f : ℂ → ℂ} {f' x : ℂ} (h₁ : has_strict_deriv_at f f' x)
(h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_strict_deriv_at (λ t, log (f t)) (f' / f x) x :=
by { rw div_eq_inv_mul, exact (has_strict_deriv_at_log h₂).comp x h₁ }
lemma has_fderiv_at.clog {f : E → ℂ} {f' : E →L[ℂ] ℂ} {x : E}
(h₁ : has_fderiv_at f f' x) (h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_fderiv_at (λ t, log (f t)) ((f x)⁻¹ • f') x :=
(has_strict_deriv_at_log h₂).has_deriv_at.comp_has_fderiv_at x h₁
lemma has_deriv_at.clog {f : ℂ → ℂ} {f' x : ℂ} (h₁ : has_deriv_at f f' x)
(h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_deriv_at (λ t, log (f t)) (f' / f x) x :=
by { rw div_eq_inv_mul, exact (has_strict_deriv_at_log h₂).has_deriv_at.comp x h₁ }
lemma differentiable_at.clog {f : E → ℂ} {x : E} (h₁ : differentiable_at ℂ f x)
(h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
differentiable_at ℂ (λ t, log (f t)) x :=
(h₁.has_fderiv_at.clog h₂).differentiable_at
lemma has_fderiv_within_at.clog {f : E → ℂ} {f' : E →L[ℂ] ℂ} {s : set E} {x : E}
(h₁ : has_fderiv_within_at f f' s x) (h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_fderiv_within_at (λ t, log (f t)) ((f x)⁻¹ • f') s x :=
(has_strict_deriv_at_log h₂).has_deriv_at.comp_has_fderiv_within_at x h₁
lemma has_deriv_within_at.clog {f : ℂ → ℂ} {f' x : ℂ} {s : set ℂ}
(h₁ : has_deriv_within_at f f' s x) (h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_deriv_within_at (λ t, log (f t)) (f' / f x) s x :=
by { rw div_eq_inv_mul,
exact (has_strict_deriv_at_log h₂).has_deriv_at.comp_has_deriv_within_at x h₁ }
lemma differentiable_within_at.clog {f : E → ℂ} {s : set E} {x : E}
(h₁ : differentiable_within_at ℂ f s x) (h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
differentiable_within_at ℂ (λ t, log (f t)) s x :=
(h₁.has_fderiv_within_at.clog h₂).differentiable_within_at
lemma differentiable_on.clog {f : E → ℂ} {s : set E}
(h₁ : differentiable_on ℂ f s) (h₂ : ∀ x ∈ s, 0 < (f x).re ∨ (f x).im ≠ 0) :
differentiable_on ℂ (λ t, log (f t)) s :=
λ x hx, (h₁ x hx).clog (h₂ x hx)
lemma differentiable.clog {f : E → ℂ} (h₁ : differentiable ℂ f)
(h₂ : ∀ x, 0 < (f x).re ∨ (f x).im ≠ 0) :
differentiable ℂ (λ t, log (f t)) :=
λ x, (h₁ x).clog (h₂ x)
end log_deriv
namespace polynomial.chebyshev
open polynomial complex
/-- The `n`-th Chebyshev polynomial of the first kind evaluates on `cos θ` to the
value `cos (n * θ)`. -/
lemma T_complex_cos (θ : ℂ) :
∀ n, (T ℂ n).eval (cos θ) = cos (n * θ)
| 0 := by simp only [T_zero, eval_one, nat.cast_zero, zero_mul, cos_zero]
| 1 := by simp only [eval_X, one_mul, T_one, nat.cast_one]
| (n + 2) :=
begin
simp only [eval_X, eval_one, T_add_two, eval_sub, eval_bit0, nat.cast_succ, eval_mul],
rw [T_complex_cos (n + 1), T_complex_cos n],
have aux : sin θ * sin θ = 1 - cos θ * cos θ,
{ rw ← sin_sq_add_cos_sq θ, ring, },
simp only [nat.cast_add, nat.cast_one, add_mul, cos_add, one_mul, sin_add, mul_assoc, aux],
ring,
end
/-- `cos (n * θ)` is equal to the `n`-th Chebyshev polynomial of the first kind evaluated
on `cos θ`. -/
lemma cos_nat_mul (n : ℕ) (θ : ℂ) :
cos (n * θ) = (T ℂ n).eval (cos θ) :=
(T_complex_cos θ n).symm
/-- The `n`-th Chebyshev polynomial of the second kind evaluates on `cos θ` to the
value `sin ((n+1) * θ) / sin θ`. -/
lemma U_complex_cos (θ : ℂ) (n : ℕ) :
(U ℂ n).eval (cos θ) * sin θ = sin ((n+1) * θ) :=
begin
induction n with d hd,
{ simp only [U_zero, nat.cast_zero, eval_one, mul_one, zero_add, one_mul] },
{ rw U_eq_X_mul_U_add_T,
simp only [eval_add, eval_mul, eval_X, T_complex_cos, add_mul, mul_assoc, hd, one_mul],
conv_rhs { rw [sin_add, mul_comm] },
push_cast,
simp only [add_mul, one_mul] }
end
/-- `sin ((n + 1) * θ)` is equal to `sin θ` multiplied with the `n`-th Chebyshev polynomial of the
second kind evaluated on `cos θ`. -/
lemma sin_nat_succ_mul (n : ℕ) (θ : ℂ) :
sin ((n + 1) * θ) = (U ℂ n).eval (cos θ) * sin θ :=
(U_complex_cos θ n).symm
end polynomial.chebyshev
namespace real
open_locale real
lemma tan_add {x y : ℝ}
(h : ((∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2)
∨ ((∃ k : ℤ, x = (2 * k + 1) * π / 2) ∧ ∃ l : ℤ, y = (2 * l + 1) * π / 2)) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=
by simpa only [← complex.of_real_inj, complex.of_real_sub, complex.of_real_add, complex.of_real_div,
complex.of_real_mul, complex.of_real_tan]
using @complex.tan_add (x:ℂ) (y:ℂ) (by convert h; norm_cast)
lemma tan_add' {x y : ℝ}
(h : ((∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2)) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=
tan_add (or.inl h)
lemma tan_two_mul {x:ℝ} : tan (2 * x) = 2 * tan x / (1 - tan x ^ 2) :=
by simpa only [← complex.of_real_inj, complex.of_real_sub, complex.of_real_div, complex.of_real_pow,
complex.of_real_mul, complex.of_real_tan, complex.of_real_bit0, complex.of_real_one]
using complex.tan_two_mul
theorem cos_eq_zero_iff {θ : ℝ} : cos θ = 0 ↔ ∃ k : ℤ, θ = (2 * k + 1) * π / 2 :=
by exact_mod_cast @complex.cos_eq_zero_iff θ
theorem cos_ne_zero_iff {θ : ℝ} : cos θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ (2 * k + 1) * π / 2 :=
by rw [← not_exists, not_iff_not, cos_eq_zero_iff]
lemma tan_ne_zero_iff {θ : ℝ} : tan θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ k * π / 2 :=
by rw [← complex.of_real_ne_zero, complex.of_real_tan, complex.tan_ne_zero_iff]; norm_cast
lemma tan_eq_zero_iff {θ : ℝ} : tan θ = 0 ↔ ∃ k : ℤ, θ = k * π / 2 :=
by rw [← not_iff_not, not_exists, ← ne, tan_ne_zero_iff]
lemma tan_int_mul_pi_div_two (n : ℤ) : tan (n * π/2) = 0 :=
tan_eq_zero_iff.mpr (by use n)
lemma tan_int_mul_pi (n : ℤ) : tan (n * π) = 0 :=
by rw tan_eq_zero_iff; use (2*n); field_simp [mul_comm ((n:ℝ)*(π:ℝ)) 2, ← mul_assoc]
lemma cos_eq_cos_iff {x y : ℝ} :
cos x = cos y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x :=
by exact_mod_cast @complex.cos_eq_cos_iff x y
lemma sin_eq_sin_iff {x y : ℝ} :
sin x = sin y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = (2 * k + 1) * π - x :=
by exact_mod_cast @complex.sin_eq_sin_iff x y
lemma has_strict_deriv_at_tan {x : ℝ} (h : cos x ≠ 0) :
has_strict_deriv_at tan (1 / (cos x)^2) x :=
by exact_mod_cast (complex.has_strict_deriv_at_tan (by exact_mod_cast h)).real_of_complex
lemma has_deriv_at_tan {x : ℝ} (h : cos x ≠ 0) :
has_deriv_at tan (1 / (cos x)^2) x :=
by exact_mod_cast (complex.has_deriv_at_tan (by exact_mod_cast h)).real_of_complex
lemma tendsto_abs_tan_of_cos_eq_zero {x : ℝ} (hx : cos x = 0) :
tendsto (λ x, abs (tan x)) (𝓝[{x}ᶜ] x) at_top :=
begin
have hx : complex.cos x = 0, by exact_mod_cast hx,
simp only [← complex.abs_of_real, complex.of_real_tan],
refine (complex.tendsto_abs_tan_of_cos_eq_zero hx).comp _,
refine tendsto.inf complex.continuous_of_real.continuous_at _,
exact tendsto_principal_principal.2 (λ y, mt complex.of_real_inj.1)
end
lemma tendsto_abs_tan_at_top (k : ℤ) :
tendsto (λ x, abs (tan x)) (𝓝[{(2 * k + 1) * π / 2}ᶜ] ((2 * k + 1) * π / 2)) at_top :=
tendsto_abs_tan_of_cos_eq_zero $ cos_eq_zero_iff.2 ⟨k, rfl⟩
lemma continuous_at_tan {x : ℝ} : continuous_at tan x ↔ cos x ≠ 0 :=
begin
refine ⟨λ hc h₀, _, λ h, (has_deriv_at_tan h).continuous_at⟩,
exact not_tendsto_nhds_of_tendsto_at_top (tendsto_abs_tan_of_cos_eq_zero h₀) _
(hc.norm.tendsto.mono_left inf_le_left)
end
lemma differentiable_at_tan {x : ℝ} : differentiable_at ℝ tan x ↔ cos x ≠ 0 :=
⟨λ h, continuous_at_tan.1 h.continuous_at, λ h, (has_deriv_at_tan h).differentiable_at⟩
@[simp] lemma deriv_tan (x : ℝ) : deriv tan x = 1 / (cos x)^2 :=
if h : cos x = 0 then
have ¬differentiable_at ℝ tan x := mt differentiable_at_tan.1 (not_not.2 h),
by simp [deriv_zero_of_not_differentiable_at this, h, sq]
else (has_deriv_at_tan h).deriv
@[simp] lemma times_cont_diff_at_tan {n x} : times_cont_diff_at ℝ n tan x ↔ cos x ≠ 0 :=
⟨λ h, continuous_at_tan.1 h.continuous_at,
λ h, (complex.times_cont_diff_at_tan.2 $ by exact_mod_cast h).real_of_complex⟩
lemma continuous_on_tan : continuous_on tan {x | cos x ≠ 0} :=
λ x hx, (continuous_at_tan.2 hx).continuous_within_at
@[continuity]
lemma continuous_tan : continuous (λ x : {x | cos x ≠ 0}, tan x) :=
continuous_on_iff_continuous_restrict.1 continuous_on_tan
lemma has_deriv_at_tan_of_mem_Ioo {x : ℝ} (h : x ∈ Ioo (-(π/2):ℝ) (π/2)) :
has_deriv_at tan (1 / (cos x)^2) x :=
has_deriv_at_tan (cos_pos_of_mem_Ioo h).ne'
lemma differentiable_at_tan_of_mem_Ioo {x : ℝ} (h : x ∈ Ioo (-(π/2):ℝ) (π/2)) :
differentiable_at ℝ tan x :=
(has_deriv_at_tan_of_mem_Ioo h).differentiable_at
lemma continuous_on_tan_Ioo : continuous_on tan (Ioo (-(π/2)) (π/2)) :=
λ x hx, (differentiable_at_tan_of_mem_Ioo hx).continuous_at.continuous_within_at
lemma tendsto_sin_pi_div_two : tendsto sin (𝓝[Iio (π/2)] (π/2)) (𝓝 1) :=
by { convert continuous_sin.continuous_within_at, simp }
lemma tendsto_cos_pi_div_two : tendsto cos (𝓝[Iio (π/2)] (π/2)) (𝓝[Ioi 0] 0) :=
begin
apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within,
{ convert continuous_cos.continuous_within_at, simp },
{ filter_upwards [Ioo_mem_nhds_within_Iio (right_mem_Ioc.mpr (norm_num.lt_neg_pos
_ _ pi_div_two_pos pi_div_two_pos))] λ x hx, cos_pos_of_mem_Ioo hx },
end
lemma tendsto_tan_pi_div_two : tendsto tan (𝓝[Iio (π/2)] (π/2)) at_top :=
begin
convert tendsto_cos_pi_div_two.inv_tendsto_zero.at_top_mul zero_lt_one
tendsto_sin_pi_div_two,
simp only [pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos]
end
lemma tendsto_sin_neg_pi_div_two : tendsto sin (𝓝[Ioi (-(π/2))] (-(π/2))) (𝓝 (-1)) :=
by { convert continuous_sin.continuous_within_at, simp }
lemma tendsto_cos_neg_pi_div_two : tendsto cos (𝓝[Ioi (-(π/2))] (-(π/2))) (𝓝[Ioi 0] 0) :=
begin
apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within,
{ convert continuous_cos.continuous_within_at, simp },
{ filter_upwards [Ioo_mem_nhds_within_Ioi (left_mem_Ico.mpr (norm_num.lt_neg_pos
_ _ pi_div_two_pos pi_div_two_pos))] λ x hx, cos_pos_of_mem_Ioo hx },
end
lemma tendsto_tan_neg_pi_div_two : tendsto tan (𝓝[Ioi (-(π/2))] (-(π/2))) at_bot :=
begin
convert tendsto_cos_neg_pi_div_two.inv_tendsto_zero.at_top_mul_neg (by norm_num)
tendsto_sin_neg_pi_div_two,
simp only [pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos]
end
lemma surj_on_tan : surj_on tan (Ioo (-(π / 2)) (π / 2)) univ :=
have _ := neg_lt_self pi_div_two_pos,
continuous_on_tan_Ioo.surj_on_of_tendsto (nonempty_Ioo.2 this)
(by simp [tendsto_tan_neg_pi_div_two, this]) (by simp [tendsto_tan_pi_div_two, this])
lemma tan_surjective : function.surjective tan :=
λ x, surj_on_tan.subset_range trivial
lemma image_tan_Ioo : tan '' (Ioo (-(π / 2)) (π / 2)) = univ :=
univ_subset_iff.1 surj_on_tan
/-- `real.tan` as an `order_iso` between `(-(π / 2), π / 2)` and `ℝ`. -/
def tan_order_iso : Ioo (-(π / 2)) (π / 2) ≃o ℝ :=
(strict_mono_incr_on_tan.order_iso _ _).trans $ (order_iso.set_congr _ _ image_tan_Ioo).trans
order_iso.set.univ
/-- Inverse of the `tan` function, returns values in the range `-π / 2 < arctan x` and
`arctan x < π / 2` -/
@[pp_nodot] noncomputable def arctan (x : ℝ) : ℝ :=
tan_order_iso.symm x
@[simp] lemma tan_arctan (x : ℝ) : tan (arctan x) = x :=
tan_order_iso.apply_symm_apply x
lemma arctan_mem_Ioo (x : ℝ) : arctan x ∈ Ioo (-(π / 2)) (π / 2) :=
subtype.coe_prop _
lemma arctan_tan {x : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) : arctan (tan x) = x :=
subtype.ext_iff.1 $ tan_order_iso.symm_apply_apply ⟨x, hx₁, hx₂⟩
lemma cos_arctan_pos (x : ℝ) : 0 < cos (arctan x) :=
cos_pos_of_mem_Ioo $ arctan_mem_Ioo x
lemma cos_sq_arctan (x : ℝ) : cos (arctan x) ^ 2 = 1 / (1 + x ^ 2) :=
by rw [one_div, ← inv_one_add_tan_sq (cos_arctan_pos x).ne', tan_arctan]
lemma sin_arctan (x : ℝ) : sin (arctan x) = x / sqrt (1 + x ^ 2) :=
by rw [← tan_div_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan]
lemma cos_arctan (x : ℝ) : cos (arctan x) = 1 / sqrt (1 + x ^ 2) :=
by rw [one_div, ← inv_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan]
lemma arctan_lt_pi_div_two (x : ℝ) : arctan x < π / 2 :=
(arctan_mem_Ioo x).2
lemma neg_pi_div_two_lt_arctan (x : ℝ) : -(π / 2) < arctan x :=
(arctan_mem_Ioo x).1
lemma arctan_eq_arcsin (x : ℝ) : arctan x = arcsin (x / sqrt (1 + x ^ 2)) :=
eq.symm $ arcsin_eq_of_sin_eq (sin_arctan x) (mem_Icc_of_Ioo $ arctan_mem_Ioo x)
lemma arcsin_eq_arctan {x : ℝ} (h : x ∈ Ioo (-(1:ℝ)) 1) :
arcsin x = arctan (x / sqrt (1 - x ^ 2)) :=
begin
rw [arctan_eq_arcsin, div_pow, sq_sqrt, one_add_div, div_div_eq_div_mul,
← sqrt_mul, mul_div_cancel', sub_add_cancel, sqrt_one, div_one];
nlinarith [h.1, h.2],
end
@[simp] lemma arctan_zero : arctan 0 = 0 :=
by simp [arctan_eq_arcsin]
lemma arctan_eq_of_tan_eq {x y : ℝ} (h : tan x = y) (hx : x ∈ Ioo (-(π / 2)) (π / 2)) :
arctan y = x :=
inj_on_tan (arctan_mem_Ioo _) hx (by rw [tan_arctan, h])
@[simp] lemma arctan_one : arctan 1 = π / 4 :=
arctan_eq_of_tan_eq tan_pi_div_four $ by split; linarith [pi_pos]
@[simp] lemma arctan_neg (x : ℝ) : arctan (-x) = - arctan x :=
by simp [arctan_eq_arcsin, neg_div]
@[continuity]
lemma continuous_arctan : continuous arctan :=
continuous_subtype_coe.comp tan_order_iso.to_homeomorph.continuous_inv_fun
lemma continuous_at_arctan {x : ℝ} : continuous_at arctan x := continuous_arctan.continuous_at
/-- `real.tan` as a `local_homeomorph` between `(-(π / 2), π / 2)` and the whole line. -/
def tan_local_homeomorph : local_homeomorph ℝ ℝ :=
{ to_fun := tan,
inv_fun := arctan,
source := Ioo (-(π / 2)) (π / 2),
target := univ,
map_source' := maps_to_univ _ _,
map_target' := λ y hy, arctan_mem_Ioo y,
left_inv' := λ x hx, arctan_tan hx.1 hx.2,
right_inv' := λ y hy, tan_arctan y,
open_source := is_open_Ioo,
open_target := is_open_univ,
continuous_to_fun := continuous_on_tan_Ioo,
continuous_inv_fun := continuous_arctan.continuous_on }
@[simp] lemma coe_tan_local_homeomorph : ⇑tan_local_homeomorph = tan := rfl
@[simp] lemma coe_tan_local_homeomorph_symm : ⇑tan_local_homeomorph.symm = arctan := rfl
lemma has_strict_deriv_at_arctan (x : ℝ) : has_strict_deriv_at arctan (1 / (1 + x^2)) x :=
have A : cos (arctan x) ≠ 0 := (cos_arctan_pos x).ne',
by simpa [cos_sq_arctan]
using tan_local_homeomorph.has_strict_deriv_at_symm trivial (by simpa) (has_strict_deriv_at_tan A)
lemma has_deriv_at_arctan (x : ℝ) : has_deriv_at arctan (1 / (1 + x^2)) x :=
(has_strict_deriv_at_arctan x).has_deriv_at
lemma differentiable_at_arctan (x : ℝ) : differentiable_at ℝ arctan x :=
(has_deriv_at_arctan x).differentiable_at
lemma differentiable_arctan : differentiable ℝ arctan := differentiable_at_arctan
@[simp] lemma deriv_arctan : deriv arctan = (λ x, 1 / (1 + x^2)) :=
funext $ λ x, (has_deriv_at_arctan x).deriv
lemma times_cont_diff_arctan {n : with_top ℕ} : times_cont_diff ℝ n arctan :=
times_cont_diff_iff_times_cont_diff_at.2 $ λ x,
have cos (arctan x) ≠ 0 := (cos_arctan_pos x).ne',
tan_local_homeomorph.times_cont_diff_at_symm_deriv (by simpa) trivial (has_deriv_at_tan this)
(times_cont_diff_at_tan.2 this)
lemma measurable_arctan : measurable arctan := continuous_arctan.measurable
end real
section
/-!
### Lemmas for derivatives of the composition of `real.arctan` with a differentiable function
In this section we register lemmas for the derivatives of the composition of `real.arctan` with a
differentiable function, for standalone use and use with `simp`. -/
open real
lemma measurable.arctan {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, arctan (f x)) :=
measurable_arctan.comp hf
section deriv
variables {f : ℝ → ℝ} {f' x : ℝ} {s : set ℝ}
lemma has_strict_deriv_at.arctan (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, arctan (f x)) ((1 / (1 + (f x)^2)) * f') x :=
(real.has_strict_deriv_at_arctan (f x)).comp x hf
lemma has_deriv_at.arctan (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, arctan (f x)) ((1 / (1 + (f x)^2)) * f') x :=
(real.has_deriv_at_arctan (f x)).comp x hf
lemma has_deriv_within_at.arctan (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, arctan (f x)) ((1 / (1 + (f x)^2)) * f') s x :=
(real.has_deriv_at_arctan (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_arctan (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λ x, arctan (f x)) s x = (1 / (1 + (f x)^2)) * (deriv_within f s x) :=
hf.has_deriv_within_at.arctan.deriv_within hxs
@[simp] lemma deriv_arctan (hc : differentiable_at ℝ f x) :
deriv (λ x, arctan (f x)) x = (1 / (1 + (f x)^2)) * (deriv f x) :=
hc.has_deriv_at.arctan.deriv
end deriv
section fderiv
variables {E : Type*} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {f' : E →L[ℝ] ℝ} {x : E}
{s : set E} {n : with_top ℕ}
lemma has_strict_fderiv_at.arctan (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, arctan (f x)) ((1 / (1 + (f x)^2)) • f') x :=
(has_strict_deriv_at_arctan (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.arctan (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, arctan (f x)) ((1 / (1 + (f x)^2)) • f') x :=
(has_deriv_at_arctan (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.arctan (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, arctan (f x)) ((1 / (1 + (f x)^2)) • f') s x :=
(has_deriv_at_arctan (f x)).comp_has_fderiv_within_at x hf
lemma fderiv_within_arctan (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
fderiv_within ℝ (λ x, arctan (f x)) s x = (1 / (1 + (f x)^2)) • (fderiv_within ℝ f s x) :=
hf.has_fderiv_within_at.arctan.fderiv_within hxs
@[simp] lemma fderiv_arctan (hc : differentiable_at ℝ f x) :
fderiv ℝ (λ x, arctan (f x)) x = (1 / (1 + (f x)^2)) • (fderiv ℝ f x) :=
hc.has_fderiv_at.arctan.fderiv
lemma differentiable_within_at.arctan (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.arctan (f x)) s x :=
hf.has_fderiv_within_at.arctan.differentiable_within_at
@[simp] lemma differentiable_at.arctan (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λ x, arctan (f x)) x :=
hc.has_fderiv_at.arctan.differentiable_at
lemma differentiable_on.arctan (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λ x, arctan (f x)) s :=
λ x h, (hc x h).arctan
@[simp] lemma differentiable.arctan (hc : differentiable ℝ f) :
differentiable ℝ (λ x, arctan (f x)) :=
λ x, (hc x).arctan
lemma times_cont_diff_at.arctan (h : times_cont_diff_at ℝ n f x) :
times_cont_diff_at ℝ n (λ x, arctan (f x)) x :=
times_cont_diff_arctan.times_cont_diff_at.comp x h
lemma times_cont_diff.arctan (h : times_cont_diff ℝ n f) :
times_cont_diff ℝ n (λ x, arctan (f x)) :=
times_cont_diff_arctan.comp h
lemma times_cont_diff_within_at.arctan (h : times_cont_diff_within_at ℝ n f s x) :
times_cont_diff_within_at ℝ n (λ x, arctan (f x)) s x :=
times_cont_diff_arctan.comp_times_cont_diff_within_at h
lemma times_cont_diff_on.arctan (h : times_cont_diff_on ℝ n f s) :
times_cont_diff_on ℝ n (λ x, arctan (f x)) s :=
times_cont_diff_arctan.comp_times_cont_diff_on h
end fderiv
end
|
theory "Differential_Axioms"
imports
Ordinary_Differential_Equations.ODE_Analysis
"Ids"
"Lib"
"Syntax"
"Denotational_Semantics"
"Frechet_Correctness"
"Axioms"
"Coincidence"
begin context ids begin
section \<open>Differential Axioms\<close>
text \<open>Differential axioms fall into two categories:
Axioms for computing the derivatives of terms and axioms for proving properties of ODEs.
The derivative axioms are all corollaries of the frechet correctness theorem. The ODE
axioms are more involved, often requiring extensive use of the ODE libraries.\<close>
subsection \<open>Derivative Axioms\<close>
definition diff_const_axiom :: "('sf, 'sc, 'sz) formula"
where [axiom_defs]:"diff_const_axiom \<equiv> Equals (Differential ($f fid1 empty)) (Const 0)"
definition diff_var_axiom :: "('sf, 'sc, 'sz) formula"
where [axiom_defs]:"diff_var_axiom \<equiv> Equals (Differential (Var vid1)) (DiffVar vid1)"
definition state_fun ::"'sf \<Rightarrow> ('sf, 'sz) trm"
where [axiom_defs]:"state_fun f = ($f f (\<lambda>i. Var i))"
definition diff_plus_axiom :: "('sf, 'sc, 'sz) formula"
where [axiom_defs]:"diff_plus_axiom \<equiv> Equals (Differential (Plus (state_fun fid1) (state_fun fid2)))
(Plus (Differential (state_fun fid1)) (Differential (state_fun fid2)))"
definition diff_times_axiom :: "('sf, 'sc, 'sz) formula"
where [axiom_defs]:"diff_times_axiom \<equiv> Equals (Differential (Times (state_fun fid1) (state_fun fid2)))
(Plus (Times (Differential (state_fun fid1)) (state_fun fid2))
(Times (state_fun fid1) (Differential (state_fun fid2))))"
\<comment> \<open>\<open>[y=g(x)][y'=1](f(g(x))' = f(y)')\<close>\<close>
definition diff_chain_axiom::"('sf, 'sc, 'sz) formula"
where [axiom_defs]:"diff_chain_axiom \<equiv> [[Assign vid2 (f1 fid2 vid1)]]([[DiffAssign vid2 (Const 1)]]
(Equals (Differential ($f fid1 (singleton (f1 fid2 vid1)))) (Times (Differential (f1 fid1 vid2)) (Differential (f1 fid2 vid1)))))"
subsection \<open>ODE Axioms\<close>
definition DWaxiom :: "('sf, 'sc, 'sz) formula"
where [axiom_defs]:"DWaxiom = ([[EvolveODE (OVar vid1) (Predicational pid1)]](Predicational pid1))"
definition DWaxiom' :: "('sf, 'sc, 'sz) formula"
where [axiom_defs]:"DWaxiom' = ([[EvolveODE (OSing vid1 (Function fid1 (singleton (Var vid1)))) (Prop vid2 (singleton (Var vid1)))]](Prop vid2 (singleton (Var vid1))))"
definition DCaxiom :: "('sf, 'sc, 'sz) formula"
where [axiom_defs]:"DCaxiom = (
([[EvolveODE (OVar vid1) (Predicational pid1)]]Predicational pid3) \<rightarrow>
(([[EvolveODE (OVar vid1) (Predicational pid1)]](Predicational pid2))
\<leftrightarrow>
([[EvolveODE (OVar vid1) (And (Predicational pid1) (Predicational pid3))]]Predicational pid2)))"
definition DEaxiom :: "('sf, 'sc, 'sz) formula"
where [axiom_defs]:"DEaxiom =
(([[EvolveODE (OSing vid1 (f1 fid1 vid1)) (p1 vid2 vid1)]] (P pid1))
\<leftrightarrow>
([[EvolveODE (OSing vid1 (f1 fid1 vid1)) (p1 vid2 vid1)]]
[[DiffAssign vid1 (f1 fid1 vid1)]]P pid1))"
definition DSaxiom :: "('sf, 'sc, 'sz) formula"
where [axiom_defs]:"DSaxiom =
(([[EvolveODE (OSing vid1 (f0 fid1)) (p1 vid2 vid1)]]p1 vid3 vid1)
\<leftrightarrow>
(Forall vid2
(Implies (Geq (Var vid2) (Const 0))
(Implies
(Forall vid3
(Implies (And (Geq (Var vid3) (Const 0)) (Geq (Var vid2) (Var vid3)))
(Prop vid2 (singleton (Plus (Var vid1) (Times (f0 fid1) (Var vid3)))))))
([[Assign vid1 (Plus (Var vid1) (Times (f0 fid1) (Var vid2)))]]p1 vid3 vid1)))))"
\<comment> \<open>\<open>(Q \<rightarrow> [c&Q](f(x)' \<ge> g(x)'))\<close>\<close>
\<comment> \<open>\<open>\<rightarrow>\<close>\<close>
\<comment> \<open>\<open>([c&Q](f(x) \<ge> g(x))) --> (Q \<rightarrow> (f(x) \<ge> g(x))\<close>\<close>
definition DIGeqaxiom :: "('sf, 'sc, 'sz) formula"
where [axiom_defs]:"DIGeqaxiom =
Implies
(Implies (Prop vid1 empty) ([[EvolveODE (OVar vid1) (Prop vid1 empty)]](Geq (Differential (f1 fid1 vid1)) (Differential (f1 fid2 vid1)))))
(Implies
(Implies(Prop vid1 empty) (Geq (f1 fid1 vid1) (f1 fid2 vid1)))
([[EvolveODE (OVar vid1) (Prop vid1 empty)]](Geq (f1 fid1 vid1) (f1 fid2 vid1))))"
\<comment> \<open>\<open>g(x) > h(x) \<rightarrow> [x'=f(x), c & p(x)](g(x)' \<ge> h(x)') \<rightarrow> [x'=f(x), c & p(x)]g(x) > h(x)\<close>\<close>
\<comment> \<open>\<open>(Q \<rightarrow> [c&Q](f(x)' \<ge> g(x)'))\<close>\<close>
\<comment> \<open>\<open>\<rightarrow>\<close>\<close>
\<comment> \<open>\<open>([c&Q](f(x) > g(x))) <-> (Q \<rightarrow> (f(x) > g(x))\<close>\<close>
definition DIGraxiom :: "('sf, 'sc, 'sz) formula"
where [axiom_defs]:"DIGraxiom =
Implies
(Implies (Prop vid1 empty) ([[EvolveODE (OVar vid1) (Prop vid1 empty)]](Geq (Differential (f1 fid1 vid1)) (Differential (f1 fid2 vid1)))))
(Implies
(Implies(Prop vid1 empty) (Greater (f1 fid1 vid1) (f1 fid2 vid1)))
([[EvolveODE (OVar vid1) (Prop vid1 empty)]](Greater (f1 fid1 vid1) (f1 fid2 vid1))))"
\<comment> \<open>\<open>[{1' = 1(1) & 1(1)}]2(1) <->\<close>\<close>
\<comment> \<open>\<open>\<exists>2. [{1'=1(1), 2' = 2(1)*2 + 3(1) & 1(1)}]2(1)*)\<close>\<close>
definition DGaxiom :: "('sf, 'sc, 'sz) formula"
where [axiom_defs]:"DGaxiom = (([[EvolveODE (OSing vid1 (f1 fid1 vid1)) (p1 vid1 vid1)]]p1 vid2 vid1) \<leftrightarrow>
(Exists vid2
([[EvolveODE (OProd (OSing vid1 (f1 fid1 vid1)) (OSing vid2 (Plus (Times (f1 fid2 vid1) (Var vid2)) (f1 fid3 vid1)))) (p1 vid1 vid1)]]
p1 vid2 vid1)))"
subsection \<open>Proofs for Derivative Axioms\<close>
lemma constant_deriv_inner:
assumes interp:"\<forall>x i. (Functions I i has_derivative FunctionFrechet I i x) (at x)"
shows "FunctionFrechet I id1 (vec_lambda (\<lambda>i. sterm_sem I (empty i) (fst \<nu>))) (vec_lambda(\<lambda>i. frechet I (empty i) (fst \<nu>) (snd \<nu>)))= 0"
proof -
have empty_zero:"(vec_lambda(\<lambda>i. frechet I (empty i) (fst \<nu>) (snd \<nu>))) = 0"
using local.empty_def Cart_lambda_cong frechet.simps(5) zero_vec_def
apply auto
apply(rule vec_extensionality)
using local.empty_def Cart_lambda_cong frechet.simps(5) zero_vec_def
by (simp add: local.empty_def)
let ?x = "(vec_lambda (\<lambda>i. sterm_sem I (empty i) (fst \<nu>)))"
from interp
have has_deriv:"(Functions I id1 has_derivative FunctionFrechet I id1 ?x) (at ?x)"
by auto
then have f_linear:"linear (FunctionFrechet I id1 ?x)"
using Deriv.has_derivative_linear by auto
then show ?thesis using empty_zero f_linear linear_0 by (auto)
qed
lemma constant_deriv_zero:"is_interp I \<Longrightarrow> directional_derivative I ($f id1 empty) \<nu> = 0"
apply(simp only: is_interp_def directional_derivative_def frechet.simps frechet_correctness)
apply(rule constant_deriv_inner)
apply(auto)
done
theorem diff_const_axiom_valid: "valid diff_const_axiom"
apply(simp only: valid_def diff_const_axiom_def equals_sem)
apply(rule allI | rule impI)+
apply(simp only: dterm_sem.simps constant_deriv_zero sterm_sem.simps)
done
theorem diff_var_axiom_valid: "valid diff_var_axiom"
apply(auto simp add: diff_var_axiom_def valid_def directional_derivative_def)
by (metis inner_prod_eq)
theorem diff_plus_axiom_valid: "valid diff_plus_axiom"
apply(auto simp add: diff_plus_axiom_def valid_def)
subgoal for I a b
using frechet_correctness[of I "(Plus (state_fun fid1) (state_fun fid2))" b]
unfolding state_fun_def apply (auto intro: dfree.intros)
unfolding directional_derivative_def by auto
done
theorem diff_times_axiom_valid: "valid diff_times_axiom"
apply(auto simp add: diff_times_axiom_def valid_def)
subgoal for I a b
using frechet_correctness[of I "(Times (state_fun fid1) (state_fun fid2))" b]
unfolding state_fun_def apply (auto intro: dfree.intros)
unfolding directional_derivative_def by auto
done
subsection \<open>Proofs for ODE Axioms\<close>
lemma DW_valid:"valid DWaxiom"
apply(unfold DWaxiom_def valid_def Let_def impl_sem )
apply(safe)
apply(auto simp only: fml_sem.simps prog_sem.simps box_sem)
subgoal for I aa ba ab bb sol t using mk_v_agree[of I "(OVar vid1)" "(ab,bb)" "sol t"]
Vagree_univ[of "aa" "ba" "sol t" "ODEs I vid1 (sol t)"] solves_ode_domainD
by (fastforce)
done
lemma DE_lemma:
fixes ab bb::"'sz simple_state"
and sol::"real \<Rightarrow> 'sz simple_state"
and I::"('sf, 'sc, 'sz) interp"
shows
"repd (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)) vid1 (dterm_sem I (f1 fid1 vid1) (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)))
= mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)"
proof
have set_eq:" {Inl vid1, Inr vid1} = {Inr vid1, Inl vid1}" by auto
have agree:"Vagree (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)) (mk_xode I (OSing vid1 (f1 fid1 vid1)) (sol t))
{Inl vid1, Inr vid1}"
using mk_v_agree[of I "(OSing vid1 (f1 fid1 vid1))" "(ab, bb)" "(sol t)"]
unfolding semBV.simps using set_eq by auto
have fact:"dterm_sem I (f1 fid1 vid1) (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t))
= snd (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)) $ vid1"
using agree unfolding Vagree_def dterm_sem.simps f1_def mk_xode.simps
proof -
assume alls:"(\<forall>i. Inl i \<in> {Inl vid1, Inr vid1} \<longrightarrow>
fst (mk_v I (OSing vid1 ($f fid1 (singleton (trm.Var vid1)))) (ab, bb) (sol t)) $ i =
fst (sol t, ODE_sem I (OSing vid1 ($f fid1 (singleton (trm.Var vid1)))) (sol t)) $ i) \<and>
(\<forall>i. Inr i \<in> {Inl vid1, Inr vid1} \<longrightarrow>
snd (mk_v I (OSing vid1 ($f fid1 (singleton (trm.Var vid1)))) (ab, bb) (sol t)) $ i =
snd (sol t, ODE_sem I (OSing vid1 ($f fid1 (singleton (trm.Var vid1)))) (sol t)) $ i)"
hence atVid'':"snd (mk_v I (OSing vid1 ($f fid1 (singleton (trm.Var vid1)))) (ab, bb) (sol t)) $ vid1 = sterm_sem I ($f fid1 (singleton (trm.Var vid1))) (sol t)"
by auto
have argsEq:"(\<chi> i. dterm_sem I (singleton (trm.Var vid1) i)
(mk_v I (OSing vid1 ($f fid1 (singleton (trm.Var vid1)))) (ab, bb) (sol t)))
= (\<chi> i. sterm_sem I (singleton (trm.Var vid1) i) (sol t))"
using alls f1_def by auto
thus "Functions I fid1 (\<chi> i. dterm_sem I (singleton (trm.Var vid1) i)
(mk_v I (OSing vid1 ($f fid1 (singleton (trm.Var vid1)))) (ab, bb) (sol t)))
= snd (mk_v I (OSing vid1 ($f fid1 (singleton (trm.Var vid1)))) (ab, bb) (sol t)) $ vid1"
by (simp only: atVid'' ODE_sem.simps sterm_sem.simps dterm_sem.simps)
qed
have eqSnd:"(\<chi> y. if vid1 = y then snd (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)) $ vid1
else snd (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)) $ y) = snd (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t))"
by (simp add: vec_extensionality)
have truth:"repd (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)) vid1
(dterm_sem I (f1 fid1 vid1) (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)))
= mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)"
using fact by (auto simp only: eqSnd repd.simps fact prod.collapse split: if_split)
thus "fst (repd (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)) vid1
(dterm_sem I (f1 fid1 vid1) (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)))) =
fst (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t))"
"snd (repd (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)) vid1
(dterm_sem I (f1 fid1 vid1) (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)))) =
snd (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)) "
by auto
qed
lemma DE_valid:"valid DEaxiom"
proof -
have dsafe:"dsafe ($f fid1 (singleton (trm.Var vid1)))" unfolding singleton_def by(auto intro: dsafe.intros)
have osafe:"osafe(OSing vid1 (f1 fid1 vid1))" unfolding f1_def empty_def singleton_def using dsafe osafe.intros dsafe.intros
by (simp add: osafe_Sing dfree_Const)
have fsafe:"fsafe (p1 vid2 vid1)" unfolding p1_def singleton_def using hpsafe_fsafe.intros(10)
using dsafe dsafe_Fun_simps image_iff
by (simp add: dfree_Const)
show "valid DEaxiom"
apply(auto simp only: DEaxiom_def valid_def Let_def iff_sem impl_sem)
apply(auto simp only: fml_sem.simps prog_sem.simps mem_Collect_eq box_sem)
proof -
fix I::"('sf,'sc,'sz) interp"
and aa ba ab bb sol
and t::real
and ac bc
assume "is_interp I"
assume allw:"\<forall>\<omega>. (\<exists>\<nu> sol t.
((ab, bb), \<omega>) = (\<nu>, mk_v I (OSing vid1 (f1 fid1 vid1)) \<nu> (sol t)) \<and>
0 \<le> t \<and>
(sol solves_ode (\<lambda>_. ODE_sem I (OSing vid1 (f1 fid1 vid1)))) {0..t}
{x. mk_v I (OSing vid1 (f1 fid1 vid1)) \<nu> x \<in> fml_sem I (p1 vid2 vid1)} \<and>
(sol 0) = (fst \<nu>) ) \<longrightarrow>
\<omega> \<in> fml_sem I (P pid1)"
assume t:"0 \<le> t"
assume aaba:"(aa, ba) = mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)"
assume solve:" (sol solves_ode (\<lambda>_. ODE_sem I (OSing vid1 (f1 fid1 vid1)))) {0..t}
{x. mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) x \<in> fml_sem I (p1 vid2 vid1)}"
assume sol0:" (sol 0) = (fst (ab, bb)) "
assume rep:" (ac, bc) =
repd (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)) vid1
(dterm_sem I (f1 fid1 vid1) (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)))"
have aaba_sem:"(aa,ba) \<in> fml_sem I (P pid1)" using allw t aaba solve sol0 rep by blast
have truth:"repd (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)) vid1
(dterm_sem I (f1 fid1 vid1) (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)))
= mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)"
using DE_lemma by auto
show "
repd (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)) vid1
(dterm_sem I (f1 fid1 vid1) (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)))
\<in> fml_sem I (P pid1)" using aaba aaba_sem truth by (auto)
next
fix I::"('sf,'sc,'sz) interp" and aa ba ab bb sol and t::real
assume "is_interp I"
assume all:"\<forall>\<omega>. (\<exists>\<nu> sol t.
((ab, bb), \<omega>) = (\<nu>, mk_v I (OSing vid1 (f1 fid1 vid1)) \<nu> (sol t)) \<and>
0 \<le> t \<and>
(sol solves_ode (\<lambda>_. ODE_sem I (OSing vid1 (f1 fid1 vid1)))) {0..t}
{x. mk_v I (OSing vid1 (f1 fid1 vid1)) \<nu> x \<in> fml_sem I (p1 vid2 vid1)} \<and>
(sol 0) = (fst \<nu>) ) \<longrightarrow>
(\<forall>\<omega>'. \<omega>' = repd \<omega> vid1 (dterm_sem I (f1 fid1 vid1) \<omega>) \<longrightarrow> \<omega>' \<in> fml_sem I (P pid1))"
hence justW:"(\<exists>\<nu> sol t.
((ab, bb), (aa, ba)) = (\<nu>, mk_v I (OSing vid1 (f1 fid1 vid1)) \<nu> (sol t)) \<and>
0 \<le> t \<and>
(sol solves_ode (\<lambda>_. ODE_sem I (OSing vid1 (f1 fid1 vid1)))) {0..t}
{x. mk_v I (OSing vid1 (f1 fid1 vid1)) \<nu> x \<in> fml_sem I (p1 vid2 vid1)} \<and>
(sol 0) = (fst \<nu>)) \<longrightarrow>
(\<forall>\<omega>'. \<omega>' = repd (aa, ba) vid1 (dterm_sem I (f1 fid1 vid1) (aa, ba)) \<longrightarrow> \<omega>' \<in> fml_sem I (P pid1))"
by (rule allE)
assume t:"0 \<le> t"
assume aaba:"(aa, ba) = mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)"
assume sol:"(sol solves_ode (\<lambda>_. ODE_sem I (OSing vid1 (f1 fid1 vid1)))) {0..t}
{x. mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) x \<in> fml_sem I (p1 vid2 vid1)}"
assume sol0:" (sol 0) = (fst (ab, bb))"
have "repd (aa, ba) vid1 (dterm_sem I (f1 fid1 vid1) (aa, ba)) \<in> fml_sem I (P pid1)"
using justW t aaba sol sol0 by auto
hence foo:"repd (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)) vid1 (dterm_sem I (f1 fid1 vid1) (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t))) \<in> fml_sem I (P pid1)"
using aaba by auto
hence "repd (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)) vid1 (dterm_sem I (f1 fid1 vid1) (mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)))
= mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t)" using DE_lemma by auto
thus "mk_v I (OSing vid1 (f1 fid1 vid1)) (ab, bb) (sol t) \<in> fml_sem I (P pid1)" using foo by auto
qed
qed
lemma ODE_zero:"\<And>i. Inl i \<notin> BVO ODE \<Longrightarrow> Inr i \<notin> BVO ODE \<Longrightarrow> ODE_sem I ODE \<nu> $ i= 0"
by(induction ODE, auto)
lemma DE_sys_valid:
assumes disj:"{Inl vid1, Inr vid1} \<inter> BVO ODE = {}"
shows "valid (([[EvolveODE (OProd (OSing vid1 (f1 fid1 vid1)) ODE) (p1 vid2 vid1)]] (P pid1)) \<leftrightarrow>
([[EvolveODE ((OProd (OSing vid1 (f1 fid1 vid1))ODE)) (p1 vid2 vid1)]]
[[DiffAssign vid1 (f1 fid1 vid1)]]P pid1))"
proof -
have dsafe:"dsafe ($f fid1 (singleton (trm.Var vid1)))" unfolding singleton_def by(auto intro: dsafe.intros)
have osafe:"osafe(OSing vid1 (f1 fid1 vid1))" unfolding f1_def empty_def singleton_def using dsafe osafe.intros dsafe.intros
by (simp add: osafe_Sing dfree_Const)
have fsafe:"fsafe (p1 vid2 vid1)" unfolding p1_def singleton_def using hpsafe_fsafe.intros(10)
using dsafe dsafe_Fun_simps image_iff
by (simp add: dfree_Const)
show "valid (([[EvolveODE (OProd (OSing vid1 (f1 fid1 vid1)) ODE) (p1 vid2 vid1)]] (P pid1)) \<leftrightarrow>
([[EvolveODE ((OProd (OSing vid1 (f1 fid1 vid1)) ODE)) (p1 vid2 vid1)]]
[[DiffAssign vid1 (f1 fid1 vid1)]]P pid1))"
apply(auto simp only: DEaxiom_def valid_def Let_def iff_sem impl_sem)
apply(auto simp only: fml_sem.simps prog_sem.simps mem_Collect_eq box_sem f1_def p1_def P_def expand_singleton)
proof -
fix I ::"('sf,'sc,'sz) interp"
and aa ba ab bb sol
and t::real
and ac bc
assume good:"is_interp I"
assume bigAll:"
\<forall>\<omega>. (\<exists>\<nu> sol t. ((ab, bb), \<omega>) = (\<nu>, mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) ODE) \<nu> (sol t)) \<and>
0 \<le> t \<and>
(sol solves_ode (\<lambda>_. ODE_sem I (OProd(OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) ODE ))) {0..t}
{x. Predicates I vid2
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) \<nu> x))} \<and>
sol 0 = fst \<nu>) \<longrightarrow>
\<omega> \<in> fml_sem I (Pc pid1)"
let ?my\<omega> = "mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab,bb) (sol t)"
assume t:"0 \<le> t"
assume aaba:"(aa, ba) = mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) (sol t)"
assume sol:"(sol solves_ode (\<lambda>_. ODE_sem I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE))) {0..t}
{x. Predicates I vid2
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) x))}"
assume sol0:"sol 0 = fst (ab, bb)"
assume acbc:"(ac, bc) =
repd (mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) (sol t)) vid1
(dterm_sem I ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) (sol t)))"
have bigEx:"(\<exists>\<nu> sol t. ((ab, bb), ?my\<omega>) = (\<nu>, mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) \<nu> (sol t)) \<and>
0 \<le> t \<and>
(sol solves_ode (\<lambda>_. ODE_sem I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE))) {0..t}
{x. Predicates I vid2
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) \<nu> x))} \<and>
sol 0 = fst \<nu>)"
apply(rule exI[where x="(ab, bb)"])
apply(rule exI[where x="sol"])
apply(rule exI[where x="t"])
apply(rule conjI)
apply(rule refl)
apply(rule conjI)
apply(rule t)
apply(rule conjI)
using sol apply blast
by (rule sol0)
have bigRes:"?my\<omega> \<in> fml_sem I (Pc pid1)" using bigAll bigEx by blast
have notin1:"Inl vid1 \<notin> BVO ODE" using disj by auto
have notin2:"Inr vid1 \<notin> BVO ODE" using disj by auto
have ODE_sem:"ODE_sem I ODE (sol t) $ vid1 = 0"
using ODE_zero notin1 notin2
by blast
have vec_eq:"(\<chi> i. sterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) (sol t)) =
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) (sol t)))"
apply(rule vec_extensionality)
apply simp
using mk_v_agree[of I "(OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE)" "(ab, bb)" "(sol t)"]
by(simp add: Vagree_def)
have sem_eq:"(?my\<omega> \<in> fml_sem I (Pc pid1)) = ((repd (mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) (sol t)) vid1
(dterm_sem I ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) (sol t)))) \<in> fml_sem I (Pc pid1))"
apply(rule coincidence_formula)
subgoal by simp
subgoal by (rule Iagree_refl)
using mk_v_agree[of "I" "(OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE)" "(ab, bb)" "(sol t)"]
unfolding Vagree_def
apply simp
apply(erule conjE)+
apply(erule allE[where x="vid1"])+
apply(simp add: ODE_sem)
using vec_eq by simp
show "repd (mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) (sol t)) vid1
(dterm_sem I ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) (sol t)))
\<in> fml_sem I (Pc pid1)"
using bigRes sem_eq by blast
next
fix I::"('sf,'sc,'sz)interp"
and aa ba ab bb sol
and t::real
assume good_interp:"is_interp I"
assume all:"\<forall>\<omega>. (\<exists>\<nu> sol t. ((ab, bb), \<omega>) = (\<nu>, mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) \<nu> (sol t)) \<and>
0 \<le> t \<and>
(sol solves_ode (\<lambda>_. ODE_sem I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE))) {0..t}
{x. Predicates I vid2
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) \<nu> x))} \<and>
sol 0 = fst \<nu>) \<longrightarrow>
(\<forall>\<omega>'. \<omega>' = repd \<omega> vid1 (dterm_sem I ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) \<omega>) \<longrightarrow> \<omega>' \<in> fml_sem I (Pc pid1))"
let ?my\<omega> = "mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) (sol t)"
assume t:"0 \<le> t"
assume aaba:"(aa, ba) = mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) (sol t)"
assume sol:"
(sol solves_ode (\<lambda>_. ODE_sem I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE))) {0..t}
{x. Predicates I vid2
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) x))}"
assume sol0:"sol 0 = fst (ab, bb)"
have bigEx:"(\<exists>\<nu> sol t. ((ab, bb), ?my\<omega>) = (\<nu>, mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) \<nu> (sol t)) \<and>
0 \<le> t \<and>
(sol solves_ode (\<lambda>_. ODE_sem I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE))) {0..t}
{x. Predicates I vid2
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) \<nu> x))} \<and>
sol 0 = fst \<nu>)"
apply(rule exI[where x="(ab, bb)"])
apply(rule exI[where x=sol])
apply(rule exI[where x=t])
apply(rule conjI)
apply(rule refl)
apply(rule conjI)
apply(rule t)
apply(rule conjI)
using sol sol0 by(blast)+
have rep_sem_eq:"repd (mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) (sol t)) vid1
(dterm_sem I ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) (sol t))) \<in> fml_sem I (Pc pid1)
= (repd ?my\<omega> vid1 (dterm_sem I ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) ?my\<omega>) \<in> fml_sem I (Pc pid1))"
apply(rule coincidence_formula)
subgoal by simp
subgoal by (rule Iagree_refl)
by(simp add: Vagree_def)
have notin1:"Inl vid1 \<notin> BVO ODE" using disj by auto
have notin2:"Inr vid1 \<notin> BVO ODE" using disj by auto
have ODE_sem:"ODE_sem I ODE (sol t) $ vid1 = 0"
using ODE_zero notin1 notin2
by blast
have vec_eq:"
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) (sol t))) =
(\<chi> i. sterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) (sol t))"
apply(rule vec_extensionality)
using mk_v_agree[of I "(OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE)" "(ab, bb)" "(sol t)"]
by (simp add: Vagree_def)
have sem_eq:
"(repd ?my\<omega> vid1 (dterm_sem I ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) ?my\<omega>) \<in> fml_sem I (Pc pid1))
= (mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) (sol t) \<in> fml_sem I (Pc pid1)) "
apply(rule coincidence_formula)
subgoal by simp
subgoal by (rule Iagree_refl)
using mk_v_agree[of I "(OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE)" "(ab, bb)" "(sol t)"]
unfolding Vagree_def apply simp
apply(erule conjE)+
apply(erule allE[where x=vid1])+
by (simp add: ODE_sem vec_eq)
have some_sem:"repd (mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) (sol t)) vid1
(dterm_sem I ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) (sol t))) \<in> fml_sem I (Pc pid1)"
using rep_sem_eq
using all bigEx by blast
have bigImp:"(\<forall>\<omega>'. \<omega>' = repd ?my\<omega> vid1 (dterm_sem I ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) ?my\<omega>) \<longrightarrow> \<omega>' \<in> fml_sem I (Pc pid1))"
apply(rule allI)
apply(rule impI)
apply auto
using some_sem by auto
have fml_sem:"repd ?my\<omega> vid1 (dterm_sem I ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) ?my\<omega>) \<in> fml_sem I (Pc pid1)"
using sem_eq bigImp by blast
show "mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))ODE) (ab, bb) (sol t) \<in> fml_sem I (Pc pid1)"
using fml_sem sem_eq by blast
qed
qed
lemma DC_valid:"valid DCaxiom"
proof (auto simp only: fml_sem.simps prog_sem.simps DCaxiom_def valid_def iff_sem impl_sem box_sem, auto)
fix I::"('sf,'sc,'sz) interp" and aa ba bb sol t
assume "is_interp I"
and all3:"\<forall>a b. (\<exists>sola. sol 0 = sola 0 \<and>
(\<exists>t. (a, b) = mk_v I (OVar vid1) (sola 0, bb) (sola t) \<and>
0 \<le> t \<and> (sola solves_ode (\<lambda>a. ODEs I vid1)) {0..t} {x. mk_v I (OVar vid1) (sola 0, bb) x \<in> Contexts I pid1 UNIV})) \<longrightarrow>
(a, b) \<in> Contexts I pid3 UNIV"
and all2:"\<forall>a b. (\<exists>sola. sol 0 = sola 0 \<and>
(\<exists>t. (a, b) = mk_v I (OVar vid1) (sola 0, bb) (sola t) \<and>
0 \<le> t \<and> (sola solves_ode (\<lambda>a. ODEs I vid1)) {0..t} {x. mk_v I (OVar vid1) (sola 0, bb) x \<in> Contexts I pid1 UNIV})) \<longrightarrow>
(a, b) \<in> Contexts I pid2 UNIV"
and t:"0 \<le> t"
and aaba:"(aa, ba) = mk_v I (OVar vid1) (sol 0, bb) (sol t)"
and sol:"(sol solves_ode (\<lambda>a. ODEs I vid1)) {0..t}
{x. mk_v I (OVar vid1) (sol 0, bb) x \<in> Contexts I pid1 UNIV \<and> mk_v I (OVar vid1) (sol 0, bb) x \<in> Contexts I pid3 UNIV}"
from sol have
sol1:"(sol solves_ode (\<lambda>a. ODEs I vid1)) {0..t} {x. mk_v I (OVar vid1) (sol 0, bb) x \<in> Contexts I pid1 UNIV}"
by (metis (mono_tags, lifting) Collect_mono solves_ode_supset_range)
from all2 have all2':"\<And>v. (\<exists>sola. sol 0 = sola 0 \<and>
(\<exists>t. v = mk_v I (OVar vid1) (sola 0, bb) (sola t) \<and>
0 \<le> t \<and> (sola solves_ode (\<lambda>a. ODEs I vid1)) {0..t} {x. mk_v I (OVar vid1) (sola 0, bb) x \<in> Contexts I pid1 UNIV})) \<Longrightarrow>
v \<in> Contexts I pid2 UNIV" by auto
show "mk_v I (OVar vid1) (sol 0, bb) (sol t) \<in> Contexts I pid2 UNIV"
apply(rule all2'[of "mk_v I (OVar vid1) (sol 0, bb) (sol t)"])
apply(rule exI[where x=sol])
apply(rule conjI)
subgoal by (rule refl)
subgoal using t sol1 by auto
done
next
fix I::"('sf,'sc,'sz) interp" and aa ba bb sol t
assume "is_interp I"
and all3:"\<forall>a b. (\<exists>sola. sol 0 = sola 0 \<and>
(\<exists>t. (a, b) = mk_v I (OVar vid1) (sola 0, bb) (sola t) \<and>
0 \<le> t \<and> (sola solves_ode (\<lambda>a. ODEs I vid1)) {0..t} {x. mk_v I (OVar vid1) (sola 0, bb) x \<in> Contexts I pid1 UNIV})) \<longrightarrow>
(a, b) \<in> Contexts I pid3 UNIV"
and all2:"\<forall>a b. (\<exists>sola. sol 0 = sola 0 \<and>
(\<exists>t. (a, b) = mk_v I (OVar vid1) (sola 0, bb) (sola t) \<and>
0 \<le> t \<and>
(sola solves_ode (\<lambda>a. ODEs I vid1)) {0..t}
{x. mk_v I (OVar vid1) (sola 0, bb) x \<in> Contexts I pid1 UNIV \<and>
mk_v I (OVar vid1) (sola 0, bb) x \<in> Contexts I pid3 UNIV})) \<longrightarrow>
(a, b) \<in> Contexts I pid2 UNIV"
and t:"0 \<le> t"
and aaba:"(aa, ba) = mk_v I (OVar vid1) (sol 0, bb) (sol t)"
and sol:"(sol solves_ode (\<lambda>a. ODEs I vid1)) {0..t} {x. mk_v I (OVar vid1) (sol 0, bb) x \<in> Contexts I pid1 UNIV}"
from all2
have all2':"\<And>v. (\<exists>sola. sol 0 = sola 0 \<and>
(\<exists>t. v = mk_v I (OVar vid1) (sola 0, bb) (sola t) \<and>
0 \<le> t \<and>
(sola solves_ode (\<lambda>a. ODEs I vid1)) {0..t}
{x. mk_v I (OVar vid1) (sola 0, bb) x \<in> Contexts I pid1 UNIV \<and>
mk_v I (OVar vid1) (sola 0, bb) x \<in> Contexts I pid3 UNIV})) \<Longrightarrow>
v \<in> Contexts I pid2 UNIV"
by auto
from all3
have all3':"\<And>v. (\<exists>sola. sol 0 = sola 0 \<and>
(\<exists>t. v = mk_v I (OVar vid1) (sola 0, bb) (sola t) \<and>
0 \<le> t \<and> (sola solves_ode (\<lambda>a. ODEs I vid1)) {0..t} {x. mk_v I (OVar vid1) (sola 0, bb) x \<in> Contexts I pid1 UNIV})) \<Longrightarrow>
v \<in> Contexts I pid3 UNIV"
by auto
have inp1:"\<And>s. 0 \<le> s \<Longrightarrow> s \<le> t \<Longrightarrow> mk_v I (OVar vid1) (sol 0, bb) (sol s) \<in> Contexts I pid1 UNIV"
using sol solves_odeD atLeastAtMost_iff by blast
have inp3:"\<And>s. 0 \<le> s \<Longrightarrow> s \<le> t \<Longrightarrow> mk_v I (OVar vid1) (sol 0, bb) (sol s) \<in> Contexts I pid3 UNIV"
apply(rule all3')
subgoal for s
apply(rule exI [where x=sol])
apply(rule conjI)
subgoal by (rule refl)
apply(rule exI [where x=s])
apply(rule conjI)
subgoal by (rule refl)
apply(rule conjI)
subgoal by assumption
subgoal using sol by (meson atLeastatMost_subset_iff order_refl solves_ode_subset)
done
done
have inp13:"\<And>s. 0 \<le> s \<Longrightarrow> s \<le> t \<Longrightarrow> mk_v I (OVar vid1) (sol 0, bb) (sol s) \<in> Contexts I pid1 UNIV \<and> mk_v I (OVar vid1) (sol 0, bb) (sol s) \<in> Contexts I pid3 UNIV"
using inp1 inp3 by auto
have sol13:"(sol solves_ode (\<lambda>a. ODEs I vid1)) {0..t}
{x. mk_v I (OVar vid1) (sol 0, bb) x \<in> Contexts I pid1 UNIV \<and> mk_v I (OVar vid1) (sol 0, bb) x \<in> Contexts I pid3 UNIV}"
apply(rule solves_odeI)
subgoal using sol by (rule solves_odeD)
subgoal for s using inp13[of s] by auto
done
show "mk_v I (OVar vid1) (sol 0, bb) (sol t) \<in> Contexts I pid2 UNIV"
using t sol13 all2'[of "mk_v I (OVar vid1) (sol 0, bb) (sol t)"] by auto
qed
lemma DS_valid:"valid DSaxiom"
proof -
have dsafe:"dsafe($f fid1 (\<lambda>i. Const 0))"
using dsafe_Const by auto
have osafe:"osafe(OSing vid1 (f0 fid1))"
unfolding f0_def empty_def
using dsafe osafe.intros
by (simp add: osafe_Sing dfree_Const)
have fsafe:"fsafe(p1 vid2 vid1)"
unfolding p1_def
apply(rule fsafe_Prop)
using singleton.simps dsafe_Const by (auto intro: dfree.intros)
show "valid DSaxiom"
apply(auto simp only: DSaxiom_def valid_def Let_def iff_sem impl_sem box_sem)
apply(auto simp only: fml_sem.simps prog_sem.simps mem_Collect_eq iff_sem impl_sem box_sem forall_sem)
proof -
fix I::"('sf,'sc,'sz) interp"
and a b r aa ba
assume good_interp:"is_interp I"
assume allW:"\<forall>\<omega>. (\<exists>\<nu> sol t.
((a, b), \<omega>) = (\<nu>, mk_v I (OSing vid1 (f0 fid1)) \<nu> (sol t)) \<and>
0 \<le> t \<and>
(sol solves_ode (\<lambda>_. ODE_sem I (OSing vid1 (f0 fid1)))) {0..t}
{x. mk_v I (OSing vid1 (f0 fid1)) \<nu> x \<in> fml_sem I (p1 vid2 vid1)} \<and>
(sol 0) = (fst \<nu>)) \<longrightarrow>
\<omega> \<in> fml_sem I (p1 vid3 vid1)"
assume "dterm_sem I (Const 0) (repv (a, b) vid2 r) \<le> dterm_sem I (trm.Var vid2) (repv (a, b) vid2 r)"
hence leq:"0 \<le> r" by (auto)
assume "\<forall>ra. repv (repv (a, b) vid2 r) vid3 ra
\<in> {v. dterm_sem I (Const 0) v \<le> dterm_sem I (trm.Var vid3) v} \<inter>
{v. dterm_sem I (trm.Var vid3) v \<le> dterm_sem I (trm.Var vid2) v} \<longrightarrow>
Predicates I vid2
(\<chi> i. dterm_sem I (singleton (Plus (trm.Var vid1) (Times (f0 fid1) (trm.Var vid3))) i)
(repv (repv (a, b) vid2 r) vid3 ra))"
hence constraint:"\<forall>ra. (0 \<le> ra \<and> ra \<le> r) \<longrightarrow>
(repv (repv (a, b) vid2 r) vid3 ra)
\<in> fml_sem I (Prop vid2 (singleton (Plus (Var vid1) (Times (f0 fid1) (Var vid3)))))"
using leq by auto
assume aaba:" (aa, ba) =
repv (repv (a, b) vid2 r) vid1
(dterm_sem I (Plus (trm.Var vid1) (Times (f0 fid1) (trm.Var vid2))) (repv (a, b) vid2 r))"
let ?abba = "repv (repd (a, b) vid1 (Functions I fid1 (\<chi> i. 0))) vid1
(dterm_sem I (Plus (trm.Var vid1) (Times (f0 fid1) (trm.Var vid2))) (repv (a, b) vid2 r))"
from allW have thisW:"(\<exists>\<nu> sol t.
((a, b), ?abba) = (\<nu>, mk_v I (OSing vid1 (f0 fid1)) \<nu> (sol t)) \<and>
0 \<le> t \<and>
(sol solves_ode (\<lambda>_. ODE_sem I (OSing vid1 (f0 fid1)))) {0..t}
{x. mk_v I (OSing vid1 (f0 fid1)) \<nu> x \<in> fml_sem I (p1 vid2 vid1)} \<and>
(sol 0) = (fst \<nu>)) \<longrightarrow>
?abba \<in> fml_sem I (p1 vid3 vid1)" by blast
let ?c = "Functions I fid1 (\<chi> _. 0)"
let ?sol = "(\<lambda>t. \<chi> i. if i = vid1 then (a $ i) + ?c * t else (a $ i))"
have agrees:"Vagree (mk_v I (OSing vid1 (f0 fid1)) (a, b) (?sol r)) (a, b) (- semBV I (OSing vid1 (f0 fid1)))
\<and> Vagree (mk_v I (OSing vid1 (f0 fid1)) (a, b) (?sol r))
(mk_xode I (OSing vid1 (f0 fid1)) (?sol r)) (semBV I (OSing vid1 (f0 fid1)))"
using mk_v_agree[of "I" "(OSing vid1 (f0 fid1))" "(a,b)" "(?sol r)"] by auto
have prereq1a:"fst ?abba
= fst (mk_v I (OSing vid1 (f0 fid1)) (a,b) (?sol r))"
using agrees aaba
apply (auto simp add: aaba Vagree_def)
apply (rule vec_extensionality)
subgoal for i
apply (cases "i = vid1")
using vne12 agrees Vagree_def apply (auto simp add: aaba f0_def empty_def)
done
apply (rule vec_extensionality)
subgoal for i
apply (cases "i = vid1")
apply(auto simp add: f0_def empty_def)
done
done
have prereq1b:"snd (?abba) = snd (mk_v I (OSing vid1 (f0 fid1)) (a,b) (?sol r))"
using agrees aaba
apply (auto simp add: aaba Vagree_def)
apply (rule vec_extensionality)
subgoal for i
apply (cases "i = vid1")
using vne12 agrees Vagree_def apply (auto simp add: aaba f0_def empty_def )
done
done
have "?abba = mk_v I (OSing vid1 (f0 fid1)) (a,b) (?sol r)"
using prod_eq_iff prereq1a prereq1b by blast
hence req1:"((a, b), ?abba) = ((a, b), mk_v I (OSing vid1 (f0 fid1)) (a,b) (?sol r))" by auto
have "sterm_sem I ($f fid1 (\<lambda>i. Const 0)) b = Functions I fid1 (\<chi> i. 0)" by auto
hence vec_simp:"(\<lambda>a b. \<chi> i. if i = vid1 then sterm_sem I ($f fid1 (\<lambda>i. Const 0)) b else 0)
= (\<lambda>a b. \<chi> i. if i = vid1 then Functions I fid1 (\<chi> i. 0) else 0)"
by (auto simp add: vec_eq_iff cong: if_cong)
have sub: "{0..r} \<subseteq> UNIV" by auto
have sub2:"{x. mk_v I (OSing vid1 (f0 fid1)) (a,b) x \<in> fml_sem I (p1 vid2 vid1)} \<subseteq> UNIV" by auto
have req3:"(?sol solves_ode (\<lambda>_. ODE_sem I (OSing vid1 (f0 fid1)))) {0..r}
{x. mk_v I (OSing vid1 (f0 fid1)) (a,b) x \<in> fml_sem I (p1 vid2 vid1)}"
apply(auto simp add: f0_def empty_def vec_simp)
apply(rule solves_odeI)
apply(auto simp only: has_vderiv_on_def has_vector_derivative_def box_sem)
apply (rule has_derivative_vec[THEN has_derivative_eq_rhs])
defer
apply (rule ext)
apply (subst scaleR_vec_def)
apply (rule refl)
apply (auto intro!: derivative_eq_intros)
\<comment> \<open>Domain constraint satisfied\<close>
using constraint apply (auto)
subgoal for t
apply(erule allE[where x="t"])
apply(auto simp add: p1_def)
proof -
have eq:"(\<chi> i. dterm_sem I (if i = vid1 then Plus (trm.Var vid1) (Times (f0 fid1) (trm.Var vid3)) else Const 0)
(\<chi> y. if vid3 = y then t else fst (\<chi> y. if vid2 = y then r else fst (a, b) $ y, b) $ y, b)) =
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OSing vid1 ($f fid1 (\<lambda>i. Const 0))) (a, b)
(\<chi> i. if i = vid1 then a $ i + Functions I fid1 (\<chi> _. 0) * t else a $ i)))"
using vne12 vne13 mk_v_agree[of "I" "(OSing vid1 ($f fid1 (\<lambda>i. Const 0)))" "(a, b)" "(\<chi> i. if i = vid1 then a $ i + Functions I fid1 (\<chi> _. 0) * t else a $ i)"]
by (auto simp add: vec_eq_iff f0_def empty_def Vagree_def)
show "0 \<le> t \<Longrightarrow>
t \<le> r \<Longrightarrow>
Predicates I vid2
(\<chi> i. dterm_sem I (if i = vid1 then Plus (trm.Var vid1) (Times (f0 fid1) (trm.Var vid3)) else Const 0)
(\<chi> y. if vid3 = y then t else fst (\<chi> y. if vid2 = y then r else fst (a, b) $ y, b) $ y, b)) \<Longrightarrow>
Predicates I vid2
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OSing vid1 ($f fid1 (\<lambda>i. Const 0))) (a, b)
(\<chi> i. if i = vid1 then a $ i + Functions I fid1 (\<chi> _. 0) * t else a $ i)))"
using eq by auto
qed
done
have req4':"?sol 0 = fst (a,b)" by (auto simp: vec_eq_iff)
then have req4: " (?sol 0) = (fst (a,b))"
using VSagree_refl[of a] req4' unfolding VSagree_def by auto
have inPred:"?abba \<in> fml_sem I (p1 vid3 vid1)"
using req1 leq req3 req4 thisW by fastforce
have sem_eq:"?abba \<in> fml_sem I (p1 vid3 vid1) \<longleftrightarrow> (aa,ba) \<in> fml_sem I (p1 vid3 vid1)"
apply (rule coincidence_formula)
apply (auto simp add: aaba Vagree_def p1_def f0_def empty_def)
subgoal using Iagree_refl by auto
done
from inPred sem_eq have inPred':"(aa,ba) \<in> fml_sem I (p1 vid3 vid1)"
by auto
\<comment> \<open>thus by lemma 6 consequence for formulas\<close>
show "repv (repv (a, b) vid2 r) vid1
(dterm_sem I (Plus (trm.Var vid1) (Times (f0 fid1) (trm.Var vid2))) (repv (a, b) vid2 r))
\<in> fml_sem I (p1 vid3 vid1)"
using aaba inPred' by (auto)
next
fix I::"('sf,'sc,'sz) interp"
and aa ba ab bb sol
and t:: real
assume good_interp:"is_interp I"
assume all:"
\<forall>r. dterm_sem I (Const 0) (repv (ab, bb) vid2 r) \<le> dterm_sem I (trm.Var vid2) (repv (ab, bb) vid2 r) \<longrightarrow>
(\<forall>ra. repv (repv (ab, bb) vid2 r) vid3 ra
\<in> {v. dterm_sem I (Const 0) v \<le> dterm_sem I (trm.Var vid3) v} \<inter>
{v. dterm_sem I (trm.Var vid3) v \<le> dterm_sem I (trm.Var vid2) v} \<longrightarrow>
Predicates I vid2
(\<chi> i. dterm_sem I (singleton (Plus (trm.Var vid1) (Times (f0 fid1) (trm.Var vid3))) i)
(repv (repv (ab, bb) vid2 r) vid3 ra))) \<longrightarrow>
(\<forall>\<omega>. \<omega> = repv (repv (ab, bb) vid2 r) vid1
(dterm_sem I (Plus (trm.Var vid1) (Times (f0 fid1) (trm.Var vid2))) (repv (ab, bb) vid2 r)) \<longrightarrow>
\<omega> \<in> fml_sem I (p1 vid3 vid1))"
assume t:"0 \<le> t"
assume aaba:"(aa, ba) = mk_v I (OSing vid1 (f0 fid1)) (ab, bb) (sol t)"
assume sol:"(sol solves_ode (\<lambda>_. ODE_sem I (OSing vid1 (f0 fid1)))) {0..t}
{x. mk_v I (OSing vid1 (f0 fid1)) (ab, bb) x \<in> fml_sem I (p1 vid2 vid1)}"
hence constraint:"\<And>s. s \<in> {0 .. t} \<Longrightarrow> sol s \<in> {x. mk_v I (OSing vid1 (f0 fid1)) (ab, bb) x \<in> fml_sem I (p1 vid2 vid1)}"
using solves_ode_domainD by fastforce
\<comment> \<open>\<open>sol 0 = fst (ab, bb)\<close>\<close>
assume sol0:" (sol 0) = (fst (ab, bb)) "
have impl:"dterm_sem I (Const 0) (repv (ab, bb) vid2 t) \<le> dterm_sem I (trm.Var vid2) (repv (ab, bb) vid2 t) \<longrightarrow>
(\<forall>ra. repv (repv (ab, bb) vid2 t) vid3 ra
\<in> {v. dterm_sem I (Const 0) v \<le> dterm_sem I (trm.Var vid3) v} \<inter>
{v. dterm_sem I (trm.Var vid3) v \<le> dterm_sem I (trm.Var vid2) v} \<longrightarrow>
Predicates I vid2
(\<chi> i. dterm_sem I (singleton (Plus (trm.Var vid1) (Times (f0 fid1) (trm.Var vid3))) i)
(repv (repv (ab, bb) vid2 t) vid3 ra))) \<longrightarrow>
(\<forall>\<omega>. \<omega> = repv (repv (ab, bb) vid2 t) vid1
(dterm_sem I (Plus (trm.Var vid1) (Times (f0 fid1) (trm.Var vid2))) (repv (ab, bb) vid2 t)) \<longrightarrow>
\<omega> \<in> fml_sem I (p1 vid3 vid1))" using all by auto
interpret ll:ll_on_open_it UNIV "(\<lambda>_. ODE_sem I (OSing vid1 (f0 fid1)))" "UNIV" 0
apply(standard)
apply(auto)
unfolding local_lipschitz_def f0_def empty_def sterm_sem.simps
using gt_ex lipschitz_on_constant by blast
have eq_UNIV:"ll.existence_ivl 0 (sol 0) = UNIV"
apply(rule ll.existence_ivl_eq_domain)
apply(auto)
subgoal for tm tM t
apply(unfold f0_def empty_def sterm_sem.simps)
by(metis add.right_neutral mult_zero_left order_refl)
done
\<comment> \<open>Combine with \<open>flow_usolves_ode\<close> and \<open>equals_flowI\<close> to get uniqueness of solution\<close>
let ?f = "(\<lambda>_. ODE_sem I (OSing vid1 (f0 fid1)))"
have sol_UNIV: "\<And>t x. (ll.flow 0 x usolves_ode ?f from 0) (ll.existence_ivl 0 x) UNIV"
using ll.flow_usolves_ode by auto
from sol have sol':
"(sol solves_ode (\<lambda>_. ODE_sem I (OSing vid1 (f0 fid1)))) {0..t} UNIV"
apply (rule solves_ode_supset_range)
by auto
from sol' have sol'':"\<And>s. s \<ge> 0 \<Longrightarrow> s \<le> t \<Longrightarrow> (sol solves_ode (\<lambda>_. ODE_sem I (OSing vid1 (f0 fid1)))) {0..s} UNIV"
by (simp add: solves_ode_subset)
have sol0_eq:"sol 0 = ll.flow 0 (sol 0) 0"
using ll.general.flow_initial_time_if by auto
have isFlow:"\<And>s. s \<ge> 0 \<Longrightarrow> s \<le> t \<Longrightarrow> sol s = ll.flow 0 (sol 0) s"
apply(rule ll.equals_flowI)
apply(auto)
subgoal using eq_UNIV by auto
subgoal using sol'' closed_segment_eq_real_ivl t by (auto simp add: solves_ode_singleton)
subgoal using eq_UNIV sol sol0_eq by auto
done
let ?c = "Functions I fid1 (\<chi> _. 0)"
let ?sol = "(\<lambda>t. \<chi> i. if i = vid1 then (ab $ i) + ?c * t else (ab $ i))"
have vec_simp:"(\<lambda>a b. \<chi> i. if i = vid1 then sterm_sem I ($f fid1 (\<lambda>i. Const 0)) b else 0)
= (\<lambda>a b. \<chi> i. if i = vid1 then Functions I fid1 (\<chi> i. 0) else 0)"
by (auto simp add: vec_eq_iff cong: if_cong)
have exp_sol:"(?sol solves_ode (\<lambda>_. ODE_sem I (OSing vid1 (f0 fid1)))) {0..t}
UNIV"
apply(auto simp add: f0_def empty_def vec_simp)
apply(rule solves_odeI)
apply(auto simp only: has_vderiv_on_def has_vector_derivative_def box_sem)
apply (rule has_derivative_vec[THEN has_derivative_eq_rhs])
defer
apply (rule ext)
apply (subst scaleR_vec_def)
apply (rule refl)
apply (auto intro!: derivative_eq_intros)
done
from exp_sol have exp_sol':"\<And>s. s \<ge> 0 \<Longrightarrow> s \<le> t \<Longrightarrow> (?sol solves_ode (\<lambda>_. ODE_sem I (OSing vid1 (f0 fid1)))) {0..s} UNIV"
by (simp add: solves_ode_subset)
have exp_sol0_eq:"?sol 0 = ll.flow 0 (?sol 0) 0"
using ll.general.flow_initial_time_if by auto
have more_eq:"(\<chi> i. if i = vid1 then ab $ i + Functions I fid1 (\<chi> _. 0) * 0 else ab $ i) = sol 0"
using sol0
apply auto
apply(rule vec_extensionality)
by(auto)
have exp_isFlow:"\<And>s. s \<ge> 0 \<Longrightarrow> s \<le> t \<Longrightarrow> ?sol s = ll.flow 0 (sol 0) s"
apply(rule ll.equals_flowI)
apply(auto)
subgoal using eq_UNIV by auto
defer
subgoal for s
using eq_UNIV apply auto
subgoal using exp_sol exp_sol0_eq more_eq
apply(auto)
done
done
using exp_sol' closed_segment_eq_real_ivl t apply(auto)
by (simp add: solves_ode_singleton)
have sol_eq_exp:"\<And>s. s \<ge> 0 \<Longrightarrow> s \<le> t \<Longrightarrow> ?sol s = sol s"
unfolding exp_isFlow isFlow by auto
then have sol_eq_exp_t:"?sol t = sol t"
using t by auto
then have sol_eq_exp_t':"sol t $ vid1 = ?sol t $ vid1" by auto
then have useful:"?sol t $ vid1 = ab $ vid1 + Functions I fid1 (\<chi> i. 0) * t"
by auto
from sol_eq_exp_t' useful have useful':"sol t $ vid1 = ab $ vid1 + Functions I fid1 (\<chi> i. 0) * t"
by auto
have sol_int:"((ll.flow 0 (sol 0)) usolves_ode ?f from 0) {0..t} {x. mk_v I (OSing vid1 (f0 fid1)) (ab, bb) x \<in> fml_sem I (p1 vid2 vid1)}"
apply (rule usolves_ode_subset_range[of "(ll.flow 0 (sol 0))" "?f" "0" "{0..t}" "UNIV" "{x. mk_v I (OSing vid1 (f0 fid1)) (ab, bb) x \<in> fml_sem I (p1 vid2 vid1)}"])
subgoal using eq_UNIV sol_UNIV[of "(sol 0)"] apply (auto)
apply (rule usolves_ode_subset)
using t by(auto)
apply(auto)
using sol apply(auto dest!: solves_ode_domainD)
subgoal for xa using isFlow[of xa] by(auto)
done
have thing:"\<And>s. 0 \<le> s \<Longrightarrow> s \<le> t \<Longrightarrow> fst (mk_v I (OSing vid1 ($f fid1 (\<lambda>i. Const 0))) (ab, bb) (?sol s)) $ vid1 = ab $ vid1 + Functions I fid1 (\<chi> i. 0) * s"
subgoal for s
using mk_v_agree[of I "(OSing vid1 ($f fid1 (\<lambda>i. Const 0)))" "(ab, bb)" "(?sol s)"] apply auto
unfolding Vagree_def by auto
done
have thing':"\<And>s. 0 \<le> s \<Longrightarrow> s \<le> t \<Longrightarrow> fst (mk_v I (OSing vid1 ($f fid1 (\<lambda>i. Const 0))) (ab, bb) (sol s)) $ vid1 = ab $ vid1 + Functions I fid1 (\<chi> i. 0) * s"
subgoal for s using thing[of s] sol_eq_exp[of s] by auto done
have another_eq:"\<And>i s. 0 \<le> s \<Longrightarrow> s \<le> t \<Longrightarrow> dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OSing vid1 (f0 fid1)) (ab, bb) (sol s))
= dterm_sem I (if i = vid1 then Plus (trm.Var vid1) (Times (f0 fid1) (trm.Var vid3)) else Const 0)
(\<chi> y. if vid3 = y then s else fst (\<chi> y. if vid2 = y then s else fst (ab, bb) $ y, bb) $ y, bb)"
using mk_v_agree[of "I" "(OSing vid1 (f0 fid1))" "(ab, bb)" "(sol s)"] vne12 vne23 vne13
apply(auto simp add: f0_def p1_def empty_def)
unfolding Vagree_def apply(simp add: f0_def empty_def)
subgoal for s using thing' by auto
done
have allRa':"(\<forall>ra. repv (repv (ab, bb) vid2 t) vid3 ra
\<in> {v. dterm_sem I (Const 0) v \<le> dterm_sem I (trm.Var vid3) v} \<inter>
{v. dterm_sem I (trm.Var vid3) v \<le> dterm_sem I (trm.Var vid2) v} \<longrightarrow>
Predicates I vid2
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OSing vid1 (f0 fid1)) (ab, bb) (sol ra))))"
apply(rule allI)
subgoal for ra
using mk_v_agree[of "I" "(OSing vid1 (f0 fid1))" "(ab, bb)" "(sol ra)"]
vne23 constraint[of ra] apply(auto simp add: Vagree_def p1_def)
done
done
have anotherFact:"\<And>ra. 0 \<le> ra \<Longrightarrow> ra \<le> t \<Longrightarrow> (\<chi> i. if i = vid1 then ab $ i + Functions I fid1 (\<chi> _. 0) * ra else ab $ i) $ vid1 =
ab $ vid1 + dterm_sem I (f0 fid1) (\<chi> y. if vid3 = y then ra else fst (\<chi> y. if vid2 = y then t else fst (ab, bb) $ y, bb) $ y, bb) * ra "
subgoal for ra
apply simp
apply(rule disjI2)
by (auto simp add: f0_def empty_def)
done
have thing':"\<And>ra i. 0 \<le> ra \<Longrightarrow> ra \<le> t \<Longrightarrow> dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) (mk_v I (OSing vid1 ($f fid1 (\<lambda>i. Const 0))) (ab, bb) (sol ra))
= dterm_sem I (if i = vid1 then Plus (trm.Var vid1) (Times (f0 fid1) (trm.Var vid3)) else Const 0)
(\<chi> y. if vid3 = y then ra else fst (\<chi> y. if vid2 = y then t else fst (ab, bb) $ y, bb) $ y, bb) "
subgoal for ra i
using vne12 vne13 mk_v_agree[of I "OSing vid1 ($f fid1 (\<lambda>i. Const 0))" "(ab,bb)" "(sol ra)"]
apply (auto)
unfolding Vagree_def apply(safe)
apply(erule allE[where x="vid1"])+
using sol_eq_exp[of ra] anotherFact[of ra] by auto
done
have allRa:"(\<forall>ra. repv (repv (ab, bb) vid2 t) vid3 ra
\<in> {v. dterm_sem I (Const 0) v \<le> dterm_sem I (trm.Var vid3) v} \<inter>
{v. dterm_sem I (trm.Var vid3) v \<le> dterm_sem I (trm.Var vid2) v} \<longrightarrow>
Predicates I vid2
(\<chi> i. dterm_sem I (singleton (Plus (trm.Var vid1) (Times (f0 fid1) (trm.Var vid3))) i)
(repv (repv (ab, bb) vid2 t) vid3 ra)))"
apply(rule allI)
subgoal for ra
using mk_v_agree[of "I" "(OSing vid1 (f0 fid1))" "(ab, bb)" "(sol ra)"]
vne23 constraint[of ra] apply(auto simp add: Vagree_def p1_def)
using sol_eq_exp[of ra] apply (auto simp add: f0_def empty_def Vagree_def vec_eq_iff)
using thing' by auto
done
have fml3:"\<And>ra. 0 \<le> ra \<Longrightarrow> ra \<le> t \<Longrightarrow>
(\<forall>\<omega>. \<omega> = repv (repv (ab, bb) vid2 t) vid1
(dterm_sem I (Plus (trm.Var vid1) (Times (f0 fid1) (trm.Var vid2))) (repv (ab, bb) vid2 t)) \<longrightarrow>
\<omega> \<in> fml_sem I (p1 vid3 vid1))"
using impl allRa by auto
have someEq:"(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(\<chi> y. if vid1 = y then (if vid2 = vid1 then t else fst (ab, bb) $ vid1) + Functions I fid1 (\<chi> i. 0) * t
else fst (\<chi> y. if vid2 = y then t else fst (ab, bb) $ y, bb) $ y,
bb))
= (\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) (mk_v I (OSing vid1 ($f fid1 (\<lambda>i. Const 0))) (ab, bb) (sol t)))"
apply(rule vec_extensionality)
using vne12 sol_eq_exp t thing by auto
show "mk_v I (OSing vid1 (f0 fid1)) (ab, bb) (sol t) \<in> fml_sem I (p1 vid3 vid1)"
using mk_v_agree[of I "OSing vid1 (f0 fid1)" "(ab, bb)" "sol t"] fml3[of t]
unfolding f0_def p1_def empty_def Vagree_def
using someEq by(auto simp add: sol_eq_exp_t' t vec_extensionality vne12)
qed qed
lemma MVT0_within:
fixes f ::"real \<Rightarrow> real"
and f'::"real \<Rightarrow> real \<Rightarrow> real"
and s t :: real
assumes f':"\<And>x. x \<in> {0..t} \<Longrightarrow> (f has_derivative (f' x)) (at x within {0..t})"
assumes geq':"\<And>x. x \<in> {0..t} \<Longrightarrow> f' x s \<ge> 0"
assumes int_s:"s > 0 \<and> s \<le> t"
assumes t: "0 < t"
shows "f s \<ge> f 0"
proof -
have "f 0 + 0 \<le> f s"
apply (rule Lib.MVT_ivl'[OF f', of 0 s 0])
subgoal for x by assumption
subgoal for x using geq' by auto
using t int_s t apply auto
subgoal for x
by (metis int_s mult.commute mult.right_neutral order.trans real_mult_le_cancel_iff2)
done
then show "?thesis" by auto
qed
lemma MVT':
fixes f g ::"real \<Rightarrow> real"
fixes f' g'::"real \<Rightarrow> real \<Rightarrow> real"
fixes s t ::real
assumes f':"\<And>s. s \<in> {0..t} \<Longrightarrow> (f has_derivative (f' s)) (at s within {0..t})"
assumes g':"\<And>s. s \<in> {0..t} \<Longrightarrow> (g has_derivative (g' s)) (at s within {0..t})"
assumes geq':"\<And>x. x \<in> {0..t} \<Longrightarrow> f' x s \<ge> g' x s"
assumes geq0:"f 0 \<ge> g 0"
assumes int_s:"s > 0 \<and> s \<le> t"
assumes t:"t > 0"
shows "f s \<ge> g s"
proof -
let ?h = "(\<lambda>x. f x - g x)"
let ?h' = "(\<lambda>s x. f' s x - g' s x)"
have "?h s \<ge> ?h 0"
apply(rule MVT0_within[of t ?h "?h'" s])
subgoal for s using f'[of s] g'[of s] by auto
subgoal for sa using geq'[of sa] by auto
subgoal using int_s by auto
subgoal using t by auto
done
then show "?thesis" using geq0 by auto
qed
lemma MVT'_gr:
fixes f g ::"real \<Rightarrow> real"
fixes f' g'::"real \<Rightarrow> real \<Rightarrow> real"
fixes s t ::real
assumes f':"\<And>s. s \<in> {0..t} \<Longrightarrow> (f has_derivative (f' s)) (at s within {0..t})"
assumes g':"\<And>s. s \<in> {0..t} \<Longrightarrow> (g has_derivative (g' s)) (at s within {0..t})"
assumes geq':"\<And>x. x \<in> {0..t} \<Longrightarrow> f' x s \<ge> g' x s"
assumes geq0:"f 0 > g 0"
assumes int_s:"s > 0 \<and> s \<le> t"
assumes t:"t > 0"
shows "f s > g s"
proof -
let ?h = "(\<lambda>x. f x - g x)"
let ?h' = "(\<lambda>s x. f' s x - g' s x)"
have "?h s \<ge> ?h 0"
apply(rule MVT0_within[of t ?h "?h'" s])
subgoal for s using f'[of s] g'[of s] by auto
subgoal for sa using geq'[of sa] by auto
subgoal using int_s by auto
subgoal using t by auto
done
then show "?thesis" using geq0 by auto
qed
lemma frech_linear:
fixes x \<theta> \<nu> \<nu>' I
assumes good_interp:"is_interp I"
assumes free:"dfree \<theta>"
shows "x * frechet I \<theta> \<nu> \<nu>' = frechet I \<theta> \<nu> (x *\<^sub>R \<nu>')"
using frechet_linear[OF good_interp free]
by (simp add: linear_simps)
lemma rift_in_space_time:
fixes sol I ODE \<psi> \<theta> t s b
assumes good_interp:"is_interp I"
assumes free:"dfree \<theta>"
assumes osafe:"osafe ODE"
assumes sol:"(sol solves_ode (\<lambda>_ \<nu>'. ODE_sem I ODE \<nu>')) {0..t}
{x. mk_v I ODE (sol 0, b) x \<in> fml_sem I \<psi>}"
assumes FVT:"FVT \<theta> \<subseteq> semBV I ODE"
assumes ivl:"s \<in> {0..t}"
shows "((\<lambda>t. sterm_sem I \<theta> (fst (mk_v I ODE (sol 0, b) (sol t))))
\<comment> \<open>This is Frechet derivative, so equivalent to:\<close>
\<comment> \<open>\<open>has_real_derivative frechet I \<theta> (fst((mk_v I ODE (sol 0, b) (sol s)))) (snd (mk_v I ODE (sol 0, b) (sol s))))) (at s within {0..t})\<close>\<close>
has_derivative (\<lambda>t'. t' * frechet I \<theta> (fst((mk_v I ODE (sol 0, b) (sol s)))) (snd (mk_v I ODE (sol 0, b) (sol s))))) (at s within {0..t})"
proof -
let ?\<phi> = "(\<lambda>t. (mk_v I ODE (sol 0, b) (sol t)))"
let ?\<phi>s = "(\<lambda>t. fst (?\<phi> t))"
have sol_deriv:"\<And>s. s \<in> {0..t} \<Longrightarrow> (sol has_derivative (\<lambda>xa. xa *\<^sub>R ODE_sem I ODE (sol s))) (at s within {0..t})"
using sol apply simp
apply (drule solves_odeD(1))
unfolding has_vderiv_on_def has_vector_derivative_def
by auto
have sol_dom:"\<And>s. s\<in> {0..t} \<Longrightarrow> ?\<phi> s \<in> fml_sem I \<psi>"
using sol apply simp
apply (drule solves_odeD(2))
by auto
let ?h = "(\<lambda>t. sterm_sem I \<theta> (?\<phi>s t))"
let ?g = "(\<lambda>\<nu>. sterm_sem I \<theta> \<nu>)"
let ?f = "?\<phi>s"
let ?f' = "(\<lambda>t'. t' *\<^sub>R (\<chi> i. if i \<in> ODE_vars I ODE then ODE_sem I ODE (sol s) $ i else 0))"
let ?g' = "(frechet I \<theta> (?\<phi>s s))"
have heq:"?h = ?g \<circ> ?f" by (auto)
have fact1:"\<And>i. i \<in> ODE_vars I ODE \<Longrightarrow> (\<lambda>t. ?\<phi>s(t) $ i) = (\<lambda>t. sol t $ i)"
subgoal for i
apply(rule ext)
subgoal for t
using mk_v_agree[of I ODE "(sol 0, b)" "sol t"]
unfolding Vagree_def by auto
done done
have fact2:"\<And>i. i \<in> ODE_vars I ODE \<Longrightarrow> (\<lambda>t. if i \<in> ODE_vars I ODE then ODE_sem I ODE (sol t) $ i else 0) = (\<lambda>t. ODE_sem I ODE (sol t) $ i)"
subgoal for i
apply(rule ext)
subgoal for t
using mk_v_agree[of I ODE "(sol 0, b)" "sol t"]
unfolding Vagree_def by auto
done done
have fact3:"\<And>i. i \<in> (-ODE_vars I ODE) \<Longrightarrow> (\<lambda>t. ?\<phi>s(t) $ i) = (\<lambda>t. sol 0 $ i)"
subgoal for i
apply(rule ext)
subgoal for t
using mk_v_agree[of I ODE "(sol 0, b)" "sol t"]
unfolding Vagree_def by auto
done done
have fact4:"\<And>i. i \<in> (-ODE_vars I ODE) \<Longrightarrow> (\<lambda>t. if i \<in> ODE_vars I ODE then ODE_sem I ODE (sol t) $ i else 0) = (\<lambda>t. 0)"
subgoal for i
apply(rule ext)
subgoal for t
using mk_v_agree[of I ODE "(sol 0, b)" "sol t"]
unfolding Vagree_def by auto
done done
have some_eq:"(\<lambda>v'. \<chi> i. v' *\<^sub>R ODE_sem I ODE (sol s) $ i) = (\<lambda>v'. v' *\<^sub>R ODE_sem I ODE (sol s))"
apply(rule ext)
apply(rule vec_extensionality)
by auto
have some_sol:"(sol has_derivative (\<lambda>v'. v' *\<^sub>R ODE_sem I ODE (sol s))) (at s within {0..t})"
using sol ivl unfolding solves_ode_def has_vderiv_on_def has_vector_derivative_def by auto
have some_eta:"(\<lambda>t. \<chi> i. sol t $ i) = sol" by (rule ext, rule vec_extensionality, auto)
have ode_deriv:"\<And>i. i \<in> ODE_vars I ODE \<Longrightarrow>
((\<lambda>t. sol t $ i) has_derivative (\<lambda> v'. v' *\<^sub>R ODE_sem I ODE (sol s) $ i)) (at s within {0..t})"
subgoal for i
apply(rule has_derivative_proj)
using some_eq some_sol some_eta by auto
done
have eta:"(\<lambda>t. (\<chi> i. ?f t $ i)) = ?f" by(rule ext, rule vec_extensionality, auto)
have eta_esque:"(\<lambda>t'. \<chi> i. t' * (if i \<in> ODE_vars I ODE then ODE_sem I ODE (sol s) $ i else 0)) =
(\<lambda>t'. t' *\<^sub>R (\<chi> i. if i \<in> ODE_vars I ODE then ODE_sem I ODE (sol s) $ i else 0))"
apply(rule ext | rule vec_extensionality)+
subgoal for t' i by auto done
have "((\<lambda>t. (\<chi> i. ?f t $ i)) has_derivative (\<lambda>t'. (\<chi> i. ?f' t' $ i))) (at s within {0..t})"
apply (rule has_derivative_vec)
subgoal for i
apply(cases "i \<in> ODE_vars I ODE")
subgoal using fact1[of i] fact2[of i] ode_deriv[of i] by auto
subgoal using fact3[of i] fact4[of i] by auto
done
done
then have fderiv:"(?f has_derivative ?f') (at s within {0..t})" using eta eta_esque by auto
have gderiv:"(?g has_derivative ?g') (at (?f s) within ?f ` {0..t})"
using has_derivative_at_withinI
using frechet_correctness free good_interp
by blast
have chain:"((?g \<circ> ?f) has_derivative (?g' \<circ> ?f')) (at s within {0..t})"
using fderiv gderiv diff_chain_within by blast
let ?co\<nu>1 = "(fst (mk_v I ODE (sol 0, b) (sol s)), ODE_sem I ODE (fst (mk_v I ODE (sol 0, b) (sol s))))"
let ?co\<nu>2 = "(fst (mk_v I ODE (sol 0, b) (sol s)), snd (mk_v I ODE (sol 0, b) (sol s)))"
have sub_cont:"\<And>a .a \<notin> ODE_vars I ODE \<Longrightarrow> Inl a \<in> FVT \<theta> \<Longrightarrow> False"
using FVT by auto
have sub_cont2:"\<And>a .a \<notin> ODE_vars I ODE \<Longrightarrow> Inr a \<in> FVT \<theta> \<Longrightarrow> False"
using FVT by auto
have "Vagree (mk_v I ODE (sol 0, b) (sol s)) (sol s, b) (Inl ` ODE_vars I ODE)"
using mk_v_agree[of I ODE "(sol 0, b)" "sol s"]
unfolding Vagree_def by auto
let ?co'\<nu>1 = "(\<lambda>x. (fst (mk_v I ODE (sol 0, b) (sol s)), x *\<^sub>R (\<chi> i. if i \<in> ODE_vars I ODE then ODE_sem I ODE (sol s) $ i else 0)))"
let ?co'\<nu>2 = "(\<lambda>x. (fst (mk_v I ODE (sol 0, b) (sol s)), x *\<^sub>R snd (mk_v I ODE (sol 0, b) (sol s))))"
have co_agree_sem:"\<And>s. Vagree (?co'\<nu>1 s) (?co'\<nu>2 s) (semBV I ODE)"
subgoal for sa
using mk_v_agree[of I ODE "(sol 0, b)" "sol s"]
unfolding Vagree_def by auto
done
have co_agree_help:"\<And>s. Vagree (?co'\<nu>1 s) (?co'\<nu>2 s) (FVT \<theta>)"
using agree_sub[OF FVT co_agree_sem] by auto
have co_agree':"\<And>s. Vagree (?co'\<nu>1 s) (?co'\<nu>2 s) (FVDiff \<theta>)"
subgoal for s
using mk_v_agree[of I ODE "(sol 0, b)" "sol s"]
unfolding Vagree_def apply auto
subgoal for i x
apply(cases x)
subgoal for a
apply(cases "a \<in> ODE_vars I ODE")
by (simp | metis (no_types, lifting) FVT ODE_vars_lr Vagree_def mk_v_agree mk_xode.elims subsetD snd_conv)+
subgoal for a
apply(cases "a \<in> ODE_vars I ODE")
by (simp | metis (no_types, lifting) FVT Vagree_def mk_v_agree mk_xode.elims subsetD snd_conv)+
done
subgoal for i x
apply(cases x)
subgoal for a
apply(cases "a \<in> ODE_vars I ODE")
using FVT ODE_vars_lr Vagree_def mk_v_agree mk_xode.elims subsetD snd_conv
by auto
subgoal for a
apply(cases "a \<in> ODE_vars I ODE")
apply(erule allE[where x=i])+
using FVT ODE_vars_lr Vagree_def mk_v_agree mk_xode.elims subsetD snd_conv
by auto
done
done
done
have heq'':"(?g' \<circ> ?f') = (\<lambda>t'. t' *\<^sub>R frechet I \<theta> (?\<phi>s s) (snd (?\<phi> s)))"
using mk_v_agree[of I ODE "(sol 0, b)" "sol s"]
unfolding comp_def
apply auto
apply(rule ext | rule vec_extensionality)+
subgoal for x
using frech_linear[of I \<theta> x "(fst (mk_v I ODE (sol 0, b) (sol s)))" "(snd (mk_v I ODE (sol 0, b) (sol s)))", OF good_interp free]
using coincidence_frechet[OF free, of "(?co'\<nu>1 x)" "(?co'\<nu>2 x)", OF co_agree'[of x], of I]
by auto
done
have "((?g \<circ> ?f) has_derivative (?g' \<circ> ?f')) (at s within {0..t})"
using chain by auto
then have "((?g \<circ> ?f) has_derivative (\<lambda>t'. t' * frechet I \<theta> (?\<phi>s s) (snd (?\<phi> s)))) (at s within {0..t})"
using heq'' by auto
then have result:"((\<lambda>t. sterm_sem I \<theta> (?\<phi>s t)) has_derivative (\<lambda>t. t * frechet I \<theta> (?\<phi>s s) (snd (?\<phi> s)))) (at s within {0..t})"
using heq by auto
then show "?thesis" by auto
qed
lemma dterm_sterm_dfree:
"dfree \<theta> \<Longrightarrow> (\<And>\<nu> \<nu>'. sterm_sem I \<theta> \<nu> = dterm_sem I \<theta> (\<nu>, \<nu>'))"
by(induction rule: dfree.induct, auto)
\<comment> \<open>\<open>g(x)\<ge> h(x) \<rightarrow> [x'=f(x), c & p(x)](g(x)' \<ge> h(x)') \<rightarrow> [x'=f(x), c]g(x) \<ge> h(x)\<close>\<close>
lemma DG_valid:"valid DGaxiom"
proof -
have osafe:"osafe (OSing vid1 (f1 fid1 vid1))"
by(auto simp add: osafe_Sing dfree_Fun dfree_Const f1_def expand_singleton)
have fsafe:"fsafe (p1 vid1 vid1)"
by(auto simp add: p1_def dfree_Const)
have osafe2:"osafe (OProd (OSing vid1 (f1 fid1 vid1)) (OSing vid2 (Plus (Times (f1 fid2 vid1) (trm.Var vid2)) (f1 fid3 vid1))))"
by(auto simp add: f1_def expand_singleton osafe.intros dfree.intros vne12)
note sem = ode_alt_sem[OF osafe fsafe]
note sem2 = ode_alt_sem[OF osafe2 fsafe]
have p2safe:"fsafe (p1 vid2 vid1)" by(auto simp add: p1_def dfree_Const)
show "valid DGaxiom"
apply(auto simp del: prog_sem.simps(8) simp add: DGaxiom_def valid_def sem sem2)
apply(rule exI[where x=0], auto simp add: f1_def p1_def expand_singleton)
subgoal for I a b aa ba sol t
proof -
assume good_interp:"is_interp I"
assume "
\<forall>aa ba. (\<exists>sol t. (aa, ba) = mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (sol t) \<and>
0 \<le> t \<and>
(sol solves_ode (\<lambda>a b. \<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) b else 0)) {0..t}
{x. Predicates I vid1
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) x))} \<and>
VSagree (sol 0) a {uu. uu = vid1 \<or>
Inl uu \<in> Inl ` {x. \<exists>xa. Inl x \<in> FVT (if xa = vid1 then trm.Var vid1 else Const 0)} \<or>
(\<exists>x. Inl uu \<in> FVT (if x = vid1 then trm.Var vid1 else Const 0))}) \<longrightarrow>
Predicates I vid2 (\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) (aa, ba))"
then have
bigAll:"
\<And>aa ba. (\<exists>sol t. (aa, ba) = mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (sol t) \<and>
0 \<le> t \<and>
(sol solves_ode (\<lambda>a b. \<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) b else 0)) {0..t}
{x. Predicates I vid1
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) x))} \<and>
VSagree (sol 0) a {uu. uu = vid1 \<or> (\<exists>x. Inl uu \<in> FVT (if x = vid1 then trm.Var vid1 else Const 0))}) \<longrightarrow>
Predicates I vid2 (\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) (aa, ba))"
by (auto)
assume aaba:"(aa, ba) =
mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then 0 else fst (a, b) $ y, b) (sol t)"
assume t:"0 \<le> t"
assume sol:"
(sol solves_ode
(\<lambda>a b. (\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) b else 0) +
(\<chi> i. if i = vid2 then sterm_sem I (Plus (Times (f1 fid2 vid1) (trm.Var vid2)) (f1 fid3 vid1)) b else 0)))
{0..t} {x. Predicates I vid1
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then 0 else fst (a, b) $ y, b) x))}"
assume VSag:"VSagree (sol 0) (\<chi> y. if vid2 = y then 0 else fst (a, b) $ y)
{x. x = vid2 \<or> x = vid1 \<or> x = vid2 \<or> x = vid1 \<or> Inl x \<in> Inl ` {x. x = vid2 \<or> x = vid1} \<or> x = vid1}"
let ?sol = "(\<lambda>t. \<chi> i. if i = vid1 then sol t $ vid1 else 0)"
let ?aaba' = "mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (?sol t)"
from bigAll[of "fst ?aaba'" "snd ?aaba'"]
have bigEx:"(\<exists>sol t. ?aaba' = mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (sol t) \<and>
0 \<le> t \<and>
(sol solves_ode (\<lambda>a b. \<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) b else 0)) {0..t}
{x. Predicates I vid1
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) x))} \<and>
VSagree (sol 0) a {uu. uu = vid1 \<or> (\<exists>x. Inl uu \<in> FVT (if x = vid1 then trm.Var vid1 else Const 0))}) \<longrightarrow>
Predicates I vid2 (\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) (?aaba'))"
by simp
have pre1:"?aaba' = mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (?sol t)"
by (rule refl)
have agreeL:"\<And>s. fst (mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then 0 else fst (a, b) $ y, b) (sol s)) $ vid1 = sol s $ vid1"
subgoal for s
using mk_v_agree[of I "(OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))" "(\<chi> y. if vid2 = y then 0 else fst (a, b) $ y, b)" "(sol s)"]
unfolding Vagree_def by auto done
have agreeR:"\<And>s. fst (mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (\<chi> i. if i = vid1 then sol s $ vid1 else 0)) $ vid1 = sol s $ vid1"
subgoal for s
using mk_v_agree[of "I" "(OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))" "(a, b)" "(\<chi> i. if i = vid1 then sol s $ vid1 else 0)"]
unfolding Vagree_def by auto
done
have FV:"(FVF (p1 vid1 vid1)) = {Inl vid1}" unfolding p1_def expand_singleton
apply auto subgoal for x xa apply(cases "xa = vid1") by auto done
have agree:"\<And>s. Vagree (mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then 0 else fst (a, b) $ y, b) (sol s)) (mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (\<chi> i. if i = vid1 then sol s $ vid1 else 0)) (FVF (p1 vid1 vid1))"
using agreeR agreeL unfolding Vagree_def FV by auto
note con_sem_eq = coincidence_formula[OF fsafe Iagree_refl agree]
have constraint:"\<And>s. 0 \<le> s \<and> s \<le> t \<Longrightarrow>
Predicates I vid1
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (\<chi> i. if i = vid1 then sol s $ vid1 else 0)))"
using sol apply simp
apply(drule solves_odeD(2))
apply auto[1]
subgoal for s using con_sem_eq by (auto simp add: p1_def expand_singleton)
done
have eta:"sol = (\<lambda>t. \<chi> i. sol t $ i)" by (rule ext, rule vec_extensionality, simp)
have yet_another_eq:"\<And>x. (\<lambda>xa. xa *\<^sub>R ((\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (sol x) else 0) +
(\<chi> i. if i = vid2 then sterm_sem I (Plus (Times (f1 fid2 vid1) (trm.Var vid2)) (f1 fid3 vid1)) (sol x) else 0)))
= (\<lambda>xa. (\<chi> i. (xa *\<^sub>R ((\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (sol x) else 0) +
(\<chi> i. if i = vid2 then sterm_sem I (Plus (Times (f1 fid2 vid1) (trm.Var vid2)) (f1 fid3 vid1)) (sol x) else 0))) $ i))"
subgoal for x by (rule ext, rule vec_extensionality, simp) done
have sol_deriv:"\<And>x. x \<in>{0..t} \<Longrightarrow>
(sol has_derivative
(\<lambda>xa. xa *\<^sub>R ((\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (sol x) else 0) +
(\<chi> i. if i = vid2 then sterm_sem I (Plus (Times (f1 fid2 vid1) (trm.Var vid2)) (f1 fid3 vid1)) (sol x) else 0))))
(at x within {0..t})"
using sol apply simp
apply(drule solves_odeD(1))
unfolding has_vderiv_on_def has_vector_derivative_def by auto
then have sol_deriv:"\<And>x. x \<in> {0..t} \<Longrightarrow>
((\<lambda>t. \<chi> i. sol t $ i) has_derivative
(\<lambda>xa. (\<chi> i. (xa *\<^sub>R ((\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (sol x) else 0) +
(\<chi> i. if i = vid2 then sterm_sem I (Plus (Times (f1 fid2 vid1) (trm.Var vid2)) (f1 fid3 vid1)) (sol x) else 0))) $ i)))
(at x within {0..t})" using yet_another_eq eta by auto
have sol_deriv1: "\<And>x. x \<in> {0..t} \<Longrightarrow>
((\<lambda>t. sol t $ vid1) has_derivative
(\<lambda>xa. (xa *\<^sub>R ((\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (sol x) else 0) +
(\<chi> i. if i = vid2 then sterm_sem I (Plus (Times (f1 fid2 vid1) (trm.Var vid2)) (f1 fid3 vid1)) (sol x) else 0)) $ vid1)))
(at x within {0..t})"
subgoal for s
(* I heard higher-order unification is hard.*)
apply(rule has_derivative_proj[of "(\<lambda> i t. sol t $ i)" "(\<lambda>j xa. (xa *\<^sub>R ((\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (sol s) else 0) +
(\<chi> i. if i = vid2 then sterm_sem I (Plus (Times (f1 fid2 vid1) (trm.Var vid2)) (f1 fid3 vid1)) (sol s) else 0)) $ j))" "at s within {0..t}""vid1"])
using sol_deriv[of s] by auto done
have hmm:"\<And>s. (\<chi> i. sterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) (sol s)) = (\<chi> i. sterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) (\<chi> i. if i = vid1 then sol s $ vid1 else 0))"
by(rule vec_extensionality, auto)
have aha:"\<And>s. (\<lambda>xa. xa * sterm_sem I (f1 fid1 vid1) (sol s)) = (\<lambda>xa. xa * sterm_sem I (f1 fid1 vid1) (\<chi> i. if i = vid1 then sol s $ vid1 else 0))"
subgoal for s
apply(rule ext)
subgoal for xa using hmm by (auto simp add: f1_def) done done
let ?sol' = "(\<lambda>s. (\<lambda>xa. \<chi> i. if i = vid1 then xa * sterm_sem I (f1 fid1 vid1) (\<chi> i. if i = vid1 then sol s $ vid1 else 0) else 0))"
let ?project_me_plz = "(\<lambda>t. (\<chi> i. if i = vid1 then ?sol t $ vid1 else 0))"
have sol_deriv_eq:"\<And>s. s \<in>{0..t} \<Longrightarrow>
((\<lambda>t. (\<chi> i. if i = vid1 then ?sol t $ vid1 else 0)) has_derivative ?sol' s) (at s within {0..t})"
subgoal for s
apply(rule has_derivative_vec)
subgoal for i
apply (cases "i = vid1", cases "i = vid2", auto)
using vne12 apply simp
using sol_deriv1[of s] using aha by auto
done done
have yup:"(\<lambda>t. (\<chi> i. if i = vid1 then ?sol t $ vid1 else 0) $ vid1) = (\<lambda>t. sol t $ vid1)"
by(rule ext, auto)
have maybe:"\<And>s. (\<lambda>xa. xa * sterm_sem I (f1 fid1 vid1) (\<chi> i. if i = vid1 then sol s $ vid1 else 0)) = (\<lambda>xa. (\<chi> i. if i = vid1 then xa * sterm_sem I (f1 fid1 vid1) (\<chi> i. if i = vid1 then sol s $ vid1 else 0) else 0) $ vid1) "
by(rule ext, auto)
have almost:"(\<lambda>x. if vid1 = vid1 then (\<chi> i. if i = vid1 then sol x $ vid1 else 0) $ vid1 else 0) =
(\<lambda>x. (\<chi> i. if i = vid1 then sol x $ vid1 else 0) $ vid1)" by(rule ext, auto)
have almost':"\<And>s. (\<lambda>h. if vid1 = vid1 then h * sterm_sem I (f1 fid1 vid1) (\<chi> i. if i = vid1 then sol s $ vid1 else 0) else 0) = (\<lambda>h. h * sterm_sem I (f1 fid1 vid1) (\<chi> i. if i = vid1 then sol s $ vid1 else 0))"
by(rule ext, auto)
have deriv':" \<And>x. x \<in> {0..t} \<Longrightarrow>
((\<lambda>t. \<chi> i. if i = vid1 then sol t $ vid1 else 0) has_derivative
(\<lambda>xa. (\<chi> i. xa *\<^sub>R (if i = vid1 then sterm_sem I (f1 fid1 vid1) (\<chi> i. if i = vid1 then sol x $ vid1 else 0) else 0))))
(at x within {0..t})"
subgoal for s
apply(rule has_derivative_vec)
subgoal for i
apply(cases "i = vid1")
prefer 2 subgoal by auto
apply auto
using has_derivative_proj[OF sol_deriv_eq[of s], of vid1] using yup maybe[of s] almost almost'[of s]
by fastforce
done
done
have derEq:"\<And>s. (\<lambda>xa. (\<chi> i. xa *\<^sub>R (if i = vid1 then sterm_sem I (f1 fid1 vid1) (\<chi> i. if i = vid1 then sol s $ vid1 else 0) else 0)))
= (\<lambda>xa. xa *\<^sub>R (\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (\<chi> i. if i = vid1 then sol s $ vid1 else 0) else 0))"
subgoal for s apply (rule ext, rule vec_extensionality) by auto done
have "\<And>x. x \<in> {0..t} \<Longrightarrow>
((\<lambda>t. \<chi> i. if i = vid1 then sol t $ vid1 else 0) has_derivative
(\<lambda>xa. xa *\<^sub>R (\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (\<chi> i. if i = vid1 then sol x $ vid1 else 0) else 0)))
(at x within {0..t})" subgoal for s using deriv'[of s] derEq[of s] by auto done
then have deriv:"((\<lambda>t. \<chi> i. if i = vid1 then sol t $ vid1 else 0) has_vderiv_on
(\<lambda>t. \<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (\<chi> i. if i = vid1 then sol t $ vid1 else 0) else 0))
{0..t}"
unfolding has_vderiv_on_def has_vector_derivative_def
by auto
have pre2:"(?sol solves_ode (\<lambda>a b. \<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) b else 0)) {0..t}
{x. Predicates I vid1
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) x))}"
apply(rule solves_odeI)
subgoal by (rule deriv)
subgoal for s using constraint by auto
done
have pre3:"VSagree (?sol 0) a {u. u = vid1 \<or> (\<exists>x. Inl u \<in> FVT (if x = vid1 then trm.Var vid1 else Const 0))}"
using vne12 VSag unfolding VSagree_def by simp
have bigPre:"(\<exists>sol t. ?aaba' = mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then Var vid1 else Const 0))) (a, b) (sol t) \<and>
0 \<le> t \<and>
(sol solves_ode (\<lambda>a b. \<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) b else 0)) {0..t}
{x. Predicates I vid1
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then Var vid1 else Const 0))) (a, b) x))} \<and>
VSagree (sol 0) a {u. u = vid1 \<or> (\<exists>x. Inl u \<in> FVT (if x = vid1 then Var vid1 else Const 0))})"
apply(rule exI[where x="?sol"])
apply(rule exI[where x=t])
apply(rule conjI)
apply(rule pre1)
apply(rule conjI)
apply(rule t)
apply(rule conjI)
apply(rule pre2)
by(rule pre3)
have pred2:"Predicates I vid2 (\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) ?aaba')"
using bigEx bigPre by auto
then have pred2':"?aaba' \<in> fml_sem I (p1 vid2 vid1)" unfolding p1_def expand_singleton by auto
let ?res_state = "(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then 0 else fst (a, b) $ y, b) (sol t))"
have aabaX:"(fst ?aaba') $ vid1 = sol t $ vid1"
using aaba mk_v_agree[of "I" "(OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))"
"(a, b)" "(?sol t)"]
proof -
assume " Vagree (mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (\<chi> i. if i = vid1 then sol t $ vid1 else 0))
(a, b) (- semBV I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))) \<and>
Vagree (mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (\<chi> i. if i = vid1 then sol t $ vid1 else 0))
(mk_xode I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (\<chi> i. if i = vid1 then sol t $ vid1 else 0))
(semBV I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))))"
then have ag:" Vagree (mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (?sol t))
(mk_xode I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (?sol t))
(semBV I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))))"
by auto
have sembv:"(semBV I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))) = {Inl vid1, Inr vid1}"
by auto
have sub:"{Inl vid1} \<subseteq> {Inl vid1, Inr vid1}" by auto
have ag':"Vagree (mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (?sol t))
(mk_xode I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (?sol t)) {Inl vid1}"
using ag agree_sub[OF sub] sembv by auto
then have eq1:"fst (mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (?sol t)) $ vid1
= fst (mk_xode I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (?sol t)) $ vid1" unfolding Vagree_def by auto
moreover have "... = sol t $ vid1" by auto
ultimately show ?thesis by auto
qed
have res_stateX:"(fst ?res_state) $ vid1 = sol t $ vid1"
using mk_v_agree[of I "(OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))"
"(\<chi> y. if vid2 = y then 0 else fst (a, b) $ y, b)" "(sol t)"]
proof -
assume "Vagree (mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then 0 else fst (a, b) $ y, b) (sol t))
(\<chi> y. if vid2 = y then 0 else fst (a, b) $ y, b)
(- semBV I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))) \<and>
Vagree (mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then 0 else fst (a, b) $ y, b) (sol t))
(mk_xode I
(OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(sol t))
(semBV I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))))))"
then have ag:" Vagree (mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then 0 else fst (a, b) $ y, b) (sol t))
(mk_xode I
(OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(sol t))
(semBV I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))))))" by auto
have sembv:"(semBV I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))) = {Inl vid1, Inr vid1, Inl vid2, Inr vid2}" by auto
have sub:"{Inl vid1} \<subseteq> {Inl vid1, Inr vid1, Inl vid2, Inr vid2}" by auto
have ag':"Vagree (mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then 0 else fst (a, b) $ y, b) (sol t))
(mk_xode I
(OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(sol t)) {Inl vid1}" using ag sembv agree_sub[OF sub] by auto
then have "fst ?res_state $ vid1 = fst ((mk_xode I
(OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(sol t))) $ vid1" unfolding Vagree_def by blast
moreover have "... = sol t $ vid1" by auto
ultimately show "?thesis" by linarith
qed
have agree:"Vagree ?aaba' (?res_state) (FVF (p1 vid2 vid1))"
unfolding p1_def Vagree_def using aabaX res_stateX by auto
have fml_sem_eq:"(?res_state \<in> fml_sem I (p1 vid2 vid1)) = (?aaba' \<in> fml_sem I (p1 vid2 vid1))"
using coincidence_formula[OF p2safe Iagree_refl agree, of I] by auto
then show "Predicates I vid2
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then 0 else fst (a, b) $ y, b) (sol t)))"
using pred2 unfolding p1_def expand_singleton by auto
qed
subgoal for I a b r aa ba sol t
proof -
assume good_interp:"is_interp I"
assume bigAll:" \<forall>aa ba. (\<exists>sol t. (aa, ba) =
mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then r else fst (a, b) $ y, b) (sol t) \<and>
0 \<le> t \<and>
(sol solves_ode
(\<lambda>a b. (\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) b else 0) +
(\<chi> i. if i = vid2 then sterm_sem I (Plus (Times (f1 fid2 vid1) (trm.Var vid2)) (f1 fid3 vid1)) b else 0)))
{0..t} {x. Predicates I vid1
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then r else fst (a, b) $ y, b) x))} \<and>
VSagree (sol 0) (\<chi> y. if vid2 = y then r else fst (a, b) $ y)
{uu. uu = vid2 \<or>
uu = vid1 \<or>
uu = vid2 \<or>
uu = vid1 \<or>
Inl uu
\<in> Inl ` ({x. \<exists>xa. Inl x \<in> FVT (if xa = vid1 then trm.Var vid1 else Const 0)} \<union>
{x. x = vid2 \<or> (\<exists>xa. Inl x \<in> FVT (if xa = vid1 then trm.Var vid1 else Const 0))}) \<or>
(\<exists>x. Inl uu \<in> FVT (if x = vid1 then trm.Var vid1 else Const 0))}) \<longrightarrow>
Predicates I vid2 (\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) (aa, ba))"
assume aaba:"(aa, ba) = mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (sol t)"
assume t:"0 \<le> t"
assume sol:"(sol solves_ode (\<lambda>a b. \<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) b else 0)) {0..t}
{x. Predicates I vid1
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) x))}"
assume VSA:"VSagree (sol 0) a
{uu. uu = vid1 \<or>
Inl uu \<in> Inl ` {x. \<exists>xa. Inl x \<in> FVT (if xa = vid1 then trm.Var vid1 else Const 0)} \<or>
(\<exists>x. Inl uu \<in> FVT (if x = vid1 then trm.Var vid1 else Const 0))}"
let ?xode = "(\<lambda>a b. \<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) b else 0)"
let ?xconstraint = UNIV
let ?ivl = "ll_on_open.existence_ivl {0 .. t} ?xode ?xconstraint 0 (sol 0)"
have freef1:"dfree ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))"
by(auto simp add: dfree_Fun dfree_Const)
have simple_term_inverse':"\<And>\<theta>. dfree \<theta> \<Longrightarrow> raw_term (simple_term \<theta>) = \<theta>"
using simple_term_inverse by auto
have old_lipschitz:"local_lipschitz (UNIV::real set) UNIV (\<lambda>a b. \<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) b else 0)"
apply(rule c1_implies_local_lipschitz[where f'="(\<lambda> (t,b). blinfun_vec(\<lambda> i. if i = vid1 then blin_frechet (good_interp I) (simple_term (Function fid1 (\<lambda> i. if i = vid1 then Var vid1 else Const 0))) b else Blinfun(\<lambda> _. 0)))"])
apply auto
subgoal for x
apply(rule has_derivative_vec)
subgoal for i
apply(auto simp add: bounded_linear_Blinfun_apply good_interp_inverse good_interp)
apply(auto simp add: simple_term_inverse'[OF freef1])
apply(cases "i = vid1")
apply(auto simp add: f1_def expand_singleton)
proof -
let ?h = "(\<lambda>b. Functions I fid1 (\<chi> i. sterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) b))"
let ?h' = "(\<lambda>b'. FunctionFrechet I fid1 (\<chi> i. sterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) x) (\<chi> i. frechet I (if i = vid1 then trm.Var vid1 else Const 0) x b'))"
let ?f = "(\<lambda> b. (\<chi> i. sterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) b))"
let ?f' = "(\<lambda> b'. (\<chi> i. frechet I (if i = vid1 then trm.Var vid1 else Const 0) x b'))"
let ?g = "Functions I fid1"
let ?g'= "FunctionFrechet I fid1 (?f x)"
have heq:"?h = ?g \<circ> ?f" by(rule ext, auto)
have heq':"?h' = ?g' \<circ> ?f'" by(rule ext, auto)
have fderiv:"(?f has_derivative ?f') (at x)"
apply(rule has_derivative_vec)
by (auto simp add: svar_deriv axis_def)
have gderiv:"(?g has_derivative ?g') (at (?f x))"
using good_interp unfolding is_interp_def by blast
have gfderiv: "((?g \<circ> ?f) has_derivative(?g' \<circ> ?f')) (at x)"
using fderiv gderiv diff_chain_at by blast
have boring_eq:"(\<lambda>b. Functions I fid1 (\<chi> i. sterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) b)) =
sterm_sem I ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))"
by(rule ext, auto)
have "(?h has_derivative ?h') (at x)" using gfderiv heq heq' by auto
then show "(sterm_sem I ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) has_derivative
(\<lambda>v'. (THE f'. \<forall>x. (Functions I fid1 has_derivative f' x) (at x)) (\<chi> i. sterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) x)
(\<chi> i. frechet I (if i = vid1 then trm.Var vid1 else Const 0) x v')))
(at x)"
using boring_eq by auto
qed
done
proof -
have the_thing:"continuous_on (UNIV::('sz Rvec set))
(\<lambda>b.
blinfun_vec
(\<lambda>i. if i = vid1 then blin_frechet (good_interp I) (simple_term ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) b
else Blinfun (\<lambda>_. 0)))"
apply(rule continuous_blinfun_vec')
subgoal for i
apply(cases "i = vid1")
apply(auto)
using frechet_continuous[OF good_interp freef1] by (auto simp add: continuous_on_const)
done
have another_cont:"continuous_on (UNIV)
(\<lambda>x.
blinfun_vec
(\<lambda>i. if i = vid1 then blin_frechet (good_interp I) (simple_term ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (snd x)
else Blinfun (\<lambda>_. 0)))"
apply(rule continuous_on_compose2[of UNIV "(\<lambda>b. blinfun_vec
(\<lambda>i. if i = vid1 then blin_frechet (good_interp I) (simple_term ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) b
else Blinfun (\<lambda>_. 0)))"])
apply(rule the_thing)
by (auto intro!: continuous_intros)
have ext:"(\<lambda>x. case x of
(t, b) \<Rightarrow>
blinfun_vec
(\<lambda>i. if i = vid1 then blin_frechet (good_interp I) (simple_term ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) b
else Blinfun (\<lambda>_. 0))) =(\<lambda>x.
blinfun_vec
(\<lambda>i. if i = vid1 then blin_frechet (good_interp I) (simple_term ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (snd x)
else Blinfun (\<lambda>_. 0))) " apply(rule ext, auto)
by (metis snd_conv)
then show "continuous_on (UNIV)
(\<lambda>x. case x of
(t, b) \<Rightarrow>
blinfun_vec
(\<lambda>i. if i = vid1 then blin_frechet (good_interp I) (simple_term ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) b
else Blinfun (\<lambda>_. 0)))"
using another_cont
by (simp add: another_cont local.ext)
qed
have old_continuous:" \<And>x. x \<in> UNIV \<Longrightarrow> continuous_on UNIV (\<lambda>t. \<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) x else 0)"
by(rule continuous_on_const)
interpret ll_old: ll_on_open_it "UNIV" ?xode ?xconstraint 0
apply(standard)
subgoal by auto
prefer 3 subgoal by auto
prefer 3 subgoal by auto
apply(rule old_lipschitz)
by (rule old_continuous)
let ?ivl = "(ll_old.existence_ivl 0 (sol 0))"
let ?flow = "ll_old.flow 0 (sol 0)"
have tclosed:"{0..t} = {0--t}" using t real_Icc_closed_segment by auto
have "(sol solves_ode (\<lambda>a b. \<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) b else 0)) {0..t} UNIV"
apply(rule solves_ode_supset_range)
apply(rule sol)
by auto
then have sol':"(sol solves_ode (\<lambda>a b. \<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) b else 0)) {0--t} UNIV"
using tclosed by auto
have sub:"{0--t} \<subseteq> ll_old.existence_ivl 0 (sol 0)"
apply(rule ll_old.closed_segment_subset_existence_ivl)
apply(rule ll_old.existence_ivl_maximal_segment)
apply(rule sol')
apply(rule refl)
by auto
have usol_old:"(?flow usolves_ode ?xode from 0) ?ivl UNIV"
by(rule ll_old.flow_usolves_ode, auto)
have sol_old:"(ll_old.flow 0 (sol 0) solves_ode ?xode) ?ivl UNIV"
by(rule ll_old.flow_solves_ode, auto)
have another_sub:"\<And>s. s \<in> {0..t} \<Longrightarrow> {s--0} \<subseteq> {0..t}"
unfolding closed_segment_def
apply auto
by (metis diff_0_right diff_left_mono mult.commute mult_left_le order.trans)
have sol_eq_flow:"\<And>s. s \<in> {0..t} \<Longrightarrow> sol s = ?flow s"
using usol_old apply simp
apply(drule usolves_odeD(4)) (* 7 subgoals*)
apply auto
subgoal for s x
proof -
assume xs0:"x \<in> {s--0}"
assume s0:"0 \<le> s" and st: "s \<le> t"
have "{s--0} \<subseteq> {0..t}" using another_sub[of s] s0 st by auto
then have "x \<in> {0..t}" using xs0 by auto
then have "x \<in> {0--t}" using tclosed by auto
then show "x \<in> ll_old.existence_ivl 0 (sol 0)"
using sub by auto
qed
apply(rule solves_ode_subset)
using sol' apply auto[1]
subgoal for s
proof -
assume s0:"0 \<le> s" and st:"s \<le> t"
show "{s--0} \<subseteq> {0--t}"
using tclosed unfolding closed_segment using s0 st
using another_sub intervalE by blast
qed
done
have sol_deriv_orig:"\<And>s. s\<in>?ivl \<Longrightarrow> (?flow has_derivative (\<lambda>xa. xa *\<^sub>R (\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (?flow s) else 0))) (at s within ?ivl)"
using sol_old apply simp
apply(drule solves_odeD(1))
by (auto simp add: has_vderiv_on_def has_vector_derivative_def)
have sol_eta:"(\<lambda>t. \<chi> i. ?flow t $ i) = ?flow" by(rule ext, rule vec_extensionality, auto)
have sol_deriv_eq1:"\<And>s i. (\<lambda>xa. xa *\<^sub>R (\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (?flow s) else 0)) = (\<lambda>xa. \<chi> i. xa * (if i = vid1 then sterm_sem I (f1 fid1 vid1) (?flow s) else 0))"
by(rule ext, rule vec_extensionality, auto)
have sol_deriv_proj:"\<And>s i. s\<in>?ivl \<Longrightarrow> ((\<lambda>t. ?flow t $ i) has_derivative (\<lambda>xa. (xa *\<^sub>R (\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (?flow s) else 0)) $ i)) (at s within ?ivl)"
subgoal for s i
apply(rule has_derivative_proj[of "(\<lambda> i t. ?flow t $ i)" "(\<lambda> i t'. (t' *\<^sub>R (\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (?flow s) else 0)) $ i)" "(at s within ?ivl)" "i"])
using sol_deriv_orig[of s] sol_eta sol_deriv_eq1 by auto
done
have sol_deriv_eq2:"\<And>s i. (\<lambda>xa. xa * (if i = vid1 then sterm_sem I (f1 fid1 vid1) (?flow s) else 0)) = (\<lambda>xa. (xa *\<^sub>R (\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (?flow s) else 0)) $ i)"
by(rule ext, auto)
have sol_deriv_proj':"\<And>s i. s\<in>?ivl \<Longrightarrow> ((\<lambda>t. ?flow t $ i) has_derivative (\<lambda>xa. xa * (if i = vid1 then sterm_sem I (f1 fid1 vid1) (?flow s) else 0))) (at s within ?ivl)"
subgoal for s i using sol_deriv_proj[of s i] sol_deriv_eq2[of i s] by metis done
have sol_deriv_proj_vid1:"\<And>s. s\<in>?ivl \<Longrightarrow> ((\<lambda>t. ?flow t $ vid1) has_derivative (\<lambda>xa. xa * (sterm_sem I (f1 fid1 vid1) (?flow s)))) (at s within ?ivl)"
subgoal for s
using sol_deriv_proj'[of s vid1] by auto done
have deriv1_args:"\<And>s. s \<in> ?ivl \<Longrightarrow> ((\<lambda> t. (\<chi> i. sterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) (?flow t))) has_derivative ((\<lambda> t'. \<chi> i . t' * (if i = vid1 then sterm_sem I (f1 fid1 vid1) (?flow s) else 0)))) (at s within ?ivl)"
apply(rule has_derivative_vec)
by (auto simp add: sol_deriv_proj_vid1)
have con_fid:"\<And>fid. continuous_on ?ivl (\<lambda>x. sterm_sem I (f1 fid vid1) (?flow x))"
subgoal for fid
apply(rule has_derivative_continuous_on[of "?ivl" "(\<lambda>x. sterm_sem I (f1 fid vid1) (?flow x))"
"(\<lambda>t t'. FunctionFrechet I fid (\<chi> i. sterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) (?flow t)) (\<chi> i . t' * (if i = vid1 then sterm_sem I (f1 fid1 vid1) (?flow t) else 0)))"])
proof -
fix s
assume ivl:"s \<in> ?ivl"
let ?h = "(\<lambda>x. sterm_sem I (f1 fid vid1) (?flow x))"
let ?g = "Functions I fid"
let ?f = "(\<lambda>x. (\<chi> i. sterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) (?flow x)))"
let ?h' = "(\<lambda>t'. FunctionFrechet I fid (\<chi> i. sterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) (?flow s))
(\<chi> i. t' * (if i = vid1 then sterm_sem I (f1 fid1 vid1) (?flow s) else 0)))"
let ?g' = "FunctionFrechet I fid (?f s)"
let ?f' = "(\<lambda> t'. \<chi> i . t' * (if i = vid1 then sterm_sem I (f1 fid1 vid1) (?flow s) else 0))"
have heq:"?h = ?g \<circ> ?f" unfolding comp_def f1_def expand_singleton by auto
have heq':"?h' = ?g' \<circ> ?f'" unfolding comp_def by auto
have fderiv:"(?f has_derivative ?f') (at s within ?ivl)"
using deriv1_args[OF ivl] by auto
have gderiv:"(?g has_derivative ?g') (at (?f s) within (?f ` ?ivl))"
using good_interp unfolding is_interp_def
using has_derivative_within_subset by blast
have gfderiv:"((?g \<circ> ?f) has_derivative (?g' \<circ> ?f')) (at s within ?ivl)"
using fderiv gderiv diff_chain_within by blast
show "((\<lambda>x. sterm_sem I (f1 fid vid1) (?flow x)) has_derivative
(\<lambda>t'. FunctionFrechet I fid (\<chi> i. sterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) (?flow s))
(\<chi> i. t' * (if i = vid1 then sterm_sem I (f1 fid1 vid1) (?flow s) else 0))))
(at s within ?ivl)"
using heq heq' gfderiv by auto
qed
done
have con:"\<And>x. continuous_on (?ivl) (\<lambda>t. x * sterm_sem I (f1 fid2 vid1) (?flow t) + sterm_sem I (f1 fid3 vid1) (?flow t))"
apply(rule continuous_on_add)
apply(rule continuous_on_mult_left)
apply(rule con_fid[of fid2])
by(rule con_fid[of fid3])
let ?axis = "(\<lambda> i. Blinfun(axis i))"
have bounded_linear_deriv:"\<And>t. bounded_linear (\<lambda>y' . y' *\<^sub>R sterm_sem I (f1 fid2 vid1) (ll_old.flow 0 (sol 0) t))"
using bounded_linear_scaleR_left by blast
have ll:"local_lipschitz (ll_old.existence_ivl 0 (sol 0)) UNIV (\<lambda>t y. y * sterm_sem I (f1 fid2 vid1) (?flow t) + sterm_sem I (f1 fid3 vid1) (?flow t))"
apply(rule c1_implies_local_lipschitz[where f'="(\<lambda> (t,y). Blinfun(\<lambda>y' . y' *\<^sub>R sterm_sem I (f1 fid2 vid1) (ll_old.flow 0 (sol 0) t)))"])
apply auto
subgoal for t x
apply(rule has_derivative_add_const)
proof -
have deriv:"((\<lambda>x. x * sterm_sem I (f1 fid2 vid1) (ll_old.flow 0 (sol 0) t)) has_derivative (\<lambda>x. x * sterm_sem I (f1 fid2 vid1) (ll_old.flow 0 (sol 0) t))) (at x)"
by(auto intro: derivative_eq_intros)
have eq:"(\<lambda>x. x * sterm_sem I (f1 fid2 vid1) (ll_old.flow 0 (sol 0) t)) = blinfun_apply (Blinfun (\<lambda>y'. y' * sterm_sem I (f1 fid2 vid1) (ll_old.flow 0 (sol 0) t)))"
apply(rule ext)
using bounded_linear_deriv[of t] by (auto simp add: bounded_linear_Blinfun_apply)
show "((\<lambda>x. x * sterm_sem I (f1 fid2 vid1) (ll_old.flow 0 (sol 0) t)) has_derivative
blinfun_apply (Blinfun (\<lambda>y'. y' * sterm_sem I (f1 fid2 vid1) (ll_old.flow 0 (sol 0) t))))
(at x)" using deriv eq by auto
qed
apply(auto intro: continuous_intros simp add: split_beta')
proof -
have bounded_linear:"\<And>x. bounded_linear (\<lambda>y'. y' * sterm_sem I (f1 fid2 vid1) x)"
by (simp add: bounded_linear_mult_left)
have eq:"(\<lambda>x. Blinfun (\<lambda>y'. y' * sterm_sem I (f1 fid2 vid1) x)) = (\<lambda>x. (sterm_sem I (f1 fid2 vid1) x) *\<^sub>R id_blinfun)"
apply(rule ext, rule blinfun_eqI)
subgoal for x i
using bounded_linear[of x] apply(auto simp add: bounded_linear_Blinfun_apply)
by (simp add: blinfun.scaleR_left)
done
have conFlow:"continuous_on (ll_old.existence_ivl 0 (sol 0)) (ll_old.flow 0 (sol 0))"
using ll_old.general.flow_continuous_on by blast
have conF':"continuous_on (ll_old.flow 0 (sol 0) ` ll_old.existence_ivl 0 (sol 0))
(\<lambda>x. (sterm_sem I (f1 fid2 vid1) x) *\<^sub>R id_blinfun)"
apply(rule continuous_on_scaleR)
apply(auto intro: continuous_intros)
apply(rule sterm_continuous')
apply(rule good_interp)
by(auto simp add: f1_def intro: dfree.intros)
have conF:"continuous_on (ll_old.flow 0 (sol 0) ` ll_old.existence_ivl 0 (sol 0))
(\<lambda>x. Blinfun (\<lambda>y'. y' * sterm_sem I (f1 fid2 vid1) x))"
apply(rule continuous_on_compose2[of "UNIV" "(\<lambda>x. Blinfun (\<lambda>y'. y' * x))" "(ll_old.flow 0 (sol 0) ` ll_old.existence_ivl 0 (sol 0))" "sterm_sem I (f1 fid2 vid1)"])
subgoal by (metis blinfun_mult_left.abs_eq bounded_linear_blinfun_mult_left continuous_on_eq linear_continuous_on)
apply(rule sterm_continuous')
apply(rule good_interp)
by(auto simp add: f1_def intro: dfree.intros)
show "continuous_on (ll_old.existence_ivl 0 (sol 0) \<times> UNIV) (\<lambda>x. Blinfun (\<lambda>y'. y' * sterm_sem I (f1 fid2 vid1) (ll_old.flow 0 (sol 0) (fst x))))"
apply(rule continuous_on_compose2[of "ll_old.existence_ivl 0 (sol 0)" "(\<lambda>x. Blinfun (\<lambda>y'. y' * sterm_sem I (f1 fid2 vid1) (ll_old.flow 0 (sol 0) x)))" "(ll_old.existence_ivl 0 (sol 0) \<times> UNIV)" "fst"])
apply(rule continuous_on_compose2[of "(ll_old.flow 0 (sol 0) ` ll_old.existence_ivl 0 (sol 0))" "(\<lambda>x. Blinfun (\<lambda>y'. y' * sterm_sem I (f1 fid2 vid1) x))"
"(ll_old.existence_ivl 0 (sol 0))" "(ll_old.flow 0 (sol 0))"])
using conF conFlow by (auto intro!: continuous_intros)
qed
let ?ivl = "ll_old.existence_ivl 0 (sol 0)"
\<comment> \<open>Construct solution to ODE for \<open>y'\<close> here:\<close>
let ?yode = "(\<lambda>t y. y * sterm_sem I (f1 fid2 vid1) (?flow t) + sterm_sem I (f1 fid3 vid1) (?flow t))"
let ?ysol0 = r
interpret ll_new: ll_on_open_it "?ivl" "?yode" "UNIV" 0
apply(standard)
apply(auto)
apply(rule ll)
by(rule con)
have sol_new:"(ll_new.flow 0 r solves_ode ?yode) (ll_new.existence_ivl 0 r) UNIV"
by(rule ll_new.flow_solves_ode, auto)
have more_lipschitz:"\<And>tm tM. tm \<in> ll_old.existence_ivl 0 (sol 0) \<Longrightarrow>
tM \<in> ll_old.existence_ivl 0 (sol 0) \<Longrightarrow>
\<exists>M L. \<forall>t\<in>{tm..tM}. \<forall>x. \<bar>x * sterm_sem I (f1 fid2 vid1) (?flow t) + sterm_sem I (f1 fid3 vid1) (?flow t)\<bar> \<le> M + L * \<bar>x\<bar>"
proof -
fix tm tM
assume tm:"tm \<in> ll_old.existence_ivl 0 (sol 0)"
assume tM:"tM \<in> ll_old.existence_ivl 0 (sol 0)"
let ?f2 = "(\<lambda>t. sterm_sem I (f1 fid2 vid1) (ll_old.flow 0 (sol 0) t))"
let ?f3 = "(\<lambda>t. sterm_sem I (f1 fid3 vid1) (ll_old.flow 0 (sol 0) t))"
let ?boundLP = "(\<lambda>L t . (tm \<le> t \<and> t \<le> tM \<longrightarrow> \<bar>?f2 t\<bar> \<le> L))"
let ?boundL = "(SOME L. (\<forall>t. ?boundLP L t))"
have compactT:"compact {tm..tM}" by auto
have sub:"{tm..tM} \<subseteq> ll_old.existence_ivl 0 (sol 0)"
by (metis atLeastatMost_empty_iff empty_subsetI ll_old.general.segment_subset_existence_ivl real_Icc_closed_segment tM tm)
let ?f2abs = "(\<lambda>x. abs(?f2 x))"
have neg_compact:"\<And>S::real set. compact S \<Longrightarrow> compact ((\<lambda>x. -x) ` S)"
by(rule compact_continuous_image, auto intro: continuous_intros)
have compactf2:"compact (?f2 ` {tm..tM})"
apply(rule compact_continuous_image)
apply(rule continuous_on_compose2[of UNIV "sterm_sem I (f1 fid2 vid1)" "{tm..tM}" "ll_old.flow 0 (sol 0)"])
apply(rule sterm_continuous)
apply(rule good_interp)
subgoal by (auto intro: dfree.intros simp add: f1_def)
apply(rule continuous_on_subset)
prefer 2 apply (rule sub)
subgoal using ll_old.general.flow_continuous_on by blast
by auto
then have boundedf2:"bounded (?f2 ` {tm..tM})" using compact_imp_bounded by auto
then have boundedf2neg:"bounded ((\<lambda>x. -x) ` ?f2 ` {tm..tM})" using compact_imp_bounded neg_compact by auto
then have bdd_above_f2neg:"bdd_above ((\<lambda>x. -x) ` ?f2 ` {tm..tM})" by (rule bounded_imp_bdd_above)
then have bdd_above_f2:"bdd_above ( ?f2 ` {tm..tM})" using bounded_imp_bdd_above boundedf2 by auto
have bdd_above_f2_abs:"bdd_above (abs ` ?f2 ` {tm..tM})"
using bdd_above_f2neg bdd_above_f2 unfolding bdd_above_def
apply auto
subgoal for M1 M2
apply(rule exI[where x="max M1 M2"])
by fastforce
done
then have theBound:"\<exists>L. (\<forall>t. ?boundLP L t)"
unfolding bdd_above_def norm_conv_dist
by (auto simp add: Ball_def Bex_def norm_conv_dist image_iff norm_bcontfun_def dist_blinfun_def)
then have boundLP:"\<forall>t. ?boundLP (?boundL) t" using someI[of "(\<lambda> L. \<forall>t. ?boundLP L t)"] by blast
let ?boundMP = "(\<lambda>M t. (tm \<le> t \<and> t \<le> tM \<longrightarrow> \<bar>?f3 t\<bar> \<le> M))"
let ?boundM = "(SOME M. (\<forall>t. ?boundMP M t))"
have compactf3:"compact (?f3 ` {tm..tM})"
apply(rule compact_continuous_image)
apply(rule continuous_on_compose2[of UNIV "sterm_sem I (f1 fid3 vid1)" "{tm..tM}" "ll_old.flow 0 (sol 0)"])
apply(rule sterm_continuous)
apply(rule good_interp)
subgoal by (auto intro: dfree.intros simp add: f1_def)
apply(rule continuous_on_subset)
prefer 2 apply (rule sub)
subgoal using ll_old.general.flow_continuous_on by blast
by auto
then have boundedf3:"bounded (?f3 ` {tm..tM})" using compact_imp_bounded by auto
then have boundedf3neg:"bounded ((\<lambda>x. -x) ` ?f3 ` {tm..tM})" using compact_imp_bounded neg_compact by auto
then have bdd_above_f3neg:"bdd_above ((\<lambda>x. -x) ` ?f3 ` {tm..tM})" by (rule bounded_imp_bdd_above)
then have bdd_above_f3:"bdd_above ( ?f3 ` {tm..tM})" using bounded_imp_bdd_above boundedf3 by auto
have bdd_above_f3_abs:"bdd_above (abs ` ?f3 ` {tm..tM})"
using bdd_above_f3neg bdd_above_f3 unfolding bdd_above_def
apply auto
subgoal for M1 M2
apply(rule exI[where x="max M1 M2"])
by fastforce
done
then have theBound:"\<exists>L. (\<forall>t. ?boundMP L t)"
unfolding bdd_above_def norm_conv_dist
by (auto simp add: Ball_def Bex_def norm_conv_dist image_iff norm_bcontfun_def dist_blinfun_def)
then have boundMP:"\<forall>t. ?boundMP (?boundM) t" using someI[of "(\<lambda> M. \<forall>t. ?boundMP M t)"] by blast
show "\<exists>M L. \<forall>t\<in>{tm..tM}. \<forall>x. \<bar>x * ?f2 t + ?f3 t\<bar> \<le> M + L * \<bar>x\<bar>"
apply(rule exI[where x="?boundM"])
apply(rule exI[where x="?boundL"])
apply auto
proof -
fix t and x :: real
assume ttm:"tm \<le> t"
assume ttM:"t \<le> tM"
from ttm ttM have ttmM:"tm \<le> t \<and> t \<le> tM" by auto
have leqf3:"\<bar>?f3 t\<bar> \<le> ?boundM" using boundMP ttmM by auto
have leqf2:"\<bar>?f2 t\<bar> \<le> ?boundL" using boundLP ttmM by auto
have gr0:" \<bar>x\<bar> \<ge> 0" by auto
have leqf2x:"\<bar>?f2 t\<bar> * \<bar>x\<bar> \<le> ?boundL * \<bar>x\<bar>" using gr0 leqf2
by (metis (no_types, lifting) real_scaleR_def scaleR_right_mono)
have "\<bar>x * ?f2 t + ?f3 t\<bar> \<le> \<bar>x\<bar> * \<bar>?f2 t\<bar> + \<bar>?f3 t\<bar>"
proof -
have f1: "\<And>r ra. \<bar>r::real\<bar> * \<bar>ra\<bar> = \<bar>r * ra\<bar>"
by (metis norm_scaleR real_norm_def real_scaleR_def)
have "\<And>r ra. \<bar>(r::real) + ra\<bar> \<le> \<bar>r\<bar> + \<bar>ra\<bar>"
by (metis norm_triangle_ineq real_norm_def)
then show ?thesis
using f1 by presburger
qed
moreover have "... = \<bar>?f3 t\<bar> + \<bar>?f2 t\<bar> * \<bar>x\<bar>"
by auto
moreover have "... \<le> ?boundM + \<bar>?f2 t\<bar> * \<bar>x\<bar>"
using leqf3 by linarith
moreover have "... \<le> ?boundM + ?boundL * \<bar>x\<bar>"
using leqf2x by linarith
ultimately show "\<bar>x * ?f2 t + ?f3 t\<bar> \<le> ?boundM + ?boundL * \<bar>x\<bar>"
by linarith
qed
qed
have ivls_eq:"(ll_new.existence_ivl 0 r) = (ll_old.existence_ivl 0 (sol 0))"
apply(rule ll_new.existence_ivl_eq_domain)
apply auto
apply (rule more_lipschitz)
by auto
have sub':"{0--t} \<subseteq> ll_new.existence_ivl 0 r"
using sub ivls_eq by auto
have sol_new':"(ll_new.flow 0 r solves_ode ?yode) {0--t} UNIV"
by(rule solves_ode_subset, rule sol_new, rule sub')
let ?soly = "ll_new.flow 0 r"
let ?sol' = "(\<lambda>t. \<chi> i. if i = vid2 then ?soly t else sol t $ i)"
let ?aaba' = "mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then r else fst (a, b) $ y, b)
(?sol' t)"
have duh:"(fst ?aaba', snd ?aaba') = ?aaba'" by auto
note bigEx = spec[OF spec[OF bigAll, where x="fst ?aaba'"], where x="snd ?aaba'"]
have sol_deriv:"\<And>s. s \<in> {0..t} \<Longrightarrow> (sol has_derivative (\<lambda>xa. xa *\<^sub>R (\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (sol s) else 0))) (at s within {0..t})"
using sol apply simp
by(drule solves_odeD(1), auto simp add: has_vderiv_on_def has_vector_derivative_def)
have silly_eq1:"(\<lambda>t. \<chi> i. sol t $ i) = sol"
by(rule ext, rule vec_extensionality, auto)
have silly_eq2:"\<And>s. (\<lambda>xa. \<chi> i. (xa *\<^sub>R (\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (sol s) else 0)) $ i) = (\<lambda>xa. xa *\<^sub>R (\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (sol s) else 0))"
by(rule ext, rule vec_extensionality, auto)
have sol_proj_deriv:"\<And>s i. s \<in> {0..t} \<Longrightarrow> ((\<lambda> t. sol t $ i) has_derivative (\<lambda>xa. (xa *\<^sub>R (\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (sol s) else 0)) $ i)) (at s within {0..t})"
subgoal for s i
apply(rule has_derivative_proj)
using sol_deriv[of s] silly_eq1 silly_eq2[of s] by auto
done
have sol_proj_deriv_vid1:"\<And>s. s \<in> {0..t} \<Longrightarrow> ((\<lambda> t. sol t $ vid1) has_derivative (\<lambda>xa. xa * sterm_sem I (f1 fid1 vid1) (sol s))) (at s within {0..t})"
subgoal for s using sol_proj_deriv[of s vid1] by auto done
have sol_proj_deriv_other:"\<And>s i. s \<in> {0..t} \<Longrightarrow> i \<noteq> vid1 \<Longrightarrow> ((\<lambda> t. sol t $ i) has_derivative (\<lambda>xa. 0)) (at s within {0..t})"
subgoal for s i using sol_proj_deriv[of s i] by auto done
have fact:"\<And>x. x \<in>{0..t} \<Longrightarrow>
(ll_new.flow 0 r has_derivative
(\<lambda>xa. xa *\<^sub>R (ll_new.flow 0 r x * sterm_sem I (f1 fid2 vid1) (ll_old.flow 0 (sol 0) x) +
sterm_sem I (f1 fid3 vid1) (ll_old.flow 0 (sol 0) x))))
(at x within {0 .. t})"
using sol_new' apply simp
apply(drule solves_odeD(1))
using tclosed unfolding has_vderiv_on_def has_vector_derivative_def by auto
have new_sol_deriv:"\<And>s. s \<in> {0..t} \<Longrightarrow> (ll_new.flow 0 r has_derivative
(\<lambda>xa. xa *\<^sub>R (ll_new.flow 0 r s * sterm_sem I (f1 fid2 vid1) (sol s) + sterm_sem I (f1 fid3 vid1) (sol s))))
(at s within {0.. t})"
subgoal for s
using fact[of s] tclosed sol_eq_flow[of s] by auto
done
have sterm_agree:"\<And>s. Vagree (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i, undefined) (sol s, undefined) {Inl vid1}"
subgoal for s unfolding Vagree_def using vne12 by auto done
have FVF:"(FVT (f1 fid2 vid1)) = {Inl vid1}" unfolding f1_def expand_singleton apply auto subgoal for x xa by (cases "xa = vid1", auto) done
have FVF2:"(FVT (f1 fid3 vid1)) = {Inl vid1}" unfolding f1_def expand_singleton apply auto subgoal for x xa by (cases "xa = vid1", auto) done
have sterm_agree_FVF:"\<And>s. Vagree (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i, undefined) (sol s, undefined) (FVT (f1 fid2 vid1))"
using sterm_agree FVF by auto
have sterm_agree_FVF2:"\<And>s. Vagree (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i, undefined) (sol s, undefined) (FVT (f1 fid3 vid1))"
using sterm_agree FVF2 by auto
have y_component_sem_eq2:"\<And>s. sterm_sem I (f1 fid2 vid1) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i)
= sterm_sem I (f1 fid2 vid1) (sol s)"
using coincidence_sterm[OF sterm_agree_FVF, of I] by auto
have y_component_sem_eq3:"\<And>s. sterm_sem I (f1 fid3 vid1) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i)
= sterm_sem I (f1 fid3 vid1) (sol s)"
using coincidence_sterm[OF sterm_agree_FVF2, of I] by auto
have y_component_ode_eq:"\<And>s. s \<in> {0..t} \<Longrightarrow>
(\<lambda>xa. xa * (ll_new.flow 0 r s * sterm_sem I (f1 fid2 vid1) (sol s) + sterm_sem I (f1 fid3 vid1) (sol s)))
= (\<lambda>xa. xa * (sterm_sem I (f1 fid2 vid1) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i) * ll_new.flow 0 r s +
sterm_sem I (f1 fid3 vid1) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i)))"
subgoal for s
apply(rule ext)
subgoal for xa
using y_component_sem_eq2 y_component_sem_eq3 by auto
done
done
have agree_vid1:"\<And>s. Vagree (sol s, undefined) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i, undefined) {Inl vid1}"
unfolding Vagree_def using vne12 by auto
have FVT_vid1:"FVT(f1 fid1 vid1) = {Inl vid1}" apply(auto simp add: f1_def) subgoal for x xa apply(cases "xa = vid1") by auto done
have agree_vid1_FVT:"\<And>s. Vagree (sol s, undefined) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i, undefined) (FVT (f1 fid1 vid1))"
using FVT_vid1 agree_vid1 by auto
have sterm_eq_vid1:"\<And>s. sterm_sem I (f1 fid1 vid1) (sol s) = sterm_sem I (f1 fid1 vid1) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i)"
subgoal for s
using coincidence_sterm[OF agree_vid1_FVT[of s], of I] by auto
done
have vid1_deriv_eq:"\<And>s. (\<lambda>xa. xa * sterm_sem I (f1 fid1 vid1) (sol s)) =
(\<lambda>xa. xa * sterm_sem I (f1 fid1 vid1) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i))"
subgoal for s
apply(rule ext)
subgoal for x'
using sterm_eq_vid1[of s] by auto
done done
have inner_deriv:"\<And>s. s \<in> {0..t} \<Longrightarrow>
((\<lambda>t. \<chi> i. if i = vid2 then ll_new.flow 0 r t else sol t $ i) has_derivative (\<lambda>xa. (\<chi> i. xa * (if i = vid1 then sterm_sem I (f1 fid1 vid1) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i) else
if i = vid2 then sterm_sem I (Plus (Times (f1 fid2 vid1) (trm.Var vid2)) (f1 fid3 vid1)) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i) else 0))))
(at s within {0..t})"
subgoal for s
apply(rule has_derivative_vec)
subgoal for i
apply(cases "i = vid2")
subgoal
using vne12
using new_sol_deriv[of s]
using y_component_ode_eq by auto
subgoal
apply(cases "i = vid1")
using sol_proj_deriv_vid1[of s] vid1_deriv_eq[of s] sol_proj_deriv_other[of s i] by auto
done
done
done
have deriv_eta:"\<And>s. (\<lambda>xa. xa *\<^sub>R ((\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i) else 0) +
(\<chi> i. if i = vid2
then sterm_sem I (Plus (Times (f1 fid2 vid1) (trm.Var vid2)) (f1 fid3 vid1))
(\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i)
else 0)))
= (\<lambda>xa. (\<chi> i. xa * (if i = vid1 then sterm_sem I (f1 fid1 vid1) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i) else
if i = vid2 then sterm_sem I (Plus (Times (f1 fid2 vid1) (trm.Var vid2)) (f1 fid3 vid1)) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i) else 0))) "
subgoal for s
apply(rule ext)
apply(rule vec_extensionality)
using vne12 by auto
done
have sol'_deriv:"\<And>s. s \<in> {0..t} \<Longrightarrow>
((\<lambda>t. \<chi> i. if i = vid2 then ll_new.flow 0 r t else sol t $ i) has_derivative
(\<lambda>xa. xa *\<^sub>R ((\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i) else 0) +
(\<chi> i. if i = vid2
then sterm_sem I (Plus (Times (f1 fid2 vid1) (trm.Var vid2)) (f1 fid3 vid1))
(\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i)
else 0))))
(at s within {0..t})"
subgoal for s
using inner_deriv[of s] deriv_eta[of s] by auto done
have FVT:"\<And>i. FVT (if i = vid1 then trm.Var vid1 else Const 0) \<subseteq> {Inl vid1}" by auto
have agree:"\<And>s. Vagree (mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (sol s)) (mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then r else fst (a, b) $ y, b) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i)) {Inl vid1}"
subgoal for s
using mk_v_agree [of "I" "(OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))" "(a, b)" "(sol s)"]
using mk_v_agree [of I "(OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))" "(\<chi> y. if vid2 = y then r else fst (a, b) $ y, b)" "(\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i)"]
unfolding Vagree_def using vne12 by simp
done
have agree':"\<And>s i. Vagree (mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (sol s)) (mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then r else fst (a, b) $ y, b) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i)) (FVT (if i = vid1 then trm.Var vid1 else Const 0))"
subgoal for s i using agree_sub[OF FVT[of i] agree[of s]] by auto done
have safe:"\<And>i. dsafe (if i = vid1 then trm.Var vid1 else Const 0)" subgoal for i apply(cases "i = vid1", auto) done done
have dterm_sem_eq:"\<And>s i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) (mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (sol s))
= dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then r else fst (a, b) $ y, b) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i))"
subgoal for s i using coincidence_dterm[OF safe[of i] agree'[of s i], of I] by auto done
have dterm_vec_eq:"\<And>s. (\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) (mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (sol s)))
= (\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then r else fst (a, b) $ y, b) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i)))"
subgoal for s
apply(rule vec_extensionality)
subgoal for i using dterm_sem_eq[of i s] by auto
done done
have pred_same:"\<And>s. s \<in> {0..t} \<Longrightarrow> Predicates I vid1
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (sol s))) \<Longrightarrow>
Predicates I vid1
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then r else fst (a, b) $ y, b) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i)))"
subgoal for s using dterm_vec_eq[of s] by auto done
have sol'_domain:"\<And>s. 0 \<le> s \<Longrightarrow>
s \<le> t \<Longrightarrow>
Predicates I vid1
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then r else fst (a, b) $ y, b) (\<chi> i. if i = vid2 then ll_new.flow 0 r s else sol s $ i)))"
subgoal for s
using sol apply simp
apply(drule solves_odeD(2))
using pred_same[of s] by auto
done
have sol':"(?sol' solves_ode
(\<lambda>a b. (\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) b else 0) +
(\<chi> i. if i = vid2 then sterm_sem I (Plus (Times (f1 fid2 vid1) (trm.Var vid2)) (f1 fid3 vid1)) b else 0)))
{0..t} {x. Predicates I vid1
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
(\<chi> y. if vid2 = y then r else fst (a, b) $ y, b) x))}"
apply(rule solves_odeI)
subgoal
unfolding has_vderiv_on_def has_vector_derivative_def
using sol'_deriv by auto
by(auto, rule sol'_domain, auto)
have set_eq:"{y. y = vid2 \<or> y = vid1 \<or> y = vid2 \<or> y = vid1 \<or> (\<exists>x. Inl y \<in> FVT (if x = vid1 then trm.Var vid1 else Const 0))} = {vid1, vid2}"
by auto
have "VSagree (?sol' 0) (\<chi> y. if vid2 = y then r else fst (a, b) $ y) {vid1, vid2}"
using VSA unfolding VSagree_def by simp
then have VSA':" VSagree (?sol' 0) (\<chi> y. if vid2 = y then r else fst (a, b) $ y)
{y. y = vid2 \<or> y = vid1 \<or> y = vid2 \<or> y = vid1 \<or> (\<exists>x. Inl y \<in> FVT (if x = vid1 then trm.Var vid1 else Const 0))} "
by (auto simp add: set_eq)
have bigPre:"(\<exists>sol t. (fst ?aaba', snd ?aaba') =
mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
((\<chi> y. if vid2 = y then r else fst (a,b) $ y), b) (sol t) \<and>
0 \<le> t \<and>
(sol solves_ode
(\<lambda>a b. (\<chi> i. if i = vid1 then sterm_sem I (f1 fid1 vid1) b else 0) +
(\<chi> i. if i = vid2 then sterm_sem I (Plus (Times (f1 fid2 vid1) (trm.Var vid2)) (f1 fid3 vid1)) b else 0)))
{0..t} {x. Predicates I vid1
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))
((\<chi> y. if vid2 = y then r else (fst (a,b)) $ y), b) x))} \<and>
VSagree (sol 0) (\<chi> y. if vid2 = y then r else fst (a,b) $ y)
{uu. uu = vid2 \<or>
uu = vid1 \<or>
uu = vid2 \<or>
uu = vid1 \<or>
Inl uu \<in> Inl ` ({x. \<exists>xa. Inl x \<in> FVT (if xa = vid1 then trm.Var vid1 else Const 0)} \<union>
{x. x = vid2 \<or> (\<exists>xa. Inl x \<in> FVT (if xa = vid1 then trm.Var vid1 else Const 0))}) \<or>
(\<exists>x. Inl uu \<in> FVT (if x = vid1 then trm.Var vid1 else Const 0))})"
apply(rule exI[where x="?sol'"])
apply(rule exI[where x=t])
apply(rule conjI)
subgoal by simp
apply(rule conjI)
subgoal by (rule t)
apply(rule conjI)
apply(rule sol')
using VSA' unfolding VSagree_def by auto
have pred_sem:"Predicates I vid2 (\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) ?aaba')"
using mp[OF bigEx bigPre] by auto
let ?other_state = "(mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (sol t))"
have agree:"Vagree (?aaba') (?other_state) {Inl vid1} "
using mk_v_agree [of "I" "(OProd (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))
(OSing vid2
(Plus (Times ($f fid2 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)) (trm.Var vid2))
($f fid3 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))))"
"(\<chi> y. if vid2 = y then r else fst (a, b) $ y, b)" "(?sol' t)"]
using mk_v_agree [of "I" "(OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0)))" "(a, b)" "(sol t)"]
unfolding Vagree_def using vne12 by simp
have sub:"\<And>i. FVT (if i = vid1 then trm.Var vid1 else Const 0) \<subseteq> {Inl vid1}"
by auto
have agree':"\<And>i. Vagree (?aaba') (?other_state) (FVT (if i = vid1 then trm.Var vid1 else Const 0)) "
subgoal for i using agree_sub[OF sub[of i] agree] by auto done
have silly_safe:"\<And>i. dsafe (if i = vid1 then trm.Var vid1 else Const 0)"
subgoal for i
apply(cases "i = vid1")
by (auto simp add: dsafe_Var dsafe_Const)
done
have dsem_eq:"(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) ?aaba') =
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0) ?other_state)"
apply(rule vec_extensionality)
subgoal for i
using coincidence_dterm[OF silly_safe[of i] agree'[of i], of I] by auto
done
show
"Predicates I vid2
(\<chi> i. dterm_sem I (if i = vid1 then trm.Var vid1 else Const 0)
(mk_v I (OSing vid1 ($f fid1 (\<lambda>i. if i = vid1 then trm.Var vid1 else Const 0))) (a, b) (sol t)))"
using pred_sem dsem_eq by auto
qed
done
qed
end end
|
\subsection{Neural Network Design and Training}
\label{subsec:nntraining}
%\begin{wrapfigure}{r}{0.5\textwidth}
% \centering
% \includegraphics[width=0.35\textwidth]{img/nnlayout}
% \caption{Network Layers}
% \label{fig:network-layers}
%\end{wrapfigure}
The network was implemented in PyTorch \cite{Paszke:2019aa} as well as Tensorflow \cite{MartinAbadi:2015aa}. The backend was later exclusively switched to PyTorch (which is also the most common deep learning framework in Science) due to its better support of quantization. The layers of the neural network are depicted in Figure~\ref{fig:eggnet}.
The network was trained on the \emph{MNIST} dataset which consists of 60.000 images of handwritten digits. Those where split up in 50.000 images used for training and 10.000 used for evaluation. The network maps mathematically an $28 \times 28$ input image $x \in \mathbb{R}^{28,28}$ to an output of vector of probabilities $y \in \mathbb{R}^{10}$ where each value corresponds how likely the input image belongs to that class. The layers of the network are listed in Table~\ref{tab:eggnet-layers}.
\begin{table}[h]
\centering
\begin{tabular}{clcl}
\toprule
Layer & Type & Data Size (output) & Purpose \\
\midrule
1 & Conv01 & $[28,28,16]$ & Extract features ($[3,3]$ kernels) \\
2 & ReLU & $[28,28,16]$ & Introduce nonlinearity \\
3 & Pool01 & $[14,14,16]$ & Introduce nonlinearity, reduce dimensions \\
4 & Conv02 & $[14,14,32]$ & Extract features ($[3,3]$ kernels) \\
5 & ReLU & $[14,14,32]$ & Introduce nonlinearity \\
6 & Pool02 & $[7,7,32]$ & Introduce nonlinearity, reduce dimensions \\
7 & Dense01 & $[32]$ & Combine features \\
8 & ReLU & $[32]$ & Introduce nonlinearity \\
9 & Dense02 & $[10]$ & Combine features \\
10 & Softmax & $[10]$ & Normalize output \\
\bottomrule
\end{tabular}
\caption{Eggnet Layers}
\label{tab:eggnet-layers}
\end{table}
Further for training of the network the \emph{ADAM} optimization algorithm \cite{Kingma:2014aa} was used to minimize the cross-entropy-loss function which is defined as
\begin{equation}
J = - y \log(h) + (1-y) \log(1-h)
\end{equation}
This loss function is standard for classification problems where each sample belongs to exactly one class.
The ADAM algorithm can be adjusted by parameters, which control the speed of convergence. The recommended values, listed in Table~\ref{tab:train-params}, by \cite{Kingma:2014aa} were used.
\begin{table}[ht]
\centering
\begin{tabular}{cc}
\toprule
Parameter & Value \\
\midrule
$\alpha$ & $0.001$ \\
$\beta_1$ & $0.9$ \\
$\beta_2$ & $0.999$ \\
\bottomrule
\end{tabular}
\caption{Network Training Parameters}
\label{tab:train-params}
\end{table}
A useful guide for implementing convolutions can be found in \cite{dumoulin2016guide}. The training of the network yielded very high accuracy rates that are typical for the MNIST dataset, which is an easy challenge for machine learning. Even though the network performance could be improved, e.g. by hyperparameter tuning the results were acceptable for our case. The progress of the training in terms of accuracy and loss can be seen in Figure~\ref{fig:network-train-acc} respectively in Figure~\ref{fig:network-train-loss}. The final output of the network over the training is evaluated in Figure~\ref{fig:network-test-cm} for real values and in Figure~\ref{fig:network-test-qcm} for fake quantized values.
Both, PyTorch and Tensorflow/Keras are Python libraries but most \gls{acr:NN} operations are not implemented in Python directly because of performance reasons. This makes debugging more difficult which is why we reimplemented the operations we needed in Python. This was done using NumPy and SWIG, which will be discussed more extensively in Section~\ref{sec:sw-python}, and enabled us to verify the correct ordering of parameters, weights and activations.
\begin{figure}[hbtp]
\centering
\begin{subfigure}[t]{0.5\textwidth}
\includegraphics[width=0.8\textwidth]{../../net/images/training_loss}
\caption{Training Loss}
\label{fig:network-train-loss}
\end{subfigure}%
~
\begin{subfigure}[t]{0.5\textwidth}
\includegraphics[width=0.8\textwidth]{../../net/images/training_accuracy}
\caption{Training Accuracy}
\label{fig:network-train-acc}
\end{subfigure}
\caption[Network loss and accuracy over the training iterations]{Network loss and accuracy over the training iterations. The blue lines show spikes which occur because of the randomly selected mini batches. The orange line shows the smoothed version over 50 periods}
\label{fig:network-training-graphs}
\end{figure}
\begin{figure}[hbtp]
\centering
\begin{subfigure}[t]{0.5\textwidth}
\includegraphics[width=0.9\textwidth]{../../net/images/cm}
\caption{Floating Point}
\label{fig:network-test-cm}
\end{subfigure}%
~
\begin{subfigure}[t]{0.5\textwidth}
\includegraphics[width=0.9\textwidth]{../../net/images/qcm}
\caption{Quantized Values}
\label{fig:network-test-qcm}
\end{subfigure}
\caption{Confusion matrix for the floating point and quantized version of the network.}
\label{fig:network-confusion-matrix}
\end{figure}
\subsection{Quantization}
\label{sec:nn-quant}
The network is trained and created using \SI{32}{\bit} floating point values in Python. Directly porting this all the weights and biases to the FPGA is due to the limited amount of available resources not feasible. The goal is therefore to reduce the amount of required hardware cells by switching from floating point arithmetic to the less expensive integer arithmetic. Then a floating point value $v$ can be approximately represented as
\begin{equation}
v \approx Q \cdot 2 ^{-m}
\end{equation}
where $Q$ and $m$ are integers. In our case all input values of the first layer are guaranteed to lie in the interval $[0,1]$ and all layer weights are known from training. It is therefore possible to precompute the expected range where the output values will be. Depending on this range it is then possible to select a suitable bit width for both $Q$ and $m$.
This is a cost-accuracy trade-off where higher bit widths would improve accuracy as well as increase the amount of hardware resources needed.
In \cite{Wu:2018aa} different strategies of choosing bit widths for $Q$ and $m$ are compared and they observed three main configurations, which are (from simple to advanced):
\begin{enumerate}
\item Use a $(Q,m)$ configuration for the whole network
\item Use a $(Q,m)$ configuration for each layer
\item Use a $(Q,m)$ configuration for each output channel
\end{enumerate}
In the third configuration the authors could reduce the bit widths the most without sacrificing accuracy this increases the complexity in transferring the weights from layer to layer because the additional shift operations are necessary in order to adjust for the different values of $m$.
In \cite{Wu:2018aa} the authors also deduced from their experiments that the accuracy of the weights can be reduced the most, followed by the activations. By analysing the weights of our network (see Figure~\ref{fig:network-weight-distributions}) a per channel quantization is not necessary, because all weights in a Convolutional Layer are equally distributed among the output channels. Another important property that can be noted is the that the weights do have zero mean and most of the values lie very close to zero. Because of the usage of ReLU layer the situation is different for the activations where unsigned integers can be used, the distributions are shown in Figure~\ref{fig:network-activations-distributions}.
Using the distribution histograms we then derived the necessary bitwidths for $Q$ and $m$. In our experiments we were able to reduce them to \SI{8}{\bit}, if we used a single configuration for the whole network and also reducing them down to \SI{4}{\bit} if the bitwidth configuration is selected for each layer independently with an accuracy drop from around \SI{98.35}{\percent} to \SI{97.37}{\percent}. The strategy to the select the values for $(Q,m)$ was
\begin{enumerate}
\item Find the value range of the weights and output activations of each layer
\item Select suitable $(Q,m)$ values that most activations fall in that range
\item Calculate the bit widths and exponents of the multiplication operation
\item Add $\lceil \log_2(n) \rceil$ extra bits to account for the accumulation of $n$ values
\item Compare the accumulated exponents and with the exponents of the successive layers input exponents. The difference is the amount of shift required
\end{enumerate}
It is noteworthy that the values for $m$ do not need to be stored in the final network, because those are only used to determine the amount of shifts between the layers. Also the values need to be clipped to their maximum and minimum values. The complete configuration of the network is summarized in Table~\ref{tab:quantization-linear-params}.
Ad 4 and 5: The transition from a layer to the next often changes the exponent $m$ and the available bitwidth. To account for this the values need to accordingly shifted. Also the decreased bitwidth needs clipping to maximum available values for the target bitwidth. This directly alters the behaviour of the network which should be accounted for during training, which is done via a saturated version of ReLU, defined as:
\begin{equation}
\text{ReLU}_{\text{sat}}: ~ f(x;p) = \begin{cases}
0 \quad \text{if} \quad x < 0 \\
p \quad \text{if} \quad x > p \\
x \quad \text{else}
\end{cases}
\end{equation}
For our network only linear quantization has been used but also non-linear quantization, e.g. in a $\log_2$ way which is proposed in \cite{Lee:2017aa}. Experiments showed that using this technique even further down to \SI{3}{\bit} weights in our case.
Another optimization technique that could be explored is the systematically removing of weights (connections) of the network and reduce the amount of operations needed to be performed, a process referred to as ''pruning'' \cite{Zhu:2017aa}. This was not explicitly performed but is implicitly done by low bit quantization.
\begin{table}[hbt]
\centering
\begin{tabular}{lcccc}
\toprule
Network Part & $|Q|$ & $m$ & $\pm$ & $v$ (real value range) \\
\midrule
Input & 8 & 8 & $+$ & $[0,1] $ \\
L1: Weights & 4 & 2 & $\pm$ & $[-2,2] $ \\
L1: Intermediates & 12 & 10 & $\pm$ & $[-2,2] $ \\
L1: Accumulated & 16 & 10 & $\pm$ & \\
\midrule
L1 $\to$ L2 & \multicolumn{4}{c}{Rshift by $10-2$ and clip values in range $[0,15]$} \\
\midrule
L2: Input & 4 & 2 & $+$ & $[-2,2] $ \\
L2: Weights & 4 & 5 & $\pm$ & $[-0.5,0.5] $ \\
L2: Intermediates & 8 & 7 & $\pm$ & $[-1,1] $ \\
L2: Accumulated & 16 & 7 & $\pm$ & \\
\midrule
L2 $\to$ L3 & \multicolumn{4}{c}{Rshift by $7-0$ and clip values in range $[0,15]$} \\
\midrule
L3: Input & 4 & 0 & $+$ & $[0,15] $ \\
L3: Weights & 4 & 5 & $\pm$ & $[-0.5,0.5] $ \\
L3: Intermediates & 8 & 5 & $\pm$ & $[-7.5,7.5] $ \\
L3: Accumulated & 19 & 5 & $\pm$ & \\
\midrule
L3 $\to$ L4 & \multicolumn{4}{c}{Rshift by $5-0$ and clip values in range $[0,15]$} \\
\midrule
L4: Input & 4 & 0 & $+$ & $[0,15] $ \\
L4: Weights & 4 & 5 & $\pm$ & $[-0.5,0.5] $ \\
L4: Intermediates & 8 & 5 & $\pm$ & $[-7.5,7.5] $ \\
L4: Accumulated & 14 & 5 & $\pm$ & $[0,1] $ \\
\bottomrule
\end{tabular}
\caption[Quantization parameters for the \SI{4}{\bit} network]{Quantization parameters for the \SI{4}{\bit} network. The intermediate terms are the values after the multiplication operation and the accumulated term denotes values after summing up of weighted inputs including bias in a channel.}
\label{tab:quantization-linear-params}
\end{table}
%% WEIGHT DISTTRIBUTIONS
\begin{figure}[htbp]
\centering
\begin{subfigure}[t]{0.5\textwidth}
\centering
\includegraphics[height=1.6in]{../../net/images/hist_cn1_k}
\caption{Convolutional Layer 1}
\end{subfigure}%
~
\begin{subfigure}[t]{0.5\textwidth}
\centering
\includegraphics[height=1.6in]{../../net/images/hist_cn2_k}
\caption{Convolutional Layer 2}
\end{subfigure}%
\\
\begin{subfigure}[t]{0.5\textwidth}
\centering
\includegraphics[height=1.6in]{../../net/images/hist_fc1_w}
\caption{Fully Connected Layer 1}
\end{subfigure}%
~
\begin{subfigure}[t]{0.5\textwidth}
\centering
\includegraphics[height=1.6in]{../../net/images/hist_fc2_w}
\caption{Fully Connected Layer 2}
\end{subfigure}
\caption[Distribution of the network weights for the different layers]{Distribution of the network weights for the different layers. It can be seen that the weights are distributed close to zero.}
\label{fig:network-weight-distributions}
\end{figure}
%% ACTIVATIONS DISTTRIBUTIONS
\begin{figure}[htbp]
\centering
\begin{subfigure}[t]{0.5\textwidth}
\centering
\includegraphics[height=1.6in]{../../net/images/hist_ao1}
\caption{Convolutional Layer 1}
\end{subfigure}%
~
\begin{subfigure}[t]{0.5\textwidth}
\centering
\includegraphics[height=1.6in]{../../net/images/hist_ao2}
\caption{Convolutional Layer 2}
\end{subfigure}%
\\
\begin{subfigure}[t]{0.5\textwidth}
\centering
\includegraphics[height=1.6in]{../../net/images/hist_ao3}
\caption{Fully Connected Layer 1}
\end{subfigure}%
~
\begin{subfigure}[t]{0.5\textwidth}
\centering
\includegraphics[height=1.6in]{../../net/images/hist_ao4}
\caption{Fully Connected Layer 2}
\end{subfigure}
\caption[Distribution of the activations for a randomly selected batch of the input data]{Distribution of the activations for a randomly selected batch of the input data. The occurring minimum and maximum values were used to define the quantization bit width.}
\label{fig:network-activations-distributions}
\end{figure}
|
(*|
######################
Coq inference behavior
######################
:Link: https://stackoverflow.com/q/36996020
|*)
(*|
Question
********
I'm trying to write the following Agda snippet in Coq.
.. code-block:: agda
open import Data.Fin using (Fin; suc; zero)
open import Data.Nat using (ℕ; suc; zero)
thin : {n : ℕ} -> Fin (suc n) -> Fin n -> Fin (suc n)
thin zero y = suc y
thin (suc x) zero = zero
thin (suc x) (suc y) = suc (thin x y)
I thought this could be straightforwardly translated to Coq as:
|*)
Inductive Fin : nat -> Type :=
| fz {n : nat} : Fin (S n)
| fs {n : nat} : Fin n -> Fin (S n).
Fail Fixpoint thin {n : nat} (x : Fin (S n)) (y : Fin n) : Fin (S n) :=
match x, y with
| fz, y' => fs y'
| fs x', fz => fz
| fs x', fs y' => fs (thin x' y')
end. (* .fails *)
(*|
I believe Coq should be able to figure out the implicit parameter
``n`` so I have no idea what is going on. I think I am unaware of a
difference between the type systems of Agda and Coq since the former
typechecks fine.
|*)
(*|
Answer
******
When pattern matching with dependent types, Coq does not usually
consider some essential relations between the variables in the context
and the variables introduced in the branches.
The easiest solution is to define the function in proof mode, at least
to understand what is going on.
This gives:
|*)
Fixpoint thin {n : nat} (x : Fin (S n)) (y : Fin n) : Fin (S n).
Proof.
remember (S n) as n1. (* trick to keep the information when destructing *)
destruct x; apply eq_add_S in Heqn1; subst n0.
- apply fs. assumption.
- destruct y.
+ apply fz.
+ apply fs. apply thin; assumption.
Defined. (* to create a transparent constant, as given by a classic Fixpoint *)
(*|
You can then print the value and read the lambda term to understand
how to define it directly. This could give:
|*)
Print thin. (* .unfold .messages *)
(*|
The ``return`` clauses of the pattern matchings is used to solve the
problem presented above: they connect the variables introduced in the
branches and the ones in the context. This is discussed more deeply
here: http://adam.chlipala.net/cpdt/html/MoreDep.html.
Also note that this particular inductive type was discussed a few
weeks ago on the coq-club mailing list. See
https://sympa.inria.fr/sympa/arc/coq-club/2016-03/msg00206.html.
----
**Q:** This helps a lot, thanks! I should have finished Chlipala's
book before actually trying to do stuff in Coq. One more question I
have: is it considered bad practice to define functions in proof mode?
**A:** I don't really know. Usually, I do that to check the lambda
term and write it myself. Anyway, I try to use mostly low-level
tactics to create a readable lambda term. Tactics like ``inversion``
create
**A:** Tactics like ``inversion`` create non-natural terms and should
be avoided. Maybe other users have stronger opinions on this
particular subject.
|*)
|
% !TEX root = ../root.tex
\section{Problem formulation}\label{sec:problem}
The aim of the project is to design and develop a UAVCAN-compatible indoor positioning system for aerial unmanned veicles (UAVs) based on the \emph{decaWave} devices.
Using these radio modules, an algorithm shall be devised and implemented in order to estimate the UAV position in a 2D coordinate system.
The resulting information is to be broadcasted through the UAVCAN bus --- a message definition shall be chosen amongst the pool of standard definitions, or designed from scratch.
The performance of the system ought to be in line with decaWave's claims in term of maximum accuracy and range, and the device has to be suitable for battery operation.
Moreover, the system shall comply with the UAVCAN specifications and support its major standard functionalities.
The project is carried out in collaboration with \emph{UAVComponents ApS}, which will lend its expertise in hardware design and provide the necessary development tools.
|
-- Reported by nils.anders.danielsson, Feb 17, 2015
-- See also Issue 292 , Issue 1406 , and Issue 1427.
-- The code below is accepted by Agda 2.4.2.2, but not by the current
-- maintenance or master branches.
data Box (A : Set) : Set where
[_] : A → Box A
data _≡_ (A : Set) : Set → Set₁ where
refl : A ≡ A
data _≅_ {A : Set₁} (x : A) : {B : Set₁} → B → Set₂ where
refl : x ≅ x
-- C could be a typed DSEL.
data C : Set → Set₁ where
c₁ c₂ : (A : Set) → C (Box A)
-- If A is considered forced, the code no longer type-checks.
-- D could be some kind of semantics for C.
data D : {A : Set} → C A → Set₂ where
d₁ : (A : Set) → D (c₁ A)
d₂ : (A : Set) → D (c₂ A)
module Doesn't-work where
-- Let's try to write an eliminator for the part of the semantics
-- that concerns c₁ programs. The basic approach doesn't work:
D-elim-c₁ : (P : {A : Set} → D (c₁ A) → Set₂) →
((A : Set) → P (d₁ A)) →
{A : Set} (x : D (c₁ A)) → P x
D-elim-c₁ P p (d₁ A) = p A
-- The following trick also fails (but for some reason the absurd
-- case is accepted):
-- Jesper 2015-12-18 update: this is no longer accepted by the new unifier.
--D-elim-c₁-helper :
-- (P : {A B : Set} {c : C A} →
-- D c → A ≡ Box B → c ≅ c₁ B → Set₂) →
-- ((A : Set) → P (d₁ A) refl refl) →
-- {A B : Set} {c : C A}
-- (x : D c) (eq₂ : c ≅ c₁ B) (eq₁ : A ≡ Box B) → P x eq₁ eq₂
--D-elim-c₁-helper P p (d₂ A) () _
--D-elim-c₁-helper P p (d₁ A) refl refl = p A
module Works where
-- I can define the eliminators by first defining and proving no
-- confusion (following McBride, Goguen and McKinna). However, this
-- requires a fair amount of work, and easy dependent pattern
-- matching is arguably one of the defining features of Agda.
--
-- A quote from "A Few Constructions on Constructors": "The Epigram
-- language and system [25, 23] takes these constructions for
-- granted. We see no reason why the users of other systems should
-- work harder than we do."
data ⊥ : Set₁ where
No-confusion : ∀ {A B} → C A → C B → Set₁
No-confusion (c₁ A) (c₁ B) = A ≡ B
No-confusion (c₂ A) (c₂ B) = A ≡ B
No-confusion _ _ = ⊥
no-confusion :
∀ {A B} (x : C A) (y : C B) → A ≡ B → x ≅ y → No-confusion x y
no-confusion (c₁ A) .(c₁ A) refl refl = refl
no-confusion (c₂ A) .(c₂ A) refl refl = refl
D-elim-c₁-helper :
(P : {A B : Set} {c : C A} →
D c → A ≡ Box B → c ≅ c₁ B → Set₂) →
((A : Set) → P (d₁ A) refl refl) →
{A B : Set} {c : C A}
(x : D c) (eq₂ : c ≅ c₁ B) (eq₁ : A ≡ Box B) → P x eq₁ eq₂
D-elim-c₁-helper P p (d₁ A) eq₂ eq₁ with no-confusion _ _ eq₁ eq₂
D-elim-c₁-helper P p (d₁ B) refl refl | refl = p B
D-elim-c₁-helper P p (d₂ A) eq₂ eq₁ with no-confusion _ _ eq₁ eq₂
D-elim-c₁-helper P p (d₂ A) eq₂ eq₁ | ()
cast : {A B : Set} {x : C A} {y : C B} →
A ≡ B → x ≅ y → D x → D y
cast refl refl x = x
D-elim-c₁ :
(P : {A : Set} → D (c₁ A) → Set₂) →
((A : Set) → P (d₁ A)) →
{A : Set} (x : D (c₁ A)) → P x
D-elim-c₁ P p x =
D-elim-c₁-helper (λ x eq₁ eq₂ → P (cast eq₁ eq₂ x)) p x refl refl
-- should type-check
|
/-
Copyright (c) 2023 Huub Vromen. All rights reserved.
Author: Huub Vromen
-/
import data.set.basic
/-- First-order semantics for Aristotle's assertoric syllogisms
A first-order logic semantics is a variant of a set-theoretic semantics.
See, for instance Malink (2013, ch. 3).
Terms are interpreted as non-empty subsets of some set of individuals. -/
variable {α : Type}
variable {x : α}
variables {A B C : α → Prop}
/-- semantics of the `a` relation -/
def universal_affirmative (A: α → Prop) (B: α → Prop) : Prop :=
∀x, B x → A x
infixr ` a ` : 80 := universal_affirmative
/-- semantics of the `e` relation -/
def universal_negative (A: α → Prop) (B: α → Prop) : Prop :=
∀x, B x → ¬ A x
infixr ` e ` : 80 := universal_negative
/-- semantics of the `i` relation -/
def particular_affirmative (A: α → Prop) (B: α → Prop) : Prop :=
∃x, A x ∧ B x
-- existential import needs to be stipulated
infixr ` i ` : 80 := particular_affirmative
/-- semantics of the `o` relation -/
def particular_negative (A: α → Prop) (B: α → Prop) : Prop :=
∃x, B x ∧ ¬ A x
infixr ` o ` : 80 := particular_negative
/-- semantics of contradictory: contradictory is defined as negation -/
def c (p : Prop) : Prop := ¬ p
/-- We prove the soundness of the axiom system DR -/
lemma Barbara₁ : A a B → B a C → A a C :=
begin
intros h1 h2,
rw universal_affirmative,
{ intros p h3,
have h4 : B p := by exact h2 p h3,
exact h1 p h4 },
end
lemma Celarent₁ : A e B → B a C → A e C :=
begin
intros h1 h2 p h3,
have h4 : B p := by exact h2 p h3,
exact h1 p h4
end
lemma e_conv : A e B → B e A :=
begin
intros h1 b h2,
by_contra,
show false, from (h1 b h) h2,
end
lemma a_conv (hex: ∃x, B x) : A a B → B i A :=
begin
intro h1,
rw universal_affirmative at h1,
rw particular_affirmative,
cases hex with p hp,
apply exists.intro p (and.intro hp (h1 p hp))
end
lemma contr {p r : Prop} : (c r → c p) → p → r :=
begin
intros h1,
contrapose,
assumption
end
/-- We can also prove the contradictories axioms -/
lemma contr_a : c (A a B) = A o B := by simp [c, particular_negative, universal_affirmative]
lemma contr_e : c (A e B) = A i B :=
begin
simp [c, particular_affirmative, universal_negative],
finish
end
lemma contr_i : c (A i B) = A e B :=
begin
simp [c, particular_affirmative, universal_negative],
finish
end
lemma contr_o : c (A o B) = A a B := by simp [c, particular_negative, universal_affirmative]
/-- it is, of course, also possible to prove the redundant axioms -/
lemma Darii₁ : A a B → B i C → A i C :=
begin
intros h1 h2,
cases h2 with p h,
apply exists.intro p,
exact and.intro (h1 p h.1) h.2
end
lemma Ferio₁ : A e B → B i C → A o C :=
begin
intros h1 h2,
cases h2 with p h,
--rw universal_denial at h1,
have h3 : ¬ A p := by exact h1 p h.1,
--rw particular_denial,
apply exists.intro p (and.intro h.2 h3)
end
lemma i_conv : A i B → B i A :=
begin
intros h1,
cases h1 with p h2,
cases h2 with q r,
apply exists.intro p (and.intro r q)
end
#lint |
module Nat.Sum where
open import Data.Nat
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open DecTotalOrder decTotalOrder hiding (refl)
+id : (n : ℕ) → n + zero ≡ n
+id zero = refl
+id (suc n) = cong suc (+id n)
+assoc : (m n : ℕ) → m + suc n ≡ suc (m + n)
+assoc zero n = refl
+assoc (suc m) n = cong suc (+assoc m n)
|
lemma limitin_subsequence: "\<lbrakk>strict_mono r; limitin X f l sequentially\<rbrakk> \<Longrightarrow> limitin X (f \<circ> r) l sequentially" |
If $c$ is a component of $s$, then $s - c$ is the union of all components of $s$ other than $c$. |
Formal statement is: lemma Lim_transform_away_within: fixes a b :: "'a::t1_space" assumes "a \<noteq> b" and "\<forall>x\<in>S. x \<noteq> a \<and> x \<noteq> b \<longrightarrow> f x = g x" and "(f \<longlongrightarrow> l) (at a within S)" shows "(g \<longlongrightarrow> l) (at a within S)" Informal statement is: If $f$ and $g$ are functions defined on a set $S$ and $f$ converges to $l$ at $a$ within $S$, then $g$ converges to $l$ at $a$ within $S$ if $f$ and $g$ agree on $S$ except possibly at $a$ and $b$. |
Formal statement is: proposition maximum_modulus_frontier: assumes holf: "f holomorphic_on (interior S)" and contf: "continuous_on (closure S) f" and bos: "bounded S" and leB: "\<And>z. z \<in> frontier S \<Longrightarrow> norm(f z) \<le> B" and "\<xi> \<in> S" shows "norm(f \<xi>) \<le> B" Informal statement is: If $f$ is holomorphic on the interior of a bounded set $S$ and continuous on the closure of $S$, and if $f$ is bounded on the boundary of $S$, then $f$ is bounded on $S$. |
module Tables
using LinearAlgebra, DataValueInterfaces, DataAPI, TableTraits, IteratorInterfaceExtensions
export rowtable, columntable
if !hasmethod(getproperty, Tuple{Tuple, Int})
Base.getproperty(t::Tuple, i::Int) = t[i]
end
"Abstract row type with a simple required interface: row values are accessible via `getproperty(row, field)`; for example, a NamedTuple like `nt = (a=1, b=2, c=3)` can access its value for `a` like `nt.a` which turns into a call to the function `getproperty(nt, :a)`"
abstract type Row end
"""
The Tables.jl package provides simple, yet powerful interface functions for working with all kinds tabular data through predictable access patterns.
```julia
Tables.rows(table) => Rows
Tables.columns(table) => Columns
```
Where `Rows` and `Columns` are the duals of each other:
* `Rows` is an iterator of property-accessible objects (any type that supports `propertynames(row)` and `getproperty(row, nm::Symbol`)
* `Columns` is a property-accessible object of iterators (i.e. each column is an iterator)
In addition to these `Rows` and `Columns` objects, it's useful to be able to query properties of these objects:
* `Tables.schema(x::Union{Rows, Columns}) => Union{Tables.Schema, Nothing}`: returns a `Tables.Schema` object, or `nothing` if the table's schema is unknown
* For the `Tables.Schema` object:
* column names can be accessed as a tuple of Symbols like `sch.names`
* column types can be accessed as a tuple of types like `sch.types`
* See `?Tables.Schema` for more details on this type
A big part of the power in these simple interface functions is that each (`Tables.rows` & `Tables.columns`) is defined for any table type, even if the table type only explicitly implements one interface function or the other.
This is accomplished by providing performant, generic fallback definitions in Tables.jl itself (though obviously nothing prevents a table type from implementing each interface function directly).
With these simple definitions, powerful workflows are enabled:
* A package providing data cleansing, manipulation, visualization, or analysis can automatically handle any number of decoupled input table types
* A tabular file format can have automatic integration with in-memory structures and translation to other file formats
So how does one go about satisfying the Tables.jl interface functions? It mainly depends on what you've already defined and the natural access patterns of your table:
First:
* `Tables.istable(::Type{<:MyTable}) = true`: this provides an explicit affirmation that your type implements the Tables interface
To support `Rows`:
* Define `Tables.rowaccess(::Type{<:MyTable}) = true`: this signals to other types that `MyTable` supports valid `Row`-iteration
* Define `Tables.rows(x::MyTable)`: return a `Row`-iterator object (perhaps the table itself if already defined)
* Define `Tables.schema(Tables.rows(x::MyTable))` to either return a `Tables.Schema` object, or `nothing` if the schema is unknown or non-inferrable for some reason
To support `Columns`:
* Define `Tables.columnaccess(::Type{<:MyTable}) = true`: this signals to other types that `MyTable` supports returning a valid `Columns` object
* Define `Tables.columns(x::MyTable)`: return a `Columns`, property-accessible object (perhaps the table itself if it naturally supports property-access to columns)
* Define `Tables.schema(Tables.columns(x::MyTable))` to either return a `Tables.Schema` object, or `nothing` if the schema is unknown or non-inferrable for some reason
The final question is how `MyTable` can be a "sink" for any other table type. The answer is quite simple: use the interface functions!
* Define a function or constructor that takes, at a minimum, a single, untyped argument and then calls `Tables.rows` or `Tables.columns` on that argument to construct an instance of `MyTable`
For example, if `MyTable` is a row-oriented format, I might define my "sink" function like:
```julia
function MyTable(x)
Tables.istable(x) || throw(ArgumentError("MyTable requires a table input"))
rows = Tables.rows(x)
sch = Tables.schema(rows)
names = sch.names
types = sch.types
# custom constructor that creates an "empty" MyTable according to given column names & types
# note that the "unknown" schema case should be considered, i.e. when `sch.types => nothing`
mytbl = MyTable(names, types)
for row in rows
# a convenience function provided in Tables.jl for "unrolling" access to each column/property of a `Row`
# it works by applying a provided function to each value; see `?Tables.eachcolumn` for more details
Tables.eachcolumn(sch, row) do val, col, name
push!(mytbl[col], val)
end
end
return mytbl
end
```
Alternatively, if `MyTable` is column-oriented, perhaps my definition would be more like:
```julia
function MyTable(x)
Tables.istable(x) || throw(ArgumentError("MyTable requires a table input"))
cols = Tables.columns(x)
# here we use Tables.eachcolumn to iterate over each column in a `Columns` object
return MyTable(collect(propertynames(cols)), [collect(col) for col in Tables.eachcolumn(cols)])
end
```
Obviously every table type is different, but via a combination of `Tables.rows` and `Tables.columns` each table type should be able to construct an instance of itself.
"""
abstract type Table end
# default definitions
istable(x::T) where {T} = istable(T) || TableTraits.isiterabletable(x) === true
istable(::Type{T}) where {T} = false
rowaccess(x::T) where {T} = rowaccess(T)
rowaccess(::Type{T}) where {T} = false
columnaccess(x::T) where {T} = columnaccess(T)
columnaccess(::Type{T}) where {T} = false
schema(x) = nothing
materializer(x) = columntable
# Schema implementation
"""
Tables.Schema(names, types)
Create a `Tables.Schema` object that holds the column names and types for a tabular data object.
`Tables.Schema` is dual-purposed: provide an easy interface for users to query these properties,
as well as provide a convenient "structural" type for code generation.
To get a table's schema, one can call `Tables.schema(tbl)`, but also note that a table may return `nothing`,
indicating that it's column names and/or column types are unknown (usually not inferrable). This is similar
to the `Base.EltypeUnknown()` trait for iterators when `Base.IteratorEltype` is called. Users should account
for the `Tables.schema(tbl) => nothing` case by using the properties of the results of `Tables.rows(x)` and `Tables.columns(x)`
directly.
To access the names, one can simply call `sch.names` to return the tuple of Symbols.
To access column types, one can similarly call `sch.types`, which will return a tuple of types (like `(Int64, Float64, String)`).
The actual type definition is
```julia
struct Schema{names, types} end
```
Where `names` is a tuple of Symbols, and `types` is a tuple _type_ of types (like `Tuple{Int64, Float64, String}`).
Encoding the names & types as type parameters allows convenient use of the type in generated functions
and other optimization use-cases.
"""
struct Schema{names, types} end
Schema(names::Tuple{Vararg{Symbol}}, types::Type{T}) where {T <: Tuple} = Schema{names, T}()
Schema(::Type{NamedTuple{names, types}}) where {names, types} = Schema{names, types}()
# pass through Ints to allow Tuples to act as rows
sym(x) = Symbol(x)
sym(x::Int) = x
Schema(names, ::Nothing) = Schema{Tuple(Base.map(sym, names)), nothing}()
Schema(names, types) = Schema{Tuple(Base.map(sym, names)), Tuple{types...}}()
function Base.show(io::IO, sch::Schema{names, types}) where {names, types}
println(io, "Tables.Schema:")
Base.print_matrix(io, hcat(collect(names), types === nothing ? fill(nothing, length(names)) : collect(fieldtype(types, i) for i = 1:fieldcount(types))))
end
function Base.getproperty(sch::Schema{names, types}, field::Symbol) where {names, types}
if field === :names
return names
elseif field === :types
return types === nothing ? nothing : Tuple(fieldtype(types, i) for i = 1:fieldcount(types))
else
throw(ArgumentError("unsupported property for Tables.Schema"))
end
end
Base.propertynames(sch::Schema) = (:names, :types)
# helper functions
include("utils.jl")
# reference implementations: Vector of NamedTuples and NamedTuple of Vectors
include("namedtuples.jl")
# generic fallback definitions
include("fallbacks.jl")
# allow any valid iterator to be a table
include("tofromdatavalues.jl")
# simple table operations on table inputs
include("operations.jl")
# matrix integration
include("matrix.jl")
"Return the column index (1-based) of a `colname` in a table with a known schema; returns 0 if `colname` doesn't exist in table"
columnindex(table, colname) = columnindex(schema(table).names, colname)
"Return the column type of a `colname` in a table with a known schema; returns Union{} if `colname` doesn't exist in table"
columntype(table, colname) = columntype(schema(table), colname)
end # module
|
(** * System Fsub subtyping without arrow types *)
Require Export unscoped.
Reserved Notation " Γ |-' s <: t" (at level 68, s, t at next level).
(** ** Syntax of types *)
Inductive type : Type :=
| var_type : fin -> type
| top : type
| all : type -> type -> type.
Fixpoint ren_type (ξ : fin -> fin) (t : type) : type :=
match t return type with
| var_type n => var_type (ξ n)
| top => top
| all t0 t1 => all (ren_type ξ t0) (ren_type (up_ren ξ) t1)
end.
Fixpoint subst_type (θ : fin -> type) (t : type) : type :=
match t return type with
| var_type n => θ n
| top => top
| all t0 t1 => all (subst_type θ t0) (subst_type (var_type 0 .: θ >> ren_type ↑) t1)
end.
(** ** Subtyping relation *)
Inductive sub' (Γ : list type) : type -> type -> Prop :=
| Refl τ : Γ |-' τ <: τ
| Trans σ τ υ : Γ |-' σ <: τ -> Γ |-' τ <: υ ->
Γ |-' σ <: υ
| Top τ : Γ |-' τ <: top
| Var n : Γ |-' var_type n <: nth_default (var_type n) Γ n
| All σ1 σ2 τ1 τ2 : Γ |-' τ1 <: σ1 -> map (ren_type ↑) (τ1 :: Γ) |-' σ2 <: τ2 ->
Γ |-' (all σ1 σ2) <: (all τ1 τ2)
where "Γ |-' σ <: τ" := (sub' Γ σ τ).
(** ** Subtyping problem *)
Definition Fsub'_SUBTYPE : (list type * (type * type)) -> Prop
:= fun ctt => let (Γ, tt) := ctt in let (σ, τ) := tt
in Γ |-' σ <: τ. |
module SemVar.Parser
import SemVar.Lexer
import SemVar.Data
import Text.Parser
import Text.Token
import Data.List
import public SemVar.Tokens
%default total
release : Grammar _ SemVarToken True String
release =
do
match Hyphen
match Text
metadata : Grammar _ SemVarToken True String
metadata =
do
match Plus
match Text
dotOrDefault : Grammar _ SemVarToken False Int
dotOrDefault =
option 0 (
do
match Dot
match Number
)
version : Grammar _ SemVarToken True Version
version =
do
major <- match Number
minor <- dotOrDefault
patch <- dotOrDefault
release <- optional release
metadata <- optional metadata
pure (MkVersion major minor patch release metadata)
tilde : Grammar _ SemVarToken True Requirement
tilde =
do
match Tilde
v <- version
pure $ AND (GTE v) (LT $ nextMinor v)
pin : Grammar _ SemVarToken True Requirement
pin =
do
match Caret
v <- version
pure $ case v of
MkVersion 0 0 patch Nothing Nothing =>
EQ v
_ =>
AND (GTE v) (LT $ nextMajor v)
exact : Grammar _ SemVarToken True Requirement
exact =
do
ignore $ optional (match CmpEQ)
v <- version
pure $ EQ v
gt : Grammar _ SemVarToken True Requirement
gt =
do
ignore $ optional (match CmpGT)
v <- version
pure $ GT v
lt : Grammar _ SemVarToken True Requirement
lt =
do
ignore $ optional (match CmpLT)
v <- version
pure $ LT v
gte : Grammar _ SemVarToken True Requirement
gte =
do
ignore $ optional (match CmpGTE)
v <- version
pure $ GTE v
lte : Grammar _ SemVarToken True Requirement
lte =
do
ignore $ optional (match CmpLTE)
v <- version
pure $ LTE v
range : Grammar _ SemVarToken True Requirement
range =
do
v0 <- version
ignore $ optional (match Whitespace)
match Hyphen
ignore $ optional (match Whitespace)
v1 <- version
pure $ AND (GTE v0) (LTE v1)
simpleRequirement : Grammar _ SemVarToken True Requirement
simpleRequirement =
(
range
<|> tilde
<|> pin
<|> exact
<|> gte
<|> gt
<|> lte
<|> lt
)
conj : Grammar _ SemVarToken True Requirement
conj =
do
v0 <- simpleRequirement
match Whitespace
v1 <- simpleRequirement
pure $ AND v0 v1
disjuction : Grammar _ SemVarToken True Requirement
disjuction =
do
v0 <- simpleRequirement
ignore $ optional (match Whitespace)
ignore $ match Pipe
ignore $ optional (match Whitespace)
v1 <- simpleRequirement
pure $ OR v0 v1
requirement : Grammar _ SemVarToken True Requirement
requirement =
(
conj
<|> disjuction
<|> simpleRequirement
)
export
parseVersionToks : List (WithBounds SemVarToken) -> Maybe Version
parseVersionToks toks = case parse version toks of
Right (j, []) => Just j
_ => Nothing
export
parseRequirementToks : List (WithBounds SemVarToken) -> Maybe Requirement
parseRequirementToks toks = case parse requirement toks of
Right (j, []) => Just j
_ => Nothing
|
State Before: α : Type ?u.8872
β : Type u_2
ι : Type ?u.8878
E : Type u_1
F : Type ?u.8884
𝕜 : Type ?u.8887
inst✝⁵ : MeasurableSpace β
inst✝⁴ : MeasurableSpace E
inst✝³ : NormedAddCommGroup E
inst✝² : NormedAddCommGroup F
q : ℝ
p : ℝ≥0∞
inst✝¹ : OpensMeasurableSpace E
f : β → E
hf : Measurable f
s : Set E
y₀ : E
h₀ : y₀ ∈ s
inst✝ : SeparableSpace ↑s
x : β
n : ℕ
⊢ ‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ≤ ‖f x - y₀‖₊ State After: α : Type ?u.8872
β : Type u_2
ι : Type ?u.8878
E : Type u_1
F : Type ?u.8884
𝕜 : Type ?u.8887
inst✝⁵ : MeasurableSpace β
inst✝⁴ : MeasurableSpace E
inst✝³ : NormedAddCommGroup E
inst✝² : NormedAddCommGroup F
q : ℝ
p : ℝ≥0∞
inst✝¹ : OpensMeasurableSpace E
f : β → E
hf : Measurable f
s : Set E
y₀ : E
h₀ : y₀ ∈ s
inst✝ : SeparableSpace ↑s
x : β
n : ℕ
this : edist (↑(approxOn f hf s y₀ h₀ n) x) (f x) ≤ edist y₀ (f x)
⊢ ‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ≤ ‖f x - y₀‖₊ Tactic: have := edist_approxOn_le hf h₀ x n State Before: α : Type ?u.8872
β : Type u_2
ι : Type ?u.8878
E : Type u_1
F : Type ?u.8884
𝕜 : Type ?u.8887
inst✝⁵ : MeasurableSpace β
inst✝⁴ : MeasurableSpace E
inst✝³ : NormedAddCommGroup E
inst✝² : NormedAddCommGroup F
q : ℝ
p : ℝ≥0∞
inst✝¹ : OpensMeasurableSpace E
f : β → E
hf : Measurable f
s : Set E
y₀ : E
h₀ : y₀ ∈ s
inst✝ : SeparableSpace ↑s
x : β
n : ℕ
this : edist (↑(approxOn f hf s y₀ h₀ n) x) (f x) ≤ edist y₀ (f x)
⊢ ‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ≤ ‖f x - y₀‖₊ State After: α : Type ?u.8872
β : Type u_2
ι : Type ?u.8878
E : Type u_1
F : Type ?u.8884
𝕜 : Type ?u.8887
inst✝⁵ : MeasurableSpace β
inst✝⁴ : MeasurableSpace E
inst✝³ : NormedAddCommGroup E
inst✝² : NormedAddCommGroup F
q : ℝ
p : ℝ≥0∞
inst✝¹ : OpensMeasurableSpace E
f : β → E
hf : Measurable f
s : Set E
y₀ : E
h₀ : y₀ ∈ s
inst✝ : SeparableSpace ↑s
x : β
n : ℕ
this : edist (↑(approxOn f hf s y₀ h₀ n) x) (f x) ≤ edist (f x) y₀
⊢ ‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ≤ ‖f x - y₀‖₊ Tactic: rw [edist_comm y₀] at this State Before: α : Type ?u.8872
β : Type u_2
ι : Type ?u.8878
E : Type u_1
F : Type ?u.8884
𝕜 : Type ?u.8887
inst✝⁵ : MeasurableSpace β
inst✝⁴ : MeasurableSpace E
inst✝³ : NormedAddCommGroup E
inst✝² : NormedAddCommGroup F
q : ℝ
p : ℝ≥0∞
inst✝¹ : OpensMeasurableSpace E
f : β → E
hf : Measurable f
s : Set E
y₀ : E
h₀ : y₀ ∈ s
inst✝ : SeparableSpace ↑s
x : β
n : ℕ
this : edist (↑(approxOn f hf s y₀ h₀ n) x) (f x) ≤ edist (f x) y₀
⊢ ‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ≤ ‖f x - y₀‖₊ State After: α : Type ?u.8872
β : Type u_2
ι : Type ?u.8878
E : Type u_1
F : Type ?u.8884
𝕜 : Type ?u.8887
inst✝⁵ : MeasurableSpace β
inst✝⁴ : MeasurableSpace E
inst✝³ : NormedAddCommGroup E
inst✝² : NormedAddCommGroup F
q : ℝ
p : ℝ≥0∞
inst✝¹ : OpensMeasurableSpace E
f : β → E
hf : Measurable f
s : Set E
y₀ : E
h₀ : y₀ ∈ s
inst✝ : SeparableSpace ↑s
x : β
n : ℕ
this : ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ≤ ↑‖f x - y₀‖₊
⊢ ‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ≤ ‖f x - y₀‖₊ Tactic: simp only [edist_nndist, nndist_eq_nnnorm] at this State Before: α : Type ?u.8872
β : Type u_2
ι : Type ?u.8878
E : Type u_1
F : Type ?u.8884
𝕜 : Type ?u.8887
inst✝⁵ : MeasurableSpace β
inst✝⁴ : MeasurableSpace E
inst✝³ : NormedAddCommGroup E
inst✝² : NormedAddCommGroup F
q : ℝ
p : ℝ≥0∞
inst✝¹ : OpensMeasurableSpace E
f : β → E
hf : Measurable f
s : Set E
y₀ : E
h₀ : y₀ ∈ s
inst✝ : SeparableSpace ↑s
x : β
n : ℕ
this : ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ≤ ↑‖f x - y₀‖₊
⊢ ‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ≤ ‖f x - y₀‖₊ State After: no goals Tactic: exact_mod_cast this |
```python
%matplotlib inline
```
# Bayesian optimization with `skopt`
Gilles Louppe, Manoj Kumar July 2016.
Reformatted by Holger Nahrstaedt 2020
.. currentmodule:: skopt
## Problem statement
We are interested in solving
\begin{align}x^* = arg \min_x f(x)\end{align}
under the constraints that
- $f$ is a black box for which no closed form is known
(nor its gradients);
- $f$ is expensive to evaluate;
- and evaluations of $y = f(x)$ may be noisy.
**Disclaimer.** If you do not have these constraints, then there
is certainly a better optimization algorithm than Bayesian optimization.
This example uses :class:`plots.plot_gaussian_process` which is available
since version 0.8.
## Bayesian optimization loop
For $t=1:T$:
1. Given observations $(x_i, y_i=f(x_i))$ for $i=1:t$, build a
probabilistic model for the objective $f$. Integrate out all
possible true functions, using Gaussian process regression.
2. optimize a cheap acquisition/utility function $u$ based on the
posterior distribution for sampling the next point.
$x_{t+1} = arg \min_x u(x)$
Exploit uncertainty to balance exploration against exploitation.
3. Sample the next observation $y_{t+1}$ at $x_{t+1}$.
## Acquisition functions
Acquisition functions $u(x)$ specify which sample $x$: should be
tried next:
- Expected improvement (default):
$-EI(x) = -\mathbb{E} [f(x) - f(x_t^+)]$
- Lower confidence bound: $LCB(x) = \mu_{GP}(x) + \kappa \sigma_{GP}(x)$
- Probability of improvement: $-PI(x) = -P(f(x) \geq f(x_t^+) + \kappa)$
where $x_t^+$ is the best point observed so far.
In most cases, acquisition functions provide knobs (e.g., $\kappa$) for
controlling the exploration-exploitation trade-off.
- Search in regions where $\mu_{GP}(x)$ is high (exploitation)
- Probe regions where uncertainty $\sigma_{GP}(x)$ is high (exploration)
```python
print(__doc__)
import numpy as np
np.random.seed(237)
import matplotlib.pyplot as plt
from skopt.plots import plot_gaussian_process
```
## Toy example
Let assume the following noisy function $f$:
```python
noise_level = 0.1
def f(x, noise_level=noise_level):
return np.sin(5 * x[0]) * (1 - np.tanh(x[0] ** 2))\
+ np.random.randn() * noise_level
```
**Note.** In `skopt`, functions $f$ are assumed to take as input a 1D
vector $x$: represented as an array-like and to return a scalar
$f(x)$:.
```python
# Plot f(x) + contours
x = np.linspace(-2, 2, 400).reshape(-1, 1)
fx = [f(x_i, noise_level=0.0) for x_i in x]
plt.plot(x, fx, "r--", label="True (unknown)")
plt.fill(np.concatenate([x, x[::-1]]),
np.concatenate(([fx_i - 1.9600 * noise_level for fx_i in fx],
[fx_i + 1.9600 * noise_level for fx_i in fx[::-1]])),
alpha=.2, fc="r", ec="None")
plt.legend()
plt.grid()
plt.show()
```
Bayesian optimization based on gaussian process regression is implemented in
:class:`gp_minimize` and can be carried out as follows:
```python
from skopt import gp_minimize
res = gp_minimize(f, # the function to minimize
[(-2.0, 2.0)], # the bounds on each dimension of x
acq_func="EI", # the acquisition function
n_calls=15, # the number of evaluations of f
n_random_starts=5, # the number of random initialization points
noise=0.1**2, # the noise level (optional)
random_state=1234) # the random seed
```
Accordingly, the approximated minimum is found to be:
```python
"x^*=%.4f, f(x^*)=%.4f" % (res.x[0], res.fun)
```
For further inspection of the results, attributes of the `res` named tuple
provide the following information:
- `x` [float]: location of the minimum.
- `fun` [float]: function value at the minimum.
- `models`: surrogate models used for each iteration.
- `x_iters` [array]:
location of function evaluation for each iteration.
- `func_vals` [array]: function value for each iteration.
- `space` [Space]: the optimization space.
- `specs` [dict]: parameters passed to the function.
```python
print(res)
```
Together these attributes can be used to visually inspect the results of the
minimization, such as the convergence trace or the acquisition function at
the last iteration:
```python
from skopt.plots import plot_convergence
plot_convergence(res);
```
Let us now visually examine
1. The approximation of the fit gp model to the original function.
2. The acquisition values that determine the next point to be queried.
```python
plt.rcParams["figure.figsize"] = (8, 14)
def f_wo_noise(x):
return f(x, noise_level=0)
```
Plot the 5 iterations following the 5 random points
```python
for n_iter in range(5):
# Plot true function.
plt.subplot(5, 2, 2*n_iter+1)
if n_iter == 0:
show_legend = True
else:
show_legend = False
ax = plot_gaussian_process(res, n_calls=n_iter,
objective=f_wo_noise,
noise_level=noise_level,
show_legend=show_legend, show_title=False,
show_next_point=False, show_acq_func=False)
ax.set_ylabel("")
ax.set_xlabel("")
# Plot EI(x)
plt.subplot(5, 2, 2*n_iter+2)
ax = plot_gaussian_process(res, n_calls=n_iter,
show_legend=show_legend, show_title=False,
show_mu=False, show_acq_func=True,
show_observations=False,
show_next_point=True)
ax.set_ylabel("")
ax.set_xlabel("")
plt.show()
```
The first column shows the following:
1. The true function.
2. The approximation to the original function by the gaussian process model
3. How sure the GP is about the function.
The second column shows the acquisition function values after every
surrogate model is fit. It is possible that we do not choose the global
minimum but a local minimum depending on the minimizer used to minimize
the acquisition function.
At the points closer to the points previously evaluated at, the variance
dips to zero.
Finally, as we increase the number of points, the GP model approaches
the actual function. The final few points are clustered around the minimum
because the GP does not gain anything more by further exploration:
```python
plt.rcParams["figure.figsize"] = (6, 4)
# Plot f(x) + contours
_ = plot_gaussian_process(res, objective=f_wo_noise,
noise_level=noise_level)
plt.show()
```
|
source("pattern_to_number.r")
computing_frequencies <- function(text, k) {
frequency_array <- array(0, 4^k)
for(i in 0:(nchar(text) - k)) {
pattern <- substr(text, i + 1, i + k)
j <- pattern_to_number(pattern)
frequency_array[j + 1] <- frequency_array[j + 1] + 1
}
return(frequency_array)
}
# message("Text")
# text <- scan("stdin", what="character", nlines=1)
# message("k")
# k <- scan("stdin", nlines=1)
#
# cat(computing_frequencies(text, k))
|
C @(#)sys100.f 20.3 2/13/96
subroutine sys100
C
include 'ipfinc/parametr.inc'
include 'ipfinc/alpha.inc'
include 'ipfinc/blank.inc'
include 'ipfinc/bus.inc'
include 'ipfinc/dc2t.inc'
include 'ipfinc/dcmt.inc'
include 'ipfinc/ikk.inc'
include 'ipfinc/merge.inc'
include 'ipfinc/mrgsys.inc'
include 'ipfinc/prt.inc'
include 'ipfinc/qksrt.inc'
include 'ipfinc/red2.inc'
dimension mtrx(MAXBUS)
character ktrpos*1,own1*3,own2*3
integer find_bus
external find_bus, kpface, spface
logical found
ksy = ksy +1
C Establish connection matrix: add 2-terminal dc to y-matrix
do i = 1,kdtot
k1 = dc2t(1,i)
k2 = dc2t(3,i)
kt = inp2opt(k1)
mt = inp2opt(k2)
C Add branch (KT,MT) to y-matrix
do isw = 1, 2
ln = km(kt) - 1
ls = kmlen(kt)
do l = 1, ls
if (ikmu(l+ln) .eq. mt) go to 102
enddo
c
c Appending an entity to km() requires relocating branch
c list to end of km().
c
ln = km(kt) - 1
ls = kmlen(kt)
do l = 1, ls
ikmu(l+yptr) = ikmu(l+ln)
enddo
ikmu(ls+yptr+1) = mt
yptr = yptr + ls + 1
km(kt) = yptr
kmlen(kt) = ls + 1
102 continue
kt = inp2opt(k2) ! swap kt and mt
mt = inp2opt(k1)
enddo
enddo
C Add N-terminal d-c to y-matrix
do i=1,mtdcln
k1=dcmtln(1,i)
k2=dcmtln(2,i)
kt = inp2opt(k1)
mt = inp2opt(k2)
do isw = 1, 2
ln = km(kt) - 1
ls = kmlen(kt)
do l = 1, ls
if (ikmu(l+ln) .eq. mt) go to 104
enddo
c
c Appending an entity to km() requires relocating branch
c list to end of km().
c
ln = km(kt) - 1
ls = kmlen(kt)
do l = 1, ls
ikmu(l+yptr) = ikmu(l+ln)
enddo
ikmu(ls+yptr+1) = mt
km(kt) = yptr + 1
kmlen(kt) = ls + 1
yptr = yptr + ls + 1
104 continue
kt = inp2opt(k2) ! swap kt and mt
mt = inp2opt(k1)
enddo
enddo
C
c IKK(1,*) = 0 - bus is in eliminated subsystem.
c 1 - bus is in retained subsystem.
c
c IKK(2,*) = 0 - bus is not specifically classified.
c 1 - bus is specifically classified.
C
c IKK(3,*) = isystm - subsystem number
C
c IKKIND(1,*) = is - starting KOLUM() index
c IKKIND(2,*) = il - KOLUM length
C
itot=1
do kt=1,ntot
k=inp2opt(kt)
jtot=0
do l = km(k), km(k)-1+kmlen(k)
mt = ikmu(l)
kolum(itot+jtot)=opt2inp(mt)
jtot=jtot+1
enddo
ikk(1,kt)=1
ikk(2,kt)=0
ikk(3,kt)=0
ikk(4,kt)=0
ikkind(1,kt)=itot
ikkind(2,kt)=jtot
itot=itot+jtot
enddo
if (itot .gt. MAXYE) then
write (errbuf(1),330) itot, MAXYE
330 format ('Total branches in system (including transposes)',
1 'is ',i5,'. Limit is ',i5,'.')
call prterx ('F',1)
kerrsw = kerrsw + 1
endif
C Identify merge subsystem
ntotx=max0(nbsys1,nbsys2)
do 370 i=1,ntotx
kt = find_bus(mrgbus(i),mrgbas(i))
if (kt .le. 0) then
if (mrgbus(i) .ne. srtlst) then
write (errbuf(1),350) mrgbus(i),mrgbas(i)
350 format ('Merged subsystem bus (',a8,f6.1,
& ') is not in system. Bus ignored. ')
call prterx ('W',1)
endif
else
ikk(1,kt)=0
endif
370 continue
C
C Identify all interface branches
C
nsave=0
do 380 i=1,ntot
if (ikk(1,i).eq.1) nsave=nsave+1
380 continue
if (nsave .eq. 0) then
write (errbuf(1),390)
390 format ('0 Caution - Merge and Base system are identical. ',
& 'Interface ignored. ')
call prterx ('W',1)
go to 580
endif
nsyst=0
itface=0
na=0
nl=0
do while (nl .le. nsave)
c
c Search for kernel node KT to prime topological emanation
c
kt = 1
found = .false.
do while (kt .le. ntot .and. .not. found)
if (ikk(1,kt) .eq. 1 .and. ikk(3,kt) .eq. 0) then
found = .true.
else
kt = kt + 1
endif
enddo
if (.not. found) then
write (errbuf(1), 400)
400 format ('Base merge failed to establish interface ')
call prterx ('F',1)
kerrsw = kerrsw + 1
go to 900
endif
c
c Add node KT as first node in subsystem NSYST
c
na=na+1
mtrx(na)=kt
nl=na
nsyst=nsyst+1
ikk(3,kt)=nsyst
do while (nl .le. na)
kt = mtrx(nl)
i5 = ikkind(1,kt)
i6 = i5+ikkind(2,kt)-1
do 470 l=i5,i6
mt=kolum(l)
if (ikk(1,mt) .eq. 0) then
ikk(2,kt)=1
ikk(2,mt)=1
do 430 i=1,itface
if (face(1,i) .eq. kt .and.
& face(2,i) .eq. mt) go to 470
430 continue
itface=itface+1
if (itface .ge. 399) then
write (errbuf(1),450) bus(kt), base(kt), bus(mt),
& base(mt)
450 format (' More that 400 merge interface branches',
& ' branch ignored :(',a8,f6.1, 2x,a8,f6.1,')')
call prterx ('W',1)
itface = 399
kerrsw = kerrsw + 1
else
face(1,itface)=kt
face(2,itface)=mt
facec(itface)='0' // owner(kt) // owner(mt)
face(4,itface)=nsyst
itface=itface+1
face(1,itface)=mt
face(2,itface)=kt
facec (itface)= '1' // owner(mt) // owner(kt)
face(4,itface)=nsyst
endif
else if (ikk(3,mt) .eq. 0) then
c
c Add node MT as subsequent node in subsystem NSYST
c
na=na+1
mtrx(na)=mt
ikk(3,mt)=nsyst
endif
470 continue
nl=nl+1
enddo
enddo
if (nl .lt. nsave) then
write (errbuf(1), 480)
480 format ('Base merge failed with an incomplete enclosure ')
call prterx ('F',1)
kerrsw = kerrsw + 1
go to 900
endif
C END PROCEDURE
490 continue
C SUMMARIZE "FACE" ARRAY BY SUBSYSTEMS
if (itface .eq. 0) go to 580
if (itface .gt. 1) then
key=1
call qiksrt(1,itface,kpface,spface)
endif
nf=1
do 570 is=1,nsyst
write (outbuf,520) is
520 format ('0 Summary of Interface Branches for Subsystem ',i2)
call prtout(1)
write (outbuf,530)
530 format ('0 Base System Merge System Owner1 Owner2 ')
call prtout(1)
do 550 i=nf,itface
if (face(4,i).ne.is) go to 560
kt=face(1,i)
mt=face(2,i)
ktrpos=facec(i)(1:1)
own1=facec(i)(2:4)
own2=facec(i)(5:7)
if (ktrpos .ne. '1') then
write (outbuf,540) bus(kt), base(kt), bus(mt), base(mt),
& own1,own2
540 format (2x,a8,f6.1,2x,a8,f6.1,3x,a3,5x,a3)
call prtout(1)
endif
550 continue
i=itface+1
560 nf=i
570 continue
580 continue
900 continue
return
end
|
Defender Economy Safety Glasses provide medium impact protection, anti-scratch lenses and 99.9% UV protection. They are an economical choice that offers a mix of protection and comfort.
Meets the Australian Standard AS/NZS 1337.1:2010 ensuring the best optical protection in most work environments. |
State Before: 𝕜 : Type u_1
inst✝⁸ : NontriviallyNormedField 𝕜
E : Type u_2
inst✝⁷ : NormedAddCommGroup E
inst✝⁶ : NormedSpace 𝕜 E
F : Type u_3
inst✝⁵ : NormedAddCommGroup F
inst✝⁴ : NormedSpace 𝕜 F
G : Type ?u.1390092
inst✝³ : NormedAddCommGroup G
inst✝² : NormedSpace 𝕜 G
G' : Type ?u.1390187
inst✝¹ : NormedAddCommGroup G'
inst✝ : NormedSpace 𝕜 G'
f f₀ f₁ g : E → F
f' f₀' f₁' g' e : E →L[𝕜] F
x : E
s t : Set E
L L₁ L₂ : Filter E
c : F
hxs : UniqueDiffWithinAt 𝕜 s x
⊢ fderivWithin 𝕜 (fun x => c) s x = 0 State After: 𝕜 : Type u_1
inst✝⁸ : NontriviallyNormedField 𝕜
E : Type u_2
inst✝⁷ : NormedAddCommGroup E
inst✝⁶ : NormedSpace 𝕜 E
F : Type u_3
inst✝⁵ : NormedAddCommGroup F
inst✝⁴ : NormedSpace 𝕜 F
G : Type ?u.1390092
inst✝³ : NormedAddCommGroup G
inst✝² : NormedSpace 𝕜 G
G' : Type ?u.1390187
inst✝¹ : NormedAddCommGroup G'
inst✝ : NormedSpace 𝕜 G'
f f₀ f₁ g : E → F
f' f₀' f₁' g' e : E →L[𝕜] F
x : E
s t : Set E
L L₁ L₂ : Filter E
c : F
hxs : UniqueDiffWithinAt 𝕜 s x
⊢ fderiv 𝕜 (fun x => c) x = 0 Tactic: rw [DifferentiableAt.fderivWithin (differentiableAt_const _) hxs] State Before: 𝕜 : Type u_1
inst✝⁸ : NontriviallyNormedField 𝕜
E : Type u_2
inst✝⁷ : NormedAddCommGroup E
inst✝⁶ : NormedSpace 𝕜 E
F : Type u_3
inst✝⁵ : NormedAddCommGroup F
inst✝⁴ : NormedSpace 𝕜 F
G : Type ?u.1390092
inst✝³ : NormedAddCommGroup G
inst✝² : NormedSpace 𝕜 G
G' : Type ?u.1390187
inst✝¹ : NormedAddCommGroup G'
inst✝ : NormedSpace 𝕜 G'
f f₀ f₁ g : E → F
f' f₀' f₁' g' e : E →L[𝕜] F
x : E
s t : Set E
L L₁ L₂ : Filter E
c : F
hxs : UniqueDiffWithinAt 𝕜 s x
⊢ fderiv 𝕜 (fun x => c) x = 0 State After: no goals Tactic: exact fderiv_const_apply _ |
using IntervalCensored
using Test
@testset "IntervalCensored.jl" begin
# Write your tests here.
end
|
import numpy as np
from sklearn_import.fixes import _parse_version
np_version = _parse_version(np.__version__)
def sparse_min_max(X, axis):
return (X.min(axis=axis).toarray().ravel(),
X.max(axis=axis).toarray().ravel())
|
= = = = Trip to Europe = = = =
|
create_output_files <- function(JOBID, max_date) {
three_panel <- readRDS(paste0("usa/results/", "three-panel-data-",JOBID,".RDS"))
infectious <- readRDS(paste0("usa/results/", "infectious-individuals-out-",JOBID,".RDS"))
model_output <- merge(three_panel, infectious, by = c('state','date'))
write.csv(model_output, paste0("usa/results/", "model-output-",max_date,".csv"), row.names = FALSE)
death_scenario <- readRDS(paste0('usa/results/deaths-scenario-out-',JOBID,'.RDS'))
mobzero <- death_scenario[death_scenario$key=='Constant mobility',]
mob20 <- death_scenario[death_scenario$key=='Increased mobility 20%',]
mob40 <- death_scenario[death_scenario$key=='Increased mobility 40%',]
mobzero <- mobzero[,c("state", "date","estimated_deaths","deaths_min","deaths_max")]
mob20 <- mob20[,c("state", "date","estimated_deaths","deaths_min","deaths_max")]
mob40 <- mob40[,c("state", "date","estimated_deaths","deaths_min","deaths_max")]
colnames(mobzero) <- c("state", "date","constant_mobility_estimated_deaths_mean","constant_mobility_estimated_deaths_lower_CI_95","constant_mobility_estimated_deaths_higher_CI_95")
colnames(mob20) <- c("state", "date","mobility_increase_20_estimated_deaths_mean","mobility_increase_20_estimated_deaths_lower_CI_95","mobility_increase_20_estimated_deaths_higher_CI_95")
colnames(mob40) <- c("state", "date","mobility_increase_40__estimated_deaths_mean","mobility_increase_40__estimated_deaths_lower_CI_95","mobility_increase_40_estimated_deaths_higher_CI_95")
deaths_scenarios <- merge(mobzero, mob20,by = c('state', 'date'))
deaths_scenarios <- merge(deaths_scenarios, mob40,by = c('state', 'date'))
deaths_scenarios <- deaths_scenarios[deaths_scenarios$date > max_date,]
write.csv(deaths_scenarios, file = paste0('usa/results/deaths-scenarios-',max_date,'.csv'), row.names = FALSE)
cases_scenario <- readRDS(paste0('usa/results/cases-scenario-out-',JOBID,'.RDS'))
mobzero <- cases_scenario[cases_scenario$key=='Constant mobility',]
mob20 <- cases_scenario[cases_scenario$key=='Increased mobility 20%',]
mob40 <- cases_scenario[cases_scenario$key=='Increased mobility 40%',]
mobzero <- mobzero[,c("state", "date","predicted_cases","cases_min","cases_max")]
mob20 <- mob20[,c("state", "date","predicted_cases","cases_min","cases_max")]
mob40 <- mob40[,c("state", "date","predicted_cases","cases_min","cases_max")]
colnames(mobzero) <- c("state", "date","constant_mobility_estimated_infections_mean","constant_mobility_estimated_infections_lower_CI_95","constant_mobility_estimated_infections_higher_CI_95")
colnames(mob20) <- c("state", "date","mobility_increase_20_estimated_infections_mean","mobility_increase_20_estimated_infections_lower_CI_95","mobility_increase_20_estimated_infections_higher_CI_95")
colnames(mob40) <- c("state", "date","mobility_increase_40__estimated_infections_mean","mobility_increase_40__estimated_infections_lower_CI_95","mobility_increase_40_estimated_infections_higher_CI_95")
cases_scenarios <- merge(mobzero, mob20,by = c('state', 'date'))
cases_scenarios <- merge(cases_scenarios, mob40,by = c('state', 'date'))
cases_scenarios <- cases_scenarios[cases_scenarios$date > max_date,]
write.csv(cases_scenarios, file = paste0('usa/results/infections-scenarios-',max_date,'.csv'), row.names = FALSE)
rt_scenario <- readRDS(paste0('usa/results/rt-scenario-out-',JOBID,'.RDS'))
mobzero <- rt_scenario[rt_scenario$key=='Constant mobility',]
mob20 <- rt_scenario[rt_scenario$key=='Increased mobility 20%',]
mob40 <- rt_scenario[rt_scenario$key=='Increased mobility 40%',]
mobzero <- mobzero[,c("state", "date","rt","rt_min","rt_max")]
mob20 <- mob20[,c("state", "date","rt","rt_min","rt_max")]
mob40 <- mob40[,c("state", "date","rt","rt_min","rt_max")]
colnames(mobzero) <- c("state", "date","constant_mobility_mean_time_varying_reproduction_number_R(t)","constant_mobility_time_varying_reproduction_number_R(t)_lower_CI_95","time_varying_reproduction_number_R(t)_Higher_CI_95")
colnames(mob20) <- c("state", "date","mobility_increase_20_mean_time_varying_reproduction_number_R(t)","mobility_increase_20_time_varying_reproduction_number_R(t)_lower_CI_95","mobility_increase_20_time_varying_reproduction_number_R(t)_Higher_CI_95")
colnames(mob40) <- c("state", "date","mobility_increase_20_mean_time_varying_reproduction_number_R(t)","mobility_increase_40_time_varying_reproduction_number_R(t)_lower_CI_95","mobility_increase_40_time_varying_reproduction_number_R(t)_Higher_CI_95")
rt_scenarios <- merge(mobzero, mob20,by = c('state', 'date'))
rt_scenarios <- merge(rt_scenarios, mob40,by = c('state', 'date'))
rt_scenarios <- rt_scenarios[rt_scenarios$date > max_date,]
write.csv(rt_scenarios, file = paste0('usa/results/time-varying-reproduction-number-scenarios-',max_date,'.csv'), row.names = FALSE)
} |
[STATEMENT]
lemma OclIsKindOf\<^sub>O\<^sub>c\<^sub>l\<^sub>A\<^sub>n\<^sub>y_Person_strict2[simp] : "(null::Person) .oclIsKindOf(OclAny) = true"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. null.oclIsKindOf(OclAny) = true
[PROOF STEP]
by(rule ext, simp add: null_fun_def null_option_def bot_option_def
OclIsKindOf\<^sub>O\<^sub>c\<^sub>l\<^sub>A\<^sub>n\<^sub>y_Person) |
-- Andreas, 2013-11-07
-- Instance candidates are now considered module judgemental equality.
module Issue899 where
postulate
A B : Set
f : {{ x : A }} → B
instance a : A
instance
a' : A
a' = a
test : B
test = f
{- The previous code fails with the following message:
Resolve implicit argument _x_257 : A. Candidates: [a : A, a : A]
There are indeed two values in scope of type A (a and a'), but given
that they are definitionally equal, Agda should not complain about it
but just pick any one of them. -}
|
Require Import Raft.
Require Import RaftRefinementInterface.
Section VotedForMoreUpToDate.
Context {orig_base_params : BaseParams}.
Context {one_node_params : OneNodeParams orig_base_params}.
Context {raft_params : RaftParams orig_base_params}.
Definition votedFor_moreUpToDate (net : network) : Prop :=
forall t h h',
currentTerm (snd (nwState net h)) = t ->
type (snd (nwState net h)) = Candidate ->
votedFor (snd (nwState net h')) = Some h ->
currentTerm (snd (nwState net h')) = t ->
exists vl,
moreUpToDate (maxTerm (log (snd (nwState net h)))) (maxIndex (log (snd (nwState net h))))
(maxTerm vl) (maxIndex vl) = true /\
In (t, h, vl) (votesWithLog (fst (nwState net h'))).
Class votedFor_moreUpToDate_interface : Prop :=
{
votedFor_moreUpToDate_invariant :
forall net,
refined_raft_intermediate_reachable net ->
votedFor_moreUpToDate net
}.
End VotedForMoreUpToDate. |
[STATEMENT]
lemma infs_suffix: "infs A w \<longleftrightarrow> (\<forall> u v. w = u @- v \<longrightarrow> sset v \<inter> A \<noteq> {})"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. infs A w = (\<forall>u v. w = u @- v \<longrightarrow> sset v \<inter> A \<noteq> {})
[PROOF STEP]
using alwD alw_iff_sdrop alw_shift ev_HLD_sset stake_sdrop
[PROOF STATE]
proof (prove)
using this:
alw ?P ?x \<Longrightarrow> ?P ?x
alw ?P ?\<omega> = (\<forall>m. ?P (sdrop m ?\<omega>))
alw ?\<phi> (?xl @- ?xs) \<Longrightarrow> alw ?\<phi> ?xs
ev (HLD ?A) ?w = (sset ?w \<inter> ?A \<noteq> {})
stake ?n ?s @- sdrop ?n ?s = ?s
goal (1 subgoal):
1. infs A w = (\<forall>u v. w = u @- v \<longrightarrow> sset v \<inter> A \<noteq> {})
[PROOF STEP]
by metis |
[GOAL]
d : ℕ
h : d ≠ 0
w : Nat.coprime (Int.natAbs 0) d
⊢ mk' 0 d = 0
[PROOFSTEP]
congr
[GOAL]
q : ℚ
⊢ q.num = 0 ↔ q = 0
[PROOFSTEP]
induction q
[GOAL]
case mk'
num✝ : ℤ
den✝ : ℕ
den_nz✝ : den✝ ≠ 0
reduced✝ : Nat.coprime (Int.natAbs num✝) den✝
⊢ (mk' num✝ den✝).num = 0 ↔ mk' num✝ den✝ = 0
[PROOFSTEP]
constructor
[GOAL]
case mk'.mp
num✝ : ℤ
den✝ : ℕ
den_nz✝ : den✝ ≠ 0
reduced✝ : Nat.coprime (Int.natAbs num✝) den✝
⊢ (mk' num✝ den✝).num = 0 → mk' num✝ den✝ = 0
[PROOFSTEP]
rintro rfl
[GOAL]
case mk'.mp
den✝ : ℕ
den_nz✝ : den✝ ≠ 0
reduced✝ : Nat.coprime (Int.natAbs 0) den✝
⊢ mk' 0 den✝ = 0
[PROOFSTEP]
exact zero_mk _ _ _
[GOAL]
case mk'.mpr
num✝ : ℤ
den✝ : ℕ
den_nz✝ : den✝ ≠ 0
reduced✝ : Nat.coprime (Int.natAbs num✝) den✝
⊢ mk' num✝ den✝ = 0 → (mk' num✝ den✝).num = 0
[PROOFSTEP]
exact congr_arg num
[GOAL]
a b : ℤ
b0 : b ≠ 0
⊢ a /. b = 0 ↔ a = 0
[PROOFSTEP]
rw [← zero_divInt b, divInt_eq_iff b0 b0, zero_mul, mul_eq_zero, or_iff_left b0]
[GOAL]
C : ℚ → Sort u
n : ℤ
d : ℕ
h : d ≠ 0
c : Nat.coprime (Int.natAbs n) d
H : (n : ℤ) → (d : ℕ) → 0 < d → Nat.coprime (Int.natAbs n) d → C (n /. ↑d)
⊢ C (mk' n d)
[PROOFSTEP]
rw [num_den']
[GOAL]
C : ℚ → Sort u
n : ℤ
d : ℕ
h : d ≠ 0
c : Nat.coprime (Int.natAbs n) d
H : (n : ℤ) → (d : ℕ) → 0 < d → Nat.coprime (Int.natAbs n) d → C (n /. ↑d)
⊢ C (n /. ↑d)
[PROOFSTEP]
exact H n d (Nat.pos_of_ne_zero h) c
[GOAL]
f : ℚ → ℚ → ℚ
f₁ f₂ : ℤ → ℤ → ℤ → ℤ → ℤ
fv :
∀ {n₁ : ℤ} {d₁ : ℕ} {h₁ : d₁ ≠ 0} {c₁ : Nat.coprime (Int.natAbs n₁) d₁} {n₂ : ℤ} {d₂ : ℕ} {h₂ : d₂ ≠ 0}
{c₂ : Nat.coprime (Int.natAbs n₂) d₂}, f (mk' n₁ d₁) (mk' n₂ d₂) = f₁ n₁ (↑d₁) n₂ ↑d₂ /. f₂ n₁ (↑d₁) n₂ ↑d₂
f0 : ∀ {n₁ d₁ n₂ d₂ : ℤ}, d₁ ≠ 0 → d₂ ≠ 0 → f₂ n₁ d₁ n₂ d₂ ≠ 0
a b c d : ℤ
b0 : b ≠ 0
d0 : d ≠ 0
H : ∀ {n₁ d₁ n₂ d₂ : ℤ}, a * d₁ = n₁ * b → c * d₂ = n₂ * d → f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂
⊢ f (a /. b) (c /. d) = f₁ a b c d /. f₂ a b c d
[PROOFSTEP]
generalize ha : a /. b = x
[GOAL]
f : ℚ → ℚ → ℚ
f₁ f₂ : ℤ → ℤ → ℤ → ℤ → ℤ
fv :
∀ {n₁ : ℤ} {d₁ : ℕ} {h₁ : d₁ ≠ 0} {c₁ : Nat.coprime (Int.natAbs n₁) d₁} {n₂ : ℤ} {d₂ : ℕ} {h₂ : d₂ ≠ 0}
{c₂ : Nat.coprime (Int.natAbs n₂) d₂}, f (mk' n₁ d₁) (mk' n₂ d₂) = f₁ n₁ (↑d₁) n₂ ↑d₂ /. f₂ n₁ (↑d₁) n₂ ↑d₂
f0 : ∀ {n₁ d₁ n₂ d₂ : ℤ}, d₁ ≠ 0 → d₂ ≠ 0 → f₂ n₁ d₁ n₂ d₂ ≠ 0
a b c d : ℤ
b0 : b ≠ 0
d0 : d ≠ 0
H : ∀ {n₁ d₁ n₂ d₂ : ℤ}, a * d₁ = n₁ * b → c * d₂ = n₂ * d → f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂
x : ℚ
ha : a /. b = x
⊢ f x (c /. d) = f₁ a b c d /. f₂ a b c d
[PROOFSTEP]
cases' x with n₁ d₁ h₁ c₁
[GOAL]
case mk'
f : ℚ → ℚ → ℚ
f₁ f₂ : ℤ → ℤ → ℤ → ℤ → ℤ
fv :
∀ {n₁ : ℤ} {d₁ : ℕ} {h₁ : d₁ ≠ 0} {c₁ : Nat.coprime (Int.natAbs n₁) d₁} {n₂ : ℤ} {d₂ : ℕ} {h₂ : d₂ ≠ 0}
{c₂ : Nat.coprime (Int.natAbs n₂) d₂}, f (mk' n₁ d₁) (mk' n₂ d₂) = f₁ n₁ (↑d₁) n₂ ↑d₂ /. f₂ n₁ (↑d₁) n₂ ↑d₂
f0 : ∀ {n₁ d₁ n₂ d₂ : ℤ}, d₁ ≠ 0 → d₂ ≠ 0 → f₂ n₁ d₁ n₂ d₂ ≠ 0
a b c d : ℤ
b0 : b ≠ 0
d0 : d ≠ 0
H : ∀ {n₁ d₁ n₂ d₂ : ℤ}, a * d₁ = n₁ * b → c * d₂ = n₂ * d → f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂
n₁ : ℤ
d₁ : ℕ
h₁ : d₁ ≠ 0
c₁ : Nat.coprime (Int.natAbs n₁) d₁
ha : a /. b = mk' n₁ d₁
⊢ f (mk' n₁ d₁) (c /. d) = f₁ a b c d /. f₂ a b c d
[PROOFSTEP]
rw [num_den'] at ha
[GOAL]
case mk'
f : ℚ → ℚ → ℚ
f₁ f₂ : ℤ → ℤ → ℤ → ℤ → ℤ
fv :
∀ {n₁ : ℤ} {d₁ : ℕ} {h₁ : d₁ ≠ 0} {c₁ : Nat.coprime (Int.natAbs n₁) d₁} {n₂ : ℤ} {d₂ : ℕ} {h₂ : d₂ ≠ 0}
{c₂ : Nat.coprime (Int.natAbs n₂) d₂}, f (mk' n₁ d₁) (mk' n₂ d₂) = f₁ n₁ (↑d₁) n₂ ↑d₂ /. f₂ n₁ (↑d₁) n₂ ↑d₂
f0 : ∀ {n₁ d₁ n₂ d₂ : ℤ}, d₁ ≠ 0 → d₂ ≠ 0 → f₂ n₁ d₁ n₂ d₂ ≠ 0
a b c d : ℤ
b0 : b ≠ 0
d0 : d ≠ 0
H : ∀ {n₁ d₁ n₂ d₂ : ℤ}, a * d₁ = n₁ * b → c * d₂ = n₂ * d → f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂
n₁ : ℤ
d₁ : ℕ
h₁ : d₁ ≠ 0
c₁ : Nat.coprime (Int.natAbs n₁) d₁
ha : a /. b = n₁ /. ↑d₁
⊢ f (mk' n₁ d₁) (c /. d) = f₁ a b c d /. f₂ a b c d
[PROOFSTEP]
generalize hc : c /. d = x
[GOAL]
case mk'
f : ℚ → ℚ → ℚ
f₁ f₂ : ℤ → ℤ → ℤ → ℤ → ℤ
fv :
∀ {n₁ : ℤ} {d₁ : ℕ} {h₁ : d₁ ≠ 0} {c₁ : Nat.coprime (Int.natAbs n₁) d₁} {n₂ : ℤ} {d₂ : ℕ} {h₂ : d₂ ≠ 0}
{c₂ : Nat.coprime (Int.natAbs n₂) d₂}, f (mk' n₁ d₁) (mk' n₂ d₂) = f₁ n₁ (↑d₁) n₂ ↑d₂ /. f₂ n₁ (↑d₁) n₂ ↑d₂
f0 : ∀ {n₁ d₁ n₂ d₂ : ℤ}, d₁ ≠ 0 → d₂ ≠ 0 → f₂ n₁ d₁ n₂ d₂ ≠ 0
a b c d : ℤ
b0 : b ≠ 0
d0 : d ≠ 0
H : ∀ {n₁ d₁ n₂ d₂ : ℤ}, a * d₁ = n₁ * b → c * d₂ = n₂ * d → f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂
n₁ : ℤ
d₁ : ℕ
h₁ : d₁ ≠ 0
c₁ : Nat.coprime (Int.natAbs n₁) d₁
ha : a /. b = n₁ /. ↑d₁
x : ℚ
hc : c /. d = x
⊢ f (mk' n₁ d₁) x = f₁ a b c d /. f₂ a b c d
[PROOFSTEP]
cases' x with n₂ d₂ h₂ c₂
[GOAL]
case mk'.mk'
f : ℚ → ℚ → ℚ
f₁ f₂ : ℤ → ℤ → ℤ → ℤ → ℤ
fv :
∀ {n₁ : ℤ} {d₁ : ℕ} {h₁ : d₁ ≠ 0} {c₁ : Nat.coprime (Int.natAbs n₁) d₁} {n₂ : ℤ} {d₂ : ℕ} {h₂ : d₂ ≠ 0}
{c₂ : Nat.coprime (Int.natAbs n₂) d₂}, f (mk' n₁ d₁) (mk' n₂ d₂) = f₁ n₁ (↑d₁) n₂ ↑d₂ /. f₂ n₁ (↑d₁) n₂ ↑d₂
f0 : ∀ {n₁ d₁ n₂ d₂ : ℤ}, d₁ ≠ 0 → d₂ ≠ 0 → f₂ n₁ d₁ n₂ d₂ ≠ 0
a b c d : ℤ
b0 : b ≠ 0
d0 : d ≠ 0
H : ∀ {n₁ d₁ n₂ d₂ : ℤ}, a * d₁ = n₁ * b → c * d₂ = n₂ * d → f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂
n₁ : ℤ
d₁ : ℕ
h₁ : d₁ ≠ 0
c₁ : Nat.coprime (Int.natAbs n₁) d₁
ha : a /. b = n₁ /. ↑d₁
n₂ : ℤ
d₂ : ℕ
h₂ : d₂ ≠ 0
c₂ : Nat.coprime (Int.natAbs n₂) d₂
hc : c /. d = mk' n₂ d₂
⊢ f (mk' n₁ d₁) (mk' n₂ d₂) = f₁ a b c d /. f₂ a b c d
[PROOFSTEP]
rw [num_den'] at hc
[GOAL]
case mk'.mk'
f : ℚ → ℚ → ℚ
f₁ f₂ : ℤ → ℤ → ℤ → ℤ → ℤ
fv :
∀ {n₁ : ℤ} {d₁ : ℕ} {h₁ : d₁ ≠ 0} {c₁ : Nat.coprime (Int.natAbs n₁) d₁} {n₂ : ℤ} {d₂ : ℕ} {h₂ : d₂ ≠ 0}
{c₂ : Nat.coprime (Int.natAbs n₂) d₂}, f (mk' n₁ d₁) (mk' n₂ d₂) = f₁ n₁ (↑d₁) n₂ ↑d₂ /. f₂ n₁ (↑d₁) n₂ ↑d₂
f0 : ∀ {n₁ d₁ n₂ d₂ : ℤ}, d₁ ≠ 0 → d₂ ≠ 0 → f₂ n₁ d₁ n₂ d₂ ≠ 0
a b c d : ℤ
b0 : b ≠ 0
d0 : d ≠ 0
H : ∀ {n₁ d₁ n₂ d₂ : ℤ}, a * d₁ = n₁ * b → c * d₂ = n₂ * d → f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂
n₁ : ℤ
d₁ : ℕ
h₁ : d₁ ≠ 0
c₁ : Nat.coprime (Int.natAbs n₁) d₁
ha : a /. b = n₁ /. ↑d₁
n₂ : ℤ
d₂ : ℕ
h₂ : d₂ ≠ 0
c₂ : Nat.coprime (Int.natAbs n₂) d₂
hc : c /. d = n₂ /. ↑d₂
⊢ f (mk' n₁ d₁) (mk' n₂ d₂) = f₁ a b c d /. f₂ a b c d
[PROOFSTEP]
rw [fv]
[GOAL]
case mk'.mk'
f : ℚ → ℚ → ℚ
f₁ f₂ : ℤ → ℤ → ℤ → ℤ → ℤ
fv :
∀ {n₁ : ℤ} {d₁ : ℕ} {h₁ : d₁ ≠ 0} {c₁ : Nat.coprime (Int.natAbs n₁) d₁} {n₂ : ℤ} {d₂ : ℕ} {h₂ : d₂ ≠ 0}
{c₂ : Nat.coprime (Int.natAbs n₂) d₂}, f (mk' n₁ d₁) (mk' n₂ d₂) = f₁ n₁ (↑d₁) n₂ ↑d₂ /. f₂ n₁ (↑d₁) n₂ ↑d₂
f0 : ∀ {n₁ d₁ n₂ d₂ : ℤ}, d₁ ≠ 0 → d₂ ≠ 0 → f₂ n₁ d₁ n₂ d₂ ≠ 0
a b c d : ℤ
b0 : b ≠ 0
d0 : d ≠ 0
H : ∀ {n₁ d₁ n₂ d₂ : ℤ}, a * d₁ = n₁ * b → c * d₂ = n₂ * d → f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂
n₁ : ℤ
d₁ : ℕ
h₁ : d₁ ≠ 0
c₁ : Nat.coprime (Int.natAbs n₁) d₁
ha : a /. b = n₁ /. ↑d₁
n₂ : ℤ
d₂ : ℕ
h₂ : d₂ ≠ 0
c₂ : Nat.coprime (Int.natAbs n₂) d₂
hc : c /. d = n₂ /. ↑d₂
⊢ f₁ n₁ (↑d₁) n₂ ↑d₂ /. f₂ n₁ (↑d₁) n₂ ↑d₂ = f₁ a b c d /. f₂ a b c d
[PROOFSTEP]
have d₁0 := ne_of_gt (Int.ofNat_lt.2 $ Nat.pos_of_ne_zero h₁)
[GOAL]
case mk'.mk'
f : ℚ → ℚ → ℚ
f₁ f₂ : ℤ → ℤ → ℤ → ℤ → ℤ
fv :
∀ {n₁ : ℤ} {d₁ : ℕ} {h₁ : d₁ ≠ 0} {c₁ : Nat.coprime (Int.natAbs n₁) d₁} {n₂ : ℤ} {d₂ : ℕ} {h₂ : d₂ ≠ 0}
{c₂ : Nat.coprime (Int.natAbs n₂) d₂}, f (mk' n₁ d₁) (mk' n₂ d₂) = f₁ n₁ (↑d₁) n₂ ↑d₂ /. f₂ n₁ (↑d₁) n₂ ↑d₂
f0 : ∀ {n₁ d₁ n₂ d₂ : ℤ}, d₁ ≠ 0 → d₂ ≠ 0 → f₂ n₁ d₁ n₂ d₂ ≠ 0
a b c d : ℤ
b0 : b ≠ 0
d0 : d ≠ 0
H : ∀ {n₁ d₁ n₂ d₂ : ℤ}, a * d₁ = n₁ * b → c * d₂ = n₂ * d → f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂
n₁ : ℤ
d₁ : ℕ
h₁ : d₁ ≠ 0
c₁ : Nat.coprime (Int.natAbs n₁) d₁
ha : a /. b = n₁ /. ↑d₁
n₂ : ℤ
d₂ : ℕ
h₂ : d₂ ≠ 0
c₂ : Nat.coprime (Int.natAbs n₂) d₂
hc : c /. d = n₂ /. ↑d₂
d₁0 : ↑d₁ ≠ ↑0
⊢ f₁ n₁ (↑d₁) n₂ ↑d₂ /. f₂ n₁ (↑d₁) n₂ ↑d₂ = f₁ a b c d /. f₂ a b c d
[PROOFSTEP]
have d₂0 := ne_of_gt (Int.ofNat_lt.2 $ Nat.pos_of_ne_zero h₂)
[GOAL]
case mk'.mk'
f : ℚ → ℚ → ℚ
f₁ f₂ : ℤ → ℤ → ℤ → ℤ → ℤ
fv :
∀ {n₁ : ℤ} {d₁ : ℕ} {h₁ : d₁ ≠ 0} {c₁ : Nat.coprime (Int.natAbs n₁) d₁} {n₂ : ℤ} {d₂ : ℕ} {h₂ : d₂ ≠ 0}
{c₂ : Nat.coprime (Int.natAbs n₂) d₂}, f (mk' n₁ d₁) (mk' n₂ d₂) = f₁ n₁ (↑d₁) n₂ ↑d₂ /. f₂ n₁ (↑d₁) n₂ ↑d₂
f0 : ∀ {n₁ d₁ n₂ d₂ : ℤ}, d₁ ≠ 0 → d₂ ≠ 0 → f₂ n₁ d₁ n₂ d₂ ≠ 0
a b c d : ℤ
b0 : b ≠ 0
d0 : d ≠ 0
H : ∀ {n₁ d₁ n₂ d₂ : ℤ}, a * d₁ = n₁ * b → c * d₂ = n₂ * d → f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂
n₁ : ℤ
d₁ : ℕ
h₁ : d₁ ≠ 0
c₁ : Nat.coprime (Int.natAbs n₁) d₁
ha : a /. b = n₁ /. ↑d₁
n₂ : ℤ
d₂ : ℕ
h₂ : d₂ ≠ 0
c₂ : Nat.coprime (Int.natAbs n₂) d₂
hc : c /. d = n₂ /. ↑d₂
d₁0 : ↑d₁ ≠ ↑0
d₂0 : ↑d₂ ≠ ↑0
⊢ f₁ n₁ (↑d₁) n₂ ↑d₂ /. f₂ n₁ (↑d₁) n₂ ↑d₂ = f₁ a b c d /. f₂ a b c d
[PROOFSTEP]
exact (divInt_eq_iff (f0 d₁0 d₂0) (f0 b0 d0)).2 (H ((divInt_eq_iff b0 d₁0).1 ha) ((divInt_eq_iff d0 d₂0).1 hc))
[GOAL]
a b c : ℚ
n : ℤ
d : ℕ
h : d ≠ 0
⊢ n /. ↑d + 0 = n /. ↑d
[PROOFSTEP]
rw [← zero_divInt d, add_def'', zero_mul, add_zero, divInt_mul_right]
[GOAL]
a b c : ℚ
n : ℤ
d : ℕ
h : d ≠ 0
⊢ ↑d ≠ 0
[PROOFSTEP]
simp [h]
[GOAL]
case b0
a b c : ℚ
n : ℤ
d : ℕ
h : d ≠ 0
⊢ ↑d ≠ 0
[PROOFSTEP]
simp [h]
[GOAL]
case d0
a b c : ℚ
n : ℤ
d : ℕ
h : d ≠ 0
⊢ ↑d ≠ 0
[PROOFSTEP]
simp [h]
[GOAL]
a b c : ℚ
n : ℤ
d : ℕ
h : d ≠ 0
⊢ 0 + n /. ↑d = n /. ↑d
[PROOFSTEP]
rw [← zero_divInt d, add_def'', zero_mul, zero_add, divInt_mul_right]
[GOAL]
a b c : ℚ
n : ℤ
d : ℕ
h : d ≠ 0
⊢ ↑d ≠ 0
[PROOFSTEP]
simp [h]
[GOAL]
case b0
a b c : ℚ
n : ℤ
d : ℕ
h : d ≠ 0
⊢ ↑d ≠ 0
[PROOFSTEP]
simp [h]
[GOAL]
case d0
a b c : ℚ
n : ℤ
d : ℕ
h : d ≠ 0
⊢ ↑d ≠ 0
[PROOFSTEP]
simp [h]
[GOAL]
a b c : ℚ
n₁ : ℤ
d₁ : ℕ
h₁ : d₁ ≠ 0
n₂ : ℤ
d₂ : ℕ
h₂ : d₂ ≠ 0
⊢ n₁ /. ↑d₁ + n₂ /. ↑d₂ = n₂ /. ↑d₂ + n₁ /. ↑d₁
[PROOFSTEP]
simp [h₁, h₂, add_comm, mul_comm]
[GOAL]
a b c : ℚ
n₁ : ℤ
d₁ : ℕ
h₁ : d₁ ≠ 0
n₂ : ℤ
d₂ : ℕ
h₂ : d₂ ≠ 0
n₃ : ℤ
d₃ : ℕ
h₃ : d₃ ≠ 0
⊢ n₁ /. ↑d₁ + n₂ /. ↑d₂ + n₃ /. ↑d₃ = n₁ /. ↑d₁ + (n₂ /. ↑d₂ + n₃ /. ↑d₃)
[PROOFSTEP]
simp [h₁, h₂, h₃]
[GOAL]
a b c : ℚ
n₁ : ℤ
d₁ : ℕ
h₁ : d₁ ≠ 0
n₂ : ℤ
d₂ : ℕ
h₂ : d₂ ≠ 0
n₃ : ℤ
d₃ : ℕ
h₃ : d₃ ≠ 0
⊢ ((n₁ * ↑d₂ + n₂ * ↑d₁) * ↑d₃ + n₃ * (↑d₁ * ↑d₂)) /. (↑d₁ * ↑d₂ * ↑d₃) =
(n₁ * (↑d₂ * ↑d₃) + (n₂ * ↑d₃ + n₃ * ↑d₂) * ↑d₁) /. (↑d₁ * (↑d₂ * ↑d₃))
[PROOFSTEP]
rw [mul_assoc, add_mul, add_mul, mul_assoc, add_assoc]
[GOAL]
a b c : ℚ
n₁ : ℤ
d₁ : ℕ
h₁ : d₁ ≠ 0
n₂ : ℤ
d₂ : ℕ
h₂ : d₂ ≠ 0
n₃ : ℤ
d₃ : ℕ
h₃ : d₃ ≠ 0
⊢ (n₁ * (↑d₂ * ↑d₃) + (n₂ * ↑d₁ * ↑d₃ + n₃ * (↑d₁ * ↑d₂))) /. (↑d₁ * (↑d₂ * ↑d₃)) =
(n₁ * (↑d₂ * ↑d₃) + (n₂ * ↑d₃ * ↑d₁ + n₃ * ↑d₂ * ↑d₁)) /. (↑d₁ * (↑d₂ * ↑d₃))
[PROOFSTEP]
congr 2
[GOAL]
case e_a.e_a
a b c : ℚ
n₁ : ℤ
d₁ : ℕ
h₁ : d₁ ≠ 0
n₂ : ℤ
d₂ : ℕ
h₂ : d₂ ≠ 0
n₃ : ℤ
d₃ : ℕ
h₃ : d₃ ≠ 0
⊢ n₂ * ↑d₁ * ↑d₃ + n₃ * (↑d₁ * ↑d₂) = n₂ * ↑d₃ * ↑d₁ + n₃ * ↑d₂ * ↑d₁
[PROOFSTEP]
ac_rfl
[GOAL]
a b c : ℚ
n : ℤ
d : ℕ
h : d ≠ 0
⊢ -(n /. ↑d) + n /. ↑d = 0
[PROOFSTEP]
simp [h, mkRat_add_mkRat]
[GOAL]
a b c : ℚ
⊢ 0 /. 1 = 0
[PROOFSTEP]
rw [divInt]
[GOAL]
a b c : ℚ
⊢ (match 0, 1 with
| n, Int.ofNat d => inline (mkRat n d)
| n, Int.negSucc d => normalize (-n) (Nat.succ d)) =
0
[PROOFSTEP]
simp
[GOAL]
a b c : ℚ
⊢ 1 /. 1 = 1
[PROOFSTEP]
rw [divInt]
[GOAL]
a b c : ℚ
⊢ (match 1, 1 with
| n, Int.ofNat d => inline (mkRat n d)
| n, Int.negSucc d => normalize (-n) (Nat.succ d)) =
1
[PROOFSTEP]
simp
[GOAL]
a b c : ℚ
⊢ -1 /. 1 = -1
[PROOFSTEP]
rw [divInt]
[GOAL]
a b c : ℚ
⊢ (match -1, 1 with
| n, Int.ofNat d => inline (mkRat n d)
| n, Int.negSucc d => normalize (-n) (Nat.succ d)) =
-1
[PROOFSTEP]
simp
[GOAL]
a b c : ℚ
n : ℤ
⊢ n /. 1 = ↑n
[PROOFSTEP]
rw [divInt]
[GOAL]
a b c : ℚ
n : ℤ
⊢ (match n, 1 with
| n, Int.ofNat d => inline (mkRat n d)
| n, Int.negSucc d => normalize (-n) (Nat.succ d)) =
↑n
[PROOFSTEP]
simp [mkRat, normalize]
[GOAL]
a b c : ℚ
n : ℤ
⊢ mk' n 1 = ↑n
[PROOFSTEP]
rfl
[GOAL]
a b c : ℚ
n : ℤ
⊢ mkRat n 1 = ↑n
[PROOFSTEP]
simp [Rat.mkRat_eq, Rat.divInt_one]
[GOAL]
a b c : ℚ
n₁ : ℤ
d₁ : ℕ
h₁ : d₁ ≠ 0
n₂ : ℤ
d₂ : ℕ
h₂ : d₂ ≠ 0
n₃ : ℤ
d₃ : ℕ
h₃ : d₃ ≠ 0
⊢ n₁ /. ↑d₁ * (n₂ /. ↑d₂) * (n₃ /. ↑d₃) = n₁ /. ↑d₁ * (n₂ /. ↑d₂ * (n₃ /. ↑d₃))
[PROOFSTEP]
simp [h₁, h₂, h₃, mul_ne_zero, mul_comm, mul_assoc, mul_left_comm]
[GOAL]
a b c : ℚ
n₁ : ℤ
d₁ : ℕ
h₁ : d₁ ≠ 0
n₂ : ℤ
d₂ : ℕ
h₂ : d₂ ≠ 0
n₃ : ℤ
d₃ : ℕ
h₃ : d₃ ≠ 0
⊢ (n₁ /. ↑d₁ + n₂ /. ↑d₂) * (n₃ /. ↑d₃) = n₁ /. ↑d₁ * (n₃ /. ↑d₃) + n₂ /. ↑d₂ * (n₃ /. ↑d₃)
[PROOFSTEP]
simp [h₁, h₂, h₃, mul_ne_zero]
[GOAL]
a b c : ℚ
n₁ : ℤ
d₁ : ℕ
h₁ : d₁ ≠ 0
n₂ : ℤ
d₂ : ℕ
h₂ : d₂ ≠ 0
n₃ : ℤ
d₃ : ℕ
h₃ : d₃ ≠ 0
⊢ (n₁ * ↑d₂ + n₂ * ↑d₁) * n₃ /. (↑d₁ * ↑d₂ * ↑d₃) =
(n₁ * n₃ * (↑d₂ * ↑d₃) + n₂ * n₃ * (↑d₁ * ↑d₃)) /. (↑d₁ * ↑d₃ * (↑d₂ * ↑d₃))
[PROOFSTEP]
rw [← divInt_mul_right (Int.coe_nat_ne_zero.2 h₃), add_mul, add_mul]
[GOAL]
a b c : ℚ
n₁ : ℤ
d₁ : ℕ
h₁ : d₁ ≠ 0
n₂ : ℤ
d₂ : ℕ
h₂ : d₂ ≠ 0
n₃ : ℤ
d₃ : ℕ
h₃ : d₃ ≠ 0
⊢ (n₁ * ↑d₂ * n₃ * ↑d₃ + n₂ * ↑d₁ * n₃ * ↑d₃) /. (↑d₁ * ↑d₂ * ↑d₃ * ↑d₃) =
(n₁ * n₃ * (↑d₂ * ↑d₃) + n₂ * n₃ * (↑d₁ * ↑d₃)) /. (↑d₁ * ↑d₃ * (↑d₂ * ↑d₃))
[PROOFSTEP]
ac_rfl
[GOAL]
a b c : ℚ
⊢ a * (b + c) = a * b + a * c
[PROOFSTEP]
rw [Rat.mul_comm, Rat.add_mul, Rat.mul_comm, Rat.mul_comm c a]
[GOAL]
a b c : ℚ
⊢ 0 ≠ 1
[PROOFSTEP]
rw [ne_comm, ← divInt_one_one, divInt_ne_zero one_ne_zero]
[GOAL]
a b c : ℚ
⊢ 1 ≠ 0
[PROOFSTEP]
exact one_ne_zero
[GOAL]
a b c : ℚ
n : ℤ
d : ℕ
h : d ≠ 0
a0 : n /. ↑d ≠ 0
⊢ n /. ↑d * (n /. ↑d)⁻¹ = 1
[PROOFSTEP]
have n0 : n ≠ 0 := mt (by rintro rfl; simp) a0
[GOAL]
a b c : ℚ
n : ℤ
d : ℕ
h : d ≠ 0
a0 : n /. ↑d ≠ 0
⊢ n = 0 → n /. ↑d = 0
[PROOFSTEP]
rintro rfl
[GOAL]
a b c : ℚ
d : ℕ
h : d ≠ 0
a0 : 0 /. ↑d ≠ 0
⊢ 0 /. ↑d = 0
[PROOFSTEP]
simp
[GOAL]
a b c : ℚ
n : ℤ
d : ℕ
h : d ≠ 0
a0 : n /. ↑d ≠ 0
n0 : n ≠ 0
⊢ n /. ↑d * (n /. ↑d)⁻¹ = 1
[PROOFSTEP]
simpa [h, n0, mul_comm] using @divInt_mul_right 1 1 (n * d) (by simp [h, n0])
[GOAL]
a b c : ℚ
n : ℤ
d : ℕ
h : d ≠ 0
a0 : n /. ↑d ≠ 0
n0 : n ≠ 0
⊢ n * ↑d ≠ 0
[PROOFSTEP]
simp [h, n0]
[GOAL]
a b c : ℚ
n : ℕ
⊢ NatCast.natCast (n + 1) = NatCast.natCast n + 1
[PROOFSTEP]
simp only [coe_int_eq_divInt, add_def'' one_ne_zero one_ne_zero, ← divInt_one_one, Nat.cast_add, Nat.cast_one, mul_one]
[GOAL]
a b c : ℚ
⊢ 0⁻¹ = 0
[PROOFSTEP]
change Rat.inv 0 = 0
[GOAL]
a b c : ℚ
⊢ Rat.inv 0 = 0
[PROOFSTEP]
rw [Rat.inv_def]
[GOAL]
a b c : ℚ
⊢ ↑0.den /. 0.num = 0
[PROOFSTEP]
rfl
[GOAL]
a b c : ℚ
⊢ Nontrivial ℚ
[PROOFSTEP]
infer_instance
[GOAL]
a b c : ℚ
⊢ CommSemiring ℚ
[PROOFSTEP]
infer_instance
[GOAL]
a b c : ℚ
⊢ Semiring ℚ
[PROOFSTEP]
infer_instance
[GOAL]
a b c : ℚ
⊢ AddCommGroup ℚ
[PROOFSTEP]
infer_instance
[GOAL]
a b c : ℚ
⊢ AddGroup ℚ
[PROOFSTEP]
infer_instance
[GOAL]
a b c : ℚ
⊢ AddCommMonoid ℚ
[PROOFSTEP]
infer_instance
[GOAL]
a b c : ℚ
⊢ AddMonoid ℚ
[PROOFSTEP]
infer_instance
[GOAL]
a b c : ℚ
⊢ AddLeftCancelSemigroup ℚ
[PROOFSTEP]
infer_instance
[GOAL]
a b c : ℚ
⊢ AddRightCancelSemigroup ℚ
[PROOFSTEP]
infer_instance
[GOAL]
a b c : ℚ
⊢ AddCommSemigroup ℚ
[PROOFSTEP]
infer_instance
[GOAL]
a b c : ℚ
⊢ AddSemigroup ℚ
[PROOFSTEP]
infer_instance
[GOAL]
a b c : ℚ
⊢ CommMonoid ℚ
[PROOFSTEP]
infer_instance
[GOAL]
a b c : ℚ
⊢ Monoid ℚ
[PROOFSTEP]
infer_instance
[GOAL]
a b c : ℚ
⊢ CommSemigroup ℚ
[PROOFSTEP]
infer_instance
[GOAL]
a b c : ℚ
⊢ Semigroup ℚ
[PROOFSTEP]
infer_instance
[GOAL]
a b c p q : ℚ
⊢ p = q ↔ p.num * ↑q.den = q.num * ↑p.den
[PROOFSTEP]
conv =>
lhs
rw [← @num_den p, ← @num_den q]
[GOAL]
a b c p q : ℚ
| p = q ↔ p.num * ↑q.den = q.num * ↑p.den
[PROOFSTEP]
lhs
rw [← @num_den p, ← @num_den q]
[GOAL]
a b c p q : ℚ
| p = q ↔ p.num * ↑q.den = q.num * ↑p.den
[PROOFSTEP]
lhs
rw [← @num_den p, ← @num_den q]
[GOAL]
a b c p q : ℚ
| p = q ↔ p.num * ↑q.den = q.num * ↑p.den
[PROOFSTEP]
lhs
[GOAL]
a b c p q : ℚ
| p = q
[PROOFSTEP]
rw [← @num_den p, ← @num_den q]
[GOAL]
a b c p q : ℚ
⊢ p.num /. ↑p.den = q.num /. ↑q.den ↔ p.num * ↑q.den = q.num * ↑p.den
[PROOFSTEP]
apply Rat.divInt_eq_iff
[GOAL]
case z₁
a b c p q : ℚ
⊢ ↑p.den ≠ 0
[PROOFSTEP]
rw [← Nat.cast_zero, Ne, Int.ofNat_inj]
[GOAL]
case z₁
a b c p q : ℚ
⊢ ¬p.den = 0
[PROOFSTEP]
apply den_nz
[GOAL]
case z₂
a b c p q : ℚ
⊢ ↑q.den ≠ 0
[PROOFSTEP]
rw [← Nat.cast_zero, Ne, Int.ofNat_inj]
[GOAL]
case z₂
a b c p q : ℚ
⊢ ¬q.den = 0
[PROOFSTEP]
apply den_nz
[GOAL]
a b c q : ℚ
hq : q.num = 0
⊢ q = 0
[PROOFSTEP]
have : q = q.num /. q.den := num_den.symm
[GOAL]
a b c q : ℚ
hq : q.num = 0
this : q = q.num /. ↑q.den
⊢ q = 0
[PROOFSTEP]
simpa [hq] using this
[GOAL]
a b c q : ℚ
x✝ : q = 0
⊢ q.num = 0
[PROOFSTEP]
simp [*]
[GOAL]
a b c q : ℚ
n d : ℤ
hq : q ≠ 0
hqnd : q = n /. d
this : n = 0
⊢ q = 0
[PROOFSTEP]
simpa [this] using hqnd
[GOAL]
a b c q : ℚ
n d : ℤ
hq : q ≠ 0
hqnd : q = n /. d
this : d = 0
⊢ q = 0
[PROOFSTEP]
simpa [this] using hqnd
[GOAL]
a b c q r : ℚ
⊢ q * r = q.num * r.num /. ↑(q.den * r.den)
[PROOFSTEP]
have hq' : (↑q.den : ℤ) ≠ 0 := by have := den_nz q; simpa
[GOAL]
a b c q r : ℚ
⊢ ↑q.den ≠ 0
[PROOFSTEP]
have := den_nz q
[GOAL]
a b c q r : ℚ
this : q.den ≠ 0
⊢ ↑q.den ≠ 0
[PROOFSTEP]
simpa
[GOAL]
a b c q r : ℚ
hq' : ↑q.den ≠ 0
⊢ q * r = q.num * r.num /. ↑(q.den * r.den)
[PROOFSTEP]
have hr' : (↑r.den : ℤ) ≠ 0 := by have := den_nz r; simpa
[GOAL]
a b c q r : ℚ
hq' : ↑q.den ≠ 0
⊢ ↑r.den ≠ 0
[PROOFSTEP]
have := den_nz r
[GOAL]
a b c q r : ℚ
hq' : ↑q.den ≠ 0
this : r.den ≠ 0
⊢ ↑r.den ≠ 0
[PROOFSTEP]
simpa
[GOAL]
a b c q r : ℚ
hq' : ↑q.den ≠ 0
hr' : ↑r.den ≠ 0
⊢ q * r = q.num * r.num /. ↑(q.den * r.den)
[PROOFSTEP]
suffices q.num /. ↑q.den * (r.num /. ↑r.den) = q.num * r.num /. ↑(q.den * r.den) by simpa [num_den] using this
[GOAL]
a b c q r : ℚ
hq' : ↑q.den ≠ 0
hr' : ↑r.den ≠ 0
this : q.num /. ↑q.den * (r.num /. ↑r.den) = q.num * r.num /. ↑(q.den * r.den)
⊢ q * r = q.num * r.num /. ↑(q.den * r.den)
[PROOFSTEP]
simpa [num_den] using this
[GOAL]
a b c q r : ℚ
hq' : ↑q.den ≠ 0
hr' : ↑r.den ≠ 0
⊢ q.num /. ↑q.den * (r.num /. ↑r.den) = q.num * r.num /. ↑(q.den * r.den)
[PROOFSTEP]
simp [mul_def' hq' hr']
[GOAL]
a b c q r : ℚ
hr : r.num = 0
⊢ q / r = q.num * ↑r.den /. (↑q.den * r.num)
[PROOFSTEP]
have hr' : r = 0 := zero_of_num_zero hr
[GOAL]
a b c q r : ℚ
hr : r.num = 0
hr' : r = 0
⊢ q / r = q.num * ↑r.den /. (↑q.den * r.num)
[PROOFSTEP]
simp [*]
[GOAL]
a b c q r : ℚ
hr : ¬r.num = 0
⊢ q * r⁻¹ = q.num /. ↑q.den * (r.num /. ↑r.den)⁻¹
[PROOFSTEP]
simp [num_den]
[GOAL]
a b c q r : ℚ
hr : ¬r.num = 0
⊢ q.num /. ↑q.den * (r.num /. ↑r.den)⁻¹ = q.num /. ↑q.den * (↑r.den /. r.num)
[PROOFSTEP]
rw [inv_def']
[GOAL]
a b c q r : ℚ
hr : ¬r.num = 0
⊢ ↑q.den ≠ 0
[PROOFSTEP]
simpa using den_nz q
[GOAL]
a✝ b✝ c✝ : ℚ
a b c : ℤ
h : c = 0
⊢ (a + b) /. c = a /. c + b /. c
[PROOFSTEP]
simp [h]
[GOAL]
a✝ b✝ c✝ : ℚ
a b c : ℤ
h : ¬c = 0
⊢ (a + b) /. c = a /. c + b /. c
[PROOFSTEP]
rw [add_def'' h h, divInt_eq_iff h (mul_ne_zero h h)]
[GOAL]
a✝ b✝ c✝ : ℚ
a b c : ℤ
h : ¬c = 0
⊢ (a + b) * (c * c) = (a * c + b * c) * c
[PROOFSTEP]
simp [add_mul, mul_assoc]
[GOAL]
a b c : ℚ
n d : ℤ
⊢ n /. d = ↑n / ↑d
[PROOFSTEP]
by_cases d0 : d = 0
[GOAL]
case pos
a b c : ℚ
n d : ℤ
d0 : d = 0
⊢ n /. d = ↑n / ↑d
[PROOFSTEP]
simp [d0, div_zero]
[GOAL]
case neg
a b c : ℚ
n d : ℤ
d0 : ¬d = 0
⊢ n /. d = ↑n / ↑d
[PROOFSTEP]
simp [division_def, coe_int_eq_divInt, mul_def' one_ne_zero d0]
[GOAL]
a b c : ℚ
x : ℤ
hx : x ≠ 0
n d : ℤ
⊢ n /. x * (x /. d) = n /. d
[PROOFSTEP]
by_cases hd : d = 0
[GOAL]
case pos
a b c : ℚ
x : ℤ
hx : x ≠ 0
n d : ℤ
hd : d = 0
⊢ n /. x * (x /. d) = n /. d
[PROOFSTEP]
rw [hd]
[GOAL]
case pos
a b c : ℚ
x : ℤ
hx : x ≠ 0
n d : ℤ
hd : d = 0
⊢ n /. x * (x /. 0) = n /. 0
[PROOFSTEP]
simp
[GOAL]
case neg
a b c : ℚ
x : ℤ
hx : x ≠ 0
n d : ℤ
hd : ¬d = 0
⊢ n /. x * (x /. d) = n /. d
[PROOFSTEP]
rw [mul_def' hx hd, mul_comm x, divInt_mul_right hx]
[GOAL]
a b c : ℚ
x : ℤ
hx : x ≠ 0
n d : ℤ
⊢ n /. x / (d /. x) = n /. d
[PROOFSTEP]
rw [div_eq_mul_inv, inv_def', divInt_mul_divInt_cancel hx]
[GOAL]
a b c : ℚ
x : ℤ
hx : x ≠ 0
n d : ℤ
⊢ x /. n / (x /. d) = d /. n
[PROOFSTEP]
rw [div_eq_mul_inv, inv_def', mul_comm, divInt_mul_divInt_cancel hx]
[GOAL]
a b c : ℚ
n d : ℤ
⊢ ↑n / ↑d = n /. d
[PROOFSTEP]
repeat' rw [coe_int_eq_divInt]
[GOAL]
a b c : ℚ
n d : ℤ
⊢ ↑n / ↑d = n /. d
[PROOFSTEP]
rw [coe_int_eq_divInt]
[GOAL]
a b c : ℚ
n d : ℤ
⊢ n /. 1 / ↑d = n /. d
[PROOFSTEP]
rw [coe_int_eq_divInt]
[GOAL]
a b c : ℚ
n d : ℤ
⊢ n /. 1 / (d /. 1) = n /. d
[PROOFSTEP]
rw [coe_int_eq_divInt]
[GOAL]
a b c : ℚ
n d : ℤ
⊢ n /. 1 / (d /. 1) = n /. d
[PROOFSTEP]
exact divInt_div_divInt_cancel_left one_ne_zero n d
[GOAL]
a b c r : ℚ
⊢ ↑r.num / ↑r.den = r
[PROOFSTEP]
rw [← Int.cast_ofNat]
[GOAL]
a b c r : ℚ
⊢ ↑r.num / ↑↑r.den = r
[PROOFSTEP]
erw [← divInt_eq_div, num_den]
[GOAL]
a b c q : ℚ
hq : q.den = 1
⊢ ↑q.num = q
[PROOFSTEP]
conv_rhs => rw [← @num_den q, hq]
[GOAL]
a b c q : ℚ
hq : q.den = 1
| q
[PROOFSTEP]
rw [← @num_den q, hq]
[GOAL]
a b c q : ℚ
hq : q.den = 1
| q
[PROOFSTEP]
rw [← @num_den q, hq]
[GOAL]
a b c q : ℚ
hq : q.den = 1
| q
[PROOFSTEP]
rw [← @num_den q, hq]
[GOAL]
a b c q : ℚ
hq : q.den = 1
⊢ ↑q.num = q.num /. ↑1
[PROOFSTEP]
rw [coe_int_eq_divInt]
[GOAL]
a b c q : ℚ
hq : q.den = 1
⊢ q.num /. 1 = q.num /. ↑1
[PROOFSTEP]
rfl
[GOAL]
a b c : ℚ
n : ℕ
⊢ ↑n = ↑n /. 1
[PROOFSTEP]
rw [← Int.cast_ofNat, coe_int_eq_divInt]
[GOAL]
a b c : ℚ
n : ℕ
⊢ (↑n).num = ↑n
[PROOFSTEP]
rw [← Int.cast_ofNat, coe_int_num]
[GOAL]
a b c : ℚ
n : ℕ
⊢ (↑n).den = 1
[PROOFSTEP]
rw [← Int.cast_ofNat, coe_int_den]
[GOAL]
a b c : ℚ
n : ℤ
d : ℕ
⊢ mkRat n d = ↑n / ↑d
[PROOFSTEP]
simp [mkRat]
[GOAL]
a b c : ℚ
n : ℤ
d : ℕ
⊢ (if h : d = 0 then 0 else normalize n d) = ↑n / ↑d
[PROOFSTEP]
by_cases d = 0
[GOAL]
a b c : ℚ
n : ℤ
d : ℕ
⊢ (if h : d = 0 then 0 else normalize n d) = ↑n / ↑d
[PROOFSTEP]
by_cases d = 0
[GOAL]
case pos
a b c : ℚ
n : ℤ
d : ℕ
h : d = 0
⊢ (if h : d = 0 then 0 else normalize n d) = ↑n / ↑d
[PROOFSTEP]
simp [h]
[GOAL]
case neg
a b c : ℚ
n : ℤ
d : ℕ
h : ¬d = 0
⊢ (if h : d = 0 then 0 else normalize n d) = ↑n / ↑d
[PROOFSTEP]
simp [h, HDiv.hDiv, Rat.div, Div.div]
[GOAL]
case neg
a b c : ℚ
n : ℤ
d : ℕ
h : ¬d = 0
⊢ normalize n d = ↑n * Rat.inv ↑d
[PROOFSTEP]
unfold Rat.inv
[GOAL]
case neg
a b c : ℚ
n : ℤ
d : ℕ
h : ¬d = 0
⊢ normalize n d =
↑n *
if h : (↑d).num < 0 then mk' (-↑(↑d).den) (Int.natAbs (↑d).num)
else if h : (↑d).num > 0 then mk' (↑(↑d).den) (Int.natAbs (↑d).num) else ↑d
[PROOFSTEP]
have h₁ : 0 < d := Nat.pos_iff_ne_zero.2 h
[GOAL]
case neg
a b c : ℚ
n : ℤ
d : ℕ
h : ¬d = 0
h₁ : 0 < d
⊢ normalize n d =
↑n *
if h : (↑d).num < 0 then mk' (-↑(↑d).den) (Int.natAbs (↑d).num)
else if h : (↑d).num > 0 then mk' (↑(↑d).den) (Int.natAbs (↑d).num) else ↑d
[PROOFSTEP]
have h₂ : ¬(d : ℤ) < 0 := by simp
[GOAL]
a b c : ℚ
n : ℤ
d : ℕ
h : ¬d = 0
h₁ : 0 < d
⊢ ¬↑d < 0
[PROOFSTEP]
simp
[GOAL]
case neg
a b c : ℚ
n : ℤ
d : ℕ
h : ¬d = 0
h₁ : 0 < d
h₂ : ¬↑d < 0
⊢ normalize n d =
↑n *
if h : (↑d).num < 0 then mk' (-↑(↑d).den) (Int.natAbs (↑d).num)
else if h : (↑d).num > 0 then mk' (↑(↑d).den) (Int.natAbs (↑d).num) else ↑d
[PROOFSTEP]
simp [h, h₁, h₂, ← Rat.normalize_eq_mk', Rat.normalize_eq_mkRat, ← mkRat_one, Rat.mkRat_mul_mkRat]
|
[STATEMENT]
lemma addfunsetD_supp : "f \<in> addfunset A M \<Longrightarrow> supp f \<subseteq> A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. f \<in> addfunset A M \<Longrightarrow> supp f \<subseteq> A
[PROOF STEP]
unfolding addfunset_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. f \<in> {f. supp f \<subseteq> A \<and> range f \<subseteq> M \<and> (\<forall>x\<in>A. \<forall>y\<in>A. f (x + y) = f x + f y)} \<Longrightarrow> supp f \<subseteq> A
[PROOF STEP]
by fast |
#ifndef SB_HPP_DEF__
#define SB_HPP_DEF__
#include<rexio/tk/toolkit.h++>
#include <string>
#include <map>
#include <boost/function.hpp>
//! displays basic information
//! about... anything
class StatusBar: public Scr::Tk::Widget
{
private:
//! message
static std::string Status;
public:
typedef std::map<Scr::Uint,boost::function<void ()> > KeyMap;
void OnRedraw(Scr::Screen &screen)throw();
//!status is global
inline static void SetStatus(std::string s)
{
Status.assign(s);
}
void OnKeyDown(Scr::Key key)throw();
};
#endif
|
module Specdris.ConsoleColor
%access export
%default total
||| Console colors
public export
data Color = Red
| Green
| Yellow
| Blue
| Magenta
| Cyan
| White
Eq Color where
(==) Red Red = True
(==) Green Green = True
(==) Yellow Yellow = True
(==) Blue Blue = True
(==) Magenta Magenta = True
(==) Cyan Cyan = True
(==) White White = True
(==) _ _ = False
Show Color where
show Red = "red"
show Green = "green"
show Yellow = "yellow"
show Blue = "blue"
show Magenta = "magenta"
show Cyan = "cyan"
show White = "white"
private
colorToCode : Color -> Nat
colorToCode Red = 1
colorToCode Green = 2
colorToCode Yellow = 3
colorToCode Blue = 4
colorToCode Magenta = 5
colorToCode Cyan = 6
colorToCode White = 7
private
colorToAnsi : Color -> String
colorToAnsi code = "\ESC[3" ++ show (colorToCode code) ++ "m"
colorise : Color -> String -> String
colorise color str = colorToAnsi color ++ str ++ "\ESC[0m"
indent : (level : Nat) -> String
indent level = foldr (\el, acc => el ++ acc) "" (replicate level " ")
format : String -> Color -> (level : Nat) -> String
format str color level = colorise color $ indent level ++ str
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.OrderedCommMonoid.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Structure
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.SIP using (TypeWithStr)
open import Cubical.Data.Sigma
open import Cubical.Algebra.CommMonoid
open import Cubical.Algebra.OrderedCommMonoid.Base
open import Cubical.Relation.Binary.Poset
private
variable
ℓ ℓ' ℓ'' : Level
module _
(M : OrderedCommMonoid ℓ ℓ')
(P : ⟨ M ⟩ → hProp ℓ'')
where
open OrderedCommMonoidStr (snd M)
module _
(·Closed : (x y : ⟨ M ⟩) → ⟨ P x ⟩ → ⟨ P y ⟩ → ⟨ P (x · y) ⟩)
(εContained : ⟨ P ε ⟩)
where
private
subtype = Σ[ x ∈ ⟨ M ⟩ ] ⟨ P x ⟩
submonoid = makeSubCommMonoid (OrderedCommMonoid→CommMonoid M) P ·Closed εContained
_≤ₛ_ : (x y : ⟨ submonoid ⟩) → Type ℓ'
x ≤ₛ y = (fst x) ≤ (fst y)
pres≤ : (x y : ⟨ submonoid ⟩) (x≤y : x ≤ₛ y) → (fst x) ≤ (fst y)
pres≤ x y x≤y = x≤y
makeOrderedSubmonoid : OrderedCommMonoid _ ℓ'
fst makeOrderedSubmonoid = subtype
OrderedCommMonoidStr._≤_ (snd makeOrderedSubmonoid) = _≤ₛ_
OrderedCommMonoidStr._·_ (snd makeOrderedSubmonoid) = CommMonoidStr._·_ (snd submonoid)
OrderedCommMonoidStr.ε (snd makeOrderedSubmonoid) = CommMonoidStr.ε (snd submonoid)
OrderedCommMonoidStr.isOrderedCommMonoid (snd makeOrderedSubmonoid) =
IsOrderedCommMonoidFromIsCommMonoid
(CommMonoidStr.isCommMonoid (snd submonoid))
(λ x y → is-prop-valued (fst x) (fst y))
(λ x → is-refl (fst x))
(λ x y z → is-trans (fst x) (fst y) (fst z))
(λ x y x≤y y≤x
→ Σ≡Prop (λ x → snd (P x))
(is-antisym (fst x) (fst y) (pres≤ x y x≤y) (pres≤ y x y≤x)))
(λ x y z x≤y → MonotoneR (pres≤ x y x≤y))
λ x y z x≤y → MonotoneL (pres≤ x y x≤y)
|
import tactic basic
namespace complex
/-! # `ext` : A mathematical triviality -/
/-
Two complex numbers with the same and imaginary parts are equal.
This is an "extensionality lemma", i.e. a lemma of the form "if two things
are made from the same pieces, they are equal".
This is not hard to prove, but we want to give the result a name
so we can tag it with the `ext` attribute, meaning that the
`ext` tactic will know it. To add to the confusion, let's call the theorem `ext` :-)
-/
/-- If two complex numbers z and w have equal real and imaginary parts, they are equal -/
@[ext] theorem ext {z w : ℂ} (hre : re(z) = re(w)) (him : im(z) = im(w)) : z = w :=
begin
cases z with zr zi,
cases w with ww wi,
simp at *,
/- goal now a logic puzzle
hre : zr = ww,
him : zi = wi
⊢ zr = ww ∧ zi = wi
-/
cc,
end
/-! # Theorem: The complex numbers are a commutative ring -/
-- Proof: we've defined all the structure, and every axiom can be checked by reducing it
-- to checking real and imaginary parts with `ext`, expanding everything out with `simp`
-- and then using the fact that the real numbers are a commutative ring.
instance : comm_ring ℂ :=
begin
-- first the data
refine_struct {
zero := (0 : ℂ), add := (+), neg := has_neg.neg, one := 1, mul := (*),
..},
-- now the axioms
-- of which there seem to be 11
-- introduce the variables
all_goals {intros},
-- we now have to prove an equality between two complex numbers.
-- It suffices to check on real and imaginary parts
all_goals {ext},
-- the simplifier can simplify stuff like re(a+0)
all_goals {simp},
-- all the goals now are identities between *real* numbers,
-- and the reals are already known to be a ring
all_goals {ring},
end
-- That is the end of the proof that the complexes form a ring. We built
-- a basic API which was honed towards the general idea that to prove
-- certain statements about the complex numbers, for example distributivity,
-- we could just check on real and imaginary parts. We trained the
-- simplifier to expand out things like re(z*w) in terms
-- of re(z), im(z), re(w), im(w).
/-!
# Optional section for mathematicians : more basic infrastructure, and term mode
-/
/-!
## `ext` revisited
Recall extensionality:
`theorem ext {z w : ℂ} (hre : re(z) = re(w)) (him : im(z) = im(w)) : z = w := ...`
Here is another tactic mode proof of extensionality. Note that we have moved
the hypotheses to the other side of the colon; this does not
change the theorem. This proof shows the power
of the `rintros` tactic.
-/
theorem ext' : ∀ z w : ℂ, z.re = w.re → z.im = w.im → z = w :=
begin
rintros ⟨zr, zi⟩ ⟨_, _⟩ ⟨rfl⟩ ⟨rfl⟩,
refl,
end
/-
Explanation: `rintros` does `cases` as many times as you like using this cool `⟨ ⟩` syntax
for the case splits. Note that if you say that a proof of `a = b` is `rfl` then
Lean will define a to be b, or b to be a, and not even introduce new notation for it.
-/
-- Here is the same proof in term mode.
theorem ext'' : ∀ {z w : ℂ}, z.re = w.re → z.im = w.im → z = w
| ⟨zr, zi⟩ ⟨_, _⟩ rfl rfl := rfl
/-!
## `eta`
-/
/-
We prove the mathematically obvious statement that the
complex number whose real part is re(z) and whose imaginary
part is im(z) is of course equal to z.
-/
/-- ⟨z.re, z.im⟩ is equal to z -/
@[simp] theorem eta : ∀ z : ℂ, complex.mk z.re z.im = z :=
begin
intro z,
cases z with x y,
/-
goal now looks complicated, and contains terms which look
like {re := a, im := b}.re which obviously simplify to a.
The `dsimp` tactic will do some tidying up for us, although
it is not logically necessary. `dsimp` does definitional simplification.
-/
dsimp,
-- Now we see the goal can be solved by reflexivity
refl,
end
/-
The proof was "unfold everything, and it's true by definition".
This proof does not teach a mathematician anything, so we may as well write
it in term mode. Many tactics have term mode equivalent.
The equation compiler does the `intro` and `cases` steps,
and `dsimp` was unnecessary -- the two sides of the equation
were definitionally equal.
-/
theorem eta' : ∀ z : ℂ, complex.mk z.re z.im = z
| ⟨x, y⟩ := rfl
/-!
## ext_iff
-/
/-
Note that `ext` is an implication -- if re(z)=re(w) and im(z)=im(w) then z=w.
The below variant `ext_iff` is the two-way implication: two complex
numbers are equal if and only if they have the same real and imaginary part.
Let's first see a tactic mode proof. See how the `ext` tactic is used?
After it is applied, we have two goals, both of which are hypotheses.
The semicolon means "apply the next tactic to all the goals produced by this one"
-/
theorem ext_iff {z w : ℂ} : z = w ↔ z.re = w.re ∧ z.im = w.im :=
begin
split,
{ intro H,
simp [H]},
{
rintro ⟨hre, him⟩,
ext; assumption,
}
end
-- Again this is easy to write in term mode, and no mathematician
-- wants to read the proof anyway.
theorem ext_iff' {z w : ℂ} : z = w ↔ z.re = w.re ∧ z.im = w.im :=
⟨λ H, by simp [H], and.rec ext⟩
end complex
/-!
# some last comments on the `simp` tactic
Some equalities, even if obvious, had to be given names, because we want `simp`
to be able to use them. In short, the `simp` tactic tries to solve
goals of the form A = B, when `refl` doesn't work (i.e. the goals are
not definitionally equal) but when any mathematician would be able
to simplify A and B via "obvious" steps such as `0 + x = x` or
`⟨z.re, z.im⟩ = z`. These things are sometimes not true by definition,
but they should be tagged as being well-known ways to simplify an equality.
When building our API for the complex numbers, if we prove a theorem of the
form `A = B` where `B` is a bit simpler than `A`, we should probably
tag it with the `@[simp]` attribute, so `simp` can use it.
Note: `simp` does *not* prove "all simple things". It proves *equalities*.
It proves `A = B` when, and only when, it can do it by applying
its "simplification rules", where a simplification rule is simply a proof
of a theorem of the form `A = B` and `B` is simpler than `A`.
-/
------------------ VERY INTERESTING BITS -------------------------
/-- The canonical map from ℝ to ℂ. -/
def of_real (r : ℝ) : ℂ := ⟨r, 0⟩
/-
We make this map into a *coercion*, which means that if `(r : ℝ)` is a real
number, then `(r : ℂ)` or `(↑r : ℂ)` will indicate the corresponding
complex number with no imaginary part. This is the notation we shall
use in our `simp` lemmas.
-/
/-- The coercion from ℝ to ℂ sending `r` to the complex number `⟨r, 0⟩` -/
instance : has_coe ℝ ℂ := ⟨of_real⟩ |
– Daily Express – Mention for the IW Walking Festival.
Further coverage was received following a media visit by leading Dutch garden writers, Marieke van Gessel and Modeste Herweg. Please click here to view this exposure. It’s been used by HDC Media: http://www.hc-hdc.nl/overhdcmedia/ several editions, circulation 255.000, read by 830.000 people and is valued at approx. £12,000. Our PR media value (ad value) coverage for 2014 now stands as £2.3million. This figure currently excludes local, on-line and any TV coverage.
You will doubtless have seen the fantastic images as some of the world’s best ice climbers took on the challenge of ascending the sheer cliffs of chalk at The Needles as the first ever Red Bull White Cliff competition came to the Island on Sunday 19th October. The film of this spectacular climb is on YouTube, or you can see it by clicking here. Katie Jones of VIOW who helped to set up the event together with The Needles Park, The National Trust and the ferry operators is hopeful of the event returning to the Island to become a real tourist attraction in 2015.
And for those who missed the Isle of Wight episode of the new BBC1 television series “Holiday of my Lifetime” featuring Len Goodman and Esther Rantzen, more details about the programme which show Len taking Esther back to the Island to relive her holiday as a 6-year old in 1946 can be found by clicking here.
In the film they can be seen in and around Bembridge, watching the daily demonstration of the donkeys at Carisbrooke Castle and visiting The Needles Park where Len surprises Esther with a chairlift ride with stunning views of the Island’s coastline. Robin Hill’s new event attraction “Electric Woods” also features in the programme as well as Isle of Wight Adventure Activities. Along the way Esther reveals that her journalistic curiosity may have started during her time on the Isle of Wight.
We were first approached by the programme makers back in June when they requested our assistance in finding suitable film locations and we were delighted to be able to provide support and act as a liaison between the television crew and relevant tourism providers. |
section \<open>Map Interface\<close>
theory IICF_Map
imports "../../Sepref"
begin
subsection \<open>Parametricity for Maps\<close>
definition [to_relAPP]: "map_rel K V \<equiv> (K \<rightarrow> \<langle>V\<rangle>option_rel)
\<inter> { (mi,m). dom mi \<subseteq> Domain K \<and> dom m \<subseteq> Range K }"
(*
definition [to_relAPP]: "map_rel K V \<equiv> (K \<rightarrow> \<langle>V\<rangle>option_rel)
\<inter> { (mi,m). dom mi \<subseteq> Domain K \<and> dom m \<subseteq> Range K
\<and> ran mi \<subseteq> Domain V \<and> ran m \<subseteq> Range V }"
*)
lemma bi_total_map_rel_eq:
"\<lbrakk>IS_RIGHT_TOTAL K; IS_LEFT_TOTAL K\<rbrakk> \<Longrightarrow> \<langle>K,V\<rangle>map_rel = K \<rightarrow> \<langle>V\<rangle>option_rel"
unfolding map_rel_def IS_RIGHT_TOTAL_def IS_LEFT_TOTAL_def
by (auto dest: fun_relD)
lemma map_rel_empty1_simp[simp]:
"(Map.empty,m)\<in>\<langle>K,V\<rangle>map_rel \<longleftrightarrow> m=Map.empty"
apply (auto simp: map_rel_def)
by (meson RangeE domIff option_rel_simp(1) subsetCE tagged_fun_relD_none)
lemma map_rel_empty2_simp[simp]:
"(m,Map.empty)\<in>\<langle>K,V\<rangle>map_rel \<longleftrightarrow> m=Map.empty"
apply (auto simp: map_rel_def)
by (meson Domain.cases domIff fun_relD2 option_rel_simp(2) subset_eq)
lemma map_rel_obtain1:
assumes 1: "(m,n)\<in>\<langle>K,V\<rangle>map_rel"
assumes 2: "n l = Some w"
obtains k v where "m k = Some v" "(k,l)\<in>K" "(v,w)\<in>V"
using 1 unfolding map_rel_def
proof clarsimp
assume R: "(m, n) \<in> K \<rightarrow> \<langle>V\<rangle>option_rel"
assume "dom n \<subseteq> Range K"
with 2 obtain k where "(k,l)\<in>K" by auto
moreover from fun_relD[OF R this] have "(m k, n l) \<in> \<langle>V\<rangle>option_rel" .
with 2 obtain v where "m k = Some v" "(v,w)\<in>V" by (cases "m k"; auto)
ultimately show thesis by - (rule that)
qed
lemma map_rel_obtain2:
assumes 1: "(m,n)\<in>\<langle>K,V\<rangle>map_rel"
assumes 2: "m k = Some v"
obtains l w where "n l = Some w" "(k,l)\<in>K" "(v,w)\<in>V"
using 1 unfolding map_rel_def
proof clarsimp
assume R: "(m, n) \<in> K \<rightarrow> \<langle>V\<rangle>option_rel"
assume "dom m \<subseteq> Domain K"
with 2 obtain l where "(k,l)\<in>K" by auto
moreover from fun_relD[OF R this] have "(m k, n l) \<in> \<langle>V\<rangle>option_rel" .
with 2 obtain w where "n l = Some w" "(v,w)\<in>V" by (cases "n l"; auto)
ultimately show thesis by - (rule that)
qed
subsection \<open>Interface Type\<close>
sepref_decl_intf ('k,'v) i_map is "'k \<rightharpoonup> 'v"
subsection \<open>Operations\<close>
sepref_decl_op map_empty: "Map.empty" :: "\<langle>K,V\<rangle>map_rel" .
sepref_decl_op map_is_empty: "(=) Map.empty" :: "\<langle>K,V\<rangle>map_rel \<rightarrow> bool_rel"
apply (rule fref_ncI)
apply parametricity
apply (rule fun_relI; auto)
done
sepref_decl_op map_update: "\<lambda>k v m. m(k\<mapsto>v)" :: "K \<rightarrow> V \<rightarrow> \<langle>K,V\<rangle>map_rel \<rightarrow> \<langle>K,V\<rangle>map_rel"
where "single_valued K" "single_valued (K\<inverse>)"
apply (rule fref_ncI)
apply parametricity
unfolding map_rel_def
apply (intro fun_relI)
apply (elim IntE; rule IntI)
apply (intro fun_relI)
apply parametricity
apply (simp add: pres_eq_iff_svb)
apply auto
done
sepref_decl_op map_delete: "\<lambda>k m. fun_upd m k None" :: "K \<rightarrow> \<langle>K,V\<rangle>map_rel \<rightarrow> \<langle>K,V\<rangle>map_rel"
where "single_valued K" "single_valued (K\<inverse>)"
apply (rule fref_ncI)
apply parametricity
unfolding map_rel_def
apply (intro fun_relI)
apply (elim IntE; rule IntI)
apply (intro fun_relI)
apply parametricity
apply (simp add: pres_eq_iff_svb)
apply auto
done
sepref_decl_op map_lookup: "\<lambda>k (m::'k\<rightharpoonup>'v). m k" :: "K \<rightarrow> \<langle>K,V\<rangle>map_rel \<rightarrow> \<langle>V\<rangle>option_rel"
apply (rule fref_ncI)
apply parametricity
unfolding map_rel_def
apply (intro fun_relI)
apply (elim IntE)
apply parametricity
done
lemma in_dom_alt: "k\<in>dom m \<longleftrightarrow> \<not>is_None (m k)" by (auto split: option.split)
sepref_decl_op map_contains_key: "\<lambda>k m. k\<in>dom m" :: "K \<rightarrow> \<langle>K,V\<rangle>map_rel \<rightarrow> bool_rel"
unfolding in_dom_alt
apply (rule fref_ncI)
apply parametricity
unfolding map_rel_def
apply (elim IntE)
apply parametricity
done
subsection \<open>Patterns\<close>
lemma pat_map_empty[pat_rules]: "\<lambda>\<^sub>2_. None \<equiv> op_map_empty" by simp
lemma pat_map_is_empty[pat_rules]:
"(=) $m$(\<lambda>\<^sub>2_. None) \<equiv> op_map_is_empty$m"
"(=) $(\<lambda>\<^sub>2_. None)$m \<equiv> op_map_is_empty$m"
"(=) $(dom$m)${} \<equiv> op_map_is_empty$m"
"(=) ${}$(dom$m) \<equiv> op_map_is_empty$m"
unfolding atomize_eq
by (auto dest: sym)
lemma pat_map_update[pat_rules]:
"fun_upd$m$k$(Some$v) \<equiv> op_map_update$'k$'v$'m"
by simp
lemma pat_map_lookup[pat_rules]: "m$k \<equiv> op_map_lookup$'k$'m"
by simp
lemma op_map_delete_pat[pat_rules]:
"(|`) $ m $ (uminus $ (insert $ k $ {})) \<equiv> op_map_delete$'k$'m"
"fun_upd$m$k$None \<equiv> op_map_delete$'k$'m"
by (simp_all add: map_upd_eq_restrict)
lemma op_map_contains_key[pat_rules]:
"(\<in>) $ k $ (dom$m) \<equiv> op_map_contains_key$'k$'m"
"Not$((=) $(m$k)$None) \<equiv> op_map_contains_key$'k$'m"
by (auto intro!: eq_reflection)
subsection \<open>Parametricity\<close>
locale map_custom_empty =
fixes op_custom_empty :: "'k\<rightharpoonup>'v"
assumes op_custom_empty_def: "op_custom_empty = op_map_empty"
begin
sepref_register op_custom_empty :: "('kx,'vx) i_map"
lemma fold_custom_empty:
"Map.empty = op_custom_empty"
"op_map_empty = op_custom_empty"
"mop_map_empty = RETURN op_custom_empty"
unfolding op_custom_empty_def by simp_all
end
end
|
If $a > b$, then eventually $x \in (b, a)$ as $x$ approaches $a$ from the left. |
module MyPackage
using LinearAlgebra: norm
include("myfile.jl")
end
|
/-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import control.functor
import data.sum.basic
/-!
# Functors with two arguments
This file defines bifunctors.
A bifunctor is a function `F : Type* → Type* → Type*` along with a bimap which turns `F α β` into
`F α' β'` given two functions `α → α'` and `β → β'`. It further
* respects the identity: `bimap id id = id`
* composes in the obvious way: `(bimap f' g') ∘ (bimap f g) = bimap (f' ∘ f) (g' ∘ g)`
## Main declarations
* `bifunctor`: A typeclass for the bare bimap of a bifunctor.
* `is_lawful_bifunctor`: A typeclass asserting this bimap respects the bifunctor laws.
-/
universes u₀ u₁ u₂ v₀ v₁ v₂
open function
/-- Lawless bifunctor. This typeclass only holds the data for the bimap. -/
class bifunctor (F : Type u₀ → Type u₁ → Type u₂) :=
(bimap : Π {α α' β β'}, (α → α') → (β → β') → F α β → F α' β')
export bifunctor ( bimap )
/-- Bifunctor. This typeclass asserts that a lawless `bifunctor` is lawful. -/
class is_lawful_bifunctor (F : Type u₀ → Type u₁ → Type u₂) [bifunctor F] :=
(id_bimap : Π {α β} (x : F α β), bimap id id x = x)
(bimap_bimap : Π {α₀ α₁ α₂ β₀ β₁ β₂} (f : α₀ → α₁) (f' : α₁ → α₂)
(g : β₀ → β₁) (g' : β₁ → β₂) (x : F α₀ β₀),
bimap f' g' (bimap f g x) = bimap (f' ∘ f) (g' ∘ g) x)
export is_lawful_bifunctor (id_bimap bimap_bimap)
attribute [higher_order bimap_id_id] id_bimap
attribute [higher_order bimap_comp_bimap] bimap_bimap
export is_lawful_bifunctor (bimap_id_id bimap_comp_bimap)
variables {F : Type u₀ → Type u₁ → Type u₂} [bifunctor F]
namespace bifunctor
/-- Left map of a bifunctor. -/
@[reducible] def fst {α α' β} (f : α → α') : F α β → F α' β := bimap f id
/-- Right map of a bifunctor. -/
@[reducible] def snd {α β β'} (f : β → β') : F α β → F α β' := bimap id f
variable [is_lawful_bifunctor F]
@[higher_order fst_id]
lemma id_fst : Π {α β} (x : F α β), fst id x = x :=
@id_bimap _ _ _
@[higher_order snd_id]
lemma id_snd : Π {α β} (x : F α β), snd id x = x :=
@id_bimap _ _ _
@[higher_order fst_comp_fst]
@[higher_order fst_comp_snd]
lemma fst_snd {α₀ α₁ β₀ β₁}
(f : α₀ → α₁) (f' : β₀ → β₁) (x : F α₀ β₀) :
fst f (snd f' x) = bimap f f' x :=
by simp [fst,bimap_bimap]
@[higher_order snd_comp_fst]
lemma snd_fst {α₀ α₁ β₀ β₁}
(f : α₀ → α₁) (f' : β₀ → β₁) (x : F α₀ β₀) :
snd f' (fst f x) = bimap f f' x :=
by simp [snd,bimap_bimap]
@[higher_order snd_comp_snd]
lemma comp_snd {α β₀ β₁ β₂}
(g : β₀ → β₁) (g' : β₁ → β₂) (x : F α β₀) :
snd g' (snd g x) = snd (g' ∘ g) x :=
by simp [snd,bimap_bimap]
attribute [functor_norm] bimap_bimap comp_snd comp_fst
snd_comp_snd snd_comp_fst fst_comp_snd fst_comp_fst bimap_comp_bimap
bimap_id_id fst_id snd_id
end bifunctor
open functor
instance : bifunctor prod :=
{ bimap := @prod.map }
instance : is_lawful_bifunctor prod :=
by refine { .. }; intros; cases x; refl
instance bifunctor.const : bifunctor const :=
{ bimap := (λ α α' β β f _, f) }
instance is_lawful_bifunctor.const : is_lawful_bifunctor const :=
by refine { .. }; intros; refl
instance bifunctor.flip : bifunctor (flip F) :=
{ bimap := (λ α α' β β' f f' x, (bimap f' f x : F β' α')) }
instance is_lawful_bifunctor.flip [is_lawful_bifunctor F] : is_lawful_bifunctor (flip F) :=
by refine { .. }; intros; simp [bimap] with functor_norm
instance : bifunctor sum :=
{ bimap := @sum.map }
instance : is_lawful_bifunctor sum :=
by refine { .. }; intros; cases x; refl
open bifunctor functor
@[priority 10]
instance bifunctor.functor {α} : functor (F α) :=
{ map := λ _ _, snd }
@[priority 10]
instance bifunctor.is_lawful_functor [is_lawful_bifunctor F] {α} : is_lawful_functor (F α) :=
by refine {..}; intros; simp [functor.map] with functor_norm
section bicompl
variables (G : Type* → Type u₀) (H : Type* → Type u₁) [functor G] [functor H]
instance : bifunctor (bicompl F G H) :=
{ bimap := λ α α' β β' f f' x, (bimap (map f) (map f') x : F (G α') (H β')) }
instance [is_lawful_functor G] [is_lawful_functor H] [is_lawful_bifunctor F] :
is_lawful_bifunctor (bicompl F G H) :=
by constructor; intros; simp [bimap,map_id,map_comp_map] with functor_norm
end bicompl
section bicompr
variables (G : Type u₂ → Type*) [functor G]
instance : bifunctor (bicompr G F) :=
{ bimap := λ α α' β β' f f' x, (map (bimap f f') x : G (F α' β')) }
instance [is_lawful_functor G] [is_lawful_bifunctor F] :
is_lawful_bifunctor (bicompr G F) :=
by constructor; intros; simp [bimap] with functor_norm
end bicompr
|
module Js.React.DOM
import Js
import Js.Object
import Js.DOM.Element
import Js.React.Element
%default total
export
%inline
render : (mount : Js.DOM.Element.Element) -> (element : Js.React.Element.Element) -> JS_IO ()
render mount = js "ReactDOM.render(%1, %0)" (Ptr -> Ptr -> JS_IO ()) (ptr mount) . ptr
|
State Before: C : Type u
inst✝¹ : Category C
inst✝ : NonPreadditiveAbelian C
X Y Z : C
f g : X ⟶ Y
h : Y ⟶ Z
⊢ (f + g) ≫ h = f ≫ h + g ≫ h State After: no goals Tactic: rw [add_def, sub_comp, neg_def, sub_comp, zero_comp, add_def, neg_def] |
# Imports and setup:
```python
# import required packages
import os
import csv
from sympy import symbols, init_printing
import numpy as np
import matplotlib
%matplotlib inline
import seaborn as sb
from matplotlib import pyplot as plt
import sympy
import itertools
import scipy
import datetime
import matplotlib.dates as mdates
from pygom import DeterministicOde, Transition, SimulateOde, TransitionType, SquareLoss
from scipy.optimize import minimize
import pickle as pk
import jsonpickle as jpk
from cycler import cycler
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
import pwlf
import pprint
ppr = pprint.PrettyPrinter()
```
/Users/n/.pyenv/versions/3.7.2/lib/python3.7/site-packages/statsmodels/tools/_testing.py:19: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.
import pandas.util.testing as tm
```python
savefigs = False # whether to save specific figures for paper to .../figures directory
```
```python
# Jupyter Specifics
from IPython.display import display, HTML
from ipywidgets.widgets import interact, interactive, IntSlider, FloatSlider, Layout, ToggleButton, ToggleButtons, fixed
display(HTML("<style>.container { width:100% !important; }</style>"))
style = {'description_width': '100px'}
slider_layout = Layout(width='99%')
```
<style>.container { width:100% !important; }</style>
# Model Definitions
```python
#from models import *
from model_fits import *
```
loading data.py...
getting JHU data...
number of countries listed 274
done with JHU data. Got 274 countries.
getting owid data...
data for population changes only slowly if at all in OWID database
done with owid data. Got 212 countries
WHO acute file found dictionary acute_who
ICU file found dictionary icus_2012
---------------------------------
Done with data.
---------------------------------
done with data.py.
making the models...
SEI3R
SC3EI3R
SC3UEI3R
done with the models.
```python
print(acute_dict) # WHO 2014 acute beds per 100000 edited by JSMcC to fill in missing data for 5 countries from previous years
```
{'Armenia': 341.07, 'Austria': 579.96, 'Azerbaijan': 354.18, 'Belgium': 567.27, 'Bulgaria': 595.04, 'Belarus': 866.42, 'Cyprus': 341.32, 'Czechia': 425.03, 'Germany': 620.83, 'Denmark': 261.67, 'Spain': 238.54, 'Estonia': 366.51, 'Finland': 307.55, 'France': 428.04, 'United Kingdom': 227.79, 'Georgia': 210.02, 'Greece': 346.25, 'Hungary': 428.87, 'Croatia': 398.84, 'Iceland': 267.32, 'Ireland': 240.44, 'Israel': 240.6, 'Italy': 274.57, 'Kazakhstan': 418.76, 'Kyrgyzstan': 353.86, 'Latvia': 339.21, 'Lithuania': 634.39, 'Luxembourg': 418.99, 'Monaco': 1119.0, 'Macedonia': 301.66, 'Moldova': 454.62, 'Malta': 323.9, 'Montenegro': 391.18, 'Netherlands': 332.38, 'Norway': 342.52, 'Poland': 487.68, 'Portugal': 325.13, 'Romania': 402.61, 'Russia': 640.69, 'Serbia': 456.25, 'Slovakia': 491.29, 'Slovenia': 423.03, 'Sweden': 234.5, 'Switzerland': 375.08, 'Tajikistan': 425.14, 'Turkey': 258.8, 'Turkmenistan': 306.4, 'Ukraine': 613.31, 'Uzbekistan': 333.87, 'ARM': 341.07, 'AUT': 579.96, 'AZE': 354.18, 'BEL': 567.27, 'BGR': 595.04, 'BLR': 866.42, 'CYP': 341.32, 'CZE': 425.03, 'DEU': 620.83, 'DNK': 261.67, 'ESP': 238.54, 'EST': 366.51, 'FIN': 307.55, 'FRA': 428.04, 'GBR': 227.79, 'GEO': 210.02, 'GRC': 346.25, 'HUN': 428.87, 'HRV': 398.84, 'ISL': 267.32, 'IRL': 240.44, 'ISR': 240.6, 'ITA': 274.57, 'KAZ': 418.76, 'KGZ': 353.86, 'LVA': 339.21, 'LTU': 634.39, 'LUX': 418.99, 'MCO': 1119.0, 'MKD': 301.66, 'MDA': 454.62, 'MLT': 323.9, 'MNE': 391.18, 'NLD': 332.38, 'NOR': 342.52, 'POL': 487.68, 'PRT': 325.13, 'ROU': 402.61, 'RUS': 640.69, 'SRB': 456.25, 'SVK': 491.29, 'SVN': 423.03, 'SWE': 234.5, 'CHE': 375.08, 'TJK': 425.14, 'TUR': 258.8, 'TKM': 306.4, 'UKR': 613.31, 'UZB': 333.87}
```python
print(icu_dict) # Intensive Care Med (2012) 38:1647–1653 DOI 10.1007/s00134-012-2627-8 IMCUs and ICUs per 100000 in 2012
```
{'Andorra': 7.1, 'Austria': 21.8, 'Belgium': 15.9, 'Bulgaria': 12.2, 'Croatia': 14.7, 'Cyprus': 11.4, 'Czechia': 11.6, 'Denmark': 6.7, 'Estonia': 14.6, 'Finland': 6.1, 'France': 11.6, 'Germany': 29.2, 'Greece': 6.0, 'Hungary': 13.8, 'Iceland': 9.1, 'Ireland': 6.5, 'Italy': 12.5, 'Latvia': 9.7, 'Lithuania': 15.5, 'Luxembourg': 24.8, 'Netherlands': 6.4, 'Norway': 8.0, 'Poland': 6.9, 'Portugal': 4.2, 'Romania': 21.4, 'Slovakia': 9.2, 'Slovenia': 6.4, 'Spain': 9.7, 'Sweden': 5.8, 'Switzerland': 11.0, 'United Kingdom': 6.6}
```python
(len(icu_dict),len(acute_dict))
```
(31, 98)
# Test ModelFit
```python
testfit = ModelFit('SC3EI3R',country='Germany',run_id="_tst")
```
============= SC3EI3R_Germany_tst
warning: changing run_id from SC3EI3R_Germany_tst to SC3EI3R_Germany_tst
loaded params from /Users/n/Projects/covid-recovery/Notebooks/covid-19-caution/params/SC3EI3R_Germany_tst.pk :
```python
testfit.dumpparams()
```
dumped params to /Users/n/Projects/covid-recovery/Notebooks/covid-19-caution/params/SC3EI3R_Germany_tst.pk
```python
testfit.stopdate
```
'09/27/20'
```python
testfit.prparams()
```
params:
{'N': 1,
'alpha': 0.2,
'beta_1': 0.36,
'beta_2': 0.0,
'beta_3': 0.0,
'c_0': 0.1,
'c_1': 0.012,
'c_2': 4881.0,
'gamma_1': 0.06999999999999999,
'gamma_2': 0.16666666666666666,
'gamma_3': 0.10000000000000003,
'mu': 0.09999999999999998,
'p_1': 0.030000000000000013,
'p_2': 0.08333333333333334}
sbparams:
{'CFR': 0.05,
'DurHosp': 4,
'DurMildInf': 10,
'Exposure': 0.4,
'FracCritical': 0.10000000000000003,
'FracMild': 0.7,
'FracSevere': 0.2,
'I0': 2.2387211385683378e-08,
'ICUFrac': 0.001,
'IncubPeriod': 5,
'TimeICUDeath': 5}
pfbarams:
{'FracConfirmedDet': 1.0, 'FracDeathsDet': 1.0, 'FracRecoveredDet': 1.0}
cbparams:
{'CautionFactor': 0.1,
'CautionICUFrac': 0.1,
'CautionRetention': 66.66666666666667,
'EconomicCostOfCaution': 0.5,
'EconomicRetention': 66.66666666666667,
'EconomicStriction': 66.66666666666667,
'EconomyRelaxation': 66.66666666666667}
dbparams:
{'country': 'Germany', 'data_src': 'owid', 'run_name': 'SC3EI3R'}
initial_values:
(array([9.999997e-01, 0.000000e+00, 3.000000e-07, 0.000000e+00,
0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00,
0.000000e+00, 0.000000e+00]),
0)
```python
# this cell for debugging methods, as needed.
# copy method here, uncomment appropriate setattr() call below, debug, copy method back to model_fits.py
#MyClass = ModelFit('SC3EI3R',run_id='tst').__class__
#setattr(MyClass,'__init__',__init__)
#setattr(MyClass,'dumpparams',dumpparams)
#setattr(MyClass,'__init__',__init__)
#setattr(MyClass,'loadparams',loadparams)
#setattr(MyClass,'prparams',prparams)
```
```python
testfit.loadparams()
```
loaded params from /Users/n/Projects/covid-recovery/Notebooks/covid-19-caution/params/SC3EI3R_Germany_tst.pk :
True
```python
testfit2 = ModelFit('SC3UEI3R',model=None,country='Italy',run_id='testfit2',datatypes='all',data_src='owid',startdate='2/15/20',stopdate='8/31/20',simdays=300)
```
============= testfit2
warning: changing run_id from testfit2 to testfit2
no file available with this run_id: /Users/n/Projects/covid-recovery/Notebooks/covid-19-caution/params/testfit2.pk
Problem loading paramfile for testfit2 ... using default set of parameters for model type SC3UEI3R
stopdate 8/31/20
```python
print(testfit2.startdate,'to',testfit2.stopdate)
print(len(testfit2.tsim),len(testfit2.tdata))
```
02/15/20 to 08/31/20
300 199
## Debugging of plotdata
Following cells are set up to debug methods of the ModelFit class without restarting kernel and reloading model_fits.py.
Edit functions here, then when debugged, copy them into the class definition of model_fits.py.
```python
# simple plot of data : finessing dates issue
def plotdata(self,dtypes=['confirmed','deaths']):
if type(dtypes)==str:
dtypes = [dtypes]
xx = np.array(range(len(self.tdata)-1))
print(len(xx))
print([(x,len(self.data[x])) for x in dtypes])
for dt in dtypes:
try:
yy = self.data[dt]
except:
print("data type '"+dt+"' not found.")
try:
plt.plot(xx,yy)
except:
print("couldn't plot xx,yy",xx,yy)
plt.show()
```
## Plotting simulation and data with solveplot method
```python
testfit.solveplot(species=['confirmed','deaths'],mag={'deaths':10},summing='daily',averaging='weekly',axes=None,
scale='linear',plottitle= '',label='',newplot = True, gbrcolors=False, figsize = (12,12), outfile = 'tst.pdf')
```
```python
testfit.prparams()
```
params:
{'N': 1,
'alpha': 0.2,
'beta_1': 0.36,
'beta_2': 0.0,
'beta_3': 0.0,
'c_0': 0.1,
'c_1': 0.012,
'c_2': 4881.0,
'gamma_1': 0.06999999999999999,
'gamma_2': 0.16666666666666666,
'gamma_3': 0.10000000000000003,
'mu': 0.09999999999999998,
'p_1': 0.030000000000000013,
'p_2': 0.08333333333333334}
sbparams:
{'CFR': 0.05,
'DurHosp': 4,
'DurMildInf': 10,
'Exposure': 0.4,
'FracCritical': 0.10000000000000003,
'FracMild': 0.7,
'FracSevere': 0.2,
'I0': 2.2387211385683378e-08,
'ICUFrac': 0.001,
'IncubPeriod': 5,
'TimeICUDeath': 5}
pfbarams:
{'FracConfirmedDet': 1.0, 'FracDeathsDet': 1.0, 'FracRecoveredDet': 1.0}
cbparams:
{'CautionFactor': 0.1,
'CautionICUFrac': 0.1,
'CautionRetention': 66.66666666666667,
'EconomicCostOfCaution': 0.5,
'EconomicRetention': 66.66666666666667,
'EconomicStriction': 66.66666666666667,
'EconomyRelaxation': 66.66666666666667}
dbparams:
{'country': 'Germany', 'data_src': 'owid', 'run_name': 'SC3EI3R'}
initial_values:
(array([9.999997e-01, 0.000000e+00, 3.000000e-07, 0.000000e+00,
0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00,
0.000000e+00, 0.000000e+00]),
0)
```python
testfit.prparams()
```
params:
{'N': 1,
'alpha': 0.2,
'beta_1': 0.36,
'beta_2': 0.0,
'beta_3': 0.0,
'c_0': 0.1,
'c_1': 0.012,
'c_2': 4881.0,
'gamma_1': 0.06999999999999999,
'gamma_2': 0.16666666666666666,
'gamma_3': 0.10000000000000003,
'mu': 0.09999999999999998,
'p_1': 0.030000000000000013,
'p_2': 0.08333333333333334}
sbparams:
{'CFR': 0.05,
'DurHosp': 4,
'DurMildInf': 10,
'Exposure': 0.4,
'FracCritical': 0.10000000000000003,
'FracMild': 0.7,
'FracSevere': 0.2,
'I0': 2.2387211385683378e-08,
'ICUFrac': 0.001,
'IncubPeriod': 5,
'TimeICUDeath': 5}
pfbarams:
{'FracConfirmedDet': 1.0, 'FracDeathsDet': 1.0, 'FracRecoveredDet': 1.0}
cbparams:
{'CautionFactor': 0.1,
'CautionICUFrac': 0.1,
'CautionRetention': 66.66666666666667,
'EconomicCostOfCaution': 0.5,
'EconomicRetention': 66.66666666666667,
'EconomicStriction': 66.66666666666667,
'EconomyRelaxation': 66.66666666666667}
dbparams:
{'country': 'Germany', 'data_src': 'owid', 'run_name': 'SC3EI3R'}
initial_values:
(array([9.999997e-01, 0.000000e+00, 3.000000e-07, 0.000000e+00,
0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00,
0.000000e+00, 0.000000e+00]),
0)
# Fitting simulation and data with sliders
## Germany
```python
testfit = ModelFit('SC3EI3R',country='Germany',run_id='SC3EI3R_Germany_tst',simdays=200)
```
============= SC3EI3R_Germany_tst
warning: changing run_id from SC3EI3R_Germany_tst to SC3EI3R_Germany_tst
loaded params from /Users/n/Projects/covid-recovery/Notebooks/covid-19-caution/params/SC3EI3R_Germany_tst.pk :
```python
def slidefitplot(modelfit,beta_1,mu,c_0,c_1,c_2,logI_0):
params={ 'beta_1':beta_1, 'mu':mu, 'c_0':c_0, 'c_1':c_1, 'c_2':c_2}
for pp in params: # careful to keep intact rest of params that don't have sliders
modelfit.params[pp] = params[pp]
modelfit.model.parameters = modelfit.params
I0 = 10**logI_0
x0 = [1.-I0,0.,I0,0.,0.,0.,0.,0.,0.,0.]
modelfit.model.initial_values = (x0,0)
modelfit.sbparams['I0'] = I0
modelfit.solveplot(species=['confirmed','deaths'],mag={'deaths':10},summing='daily',averaging='weekly',axes=None,
scale='linear',plottitle= '',label='',newplot = True, gbrcolors=False,
figsize = (15,10),outfile = testfit.run_id+'.pdf')
```
```python
params=testfit.params
logI_0 = np.log10(testfit.sbparams['I0'])
w =interactive(slidefitplot,modelfit=fixed(testfit),
beta_1=FloatSlider(min=0,max=1,step=0.01,value=params['beta_1'],description='beta_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
mu=FloatSlider(min=0,max=0.2,step=0.002,value=params['mu'],description='mu',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_0=FloatSlider(min=0,max=1,step=0.01,value=params['c_0'],description='c_0',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_1=FloatSlider(min=0,max=1,step=0.001,value=params['c_1'],description='c_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_2=FloatSlider(min=0,max=20000,step=1,value=params['c_2'],description='c_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.1f'),
logI_0=FloatSlider(min=-10,max=0,step=0.01,value=logI_0,description='log I_0',
style=style,layout=slider_layout,continuous_update=False)
)
display(w)
```
interactive(children=(FloatSlider(value=0.36, continuous_update=False, description='beta_1', layout=Layout(wid…
```python
testfit.prparams(testfit.run_id+'.params')
```
```python
testfit.prparams()
```
params:
{'N': 1,
'alpha': 0.2,
'beta_1': 0.36,
'beta_2': 0.0,
'beta_3': 0.0,
'c_0': 0.1,
'c_1': 0.012,
'c_2': 4881.0,
'gamma_1': 0.06999999999999999,
'gamma_2': 0.16666666666666666,
'gamma_3': 0.10000000000000003,
'mu': 0.09999999999999998,
'p_1': 0.030000000000000013,
'p_2': 0.08333333333333334}
sbparams:
{'CFR': 0.05,
'DurHosp': 4,
'DurMildInf': 10,
'Exposure': 0.4,
'FracCritical': 0.10000000000000003,
'FracMild': 0.7,
'FracSevere': 0.2,
'I0': 2.3442288153199228e-08,
'ICUFrac': 0.001,
'IncubPeriod': 5,
'TimeICUDeath': 5}
pfbarams:
{'FracConfirmedDet': 1.0, 'FracDeathsDet': 1.0, 'FracRecoveredDet': 1.0}
cbparams:
{'CautionFactor': 0.1,
'CautionICUFrac': 0.1,
'CautionRetention': 66.66666666666667,
'EconomicCostOfCaution': 0.5,
'EconomicRetention': 66.66666666666667,
'EconomicStriction': 66.66666666666667,
'EconomyRelaxation': 66.66666666666667}
dbparams:
{'country': 'Germany', 'data_src': 'owid', 'run_name': 'SC3EI3R'}
initial_values:
(array([9.999997e-01, 0.000000e+00, 3.000000e-07, 0.000000e+00,
0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00,
0.000000e+00, 0.000000e+00]),
0)
```python
testfit.plotdata()
# I left this cell in so you can see how one can use the mdates together with my data structures to add real dates to the plots
# Have to replace xx with the dates in the solveplot method in that case
def truncx(xx,daystart,daystop):
"""truncate array xx to run from daystart to daystop
do this before trying to extend the arrays if required"""
daymin = max(daystart,0)
daymax = min(daystop,(xx[-1]-xx[0]).days)
return xx[daymin:daymax+1]
def truncy(xx,yy,daystart,daystop):
"""truncate arrays xx and yy to run from daystart to daystop
do this before trying to extend the arrays if required"""
daymin = max(daystart,0)
daymax = min(daystop,(xx[-1]-xx[0]).days)
return yy[daymin:daymax+1]
def plotCountry_(country_s, datatype='confirmed', dataaccum='cumulative', fittype=None, ax=None, ax2=False,
symbol='o--', step=None, firstdate=None, lastdate=None, intdates=False, linecolor=None, maxyval=None, minconfirmed=0,nsegments=3,database='jhu'):
""" plots selected data for a list of countries or single country
datatypes allowed are 'confirmed','deaths','recovered'
dataaccum specifies either 'cumulative' or 'daily' or averaged over 7 days 'cum_av_weekly' or 'daily_av_weekly'
fittypes allowed are currently None, 'piecewise-linear'
ax graphical axes to use for plot: default None -> new axes
ax2 true if second axes as twin axes for overlay plotting
symbol to use for plotting
step whether to use step plotting instead of points: default None -> points
firstdate to plot (maybe before first date in data - pad with 0)
lastdate to plot (maybe after last date in data - pad with 0)
intdates : whether to plot dates as integers for compatibility (default as dates)
linecolor is default color to use for a single trace, instead of listed set)
"""
global covid_ts, covid_ts_owid
import math
import warnings
# extract list of countries in [(country,region),...] format from first parameter
countries = []
if isinstance(country_s,list):
for country in country_s:
if isinstance(country,str) and database == 'jhu':
country = (country,'')
countries.append(country)
elif isinstance(country_s,str):
if database == 'jhu':
countries = [( country_s,'')]
else:
countries = [country_s]
else: # single ('country','reg') entry
countries = [country_s]
# get data with datatype and extend dates to padd desired interval specified by firstdate,lastdate
if database == 'jhu':
popkeyed = covid_ts[datatype]
dates = popkeyed['dates']
fmt = '%m/%d/%y'
elif database == 'owid':
popkeyed = covid_owid_ts[datatype]
dates = popkeyed['dates']
fmt = '%m/%d/%y'
# fmt = '%Y-%m-%d' the owid date format was converted to the jhu date format in get_data_owid
xxd = [datetime.datetime.strptime(dd,fmt) for dd in dates ]
if firstdate:
firstdate_d = datetime.datetime.strptime(firstdate,fmt)
else:
firstdate_d = datetime.datetime.strptime(dates[0],fmt)
if lastdate:
lastdate_d = datetime.datetime.strptime(lastdate,fmt)
else:
lastdate_d = datetime.datetime.strptime(dates[-1],fmt)
daystart = (firstdate_d-xxd[0]).days
daystop = (lastdate_d-xxd[0]).days
xx = [0.]*(daystop-daystart+1)
xx = truncx(xxd,daystart,daystop) # truncates list to chosen date interval !!!!!!!!!!!!!!!!!!!!!!!!!
# print('1 len xx',len(xx))
if daystart <0:
xx0 = [xx[0]+datetime.timedelta(days=i) for i in range(daystart,0)]
yy0 = [0.]*(-daystart)
else:
xx0 = []
yy0 = []
if daystop > (xxd[-1]-xxd[0]).days:
xx1 = [xxd[-1]+datetime.timedelta(days=i) for i in range(daystop-(xxd[-1]-xxd[0]).days)]
yy1 = [' ']*(daystop-(xxd[-1]-xxd[0]).days)
else:
xx1 = []
yy1 = []
xx = xx0 + xx + xx1
# print('2 len xx',len(xx))
#print('len xx1 yy1',len(xx1),len(yy1))
# print('len xx',len(xx))
if fittype == 'piecewise-linear':
xxi = [Float((x-xx[0]).days) for x in xx ]
# print(xxi)
# print('len xxi',len(xxi))
# locator = mdates.MonthLocator()
locator = mdates.AutoDateLocator(minticks=5, maxticks=13)
formatter= mdates.ConciseDateFormatter(locator)
if not ax:
fig,ax = plt.subplots(1,1,figsize=(9,6))
ax2 = ax
elif ax2:
ax2 = ax.twinx()
else:
ax2 = ax
colors = ['k', 'b', 'c', 'm', 'y', 'g', 'olive', 'chocolate']
i = 0
j = 0
for country in countries:
try:
yyd = popkeyed[country]
if np.max(yyd) >= minconfirmed:
j = j+1
else:
i = i + 1
continue
except:
print('country not found',country)
i = i + 1
continue
yy = truncy(xxd,yyd,daystart,daystop)
# print(country,'1 len yy yyd',len(yy),len(yyd))
yyf = [Float(y) for y in yy]
yy = yy0 + yyf + yy1
# print(country,'2 len yy',len(yy))
# ymax=np.max(np.array(yy))
yyf = [Float(y) for y in yy]
if dataaccum == 'daily':
yy = [0.]*len(yy)
yy[0] = yyf[0]
for k in range(1,len(yy)):
yy[k] = yyf[k]-yyf[k-1]
elif dataaccum == 'cum_av_weekly':
yy = [0.]*len(yy)
moving_av = 0.
for k in range(len(yy)):
if k-7 >= 0:
moving_av = moving_av - yyf[k-7]
moving_av = moving_av + yyf[k]
yy[k] = moving_av/min(7.0,float(k+1))
elif dataaccum == 'daily_av_weekly':
yy = [0.]*len(yyf)
yy[0] = yyf[0]
for k in range(1,len(yy)):
yy[k] = yyf[k]-yyf[k-1]
yyf = [y for y in yy]
yy = [0.]*len(yy)
moving_av = 0.
for k in range(len(yy)):
if k-7 >= 0:
moving_av = moving_av - yyf[k-7]
moving_av = moving_av + yyf[k]
yy[k] = moving_av/min(7.0,float(k+1))
if intdates:
xx = range(len(xx))
if step:
ax2.step(xx,yy,label = country[0])
else:
# print(ax,ax2)
# ax2.set_ylim(ymax,0)
if linecolor:
color = linecolor
else:
color = colors[i]
ax2.plot(xx, yy, symbol, markersize=3, color = color, alpha=0.8, label = country[0])
if maxyval: ax.set_ylim(0,maxyval)
if maxyval: ax2.set_ylim(0,maxyval)
plt.title(country[0]+'-'+country[1]) # +' '+datatype)
if fittype == 'piecewise-linear':
warnings.filterwarnings("ignore", message="Warning: zero length interval encountered in pwlf.py calc_slopes")
# initialize piecewise linear fit with your x and y data
# yyf = [Float(y) for y in yy]
yyf = [Float(y) if not math.isnan(y) else 0.0 for y in yy]
# print(yyf)
my_pwlf = pwlf.PiecewiseLinFit(xxi, yyf)
# fit the data for three line segments
res = my_pwlf.fit(nsegments)
ppp = my_pwlf.p_values(method='non-linear', step_size=1e-4)
se = my_pwlf.se # standard errors
parameters = np.concatenate((my_pwlf.beta,
my_pwlf.fit_breaks[1:-1]))
header = ['Parameter type', 'Parameter value ', 'Standard error ', 't ', 'P > np.abs(t) (p-value)']
print(*header, sep=' | ')
fltfmt = "{:12.3f}".format
values = np.zeros((parameters.size, 5), dtype=np.object_)
values[:, 1] = [fltfmt(np.around(term, decimals=3)) for term in parameters]
values[:, 2] = [fltfmt(np.around(term, decimals=3)) for term in se]
values[:, 3] = [fltfmt(np.around(term, decimals=3)) for term in parameters/se]
values[:, 4] = [fltfmt(np.around(term, decimals=3)) for term in ppp]
for iii, row in enumerate(values):
if iii < my_pwlf.beta.size:
row[0] = 'Slope '
print(*row, sep=' | ')
else:
row[0] = 'Breakpoint'
print(*row, sep=' | ')
print("")
# predict for the determined points
xHat = np.linspace(min(xxi), max(xxi), num=len(xx))
# print(len(xHat),len(xxi))
yHat = my_pwlf.predict(xHat)
ax2.plot(xx, yHat, color = colors[i], alpha=0.5, label = country[0]+' fit')
i = i+1
if j==0:
ax.axis("off")
else:
if j > 1:
plt.legend(loc="upper left")
plt.title('countries '+datatype+dataaccum)
if not intdates:
ax2.xaxis.set_major_formatter(formatter)
ax2.xaxis.set_major_locator(locator)
for tick in ax2.get_xticklabels():
tick.set_rotation(40)
```
## Spain
```python
testfit = ModelFit('SC3EI3R',country='Spain',run_id='_tst',stopdate='09/10/20')
```
============= SC3EI3R_Spain_tst
warning: changing run_id from SC3EI3R_Spain_tst to SC3EI3R_Spain_tst
loaded params from /Users/n/Projects/covid-recovery/Notebooks/covid-19-caution/params/SC3EI3R_Spain_tst.pk :
stopdate 09/10/20
```python
print([x for x in dir(testfit) if 'date' in x])
testfit.stopdate
```
['dates', 'startdate', 'stopdate']
'09/10/20'
```python
[pp for pp in testfit.params]
```
['beta_1',
'beta_2',
'beta_3',
'alpha',
'gamma_1',
'gamma_2',
'gamma_3',
'p_1',
'p_2',
'mu',
'c_0',
'c_1',
'c_2',
'N']
```python
def slidefitplot(modelfit,beta_1,alpha,gamma_1,gamma_2,gamma_3,mu,c_0,c_1,c_2,logI_0):
params={ 'beta_1':beta_1, 'alpha':alpha,'gamma_1':gamma_1,'gamma_2':gamma_2,'gamma_3':gamma_3,
'mu':mu, 'c_0':c_0, 'c_1':c_1, 'c_2':c_2}
for pp in params: # careful to keep intact rest of params that don't have sliders
modelfit.params[pp] = params[pp]
modelfit.model.parameters = modelfit.params
I0 = 10**logI_0
x0 = [1.-I0,0.,I0,0.,0.,0.,0.,0.,0.,0.]
modelfit.model.initial_values = (x0,0)
modelfit.sbparams['I0'] = I0
modelfit.solveplot(species=['confirmed','deaths'],mag={'deaths':10},summing='daily',averaging='weekly',axes=None,
scale='linear',plottitle= '',label='',newplot = True, gbrcolors=False,
figsize = (15,10),outfile = testfit.run_id+'.pdf')
```
```python
params=testfit.params
logI_0 = np.log10(testfit.sbparams['I0'])
w =interactive(slidefitplot,modelfit=fixed(testfit),
beta_1=FloatSlider(min=0,max=1,step=0.01,value=params['beta_1'],description='beta_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
alpha=FloatSlider(min=0,max=1,step=0.01,value=params['alpha'],description='alpha',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
gamma_1=FloatSlider(min=0,max=0.5,step=0.002,value=params['gamma_1'],description='gamma_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
gamma_2=FloatSlider(min=0,max=0.5,step=0.002,value=params['gamma_2'],description='gamma_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
gamma_3=FloatSlider(min=0,max=0.5,step=0.002,value=params['gamma_3'],description='gamma_3',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
mu=FloatSlider(min=0,max=0.2,step=0.002,value=params['mu'],description='mu',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_0=FloatSlider(min=0,max=1,step=0.01,value=params['c_0'],description='c_0',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_1=FloatSlider(min=0,max=1,step=0.001,value=params['c_1'],description='c_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_2=FloatSlider(min=0,max=20000,step=1,value=params['c_2'],description='c_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.1f'),
logI_0=FloatSlider(min=-10,max=0,step=0.01,value=logI_0,description='log I_0',
style=style,layout=slider_layout,continuous_update=False)
)
display(w)
```
interactive(children=(FloatSlider(value=0.4, continuous_update=False, description='beta_1', layout=Layout(widt…
```python
testfit.prparams(testfit.run_id+'.params')
```
```python
testfit.prparams()
```
params:
{'N': 1,
'alpha': 0.2,
'beta_1': 0.4,
'beta_2': 0.0,
'beta_3': 0.0,
'c_0': 0.12,
'c_1': 0.04,
'c_2': 2575.0,
'gamma_1': 0.06999999999999999,
'gamma_2': 0.16666666666666666,
'gamma_3': 0.10000000000000003,
'mu': 0.042,
'p_1': 0.030000000000000013,
'p_2': 0.08333333333333334}
sbparams:
{'CFR': 0.05,
'DurHosp': 4,
'DurMildInf': 10,
'Exposure': 0.4,
'FracCritical': 0.10000000000000003,
'FracMild': 0.7,
'FracSevere': 0.2,
'I0': 1.5848931924611143e-08,
'ICUFrac': 0.001,
'IncubPeriod': 5,
'TimeICUDeath': 5}
pfbarams:
{'FracConfirmedDet': 1.0, 'FracDeathsDet': 1.0, 'FracRecoveredDet': 1.0}
cbparams:
{'CautionFactor': 0.1,
'CautionICUFrac': 0.1,
'CautionRetention': 66.66666666666667,
'EconomicCostOfCaution': 0.5,
'EconomicRetention': 66.66666666666667,
'EconomicStriction': 66.66666666666667,
'EconomyRelaxation': 66.66666666666667}
dbparams:
{'country': 'Germany', 'data_src': 'owid', 'run_name': 'SC3EI3R'}
initial_values:
(array([9.999997e-01, 0.000000e+00, 3.000000e-07, 0.000000e+00,
0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00,
0.000000e+00, 0.000000e+00]),
0)
## Italy
```python
testfit = ModelFit('SC3EI3R',country='Italy',run_id='_tst',stopdate='09/10/20')
```
============= SC3EI3R_Italy_tst
warning: changing run_id from SC3EI3R_Italy_tst to SC3EI3R_Italy_tst
no file available with this run_id /Users/n/Projects/covid-recovery/Notebooks/covid-19-caution/params/SC3EI3R_Italy_tst.pk
Problem loading paramfile for _tst ... using default set of parameters for model type SC3EI3R
stopdate 09/10/20
```python
print([x for x in dir(testfit) if 'date' in x])
testfit.stopdate
```
['dates', 'startdate', 'stopdate']
'09/10/20'
```python
def slidefitplot(modelfit,beta_1,alpha,gamma_1,gamma_2,gamma_3,mu,c_0,c_1,c_2,logI_0):
params={ 'beta_1':beta_1, 'alpha':alpha,'gamma_1':gamma_1,'gamma_2':gamma_2,'gamma_3':gamma_3,
'mu':mu, 'c_0':c_0, 'c_1':c_1, 'c_2':c_2}
for pp in params: # careful to keep intact rest of params that don't have sliders
modelfit.params[pp] = params[pp]
modelfit.model.parameters = modelfit.params
I0 = 10**logI_0
x0 = [1.-I0,0.,I0,0.,0.,0.,0.,0.,0.,0.]
modelfit.model.initial_values = (x0,0)
modelfit.sbparams['I0'] = I0
modelfit.solveplot(species=['confirmed','deaths'],mag={'deaths':10},summing='daily',averaging='weekly',axes=None,
scale='linear',plottitle= '',label='',newplot = True, gbrcolors=False,
figsize = (15,10),outfile = testfit.run_id+'.pdf')
```
```python
params=testfit.params
logI_0 = np.log10(testfit.sbparams['I0'])
w =interactive(slidefitplot,modelfit=fixed(testfit),
beta_1=FloatSlider(min=0,max=1,step=0.01,value=params['beta_1'],description='beta_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
alpha=FloatSlider(min=0,max=1,step=0.01,value=params['alpha'],description='alpha',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
gamma_1=FloatSlider(min=0,max=0.5,step=0.002,value=params['gamma_1'],description='gamma_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
gamma_2=FloatSlider(min=0,max=0.5,step=0.002,value=params['gamma_2'],description='gamma_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
gamma_3=FloatSlider(min=0,max=0.5,step=0.002,value=params['gamma_3'],description='gamma_3',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
mu=FloatSlider(min=0,max=0.2,step=0.002,value=params['mu'],description='mu',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_0=FloatSlider(min=0,max=1,step=0.01,value=params['c_0'],description='c_0',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_1=FloatSlider(min=0,max=1,step=0.001,value=params['c_1'],description='c_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_2=FloatSlider(min=0,max=20000,step=1,value=params['c_2'],description='c_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.1f'),
logI_0=FloatSlider(min=-10,max=0,step=0.01,value=logI_0,description='log I_0',
style=style,layout=slider_layout,continuous_update=False)
)
display(w)
```
interactive(children=(FloatSlider(value=0.4, continuous_update=False, description='beta_1', layout=Layout(widt…
```python
from shutil import copyfile
```
```python
testfit.prparams(testfit.run_id+'.params')
paramfile = './params/'+testfit.run_id+'.pk'
copyfile(paramfile,testfit.run_id+'.pk')
```
'SC3EI3R_Italy_tst.pk'
## Brazil
```python
testfit = ModelFit('SC3EI3R',country='Brazil',run_id='_tst',stopdate='09/10/20')
```
============= SC3EI3R_Brazil_tst
warning: changing run_id from SC3EI3R_Brazil_tst to SC3EI3R_Brazil_tst
no file available with this run_id /Users/n/Projects/covid-recovery/Notebooks/covid-19-caution/params/SC3EI3R_Brazil_tst.pk
Problem loading paramfile for _tst ... using default set of parameters for model type SC3EI3R
stopdate 09/10/20
```python
print([x for x in dir(testfit) if 'date' in x])
testfit.stopdate
```
['dates', 'startdate', 'stopdate']
'09/10/20'
```python
def slidefitplot(modelfit,beta_1,alpha,gamma_1,gamma_2,gamma_3,mu,c_0,c_1,c_2,logI_0):
params={ 'beta_1':beta_1, 'alpha':alpha,'gamma_1':gamma_1,'gamma_2':gamma_2,'gamma_3':gamma_3,
'mu':mu, 'c_0':c_0, 'c_1':c_1, 'c_2':c_2}
for pp in params: # careful to keep intact rest of params that don't have sliders
modelfit.params[pp] = params[pp]
modelfit.model.parameters = modelfit.params
I0 = 10**logI_0
x0 = [1.-I0,0.,I0,0.,0.,0.,0.,0.,0.,0.]
modelfit.model.initial_values = (x0,0)
modelfit.sbparams['I0'] = I0
modelfit.solveplot(species=['confirmed','deaths'],mag={'deaths':10},summing='daily',averaging='weekly',axes=None,
scale='linear',plottitle= '',label='',newplot = True, gbrcolors=False,
figsize = (15,10),outfile = testfit.run_id+'.pdf')
```
```python
params=testfit.params
logI_0 = np.log10(testfit.sbparams['I0'])
w =interactive(slidefitplot,modelfit=fixed(testfit),
beta_1=FloatSlider(min=0,max=1,step=0.01,value=params['beta_1'],description='beta_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
alpha=FloatSlider(min=0,max=1,step=0.01,value=params['alpha'],description='alpha',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
gamma_1=FloatSlider(min=0,max=0.5,step=0.002,value=params['gamma_1'],description='gamma_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
gamma_2=FloatSlider(min=0,max=0.5,step=0.002,value=params['gamma_2'],description='gamma_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
gamma_3=FloatSlider(min=0,max=0.5,step=0.002,value=params['gamma_3'],description='gamma_3',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
mu=FloatSlider(min=0,max=0.2,step=0.002,value=params['mu'],description='mu',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_0=FloatSlider(min=0,max=1,step=0.01,value=params['c_0'],description='c_0',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_1=FloatSlider(min=0,max=1,step=0.001,value=params['c_1'],description='c_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_2=FloatSlider(min=0,max=20000,step=1,value=params['c_2'],description='c_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.1f'),
logI_0=FloatSlider(min=-10,max=0,step=0.01,value=logI_0,description='log I_0',
style=style,layout=slider_layout,continuous_update=False)
)
display(w)
```
interactive(children=(FloatSlider(value=0.4, continuous_update=False, description='beta_1', layout=Layout(widt…
```python
from shutil import copyfile
```
```python
testfit.prparams(testfit.run_id+'.params')
paramfile = './params/'+testfit.run_id+'.pk'
copyfile(paramfile,testfit.run_id+'.pk')
```
'SC3EI3R_Italy_tst.pk'
## Sweden
### SC3EI3R
```python
testfit = ModelFit('SC3EI3R',country='Sweden',run_id='_tst',stopdate='09/10/20')
```
============= SC3EI3R_Sweden_tst
warning: changing run_id from SC3EI3R_Sweden_tst to SC3EI3R_Sweden_tst
no file available with this run_id /Users/n/Projects/covid-recovery/Notebooks/covid-19-caution/params/SC3EI3R_Sweden_tst.pk
Problem loading paramfile for _tst ... using default set of parameters for model type SC3EI3R
stopdate 09/10/20
```python
print([x for x in dir(testfit) if 'date' in x])
testfit.stopdate
```
['dates', 'startdate', 'stopdate']
'09/10/20'
```python
def slidefitplot(modelfit,beta_1,alpha,gamma_1,gamma_2,gamma_3,mu,c_0,c_1,c_2,logI_0):
params={ 'beta_1':beta_1, 'alpha':alpha,'gamma_1':gamma_1,'gamma_2':gamma_2,'gamma_3':gamma_3,
'mu':mu, 'c_0':c_0, 'c_1':c_1, 'c_2':c_2}
for pp in params: # careful to keep intact rest of params that don't have sliders
modelfit.params[pp] = params[pp]
modelfit.model.parameters = modelfit.params
I0 = 10**logI_0
x0 = [1.-I0,0.,I0,0.,0.,0.,0.,0.,0.,0.]
modelfit.model.initial_values = (x0,0)
modelfit.sbparams['I0'] = I0
modelfit.solveplot(species=['confirmed','deaths'],mag={'deaths':10},summing='daily',averaging='weekly',axes=None,
scale='linear',plottitle= '',label='',newplot = True, gbrcolors=False,
figsize = (15,10),outfile = testfit.run_id+'.pdf')
```
```python
params=testfit.params
logI_0 = np.log10(testfit.sbparams['I0'])
w =interactive(slidefitplot,modelfit=fixed(testfit),
beta_1=FloatSlider(min=0,max=1,step=0.01,value=params['beta_1'],description='beta_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
alpha=FloatSlider(min=0,max=1,step=0.01,value=params['alpha'],description='alpha',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
gamma_1=FloatSlider(min=0,max=0.5,step=0.002,value=params['gamma_1'],description='gamma_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
gamma_2=FloatSlider(min=0,max=0.5,step=0.002,value=params['gamma_2'],description='gamma_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
gamma_3=FloatSlider(min=0,max=0.5,step=0.002,value=params['gamma_3'],description='gamma_3',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
mu=FloatSlider(min=0,max=0.2,step=0.002,value=params['mu'],description='mu',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_0=FloatSlider(min=0,max=1,step=0.01,value=params['c_0'],description='c_0',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_1=FloatSlider(min=0,max=1,step=0.001,value=params['c_1'],description='c_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_2=FloatSlider(min=0,max=20000,step=1,value=params['c_2'],description='c_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.1f'),
logI_0=FloatSlider(min=-10,max=0,step=0.01,value=logI_0,description='log I_0',
style=style,layout=slider_layout,continuous_update=False)
)
display(w)
```
interactive(children=(FloatSlider(value=0.4, continuous_update=False, description='beta_1', layout=Layout(widt…
```python
from shutil import copyfile
```
```python
testfit.prparams(testfit.run_id+'.params')
paramfile = './params/'+testfit.run_id+'.pk'
copyfile(paramfile,testfit.run_id+'.pk')
```
'SC3EI3R_Sweden_tst.pk'
### SC3UEI3R
```python
testfit = ModelFit('SC3UEI3R',country='Sweden',run_id='_tst',stopdate='09/10/20')
```
============= SC3UEI3R_Sweden_tst
warning: changing run_id from SC3UEI3R_Sweden_tst to SC3UEI3R_Sweden_tst
no file available with this run_id /Users/n/Projects/covid-recovery/Notebooks/covid-19-caution/params/SC3UEI3R_Sweden_tst.pk
Problem loading paramfile for _tst ... using default set of parameters for model type SC3UEI3R
stopdate 09/10/20
```python
print([x for x in dir(testfit) if 'date' in x])
testfit.stopdate
```
['dates', 'startdate', 'stopdate']
'09/10/20'
```python
def slidefitplot(modelfit,beta_1,alpha,gamma_1,gamma_2,gamma_3,mu,c_0,c_1,c_2,logI_0,k_u,k_1,k_w,kappa):
params={ 'beta_1':beta_1, 'alpha':alpha,'gamma_1':gamma_1,'gamma_2':gamma_2,'gamma_3':gamma_3,
'mu':mu, 'c_0':c_0, 'c_1':c_1, 'c_2':c_2,'k_u':k_u, 'k_1':k_1, 'k_w':k_w, 'kappa':kappa}
for pp in params: # careful to keep intact rest of params that don't have sliders
modelfit.params[pp] = params[pp]
modelfit.model.parameters = modelfit.params
I0 = 10**logI_0
x0 = [1.-I0,0.,I0,0.,0.,0.,0.,0.,0.,0.,0.0,0.0]
modelfit.model.initial_values = (x0,0)
modelfit.sbparams['I0'] = I0
modelfit.solveplot(species=['confirmed','deaths'],mag={'deaths':10},summing='daily',averaging='weekly',axes=None,
scale='linear',plottitle= '',label='',newplot = True, gbrcolors=False,
figsize = (15,10),outfile = testfit.run_id+'.pdf')
```
```python
params=testfit.params
logI_0 = np.log10(testfit.sbparams['I0'])
w =interactive(slidefitplot,modelfit=fixed(testfit),
beta_1=FloatSlider(min=0,max=1,step=0.01,value=params['beta_1'],description='beta_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
alpha=FloatSlider(min=0,max=1,step=0.01,value=params['alpha'],description='alpha',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
gamma_1=FloatSlider(min=0,max=0.5,step=0.002,value=params['gamma_1'],description='gamma_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
gamma_2=FloatSlider(min=0,max=0.5,step=0.002,value=params['gamma_2'],description='gamma_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
gamma_3=FloatSlider(min=0,max=0.5,step=0.002,value=params['gamma_3'],description='gamma_3',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
mu=FloatSlider(min=0,max=0.2,step=0.002,value=params['mu'],description='mu',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_0=FloatSlider(min=0,max=1,step=0.01,value=params['c_0'],description='c_0',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_1=FloatSlider(min=0,max=1,step=0.001,value=params['c_1'],description='c_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_2=FloatSlider(min=0,max=20000,step=1,value=params['c_2'],description='c_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.1f'),
logI_0=FloatSlider(min=-10,max=0,step=0.01,value=logI_0,description='log I_0',
style=style,layout=slider_layout,continuous_update=False),
k_u=FloatSlider(min=0,max=1,step=0.001,value=params['k_u'],description='k_u',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
k_1=FloatSlider(min=0,max=1,step=0.001,value=params['k_1'],description='k_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
k_w=FloatSlider(min=0,max=1,step=0.001,value=params['k_w'],description='k_w',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
kappa=FloatSlider(min=0,max=1,step=0.001,value=params['kappa'],description='kappa',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f')
)
display(w)
```
interactive(children=(FloatSlider(value=0.4, continuous_update=False, description='beta_1', layout=Layout(widt…
```python
from shutil import copyfile
```
```python
testfit.prparams(testfit.run_id+'.params')
paramfile = './params/'+testfit.run_id+'.pk'
copyfile(paramfile,testfit.run_id+'.pk')
```
'SC3UEI3R_Sweden_tst.pk'
# Data
## Oxford data
```python
owid_file = '../../covid-policy-tracker/data/OxCGRT_latest.csv'
oxdat = []
with open(owid_file,'r',newline='') as fp:
myreader = csv.DictReader(fp,delimiter=',')
# rows = list(itertools.islice(myreader,4))
for row in myreader:
oxdat.append(row)
```
```python
oxdat[0].keys()
```
odict_keys(['CountryName', 'CountryCode', 'RegionName', 'RegionCode', 'Date', 'C1_School closing', 'C1_Flag', 'C2_Workplace closing', 'C2_Flag', 'C3_Cancel public events', 'C3_Flag', 'C4_Restrictions on gatherings', 'C4_Flag', 'C5_Close public transport', 'C5_Flag', 'C6_Stay at home requirements', 'C6_Flag', 'C7_Restrictions on internal movement', 'C7_Flag', 'C8_International travel controls', 'E1_Income support', 'E1_Flag', 'E2_Debt/contract relief', 'E3_Fiscal measures', 'E4_International support', 'H1_Public information campaigns', 'H1_Flag', 'H2_Testing policy', 'H3_Contact tracing', 'H4_Emergency investment in healthcare', 'H5_Investment in vaccines', 'M1_Wildcard', 'ConfirmedCases', 'ConfirmedDeaths', 'StringencyIndex', 'StringencyIndexForDisplay', 'StringencyLegacyIndex', 'StringencyLegacyIndexForDisplay', 'GovernmentResponseIndex', 'GovernmentResponseIndexForDisplay', 'ContainmentHealthIndex', 'ContainmentHealthIndexForDisplay', 'EconomicSupportIndex', 'EconomicSupportIndexForDisplay'])
```python
countries = list(set([(dd['CountryName'],dd['CountryCode']) for dd in oxdat]))
```
```python
len(countries)
```
185
```python
[countries[i] for i in range(10)]
```
[('Saudi Arabia', 'SAU'),
('South Korea', 'KOR'),
('Greece', 'GRC'),
('Fiji', 'FJI'),
('Montserrat', 'MSR'),
('Ecuador', 'ECU'),
('Rwanda', 'RWA'),
('Romania', 'ROU'),
('Turks and Caicos Islands', 'TCA'),
('Slovak Republic', 'SVK')]
```python
dates = np.sort(list([dd['Date'] for dd in oxdat]))
dates_uniq = np.unique(dates)
dates_uniq
```
array(['20200101', '20200102', '20200103', '20200104', '20200105',
'20200106', '20200107', '20200108', '20200109', '20200110',
'20200111', '20200112', '20200113', '20200114', '20200115',
'20200116', '20200117', '20200118', '20200119', '20200120',
'20200121', '20200122', '20200123', '20200124', '20200125',
'20200126', '20200127', '20200128', '20200129', '20200130',
'20200131', '20200201', '20200202', '20200203', '20200204',
'20200205', '20200206', '20200207', '20200208', '20200209',
'20200210', '20200211', '20200212', '20200213', '20200214',
'20200215', '20200216', '20200217', '20200218', '20200219',
'20200220', '20200221', '20200222', '20200223', '20200224',
'20200225', '20200226', '20200227', '20200228', '20200229',
'20200301', '20200302', '20200303', '20200304', '20200305',
'20200306', '20200307', '20200308', '20200309', '20200310',
'20200311', '20200312', '20200313', '20200314', '20200315',
'20200316', '20200317', '20200318', '20200319', '20200320',
'20200321', '20200322', '20200323', '20200324', '20200325',
'20200326', '20200327', '20200328', '20200329', '20200330',
'20200331', '20200401', '20200402', '20200403', '20200404',
'20200405', '20200406', '20200407', '20200408', '20200409',
'20200410', '20200411', '20200412', '20200413', '20200414',
'20200415', '20200416', '20200417', '20200418', '20200419',
'20200420', '20200421', '20200422', '20200423', '20200424',
'20200425', '20200426', '20200427', '20200428', '20200429',
'20200430', '20200501', '20200502', '20200503', '20200504',
'20200505', '20200506', '20200507', '20200508', '20200509',
'20200510', '20200511', '20200512', '20200513', '20200514',
'20200515', '20200516', '20200517', '20200518', '20200519',
'20200520', '20200521', '20200522', '20200523', '20200524',
'20200525', '20200526', '20200527', '20200528', '20200529',
'20200530', '20200531', '20200601', '20200602', '20200603',
'20200604', '20200605', '20200606', '20200607', '20200608',
'20200609', '20200610', '20200611', '20200612', '20200613',
'20200614', '20200615', '20200616', '20200617', '20200618',
'20200619', '20200620', '20200621', '20200622', '20200623',
'20200624', '20200625', '20200626', '20200627', '20200628',
'20200629', '20200630', '20200701', '20200702', '20200703',
'20200704', '20200705', '20200706', '20200707', '20200708',
'20200709', '20200710', '20200711', '20200712', '20200713',
'20200714', '20200715', '20200716', '20200717', '20200718',
'20200719', '20200720', '20200721', '20200722', '20200723',
'20200724', '20200725', '20200726', '20200727', '20200728',
'20200729', '20200730', '20200731', '20200801', '20200802',
'20200803', '20200804', '20200805', '20200806', '20200807',
'20200808', '20200809', '20200810', '20200811', '20200812',
'20200813', '20200814', '20200815', '20200816', '20200817',
'20200818', '20200819', '20200820', '20200821', '20200822',
'20200823', '20200824', '20200825', '20200826', '20200827',
'20200828', '20200829', '20200830', '20200831'], dtype='<U8')
```python
foo = [(dd['Date'],dd['C1_School closing'],dd['C1_Flag']) for dd in oxdat if dd['CountryCode']=='USA']
```
```python
xx = foo[0:10]
print(xx)
xx=foo[-10:]
print(xx)
```
[('20200101', '0.00', ''), ('20200102', '0.00', ''), ('20200103', '0.00', ''), ('20200104', '0.00', ''), ('20200105', '0.00', ''), ('20200106', '0.00', ''), ('20200107', '0.00', ''), ('20200108', '0.00', ''), ('20200109', '0.00', ''), ('20200110', '0.00', '')]
[('20200822', '', ''), ('20200823', '', ''), ('20200824', '', ''), ('20200825', '', ''), ('20200826', '', ''), ('20200827', '', ''), ('20200828', '', ''), ('20200829', '', ''), ('20200830', '', ''), ('20200831', '', '')]
```python
ccodes = [cc[1] for cc in countries]
for cc in ccodes:
foo = [(dd['CountryCode'],dd['RegionName']) for dd in oxdat if dd['CountryCode'] == cc]
if len(set([x[1] for x in foo]))>1:
print(cc)
print( set([x[1] for x in foo]))
```
USA
{'', 'New Hampshire', 'California', 'Maryland', 'Tennessee', 'Rhode Island', 'Georgia', 'Louisiana', 'Virgin Islands', 'Arkansas', 'Washington', 'Iowa', 'Hawaii', 'Virginia', 'Colorado', 'Vermont', 'North Carolina', 'Oklahoma', 'West Virginia', 'Indiana', 'Delaware', 'Alaska', 'Idaho', 'Nebraska', 'Wyoming', 'Illinois', 'Texas', 'Missouri', 'New Jersey', 'Minnesota', 'South Dakota', 'Kentucky', 'New York', 'Ohio', 'North Dakota', 'Florida', 'Mississippi', 'Alabama', 'Montana', 'South Carolina', 'Wisconsin', 'Michigan', 'Washington DC', 'Oregon', 'Kansas', 'Connecticut', 'Maine', 'Arizona', 'New Mexico', 'Massachusetts', 'Nevada', 'Pennsylvania', 'Utah'}
GBR
{'', 'Wales', 'England', 'Northern Ireland', 'Scotland'}
```python
[cc for cc in countries if cc[1]=='USA']
```
[('United States', 'USA')]
```python
foo = [(dd['Date'],dd['C1_School closing'],dd['C1_Flag'])
for dd in oxdat if dd['CountryCode']=='USA']
fmt = '%Y%m%d'
first = 31+22-1
xx = [datetime.datetime.strptime(dd[0],fmt) for dd in foo][first:]
yy = []
for dd in foo[first:]:
try:
yy.append(float(dd[1]))
except:
yy.append(float('NaN'))
locator = mdates.MonthLocator()
formatter= mdates.ConciseDateFormatter(locator)
fig,ax = plt.subplots(1,1)
ax.step(xx,yy)
ax.xaxis.set_major_formatter(formatter)
ax.xaxis.set_major_locator(locator)
for tick in ax.get_xticklabels():
tick.set_rotation(40)
plt.title('USA')
plt.show()
```
Note: no wildcard data:
```python
foo = [(dd['Date'],dd['CountryCode'],dd['M1_Wildcard'])
for dd in oxdat if dd['M1_Wildcard'] != '']
```
```python
foo
```
[]
Notes:
* first version of `datcodes` leaves out all flags (general vs. targeted implementation)
* 2nd version leaves out all variables measured in dollars
```python
datcodes = ['C1_School closing', 'C2_Workplace closing',
'C3_Cancel public events', 'C4_Restrictions on gatherings',
'C5_Close public transport', 'C6_Stay at home requirements',
'C7_Restrictions on internal movement', 'C8_International travel controls',
'E1_Income support', 'E2_Debt/contract relief', 'E3_Fiscal measures',
'E4_International support', 'H1_Public information campaigns',
'H2_Testing policy', 'H3_Contact tracing',
'H4_Emergency investment in healthcare', 'H5_Investment in vaccines']
datcodes = ['C1_School closing', 'C2_Workplace closing',
'C3_Cancel public events', 'C4_Restrictions on gatherings',
'C5_Close public transport', 'C6_Stay at home requirements',
'C7_Restrictions on internal movement', 'C8_International travel controls',
'E1_Income support', 'E2_Debt/contract relief',
'H1_Public information campaigns',
'H2_Testing policy', 'H3_Contact tracing']
```
```python
countrycodes = list(set([dd['CountryCode'] for dd in oxdat if Float(dd['ConfirmedCases'])>10000]))
len(countrycodes)
```
90
```python
countriesox = list(set([dd['CountryName'] for dd in oxdat if Float(dd['ConfirmedCases'])>10000]))
```
```python
len(countriesox)
```
90
```python
def Float(x):
try:
rtn = float(x)
except:
rtn = float('NaN')
return rtn
```
```python
datcodes
```
['C1_School closing',
'C2_Workplace closing',
'C3_Cancel public events',
'C4_Restrictions on gatherings',
'C5_Close public transport',
'C6_Stay at home requirements',
'C7_Restrictions on internal movement',
'C8_International travel controls',
'E1_Income support',
'E2_Debt/contract relief',
'H1_Public information campaigns',
'H2_Testing policy',
'H3_Contact tracing']
```python
def get_codedat(countrycode='USA'):
codedat = []
foo = [[dd['Date']]+ [Float(dd[c]) for c in datcodes]
for dd in oxdat if dd['CountryCode']==countrycode]
return foo
```
```python
get_codedat()
```
[['20200101', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200102', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200103', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200104', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200105', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200106', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200107', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200108', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200109', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200110', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200111', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200112', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200113', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200114', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200115', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200116', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200117', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200118', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200119', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200120', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200121', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200122', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200123', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200124', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200125', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200126', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200127', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200128', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200129', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200130', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200131', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200201', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200202', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200203', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200204', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200205', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200206', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200207', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200208', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200209', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200210', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200211', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200212', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200213', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200214', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200215', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200216', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200217', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200218', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200219', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200220', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200221', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200222', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200223', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200224', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200225', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200226', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200227', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0],
['20200228', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200229', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200301', 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200302', 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200303', 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200304', 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 2.0, 1.0],
['20200305', 3.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 2.0, 1.0],
['20200306', 3.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 2.0, 1.0],
['20200307', 3.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 2.0, 1.0],
['20200308', 3.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 2.0, 1.0],
['20200309', 3.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 2.0, 1.0],
['20200310', 3.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 2.0, 1.0],
['20200311', 3.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 2.0, 1.0],
['20200312', 3.0, 0.0, 2.0, 2.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 2.0, 1.0],
['20200313', 3.0, 0.0, 2.0, 2.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 2.0, 1.0],
['20200314', 3.0, 0.0, 2.0, 2.0, 0.0, 0.0, 1.0, 3.0, 0.0, 0.0, 0.0, 3.0, 1.0],
['20200315', 3.0, 0.0, 2.0, 2.0, 0.0, 2.0, 1.0, 3.0, 0.0, 0.0, 0.0, 3.0, 1.0],
['20200316', 3.0, 0.0, 2.0, 2.0, 0.0, 2.0, 1.0, 3.0, 0.0, 0.0, 2.0, 3.0, 1.0],
['20200317', 3.0, 0.0, 2.0, 2.0, 1.0, 2.0, 1.0, 3.0, 0.0, 0.0, 2.0, 3.0, 1.0],
['20200318', 3.0, 0.0, 2.0, 2.0, 1.0, 2.0, 1.0, 3.0, 0.0, 0.0, 2.0, 3.0, 1.0],
['20200319', 3.0, 3.0, 2.0, 2.0, 1.0, 2.0, 2.0, 3.0, 0.0, 0.0, 2.0, 3.0, 1.0],
['20200320', 3.0, 3.0, 2.0, 2.0, 1.0, 2.0, 2.0, 3.0, 0.0, 0.0, 2.0, 3.0, 1.0],
['20200321', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 0.0, 0.0, 2.0, 3.0, 1.0],
['20200322', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 0.0, 0.0, 2.0, 3.0, 1.0],
['20200323', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 0.0, 0.0, 2.0, 3.0, 1.0],
['20200324', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 0.0, 0.0, 2.0, 3.0, 1.0],
['20200325', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 0.0, 0.0, 2.0, 3.0, 1.0],
['20200326', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 0.0, 0.0, 2.0, 3.0, 1.0],
['20200327', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200328', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200329', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200330', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200331', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200401', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200402', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200403', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200404', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200405', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200406', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200407', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200408', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200409', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200410', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200411', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200412', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200413', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200414', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200415', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200416', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200417', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200418', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200419', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200420', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200421', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200422', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200423', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200424', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200425', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200426', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200427', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200428', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200429', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200430', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200501', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200502', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200503', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200504', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200505', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200506', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200507', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200508', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200509', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200510', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200511', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200512', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200513', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200514', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200515', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200516', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200517', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200518', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200519', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200520', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200521', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200522', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200523', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200524', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200525', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200526', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200527', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200528', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200529', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200530', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200531', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200601', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200602', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200603', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200604', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200605', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200606', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200607', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200608', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200609', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200610', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200611', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200612', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200613', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200614', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200615', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200616', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200617', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200618', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200619', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200620', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200621', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200622', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200623', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200624', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200625', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200626', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200627', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200628', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200629', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200630', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200701', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200702', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200703', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200704', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200705', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200706', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200707', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200708', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200709', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200710', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200711', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200712', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200713', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200714', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200715', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200716', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200717', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200718', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200719', 3.0, 2.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200720', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200721', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200722', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200723', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200724', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200725', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200726', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200727', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200728', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200729', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200730', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200731', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200801', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200802', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200803', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200804', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200805', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200806', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200807', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200808', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200809', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200810', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200811', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200812', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200813', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200814', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200815', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200816', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200817', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200818', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200819', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200820', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200821', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200822', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200823', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200824', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200825', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200826', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200827', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200828', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200829', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200830', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200831', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200101', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200102', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200103', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200104', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200105', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200106', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200107', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200108', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
['20200109', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
['20200110', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
['20200111', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
['20200112', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
['20200113', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
['20200114', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
['20200115', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
['20200116', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
['20200117', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
['20200118', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
['20200119', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
['20200120', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
['20200121', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200122', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200123', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200124', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200125', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200126', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200127', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200128', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200129', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200130', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200131', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200201', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200202', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200203', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200204', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200205', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200206', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200207', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200208', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200209', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200210', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200211', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200212', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200213', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200214', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200215', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200216', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200217', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200218', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200219', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200220', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200221', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200222', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200223', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200224', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200225', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200226', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200227', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200228', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200229', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200301', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200302', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200303', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200304', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200305', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200306', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200307', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200308', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200309', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200310', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200311', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200312', 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 1.0, 2.0],
['20200313', 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 1.0, 2.0],
['20200314', 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 1.0, 2.0],
['20200315', 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 1.0, 2.0],
['20200316', 3.0, 2.0, 1.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 0.0, 2.0, 1.0, 2.0],
['20200317', 3.0, 2.0, 2.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 1.0, 2.0, 1.0, 2.0],
['20200318', 3.0, 2.0, 2.0, 3.0, 1.0, 0.0, 1.0, 3.0, 0.0, 1.0, 2.0, 1.0, 2.0],
['20200319', 3.0, 2.0, 2.0, 3.0, 1.0, 0.0, 1.0, 3.0, 0.0, 1.0, 2.0, 1.0, 2.0],
['20200320', 3.0, 2.0, 2.0, 3.0, 1.0, 0.0, 1.0, 3.0, 1.0, 2.0, 2.0, 1.0, 2.0],
['20200321', 3.0, 2.0, 2.0, 4.0, 1.0, 0.0, 1.0, 3.0, 1.0, 2.0, 2.0, 1.0, 2.0],
['20200322', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 1.0, 2.0, 2.0, 1.0, 2.0],
['20200323', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 1.0, 2.0, 2.0, 1.0, 2.0],
['20200324', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 1.0, 2.0, 2.0, 1.0, 2.0],
['20200325', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 1.0, 2.0, 2.0, 1.0, 2.0],
['20200326', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 1.0, 2.0, 2.0, 1.0, 2.0],
['20200327', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 2.0, 2.0, 1.0, 2.0],
['20200328', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 2.0, 2.0, 1.0, 2.0],
['20200329', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 2.0, 2.0, 1.0, 2.0],
['20200330', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 2.0, 2.0, 1.0, 2.0],
['20200331', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 2.0, 2.0, 1.0, 2.0],
['20200401', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 2.0, 2.0, 1.0, 2.0],
['20200402', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 2.0, 3.0, 2.0, 2.0, 2.0, 1.0, 2.0],
['20200403', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 2.0, 2.0, 1.0, 2.0],
['20200404', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 2.0, 2.0, 1.0, 2.0],
['20200405', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 2.0, 2.0, 1.0, 2.0],
['20200406', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 2.0, 2.0, 1.0, 2.0],
['20200407', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 2.0, 2.0, 1.0, 2.0],
['20200408', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 2.0, 2.0, 1.0, 2.0],
['20200409', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200410', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200411', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200412', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200413', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200414', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200415', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200416', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200417', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200418', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200419', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200420', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200421', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200422', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200423', 3.0, 3.0, 2.0, 4.0, 2.0, 2.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200424', 3.0, 2.0, 2.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200425', 3.0, 2.0, 2.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200426', 3.0, 2.0, 2.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200427', 3.0, 2.0, 2.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200428', 3.0, 2.0, 2.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200429', 3.0, 2.0, 2.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200430', 3.0, 2.0, 2.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200501', 3.0, 2.0, 2.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200502', 3.0, 2.0, 2.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200503', 3.0, 2.0, 2.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200504', 3.0, 2.0, 2.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200505', 3.0, 2.0, 2.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200506', 3.0, 2.0, 2.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200507', 3.0, 2.0, 2.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200508', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200509', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200510', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200511', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200512', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200513', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200514', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200515', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200516', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200517', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200518', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200519', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200520', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200521', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200522', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200523', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200524', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200525', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200526', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200527', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200528', 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200529', 3.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200530', 3.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200531', 3.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200601', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200602', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200603', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200604', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200605', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200606', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200607', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200608', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200609', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200610', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200611', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200612', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200613', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200614', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200615', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200616', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200617', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200618', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200619', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200620', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200621', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200622', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200623', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200624', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200625', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200626', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200627', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200628', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200629', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200630', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200701', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200702', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200703', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200704', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200705', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200706', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200707', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200708', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200709', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200710', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200711', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200712', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200713', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200714', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200715', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200716', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200717', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200718', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200719', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200720', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200721', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200722', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200723', 3.0, 1.0, 1.0, 2.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200724', 3.0, 1.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200725', 3.0, 1.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200726', 3.0, 1.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200727', 3.0, 1.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200728', 3.0, 1.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200729', 3.0, 1.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200730', 3.0, 1.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200731', 3.0, 1.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200801', 3.0, 1.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200802', 3.0, 1.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200803', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200804', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200805', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200806', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200807', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200808', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200809', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200810', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200811', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200812', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200813', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200814', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200815', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200816', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200817', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200818', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200819', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200820', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200821', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200822', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200823', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200824', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200825', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200826', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200827', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200828', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200829', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200830', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200831', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200101', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200102', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200103', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200104', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200105', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200106', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200107', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200108', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200109', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200110', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200111', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200112', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200113', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200114', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200115', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200116', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200117', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200118', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200119', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200120', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200121', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200122', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200123', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200124', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200125', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200126', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200127', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200128', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200129', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200130', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200131', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200201', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200202', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200203', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200204', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200205', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200206', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200207', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200208', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200209', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200210', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200211', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200212', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200213', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200214', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200215', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200216', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200217', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200218', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200219', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200220', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200221', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200222', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200223', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200224', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200225', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200226', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200227', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200228', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200229', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200301', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200302', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200303', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200304', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200305', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200306', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 2.0, 1.0],
['20200307', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 2.0, 1.0],
['20200308', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 2.0, 1.0],
['20200309', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 2.0, 1.0],
['20200310', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 2.0, 1.0],
['20200311', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 2.0, 1.0],
['20200312', 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 2.0, 1.0],
['20200313', 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 2.0, 1.0],
['20200314', 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 2.0, 1.0],
['20200315', 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 2.0, 2.0, 1.0],
['20200316', 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 3.0, 0.0, 0.0, 2.0, 2.0, 1.0],
['20200317', 1.0, 2.0, 2.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 0.0, 2.0, 2.0, 1.0],
['20200318', 1.0, 2.0, 2.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 0.0, 2.0, 2.0, 1.0],
['20200319', 2.0, 2.0, 2.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 0.0, 2.0, 2.0, 1.0],
['20200320', 3.0, 3.0, 2.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 0.0, 2.0, 2.0, 1.0],
['20200321', 3.0, 3.0, 2.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 0.0, 2.0, 2.0, 1.0],
['20200322', 3.0, 3.0, 2.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 0.0, 2.0, 2.0, 1.0],
['20200323', 3.0, 3.0, 2.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 0.0, 2.0, 2.0, 1.0],
['20200324', 3.0, 3.0, 2.0, 3.0, 1.0, 2.0, 1.0, 3.0, nan, 0.0, 2.0, 2.0, 1.0],
['20200325', 3.0, 3.0, 2.0, 3.0, 1.0, 2.0, 1.0, 3.0, 0.0, 0.0, 2.0, 2.0, 1.0],
['20200326', 3.0, 3.0, 2.0, 3.0, 1.0, 2.0, 1.0, 3.0, 0.0, 0.0, 2.0, 2.0, 1.0],
['20200327', 3.0, 3.0, 2.0, 3.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200328', 3.0, 3.0, 2.0, 3.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200329', 3.0, 3.0, 2.0, 3.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200330', 3.0, 3.0, 2.0, 3.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200331', 3.0, 3.0, 2.0, 3.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200401', 3.0, 3.0, 2.0, 3.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200402', 3.0, 3.0, 2.0, 3.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200403', 3.0, 3.0, 2.0, 3.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200404', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200405', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200406', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200407', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200408', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200409', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200410', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200411', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200412', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200413', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200414', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200415', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200416', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200417', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200418', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200419', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200420', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200421', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200422', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200423', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200424', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200425', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200426', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200427', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200428', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200429', 3.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200430', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200501', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200502', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200503', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200504', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200505', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200506', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200507', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200508', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200509', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200510', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200511', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200512', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200513', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200514', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200515', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200516', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200517', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200518', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200519', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200520', 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200521', 3.0, 2.0, 2.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200522', 3.0, 2.0, 2.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200523', 3.0, 2.0, 2.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200524', 3.0, 2.0, 2.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200525', 3.0, 2.0, 2.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200526', 3.0, 2.0, 2.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200527', 3.0, 2.0, 2.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200528', 3.0, 2.0, 2.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200529', 3.0, 2.0, 2.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200530', 3.0, 2.0, 2.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200531', 3.0, 2.0, 2.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200601', 2.0, 2.0, 2.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200602', 2.0, 2.0, 2.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200603', 2.0, 2.0, 2.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200604', 2.0, 2.0, 2.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 2.0],
['20200605', 2.0, 2.0, 2.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200606', 2.0, 2.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200607', 2.0, 2.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200608', 2.0, 2.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200609', 2.0, 2.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200610', 2.0, 2.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200611', 2.0, 2.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200612', 2.0, 2.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200613', 2.0, 2.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200614', 2.0, 2.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200615', 2.0, 2.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200616', 2.0, 2.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200617', 2.0, 2.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200618', 2.0, 2.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200619', 2.0, 2.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200620', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200621', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200622', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200623', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200624', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200625', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200626', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200627', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200628', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200629', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200630', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200701', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200702', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200703', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200704', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200705', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200706', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200707', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200708', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200709', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200710', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200711', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200712', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200713', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200714', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200715', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200716', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200717', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200718', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200719', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200720', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200721', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200722', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200723', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200724', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200725', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200726', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200727', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200728', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200729', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200730', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200731', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200801', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200802', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200803', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200804', 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200805', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200806', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200807', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200808', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200809', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200810', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200811', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200812', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200813', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200814', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200815', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200816', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200817', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200818', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200819', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200820', 2.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200821', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200822', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200823', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200824', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200825', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200826', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200827', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200828', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200829', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200830', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200831', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200101', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200102', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200103', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200104', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200105', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200106', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200107', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200108', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200109', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200110', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200111', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200112', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200113', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200114', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200115', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200116', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200117', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200118', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200119', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200120', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200121', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200122', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200123', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200124', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200125', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200126', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200127', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200128', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200129', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200130', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200131', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200201', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200202', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200203', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200204', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200205', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200206', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200207', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200208', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200209', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200210', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200211', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200212', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200213', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200214', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200215', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200216', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200217', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200218', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200219', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200220', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200221', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200222', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200223', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200224', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200225', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200226', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200227', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200228', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200229', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200301', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200302', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200303', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200304', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200305', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200306', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200307', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200308', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200309', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200310', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200311', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200312', 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200313', 1.0, 1.0, 1.0, 2.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200314', 1.0, 1.0, 1.0, 2.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200315', 1.0, 1.0, 1.0, 2.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 1.0, 1.0, 1.0],
['20200316', 1.0, 1.0, 1.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 0.0, 2.0, 1.0, 1.0],
['20200317', 3.0, 2.0, 1.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 1.0, 2.0, 1.0, 1.0],
['20200318', 3.0, 2.0, 1.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 1.0, 2.0, 1.0, 1.0],
['20200319', 3.0, 2.0, 1.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 1.0, 2.0, 1.0, 1.0],
['20200320', 3.0, 2.0, 1.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 1.0, 2.0, 1.0, 1.0],
['20200321', 3.0, 2.0, 1.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 1.0, 2.0, 1.0, 1.0],
['20200322', 3.0, 2.0, 1.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 1.0, 2.0, 1.0, 1.0],
['20200323', 3.0, 2.0, 1.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 1.0, 2.0, 1.0, 1.0],
['20200324', 3.0, 2.0, 1.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 1.0, 2.0, 1.0, 1.0],
['20200325', 3.0, 2.0, 1.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 1.0, 2.0, 1.0, 1.0],
['20200326', 3.0, 2.0, 1.0, 3.0, 0.0, 0.0, 1.0, 3.0, 0.0, 1.0, 2.0, 1.0, 1.0],
['20200327', 3.0, 2.0, 2.0, 4.0, 0.0, 0.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200328', 3.0, 2.0, 2.0, 4.0, 0.0, 0.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200329', 3.0, 2.0, 2.0, 4.0, 0.0, 0.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200330', 3.0, 2.0, 2.0, 4.0, 0.0, 0.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200331', 3.0, 2.0, 2.0, 4.0, 0.0, 0.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200401', 3.0, 2.0, 2.0, 4.0, 0.0, 0.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200402', 3.0, 2.0, 2.0, 4.0, 0.0, 0.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200403', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200404', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200405', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200406', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200407', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200408', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200409', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200410', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200411', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200412', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200413', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200414', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200415', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200416', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200417', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200418', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200419', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200420', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0],
['20200421', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200422', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200423', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200424', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200425', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200426', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200427', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200428', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200429', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200430', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200501', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200502', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200503', 3.0, 2.0, 2.0, 4.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200504', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200505', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200506', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200507', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200508', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200509', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200510', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200511', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200512', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200513', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200514', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0],
['20200515', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200516', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200517', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200518', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200519', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200520', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200521', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200522', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200523', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200524', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200525', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200526', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200527', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200528', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200529', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200530', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200531', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200601', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200602', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200603', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200604', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200605', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200606', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200607', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200608', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200609', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200610', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200611', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200612', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200613', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200614', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200615', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200616', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200617', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200618', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200619', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200620', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200621', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200622', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200623', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200624', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200625', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200626', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200627', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200628', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200629', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200630', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200701', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200702', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200703', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200704', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200705', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200706', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200707', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200708', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200709', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200710', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200711', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200712', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200713', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200714', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200715', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200716', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200717', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200718', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200719', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200720', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200721', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200722', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200723', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200724', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200725', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200726', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200727', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200728', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200729', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200730', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200731', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200801', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200802', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200803', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200804', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200805', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200806', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200807', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200808', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200809', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200810', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200811', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200812', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200813', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200814', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200815', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200816', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200817', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 1.0],
['20200818', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200819', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200820', 3.0, 2.0, 1.0, 3.0, 0.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0],
['20200821', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200822', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200823', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200824', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200825', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200826', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200827', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200828', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200829', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200830', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200831', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],
['20200101', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200102', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200103', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200104', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200105', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200106', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200107', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200108', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200109', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200110', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200111', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200112', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200113', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200114', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200115', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200116', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200117', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200118', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200119', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200120', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
['20200121', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200122', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200123', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
['20200124', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0],
...]
### Stringency
```python
[x for x in oxdat[0]]
```
['CountryName',
'CountryCode',
'RegionName',
'RegionCode',
'Date',
'C1_School closing',
'C1_Flag',
'C2_Workplace closing',
'C2_Flag',
'C3_Cancel public events',
'C3_Flag',
'C4_Restrictions on gatherings',
'C4_Flag',
'C5_Close public transport',
'C5_Flag',
'C6_Stay at home requirements',
'C6_Flag',
'C7_Restrictions on internal movement',
'C7_Flag',
'C8_International travel controls',
'E1_Income support',
'E1_Flag',
'E2_Debt/contract relief',
'E3_Fiscal measures',
'E4_International support',
'H1_Public information campaigns',
'H1_Flag',
'H2_Testing policy',
'H3_Contact tracing',
'H4_Emergency investment in healthcare',
'H5_Investment in vaccines',
'M1_Wildcard',
'ConfirmedCases',
'ConfirmedDeaths',
'StringencyIndex',
'StringencyIndexForDisplay',
'StringencyLegacyIndex',
'StringencyLegacyIndexForDisplay',
'GovernmentResponseIndex',
'GovernmentResponseIndexForDisplay',
'ContainmentHealthIndex',
'ContainmentHealthIndexForDisplay',
'EconomicSupportIndex',
'EconomicSupportIndexForDisplay']
```python
country='DEU'
reg = '' # to get entire country for UK, USA
foo = [(dd['Date'],dd['StringencyIndex'],dd['C1_Flag'])
for dd in oxdat if dd['CountryCode']==country and dd['RegionName']==reg]
fmt_ox = '%Y%m%d'
first = 31+22-1 # to get to Feb 22 where data starts
xx = [datetime.datetime.strptime(dd[0],fmt_ox) for dd in foo][first:]
yy = []
for dd in foo[first:]:
try:
yy.append(float(dd[1]))
except:
yy.append(float('NaN'))
locator = mdates.MonthLocator()
formatter= mdates.ConciseDateFormatter(locator)
fig,ax = plt.subplots(1,1)
ax.step(xx,yy)
ax.xaxis.set_major_formatter(formatter)
ax.xaxis.set_major_locator(locator)
for tick in ax.get_xticklabels():
tick.set_rotation(40)
plt.title(country+' Stringency')
plt.show()
```
```python
print("number of countries",len(countrycodes))
```
number of countries 90
```python
def get_stringency(country,to_database='jhu'):
global fmt_jhu,fmt_ox,fmt_owid,dates_jhu,dates_owid
stri = [(dd['Date'],dd['StringencyIndex'],dd['C1_Flag'])
for dd in oxdat if dd['CountryName']==country and dd['RegionName']=='']
fmt_ox = '%Y%m%d'
#first = 31+22-1 # to get to Feb 22 where data starts
dates_t = [datetime.datetime.strptime(dd[0],fmt_ox) for dd in stri]
if to_database=='jhu':
fmt = fmt_jhu
dates = dates_jhu
elif to_database=='owid':
fmt = fmt_jhu # already converted from fmt_owid
dates = dates_owid
print('first date',dates[0],'last date',dates[-1])
firstdate = datetime.datetime.strptime(dates[0],fmt)
lastdate = datetime.datetime.strptime(dates[-1],fmt)
ndates=len(dates)
daystart = (dates_t[0]-firstdate).days
#dates = [date.strftime(fmt_jhu) for date in dates_t]
yy = np.zeros((lastdate-firstdate).days+1)
for i,dd in enumerate(stri):
if daystart+i < len(dates):
try:
yy[daystart+i]=float(dd[1])
except:
yy[daystart+i]=float('NaN')
return([dates,yy])
```
```python
stri = get_stringency('Germany',to_database='jhu')
plt.plot([datetime.datetime.strptime(date,fmt_jhu) for date in stri[0]],stri[1]);
```
```python
stri = get_stringency('Germany')
datesf = [datetime.datetime.strptime(date,fmt_jhu) for date in stri[0]]
plt.figure(figsize=(12,12))
plt.plot(datesf,np.array(stri[1])/100.,label='Germany');
stri = get_stringency('Spain')
plt.plot(datesf,np.array(stri[1])/100.,label='Spain');
stri = get_stringency('Italy')
plt.plot(datesf,np.array(stri[1])/100.,label='Italy');
stri = get_stringency('United States')
plt.plot(datesf,np.array(stri[1])/100.,label='United States');
plt.legend()
```
```python
import matplotlib.dates as mdates
```
```python
max_rows=12
max_cols=8
idx = 0
fig, axes = plt.subplots(nrows=max_rows, ncols=max_cols, figsize=(20,40))
fig.autofmt_xdate()
for idx, country in enumerate(countriesox):
foo = get_stringency(country)
row = idx // max_cols
col = idx % max_cols
axes[row, col].set_ylim((0,110))
axes[row, col].xaxis.set_major_locator(plt.MaxNLocator(3))
axes[row, col].fmt_xdata = mdates.DateFormatter('%Y-%m-%d')
axes[row, col].plot(foo[0],foo[1])
axes[row, col].set_title(country)
for idx in range(len(countriesox),max_rows*max_cols):
row = idx // max_cols
col = idx % max_cols
axes[row, col].axis("off")
```
```python
len(countriesox)
```
90
```python
import pickle as pk
```
```python
dicstringency={}
for cc in countriesox:
foo = get_stringency(cc)
dicstringency[cc] = [x[1] for x in foo] # skip date
dates = [x[0] for x in foo]
stringency={}
stringency['dates'] = dates
stringency['data'] = dicstringency
pk.dump(stringency,open('stringency.pk','wb'))
```
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
first date 1/22/20 last date 8/30/20
## Plots of data for Cautionary Model comparison
Comment out line 1110 in pwlf.py (in /usr/local/lib/python3.7/site-packages/pwlf directory)
print("Warning: zero length interval encountered in pwlf.py calc_slopes").
to remove repeated warnings, which don't seem to harm final result
Warning: zero length interval encountered in pwlf.py calc_slopes
```python
plotCountry_(['Italy','Spain','Germany','France','United Kingdom','Sweden','Turkey'],
'confirmed','cum_av_weekly',firstdate='02/15/20',lastdate='09/1/20',fittype='piecewise-linear',nsegments=4)
if savefigs:
plt.savefig("covid-19-caution/figures/fig1a.pdf",bbox_inches='tight')
```
```python
plotCountry_(['Italy','Spain','Germany','France','United Kingdom','Sweden','Turkey'],
'confirmed','daily_av_weekly',firstdate='02/15/20',lastdate='08/31/20',database='jhu')
if savefigs:
plt.savefig("covid-19-caution/figures/fig1b.pdf",bbox_inches='tight')
```
```python
plotCountry_(['Italy','Spain','Germany','France','United Kingdom','Sweden','Turkey'],
'confirmed','daily_av_weekly',firstdate='02/15/20',lastdate='08/31/20',database='owid')
if savefigs:
plt.savefig("covid-19-caution/figures/fig1b_owid.pdf",bbox_inches='tight')
```
# Parameter fitting
## Fitting via sliders
### SC3EIR Model
```python
len(t)
```
```python
model = 'SC3EIR'
params={'beta':0.25,'alpha':1./5.,'gamma':0.1,'mu':0.05,'c_0':0.3, 'c_1':1/14., 'c_2':2000}
def slidefitplot(beta,alpha,gamma,mu,c_0,c_1,c_2,logI_0):
params={ 'beta':beta, 'alpha':alpha, 'gamma':gamma, 'mu':mu, 'c_0':c_0, 'c_1':c_1, 'c_2':c_2}
cmodels[model].parameters = params
I0 = 10**logI_0
x0 = [1.-I0,0.,I0,0.,0.,0.,0.,0.]
cmodels[model].initial_values = (x0,t[0])
solveplot(smodels=[model],species=['confirmed','recovered','deaths'],tmax=len(t),summing='daily',fitdata=y_jhu[test_country],scale='linear',plottitle= '',label='confirmed',newplot = True)
```
```python
interact(slidefitplot,
beta=FloatSlider(min=0,max=1,step=0.01,value=params['beta'],description='beta',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
alpha=FloatSlider(min=0,max=1,step=0.01,value=params['alpha'],description='alpha',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
gamma=FloatSlider(min=0,max=1,step=0.01,value=params['gamma'],description='gamma',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
mu=FloatSlider(min=0,max=0.2,step=0.002,value=params['mu'],description='mu',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_0=FloatSlider(min=0,max=1,step=0.01,value=params['c_0'],description='c_0',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_1=FloatSlider(min=0,max=1,step=0.001,value=params['c_1'],description='c_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_2=FloatSlider(min=0,max=5000,step=1,value=params['c_2'],description='c_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.1f'),
logI_0=FloatSlider(min=-10,max=0,step=0.01,value=-6,description='log I_0',
style=style,layout=slider_layout,continuous_update=False))
```
### SC3EI3R Model
#### Germany
```python
# assumed data starting on firstdate
test_country='Germany'
N = 80000000
firstdate = '01/25/20'
lastdate = '01/08/20'
xx,xxf,yy0 = get_country_data(test_country,'confirmed',firstdate=firstdate,lastdate=lastdate)
xx,xxf,yy1 = get_country_data(test_country,'recovered',firstdate=firstdate,lastdate=lastdate)
xx,xxf,yy2 = get_country_data(test_country,'deaths',firstdate=firstdate,lastdate=lastdate)
print(xxf)
y_jhu={}
y_jhu[test_country] = np.array([[yy0[i],yy1[i],yy2[i]] for i in range(0,len(yy0))])/N
# data = np.array([[xxf[i],yy0[i],yy1[i],yy2[i]] for i in range(len(yy))])
# print(data)
lastday = len(y_jhu[test_country])
print('days 0 to',lastday,'data stored in y_jhu')
```
```python
len(t)
```
```python
(1.0/TimeICUDeath)*(CFR/FracCritical)
```
```python
model = 'SC3EI3R'
# Define parameters based on clinical observations Dr. Alison
Exposure=0.4 # Rate coefficient for exposure per individual in contact per day
IncubPeriod=5 #Incubation period, days
DurMildInf=10 #Duration of mild infections, days : includes time for reg. of recovery
FracMild=0.7 #Fraction of infections that are mild
FracSevere=0.20 #Fraction of infections that are severe
FracCritical=0.1 #Fraction of infections that are critical
CFR=0.05 #Case fatality rate (fraction of infections resulting in death)
TimeICUDeath=5 #Time from ICU admission to death, days
DurHosp=4 #Duration of hospitalization, days : includes 4 day reg of recovery
# Model fitting extension to allow for incomplete detection
FracConfirmedDet=1.0 # Fraction of recovered individuals measured : plots made with this parameter NYI
FracRecoveredDet=FracConfirmedDet # Fraction of recovered individuals measured
FracDeathsDet=1.0
# Model extension by John McCaskill to include caution
CautionFactor= 0.1 # Fractional reduction of exposure rate for cautioned individuals
CautionRetention= 60. # Duration of cautionary state of susceptibles (2 weeks)
CautionICUFrac= 0.1 # Fraction of ICUs occupied leading to transition to caution @ 1/day
ICUFrac= 0.001 # Fraction of ICUs relative to population size N
params = {'beta_1' : Exposure/sum(x0_SC3EI3R),
'beta_2' : 0.0,
'beta_3' : 0.0,
'alpha' : 1.0/IncubPeriod,
'gamma_1': (1.0/DurMildInf)*FracMild,
'gamma_2': (1.0/DurHosp)-(1/DurHosp)*(FracCritical/(FracCritical+FracSevere)),
'gamma_3': (1.0/TimeICUDeath)-(1/TimeICUDeath)*(CFR/FracCritical),
'p_1' : (1.0/DurMildInf)-(1.0/DurMildInf)*FracMild,
'p_2' : (1.0/DurHosp)*(FracCritical/(FracCritical+FracSevere)),
'mu' : (1.0/TimeICUDeath)*(CFR/FracCritical),
'c_0' : CautionFactor,
'c_1' : 1.0/CautionRetention,
'c_2' : 1.0/(sum(x0_SC3EI3R)*ICUFrac*CautionICUFrac),
'N' : sum(x0_SC3EI3R)}
print(params)
SC3EI3R_model.parameters = params
def slidefitplot(beta_1,mu,c_0,c_1,c_2,logI_0):
params={ 'beta_1':beta_1, 'mu':mu, 'c_0':c_0, 'c_1':c_1, 'c_2':c_2}
cmodels[model].parameters = params
I0 = 10**logI_0
x0 = [1.-I0,0.,I0,0.,0.,0.,0.,0.,0.,0.]
cmodels[model].initial_values = (x0,t[0])
weights=np.array([1.,1.,1.])
solveplot(smodels=[model],species=['confirmed','recovered','deaths_x10'],tmax=len(t),summing='daily',averaging='weekly',fitdata=y_jhu[test_country]*weights,scale='linear',plottitle= '',label='confirmed',newplot = True, figsize = (15,15))
```
```python
w =interactive(slidefitplot,
beta_1=FloatSlider(min=0,max=1,step=0.01,value=params['beta_1'],description='beta_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
mu=FloatSlider(min=0,max=0.2,step=0.002,value=params['mu'],description='mu',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_0=FloatSlider(min=0,max=1,step=0.01,value=params['c_0'],description='c_0',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_1=FloatSlider(min=0,max=1,step=0.001,value=params['c_1'],description='c_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_2=FloatSlider(min=0,max=20000,step=1,value=params['c_2'],description='c_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.1f'),
logI_0=FloatSlider(min=-10,max=0,step=0.01,value=-6,description='log I_0',
style=style,layout=slider_layout,continuous_update=False)
)
display(w)
```
```python
params=w.kwargs
print(params)
```
```python
```
#### Spain
```python
# assumed data starting on firstdate
test_country='Spain'
N = 80000000
firstdate = '01/25/20'
lastdate = '01/08/20'
xx,xxf,yy0 = get_country_data(test_country,'confirmed',firstdate=firstdate,lastdate=lastdate)
xx,xxf,yy1 = get_country_data(test_country,'recovered',firstdate=firstdate,lastdate=lastdate)
xx,xxf,yy2 = get_country_data(test_country,'deaths',firstdate=firstdate,lastdate=lastdate)
print(xxf)
y_jhu={}
y_jhu[test_country] = np.array([[yy0[i],yy1[i],yy2[i]] for i in range(0,len(yy0))])/N
# data = np.array([[xxf[i],yy0[i],yy1[i],yy2[i]] for i in range(len(yy))])
# print(data)
lastday = len(y_jhu[test_country])
print('days 0 to',lastday,'data stored in y_jhu')
```
```python
len(t)
```
```python
(1.0/TimeICUDeath)*(CFR/FracCritical)
```
```python
model = 'SC3EI3R'
# Define parameters based on clinical observations Dr. Alison
Exposure=0.4 # Rate coefficient for exposure per individual in contact per day
IncubPeriod=5 #Incubation period, days
DurMildInf=10 #Duration of mild infections, days : includes time for reg. of recovery
FracMild=0.7 #Fraction of infections that are mild
FracSevere=0.20 #Fraction of infections that are severe
FracCritical=0.1 #Fraction of infections that are critical
CFR=0.05 #Case fatality rate (fraction of infections resulting in death)
TimeICUDeath=5 #Time from ICU admission to death, days
DurHosp=4 #Duration of hospitalization, days : includes 4 day reg of recovery
# Model fitting extension to allow for incomplete detection
FracConfirmedDet=0.5 # Fraction of confirmed individuals measured : plots made with this parameter NYI
FracRecoveredDet=FracConfirmedDet # Fraction of recovered individuals measured
FracDeathsDet=1.0
# Model extension by John McCaskill to include caution
CautionFactor= 0.1 # Fractional reduction of exposure rate for cautioned individuals
CautionRetention= 60. # Duration of cautionary state of susceptibles (2 weeks)
CautionICUFrac= 0.1 # Fraction of ICUs occupied leading to transition to caution @ 1/day
ICUFrac= 0.001 # Fraction of ICUs relative to population size N
params = {'beta_1' : Exposure/sum(x0_SC3EI3R),
'beta_2' : 0.0,
'beta_3' : 0.0,
'alpha' : 1.0/IncubPeriod,
'gamma_1': (1.0/DurMildInf)*FracMild,
'gamma_2': (1.0/DurHosp)-(1/DurHosp)*(FracCritical/(FracCritical+FracSevere)),
'gamma_3': (1.0/TimeICUDeath)-(1/TimeICUDeath)*(CFR/FracCritical),
'p_1' : (1.0/DurMildInf)-(1.0/DurMildInf)*FracMild,
'p_2' : (1.0/DurHosp)*(FracCritical/(FracCritical+FracSevere)),
'mu' : (1.0/TimeICUDeath)*(CFR/FracCritical),
'c_0' : CautionFactor,
'c_1' : 1.0/CautionRetention,
'c_2' : 1.0/(sum(x0_SC3EI3R)*ICUFrac*CautionICUFrac),
'N' : sum(x0_SC3EI3R)}
print(params)
SC3EI3R_model.parameters = params
def slidefitplot(beta_1,mu,c_0,c_1,c_2,logI_0):
params={ 'beta_1':beta_1, 'mu':mu, 'c_0':c_0, 'c_1':c_1, 'c_2':c_2}
cmodels[model].parameters = params
I0 = 10**logI_0
x0 = [1.-I0,0.,I0,0.,0.,0.,0.,0.,0.,0.]
cmodels[model].initial_values = (x0,t[0])
weights=np.array([1.,1.,1.])
solveplot(smodels=[model],species=['confirmed','recovered','deaths_x10'],tmax=len(t),summing='daily',averaging='weekly',fitdata=y_jhu[test_country]*weights,scale='linear',plottitle= '',label='confirmed',newplot = True, figsize = (15,15))
```
```python
w =interactive(slidefitplot,
beta_1=FloatSlider(min=0,max=1,step=0.01,value=params['beta_1'],description='beta_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
mu=FloatSlider(min=0,max=0.2,step=0.002,value=params['mu'],description='mu',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_0=FloatSlider(min=0,max=1,step=0.01,value=params['c_0'],description='c_0',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_1=FloatSlider(min=0,max=1,step=0.001,value=params['c_1'],description='c_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_2=FloatSlider(min=0,max=20000,step=1,value=params['c_2'],description='c_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.1f'),
logI_0=FloatSlider(min=-10,max=0,step=0.01,value=-6,description='log I_0',
style=style,layout=slider_layout,continuous_update=False)
)
display(w)
```
```python
params=w.kwargs
print(params)
```
#### Italy
```python
# assumed data starting on firstdate
test_country='Italy'
N = 66650000
firstdate = '01/25/20'
lastdate = '01/08/20'
xx,xxf,yy0 = get_country_data(test_country,'confirmed',firstdate=firstdate,lastdate=lastdate)
xx,xxf,yy1 = get_country_data(test_country,'recovered',firstdate=firstdate,lastdate=lastdate)
xx,xxf,yy2 = get_country_data(test_country,'deaths',firstdate=firstdate,lastdate=lastdate)
print(xxf)
y_jhu={}
y_jhu[test_country] = np.array([[yy0[i],yy1[i],yy2[i]] for i in range(0,len(yy0))])/N
# data = np.array([[xxf[i],yy0[i],yy1[i],yy2[i]] for i in range(len(yy))])
# print(data)
lastday = len(y_jhu[test_country])
print('days 0 to',lastday,'data stored in y_jhu')
```
```python
model = 'SC3EI3R'
# Define parameters based on clinical observations Dr. Alison
Exposure=0.4 # Rate coefficient for exposure per individual in contact per day
IncubPeriod=5 #Incubation period, days
DurMildInf=8 #Duration of mild infections, days
FracMild=0.65 #Fraction of infections that are mild
FracSevere=0.20 #Fraction of infections that are severe
FracCritical=0.15 #Fraction of infections that are critical
CFR=0.1 #Case fatality rate (fraction of infections resulting in death)
TimeICUDeath=4 #Time from ICU admission to death, days
DurHosp=4 #Duration of hospitalization, days
# Model fitting extension to allow for incomplete detection
FracConfirmedDet=0.5 # Fraction of infected individuals confirmed
FracRecoveredDet=FracConfirmedDet # Fraction of recovered individuals measured
FracDeathsDet=1.0
# Model extension by John McCaskill to include caution
CautionFactor= 0.1 # Fractional reduction of exposure rate for cautioned individuals
CautionRetention= 60. # Duration of cautionary state of susceptibles (2 weeks)
CautionICUFrac= 0.1 # Fraction of ICUs occupied leading to transition to caution @ 1/day
ICUFrac= 0.001 # Fraction of ICUs relative to population size N
params = {'beta_1' : Exposure/sum(x0_SC3EI3R),
'beta_2' : 0.0,
'beta_3' : 0.0,
'alpha' : 1.0/IncubPeriod,
'gamma_1': (1.0/DurMildInf)*FracMild,
'gamma_2': (1.0/DurHosp)-(1/DurHosp)*(FracCritical/(FracCritical+FracSevere)),
'gamma_3': (1.0/TimeICUDeath)-(1/TimeICUDeath)*(CFR/FracCritical),
'p_1' : (1.0/DurMildInf)-(1.0/DurMildInf)*FracMild,
'p_2' : (1.0/DurHosp)*(FracCritical/(FracCritical+FracSevere)),
'mu' : (1.0/TimeICUDeath)*(CFR/FracCritical),
'c_0' : CautionFactor,
'c_1' : 1.0/CautionRetention,
'c_2' : 1.0/(sum(x0_SC3EI3R)*ICUFrac*CautionICUFrac),
'N' : sum(x0_SC3EI3R)}
print(params)
SC3EI3R_model.parameters = params
def slidefitplot(beta_1,mu,c_0,c_1,c_2,logI_0):
params={ 'beta_1':beta_1, 'mu':mu, 'c_0':c_0, 'c_1':c_1, 'c_2':c_2}
cmodels[model].parameters = params
I0 = 10**logI_0
x0 = [1.-I0,0.,I0,0.,0.,0.,0.,0.,0.,0.]
cmodels[model].initial_values = (x0,t[0])
weights=np.array([1.,1.,1.])
solveplot(smodels=[model],species=['confirmed','recovered','deaths_x10'],tmax=len(t),summing='daily',averaging='weekly',fitdata=y_jhu[test_country]*weights,scale='linear',plottitle= '',label='confirmed',newplot = True, figsize = (15,15))
```
```python
w =interactive(slidefitplot,
beta_1=FloatSlider(min=0,max=1,step=0.01,value=params['beta_1'],description='beta_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
mu=FloatSlider(min=0,max=0.2,step=0.002,value=params['mu'],description='mu',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_0=FloatSlider(min=0,max=1,step=0.01,value=params['c_0'],description='c_0',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_1=FloatSlider(min=0,max=1,step=0.001,value=params['c_1'],description='c_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_2=FloatSlider(min=0,max=20000,step=1,value=params['c_2'],description='c_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.1f'),
logI_0=FloatSlider(min=-10,max=0,step=0.01,value=-6,description='log I_0',
style=style,layout=slider_layout,continuous_update=False)
)
display(w)
```
```python
params=w.kwargs
print(params)
```
Note that we have used 50% detection of confirmed and recovered, 100% for deaths in manual fit.
It appears that Italy's registration of recovery, although the right overall magnitude is markedly delayed - check reporting delays.
Italy also had at least two successive regional infections, as seen in the dual peak confirmed data, so not easy to fit with one model.
See below for simulation of second peak.
```python
w =interactive(slidefitplot,
beta_1=FloatSlider(min=0,max=1,step=0.01,value=params['beta_1'],description='beta_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
mu=FloatSlider(min=0,max=0.2,step=0.002,value=params['mu'],description='mu',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_0=FloatSlider(min=0,max=1,step=0.01,value=params['c_0'],description='c_0',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_1=FloatSlider(min=0,max=1,step=0.001,value=params['c_1'],description='c_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_2=FloatSlider(min=0,max=20000,step=1,value=params['c_2'],description='c_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.1f'),
logI_0=FloatSlider(min=-10,max=0,step=0.01,value=-6,description='log I_0',
style=style,layout=slider_layout,continuous_update=False)
)
display(w)
```
#### Brazil
```python
# assumed data starting on firstdate
test_country='Brazil'
N = 210000000
firstdate = '01/25/20'
lastdate = '01/08/20'
xx,xxf,yy0 = get_country_data(test_country,'confirmed',firstdate=firstdate,lastdate=lastdate)
xx,xxf,yy1 = get_country_data(test_country,'recovered',firstdate=firstdate,lastdate=lastdate)
xx,xxf,yy2 = get_country_data(test_country,'deaths',firstdate=firstdate,lastdate=lastdate)
print(xxf)
y_jhu={}
y_jhu[test_country] = np.array([[yy0[i],yy1[i],yy2[i]] for i in range(0,len(yy0))])/N
# data = np.array([[xxf[i],yy0[i],yy1[i],yy2[i]] for i in range(len(yy))])
# print(data)
lastday = len(y_jhu[test_country])
print('days 0 to',lastday,'data stored in y_jhu')
```
```python
model = 'SC3EI3R'
# Define parameters based on clinical observations Dr. Alison
Exposure=0.4 # Rate coefficient for exposure per individual in contact per day
IncubPeriod=5 #Incubation period, days
DurMildInf=8 #Duration of mild infections, days
FracMild=0.65 #Fraction of infections that are mild
FracSevere=0.20 #Fraction of infections that are severe
FracCritical=0.15 #Fraction of infections that are critical
CFR=0.1 #Case fatality rate (fraction of infections resulting in death)
TimeICUDeath=4 #Time from ICU admission to death, days
DurHosp=8 #Duration of hospitalization, days
# Model fitting extension to allow for incomplete detection
FracConfirmedDet=0. # Fraction of recovered individuals measured
FracRecoveredDet=FracConfirmedDet # Fraction of recovered individuals measured
FracDeathsDet=1.0
# Model extension by John McCaskill to include caution
CautionFactor= 0.1 # Fractional reduction of exposure rate for cautioned individuals
CautionRetention= 60. # Duration of cautionary state of susceptibles (2 weeks)
CautionICUFrac= 0.1 # Fraction of ICUs occupied leading to transition to caution @ 1/day
ICUFrac= 0.001 # Fraction of ICUs relative to population size N
params = {'beta_1' : Exposure/sum(x0_SC3EI3R),
'beta_2' : 0.0,
'beta_3' : 0.0,
'alpha' : 1.0/IncubPeriod,
'gamma_1': (1.0/DurMildInf)*FracMild,
'gamma_2': (1.0/DurHosp)-(1/DurHosp)*(FracCritical/(FracCritical+FracSevere)),
'gamma_3': (1.0/TimeICUDeath)-(1/TimeICUDeath)*(CFR/FracCritical),
'p_1' : (1.0/DurMildInf)-(1.0/DurMildInf)*FracMild,
'p_2' : (1.0/DurHosp)*(FracCritical/(FracCritical+FracSevere)),
'mu' : (1.0/TimeICUDeath)*(CFR/FracCritical),
'c_0' : CautionFactor,
'c_1' : 1.0/CautionRetention,
'c_2' : 1.0/(sum(x0_SC3EI3R)*ICUFrac*CautionICUFrac),
'N' : sum(x0_SC3EI3R)}
print(params)
SC3EI3R_model.parameters = params
def slidefitplot(beta_1,mu,c_0,c_1,c_2,logI_0):
params={ 'beta_1':beta_1, 'mu':mu, 'c_0':c_0, 'c_1':c_1, 'c_2':c_2}
cmodels[model].parameters = params
I0 = 10**logI_0
x0 = [1.-I0,0.,I0,0.,0.,0.,0.,0.,0.,0.]
cmodels[model].initial_values = (x0,t[0])
weights=np.array([1.,1.,1.])
solveplot(smodels=[model],species=['confirmed','recovered','deaths_x10'],tmax=len(t),summing='cumulative',averaging='weekly',fitdata=y_jhu[test_country]*weights,scale='linear',plottitle= '',label='confirmed',newplot = True, figsize = (15,15))
```
```python
w =interactive(slidefitplot,
beta_1=FloatSlider(min=0,max=1,step=0.01,value=params['beta_1'],description='beta_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
mu=FloatSlider(min=0,max=0.2,step=0.002,value=params['mu'],description='mu',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_0=FloatSlider(min=0,max=1,step=0.01,value=params['c_0'],description='c_0',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_1=FloatSlider(min=0,max=1,step=0.001,value=params['c_1'],description='c_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_2=FloatSlider(min=0,max=20000,step=1,value=params['c_2'],description='c_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.1f'),
logI_0=FloatSlider(min=-10,max=0,step=0.01,value=-6,description='log I_0',
style=style,layout=slider_layout,continuous_update=False)
)
display(w)
```
The Brazil data shows that death is not as delayed as assumed. The process of progression is perhaps less clearly documented.
#### Russia
```python
# assumed data starting on firstdate
test_country='Iran'
N = 144500000
firstdate = '01/25/20'
lastdate = '01/08/20'
xx,xxf,yy0 = get_country_data(test_country,'confirmed',firstdate=firstdate,lastdate=lastdate)
xx,xxf,yy1 = get_country_data(test_country,'recovered',firstdate=firstdate,lastdate=lastdate)
xx,xxf,yy2 = get_country_data(test_country,'deaths',firstdate=firstdate,lastdate=lastdate)
print(xxf)
y_jhu={}
y_jhu[test_country] = np.array([[yy0[i],yy1[i],yy2[i]] for i in range(0,len(yy0))])/N
# data = np.array([[xxf[i],yy0[i],yy1[i],yy2[i]] for i in range(len(yy))])
# print(data)
lastday = len(y_jhu[test_country])
print('days 0 to',lastday,'data stored in y_jhu')
```
```python
model = 'SC3EI3R'
# Define parameters based on clinical observations Dr. Alison
Exposure=0.4 # Rate coefficient for exposure per individual in contact per day
IncubPeriod=5 #Incubation period, days
DurMildInf=8 #Duration of mild infections, days
FracMild=0.65 #Fraction of infections that are mild
FracSevere=0.20 #Fraction of infections that are severe
FracCritical=0.15 #Fraction of infections that are critical
CFR=0.1 #Case fatality rate (fraction of infections resulting in death)
TimeICUDeath=4 #Time from ICU admission to death, days
DurHosp=8 #Duration of hospitalization, days
# Model fitting extension to allow for incomplete detection
FracConfirmedDet=0. # Fraction of recovered individuals measured
FracRecoveredDet=FracConfirmedDet # Fraction of recovered individuals measured
FracDeathsDet=1.0
# Model extension by John McCaskill to include caution
CautionFactor= 0.1 # Fractional reduction of exposure rate for cautioned individuals
CautionRetention= 60. # Duration of cautionary state of susceptibles (2 weeks)
CautionICUFrac= 0.1 # Fraction of ICUs occupied leading to transition to caution @ 1/day
ICUFrac= 0.002 # Fraction of ICUs relative to population size N
params = {'beta_1' : Exposure/sum(x0_SC3EI3R),
'beta_2' : 0.0,
'beta_3' : 0.0,
'alpha' : 1.0/IncubPeriod,
'gamma_1': (1.0/DurMildInf)*FracMild,
'gamma_2': (1.0/DurHosp)-(1/DurHosp)*(FracCritical/(FracCritical+FracSevere)),
'gamma_3': (1.0/TimeICUDeath)-(1/TimeICUDeath)*(CFR/FracCritical),
'p_1' : (1.0/DurMildInf)-(1.0/DurMildInf)*FracMild,
'p_2' : (1.0/DurHosp)*(FracCritical/(FracCritical+FracSevere)),
'mu' : (1.0/TimeICUDeath)*(CFR/FracCritical),
'c_0' : CautionFactor,
'c_1' : 1.0/CautionRetention,
'c_2' : 1.0/(sum(x0_SC3EI3R)*ICUFrac*CautionICUFrac),
'N' : sum(x0_SC3EI3R)}
print(params)
SC3EI3R_model.parameters = params
def slidefitplot(beta_1,mu,c_0,c_1,c_2,logI_0):
params={ 'beta_1':beta_1, 'mu':mu, 'c_0':c_0, 'c_1':c_1, 'c_2':c_2}
cmodels[model].parameters = params
I0 = 10**logI_0
x0 = [1.-I0,0.,I0,0.,0.,0.,0.,0.,0.,0.]
cmodels[model].initial_values = (x0,t[0])
weights=np.array([1.,1.,1.])
solveplot(smodels=[model],species=['confirmed','recovered','deaths_x10'],tmax=len(t),summing='cumulative',averaging='weekly',fitdata=y_jhu[test_country]*weights,scale='linear',plottitle= '',label='confirmed',newplot = True, figsize = (15,15))
```
```python
w =interactive(slidefitplot,
beta_1=FloatSlider(min=0,max=1,step=0.01,value=params['beta_1'],description='beta_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
mu=FloatSlider(min=0,max=0.2,step=0.002,value=params['mu'],description='mu',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_0=FloatSlider(min=0,max=1,step=0.01,value=params['c_0'],description='c_0',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_1=FloatSlider(min=0,max=1,step=0.001,value=params['c_1'],description='c_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_2=FloatSlider(min=0,max=20000,step=1,value=params['c_2'],description='c_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.1f'),
logI_0=FloatSlider(min=-10,max=0,step=0.01,value=-6,description='log I_0',
style=style,layout=slider_layout,continuous_update=False)
)
display(w)
```
### SC3UEIR Model
```python
# assumed data starting on firstdate
test_country='US'
N = 66650000
firstdate = '01/25/20'
lastdate = '01/08/20'
xx,xxf,yy0 = get_country_data(test_country,'confirmed',firstdate=firstdate,lastdate=lastdate)
xx,xxf,yy1 = get_country_data(test_country,'recovered',firstdate=firstdate,lastdate=lastdate)
xx,xxf,yy2 = get_country_data(test_country,'deaths',firstdate=firstdate,lastdate=lastdate)
print(xxf)
y_jhu={}
y_jhu[test_country] = np.array([[yy0[i],yy1[i],yy2[i]] for i in range(0,len(yy0))])/N
# data = np.array([[xxf[i],yy0[i],yy1[i],yy2[i]] for i in range(len(yy))])
# print(data)
lastday = len(y_jhu[test_country])
print('days 0 to',lastday,'data stored in y_jhu')
```
```python
model = 'SC3UEIR'
I_0 = 0.00003
x0_SC3UEIR = [1.0-I_0, 0.0, I_0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]
SC3UEIR_model.initial_values = (x0_SC3UEIR, t[0])
# Define parameters based on clinical observations Dr. Alison
Exposure=0.4 # Rate coefficient for exposure per individual in contact per day
IncubPeriod=5 #Incubation period, days
DurMildInf=8 #Duration of mild infections, days
FracMild=0.65 #Fraction of infections that are mild
FracSevere=0.20 #Fraction of infections that are severe
FracCritical=0.15 #Fraction of infections that are critical
CFR=0.1 #Case fatality rate (fraction of infections resulting in death)
TimeICUDeath=4 #Time from ICU admission to death, days
DurHosp=8 #Duration of hospitalization, days
# Model fitting extension to allow for incomplete detection
FracConfirmedDet=0.5 # Fraction of recovered individuals measured
FracRecoveredDet=FracConfirmedDet # Fraction of recovered individuals measured
FracDeathsDet=1.0
# Model extension by John McCaskill to include caution
CautionFactor= 0.1 # Fractional reduction of exposure rate for cautioned individuals
CautionRetention= 60. # Duration of cautionary state of susceptibles (2 weeks)
CautionICUFrac= 0.1 # Fraction of ICUs occupied leading to transition to caution @ 1/day
ICUFrac= 0.001 # Fraction of ICUs relative to population size N
# Model extension by John McCaskill to include economic influence on caution
EconomicCostOfCaution= 0.5 # Fractional reduction of economic contribution for cautioned individuals
p = [0,(1.0/DurMildInf)-(1.0/DurMildInf)*FracMild, (1.0/DurHosp)*(FracCritical/(FracCritical+FracSevere))]
g = [0,(1.0/DurMildInf)*FracMild, (1.0/DurHosp)-(1/DurHosp)*(FracCritical/(FracCritical+FracSevere)),
(1.0/TimeICUDeath)-(1/TimeICUDeath)*(CFR/FracCritical)]
u = (1.0/TimeICUDeath)*(CFR/FracCritical)
params = {'beta' : Exposure/sum(x0_SC3UEIR),
'alpha' : 1.0/IncubPeriod,
'gamma' : g[1]+g[2]*(p[1]/(g[2]+p[2]))+g[3]*(p[1]/(g[2]+p[2]))*(p[2]/(g[3]+u)),
'mu' : u*(p[1]/(g[2]+p[2])*(p[2]/(g[3]+u))),
'c_0' : CautionFactor,
'c_1' : 1.0/CautionRetention,
'c_2' : 1.0/(sum(x0_SC3UEIR)*ICUFrac*CautionICUFrac),
'N' : sum(x0_SC3UEIR),
'k_u' : 1.0/CautionRetention,
'k_1' : 1.0/CautionRetention,
'k_w' : 1.0/CautionRetention,
'kappa' : EconomicCostOfCaution}
print(params)
SC3UEIR_model.parameters = params.copy()
# solution = SCIR_model.integrate(t[1::])
def slidefitplot(beta,alpha,gamma,mu,c_0,c_1,c_2,logI_0,k_u,k_1,k_w,kappa):
params={ 'beta':beta, 'alpha':alpha, 'gamma':gamma, 'mu':mu, 'c_0':c_0, 'c_1':c_1, 'c_2':c_2, 'k_u':k_u, 'k_1':k_1, 'k_w':k_w, 'kappa':kappa}
cmodels[model].parameters = params
I0 = 10**logI_0
x0 = [1.-I0,0.,I0,0.,0.,0.,0.,0.,0.,1.]
cmodels[model].initial_values = (x0,t[0])
weights=np.array([1.,1.,1.])
solveplot(smodels=[model],species=['confirmed','recovered','deaths_x10'],tmax=len(t),summing='daily',averaging='weekly',fitdata=y_jhu[test_country]*weights,scale='linear',plottitle= '',label='confirmed',newplot = True, figsize = (15,15))
```
```python
w = interactive(slidefitplot,
beta=FloatSlider(min=0,max=1,step=0.01,value=params['beta'],description='beta',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
alpha=FloatSlider(min=0,max=1,step=0.01,value=params['alpha'],description='alpha',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
gamma=FloatSlider(min=0,max=1,step=0.01,value=params['gamma'],description='gamma',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
mu=FloatSlider(min=0,max=0.2,step=0.002,value=params['mu'],description='mu',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_0=FloatSlider(min=0,max=1,step=0.01,value=params['c_0'],description='c_0',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_1=FloatSlider(min=0,max=1,step=0.001,value=params['c_1'],description='c_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_2=FloatSlider(min=0,max=5000,step=1,value=params['c_2'],description='c_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.1f'),
logI_0=FloatSlider(min=-10,max=0,step=0.01,value=-6,description='log I_0',
style=style,layout=slider_layout,continuous_update=False),
k_u=FloatSlider(min=0,max=1,step=0.001,value=params['k_u'],description='k_u',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
k_1=FloatSlider(min=0,max=1,step=0.001,value=params['k_1'],description='k_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
k_w=FloatSlider(min=0,max=1,step=0.001,value=params['k_w'],description='k_w',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
kappa=FloatSlider(min=0,max=1,step=0.001,value=params['kappa'],description='kappa',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'))
display(w)
```
```python
params=w.kwargs
# not a good fit yet, did better last week
print(params)
```
### SC3UEI3R Model
#### USA
```python
# assumed data starting on firstdate
test_country='US'
N = 66650000
firstdate = '01/25/20'
lastdate = '01/08/20'
xx,xxf,yy0 = get_country_data(test_country,'confirmed',firstdate=firstdate,lastdate=lastdate)
xx,xxf,yy1 = get_country_data(test_country,'recovered',firstdate=firstdate,lastdate=lastdate)
xx,xxf,yy2 = get_country_data(test_country,'deaths',firstdate=firstdate,lastdate=lastdate)
print(xxf)
y_jhu={}
y_jhu[test_country] = np.array([[yy0[i],yy1[i],yy2[i]] for i in range(0,len(yy0))])/N
# data = np.array([[xxf[i],yy0[i],yy1[i],yy2[i]] for i in range(len(yy))])
# print(data)
lastday = len(y_jhu[test_country])
print('days 0 to',lastday,'data stored in y_jhu')
```
```python
model = 'SC3UEI3R'
I_0 = 0.00003
x0_SC3UEI3R = [1.0-I_0, 0.0, I_0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]
SC3UEI3R_model.initial_values = (x0_SC3UEI3R, t[0])
# Define parameters based on clinical observations Dr. Alison
Exposure=0.4 # Rate coefficient for exposure per individual in contact per day
IncubPeriod=5 #Incubation period, days
DurMildInf=8 #Duration of mild infections, days
FracMild=0.65 #Fraction of infections that are mild
FracSevere=0.20 #Fraction of infections that are severe
FracCritical=0.15 #Fraction of infections that are critical
CFR=0.1 #Case fatality rate (fraction of infections resulting in death)
TimeICUDeath=4 #Time from ICU admission to death, days
DurHosp=5 #Duration of hospitalization, days
# Model fitting extension to allow for incomplete detection
FracConfirmedDet=0.5 # Fraction of recovered individuals measured
FracRecoveredDet=FracConfirmedDet # Fraction of recovered individuals measured
FracDeathsDet=1.0
# Model extension by John McCaskill to include caution
CautionFactor= 0.1 # Fractional reduction of exposure rate for cautioned individuals
CautionRetention= 60. # Duration of cautionary state of susceptibles (2 weeks)
CautionICUFrac= 0.1 # Fraction of ICUs occupied leading to transition to caution @ 1/day
ICUFrac= 0.001 # Fraction of ICUs relative to population size N
# Model extension by John McCaskill to include economic influence on caution
EconomicCostOfCaution= 0.5 # Fractional reduction of economic contribution for cautioned individuals
p = [0,(1.0/DurMildInf)-(1.0/DurMildInf)*FracMild, (1.0/DurHosp)*(FracCritical/(FracCritical+FracSevere))]
g = [0,(1.0/DurMildInf)*FracMild, (1.0/DurHosp)-(1/DurHosp)*(FracCritical/(FracCritical+FracSevere)),
(1.0/TimeICUDeath)-(1/TimeICUDeath)*(CFR/FracCritical)]
u = (1.0/TimeICUDeath)*(CFR/FracCritical)
params = {'beta_1' : Exposure/sum(x0_SC3UEI3R),
'beta_2' : 0.0,
'beta_3' : 0.0,
'alpha' : 1.0/IncubPeriod,
'gamma_1': (1.0/DurMildInf)*FracMild,
'gamma_2': (1.0/DurHosp)-(1/DurHosp)*(FracCritical/(FracCritical+FracSevere)),
'gamma_3': (1.0/TimeICUDeath)-(1/TimeICUDeath)*(CFR/FracCritical),
'p_1' : (1.0/DurMildInf)-(1.0/DurMildInf)*FracMild,
'p_2' : (1.0/DurHosp)*(FracCritical/(FracCritical+FracSevere)),
'mu' : (1.0/TimeICUDeath)*(CFR/FracCritical),
'c_0' : CautionFactor,
'c_1' : 1.0/CautionRetention,
'c_2' : 1.0/(ICUFrac*CautionICUFrac),
'k_u' : 1.0/5.,
'k_1' : 1.0/90,
'k_w' : 1.0/90,
'kappa' : EconomicCostOfCaution,
'N' : sum(x0_SC3UEI3R)}
print(params)
SC3UEI3R_model.parameters = params.copy()
```
```python
def slidefitplot(beta_1,alpha,mu,c_0,c_1,c_2,logI_0,k_u,k_1,k_w,kappa):
params={ 'beta_1':beta_1, 'alpha':alpha, 'mu':mu, 'c_0':c_0, 'c_1':c_1, 'c_2':c_2, 'k_u':k_u, 'k_1':k_1, 'k_w':k_w, 'kappa':kappa}
cmodels[model].parameters = params
I0 = 10**logI_0
x0 = [1.-I0,0.,I0,0.,0.,0.,0.,0.,0.,0.,0.,1.]
cmodels[model].initial_values = (x0,t[0])
weights=np.array([1.,1.,1.])
solveplot(smodels=[model],species=['confirmed','recovered','deaths_x10'],tmax=len(t),summing='daily',averaging='weekly',fitdata=y_jhu[test_country]*weights,scale='linear',plottitle= '',label='confirmed',newplot = True, figsize = (15,15))
```
```python
w=interactive(slidefitplot,
beta_1=FloatSlider(min=0,max=1,step=0.01,value=params['beta_1'],description='beta_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
alpha=FloatSlider(min=0,max=1,step=0.01,value=params['alpha'],description='alpha',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
mu=FloatSlider(min=0,max=0.2,step=0.002,value=params['mu'],description='mu',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_0=FloatSlider(min=0,max=1,step=0.01,value=params['c_0'],description='c_0',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_1=FloatSlider(min=0,max=1,step=0.001,value=params['c_1'],description='c_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_2=FloatSlider(min=0,max=5000,step=1,value=params['c_2'],description='c_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.1f'),
logI_0=FloatSlider(min=-10,max=0,step=0.01,value=-6,description='log I_0',
style=style,layout=slider_layout,continuous_update=False),
k_u=FloatSlider(min=0,max=1,step=0.001,value=params['k_u'],description='k_u',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
k_1=FloatSlider(min=0,max=1,step=0.001,value=params['k_1'],description='k_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
k_w=FloatSlider(min=0,max=1,step=0.001,value=params['k_w'],description='k_w',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
kappa=FloatSlider(min=0,max=1,step=0.001,value=params['kappa'],description='kappa',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'))
display(w)
```
```python
params=w.kwargs
print(params)
```
#### Spain
```python
# assumed data starting on firstdate
test_country='Spain'
N = 66650000
firstdate = '01/25/20'
lastdate = '01/08/20'
xx,xxf,yy0 = get_country_data(test_country,'confirmed',firstdate=firstdate,lastdate=lastdate)
xx,xxf,yy1 = get_country_data(test_country,'recovered',firstdate=firstdate,lastdate=lastdate)
xx,xxf,yy2 = get_country_data(test_country,'deaths',firstdate=firstdate,lastdate=lastdate)
print(xxf)
y_jhu={}
y_jhu[test_country] = np.array([[yy0[i],yy1[i],yy2[i]] for i in range(0,len(yy0))])/N
# data = np.array([[xxf[i],yy0[i],yy1[i],yy2[i]] for i in range(len(yy))])
# print(data)
lastday = len(y_jhu[test_country])
print('days 0 to',lastday,'data stored in y_jhu')
```
```python
model = 'SC3UEI3R'
I_0 = 0.00003
x0_SC3UEI3R = [1.0-I_0, 0.0, I_0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]
SC3UEI3R_model.initial_values = (x0_SC3UEI3R, t[0])
# Define parameters based on clinical observations Dr. Alison
Exposure=0.4 # Rate coefficient for exposure per individual in contact per day
IncubPeriod=5 #Incubation period, days
DurMildInf=8 #Duration of mild infections, days
FracMild=0.65 #Fraction of infections that are mild
FracSevere=0.20 #Fraction of infections that are severe
FracCritical=0.15 #Fraction of infections that are critical
CFR=0.1 #Case fatality rate (fraction of infections resulting in death)
TimeICUDeath=4 #Time from ICU admission to death, days
DurHosp=5 #Duration of hospitalization, days
# Model fitting extension to allow for incomplete detection
FracConfirmedDet=0.5 # Fraction of recovered individuals measured
FracRecoveredDet=FracConfirmedDet # Fraction of recovered individuals measured
FracDeathsDet=1.0
# Model extension by John McCaskill to include caution
CautionFactor= 0.1 # Fractional reduction of exposure rate for cautioned individuals
CautionRetention= 60. # Duration of cautionary state of susceptibles (2 weeks)
CautionICUFrac= 0.1 # Fraction of ICUs occupied leading to transition to caution @ 1/day
ICUFrac= 0.001 # Fraction of ICUs relative to population size N
# Model extension by John McCaskill to include economic influence on caution
EconomicCostOfCaution= 0.5 # Fractional reduction of economic contribution for cautioned individuals
p = [0,(1.0/DurMildInf)-(1.0/DurMildInf)*FracMild, (1.0/DurHosp)*(FracCritical/(FracCritical+FracSevere))]
g = [0,(1.0/DurMildInf)*FracMild, (1.0/DurHosp)-(1/DurHosp)*(FracCritical/(FracCritical+FracSevere)),
(1.0/TimeICUDeath)-(1/TimeICUDeath)*(CFR/FracCritical)]
u = (1.0/TimeICUDeath)*(CFR/FracCritical)
params = {'beta_1' : Exposure/sum(x0_SC3UEI3R),
'beta_2' : 0.0,
'beta_3' : 0.0,
'alpha' : 1.0/IncubPeriod,
'gamma_1': (1.0/DurMildInf)*FracMild,
'gamma_2': (1.0/DurHosp)-(1/DurHosp)*(FracCritical/(FracCritical+FracSevere)),
'gamma_3': (1.0/TimeICUDeath)-(1/TimeICUDeath)*(CFR/FracCritical),
'p_1' : (1.0/DurMildInf)-(1.0/DurMildInf)*FracMild,
'p_2' : (1.0/DurHosp)*(FracCritical/(FracCritical+FracSevere)),
'mu' : (1.0/TimeICUDeath)*(CFR/FracCritical),
'c_0' : CautionFactor,
'c_1' : 1.0/CautionRetention,
'c_2' : 1.0/(ICUFrac*CautionICUFrac),
'k_u' : 1.0/5.,
'k_1' : 1.0/90,
'k_w' : 1.0/90,
'kappa' : EconomicCostOfCaution,
'N' : sum(x0_SC3UEI3R)}
print(params)
SC3UEI3R_model.parameters = params.copy()
```
```python
def slidefitplot(beta_1,alpha,mu,c_0,c_1,c_2,logI_0,k_u,k_1,k_w,kappa):
params={ 'beta_1':beta_1, 'alpha':alpha, 'mu':mu, 'c_0':c_0, 'c_1':c_1, 'c_2':c_2, 'k_u':k_u, 'k_1':k_1, 'k_w':k_w, 'kappa':kappa}
cmodels[model].parameters = params
I0 = 10**logI_0
x0 = [1.-I0,0.,I0,0.,0.,0.,0.,0.,0.,0.,0.,1.]
cmodels[model].initial_values = (x0,t[0])
weights=np.array([1.,1.,1.])
solveplot(smodels=[model],species=['confirmed','recovered','deaths_x10'],tmax=len(t),summing='daily',averaging='weekly',fitdata=y_jhu[test_country]*weights,scale='linear',plottitle= '',label='confirmed',newplot = True, figsize = (15,15))
```
```python
w=interactive(slidefitplot,
beta_1=FloatSlider(min=0,max=1,step=0.01,value=params['beta_1'],description='beta_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
alpha=FloatSlider(min=0,max=1,step=0.01,value=params['alpha'],description='alpha',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
mu=FloatSlider(min=0,max=0.2,step=0.002,value=params['mu'],description='mu',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_0=FloatSlider(min=0,max=1,step=0.01,value=params['c_0'],description='c_0',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_1=FloatSlider(min=0,max=1,step=0.001,value=params['c_1'],description='c_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
c_2=FloatSlider(min=0,max=5000,step=1,value=params['c_2'],description='c_2',
style=style,layout=slider_layout,continuous_update=False,readout_format='.1f'),
logI_0=FloatSlider(min=-10,max=0,step=0.01,value=-6,description='log I_0',
style=style,layout=slider_layout,continuous_update=False),
k_u=FloatSlider(min=0,max=1,step=0.001,value=params['k_u'],description='k_u',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
k_1=FloatSlider(min=0,max=1,step=0.001,value=params['k_1'],description='k_1',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
k_w=FloatSlider(min=0,max=1,step=0.001,value=params['k_w'],description='k_w',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'),
kappa=FloatSlider(min=0,max=1,step=0.001,value=params['kappa'],description='kappa',
style=style,layout=slider_layout,continuous_update=False,readout_format='.3f'))
display(w)
```
```python
params=w.kwargs
print(params)
```
## Fit SC3EI3R parameters to jhu data based on square_loss
### Fit c_0 , c_1 and c_2 as well as initial value of I_1
```python
SC3EI3R_model.parameters
```
```python
SC3EI3R_model.parameters = {'beta_1': 0.4, 'beta_2': 0.0, 'beta_3': 0.0, 'alpha': 0.2, 'gamma_1': 0.06999999999999999, 'gamma_2': 0.16666666666666669, 'gamma_3': 0.1, 'p_1': 0.030000000000000013, 'p_2': 0.08333333333333333, 'mu': 0.1, 'c_0': 0.1, 'c_1': 0.016666666666666666, 'c_2': 10000.0, 'N': 1.0}
```
```python
# Initial guess of parameters and initial condition, and bounding constraints
I0 =10**-7
x0_SC3EI3R = [1.-I0,0.,I0,0.,0.,0.,0.,0.,0.,0.]
SC3EI3R_model.parameters={'beta_1': 0.41, 'mu': 0.1, 'c_0': 0.1, 'c_1': 0.0166, 'c_2': 10000.0}
cautionparams = list(params.values())[-4:-1]
theta = [0.3,0.0167,10000.] # cautionparams
boxBounds = [(0.3,0.5),(0.01,0.02),(6000.,12000.)]
# set up optimization function with cost and sensitivity (Jacobian)
objSC3EI3R = SquareLoss(theta=theta, ode=SC3EI3R_model, x0=x0_SC3EI3R, t0=t[0], t=t[1::], y=y_jhu[test_country][1::,1:],
state_weight=[1.,10.],state_name=['R','D'],
target_param=['c_0','c_1','c_2'],target_state=['I_1'])
# perform optimization
res = minimize(fun=objSC3EI3R.costIV,
jac=objSC3EI3R.sensitivityIV,
x0=theta+[I0],
bounds=boxBounds+[(0.00000001,0.000001)],
#method='BFGS',
method='SLSQP',
#options={'disp':True,'maxiter':1000,'eps':0.01,'gtol':0.01})
#options={'disp':True})
options={'disp':True,'maxiter':1000,'eps':0.0001,'ftol':0.000001})
print(res)
```
```python
# model with fitted parameters
print(params)
print(x0_SC3EI3R)
params_fit = params.copy()
params_fit['c_0'] = res.x[0]
params_fit['c_1'] = res.x[1]
params_fit['c_2'] = res.x[2]
SC3EI3R_model.params = params_fit
print(SC3EI3R_model.params)
#ode_fit = common_models.SEI3R({'beta':res.x[0], 'gamma':res.x[1],'alpha':res.x[2]})
#x0_fit = [1-1.27e-6, 1.27e-6, 0]
x0_fit = x0_SC3EI3R.copy()
x0_fit[2] = res.x[3]
t_fit = np.linspace(0, 150, 1000)
#t_fit = t
SC3EI3R_model.initial_values = (x0_fit, t_fit[0])
# %timeit sol_fit =SCEI3R_model.integrate(t_fit[1::]) # use magic %timeit to time
# sol_fit =SCEI3R_model.integrate(t_fit[0::])
sol_fit = scipy.integrate.odeint(SC3EI3R_model.ode, x0_fit, t_fit[1::])
#
plt.figure(figsize=(15,10))
#plt.plot(t[1::],y_jhu[test_country][1::,0], 'o',color='lightgreen') # infected observations
plt.plot(t[1::],y_jhu[test_country][1::,1], 'bo') # recovered
plt.plot(t[1::],10*y_jhu[test_country][1::,2], 'ro') # died x10
plt.plot(t_fit[1::], sol_fit[::,SC3EI3R_model.recovered]) # R
plt.plot(t_fit[1::], 10*sol_fit[::,SC3EI3R_model.deaths]) # D x10
#plt.ylim([0,0.004])
#plt.show(())
#ode_fit.plot()
peak_i = np.argmax(sol_fit[:,2])
print('Peak infection (days)', t_fit[peak_i])
```
## Testing fitting
### Generate test data based on SCEI3R simulation
```python
# Add noise
y = solution[:,2:7].copy()
#print('len(y)',len(y),'t',len(t),t[0],t[1],'...',t[-1])
np.random.seed(seed=6)
noise = np.random.normal(0,1.e-2,[len(t),5])
# ynoise = y *(1+noise)
ynoise = y *(1.0 + noise)
ynoise[ynoise<0] = 0
plt.figure(figsize=(15,10))
plt.plot(t,ynoise[:,0], 'go', label='I_1')
plt.plot(t,ynoise[:,1], 'go', label='I_2')
plt.plot(t,ynoise[:,2], 'go', label='I_3')
plt.plot(t,ynoise[:,3], 'bo', label='R')
plt.plot(t,ynoise[:,4], 'ro', label='D')
plt.plot(t,y[:,0], 'g', label='I_1')
plt.plot(t,y[:,1], 'g', label='I_2')
plt.plot(t,y[:,2], 'g', label='I_3')
plt.plot(t,y[:,3], 'b', label='R')
plt.plot(t,y[:,4], 'r', label='D')
plt.legend()
plt.ylim(0,0.003)
plt.show()
```
```python
# model with generating parameters
print(params)
params_fit = params.copy()
print(params_fit['c_0'],params_fit['c_1'])
SCEI3R_model.params = params_fit
x0_fit = x0_SCEI3R.copy()
print(x0_fit)
#t_fit = numpy.linspace(0, 150, 1000)
t_fit = t
SCEI3R_model.initial_values = (x0_fit, t_fit[0])
# %timeit sol_fit =SCEI3R_model.integrate(t_fit[1::]) # use magic %timeit to time
sol_fit = scipy.integrate.odeint(SCEI3R_model.ode, x0_fit, t_fit[1::])
# print(len(sol_fit[0]))
#
plt.figure(figsize=(15,10))
plt.plot(t,ynoise[:,0], 'go',label='I_1') # infected observations
plt.plot(t,ynoise[:,1], 'go',label='I_2') # infected observations
plt.plot(t,ynoise[:,2], 'go',label='I_3') # infected observations
plt.plot(t,ynoise[:,3], 'bo',label='R') # recoverd
plt.plot(t,ynoise[:,4], 'ro',label='D') # died
plt.gca().set_prop_cycle(color=['grey','orange','green','green','green','blue','red', 'black'])
plt.plot(t_fit[1::], sol_fit)
plt.ylim([0,0.004])
plt.legend()
#plt.show(())
#ode_fit.plot()
peak_i = np.argmax(sol_fit[:,2])
print('Peak infection (days)', t_fit[peak_i])
```
```python
params # use list(...) to convert to list
```
### Fit parameters to randomized simulation data based on square_loss
#### Fit c_0 and c_1 only
```python
# Initial guess of parameters, and bounding constraints
cautionparams = list(params.values())[-4:-2]
theta = [value for value in cautionparams]
theta = [0.21,0.08]
boxBounds = [(0.2,0.4),(0.05,0.15)]
objSCEI3R = SquareLoss(theta=theta, ode=SCEI3R_model, x0=x0_SCEI3R, t0=t[0], t=t[1::], y=ynoise[1::,:],
state_weight=[1.,1.,1.,1.0,10.0],state_name=['I_1','I_2','I_3','R','D'],
target_param=['c_0','c_1'])
# perform optimization
res = minimize(fun=objSCEI3R.cost,
jac=objSCEI3R.sensitivity,
x0=theta,
#bounds=boxBounds,
method='BFGS',
options={'disp':True,'maxiter':1000,'eps':0.0001})# ,'ftol':0.01}) #not BFGS
print(res)
```
#### Fit c_0 and c_1 as well as initial value of E
##### Fit c_0 and c_1 as well as initial value of E with 'SLSQP'
does not work well
note use of special methods IV for initial value fitting of target_state
```python
# Initial guess of parameters and initial condition, and bounding constraints
cautionparams = list(params.values())[-4:-2]
theta = [0.25,0.08]
boxBounds = [(0.2,0.4),(0.05,0.15)]
objSCEI3R = SquareLoss(theta=theta, ode=SCEI3R_model, x0=x0_SCEI3R, t0=t[0], t=t[1::], y=ynoise[1::,:],
state_weight=[1.,1.,1.,1.,1.],state_name=['I_1','I_2','I_3','R','D'],
target_param=['c_0','c_1'],target_state=['E'])
# perform optimization
res = minimize(fun=objSCEI3R.costIV,
jac=objSCEI3R.sensitivityIV,
x0=theta+[0.00005],
#bounds=boxBounds+[(0.0000001,0.001)],
method='SLSQP',
options={'disp':True,'maxiter':1000,'eps':0.01,'ftol':0.01})
print(res)
```
##### Fit c_0 and c_1 as well as initial value of E with BFGS
works well: no constraints and gtol not ftol
```python
# Initial guess of parameters and initial condition, and bounding constraints
cautionparams = list(params.values())[-4:-2]
theta = [0.25,0.08]
boxBounds = [(0.2,0.4),(0.05,0.15)]
objSCEI3R = SquareLoss(theta=theta, ode=SCEI3R_model, x0=x0_SCEI3R, t0=t[0], t=t[1::], y=ynoise[1::,:],
state_weight=[1.,1.,1.,1.,1.],state_name=['I_1','I_2','I_3','R','D'],
target_param=['c_0','c_1'],target_state=['E'])
# perform optimization
res = minimize(fun=objSCEI3R.costIV,
jac=objSCEI3R.sensitivityIV,
x0=theta+[0.00005],
#bounds=boxBounds+[(0.0000001,0.001)],
method='BFGS',
options={'disp':True,'maxiter':1000,'eps':0.01,'gtol':0.01})
print(res)
```
```python
# model with fitted parameters
print(params)
print(x0_SCEI3R)
params_fit = params.copy()
#params_fit['c_0'] = res.x[0]
#params_fit['c_1'] = res.x[1]
SCEI3R_model.params = params_fit
print(SCEI3R_model.params)
#ode_fit = common_models.SEI3R({'beta':res.x[0], 'gamma':res.x[1],'alpha':res.x[2]})
#x0_fit = [1-1.27e-6, 1.27e-6, 0]
x0_fit = x0.copy()
#x0_fit[2] = res.x[2]
#t_fit = numpy.linspace(0, 150, 1000)
t_fit = t
SCEI3R_model.initial_values = (x0_fit, t_fit[0])
# %timeit sol_fit =SCEI3R_model.integrate(t_fit[1::]) # use magic %timeit to time
# sol_fit =SCEI3R_model.integrate(t_fit[0::])
sol_fit = scipy.integrate.odeint(SCEI3R_model.ode, x0_fit, t_fit[1::])
#
plt.figure(figsize=(15,10))
plt.plot(t,ynoise[:,0], 'go') # infected observations
plt.plot(t,ynoise[:,1], 'go') # infected observations
plt.plot(t,ynoise[:,2], 'go') # infected observations
plt.plot(t,ynoise[:,3], 'bo') # recoverd
plt.plot(t,ynoise[:,4], 'ro') # died
plt.plot(t_fit[1::], sol_fit)
plt.ylim([0,0.004])
#plt.show(())
#ode_fit.plot()
peak_i = np.argmax(sol_fit[:,2])
print('Peak infection (days)', t_fit[peak_i])
```
##### Fit c_0 and c_1 as well as initial value of E using L-BFGS-B
this method does not work well
```python
# Initial guess of parameters and initial condition, and bounding constraints
cautionparams = list(params.values())[-4:-2]
theta = [0.25,0.08]
boxBounds = [(0.2,0.4),(0.05,0.15)]
objSCEI3R = SquareLoss(theta=theta, ode=SCEI3R_model, x0=x0_SCEI3R, t0=t[0], t=t[1::], y=ynoise[1::,:],
state_weight=[1.,1.,1.,1.,1.],state_name=['I_1','I_2','I_3','R','D'],
target_param=['c_0','c_1'],target_state=['E'])
# perform optimization
res = minimize(fun=objSCEI3R.costIV,
jac=objSCEI3R.sensitivityIV,
x0=theta+[0.00005],
bounds=boxBounds+[(0.0000001,0.001)],
method='L-BFGS-B',
options={'disp':True,'maxiter':1000,'eps':0.0001,'ftol':0.001})
print(res)
```
```python
objSCEI3R.residual()
```
##### Fit c_0 and c_1 as well as initial value of E with Nelder-Mead
no use of Jacobian and no constraints
```python
# Initial guess of parameters and initial condition, and bounding constraints
cautionparams = list(params.values())[-4:-2]
theta = [0.25,0.08]
boxBounds = [(0.2,0.4),(0.05,0.15)]
objSCEI3R = SquareLoss(theta=theta, ode=SCEI3R_model, x0=x0_SCEI3R, t0=t[0], t=t[1::], y=ynoise[1::,:],
state_weight=[1.,1.,1.,1.,1.],state_name=['I_1','I_2','I_3','R','D'],
target_param=['c_0','c_1'],target_state=['E'])
# perform optimization
res = minimize(fun=objSCEI3R.costIV,
#jac=objSCEI3R.sensitivityIV,
x0=theta+[0.00005],
#bounds=boxBounds+[(0.0000001,0.001)],
method='Nelder-Mead',
options={'disp':True,'maxiter':1000}) #,'eps':0.0001,'ftol':0.01}) #not NM
print(res)
```
```python
# model with fitted parameters
print(params)
print(x0_SCEI3R)
params_fit = params.copy()
#params_fit['c_0'] = res.x[0]
#params_fit['c_1'] = res.x[1]
SCEI3R_model.params = params_fit
print(SCEI3R_model.params)
#ode_fit = common_models.SEI3R({'beta':res.x[0], 'gamma':res.x[1],'alpha':res.x[2]})
#x0_fit = [1-1.27e-6, 1.27e-6, 0]
x0_fit = x0_SCEI3R.copy()
#x0_fit[2] = res.x[2]
#t_fit = numpy.linspace(0, 150, 1000)
t_fit = t
SCEI3R_model.initial_values = (x0_fit, t_fit[0])
# %timeit sol_fit =SCEI3R_model.integrate(t_fit[1::]) # use magic %timeit to time
# sol_fit =SCEI3R_model.integrate(t_fit[0::])
sol_fit = scipy.integrate.odeint(SCEI3R_model.ode, x0_fit, t_fit[1::])
#
plt.figure(figsize=(15,10))
plt.plot(t,ynoise[:,0], 'go') # infected observations
plt.plot(t,ynoise[:,1], 'go') # infected observations
plt.plot(t,ynoise[:,2], 'go') # infected observations
plt.plot(t,ynoise[:,3], 'bo') # recoverd
plt.plot(t,ynoise[:,4], 'ro') # died
plt.plot(t_fit[1::], sol_fit)
plt.ylim([0,0.004])
#plt.show(())
#ode_fit.plot()
peak_i = np.argmax(sol_fit[:,2])
print('Peak infection (days)', t_fit[peak_i])
```
## Fit SC2IR parameters to jhu data based on square_loss
```python
params=SC2IR_model.parameters
print(params)
```
```python
# Initial guess of parameters and initial condition, and bounding constraints
theta = [0.4,0.11,0.007,0.33,0.228,275.]
boxBounds = [(0.2,0.5),(0.05,0.15),(0.005,0.015),(0.25,0.55),(0.15,0.4),(5.,2000.)]
# setup cost function and Jacobian with target parameters and initial states
objSC2IR = SquareLoss(theta=theta, ode=SC2IR_model, x0=x0, t0=t[0], t=t[1::], y=y_jhu[test_country][1::,1:3],
state_weight=[0.2,1.],state_name=['R','D'],
target_param=['beta','gamma','mu','c_0','c_1','c_2'],
target_state=['I'])
# perform optimization
res = minimize(fun=objSC2IR.costIV,
jac=objSC2IR.sensitivityIV,
x0=theta+[0.000000001],
bounds=boxBounds+[(0.0000000001,0.000001)],
# method='L-BFGS-B',
# method='Nelder-Mead',
#options={'disp':True,'maxiter':1000,'eps':0.01,'gtol':0.01})
options={'disp':True,'maxiter':1000,'eps':0.000001,'ftol':0.000000001})
print(res)
```
```python
# model with fitted parameters
startparams = SC2IR_model.parameters.copy() # save starting parameters (not fit)
print(params)
print(x0)
params_fit = params.copy()
params_fit['beta'] = res.x[0]
params_fit['gamma'] = res.x[1]
params_fit['mu'] = res.x[2]
params_fit['c_0'] = res.x[3]
params_fit['c_1'] = res.x[4]
params_fit['c_2'] = res.x[5]
SC2IR_model.params = params_fit
print(SC2IR_model.params)
x0_fit = x0.copy()
x0_fit[1] = res.x[6]
t_fit = t
SC2IR_model.initial_values = (x0_fit, t_fit[0])
sol_fit = scipy.integrate.odeint(SC2IR_model.ode, x0_fit, t_fit[1::])
#
plt.figure(figsize=(15,10))
plt.semilogy()
plt.ylim([0.000001,1])
plt.plot(t,y_jhu[test_country][:,1], 'bo',label='R') # recovered
plt.semilogy()
plt.ylim([0.000001,1])
plt.plot(t,y_jhu[test_country][:,2], 'ro',label='D') # died
plt.semilogy()
plt.ylim([0.000001,1])
plt.gca().set_prop_cycle(color=['grey','green','blue','red', 'black'])
plt.plot(t_fit[1::], sol_fit)
plt.ylim([0.000001,1])
plt.legend(('R','D','S','I','R','D','S_c','I_c'))
plt.semilogy()
#plt.show(())
#ode_fit.plot()
peak_i = np.argmax(sol_fit[:,1])
print('Peak infection (days)', t_fit[peak_i])
SC2IR_model.parameters = startparams
```
## Fit SC3EI3R parameters to jhu data based on square_loss
### Fit c_0 and c_1 only
```python
# Initial guess of parameters, and bounding constraints
cautionparams = list(params.values())[-4:-1]
theta = [value for value in cautionparams]
print(theta)
theta = [0.3,0.08,2500.]
boxBounds = [(0.2,0.8),(0.05,0.15),(100.,10000.)]
objSC3EI3R = SquareLoss(theta=theta, ode=SC3EI3R_model, x0=x0_SC3EI3R, t0=t[0], t=t[1::], y=y_jhu[test_country][1::,1:3],
state_weight=[1.,1.],state_name=['R','D'],
target_param=['c_0','c_1','c_2'])
# perform optimization
res = minimize(fun=objSC3EI3R.cost,
#jac=objSC3EI3R.sensitivity,
x0=theta,
#bounds=boxBounds,
method='L-BFGS-B',
# method='Nelder-Mead',
options={'disp':True,'maxiter':1000,'eps':0.00001})# ,'ftol':0.01}) #not BFGS
print(res)
```
### Fit c_0 and c_1 as well as initial value of E
#### Fit c_0 and c_1 as well as initial value of E with 'SLSQP'
does not work well
note use of special methods IV for initial value fitting of target_state
```python
# Initial guess of parameters and initial condition, and bounding constraints
cautionparams = list(params.values())[-4:-3]
theta = [value for value in cautionparams]
theta = [0.21,0.08,2500.]
objSC3EI3R = SquareLoss(theta=theta, ode=SC3EI3R_model, x0=x0_SC3EI3R, t0=t[0], t=t[1::], y=y_jhu[test_country][1::,1:3],
state_weight=[1.,1.],state_name=['R','D'],
target_param=['c_0','c_1','c_2'],target_state=['I_1'])
# perform optimization
res = minimize(fun=objSC3EI3R.costIV,
jac=objSC3EI3R.sensitivityIV,
x0=theta+[0.00005],
bounds=boxBounds+[(0.0000001,0.001)],
# method='BFGS',
method='L-BFGS-B',
options={'disp':True,'maxiter':1000,'eps':0.01,'gtol':0.01})
print(res)
```
#### Fit c_0 and c_1 as well as initial value of E with BFGS
works well: no constraints and gtol not ftol
```python
# Initial guess of parameters and initial condition, and bounding constraints
cautionparams = list(params.values())[-4:-2]
theta = [0.25,0.08]
boxBounds = [(0.2,0.4),(0.05,0.15)]
objSCEI3R = SquareLoss(theta=theta, ode=SCEI3R_model, x0=x0_SC3EI3R, t0=t[0], t=t[1::], y=ynoise[1::,:],
state_weight=[1.,1.,1.,1.,1.],state_name=['I_1','I_2','I_3','R','D'],
target_param=['c_0','c_1'],target_state=['E'])
# perform optimization
res = minimize(fun=objSCEI3R.costIV,
jac=objSCEI3R.sensitivityIV,
x0=theta+[0.00005],
#bounds=boxBounds+[(0.0000001,0.001)],
method='BFGS',
options={'disp':True,'maxiter':1000,'eps':0.01,'gtol':0.01})
print(res)
```
```python
# model with fitted parameters
print(params)
print(x0_SC3EI3R)
params_fit = params.copy()
#params_fit['c_0'] = res.x[0]
#params_fit['c_1'] = res.x[1]
SC3EI3R_model.params = params_fit
print(SC3EI3R_model.params)
#ode_fit = common_models.SEI3R({'beta':res.x[0], 'gamma':res.x[1],'alpha':res.x[2]})
#x0_fit = [1-1.27e-6, 1.27e-6, 0]
x0_fit = x0_SC3EI3R.copy()
#x0_fit[2] = res.x[2]
#t_fit = numpy.linspace(0, 150, 1000)
t_fit = t
SC3EI3R_model.initial_values = (x0_fit, t_fit[0])
# %timeit sol_fit =SCEI3R_model.integrate(t_fit[1::]) # use magic %timeit to time
# sol_fit =SCEI3R_model.integrate(t_fit[0::])
sol_fit = scipy.integrate.odeint(SC3EI3R_model.ode, x0_fit, t_fit[1::])
#
plt.figure(figsize=(15,10))
plt.plot(t,ynoise[:,0], 'o',color='lightgreen') # infected observations
plt.plot(t,ynoise[:,1], 'o',color='green') # infected observations
plt.plot(t,ynoise[:,2], 'o',color='darkgreen') # infected observations
plt.plot(t,ynoise[:,3], 'bo') # recoverd
plt.plot(t,ynoise[:,4], 'ro') # died
plt.plot(t_fit[1::], sol_fit)
plt.ylim([0,0.004])
#plt.show(())
#ode_fit.plot()
peak_i = np.argmax(sol_fit[:,2])
print('Peak infection (days)', t_fit[peak_i])
```
#### Fit c_0 and c_1 as well as initial value of E using L-BFGS-B
this method does not work well
```python
# Initial guess of parameters and initial condition, and bounding constraints
cautionparams = list(params.values())[-4:-2]
theta = [0.25,0.08]
boxBounds = [(0.2,0.4),(0.05,0.15)]
objSCEI3R = SquareLoss(theta=theta, ode=SCEI3R_model, x0=x0_SC3EI3R, t0=t[0], t=t[1::], y=ynoise[1::,:],
state_weight=[1.,1.,1.,1.,1.],state_name=['I_1','I_2','I_3','R','D'],
target_param=['c_0','c_1'],target_state=['E'])
# perform optimization
res = minimize(fun=objSCEI3R.costIV,
jac=objSCEI3R.sensitivityIV,
x0=theta+[0.00005],
bounds=boxBounds+[(0.0000001,0.001)],
method='L-BFGS-B',
options={'disp':True,'maxiter':1000,'eps':0.0001,'ftol':0.001})
print(res)
```
```python
objSCEI3R.residual()
```
#### Fit c_0 and c_1 as well as initial value of E with Nelder-Mead
no use of Jacobian and no constraints
```python
# Initial guess of parameters and initial condition, and bounding constraints
cautionparams = list(params.values())[-4:-2]
theta = [0.25,0.08]
boxBounds = [(0.2,0.4),(0.05,0.15)]
objSCEI3R = SquareLoss(theta=theta, ode=SCEI3R_model, x0=x0_SC3EI3R, t0=t[0], t=t[1::], y=ynoise[1::,:],
state_weight=[1.,1.,1.,1.,1.],state_name=['I_1','I_2','I_3','R','D'],
target_param=['c_0','c_1'],target_state=['E'])
# perform optimization
res = minimize(fun=objSCEI3R.costIV,
#jac=objSCEI3R.sensitivityIV,
x0=theta+[0.00005],
#bounds=boxBounds+[(0.0000001,0.001)],
method='Nelder-Mead',
options={'disp':True,'maxiter':1000}) #,'eps':0.0001,'ftol':0.01}) #not NM
print(res)
```
```python
# model with fitted parameters
print(params)
print(x0_SC3EI3R)
params_fit = params.copy()
params_fit['c_0'] = res.x[0]
params_fit['c_1'] = res.x[1]
SC3EI3R_model.params = params_fit
print(SC3EI3R_model.params)
x0_fit = x0_SC3EI3R.copy()
#x0_fit[2] = res.x[2]
#t_fit = numpy.linspace(0, 150, 1000)
t_fit = t
SC3EI3R_model.initial_values = (x0_fit, t_fit[0])
# %timeit sol_fit =SC3EI3R_model.integrate(t_fit[1::]) # use magic %timeit to time
# sol_fit =SC3EI3R_model.integrate(t_fit[0::])
sol_fit = scipy.integrate.odeint(SC3EI3R_model.ode, x0_fit, t_fit[1::])
#
plt.figure(figsize=(15,10))
plt.plot(t,y_jhu[:,0], 'bo') # recoverd
plt.plot(t,y_jhu[:,1], 'ro') # died
plt.plot(t_fit[1::], sol_fit)
plt.ylim([0,0.004])
#plt.show(())
#ode_fit.plot()
peak_i = np.argmax(sol_fit[:,2])
print('Peak infection (days)', t_fit[peak_i])
```
### Information on method options
```python
scipy.optimize.show_options(solver='minimize', method='SLSQP', disp=True)
print(' ')
scipy.optimize.show_options(solver='minimize', method='L-BFGS-B', disp=True)
```
## Plot using full control
```python
def plotmodel(solns,t,scale='linear',species='no_susc',plottitle= '',label='',
newplot = True,models=['SEI3R','SCEI3R','SC3EI3R']):
"""
plot solns over
times t interpreted as models indicated in models parameter
scale: alternative 'linear' or 'log'
species alternatives 'all', 'confirmed', 'deaths', 'daily confirmed', 'daily deaths'
plottitle : title for plot
label : label for curve when called as part of multicurve plot
newplot : whether to open new plot True/False
models : list of models to include, default all three of those possible
"""
nmodels = len(models)
if len(solns) != len(models):
print("Error: number of models must match number of solutions")
return None
nm = 0
if newplot == True:
plt.figure(figsize=(nmodels*8,6))
for nm in range(nmodels):
soln = solns[nm]
if models[nm] == 'SEI3R': #SEI3R
plt.subplot(1,nmodels,nm+1)
if scale == 'log': #Plot on log scale
plt.semilogy()
plt.ylim([1,10000])
elif species != 'daily confirmed': # Plot on normal linear scale
#plt.ylim([0,10000])
pass
if species == 'no_susc':
plt.plot(tvec,soln[:,1:5],label=label)
plt.legend(("E","I1","I2","I3"))
elif species == 'confirmed' or species == 'daily confirmed':
suma = np.sum(soln[:,2:7],axis=1)
# print('length=',len(suma))
if species == 'daily confirmed':
sumd = np.zeros(len(suma))
for i in range(1,len(suma)):
sumd[i] = suma[i]-suma[i-1]
#plt.ylim([0,1000])
plt.plot(tvec,sumd,label=label)
else:
#plt.ylim([0,200000])
plt.plot(t,suma,label=label)
elif species == 'all':
plt.plot(tvec,soln,label=label)
plt.legend(("S","E","I1","I2","I3","R","D"))
plt.xlabel("Time (days)")
plt.ylabel("Portion of population N")
plt.title('SEI3R %s' % plottitle)
elif models[nm] == 'SCEI3R': #SCEI3R
#Plot
plt.subplot(1,nmodels,nm+1)
if scale == 'log': #Plot on log scale
plt.semilogy()
plt.ylim([1,10000])
elif species != 'daily confirmed': # Plot on normal linear scale
#plt.ylim([0,10000])
pass
if species == 'no_susc':
plt.plot(t,soln[:,1:5],label=label)
plt.legend(("E","I1","I2","I3"))
elif species == 'confirmed' or species == 'daily confirmed':
suma = np.sum(soln[:,2:7],axis=1)
# print('length=',len(suma))
if species == 'daily confirmed':
sumd = np.zeros(len(suma))
for i in range(1,len(suma)):
sumd[i] = suma[i]-suma[i-1]
#plt.ylim([0,1000])
plt.plot(t,sumd,label=label)
else:
#plt.ylim([0,200000])
plt.plot(t,suma,label=label)
elif species == 'all':
plt.plot(t,soln,label=label)
plt.legend(("S","E","I1","I2","I3","R","D","Sc"))
plt.xlabel("Time (days)")
plt.ylabel("Portion of population N")
plt.title('SCEI3R %s' % plottitle)
elif models[nm] == 'SC3EI3R': #SC3EI3R
plt.subplot(1,nmodels,nm+1)
if scale == 'log': #Plot on log scale
plt.semilogy()
plt.ylim([1,10000])
elif species != 'daily confirmed': # Plot on normal linear scale
#plt.ylim([0,10000])
pass
if species == 'no_susc':
plt.plot(t,sol[:,1:5])
plt.legend(("E","I1","I2","I3"))
elif species == 'confirmed' or species == 'daily confirmed':
suma = np.sum(soln[:,2:7],axis=1) + soln[:,9]
if species == 'daily confirmed':
sumd = np.zeros(len(suma))
for i in range(1,len(suma)):
sumd[i] = suma[i]-suma[i-1]
# plt.ylim([0,1000])
plt.plot(t,sumd,label=label)
else:
# plt.ylim([0,200000])
plt.plot(t,suma,label=label)
elif species == 'all':
plt.plot(t,soln,label=label)
plt.legend(("S","E","I1","I2","I3","R","D","Sc","Ec","I1c"))
plt.xlabel("Time (days)")
plt.ylabel("Portion of population N")
plt.title('SC3EI3R %s' % plottitle)
return True
```
```python
plotmodel([sol_fit],t_fit[1:],scale='linear',species='no_susc',plottitle= 'test',label='',
newplot = True,models=['SCEI3R'])
```
```python
```
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.