text
stringlengths 0
3.34M
|
---|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Functions.FunExtEquiv where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.CartesianKanOps
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Data.Vec
open import Cubical.Data.Nat
open import Cubical.Reflection.StrictEquiv
private
variable
ℓ ℓ₁ ℓ₂ ℓ₃ : Level
-- Function extensionality is an equivalence
module _ {A : Type ℓ} {B : A → I → Type ℓ₁}
{f : (x : A) → B x i0} {g : (x : A) → B x i1} where
funExtEquiv : (∀ x → PathP (B x) (f x) (g x)) ≃ PathP (λ i → ∀ x → B x i) f g
unquoteDef funExtEquiv = defStrictEquiv funExtEquiv funExt funExt⁻
funExtPath : (∀ x → PathP (B x) (f x) (g x)) ≡ PathP (λ i → ∀ x → B x i) f g
funExtPath = ua funExtEquiv
funExtIso : Iso (∀ x → PathP (B x) (f x) (g x)) (PathP (λ i → ∀ x → B x i) f g)
funExtIso = iso funExt funExt⁻ (λ x → refl {x = x}) (λ x → refl {x = x})
-- Function extensionality for binary functions
funExt₂ : {A : Type ℓ} {B : A → Type ℓ₁} {C : (x : A) → B x → I → Type ℓ₂}
{f : (x : A) → (y : B x) → C x y i0}
{g : (x : A) → (y : B x) → C x y i1}
→ ((x : A) (y : B x) → PathP (C x y) (f x y) (g x y))
→ PathP (λ i → ∀ x y → C x y i) f g
funExt₂ p i x y = p x y i
-- Function extensionality for binary functions is an equivalence
module _ {A : Type ℓ} {B : A → Type ℓ₁} {C : (x : A) → B x → I → Type ℓ₂}
{f : (x : A) → (y : B x) → C x y i0}
{g : (x : A) → (y : B x) → C x y i1} where
private
appl₂ : PathP (λ i → ∀ x y → C x y i) f g → ∀ x y → PathP (C x y) (f x y) (g x y)
appl₂ eq x y i = eq i x y
funExt₂Equiv : (∀ x y → PathP (C x y) (f x y) (g x y)) ≃ (PathP (λ i → ∀ x y → C x y i) f g)
unquoteDef funExt₂Equiv = defStrictEquiv funExt₂Equiv funExt₂ appl₂
funExt₂Path : (∀ x y → PathP (C x y) (f x y) (g x y)) ≡ (PathP (λ i → ∀ x y → C x y i) f g)
funExt₂Path = ua funExt₂Equiv
-- Function extensionality for ternary functions
funExt₃ : {A : Type ℓ} {B : A → Type ℓ₁} {C : (x : A) → B x → Type ℓ₂}
{D : (x : A) → (y : B x) → C x y → I → Type ℓ₃}
{f : (x : A) → (y : B x) → (z : C x y) → D x y z i0}
{g : (x : A) → (y : B x) → (z : C x y) → D x y z i1}
→ ((x : A) (y : B x) (z : C x y) → PathP (D x y z) (f x y z) (g x y z))
→ PathP (λ i → ∀ x y z → D x y z i) f g
funExt₃ p i x y z = p x y z i
-- Function extensionality for ternary functions is an equivalence
module _ {A : Type ℓ} {B : A → Type ℓ₁} {C : (x : A) → B x → Type ℓ₂}
{D : (x : A) → (y : B x) → C x y → I → Type ℓ₃}
{f : (x : A) → (y : B x) → (z : C x y) → D x y z i0}
{g : (x : A) → (y : B x) → (z : C x y) → D x y z i1} where
private
appl₃ : PathP (λ i → ∀ x y z → D x y z i) f g → ∀ x y z → PathP (D x y z) (f x y z) (g x y z)
appl₃ eq x y z i = eq i x y z
funExt₃Equiv : (∀ x y z → PathP (D x y z) (f x y z) (g x y z)) ≃ (PathP (λ i → ∀ x y z → D x y z i) f g)
unquoteDef funExt₃Equiv = defStrictEquiv funExt₃Equiv funExt₃ appl₃
funExt₃Path : (∀ x y z → PathP (D x y z) (f x y z) (g x y z)) ≡ (PathP (λ i → ∀ x y z → D x y z i) f g)
funExt₃Path = ua funExt₃Equiv
-- n-ary non-dependent funext
nAryFunExt : {X : Type ℓ} {Y : I → Type ℓ₁} (n : ℕ) (fX : nAryOp n X (Y i0)) (fY : nAryOp n X (Y i1))
→ ((xs : Vec X n) → PathP Y (fX $ⁿ xs) (fY $ⁿ map (λ x → x) xs))
→ PathP (λ i → nAryOp n X (Y i)) fX fY
nAryFunExt zero fX fY p = p []
nAryFunExt (suc n) fX fY p i x = nAryFunExt n (fX x) (fY x) (λ xs → p (x ∷ xs)) i
-- n-ary funext⁻
nAryFunExt⁻ : (n : ℕ) {X : Type ℓ} {Y : I → Type ℓ₁} (fX : nAryOp n X (Y i0)) (fY : nAryOp n X (Y i1))
→ PathP (λ i → nAryOp n X (Y i)) fX fY
→ ((xs : Vec X n) → PathP Y (fX $ⁿ xs) (fY $ⁿ map (λ x → x) xs))
nAryFunExt⁻ zero fX fY p [] = p
nAryFunExt⁻ (suc n) fX fY p (x ∷ xs) = nAryFunExt⁻ n (fX x) (fY x) (λ i → p i x) xs
nAryFunExtEquiv : (n : ℕ) {X : Type ℓ} {Y : I → Type ℓ₁} (fX : nAryOp n X (Y i0)) (fY : nAryOp n X (Y i1))
→ ((xs : Vec X n) → PathP Y (fX $ⁿ xs) (fY $ⁿ map (λ x → x) xs)) ≃ PathP (λ i → nAryOp n X (Y i)) fX fY
nAryFunExtEquiv n {X} {Y} fX fY = isoToEquiv (iso (nAryFunExt n fX fY) (nAryFunExt⁻ n fX fY)
(linv n fX fY) (rinv n fX fY))
where
linv : (n : ℕ) (fX : nAryOp n X (Y i0)) (fY : nAryOp n X (Y i1))
(p : PathP (λ i → nAryOp n X (Y i)) fX fY)
→ nAryFunExt n fX fY (nAryFunExt⁻ n fX fY p) ≡ p
linv zero fX fY p = refl
linv (suc n) fX fY p i j x = linv n (fX x) (fY x) (λ k → p k x) i j
rinv : (n : ℕ) (fX : nAryOp n X (Y i0)) (fY : nAryOp n X (Y i1))
(p : (xs : Vec X n) → PathP Y (fX $ⁿ xs) (fY $ⁿ map (λ x → x) xs))
→ nAryFunExt⁻ n fX fY (nAryFunExt n fX fY p) ≡ p
rinv zero fX fY p i [] = p []
rinv (suc n) fX fY p i (x ∷ xs) = rinv n (fX x) (fY x) (λ ys i → p (x ∷ ys) i) i xs
-- Funext when the domain also depends on the interval
funExtDep : {A : I → Type ℓ} {B : (i : I) → A i → Type ℓ₁}
{f : (x : A i0) → B i0 x} {g : (x : A i1) → B i1 x}
→ ({x₀ : A i0} {x₁ : A i1} (p : PathP A x₀ x₁) → PathP (λ i → B i (p i)) (f x₀) (g x₁))
→ PathP (λ i → (x : A i) → B i x) f g
funExtDep {A = A} {B} {f} {g} h i x =
comp
(λ k → B i (coei→i A i x k))
(λ k → λ
{ (i = i0) → f (coei→i A i0 x k)
; (i = i1) → g (coei→i A i1 x k)
})
(h (λ j → coei→j A i j x) i)
funExtDep⁻ : {A : I → Type ℓ} {B : (i : I) → A i → Type ℓ₁}
{f : (x : A i0) → B i0 x} {g : (x : A i1) → B i1 x}
→ PathP (λ i → (x : A i) → B i x) f g
→ ({x₀ : A i0} {x₁ : A i1} (p : PathP A x₀ x₁) → PathP (λ i → B i (p i)) (f x₀) (g x₁))
funExtDep⁻ q p i = q i (p i)
funExtDepEquiv : {A : I → Type ℓ} {B : (i : I) → A i → Type ℓ₁}
{f : (x : A i0) → B i0 x} {g : (x : A i1) → B i1 x}
→ ({x₀ : A i0} {x₁ : A i1} (p : PathP A x₀ x₁) → PathP (λ i → B i (p i)) (f x₀) (g x₁))
≃ PathP (λ i → (x : A i) → B i x) f g
funExtDepEquiv {A = A} {B} {f} {g} = isoToEquiv isom
where
open Iso
isom : Iso _ _
isom .fun = funExtDep
isom .inv = funExtDep⁻
isom .rightInv q m i x =
comp
(λ k → B i (coei→i A i x (k ∨ m)))
(λ k → λ
{ (i = i0) → f (coei→i A i0 x (k ∨ m))
; (i = i1) → g (coei→i A i1 x (k ∨ m))
; (m = i1) → q i x
})
(q i (coei→i A i x m))
isom .leftInv h m p i =
comp
(λ k → B i (lemi→i m k))
(λ k → λ
{ (i = i0) → f (lemi→i m k)
; (i = i1) → g (lemi→i m k)
; (m = i1) → h p i
})
(h (λ j → lemi→j j m) i)
where
lemi→j : ∀ j → coei→j A i j (p i) ≡ p j
lemi→j j =
coei→j (λ k → coei→j A i k (p i) ≡ p k) i j (coei→i A i (p i))
lemi→i : PathP (λ m → lemi→j i m ≡ p i) (coei→i A i (p i)) refl
lemi→i =
sym (coei→i (λ k → coei→j A i k (p i) ≡ p k) i (coei→i A i (p i)))
◁ λ m k → lemi→j i (m ∨ k)
heteroHomotopy≃Homotopy : {A : I → Type ℓ} {B : (i : I) → Type ℓ₁}
{f : A i0 → B i0} {g : A i1 → B i1}
→ ({x₀ : A i0} {x₁ : A i1} → PathP A x₀ x₁ → PathP B (f x₀) (g x₁))
≃ ((x₀ : A i0) → PathP B (f x₀) (g (transport (λ i → A i) x₀)))
heteroHomotopy≃Homotopy {A = A} {B} {f} {g} = isoToEquiv isom
where
open Iso
isom : Iso _ _
isom .fun h x₀ = h (isContrSinglP A x₀ .fst .snd)
isom .inv k {x₀} {x₁} p =
subst (λ fib → PathP B (f x₀) (g (fib .fst))) (isContrSinglP A x₀ .snd (x₁ , p)) (k x₀)
isom .rightInv k = funExt λ x₀ →
cong (λ α → subst (λ fib → PathP B (f x₀) (g (fib .fst))) α (k x₀))
(isProp→isSet isPropSinglP (isContrSinglP A x₀ .fst) _
(isContrSinglP A x₀ .snd (isContrSinglP A x₀ .fst))
refl)
∙ transportRefl (k x₀)
isom .leftInv h j {x₀} {x₁} p =
transp
(λ i → PathP B (f x₀) (g (isContrSinglP A x₀ .snd (x₁ , p) (i ∨ j) .fst)))
j
(h (isContrSinglP A x₀ .snd (x₁ , p) j .snd))
|
(* Title: Verification components with relational MKA
Author: Jonathan Julián Huerta y Munive, 2019
Maintainer: Jonathan Julián Huerta y Munive <[email protected]>
*)
section \<open> Verification components with relational MKA \<close>
text \<open> We show that relations form an antidomain Kleene algebra (hence a modal Kleene
algebra). We use its forward box operator to derive rules in the algebra for weakest
liberal preconditions (wlps) of hybrid programs. Finally, we derive our three methods
for verifying correctness specifications for the continuous dynamics of HS in this setting. \<close>
theory HS_VC_MKA_rel
imports "../HS_ODEs" "KAD.Modal_Kleene_Algebra"
begin
subsection \<open> Modal Kleene algebra preparation \<close>
context dioid_one_zero (* by Victor Gomes, Georg Struth *)
begin
lemma power_inductl: "z + x \<cdot> y \<le> y \<Longrightarrow> (x ^ n) \<cdot> z \<le> y"
by(induct n, auto, metis mult.assoc mult_isol order_trans)
lemma power_inductr: "z + y \<cdot> x \<le> y \<Longrightarrow> z \<cdot> (x ^ n) \<le> y"
proof (induct n)
case 0 show ?case
using "0.prems" by auto
case Suc
{
fix n
assume "z + y \<cdot> x \<le> y \<Longrightarrow> z \<cdot> x ^ n \<le> y"
and "z + y \<cdot> x \<le> y"
hence "z \<cdot> x ^ n \<le> y"
by auto
also have "z \<cdot> x ^ Suc n = z \<cdot> x \<cdot> x ^ n"
by (metis mult.assoc power_Suc)
moreover have "... = (z \<cdot> x ^ n) \<cdot> x"
by (metis mult.assoc power_commutes)
moreover have "... \<le> y \<cdot> x"
by (metis calculation(1) mult_isor)
moreover have "... \<le> y"
using \<open>z + y \<cdot> x \<le> y\<close> by auto
ultimately have "z \<cdot> x ^ Suc n \<le> y" by auto
}
thus ?case
by (metis Suc)
qed
end
context antidomain_kleene_algebra
begin
lemma fbox_frame: "d p \<cdot> x \<le> x \<cdot> d p \<Longrightarrow> d q \<le> |x] t \<Longrightarrow> d p \<cdot> d q \<le> |x] (d p \<cdot> d t)"
using dual.mult_isol_var fbox_add1 fbox_demodalisation3 fbox_simp by auto
lemma plus_inv: "i \<le> |x] i \<Longrightarrow> j \<le> |x] j \<Longrightarrow> (i + j) \<le> |x] (i + j)"
by (metis ads_d_def dka.dsr5 fbox_simp fbox_subdist join.sup_mono order_trans)
lemma mult_inv: "d i \<le> |x] d i \<Longrightarrow> d j \<le> |x] d j \<Longrightarrow> (d i \<cdot> d j) \<le> |x] (d i \<cdot> d j)"
using fbox_demodalisation3 fbox_frame fbox_simp by auto
lemma fbox_export1: "ad p + |x] q = |d p \<cdot> x] q"
using a_d_add_closure addual.ars_r_def fbox_def fbox_mult by auto
lemma fbox_stari: "d p \<le> d i \<Longrightarrow> d i \<le> |x] i \<Longrightarrow> d i \<le> d q \<Longrightarrow> d p \<le> |x\<^sup>\<star>] q"
by (meson dual_order.trans fbox_iso fbox_star_induct_var)
declare fbox_mult [simp]
definition cond :: "'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a" ("if _ then _ else _ fi" [64,64,64] 63)
where "if p then x else y fi = d p \<cdot> x + ad p \<cdot> y"
lemma fbox_cond_var [simp]: "|if p then x else y fi] q = (ad p + |x] q) \<cdot> (d p + |y] q)"
using cond_def a_closure' ads_d_def ans_d_def fbox_add2 fbox_export1 by auto
definition loopi :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" ("loop _ inv _ " [64,64] 63)
where "loop x inv i = x\<^sup>\<star>"
lemma fbox_loopi: "d p \<le> d i \<Longrightarrow> d i \<le> |x] i \<Longrightarrow> d i \<le> d q \<Longrightarrow> d p \<le> |loop x inv i] q"
unfolding loopi_def using fbox_stari by blast
end
subsection \<open> Relational model \<close> (* by Victor Gomes, Georg Struth *)
interpretation rel_dioid: dioid_one_zero "(\<union>)" "(O)" Id "{}" "(\<subseteq>)" "(\<subset>)"
by (unfold_locales, auto)
lemma power_is_relpow: "rel_dioid.power X n = X ^^ n"
proof (induct n)
case 0 show ?case
by (metis rel_dioid.power_0 relpow.simps(1))
case Suc thus ?case
by (metis rel_dioid.power_Suc2 relpow.simps(2))
qed
lemma rel_star_def: "X^* = (\<Union>n. rel_dioid.power X n)"
by (simp add: power_is_relpow rtrancl_is_UN_relpow)
lemma rel_star_contl: "X O Y^* = (\<Union>n. X O rel_dioid.power Y n)"
by (metis rel_star_def relcomp_UNION_distrib)
lemma rel_star_contr: "X^* O Y = (\<Union>n. (rel_dioid.power X n) O Y)"
by (metis rel_star_def relcomp_UNION_distrib2)
interpretation rel_ka: kleene_algebra "(\<union>)" "(O)" Id "{}" "(\<subseteq>)" "(\<subset>)" rtrancl
proof
fix x y z :: "'a rel"
show "Id \<union> x O x\<^sup>* \<subseteq> x\<^sup>*"
by (metis order_refl r_comp_rtrancl_eq rtrancl_unfold)
next
fix x y z :: "'a rel"
assume "z \<union> x O y \<subseteq> y"
thus "x\<^sup>* O z \<subseteq> y"
by (simp only: rel_star_contr, metis (lifting) SUP_le_iff rel_dioid.power_inductl)
next
fix x y z :: "'a rel"
assume "z \<union> y O x \<subseteq> y"
thus "z O x\<^sup>* \<subseteq> y"
by (simp only: rel_star_contl, metis (lifting) SUP_le_iff rel_dioid.power_inductr)
qed
definition rel_ad :: "'a rel \<Rightarrow> 'a rel" where
"rel_ad R = {(x,x) | x. \<not> (\<exists>y. (x,y) \<in> R)}"
interpretation rel_aka: antidomain_kleene_algebra rel_ad "(\<union>)" "(O)" Id "{}" "(\<subseteq>)" "(\<subset>)" rtrancl
by unfold_locales (auto simp: rel_ad_def)
subsection \<open> Store and weakest preconditions \<close>
type_synonym 'a pred = "'a \<Rightarrow> bool"
no_notation Archimedean_Field.ceiling ("\<lceil>_\<rceil>")
and Range_Semiring.antirange_semiring_class.ars_r ("r")
and antidomain_semiringl.ads_d ("d")
notation Id ("skip")
and relcomp (infixl ";" 70)
and zero_class.zero ("0")
and rel_aka.fbox ("wp")
definition p2r :: "'a pred \<Rightarrow> 'a rel" ("(1\<lceil>_\<rceil>)") where
"\<lceil>P\<rceil> = {(s,s) |s. P s}"
lemma p2r_simps[simp]:
"\<lceil>P\<rceil> \<le> \<lceil>Q\<rceil> = (\<forall>s. P s \<longrightarrow> Q s)"
"(\<lceil>P\<rceil> = \<lceil>Q\<rceil>) = (\<forall>s. P s = Q s)"
"(\<lceil>P\<rceil> ; \<lceil>Q\<rceil>) = \<lceil>\<lambda> s. P s \<and> Q s\<rceil>"
"(\<lceil>P\<rceil> \<union> \<lceil>Q\<rceil>) = \<lceil>\<lambda> s. P s \<or> Q s\<rceil>"
"rel_ad \<lceil>P\<rceil> = \<lceil>\<lambda>s. \<not> P s\<rceil>"
"rel_aka.ads_d \<lceil>P\<rceil> = \<lceil>P\<rceil>"
unfolding p2r_def rel_ad_def rel_aka.ads_d_def by auto
lemma wp_rel: "wp R \<lceil>P\<rceil> = \<lceil>\<lambda> x. \<forall> y. (x,y) \<in> R \<longrightarrow> P y\<rceil>"
unfolding rel_aka.fbox_def p2r_def rel_ad_def by auto
definition vec_upd :: "('a^'b) \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> 'a^'b"
where "vec_upd s i a = (\<chi> j. ((($) s)(i := a)) j)"
definition assign :: "'b \<Rightarrow> ('a^'b \<Rightarrow> 'a) \<Rightarrow> ('a^'b) rel" ("(2_ ::= _)" [70, 65] 61)
where "(x ::= e) = {(s, vec_upd s x (e s))| s. True}"
lemma wp_assign [simp]: "wp (x ::= e) \<lceil>Q\<rceil> = \<lceil>\<lambda>s. Q (\<chi> j. ((($) s)(x := (e s))) j)\<rceil>"
unfolding wp_rel vec_upd_def assign_def by (auto simp: fun_upd_def)
abbreviation cond_sugar :: "'a pred \<Rightarrow> 'a rel \<Rightarrow> 'a rel \<Rightarrow> 'a rel" ("IF _ THEN _ ELSE _" [64,64] 63)
where "IF P THEN X ELSE Y \<equiv> rel_aka.cond \<lceil>P\<rceil> X Y"
abbreviation loopi_sugar :: "'a rel \<Rightarrow> 'a pred \<Rightarrow> 'a rel" ("LOOP _ INV _ " [64,64] 63)
where "LOOP R INV I \<equiv> rel_aka.loopi R \<lceil>I\<rceil>"
lemma wp_loopI: "\<lceil>P\<rceil> \<le> \<lceil>I\<rceil> \<Longrightarrow> \<lceil>I\<rceil> \<le> \<lceil>Q\<rceil> \<Longrightarrow> \<lceil>I\<rceil> \<le> wp R \<lceil>I\<rceil> \<Longrightarrow> \<lceil>P\<rceil> \<le> wp (LOOP R INV I) \<lceil>Q\<rceil>"
using rel_aka.fbox_loopi[of "\<lceil>P\<rceil>"] by auto
subsection \<open> Verification of hybrid programs \<close>
text \<open>Verification by providing evolution\<close>
definition g_evol :: "(('a::ord) \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b pred \<Rightarrow> 'a set \<Rightarrow> 'b rel" ("EVOL")
where "EVOL \<phi> G T = {(s,s') |s s'. s' \<in> g_orbit (\<lambda>t. \<phi> t s) G T}"
lemma wp_g_dyn[simp]:
fixes \<phi> :: "('a::preorder) \<Rightarrow> 'b \<Rightarrow> 'b"
shows "wp (EVOL \<phi> G T) \<lceil>Q\<rceil> = \<lceil>\<lambda>s. \<forall>t\<in>T. (\<forall>\<tau>\<in>down T t. G (\<phi> \<tau> s)) \<longrightarrow> Q (\<phi> t s)\<rceil>"
unfolding wp_rel g_evol_def g_orbit_eq by auto
text \<open>Verification by providing solutions\<close>
definition g_ode :: "(('a::banach)\<Rightarrow>'a) \<Rightarrow> 'a pred \<Rightarrow> real set \<Rightarrow> 'a set \<Rightarrow> real \<Rightarrow>
'a rel" ("(1x\<acute>=_ & _ on _ _ @ _)")
where "(x\<acute>= f & G on T S @ t\<^sub>0) = {(s,s') |s s'. s' \<in> g_orbital f G T S t\<^sub>0 s}"
lemma wp_g_orbital: "wp (x\<acute>= f & G on T S @ t\<^sub>0) \<lceil>Q\<rceil> =
\<lceil>\<lambda> s. \<forall>X\<in>Sols (\<lambda>t. f) T S t\<^sub>0 s. \<forall>t\<in>T. (\<forall>\<tau>\<in>down T t. G (X \<tau>)) \<longrightarrow> Q (X t)\<rceil>"
unfolding g_orbital_eq wp_rel ivp_sols_def g_ode_def by auto
context local_flow
begin
lemma wp_g_ode: "wp (x\<acute>= f & G on T S @ 0) \<lceil>Q\<rceil> =
\<lceil>\<lambda> s. s \<in> S \<longrightarrow> (\<forall>t\<in>T. (\<forall>\<tau>\<in>down T t. G (\<phi> \<tau> s)) \<longrightarrow> Q (\<phi> t s))\<rceil>"
unfolding wp_g_orbital
apply(clarsimp, safe)
apply(erule_tac x="\<lambda>t. \<phi> t s" in ballE)
using in_ivp_sols
apply(force, force, force simp: init_time ivp_sols_def)
apply(subgoal_tac "\<forall>\<tau>\<in>down T t. X \<tau> = \<phi> \<tau> s", simp_all, clarsimp)
apply(subst eq_solution, simp_all add: ivp_sols_def)
using init_time by auto
lemma fbox_g_ode_ivl: "t \<ge> 0 \<Longrightarrow> t \<in> T \<Longrightarrow> wp (x\<acute>=f & G on {0..t} S @ 0) \<lceil>Q\<rceil> =
\<lceil>\<lambda>s. s \<in> S \<longrightarrow> (\<forall>t\<in>{0..t}. (\<forall>\<tau>\<in>{0..t}. G (\<phi> \<tau> s)) \<longrightarrow> Q (\<phi> t s))\<rceil>"
unfolding wp_g_orbital
apply(clarsimp, safe)
apply(erule_tac x="\<lambda>t. \<phi> t s" in ballE, force)
using in_ivp_sols_ivl
apply(force simp: closed_segment_eq_real_ivl)
using in_ivp_sols_ivl
apply(force simp: ivp_sols_def)
apply(subgoal_tac "\<forall>t\<in>{0..t}. (\<forall>\<tau>\<in>{0..t}. X \<tau> = \<phi> \<tau> s)", simp, clarsimp)
apply(subst eq_solution_ivl, simp_all add: ivp_sols_def)
apply(rule has_vderiv_on_subset, force, force simp: closed_segment_eq_real_ivl)
apply(force simp: closed_segment_eq_real_ivl)
using interval_time init_time
apply (meson is_interval_1 order_trans)
using init_time by force
lemma wp_orbit: "wp ({(s,s') | s s'. s' \<in> \<gamma>\<^sup>\<phi> s}) \<lceil>Q\<rceil> = \<lceil>\<lambda> s. s \<in> S \<longrightarrow> (\<forall> t \<in> T. Q (\<phi> t s))\<rceil>"
unfolding orbit_def wp_g_ode g_ode_def[symmetric] by auto
end
text \<open> Verification with differential invariants \<close>
definition g_ode_inv :: "(('a::banach)\<Rightarrow>'a) \<Rightarrow> 'a pred \<Rightarrow> real set \<Rightarrow> 'a set \<Rightarrow>
real \<Rightarrow> 'a pred \<Rightarrow> 'a rel" ("(1x\<acute>=_ & _ on _ _ @ _ DINV _ )")
where "(x\<acute>= f & G on T S @ t\<^sub>0 DINV I) = (x\<acute>= f & G on T S @ t\<^sub>0)"
lemma wp_g_orbital_guard:
assumes "H = (\<lambda>s. G s \<and> Q s)"
shows "wp (x\<acute>= f & G on T S @ t\<^sub>0) \<lceil>Q\<rceil> = wp (x\<acute>= f & G on T S @ t\<^sub>0) \<lceil>H\<rceil>"
unfolding wp_g_orbital using assms by auto
lemma wp_g_orbital_inv:
assumes "\<lceil>P\<rceil> \<le> \<lceil>I\<rceil>" and "\<lceil>I\<rceil> \<le> wp (x\<acute>= f & G on T S @ t\<^sub>0) \<lceil>I\<rceil>" and "\<lceil>I\<rceil> \<le> \<lceil>Q\<rceil>"
shows "\<lceil>P\<rceil> \<le> wp (x\<acute>= f & G on T S @ t\<^sub>0) \<lceil>Q\<rceil>"
using assms(1)
apply(rule order.trans)
using assms(2)
apply(rule order.trans)
apply(rule rel_aka.fbox_iso)
using assms(3) by auto
lemma wp_diff_inv[simp]: "(\<lceil>I\<rceil> \<le> wp (x\<acute>= f & G on T S @ t\<^sub>0) \<lceil>I\<rceil>) = diff_invariant I f T S t\<^sub>0 G"
unfolding diff_invariant_eq wp_g_orbital by(auto simp: p2r_def)
lemma diff_inv_guard_ignore:
assumes "\<lceil>I\<rceil> \<le> wp (x\<acute>= f & (\<lambda>s. True) on T S @ t\<^sub>0) \<lceil>I\<rceil>"
shows "\<lceil>I\<rceil> \<le> wp (x\<acute>= f & G on T S @ t\<^sub>0) \<lceil>I\<rceil>"
using assms unfolding wp_diff_inv diff_invariant_eq by auto
context local_flow
begin
lemma wp_diff_inv_eq: "diff_invariant I f T S 0 (\<lambda>s. True) =
(\<lceil>\<lambda>s. s \<in> S \<longrightarrow> I s\<rceil> = wp (x\<acute>= f & (\<lambda>s. True) on T S @ 0) \<lceil>\<lambda>s. s \<in> S \<longrightarrow> I s\<rceil>)"
unfolding wp_diff_inv[symmetric] wp_g_orbital
using init_time
apply(clarsimp simp: ivp_sols_def)
apply(safe, force, force)
apply(subst ivp(2)[symmetric], simp)
apply(erule_tac x="\<lambda>t. \<phi> t s" in allE)
using in_domain has_vderiv_on_domain ivp(2) init_time by auto
lemma diff_inv_eq_inv_set:
"diff_invariant I f T S 0 (\<lambda>s. True) = (\<forall>s. I s \<longrightarrow> \<gamma>\<^sup>\<phi> s \<subseteq> {s. I s})"
unfolding diff_inv_eq_inv_set orbit_def by (auto simp: p2r_def)
end
lemma wp_g_odei: "\<lceil>P\<rceil> \<le> \<lceil>I\<rceil> \<Longrightarrow> \<lceil>I\<rceil> \<le> wp (x\<acute>= f & G on T S @ t\<^sub>0) \<lceil>I\<rceil> \<Longrightarrow> \<lceil>\<lambda>s. I s \<and> G s\<rceil> \<le> \<lceil>Q\<rceil> \<Longrightarrow>
\<lceil>P\<rceil> \<le> wp (x\<acute>= f & G on T S @ t\<^sub>0 DINV I) \<lceil>Q\<rceil>"
unfolding g_ode_inv_def
apply(rule_tac b="wp (x\<acute>= f & G on T S @ t\<^sub>0) \<lceil>I\<rceil>" in order.trans)
apply(rule_tac I="I" in wp_g_orbital_inv, simp_all)
apply(subst wp_g_orbital_guard, simp)
by (rule rel_aka.fbox_iso, simp)
subsection \<open> Derivation of the rules of dL \<close>
text\<open> We derive domain specific rules of differential dynamic logic (dL). First we present a
generalised version, then we show the rules as instances of the general ones.\<close>
lemma diff_solve_axiom:
fixes c::"'a::{heine_borel, banach}"
assumes "0 \<in> T" and "is_interval T" "open T"
shows "wp (x\<acute>=(\<lambda>s. c) & G on T UNIV @ 0) \<lceil>Q\<rceil> =
\<lceil>\<lambda>s. \<forall>t\<in>T. (\<P> (\<lambda>t. s + t *\<^sub>R c) (down T t) \<subseteq> {s. G s}) \<longrightarrow> Q (s + t *\<^sub>R c)\<rceil>"
apply(subst local_flow.wp_g_ode[where f="\<lambda>s. c" and \<phi>="(\<lambda> t x. x + t *\<^sub>R c)"])
using line_is_local_flow assms by auto
lemma diff_solve_rule:
assumes "local_flow f T UNIV \<phi>"
and "\<forall>s. P s \<longrightarrow> (\<forall> t\<in>T. (\<P> (\<lambda>t. \<phi> t s) (down T t) \<subseteq> {s. G s}) \<longrightarrow> Q (\<phi> t s))"
shows "\<lceil>P\<rceil> \<le> wp (x\<acute>= f & G on T UNIV @ 0) \<lceil>Q\<rceil>"
using assms by(subst local_flow.wp_g_ode, auto)
lemma diff_weak_axiom:
"wp (x\<acute>= f & G on T S @ t\<^sub>0) \<lceil>Q\<rceil> = wp (x\<acute>= f & G on T S @ t\<^sub>0) \<lceil>\<lambda> s. G s \<longrightarrow> Q s\<rceil>"
unfolding wp_g_orbital image_def by force
lemma diff_weak_rule:
assumes "\<lceil>G\<rceil> \<le> \<lceil>Q\<rceil>"
shows "\<lceil>P\<rceil> \<le> wp (x\<acute>= f & G on T S @ t\<^sub>0) \<lceil>Q\<rceil>"
using assms apply(subst wp_rel)
by(auto simp: g_orbital_eq g_ode_def)
lemma wp_g_evol_IdD:
assumes "wp (x\<acute>= f & G on T S @ t\<^sub>0) \<lceil>C\<rceil> = Id"
and "\<forall>\<tau>\<in>(down T t). (s, x \<tau>) \<in> (x\<acute>= f & G on T S @ t\<^sub>0)"
shows "\<forall>\<tau>\<in>(down T t). C (x \<tau>)"
proof
fix \<tau> assume "\<tau> \<in> (down T t)"
hence "x \<tau> \<in> g_orbital f G T S t\<^sub>0 s"
using assms(2) unfolding g_ode_def by blast
also have "\<forall>y. y \<in> (g_orbital f G T S t\<^sub>0 s) \<longrightarrow> C y"
using assms(1) unfolding wp_rel g_ode_def by(auto simp: p2r_def)
ultimately show "C (x \<tau>)"
by blast
qed
lemma diff_cut_axiom:
assumes Thyp: "is_interval T" "t\<^sub>0 \<in> T"
and "wp (x\<acute>= f & G on T S @ t\<^sub>0) \<lceil>C\<rceil> = Id"
shows "wp (x\<acute>= f & G on T S @ t\<^sub>0) \<lceil>Q\<rceil> = wp (x\<acute>= f & (\<lambda>s. G s \<and> C s) on T S @ t\<^sub>0) \<lceil>Q\<rceil>"
proof(rule_tac f="\<lambda> x. wp x \<lceil>Q\<rceil>" in HOL.arg_cong, rule subset_antisym)
show "(x\<acute>=f & G on T S @ t\<^sub>0) \<subseteq> (x\<acute>=f & \<lambda>s. G s \<and> C s on T S @ t\<^sub>0)"
proof(clarsimp simp: g_ode_def)
fix s and s' assume "s' \<in> g_orbital f G T S t\<^sub>0 s"
then obtain \<tau>::real and X where x_ivp: "X \<in> Sols (\<lambda>t. f) T S t\<^sub>0 s"
and "X \<tau> = s'" and "\<tau> \<in> T" and guard_x:"(\<P> X (down T \<tau>) \<subseteq> {s. G s})"
using g_orbitalD[of s' "f" G T S t\<^sub>0 s] by blast
have "\<forall>t\<in>(down T \<tau>). \<P> X (down T t) \<subseteq> {s. G s}"
using guard_x by (force simp: image_def)
also have "\<forall>t\<in>(down T \<tau>). t \<in> T"
using \<open>\<tau> \<in> T\<close> Thyp by auto
ultimately have "\<forall>t\<in>(down T \<tau>). X t \<in> g_orbital f G T S t\<^sub>0 s"
using g_orbitalI[OF x_ivp] by (metis (mono_tags, lifting))
hence "\<forall>t\<in>(down T \<tau>). C (X t)"
using wp_g_evol_IdD[OF assms(3)] unfolding g_ode_def by blast
thus "s' \<in> g_orbital f (\<lambda>s. G s \<and> C s) T S t\<^sub>0 s"
using g_orbitalI[OF x_ivp \<open>\<tau> \<in> T\<close>] guard_x \<open>X \<tau> = s'\<close> by fastforce
qed
next show "(x\<acute>=f & \<lambda>s. G s \<and> C s on T S @ t\<^sub>0) \<subseteq> (x\<acute>=f & G on T S @ t\<^sub>0)"
by (auto simp: g_orbital_eq g_ode_def)
qed
lemma diff_cut_rule:
assumes Thyp: "is_interval T" "t\<^sub>0 \<in> T"
and wp_C: "\<lceil>P\<rceil> \<le> wp (x\<acute>= f & G on T S @ t\<^sub>0) \<lceil>C\<rceil>"
and wp_Q: "\<lceil>P\<rceil> \<subseteq> wp (x\<acute>= f & (\<lambda>s. G s \<and> C s) on T S @ t\<^sub>0) \<lceil>Q\<rceil>"
shows "\<lceil>P\<rceil> \<subseteq> wp (x\<acute>= f & G on T S @ t\<^sub>0) \<lceil>Q\<rceil>"
proof(subst wp_rel, simp add: g_orbital_eq p2r_def g_ode_def, clarsimp)
fix t::real and X::"real \<Rightarrow> 'a" and s assume "P s" and "t \<in> T"
and x_ivp:"X \<in> Sols (\<lambda>t. f) T S t\<^sub>0 s"
and guard_x:"\<forall>x. x \<in> T \<and> x \<le> t \<longrightarrow> G (X x)"
have "\<forall>t\<in>(down T t). X t \<in> g_orbital f G T S t\<^sub>0 s"
using g_orbitalI[OF x_ivp] guard_x by auto
hence "\<forall>t\<in>(down T t). C (X t)"
using wp_C \<open>P s\<close> by (subst (asm) wp_rel, auto simp: g_ode_def)
hence "X t \<in> g_orbital f (\<lambda>s. G s \<and> C s) T S t\<^sub>0 s"
using guard_x \<open>t \<in> T\<close> by (auto intro!: g_orbitalI x_ivp)
thus "Q (X t)"
using \<open>P s\<close> wp_Q by (subst (asm) wp_rel) (auto simp: g_ode_def)
qed
text \<open>The rules of dL\<close>
abbreviation g_global_ode ::"(('a::banach)\<Rightarrow>'a) \<Rightarrow> 'a pred \<Rightarrow> 'a rel" ("(1x\<acute>=_ & _)")
where "(x\<acute>= f & G) \<equiv> (x\<acute>= f & G on UNIV UNIV @ 0)"
abbreviation g_global_ode_inv :: "(('a::banach)\<Rightarrow>'a) \<Rightarrow> 'a pred \<Rightarrow> 'a pred \<Rightarrow> 'a rel"
("(1x\<acute>=_ & _ DINV _)") where "(x\<acute>= f & G DINV I) \<equiv> (x\<acute>= f & G on UNIV UNIV @ 0 DINV I)"
lemma DS:
fixes c::"'a::{heine_borel, banach}"
shows "wp (x\<acute>=(\<lambda>s. c) & G) \<lceil>Q\<rceil> = \<lceil>\<lambda>x. \<forall>t. (\<forall>\<tau>\<le>t. G (x + \<tau> *\<^sub>R c)) \<longrightarrow> Q (x + t *\<^sub>R c)\<rceil>"
by (subst diff_solve_axiom[of UNIV]) auto
lemma solve:
assumes "local_flow f UNIV UNIV \<phi>"
and "\<forall>s. P s \<longrightarrow> (\<forall>t. (\<forall>\<tau>\<le>t. G (\<phi> \<tau> s)) \<longrightarrow> Q (\<phi> t s))"
shows "\<lceil>P\<rceil> \<le> wp (x\<acute>= f & G) \<lceil>Q\<rceil>"
apply(rule diff_solve_rule[OF assms(1)])
using assms(2) by simp
lemma DW: "wp (x\<acute>= f & G) \<lceil>Q\<rceil> = wp (x\<acute>= f & G) \<lceil>\<lambda>s. G s \<longrightarrow> Q s\<rceil>"
by (rule diff_weak_axiom)
lemma DC:
assumes "wp (x\<acute>= f & G) \<lceil>C\<rceil> = Id"
shows "wp (x\<acute>= f & G) \<lceil>Q\<rceil> = wp (x\<acute>= f & (\<lambda>s. G s \<and> C s)) \<lceil>Q\<rceil>"
apply (rule diff_cut_axiom)
using assms by auto
lemma dC:
assumes "\<lceil>P\<rceil> \<le> wp (x\<acute>= f & G) \<lceil>C\<rceil>"
and "\<lceil>P\<rceil> \<le> wp (x\<acute>= f & (\<lambda>s. G s \<and> C s)) \<lceil>Q\<rceil>"
shows "\<lceil>P\<rceil> \<le> wp (x\<acute>= f & G) \<lceil>Q\<rceil>"
apply(rule diff_cut_rule)
using assms by auto
end |
lemma adjoint_clauses: fixes f :: "'n::euclidean_space \<Rightarrow> 'm::euclidean_space" assumes lf: "linear f" shows "x \<bullet> adjoint f y = f x \<bullet> y" and "adjoint f y \<bullet> x = y \<bullet> f x" |
%Computes the position difference in meters between two coordinates defined
%with Llh.
%Inputs:
%ref=[Lat, lon, height]' of reference.
%height=[h1;h2;...;hn] where n is the number of coordinate
%hpos must be oneof the following: (each position must be on a new row)
%hpos=3rd row of Cen=[-cos(Lat)cos(lon) -cos(Lat)sin(lon) -sin(Lat)];
%or
%hpos=[Lat lon]
%Output: Metric difference between corrdinates defined in the nav frame of
%reference.
function metricdif=posdiff(hpos, height, ref)
E_SQR=0.00669437999014;
SM_AXIS=6378137;
%Convert ref into ecef and compute Cen(ref)
sL=sin(ref(1));
cL=cos(ref(1));
sl=sin(ref(2));
cl=cos(ref(2));
h=ref(3);
Re=SM_AXIS/(sqrt(1.0-E_SQR*sL*sL));
refECEF=[(Re+h)*cL*cl (Re+h)*cL*sl (Re*(1-E_SQR)+h)*sL];
CenRef=[-sL*cl -sL*sl cL;-sl cl 0;-cL*cl -cL*sl -sL];
%%%%Convert hpos to ecef
%Be sure that hpos and height is in correct order
if (size(height,2)>size(height,1))
height=height';
hpos=hpos';
end
%Compute the normal to the elipsoid in ECEF frame
if size(hpos,2)==2 %hpos is defined as lat/lon. Convert it to 3rd row of Cen
normal=[-cos(hpos(:,1)).*cos(hpos(:,2)) -cos(hpos(:,1)).*sin(hpos(:,2)) -sin(hpos(:,1))];
elseif (size(hpos,2)==3) %hpos is defined
normal=hpos;
end
Re=SM_AXIS./(1.0-E_SQR*normal(:,3).^2).^0.5;
%Compute ecef coordinates
posECEF=-[(Re+height).*normal(:,1) (Re+height).*normal(:,2) (Re*(1-E_SQR)+height).*normal(:,3)];
%Difference
metricdif=(posECEF-ones(size(posECEF,1),1)*refECEF)*CenRef';
|
using Blink
using Test
# IMPORTANT: Window(...) cannot appear inside of a @testset for as-of-yet
# unknown reasons.
w = Window(Blink.@d(:show => false, :width=>150, :height=>100), async=false);
@testset "size Tests" begin
@test size(w) == [150,100]
size(w, 200,200)
@test size(w) == [200,200]
end
# @testset "async" begin
# # Test that async Window() creation is faster than synchronous creation.
# # (Repeat the test a few times, just to be sure it's consistent.)
# for _ in 1:5
# (@timed Window(Blink.@d(:show => false), async=true))[2] <
# (@timed Window(Blink.@d(:show => false), async=false))[2]
# end
# # end
|
Fleetwood Mac unveiled a massive Deluxe Edition of its revered double album Tusk late last year that featured 22 previously unreleased live performances selected from the band’s 1979-80 tour. Until now, those concert recordings have only been available as part of the set and only on CD and digitally. That will change soon with the release of Fleetwood Mac: In Concert.
All of the live music from the 2015 reissue of Tusk will be available on March 4th from Warner Bros. Records as a three-LP set. Pressed on 180-gram vinyl, the albums will be presented in a tri-fold jacket and available for a suggested list price of $59.98.
Mick Fleetwood, John McVie, Christine McVie, Lindsey Buckingham and Stevie Nicks originally released Tusk in October of 1979. The Grammy Award-nominated, double-album went onto sell more than four million copies worldwide and introduced fans to hits like “Sara,” “Think About Me,” and the title track.
The music heard on In Concert was recorded at four stops during the band’s 111-show world tour promoting Tusk. This new collection serves as a worthy companion to the classic 1980 album Live. Although a few songs are duplicated from that album, including “Say You Love Me,” “Landslide” and “Go Your Own Way,” each performance on In Concert is unique and taken from a different show.
In Concert boasts ten songs not heard on Live, including “World Turning” from the Fleetwood Mac’s 1975 self-titled release, and “The Chain” from the band’s best-selling album Rumours (1977), a Grammy-award winning juggernaut that has sold more than 40 million copies. |
##### Copyright 2020 The TensorFlow Authors.
```python
#@title 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
#
# https://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.
```
# Quantum data
<table class="tfo-notebook-buttons" align="left">
<td>
<a target="_blank" href="https://www.tensorflow.org/quantum/tutorials/quantum_data">View on TensorFlow.org</a>
</td>
<td>
<a target="_blank" href="https://colab.research.google.com/github/tensorflow/quantum/blob/master/docs/tutorials/quantum_data.ipynb">Run in Google Colab</a>
</td>
<td>
<a target="_blank" href="https://github.com/tensorflow/quantum/blob/master/docs/tutorials/quantum_data.ipynb">View source on GitHub</a>
</td>
<td>
<a href="https://storage.googleapis.com/tensorflow_docs/quantum/docs/tutorials/quantum_data.ipynb">Download notebook</a>
</td>
</table>
Building off of the comparisons made in the [MNIST](https://www.tensorflow.org/quantum/tutorials/mnist) tutorial, this tutorial explores the recent work of [Huang et al.](https://arxiv.org/abs/2011.01938) that shows how different datasets affect performance comparisons. In the work, the authors seek to understand how and when classical machine learning models can learn as well as (or better than) quantum models. The work also showcases an empirical performance separation between classical and quantum machine learning model via a carefully crafted dataset. You will:
1. Prepare a reduced dimension Fashion-MNIST dataset.
2. Use quantum circuits to re-label the dataset and compute Projected Quantum Kernel features (PQK).
3. Train a classical neural network on the re-labeled dataset and compare the performance with a model that has access to the PQK features.
## Setup
```python
!pip -q install tensorflow==2.3.1 tensorflow-quantum
```
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
```python
import cirq
import sympy
import numpy as np
import tensorflow as tf
import tensorflow_quantum as tfq
# visualization tools
%matplotlib inline
import matplotlib.pyplot as plt
from cirq.contrib.svg import SVGCircuit
np.random.seed(1234)
```
## 1. Data preparation
You will begin by preparing the fashion-MNIST dataset for running on a quantum computer.
### 1.1 Download fashion-MNIST
The first step is to get the traditional fashion-mnist dataset. This can be done using the `tf.keras.datasets` module.
```python
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.fashion_mnist.load_data()
# Rescale the images from [0,255] to the [0.0,1.0] range.
x_train, x_test = x_train/255.0, x_test/255.0
print("Number of original training examples:", len(x_train))
print("Number of original test examples:", len(x_test))
```
Number of original training examples: 60000
Number of original test examples: 10000
Filter the dataset to keep just the T-shirts/tops and dresses, remove the other classes. At the same time convert the label, `y`, to boolean: True for 0 and False for 3.
```python
def filter_03(x, y):
keep = (y == 0) | (y == 3)
x, y = x[keep], y[keep]
y = y == 0
return x,y
```
```python
x_train, y_train = filter_03(x_train, y_train)
x_test, y_test = filter_03(x_test, y_test)
print("Number of filtered training examples:", len(x_train))
print("Number of filtered test examples:", len(x_test))
```
Number of filtered training examples: 12000
Number of filtered test examples: 2000
```python
print(y_train[0])
plt.imshow(x_train[0, :, :])
plt.colorbar()
```
### 1.2 Downscale the images
Just like the MNIST example, you will need to downscale these images in order to be within the boundaries for current quantum computers. This time however you will use a PCA transformation to reduce the dimensions instead of a `tf.image.resize` operation.
```python
def truncate_x(x_train, x_test, n_components=10):
"""Perform PCA on image dataset keeping the top `n_components` components."""
n_points_train = tf.gather(tf.shape(x_train), 0)
n_points_test = tf.gather(tf.shape(x_test), 0)
# Flatten to 1D
x_train = tf.reshape(x_train, [n_points_train, -1])
x_test = tf.reshape(x_test, [n_points_test, -1])
# Normalize.
feature_mean = tf.reduce_mean(x_train, axis=0)
x_train_normalized = x_train - feature_mean
x_test_normalized = x_test - feature_mean
# Truncate.
e_values, e_vectors = tf.linalg.eigh(
tf.einsum('ji,jk->ik', x_train_normalized, x_train_normalized))
return tf.einsum('ij,jk->ik', x_train_normalized, e_vectors[:,-n_components:]), \
tf.einsum('ij,jk->ik', x_test_normalized, e_vectors[:, -n_components:])
```
```python
DATASET_DIM = 10
x_train, x_test = truncate_x(x_train, x_test, n_components=DATASET_DIM)
print(f'New datapoint dimension:', len(x_train[0]))
```
New datapoint dimension: 10
The last step is to reduce the size of the dataset to just 1000 training datapoints and 200 testing datapoints.
```python
N_TRAIN = 1000
N_TEST = 200
x_train, x_test = x_train[:N_TRAIN], x_test[:N_TEST]
y_train, y_test = y_train[:N_TRAIN], y_test[:N_TEST]
```
```python
print("New number of training examples:", len(x_train))
print("New number of test examples:", len(x_test))
```
New number of training examples: 1000
New number of test examples: 200
## 2. Relabeling and computing PQK features
You will now prepare a "stilted" quantum dataset by incorporating quantum components and re-labeling the truncated fashion-MNIST dataset you've created above. In order to get the most seperation between quantum and classical methods, you will first prepare the PQK features and then relabel outputs based on their values.
### 2.1 Quantum encoding and PQK features
You will create a new set of features, based on `x_train`, `y_train`, `x_test` and `y_test` that is defined to be the 1-RDM on all qubits of:
$V(x_{\text{train}} / n_{\text{trotter}}) ^ {n_{\text{trotter}}} U_{\text{1qb}} | 0 \rangle$
Where $U_\text{1qb}$ is a wall of single qubit rotations and $V(\hat{\theta}) = e^{-i\sum_i \hat{\theta_i} (X_i X_{i+1} + Y_i Y_{i+1} + Z_i Z_{i+1})}$
First, you can generate the wall of single qubit rotations:
```python
def single_qubit_wall(qubits, rotations):
"""Prepare a single qubit X,Y,Z rotation wall on `qubits`."""
wall_circuit = cirq.Circuit()
for i, qubit in enumerate(qubits):
for j, gate in enumerate([cirq.X, cirq.Y, cirq.Z]):
wall_circuit.append(gate(qubit) ** rotations[i][j])
return wall_circuit
```
You can quickly verify this works by looking at the circuit:
```python
SVGCircuit(single_qubit_wall(
cirq.GridQubit.rect(1,4), np.random.uniform(size=(4, 3))))
```
Next you can prepare $V(\hat{\theta})$ with the help of `tfq.util.exponential` which can exponentiate any commuting `cirq.PauliSum` objects:
```python
def v_theta(qubits):
"""Prepares a circuit that generates V(\theta)."""
ref_paulis = [
cirq.X(q0) * cirq.X(q1) + \
cirq.Y(q0) * cirq.Y(q1) + \
cirq.Z(q0) * cirq.Z(q1) for q0, q1 in zip(qubits, qubits[1:])
]
exp_symbols = list(sympy.symbols('ref_0:'+str(len(ref_paulis))))
return tfq.util.exponential(ref_paulis, exp_symbols), exp_symbols
```
This circuit might be a little bit harder to verify by looking at, but you can still examine a two qubit case to see what is happening:
```python
test_circuit, test_symbols = v_theta(cirq.GridQubit.rect(1, 2))
print(f'Symbols found in circuit:{test_symbols}')
SVGCircuit(test_circuit)
```
Symbols found in circuit:[ref_0]
Now you have all the building blocks you need to put your full encoding circuits together:
```python
def prepare_pqk_circuits(qubits, classical_source, n_trotter=10):
"""Prepare the pqk feature circuits around a dataset."""
n_qubits = len(qubits)
n_points = len(classical_source)
# Prepare random single qubit rotation wall.
random_rots = np.random.uniform(-2, 2, size=(n_qubits, 3))
initial_U = single_qubit_wall(qubits, random_rots)
# Prepare parametrized V
V_circuit, symbols = v_theta(qubits)
exp_circuit = cirq.Circuit(V_circuit for t in range(n_trotter))
# Convert to `tf.Tensor`
initial_U_tensor = tfq.convert_to_tensor([initial_U])
initial_U_splat = tf.tile(initial_U_tensor, [n_points])
full_circuits = tfq.layers.AddCircuit()(
initial_U_splat, append=exp_circuit)
# Replace placeholders in circuits with values from `classical_source`.
return tfq.resolve_parameters(
full_circuits, tf.convert_to_tensor([str(x) for x in symbols]),
tf.convert_to_tensor(classical_source*(n_qubits/3)/n_trotter))
```
Choose some qubits and prepare the data encoding circuits:
```python
qubits = cirq.GridQubit.rect(1, DATASET_DIM + 1)
q_x_train_circuits = prepare_pqk_circuits(qubits, x_train)
q_x_test_circuits = prepare_pqk_circuits(qubits, x_test)
```
Next, compute the PQK features based on the 1-RDM of the dataset circuits above and store the results in `rdm`, a `tf.Tensor` with shape `[n_points, n_qubits, 3]`. The entries in `rdm[i][j][k]` = $\langle \psi_i | OP^k_j | \psi_i \rangle$ where `i` indexes over datapoints, `j` indexes over qubits and `k` indexes over $\lbrace \hat{X}, \hat{Y}, \hat{Z} \rbrace$ .
```python
def get_pqk_features(qubits, data_batch):
"""Get PQK features based on above construction."""
ops = [[cirq.X(q), cirq.Y(q), cirq.Z(q)] for q in qubits]
ops_tensor = tf.expand_dims(tf.reshape(tfq.convert_to_tensor(ops), -1), 0)
batch_dim = tf.gather(tf.shape(data_batch), 0)
ops_splat = tf.tile(ops_tensor, [batch_dim, 1])
exp_vals = tfq.layers.Expectation()(data_batch, operators=ops_splat)
rdm = tf.reshape(exp_vals, [batch_dim, len(qubits), -1])
return rdm
```
```python
x_train_pqk = get_pqk_features(qubits, q_x_train_circuits)
x_test_pqk = get_pqk_features(qubits, q_x_test_circuits)
print('New PQK training dataset has shape:', x_train_pqk.shape)
print('New PQK testing dataset has shape:', x_test_pqk.shape)
```
New PQK training dataset has shape: (1000, 11, 3)
New PQK testing dataset has shape: (200, 11, 3)
### 2.2 Re-labeling based on PQK features
Now that you have these quantum generated features in `x_train_pqk` and `x_test_pqk`, it is time to re-label the dataset. To achieve maximum seperation between quantum and classical performance you can re-label the dataset based on the spectrum information found in `x_train_pqk` and `x_test_pqk`.
Note: This preparation of your dataset to explicitly maximize the seperation in performance between the classical and quantum models might feel like cheating, but it provides a **very** important proof of existance for datasets that are hard for classical computers and easy for quantum computers to model. There would be no point in searching for quantum advantage in QML if you couldn't first create something like this to demonstrate advantage.
```python
def compute_kernel_matrix(vecs, gamma):
"""Computes d[i][j] = e^ -gamma * (vecs[i] - vecs[j]) ** 2 """
scaled_gamma = gamma / (
tf.cast(tf.gather(tf.shape(vecs), 1), tf.float32) * tf.math.reduce_std(vecs))
return scaled_gamma * tf.einsum('ijk->ij',(vecs[:,None,:] - vecs) ** 2)
def get_spectrum(datapoints, gamma=1.0):
"""Compute the eigenvalues and eigenvectors of the kernel of datapoints."""
KC_qs = compute_kernel_matrix(datapoints, gamma)
S, V = tf.linalg.eigh(KC_qs)
S = tf.math.abs(S)
return S, V
```
```python
S_pqk, V_pqk = get_spectrum(
tf.reshape(tf.concat([x_train_pqk, x_test_pqk], 0), [-1, len(qubits) * 3]))
S_original, V_original = get_spectrum(
tf.cast(tf.concat([x_train, x_test], 0), tf.float32), gamma=0.005)
print('Eigenvectors of pqk kernel matrix:', V_pqk)
print('Eigenvectors of original kernel matrix:', V_original)
```
Eigenvectors of pqk kernel matrix: tf.Tensor(
[[-2.09569391e-02 1.05973557e-02 2.16634180e-02 ... 2.80352887e-02
1.55521873e-02 2.82677952e-02]
[-2.29303762e-02 4.66355234e-02 7.91163836e-03 ... -6.14174758e-04
-7.07804322e-01 2.85902526e-02]
[-1.77853629e-02 -3.00758495e-03 -2.55225878e-02 ... -2.40783971e-02
2.11018627e-03 2.69009806e-02]
...
[ 6.05797209e-02 1.32483775e-02 2.69536003e-02 ... -1.38843581e-02
3.05043962e-02 3.85345481e-02]
[ 6.33309558e-02 -3.04112374e-03 9.77444276e-03 ... 7.48321265e-02
3.42793856e-03 3.67484428e-02]
[ 5.86028099e-02 5.84433973e-03 2.64811981e-03 ... 2.82612257e-02
-3.80136147e-02 3.29943895e-02]], shape=(1200, 1200), dtype=float32)
Eigenvectors of original kernel matrix: tf.Tensor(
[[ 0.03835681 0.0283473 -0.01169789 ... 0.02343717 0.0211248
0.03206972]
[-0.04018159 0.00888097 -0.01388255 ... 0.00582427 0.717551
0.02881948]
[-0.0166719 0.01350376 -0.03663862 ... 0.02467175 -0.00415936
0.02195409]
...
[-0.03015648 -0.01671632 -0.01603392 ... 0.00100583 -0.00261221
0.02365689]
[ 0.0039777 -0.04998879 -0.00528336 ... 0.01560401 -0.04330755
0.02782002]
[-0.01665728 -0.00818616 -0.0432341 ... 0.00088256 0.00927396
0.01875088]], shape=(1200, 1200), dtype=float32)
Now you have everything you need to re-label the dataset! Now you can consult with the flowchart to better understand how to maximize performance seperation when re-labeling the dataset:
In order to maximize the seperation between quantum and classical models, you will attempt to maximize the geometric difference between the original dataset and the PQK features kernel matrices $g(K_1 || K_2) = \sqrt{ || \sqrt{K_2} K_1^{-1} \sqrt{K_2} || _\infty}$ using `S_pqk, V_pqk` and `S_original, V_original`. A large value of $g$ ensures that you initially move to the right in the flowchart down towards a prediction advantage in the quantum case.
Note: Computing quantities for $s$ and $d$ are also very useful when looking to better understand performance seperations. In this case ensuring a large $g$ value is enough to see performance seperation.
```python
def get_stilted_dataset(S, V, S_2, V_2, lambdav=1.1):
"""Prepare new labels that maximize geometric distance between kernels."""
S_diag = tf.linalg.diag(S ** 0.5)
S_2_diag = tf.linalg.diag(S_2 / (S_2 + lambdav) ** 2)
scaling = S_diag @ tf.transpose(V) @ \
V_2 @ S_2_diag @ tf.transpose(V_2) @ \
V @ S_diag
# Generate new lables using the largest eigenvector.
_, vecs = tf.linalg.eig(scaling)
new_labels = tf.math.real(
tf.einsum('ij,j->i', tf.cast(V @ S_diag, tf.complex64), vecs[-1])).numpy()
# Create new labels and add some small amount of noise.
final_y = new_labels > np.median(new_labels)
noisy_y = (final_y ^ (np.random.uniform(size=final_y.shape) > 0.95))
return noisy_y
```
```python
y_relabel = get_stilted_dataset(S_pqk, V_pqk, S_original, V_original)
y_train_new, y_test_new = y_relabel[:N_TRAIN], y_relabel[N_TRAIN:]
```
## 3. Comparing models
Now that you have prepared your dataset it is time to compare model performance. You will create two small feedforward neural networks and compare performance when they are given access to the PQK features found in `x_train_pqk`.
### 3.1 Create PQK enhanced model
Using standard `tf.keras` library features you can now create and a train a model on the `x_train_pqk` and `y_train_new` datapoints:
```python
#docs_infra: no_execute
def create_pqk_model():
model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(32, activation='sigmoid', input_shape=[len(qubits) * 3,]))
model.add(tf.keras.layers.Dense(16, activation='sigmoid'))
model.add(tf.keras.layers.Dense(1))
return model
pqk_model = create_pqk_model()
pqk_model.compile(loss=tf.keras.losses.BinaryCrossentropy(from_logits=True),
optimizer=tf.keras.optimizers.Adam(learning_rate=0.003),
metrics=['accuracy'])
pqk_model.summary()
```
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
dense (Dense) (None, 32) 1088
_________________________________________________________________
dense_1 (Dense) (None, 16) 528
_________________________________________________________________
dense_2 (Dense) (None, 1) 17
=================================================================
Total params: 1,633
Trainable params: 1,633
Non-trainable params: 0
_________________________________________________________________
```python
#docs_infra: no_execute
pqk_history = pqk_model.fit(tf.reshape(x_train_pqk, [N_TRAIN, -1]),
y_train_new,
batch_size=32,
epochs=1000,
verbose=0,
validation_data=(tf.reshape(x_test_pqk, [N_TEST, -1]), y_test_new))
```
### 3.2 Create a classical model
Similar to the code above you can now also create a classical model that doesn't have access to the PQK features in your stilted dataset. This model can be trained using `x_train` and `y_label_new`.
```python
#docs_infra: no_execute
def create_fair_classical_model():
model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(32, activation='sigmoid', input_shape=[DATASET_DIM,]))
model.add(tf.keras.layers.Dense(16, activation='sigmoid'))
model.add(tf.keras.layers.Dense(1))
return model
model = create_fair_classical_model()
model.compile(loss=tf.keras.losses.BinaryCrossentropy(from_logits=True),
optimizer=tf.keras.optimizers.Adam(learning_rate=0.03),
metrics=['accuracy'])
model.summary()
```
Model: "sequential_1"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
dense_3 (Dense) (None, 32) 352
_________________________________________________________________
dense_4 (Dense) (None, 16) 528
_________________________________________________________________
dense_5 (Dense) (None, 1) 17
=================================================================
Total params: 897
Trainable params: 897
Non-trainable params: 0
_________________________________________________________________
```python
#docs_infra: no_execute
classical_history = model.fit(x_train,
y_train_new,
batch_size=32,
epochs=1000,
verbose=0,
validation_data=(x_test, y_test_new))
```
### 3.3 Compare performance
Now that you have trained the two models you can quickly plot the performance gaps in the validation data between the two. Typically both models will achieve > 0.9 accuaracy on the training data. However on the validation data it becomes clear that only the information found in the PQK features is enough to make the model generalize well to unseen instances.
```python
#docs_infra: no_execute
plt.figure(figsize=(10,5))
plt.plot(classical_history.history['accuracy'], label='accuracy_classical')
plt.plot(classical_history.history['val_accuracy'], label='val_accuracy_classical')
plt.plot(pqk_history.history['accuracy'], label='accuracy_quantum')
plt.plot(pqk_history.history['val_accuracy'], label='val_accuracy_quantum')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.legend()
```
Success: You have engineered a stilted quantum dataset that can intentionally defeat classical models in a fair (but contrived) setting. Try comparing results using other types of classical models. The next step is to try and see if you can find new and interesting datasets that can defeat classical models without needing to engineer them yourself!
## 4. Important conclusions
There are several important conclusions you can draw from this and the [MNIST](https://www.tensorflow.org/quantum/tutorials/mnist) experiments:
1. It's very unlikely that the quantum models of today will beat classical model performance on classical data. Especially on today's classical datasets that can have upwards of a million datapoints.
2. Just because the data might come from a hard to classically simulate quantum circuit, doesn't necessarily make the data hard to learn for a classical model.
3. Datasets (ultimately quantum in nature) that are easy for quantum models to learn and hard for classical models to learn do exist, regardless of model architecture or training algorithms used.
|
function item = setval(item, val, dflag)
% function item = setval(item, val, dflag)
% set item.val{1} to val. Validity checks are performed through subsasgn.
% If val == {}, set item.val to {}.
% If dflag is true, and item.def is not empty, set the default setting for
% this item instead by calling feval(item.def{:}, val). If val == {}, use
% the string '<UNDEFINED>' as in a harvested tree. If dflag is true, but
% no item.def defined, set item.val{1} instead.
%
% This code is part of a batch job configuration system for MATLAB. See
% help matlabbatch
% for a general overview.
%_______________________________________________________________________
% Copyright (C) 2007 Freiburg Brain Imaging
% Volkmar Glauche
% $Id: setval.m 5678 2013-10-11 14:58:04Z volkmar $
rev = '$Rev: 5678 $'; %#ok
if iscell(val) && isempty(val)
if dflag
if ~isempty(item.def)
try
feval(item.def, {'<UNDEFINED>'});
catch
cfg_message('matlabbatch:setval:defaults', ...
'%s: unable to set default value.', ...
subsasgn_checkstr(item, substruct('.','val')));
end
else
item = subsasgn(item, substruct('.','val'), {});
end
else
item = subsasgn(item, substruct('.','val'), {});
end
else
if dflag
[sts, val1] = subsasgn_check(item, substruct('.','val'), {val});
if sts
if ~isempty(item.def)
try
feval(item.def, val1);
catch
cfg_message('matlabbatch:setval:defaults', ...
'%s: unable to set default value.', ...
subsasgn_checkstr(item, substruct('.','val')));
end
else
item = subsasgn(item, substruct('.','val'), {val});
end
end
else
item = subsasgn(item, substruct('.','val'), {val});
end
end
|
module ElemCount
import Data.Vect
import Sortings
%default total
count : Eq a => a -> Vect n a -> Fin (S n)
count _ Nil = 0
count x (y :: xs) = (if x == y then FS else weaken) $ count x xs
data ElemCount : Fin (S n) -> a -> Vect n a -> Type where
NoElem : ElemCount FZ x []
IncHere : ElemCount c x xs -> ElemCount (FS c) x (x :: xs)
IncThere : ElemCount c x xs -> Not (x = y) -> ElemCount (weaken c) x (y :: xs)
-- A variant with non-structural equality
--IncThere : Eq a => {x, y : a} -> ElemCount c x xs -> Not (So (x == y)) -> ElemCount (weaken c) x (y :: xs)
-- TODO To define permutation through `ElemCount` (probably, the structural one)
-- TODO and prove equivalence with the structurally defined permutation property.
(+) : Fin (S n) -> Fin (S m) -> Fin (S $ n + m)
(+) {m} x FZ = weakenN m x
(+) {n} {m} x (FS y) = rewrite plusSuccRightSucc n m in FS (x + y)
ecConcPresSum : ElemCount ca x as -> ElemCount cb x bs -> ElemCount (ca + cb) x (as ++ bs)
ecConcPresSum = ?ecConcPresSum_impl
||| Proof that permutationproperty preserves elements (i.e. preserves elements count)
permPresElems : Permutation xs ys -> ElemCount n e xs -> ElemCount n e ys
permPresElems EmptyPerm ec = ec
permPresElems {xs=a::as} (InsertPerm ip) (IncHere iec) = ?perm_here
permPresElems (InsertPerm ip) (IncThere iec xy) = ?perm_there
|
interface Foo m where
bar : k -> v -> m k v -> m k v
-- This is kind of meaningless, except it exposes a potential error where
-- (\s, t => List (s, t)) is substituted in as 'm' in 'm k v' and the ks
-- clash, so one has to be renamed.
Eq k => Foo (\s, t => List (s, t)) where
bar x y z = ?bang
|
The complex conjugate of the complex conjugate of $z$ is $z$. |
The quotient of a fraction is equal to the fraction itself. |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import order.bounded_order
/-!
# Disjointness and complements
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines `disjoint`, `codisjoint`, and the `is_compl` predicate.
## Main declarations
* `disjoint x y`: two elements of a lattice are disjoint if their `inf` is the bottom element.
* `codisjoint x y`: two elements of a lattice are codisjoint if their `join` is the top element.
* `is_compl x y`: In a bounded lattice, predicate for "`x` is a complement of `y`". Note that in a
non distributive lattice, an element can have several complements.
* `complemented_lattice α`: Typeclass stating that any element of a lattice has a complement.
-/
variable {α : Type*}
section disjoint
section partial_order_bot
variables [partial_order α] [order_bot α] {a b c d : α}
/-- Two elements of a lattice are disjoint if their inf is the bottom element.
(This generalizes disjoint sets, viewed as members of the subset lattice.)
Note that we define this without reference to `⊓`, as this allows us to talk about orders where
the infimum is not unique, or where implementing `has_inf` would require additional `decidable`
arguments. -/
def disjoint (a b : α) : Prop := ∀ ⦃x⦄, x ≤ a → x ≤ b → x ≤ ⊥
lemma disjoint.comm : disjoint a b ↔ disjoint b a := forall_congr $ λ _, forall_swap
@[symm] lemma disjoint.symm ⦃a b : α⦄ : disjoint a b → disjoint b a := disjoint.comm.1
lemma symmetric_disjoint : symmetric (disjoint : α → α → Prop) := disjoint.symm
@[simp] lemma disjoint_bot_left : disjoint ⊥ a := λ x hbot ha, hbot
@[simp] lemma disjoint_bot_right : disjoint a ⊥ := λ x ha hbot, hbot
lemma disjoint.mono (h₁ : a ≤ b) (h₂ : c ≤ d) : disjoint b d → disjoint a c :=
λ h x ha hc, h (ha.trans h₁) (hc.trans h₂)
lemma disjoint.mono_left (h : a ≤ b) : disjoint b c → disjoint a c := disjoint.mono h le_rfl
lemma disjoint.mono_right : b ≤ c → disjoint a c → disjoint a b := disjoint.mono le_rfl
@[simp] lemma disjoint_self : disjoint a a ↔ a = ⊥ :=
⟨λ hd, bot_unique $ hd le_rfl le_rfl, λ h x ha hb, ha.trans_eq h⟩
/- TODO: Rename `disjoint.eq_bot` to `disjoint.inf_eq` and `disjoint.eq_bot_of_self` to
`disjoint.eq_bot` -/
alias disjoint_self ↔ disjoint.eq_bot_of_self _
lemma disjoint.ne (ha : a ≠ ⊥) (hab : disjoint a b) : a ≠ b :=
λ h, ha $ disjoint_self.1 $ by rwa ←h at hab
lemma disjoint.eq_bot_of_le (hab : disjoint a b) (h : a ≤ b) : a = ⊥ :=
eq_bot_iff.2 $ hab le_rfl h
lemma disjoint.eq_bot_of_ge (hab : disjoint a b) : b ≤ a → b = ⊥ := hab.symm.eq_bot_of_le
end partial_order_bot
section partial_bounded_order
variables [partial_order α] [bounded_order α] {a : α}
@[simp] theorem disjoint_top : disjoint a ⊤ ↔ a = ⊥ :=
⟨λ h, bot_unique $ h le_rfl le_top, λ h x ha htop, ha.trans_eq h⟩
@[simp] theorem top_disjoint : disjoint ⊤ a ↔ a = ⊥ :=
⟨λ h, bot_unique $ h le_top le_rfl, λ h x htop ha, ha.trans_eq h⟩
end partial_bounded_order
section semilattice_inf_bot
variables [semilattice_inf α] [order_bot α] {a b c d : α}
lemma disjoint_iff_inf_le : disjoint a b ↔ a ⊓ b ≤ ⊥ :=
⟨λ hd, hd inf_le_left inf_le_right, λ h x ha hb, (le_inf ha hb).trans h⟩
lemma disjoint_iff : disjoint a b ↔ a ⊓ b = ⊥ := disjoint_iff_inf_le.trans le_bot_iff
lemma disjoint.le_bot : disjoint a b → a ⊓ b ≤ ⊥ := disjoint_iff_inf_le.mp
lemma disjoint.eq_bot : disjoint a b → a ⊓ b = ⊥ := bot_unique ∘ disjoint.le_bot
lemma disjoint_assoc : disjoint (a ⊓ b) c ↔ disjoint a (b ⊓ c) :=
by rw [disjoint_iff_inf_le, disjoint_iff_inf_le, inf_assoc]
lemma disjoint_left_comm : disjoint a (b ⊓ c) ↔ disjoint b (a ⊓ c) :=
by simp_rw [disjoint_iff_inf_le, inf_left_comm]
lemma disjoint_right_comm : disjoint (a ⊓ b) c ↔ disjoint (a ⊓ c) b :=
by simp_rw [disjoint_iff_inf_le, inf_right_comm]
variables (c)
lemma disjoint.inf_left (h : disjoint a b) : disjoint (a ⊓ c) b := h.mono_left inf_le_left
lemma disjoint.inf_left' (h : disjoint a b) : disjoint (c ⊓ a) b := h.mono_left inf_le_right
lemma disjoint.inf_right (h : disjoint a b) : disjoint a (b ⊓ c) := h.mono_right inf_le_left
lemma disjoint.inf_right' (h : disjoint a b) : disjoint a (c ⊓ b) := h.mono_right inf_le_right
variables {c}
lemma disjoint.of_disjoint_inf_of_le (h : disjoint (a ⊓ b) c) (hle : a ≤ c) : disjoint a b :=
disjoint_iff.2 $ h.eq_bot_of_le $ inf_le_of_left_le hle
lemma disjoint.of_disjoint_inf_of_le' (h : disjoint (a ⊓ b) c) (hle : b ≤ c) : disjoint a b :=
disjoint_iff.2 $ h.eq_bot_of_le $ inf_le_of_right_le hle
end semilattice_inf_bot
section distrib_lattice_bot
variables [distrib_lattice α] [order_bot α] {a b c : α}
@[simp] lemma disjoint_sup_left : disjoint (a ⊔ b) c ↔ disjoint a c ∧ disjoint b c :=
by simp only [disjoint_iff, inf_sup_right, sup_eq_bot_iff]
@[simp] lemma disjoint_sup_right : disjoint a (b ⊔ c) ↔ disjoint a b ∧ disjoint a c :=
by simp only [disjoint_iff, inf_sup_left, sup_eq_bot_iff]
lemma disjoint.sup_left (ha : disjoint a c) (hb : disjoint b c) : disjoint (a ⊔ b) c :=
disjoint_sup_left.2 ⟨ha, hb⟩
lemma disjoint.sup_right (hb : disjoint a b) (hc : disjoint a c) : disjoint a (b ⊔ c) :=
disjoint_sup_right.2 ⟨hb, hc⟩
lemma disjoint.left_le_of_le_sup_right (h : a ≤ b ⊔ c) (hd : disjoint a c) : a ≤ b :=
le_of_inf_le_sup_le (le_trans hd.le_bot bot_le) $ sup_le h le_sup_right
lemma disjoint.left_le_of_le_sup_left (h : a ≤ c ⊔ b) (hd : disjoint a c) : a ≤ b :=
hd.left_le_of_le_sup_right $ by rwa sup_comm
end distrib_lattice_bot
end disjoint
section codisjoint
section partial_order_top
variables [partial_order α] [order_top α] {a b c d : α}
/-- Two elements of a lattice are codisjoint if their sup is the top element.
Note that we define this without reference to `⊔`, as this allows us to talk about orders where
the supremum is not unique, or where implement `has_sup` would require additional `decidable`
arguments. -/
def codisjoint (a b : α) : Prop := ∀ ⦃x⦄, a ≤ x → b ≤ x → ⊤ ≤ x
lemma codisjoint.comm : codisjoint a b ↔ codisjoint b a := forall_congr $ λ _, forall_swap
@[symm] lemma codisjoint.symm ⦃a b : α⦄ : codisjoint a b → codisjoint b a := codisjoint.comm.1
lemma symmetric_codisjoint : symmetric (codisjoint : α → α → Prop) := codisjoint.symm
@[simp] lemma codisjoint_top_left : codisjoint ⊤ a := λ x htop ha, htop
@[simp] lemma codisjoint_top_right : codisjoint a ⊤ := λ x ha htop, htop
lemma codisjoint.mono (h₁ : a ≤ b) (h₂ : c ≤ d) : codisjoint a c → codisjoint b d :=
λ h x ha hc, h (h₁.trans ha) (h₂.trans hc)
lemma codisjoint.mono_left (h : a ≤ b) : codisjoint a c → codisjoint b c :=
codisjoint.mono h le_rfl
lemma codisjoint.mono_right : b ≤ c → codisjoint a b → codisjoint a c :=
codisjoint.mono le_rfl
@[simp] lemma codisjoint_self : codisjoint a a ↔ a = ⊤ :=
⟨λ hd, top_unique $ hd le_rfl le_rfl, λ h x ha hb, h.symm.trans_le ha⟩
/- TODO: Rename `codisjoint.eq_top` to `codisjoint.sup_eq` and `codisjoint.eq_top_of_self` to
`codisjoint.eq_top` -/
alias codisjoint_self ↔ codisjoint.eq_top_of_self _
lemma codisjoint.ne (ha : a ≠ ⊤) (hab : codisjoint a b) : a ≠ b :=
λ h, ha $ codisjoint_self.1 $ by rwa ←h at hab
lemma codisjoint.eq_top_of_le (hab : codisjoint a b) (h : b ≤ a) : a = ⊤ :=
eq_top_iff.2 $ hab le_rfl h
lemma codisjoint.eq_top_of_ge (hab : codisjoint a b) : a ≤ b → b = ⊤ := hab.symm.eq_top_of_le
end partial_order_top
section partial_bounded_order
variables [partial_order α] [bounded_order α] {a : α}
@[simp] theorem codisjoint_bot : codisjoint a ⊥ ↔ a = ⊤ :=
⟨λ h, top_unique $ h le_rfl bot_le, λ h x ha htop, h.symm.trans_le ha⟩
@[simp] theorem bot_codisjoint : codisjoint ⊥ a ↔ a = ⊤ :=
⟨λ h, top_unique $ h bot_le le_rfl, λ h x htop ha, h.symm.trans_le ha⟩
end partial_bounded_order
section semilattice_sup_top
variables [semilattice_sup α] [order_top α] {a b c d : α}
lemma codisjoint_iff_le_sup : codisjoint a b ↔ ⊤ ≤ a ⊔ b := @disjoint_iff_inf_le αᵒᵈ _ _ _ _
lemma codisjoint_iff : codisjoint a b ↔ a ⊔ b = ⊤ := @disjoint_iff αᵒᵈ _ _ _ _
lemma codisjoint.top_le : codisjoint a b → ⊤ ≤ a ⊔ b := @disjoint.le_bot αᵒᵈ _ _ _ _
lemma codisjoint.eq_top : codisjoint a b → a ⊔ b = ⊤ := @disjoint.eq_bot αᵒᵈ _ _ _ _
lemma codisjoint_assoc : codisjoint (a ⊔ b) c ↔ codisjoint a (b ⊔ c) :=
@disjoint_assoc αᵒᵈ _ _ _ _ _
lemma codisjoint_left_comm : codisjoint a (b ⊔ c) ↔ codisjoint b (a ⊔ c) :=
@disjoint_left_comm αᵒᵈ _ _ _ _ _
lemma codisjoint_right_comm : codisjoint (a ⊔ b) c ↔ codisjoint (a ⊔ c) b :=
@disjoint_right_comm αᵒᵈ _ _ _ _ _
variables (c)
lemma codisjoint.sup_left (h : codisjoint a b) : codisjoint (a ⊔ c) b := h.mono_left le_sup_left
lemma codisjoint.sup_left' (h : codisjoint a b) : codisjoint (c ⊔ a) b := h.mono_left le_sup_right
lemma codisjoint.sup_right (h : codisjoint a b) : codisjoint a (b ⊔ c) := h.mono_right le_sup_left
lemma codisjoint.sup_right' (h : codisjoint a b) : codisjoint a (c ⊔ b) := h.mono_right le_sup_right
variables {c}
lemma codisjoint.of_codisjoint_sup_of_le (h : codisjoint (a ⊔ b) c) (hle : c ≤ a) :
codisjoint a b :=
@disjoint.of_disjoint_inf_of_le αᵒᵈ _ _ _ _ _ h hle
lemma codisjoint.of_codisjoint_sup_of_le' (h : codisjoint (a ⊔ b) c) (hle : c ≤ b) :
codisjoint a b :=
@disjoint.of_disjoint_inf_of_le' αᵒᵈ _ _ _ _ _ h hle
end semilattice_sup_top
section distrib_lattice_top
variables [distrib_lattice α] [order_top α] {a b c : α}
@[simp] lemma codisjoint_inf_left : codisjoint (a ⊓ b) c ↔ codisjoint a c ∧ codisjoint b c :=
by simp only [codisjoint_iff, sup_inf_right, inf_eq_top_iff]
@[simp] lemma codisjoint_inf_right : codisjoint a (b ⊓ c) ↔ codisjoint a b ∧ codisjoint a c :=
by simp only [codisjoint_iff, sup_inf_left, inf_eq_top_iff]
lemma codisjoint.inf_left (ha : codisjoint a c) (hb : codisjoint b c) : codisjoint (a ⊓ b) c :=
codisjoint_inf_left.2 ⟨ha, hb⟩
lemma codisjoint.inf_right (hb : codisjoint a b) (hc : codisjoint a c) : codisjoint a (b ⊓ c) :=
codisjoint_inf_right.2 ⟨hb, hc⟩
lemma codisjoint.left_le_of_le_inf_right (h : a ⊓ b ≤ c) (hd : codisjoint b c) : a ≤ c :=
@disjoint.left_le_of_le_sup_right αᵒᵈ _ _ _ _ _ h hd.symm
lemma codisjoint.left_le_of_le_inf_left (h : b ⊓ a ≤ c) (hd : codisjoint b c) : a ≤ c :=
hd.left_le_of_le_inf_right $ by rwa inf_comm
end distrib_lattice_top
end codisjoint
open order_dual
lemma disjoint.dual [semilattice_inf α] [order_bot α] {a b : α} :
disjoint a b → codisjoint (to_dual a) (to_dual b) := id
lemma codisjoint.dual [semilattice_sup α] [order_top α] {a b : α} :
codisjoint a b → disjoint (to_dual a) (to_dual b) := id
@[simp] lemma disjoint_to_dual_iff [semilattice_sup α] [order_top α] {a b : α} :
disjoint (to_dual a) (to_dual b) ↔ codisjoint a b := iff.rfl
@[simp] lemma disjoint_of_dual_iff [semilattice_inf α] [order_bot α] {a b : αᵒᵈ} :
disjoint (of_dual a) (of_dual b) ↔ codisjoint a b := iff.rfl
@[simp] lemma codisjoint_to_dual_iff [semilattice_inf α] [order_bot α] {a b : α} :
codisjoint (to_dual a) (to_dual b) ↔ disjoint a b := iff.rfl
@[simp] lemma codisjoint_of_dual_iff [semilattice_sup α] [order_top α] {a b : αᵒᵈ} :
codisjoint (of_dual a) (of_dual b) ↔ disjoint a b := iff.rfl
section distrib_lattice
variables [distrib_lattice α] [bounded_order α] {a b c : α}
lemma disjoint.le_of_codisjoint (hab : disjoint a b) (hbc : codisjoint b c) : a ≤ c :=
begin
rw [←@inf_top_eq _ _ _ a, ←@bot_sup_eq _ _ _ c, ←hab.eq_bot, ←hbc.eq_top, sup_inf_right],
exact inf_le_inf_right _ le_sup_left,
end
end distrib_lattice
section is_compl
/-- Two elements `x` and `y` are complements of each other if `x ⊔ y = ⊤` and `x ⊓ y = ⊥`. -/
@[protect_proj] structure is_compl [partial_order α] [bounded_order α] (x y : α) : Prop :=
(disjoint : disjoint x y)
(codisjoint : codisjoint x y)
lemma is_compl_iff [partial_order α] [bounded_order α] {a b : α} :
is_compl a b ↔ disjoint a b ∧ codisjoint a b := ⟨λ h, ⟨h.1, h.2⟩, λ h, ⟨h.1, h.2⟩⟩
namespace is_compl
section bounded_partial_order
variables [partial_order α] [bounded_order α] {x y z : α}
@[symm] protected lemma symm (h : is_compl x y) : is_compl y x := ⟨h.1.symm, h.2.symm⟩
lemma dual (h : is_compl x y) : is_compl (to_dual x) (to_dual y) := ⟨h.2, h.1⟩
lemma of_dual {a b : αᵒᵈ} (h : is_compl a b) : is_compl (of_dual a) (of_dual b) := ⟨h.2, h.1⟩
end bounded_partial_order
section bounded_lattice
variables [lattice α] [bounded_order α] {x y z : α}
lemma of_le (h₁ : x ⊓ y ≤ ⊥) (h₂ : ⊤ ≤ x ⊔ y) : is_compl x y :=
⟨disjoint_iff_inf_le.mpr h₁, codisjoint_iff_le_sup.mpr h₂⟩
lemma of_eq (h₁ : x ⊓ y = ⊥) (h₂ : x ⊔ y = ⊤) : is_compl x y :=
⟨disjoint_iff.mpr h₁, codisjoint_iff.mpr h₂⟩
lemma inf_eq_bot (h : is_compl x y) : x ⊓ y = ⊥ := h.disjoint.eq_bot
lemma sup_eq_top (h : is_compl x y) : x ⊔ y = ⊤ := h.codisjoint.eq_top
end bounded_lattice
variables [distrib_lattice α] [bounded_order α] {a b x y z : α}
lemma inf_left_le_of_le_sup_right (h : is_compl x y) (hle : a ≤ b ⊔ y) : a ⊓ x ≤ b :=
calc a ⊓ x ≤ (b ⊔ y) ⊓ x : inf_le_inf hle le_rfl
... = (b ⊓ x) ⊔ (y ⊓ x) : inf_sup_right
... = b ⊓ x : by rw [h.symm.inf_eq_bot, sup_bot_eq]
... ≤ b : inf_le_left
lemma le_sup_right_iff_inf_left_le {a b} (h : is_compl x y) : a ≤ b ⊔ y ↔ a ⊓ x ≤ b :=
⟨h.inf_left_le_of_le_sup_right, h.symm.dual.inf_left_le_of_le_sup_right⟩
lemma inf_left_eq_bot_iff (h : is_compl y z) : x ⊓ y = ⊥ ↔ x ≤ z :=
by rw [← le_bot_iff, ← h.le_sup_right_iff_inf_left_le, bot_sup_eq]
lemma inf_right_eq_bot_iff (h : is_compl y z) : x ⊓ z = ⊥ ↔ x ≤ y :=
h.symm.inf_left_eq_bot_iff
lemma disjoint_left_iff (h : is_compl y z) : disjoint x y ↔ x ≤ z :=
by { rw disjoint_iff, exact h.inf_left_eq_bot_iff }
lemma disjoint_right_iff (h : is_compl y z) : disjoint x z ↔ x ≤ y :=
h.symm.disjoint_left_iff
lemma le_left_iff (h : is_compl x y) : z ≤ x ↔ disjoint z y :=
h.disjoint_right_iff.symm
lemma le_right_iff (h : is_compl x y) : z ≤ y ↔ disjoint z x :=
h.symm.le_left_iff
lemma right_le_iff (h : is_compl x y) : y ≤ z ↔ codisjoint z x := h.symm.left_le_iff
protected lemma antitone {x' y'} (h : is_compl x y) (h' : is_compl x' y') (hx : x ≤ x') :
y' ≤ y :=
h'.right_le_iff.2 $ h.symm.codisjoint.mono_right hx
lemma right_unique (hxy : is_compl x y) (hxz : is_compl x z) :
y = z :=
le_antisymm (hxz.antitone hxy $ le_refl x) (hxy.antitone hxz $ le_refl x)
lemma left_unique (hxz : is_compl x z) (hyz : is_compl y z) :
x = y :=
hxz.symm.right_unique hyz.symm
lemma sup_inf {x' y'} (h : is_compl x y) (h' : is_compl x' y') :
is_compl (x ⊔ x') (y ⊓ y') :=
of_eq
(by rw [inf_sup_right, ← inf_assoc, h.inf_eq_bot, bot_inf_eq, bot_sup_eq, inf_left_comm,
h'.inf_eq_bot, inf_bot_eq])
(by rw [sup_inf_left, @sup_comm _ _ x, sup_assoc, h.sup_eq_top, sup_top_eq, top_inf_eq,
sup_assoc, sup_left_comm, h'.sup_eq_top, sup_top_eq])
lemma inf_sup {x' y'} (h : is_compl x y) (h' : is_compl x' y') :
is_compl (x ⊓ x') (y ⊔ y') :=
(h.symm.sup_inf h'.symm).symm
end is_compl
namespace prod
variables {β : Type*} [partial_order α] [partial_order β]
protected lemma disjoint_iff [order_bot α] [order_bot β] {x y : α × β} :
disjoint x y ↔ disjoint x.1 y.1 ∧ disjoint x.2 y.2 :=
begin
split,
{ intros h,
refine ⟨λ a hx hy, (@h (a, ⊥) ⟨hx, _⟩ ⟨hy, _⟩).1, λ b hx hy, (@h (⊥, b) ⟨_, hx⟩ ⟨_, hy⟩).2⟩,
all_goals { exact bot_le }, },
{ rintros ⟨ha, hb⟩ z hza hzb,
refine ⟨ha hza.1 hzb.1, hb hza.2 hzb.2⟩ },
end
protected lemma codisjoint_iff [order_top α] [order_top β] {x y : α × β} :
codisjoint x y ↔ codisjoint x.1 y.1 ∧ codisjoint x.2 y.2 :=
@prod.disjoint_iff αᵒᵈ βᵒᵈ _ _ _ _ _ _
protected lemma is_compl_iff [bounded_order α] [bounded_order β]
{x y : α × β} :
is_compl x y ↔ is_compl x.1 y.1 ∧ is_compl x.2 y.2 :=
by simp_rw [is_compl_iff, prod.disjoint_iff, prod.codisjoint_iff, and_and_and_comm]
end prod
section
variables [lattice α] [bounded_order α] {a b x : α}
@[simp] lemma is_compl_to_dual_iff : is_compl (to_dual a) (to_dual b) ↔ is_compl a b :=
⟨is_compl.of_dual, is_compl.dual⟩
@[simp] lemma is_compl_of_dual_iff {a b : αᵒᵈ} : is_compl (of_dual a) (of_dual b) ↔ is_compl a b :=
⟨is_compl.dual, is_compl.of_dual⟩
lemma is_compl_bot_top : is_compl (⊥ : α) ⊤ := is_compl.of_eq bot_inf_eq sup_top_eq
lemma is_compl_top_bot : is_compl (⊤ : α) ⊥ := is_compl.of_eq inf_bot_eq top_sup_eq
lemma eq_top_of_is_compl_bot (h : is_compl x ⊥) : x = ⊤ := sup_bot_eq.symm.trans h.sup_eq_top
lemma eq_top_of_bot_is_compl (h : is_compl ⊥ x) : x = ⊤ := eq_top_of_is_compl_bot h.symm
lemma eq_bot_of_is_compl_top (h : is_compl x ⊤) : x = ⊥ := eq_top_of_is_compl_bot h.dual
lemma eq_bot_of_top_is_compl (h : is_compl ⊤ x) : x = ⊥ := eq_top_of_bot_is_compl h.dual
end
/-- A complemented bounded lattice is one where every element has a (not necessarily unique)
complement. -/
class complemented_lattice (α) [lattice α] [bounded_order α] : Prop :=
(exists_is_compl : ∀ (a : α), ∃ (b : α), is_compl a b)
export complemented_lattice (exists_is_compl)
namespace complemented_lattice
variables [lattice α] [bounded_order α] [complemented_lattice α]
instance : complemented_lattice αᵒᵈ :=
⟨λ a, let ⟨b, hb⟩ := exists_is_compl (show α, from a) in ⟨b, hb.dual⟩⟩
end complemented_lattice
end is_compl
|
[STATEMENT]
lemma ptrm_fvs_finite:
shows "finite (ptrm_fvs X)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. finite (ptrm_fvs X)
[PROOF STEP]
by(induction X, auto) |
\section{Functions}
\subsection{Definition and Terminology}
In this section, we will answer two questions. Namely, what is a function, and what do functions do?
From prior experience in precalculus and calculus courses most people have an intuitive picture of what functions are. For most purposes, they are ``rules'' that sends values to other values. In other words:
\begin{tcolorbox}
A function is a rule that assigns to certain elements in a set, certain elements to another set.
\end{tcolorbox}
The word rule is not very clear or rigorous. For example, we might consider the real valued functions $f(x) = x^3$ and $g(x) = x^3 + 3x - 3(x + 3) + 9$. These have the same value everywhere, but the rule for evaluating them is slightly different.
It turns out that when defining functions rigorously, the ``rule'' is a means to an end. All we care about when talking about any specific function is the output given the input.
\begin{definition}
A function $f:A \to B$ (read as ``$f$ from $A$ to $B$'') is defined as a set of ordered pairs $(a, b)$ where $a \in A$ and $b \in B$ (more specifically, a subset of the set of ordered pairs $A \times B$). $f$ has the following properties:
\begin{enumerate}
\item For all $a \in A$, there exists some $b \in B$ such that $(a, b) \in f$.
\item For all $a \in A$, $b, c \in B$, if $(a,b) \in f$ and $(a, c) \in f$, then $b = c$.
\end{enumerate}
\end{definition}
In other words, every value $a \in A$ will have some value $b$ such that $(a, b)$ is in $f$. Moreover, this value is \textbf{unique}. We define $f(a)$ as the unique value in $B$ such that $(a, f(a)) \in f$.
Here is some more terminology.
\begin{definition}
Let $f: A \to B$ be a function. We say $A$ is the \textbf{domain} of the function $f$ and $B$ is the \textbf{codomain} of $f$. We say that $a$ is mapped to $b$ or $f$ maps $a$ to $b$ if $(a, b) \in f$. You can also write $a \mapsto b$ as long as it is clear what $f$ is.
\end{definition}
Using these definitions, we can say the following: Given any function $f:A \to B$, every value in the domain will be mapped to exactly one value in the codomain.
\subsection{Injectivity, Surjectivity, Bijectivity}
Here are the relevant definitions:
\begin{itemize}
\item A function $f:A \to B$ is injective (or one to one) if $f(a) = f(b) \implies a = b$. So two different values in $A$ do not map to the same value in $B$.
\item A function $f:A \to B$ is surjective (or onto) if for all $b \in B$ we can find a value in $A$ such that $f(a) = b$.
\item A function $f$ is bijective if it is both injective and surjective.
\end{itemize}
Here is an interesting observation: if $f: A \to B$ is a bijection, then there is an inverse function $g: B \to A$. For each $b \in B$, we can define $g(b)$ as the unique value $a \in A$ such that $f(a) = b$. We know such a value exists because $f$ is surjective, and we know that this value is unique because $f$ is injective.
%%NOTE: define inverse functions.
\section{Relations}
Let $A$ be a set. Traditionally, we have lots of different notation for when we might want to \textit{compare} two objects in $A$. For example, the $=$ notation ``compares'' for equality, and the $\leq$ symbol compares two objects for magnitude. Relations generalize these comparison operators.
\begin{definition}
Let $A$ be a set. A relation $R$ on $A$ is a subset of $A \times A$. That is, $R$ is any subset of ordered pairs $(a, b)$ where $a \in A$ and $b \in A$.
\end{definition}
This definition can used as a comparison property as we demonstrate using the following terminology. We say that an element $a \in A$ is related to an element $b \in A$ if $(a, b) \in R$. So in fact it is beneficial to just think of $R$ as the set of all possible relations.
\begin{definition}
Let $A$ be a set and $R$ be a relation on $A \times A$. A relation is
\begin{itemize}
\item \textit{reflexive} if $(a, a) \in R$ for every $a \in A$,
\item \textit{symmetric}, if for all $a, b \in A$, $(a, b) \in R \implies (b, a) \in R$.
\item \textit{transitive} if for all $a, b, c \in A$, $(a, b) \in R, (b, c) \in R \implies (a, c) \in R$.
\end{itemize}
Usually, given a relation $R$, we will write $aRb$ if $(a, b) \in R$. This will save use space and ink.
\end{definition}
|
[GOAL]
α✝ : Type u_1
β : Type u_2
γ : Type u_3
α : Type u_4
inst✝ : Finite α
⊢ α ≃ Fin (Nat.card α)
[PROOFSTEP]
have := (Finite.exists_equiv_fin α).choose_spec.some
[GOAL]
α✝ : Type u_1
β : Type u_2
γ : Type u_3
α : Type u_4
inst✝ : Finite α
this : α ≃ Fin (Exists.choose (_ : ∃ n, Nonempty (α ≃ Fin n)))
⊢ α ≃ Fin (Nat.card α)
[PROOFSTEP]
rwa [Nat.card_eq_of_equiv_fin this]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
n : ℕ
h : Nat.card α = n
⊢ α ≃ Fin n
[PROOFSTEP]
subst h
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
⊢ α ≃ Fin (Nat.card α)
[PROOFSTEP]
apply Finite.equivFin
[GOAL]
α✝ : Type u_1
β : Type u_2
γ : Type u_3
α : Type u_4
⊢ Nat.card α = if h : Finite α then Fintype.card α else 0
[PROOFSTEP]
cases finite_or_infinite α
[GOAL]
case inl
α✝ : Type u_1
β : Type u_2
γ : Type u_3
α : Type u_4
h✝ : Finite α
⊢ Nat.card α = if h : Finite α then Fintype.card α else 0
[PROOFSTEP]
letI := Fintype.ofFinite α
[GOAL]
case inl
α✝ : Type u_1
β : Type u_2
γ : Type u_3
α : Type u_4
h✝ : Finite α
this : Fintype α := Fintype.ofFinite α
⊢ Nat.card α = if h : Finite α then Fintype.card α else 0
[PROOFSTEP]
simp only [*, Nat.card_eq_fintype_card, dif_pos]
[GOAL]
case inr
α✝ : Type u_1
β : Type u_2
γ : Type u_3
α : Type u_4
h✝ : Infinite α
⊢ Nat.card α = if h : Finite α then Fintype.card α else 0
[PROOFSTEP]
simp only [*, card_eq_zero_of_infinite, not_finite_iff_infinite.mpr, dite_false]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
⊢ 0 < Nat.card α ↔ Nonempty α
[PROOFSTEP]
haveI := Fintype.ofFinite α
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
this : Fintype α
⊢ 0 < Nat.card α ↔ Nonempty α
[PROOFSTEP]
rw [Nat.card_eq_fintype_card, Fintype.card_pos_iff]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝¹ : Finite α
inst✝ : Finite β
⊢ Nat.card α = Nat.card β ↔ Nonempty (α ≃ β)
[PROOFSTEP]
haveI := Fintype.ofFinite α
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝¹ : Finite α
inst✝ : Finite β
this : Fintype α
⊢ Nat.card α = Nat.card β ↔ Nonempty (α ≃ β)
[PROOFSTEP]
haveI := Fintype.ofFinite β
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝¹ : Finite α
inst✝ : Finite β
this✝ : Fintype α
this : Fintype β
⊢ Nat.card α = Nat.card β ↔ Nonempty (α ≃ β)
[PROOFSTEP]
simp only [Nat.card_eq_fintype_card, Fintype.card_eq]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
⊢ Nat.card α ≤ 1 ↔ Subsingleton α
[PROOFSTEP]
haveI := Fintype.ofFinite α
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
this : Fintype α
⊢ Nat.card α ≤ 1 ↔ Subsingleton α
[PROOFSTEP]
simp only [Nat.card_eq_fintype_card, Fintype.card_le_one_iff_subsingleton]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
⊢ 1 < Nat.card α ↔ Nontrivial α
[PROOFSTEP]
haveI := Fintype.ofFinite α
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
this : Fintype α
⊢ 1 < Nat.card α ↔ Nontrivial α
[PROOFSTEP]
simp only [Nat.card_eq_fintype_card, Fintype.one_lt_card_iff_nontrivial]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
⊢ Nat.card (Option α) = Nat.card α + 1
[PROOFSTEP]
haveI := Fintype.ofFinite α
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
this : Fintype α
⊢ Nat.card (Option α) = Nat.card α + 1
[PROOFSTEP]
simp only [Nat.card_eq_fintype_card, Fintype.card_option]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite β
f : α → β
hf : Function.Injective f
⊢ Nat.card α ≤ Nat.card β
[PROOFSTEP]
haveI := Fintype.ofFinite β
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite β
f : α → β
hf : Function.Injective f
this : Fintype β
⊢ Nat.card α ≤ Nat.card β
[PROOFSTEP]
haveI := Fintype.ofInjective f hf
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite β
f : α → β
hf : Function.Injective f
this✝ : Fintype β
this : Fintype α
⊢ Nat.card α ≤ Nat.card β
[PROOFSTEP]
simpa only [Nat.card_eq_fintype_card, ge_iff_le] using Fintype.card_le_of_injective f hf
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
f : α → β
hf : Function.Surjective f
⊢ Nat.card β ≤ Nat.card α
[PROOFSTEP]
haveI := Fintype.ofFinite α
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
f : α → β
hf : Function.Surjective f
this : Fintype α
⊢ Nat.card β ≤ Nat.card α
[PROOFSTEP]
haveI := Fintype.ofSurjective f hf
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
f : α → β
hf : Function.Surjective f
this✝ : Fintype α
this : Fintype β
⊢ Nat.card β ≤ Nat.card α
[PROOFSTEP]
simpa only [Nat.card_eq_fintype_card, ge_iff_le] using Fintype.card_le_of_surjective f hf
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
⊢ Nat.card α = 0 ↔ IsEmpty α
[PROOFSTEP]
haveI := Fintype.ofFinite α
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
this : Fintype α
⊢ Nat.card α = 0 ↔ IsEmpty α
[PROOFSTEP]
simp only [Nat.card_eq_fintype_card, Fintype.card_eq_zero_iff]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β
hf : Function.Surjective f
h : Nat.card β = 0
⊢ Nat.card α = 0
[PROOFSTEP]
cases finite_or_infinite β
[GOAL]
case inl
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β
hf : Function.Surjective f
h : Nat.card β = 0
h✝ : Finite β
⊢ Nat.card α = 0
[PROOFSTEP]
haveI := card_eq_zero_iff.mp h
[GOAL]
case inl
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β
hf : Function.Surjective f
h : Nat.card β = 0
h✝ : Finite β
this : IsEmpty β
⊢ Nat.card α = 0
[PROOFSTEP]
haveI := Function.isEmpty f
[GOAL]
case inl
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β
hf : Function.Surjective f
h : Nat.card β = 0
h✝ : Finite β
this✝ : IsEmpty β
this : IsEmpty α
⊢ Nat.card α = 0
[PROOFSTEP]
exact Nat.card_of_isEmpty
[GOAL]
case inr
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β
hf : Function.Surjective f
h : Nat.card β = 0
h✝ : Infinite β
⊢ Nat.card α = 0
[PROOFSTEP]
haveI := Infinite.of_surjective f hf
[GOAL]
case inr
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β
hf : Function.Surjective f
h : Nat.card β = 0
h✝ : Infinite β
this : Infinite α
⊢ Nat.card α = 0
[PROOFSTEP]
exact Nat.card_eq_zero_of_infinite
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝¹ : Finite α
inst✝ : Finite β
⊢ Nat.card (α ⊕ β) = Nat.card α + Nat.card β
[PROOFSTEP]
haveI := Fintype.ofFinite α
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝¹ : Finite α
inst✝ : Finite β
this : Fintype α
⊢ Nat.card (α ⊕ β) = Nat.card α + Nat.card β
[PROOFSTEP]
haveI := Fintype.ofFinite β
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝¹ : Finite α
inst✝ : Finite β
this✝ : Fintype α
this : Fintype β
⊢ Nat.card (α ⊕ β) = Nat.card α + Nat.card β
[PROOFSTEP]
simp only [Nat.card_eq_fintype_card, Fintype.card_sum]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
p : α → Prop
⊢ Nat.card { x // p x } ≤ Nat.card α
[PROOFSTEP]
haveI := Fintype.ofFinite α
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
p : α → Prop
this : Fintype α
⊢ Nat.card { x // p x } ≤ Nat.card α
[PROOFSTEP]
simpa only [Nat.card_eq_fintype_card, ge_iff_le] using Fintype.card_subtype_le p
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
p : α → Prop
x : α
hx : ¬p x
⊢ Nat.card { x // p x } < Nat.card α
[PROOFSTEP]
haveI := Fintype.ofFinite α
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝ : Finite α
p : α → Prop
x : α
hx : ¬p x
this : Fintype α
⊢ Nat.card { x // p x } < Nat.card α
[PROOFSTEP]
simpa only [Nat.card_eq_fintype_card, gt_iff_lt] using Fintype.card_subtype_lt hx
[GOAL]
α✝ : Type u_1
β : Type u_2
γ : Type u_3
α : Type u_4
inst✝ : Finite α
⊢ card α = ↑(Nat.card α)
[PROOFSTEP]
unfold PartENat.card
[GOAL]
α✝ : Type u_1
β : Type u_2
γ : Type u_3
α : Type u_4
inst✝ : Finite α
⊢ ↑Cardinal.toPartENat (Cardinal.mk α) = ↑(Nat.card α)
[PROOFSTEP]
apply symm
[GOAL]
case a
α✝ : Type u_1
β : Type u_2
γ : Type u_3
α : Type u_4
inst✝ : Finite α
⊢ ↑(Nat.card α) = ↑Cardinal.toPartENat (Cardinal.mk α)
[PROOFSTEP]
rw [Cardinal.natCast_eq_toPartENat_iff]
[GOAL]
case a
α✝ : Type u_1
β : Type u_2
γ : Type u_3
α : Type u_4
inst✝ : Finite α
⊢ ↑(Nat.card α) = Cardinal.mk α
[PROOFSTEP]
exact Finite.cast_card_eq_mk
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
s t : Set α
⊢ Nat.card ↑(s ∪ t) ≤ Nat.card ↑s + Nat.card ↑t
[PROOFSTEP]
cases' _root_.finite_or_infinite (↥(s ∪ t)) with h h
[GOAL]
case inl
α : Type u_1
β : Type u_2
γ : Type u_3
s t : Set α
h : Finite ↑(s ∪ t)
⊢ Nat.card ↑(s ∪ t) ≤ Nat.card ↑s + Nat.card ↑t
[PROOFSTEP]
rw [finite_coe_iff, finite_union, ← finite_coe_iff, ← finite_coe_iff] at h
[GOAL]
case inl
α : Type u_1
β : Type u_2
γ : Type u_3
s t : Set α
h : Finite ↑s ∧ Finite ↑t
⊢ Nat.card ↑(s ∪ t) ≤ Nat.card ↑s + Nat.card ↑t
[PROOFSTEP]
cases h
[GOAL]
case inl.intro
α : Type u_1
β : Type u_2
γ : Type u_3
s t : Set α
left✝ : Finite ↑s
right✝ : Finite ↑t
⊢ Nat.card ↑(s ∪ t) ≤ Nat.card ↑s + Nat.card ↑t
[PROOFSTEP]
rw [← Cardinal.natCast_le, Nat.cast_add, Finite.cast_card_eq_mk, Finite.cast_card_eq_mk, Finite.cast_card_eq_mk]
[GOAL]
case inl.intro
α : Type u_1
β : Type u_2
γ : Type u_3
s t : Set α
left✝ : Finite ↑s
right✝ : Finite ↑t
⊢ Cardinal.mk ↑(s ∪ t) ≤ Cardinal.mk ↑s + Cardinal.mk ↑t
[PROOFSTEP]
exact Cardinal.mk_union_le s t
[GOAL]
case inr
α : Type u_1
β : Type u_2
γ : Type u_3
s t : Set α
h : Infinite ↑(s ∪ t)
⊢ Nat.card ↑(s ∪ t) ≤ Nat.card ↑s + Nat.card ↑t
[PROOFSTEP]
exact Nat.card_eq_zero_of_infinite.trans_le (zero_le _)
|
Denardo Coleman – drums
|
# Pill 15 - Linear models
Outline:
+ Ordinary least squares regression
+ Logistic regression
+ Generalized additive models
+ Support Vector Machines
# Ordinary least squares regression
We have seen linear models before several times. Let us recall what they are about. The underlying model is a linear one, this is
$$h(x) = a^Tx + b$$
In the context of regression, the use of this model can be associated to the minimization of the squared mean error loss, this is
$$
\begin{align}
\underset{a,b}{\text{minimize}} &\quad \sum_i (y_i - h(x_i;a,b))^2
\end{align}$$
As we saw in other notebooks, this problem can be easily solved using iterative approaches or even using a closed form solution.
# Logistic regression
Logistic regression is a **linear classifier** that is based on maximum likelihood principles to jointly model the classification boundary and the certainty of the fit. It is based on fitting a logistic function to the data.
$$p(x_i|y) = \frac{1}{1+e^{-(a^Tx+b)}}$$
```python
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
beta= 0.5
x = np.linspace(-10,10,100)
p = 1./(1+np.exp(-beta*x))
plt.plot(p)
```
<div class = "alert alert-success" style = "border-radius:10px"> **EXERCISE: ** What are hypothesis with respect to the probability modeling?</div>
<div class = "alert alert-success" style ="border-radius:10px">**EXERCISE: ** Change the value of $\beta$ and describe its effect.</div>
The likelihood function can be written as
$$p(x|y) = \prod\limits_{i=1}^N p(x_i|y)^{y_i}(1-p(x_i|y))^{1-y_i}$$
and the goal is to
$$\text{maximize} \quad p(x|y)$$
Taking the logarithm, we can equivalently maximize
$$\text{maximize} \quad \sum_i y_i \ln p(x_i|y) + (1-y_i) \ln(1-p(x_i|x))$$
We can model the probability $p(x_i|x)$ with a logit function, i.e.
$$p(x_i|y) = \ell(x_i) = \frac{1}{1+e^{-(a^Tx+b)}}$$
In order to optimize this model let us write the derivative of the logit function,
$$\frac{\partial \ell}{\partial a} = (1+e^{-(a^Tx+b)})^{-2}e^{-(a^Tx+b)}x$$
$$\frac{\partial \ell}{\partial b} = (1+e^{-(a^Tx+b)})^{-2}e^{-(a^Tx+b)}$$
In terms of the loss function the gradient with respect to the parameters is
$$\nabla_a \mathcal{L} = \sum_i x_i \ell(x_i)(y_i e^{-(a^Tx_i+b)} - (1-y_i) ) $$
$$\nabla_b \mathcal{L} = \sum_i \ell(x_i)(y_i e^{-(a^Tx_i+b)} - (1-y_i) ) $$
Let us solve this using gradient descent:
```python
%matplotlib inline
import numpy as np
m1 = [0.,0.]
s1 = [[1,-0.9],[-0.9,1]]
m2 = [3.,6.]
s2 = [[1,0],[0,1]]
m3 = [4.,-1.]
s3 = [[1,0.5],[0.5,1]]
print (s3)
c1 = np.random.multivariate_normal(m1,s1,100)
c2 = np.random.multivariate_normal(m2,s2,100)
x= np.r_[c1,c2]
y= np.r_[np.zeros(c1.shape[0]),np.ones(c2.shape[0])]
print (x.shape,y.shape)
import matplotlib.pyplot as plt
plt.plot(c1[:,0],c1[:,1],'r.')
plt.plot(c2[:,0],c2[:,1],'b.')
plt.gcf().set_size_inches((9,9))
```
```python
#gradient descent
def logit(x,a,b):
return 1./(1+np.exp(-(np.sum(a*x,axis=1)+b)))
def evaluate_objective(x,y,a,b):
return np.sum(y*np.log(logit(x,a,b))+(1-y)*np.log((1-logit(x,a,b))))
def partial_a_objective(x,y,a,b):
partial = x*np.tile((y*np.exp(-(np.sum(a*x,axis=1)+b))*logit(x,a,b)-(1-y)*logit(x,a,b))[:,np.newaxis],(1,2))
return np.sum(partial,axis=0)
def partial_b_objective(x,y,a,b):
partial = (y*np.exp(-(np.sum(a*x,axis=1)+b))*logit(x,a,b)-(1-y)*logit(x,a,b))
return np.sum(partial)
n_iters = 1000
nu=0.01
a = np.random.rand(1,x.shape[1])
b = np.random.rand(1)
conv = []
for i in range(n_iters):
at = a + nu*partial_a_objective(x,y,a,b) #maximize
b = b + nu*partial_b_objective(x,y,a,b) #maximize
a = at
conv.append(evaluate_objective(x,y,a,b))
plt.plot(conv)
```
```python
print (a,b)
```
[[ 1.97499493 2.24863925]] [-7.14607427]
```python
#my code
xx,yy = np.meshgrid(np.linspace(-3,7,200),np.linspace(-4,10,200))
viz=np.c_[xx.ravel(),yy.ravel()]
z = logit(viz,a,b)
plt.plot(c1[:,0],c1[:,1],'r.')
plt.plot(c2[:,0],c2[:,1],'b.')
plt.gca().set_xlim([-3.,7.])
plt.gca().set_ylim([-4.,10.])
plt.imshow(z.reshape((200,200)), interpolation='bilinear', origin='lower', extent=(-3,7,-4,10),alpha=0.3, vmin=0, vmax=1)
plt.contour(xx,yy,z.reshape((200,200)))
plt.gcf().set_size_inches((10,10))
```
```python
%matplotlib inline
import numpy as np
m1 = [0.,0.]
s1 = [[1,-0.9],[-0.9,1]]
m2 = [1.,2.]
s2 = [[1,0],[0,1]]
c1 = np.random.multivariate_normal(m1,s1,100)
c2 = np.random.multivariate_normal(m2,s2,100)
x= np.r_[c1,c2]
y= np.r_[np.zeros(c1.shape[0]),np.ones(c2.shape[0])]
print (x.shape,y.shape)
import matplotlib.pyplot as plt
plt.plot(c1[:,0],c1[:,1],'r.')
plt.plot(c2[:,0],c2[:,1],'b.')
plt.gcf().set_size_inches((9,9))
```
```python
#gradient descent
def logit(x,a,b):
return 1./(1+np.exp(-(np.sum(a*x,axis=1)+b)))
def evaluate_objective(x,y,a,b):
return np.sum(y*np.log(logit(x,a,b))+(1-y)*np.log((1-logit(x,a,b))))
def partial_a_objective(x,y,a,b):
partial = x*np.tile((y*np.exp(-(np.sum(a*x,axis=1)+b))*logit(x,a,b)-(1-y)*logit(x,a,b))[:,np.newaxis],(1,2))
return np.sum(partial,axis=0)
def partial_b_objective(x,y,a,b):
partial = (y*np.exp(-(np.sum(a*x,axis=1)+b))*logit(x,a,b)-(1-y)*logit(x,a,b))
return np.sum(partial)
n_iters = 10000
nu=0.01
a = np.random.rand(1,x.shape[1])
b = np.random.rand(1)
conv = []
for i in range(n_iters):
at = a + nu*partial_a_objective(x,y,a,b) #maximize
b = b + nu*partial_b_objective(x,y,a,b) #maximize
a = at
conv.append(evaluate_objective(x,y,a,b))
plt.plot(conv)
```
```python
#my code
xx,yy = np.meshgrid(np.linspace(-3,6,200),np.linspace(-4,6,200))
viz=np.c_[xx.ravel(),yy.ravel()]
z = logit(viz,a,b)
plt.plot(c1[:,0],c1[:,1],'r.')
plt.plot(c2[:,0],c2[:,1],'b.')
plt.gca().set_xlim([-3.,6.])
plt.gca().set_ylim([-4.,6.])
plt.imshow(z.reshape((200,200)), interpolation='bilinear', origin='lower', extent=(-3,6,-4,6),alpha=0.3, vmin=0, vmax=1)
plt.contour(xx,yy,z.reshape((200,200)),[0.1,0.5,0.9])
plt.gcf().set_size_inches((9,9))
```
Let us code this model using CVX
# Support vector machines
Support Vector Machines (SVM) is a prototypical example of discriminative learning. In this setting one explicitly assumes a function model class of the boundary. The classical model for SVM is a linear model. SVM is not the only discriminative linear model, e.g. perceptron, logistic classifier, etc. But, it is probably the most complete problem formulation.
Let us first check the intuition behind SVM,
```python
%matplotlib inline
%reset -f
import numpy as np
import matplotlib.pyplot as plt
from IPython.html.widgets import interact
class HLA():
def __init__(self):
np.random.seed(1)
self.X = np.concatenate([1.25*np.random.randn(40,2),5+1.5*np.random.randn(40,2)])
self.y = np.concatenate([np.ones((40,1)),-np.ones((40,1))])
plt.scatter(self.X[0:40,0],self.X[0:40,1],color='r')
plt.scatter(self.X[40:,0],self.X[40:,1],color='b')
delta = 0.025
xx = np.arange(-5.0, 10.0, delta)
yy = np.arange(-5.0, 10.0, delta)
XX, YY = np.meshgrid(xx, yy)
Xf = XX.flatten()
Yf = YY.flatten()
self.sz=XX.shape
self.data = np.concatenate([Xf[:,np.newaxis],Yf[:,np.newaxis]],axis=1);
def run(self,w0,w1,offset):
w=np.array([w0,w1])
w.shape=(2,1)
Z = self.data.dot(w)+offset
Z.shape=self.sz
plt.scatter(self.X[0:40,0],self.X[0:40,1],color='r')
plt.scatter(self.X[40:,0],self.X[40:,1],color='b')
plt.imshow(Z, interpolation='bilinear', origin='lower', extent=(-5,10,-5,10),alpha=0.3, vmin=-30, vmax=30)
XX = self.data[:,0].reshape(self.sz)
YY = self.data[:,1].reshape(self.sz)
plt.contour(XX,YY,Z,[0])
fig = plt.gcf()
fig.set_size_inches(9,9)
def decorator(w0,w1,offset):
widget_hla.run(w0,w1,offset)
widget_hla = HLA()
interact(decorator, w0=(-10.,10.), w1=(-10.,10.), offset=(-20.,40.));
```
<div class = "alert alert-success">**QUESTION:** Using the former widget, check manually the following configurations:
<li> $(w_0,w_1,\text{offset}) = (-1.7, -3.1, 10)$
<li> $(w_0,w_1,\text{offset}) = (-3.7, -0.5, 10.3)$
<li> $(w_0,w_1,\text{offset}) = (-7.5, -3.2, 28.8)$
<p>
Which one of those configuration do you think yields a better boundary? Why?
</div>
<div class="alert alert-info">
**INTUITION:** The Support Vector Machine classifer finds the boundary with maximum distance/**margin** to both classes.</div>
Observations:
- It implicitly models the notion of noise. One expects that the boundary with maximum margin will be robust to small perturbations in the data.
- A maximum margin classifier has a unique solution in the separable case.
```python
%reset -f
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from IPython.html.widgets import interact
from sklearn import svm
class svm_example():
def __init__(self):
'''Data creation'''
np.random.seed(1)
self.X = np.concatenate([1.25*np.random.randn(40,2),5+1.5*np.random.randn(40,2)])
self.y = np.concatenate([np.ones((40,1)),-np.ones((40,1))])
def run(self):
'''Fit a linear SVM'''
self.clf = svm.SVC(kernel='linear')
self.clf.fit(self.X,self.y.ravel())
def display(self):
'''Display stuff'''
delta = 0.25
xx = np.arange(-5.0, 10.0, delta)
yy = np.arange(-5.0, 10.0, delta)
XX, YY = np.meshgrid(xx, yy)
Xf = XX.flatten()
Yf = YY.flatten()
sz=XX.shape
data = np.concatenate([Xf[:,np.newaxis],Yf[:,np.newaxis]],axis=1);
Z=self.clf.decision_function(data)
Z.shape=sz
plt.scatter(self.X[0:40,0],self.X[0:40,1],color='r')
plt.scatter(self.X[40:,0],self.X[40:,1],color='b')
plt.imshow(Z, interpolation='bilinear', origin='lower', extent=(-5,10,-5,10),alpha=0.3, vmin=-3, vmax=3)
XX = data[:,0].reshape(sz)
YY = data[:,1].reshape(sz)
plt.contour(XX,YY,Z,[-1,0,1],colors=['b','k','r'])
fig = plt.gcf()
fig.set_size_inches(9,9)
print ('Number of support vectors: ' + str(np.sum(self.clf.n_support_)))
plt.scatter(self.clf.support_vectors_[:, 0],
self.clf.support_vectors_[:, 1],
s=120,
facecolors='none',
linewidths=2,
zorder=10)
print ('(w0,w1) = ' + str(10*self.clf.coef_[0]))
print ('offset = ' + str(10*self.clf.intercept_[0]))
return XX,YY,Z
c = svm_example()
c.run()
XX,YY,Z=c.display()
```
Observe that there is a critical subset of data points. These are called **Support Vectors**. If any of those points disappear the boundary changes. The decision boundary depends on the support vectors, thus we have to store them in our model.
Check the intuition in 3D:
```python
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
np.random.seed(1)
X = np.concatenate([1.25*np.random.randn(40,2),5+1.5*np.random.randn(40,2)])
y = np.concatenate([np.ones((40,1)),-np.ones((40,1))])
def control3D(elevation,azimuth):
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
fig.set_size_inches(12,12)
ax.plot_surface(XX,YY,Z,cmap=cm.coolwarm,alpha=0.3,linewidth=0)
ax.scatter(X[0:40,0],X[0:40,1],1,color='r')
ax.scatter(X[40:,0],X[40:,1],-1,color='b')
ax.contour(XX,YY,Z,[-1,0,1],colors=['b','k','r'])
ax.view_init(elev=elevation, azim=azimuth)
#Ipython 2.0
interact(control3D,elevation=(0.,90.),azimuth=(0,360))
#Ipython 1.1
#elevation = 45
#azimuth = 180
#control3D(elevation,azimuth)
```
<div class = "alert alert-success">**QUESTIONS: **
<li> Set the azimuth to $113$ and elevation to $0$. Observe the data points and the relative position of the hyperplane.
<li> Change the elevation to $90$. Describe this projection.
</div>
### 3.1.1 Geometry of the hyperplane
A hyperplane in ${\bf R}^d$ is defined as an affine combination of the variables: $\pi\equiv a^Tx + b = 0$.
Features:
+ A hyperplane splits the space in two half-spaces. The evaluation of the equation of the hyperplane on any element of one of the half-space is a positive value. It is a negative value for all the elements in the other half-space.
+ The distance of a point $x \in{\bf R}^d$ to the hyperplane $\pi$ is
$$d(x,\pi)=\frac{a^Tx+b}{\|a\|_2}$$
### 3.1.2 Modeling the separating hyperplane
Given a binary classification problem with training data $\mathcal{D}=\{(x_i,y_i)\},\; i=1\dots N, \; y_i\in\{+1,-1\} $. Consider $\mathcal{S} \subseteq \mathcal{D}$ the subset of all data points belonging to class $+1$, $\mathcal{S}=\{x_i | y_i=+1\}$, and $\mathcal{R}=\{x_i | y_i=-1\}$ its complement.
Then the problem of finding a separating hyperplane consists of fulfilling the following constraints
$$a^Ts_i+b>0\; \text{and}\; a^Tr_i+b<0 \quad \forall s_i\in\mathcal{S}, r_i\in\mathcal{R}.$$
Note the strict inequalities in the formulation. Informally, we can consider the smallest satisfied constraint. And observe that the rest must be satisfied with a larger value. Thus, we can arbitrarily set that value to 1 and rewrite the problem as $$a^Ts_i+b\geq 1\; \text{and}\; a^Tr_i+b\leq -1.$$
This is a *feasibility problem* and it is usually written in the following way in optimization standard notation
$$
\begin{align}
\text{minimize} & 1\\
\text{subject to} & a^T r_i + b \leq -1,\; \forall r_i \in \mathcal{R}\\
& a^T s_i + b \geq 1\; \forall s_i \in \mathcal{S}
\end{align}
$$
or in a compact way
$$
\begin{align}
\text{minimize} & 1\\
\text{subject to} & y_i (a^T x_i + b) \geq 1,\; \forall x_i \in \mathcal{D}\\
\end{align}
$$
The solution of this problem is not unique, e.g. remember all the parameters of the 'Human Learning Algorithm'.
```python
%matplotlib inline
import numpy as np
m1 = [0.,0.]
s1 = [[1,-0.9],[-0.9,1]]
m2 = [3.,6.]
s2 = [[1,0],[0,1]]
m3 = [4.,-1.]
s3 = [[1,0.5],[0.5,1]]
print (s3)
c1 = np.random.multivariate_normal(m1,s1,100)
c2 = np.random.multivariate_normal(m2,s2,100)
x= np.r_[c1,c2]
y= np.r_[-np.ones(c1.shape[0]),np.ones(c2.shape[0])]
print (x.shape,y.shape)
import matplotlib.pyplot as plt
plt.plot(c1[:,0],c1[:,1],'r.')
plt.plot(c2[:,0],c2[:,1],'b.')
plt.gcf().set_size_inches((9,9))
```
```python
from cvxpy import *
import numpy
d = x.shape[1]
N = x.shape[0]
# Construct the problem.
a = Variable(d)
b = Variable()
error = 1.
obj = Minimize(error)
constraints = [mul_elemwise(y,x*a+b)>=1]
prob = Problem(obj,constraints)
prob.solve()
```
1.0
```python
prob.status
```
'optimal'
```python
a.value, b.value
```
(matrix([[ 2.18098634],
[ 2.58581768]]), -7.4021516960174134)
<div class = "alert alert-success" style = "border-radius:10px"> **EXERCISE: ** Fill the blank with the model function to predict the boundary</div>
```python
#your code
xx,yy = np.meshgrid(np.linspace(-3,6,200),np.linspace(-4,6,200))
viz=np.c_[xx.ravel(),yy.ravel()]
z = # PUT HERE YOUR CODE
plt.plot(c1[:,0],c1[:,1],'r.')
plt.plot(c2[:,0],c2[:,1],'b.')
plt.gca().set_xlim([-3.,6.])
plt.gca().set_ylim([-4.,6.])
plt.imshow(z.reshape((200,200)), interpolation='bilinear', origin='lower', extent=(-3,6,-4,6),alpha=0.3, vmin=-1, vmax=1)
plt.contour(xx,yy,z.reshape((200,200)),[0.])
plt.gcf().set_size_inches((9,9))
```
### 3.1.3 The maximum margin hyperplane
Selecting the maximum margin hyperplane requires to add a new constraint to our problem. Remember from the geometry of the hyperplane that the distance of any point to a hyperplane is given by $d(x,\pi)=\frac{a^Tx+b}{\|a\|_2}$.
Recall that we want positive data to be beyond value 1 and negative data below -1. Thus, what is the distance value we want to maximize?
The positive point closest to the boundary is at $1/\|a\|_2$ and the negative point closest to the boundary data point is also at $1/\|a\|_2$. Thus data points from different classes are at least $2/\|a\|_2$ apart.
Recall that our goal is to find the separating hyperplane with maximum margin, i.e. with maximum distance among elements from different classes. Thus, we can complete the former formulation with our last requirement as follows
$$
\begin{align}
\text{maximize} & \quad 2/\|a\|_2 \\
\text{subject to} & \quad y_i (a^T x_i + b) \geq 1,\; \forall x_i \in \mathcal{D}\\
\end{align}
$$
or equivalently,
$$
\begin{align}
\text{minimize} & \quad \|a\|_2/2 \\
\text{subject to} & \quad y_i (a^T x_i + b) \geq 1,\; \forall x_i \in \mathcal{D}\\
\end{align}
$$
This formulation has a solution as long as the problem is linearly separable.
<div class = "alert alert-success">**EXERCISE: ** Code the hard margin SVM.</div>
```python
%matplotlib inline
import numpy as np
m1 = [0.,0.]
s1 = [[1,-0.9],[-0.9,1]]
m2 = [3.,6.]
s2 = [[1,0],[0,1]]
m3 = [4.,-1.]
s3 = [[1,0.5],[0.5,1]]
print (s3)
c1 = np.random.multivariate_normal(m1,s1,100)
c2 = np.random.multivariate_normal(m2,s2,100)
x= np.r_[c1,c2]
y= np.r_[-np.ones(c1.shape[0]),np.ones(c2.shape[0])]
print (x.shape,y.shape)
import matplotlib.pyplot as plt
plt.plot(c1[:,0],c1[:,1],'r.')
plt.plot(c2[:,0],c2[:,1],'b.')
plt.gcf().set_size_inches((9,9))
```
```python
#Your code here
from cvxpy import *
import numpy
x = x[0:,:]
y = y[0:]
d = x.shape[1]
N = x.shape[0]
# Construct the problem.
# Declare variables
objective= ###########
constraints= ###########
prob = Problem(objective,constraints)
prob.solve()
```
```python
a.value
```
matrix([[ 0.27103272],
[ 0.40360088]])
```python
#my code
xx,yy = np.meshgrid(np.linspace(-3,6,200),np.linspace(-4,6,200))
viz=np.c_[xx.ravel(),yy.ravel()]
z = np.dot(viz,a.value)+b.value
plt.plot(c1[:,0],c1[:,1],'r.')
plt.plot(c2[:,0],c2[:,1],'b.')
plt.gca().set_xlim([-3.,6.])
plt.gca().set_ylim([-4.,6.])
plt.imshow(z.reshape((200,200)), interpolation='bilinear', origin='lower', extent=(-3,6,-4,6),alpha=0.3, vmin=-1, vmax=1)
plt.contour(xx,yy,z.reshape((200,200)),[-1.,0.,1.])
plt.gcf().set_size_inches((9,9))
```
### 3.1.4 Dealing with the non-separable case
In order to deal with misclassifications, we are going to introduce a new set of variables $\xi_i$, that represents the amount of violation in the $i-th$ constraint. If the constraint is already satisfied, then $\xi_i=0$, and $\xi_i>0$ otherwise. Because $\xi_i$ is related to the errors, we would like to keep this amount as close so zero as possible. This makes us introduce a element in the objective trading-off with the maximum margin.
The new model becomes
$$
\begin{align}
\text{minimize} & \|a\|_2/2 + C \sum\limits_{i=1}^N \xi_i\\
\text{subject to} & y_i (a^T x_i + b) \geq 1 - \xi_i,\; i=1\dots N\\
& \xi_i\geq 0
\end{align}
$$
where $C$ is the trade-off parameter that roughly balances margin and misclassification rate. This formulation is also called **soft-margin SVM**.
```python
%matplotlib inline
import numpy as np
m1 = [0.,0.]
s1 = [[1,-0.9],[-0.9,1]]
m2 = [1.,2.]
s2 = [[1,0],[0,1]]
c1 = np.random.multivariate_normal(m1,s1,100)
c2 = np.random.multivariate_normal(m2,s2,100)
x= np.r_[c1,c2]
y= np.r_[-np.ones(c1.shape[0]),np.ones(c2.shape[0])]
print (x.shape,y.shape)
import matplotlib.pyplot as plt
plt.plot(c1[:,0],c1[:,1],'r.')
plt.plot(c2[:,0],c2[:,1],'b.')
plt.gcf().set_size_inches((9,9))
```
<div class = "alert alert-success" style = "border-radius:10px">**EXERCISE: ** Run the code for the hard margin SVM. Describe the result.</div>
```python
#Your code here
from cvxpy import *
import numpy
d = x.shape[1]
N = x.shape[0]
# Construct the problem.
# Declare variables
objective= ###########
constraints= ###########
prob = Problem(objective,constraints)
prob.solve()
prob.status
```
<div class = "alert alert-success" style = "border-radius:10px">**EXERCISE: ** Code the soft margin SVM. Describe the result when changing parameter C.</div>
```python
#your code
#my code
from cvxpy import *
import numpy
d = x.shape[1]
N = x.shape[0]
C = 100.
# Construct the problem.
# Declare variables
objective= ###########
constraints= ###########
prob = Problem(objective,constraints)
prob.solve()
prob.status
```
```python
xx,yy = np.meshgrid(np.linspace(-3,6,200),np.linspace(-4,6,200))
viz=np.c_[xx.ravel(),yy.ravel()]
z = np.dot(viz,a.value)+b.value
plt.plot(c1[:,0],c1[:,1],'r.')
plt.plot(c2[:,0],c2[:,1],'b.')
plt.gca().set_xlim([-3.,6.])
plt.gca().set_ylim([-4.,6.])
plt.imshow(z.reshape((200,200)), interpolation='bilinear', origin='lower', extent=(-3,6,-4,6),alpha=0.3, vmin=-1, vmax=1)
plt.contour(xx,yy,z.reshape((200,200)),[-1.,0.,1.])
plt.gcf().set_size_inches((9,9))
```
<div class = "alert alert-success" style = "border-radius:10px">**EXERCISE: ** Consider the formulation of the soft-margin SVM in a separable case. If one sets parameter $C$ to 0, what is the resutl? do we recover the hard-margin SVM? </div>
<div class="alert alert-info">**Take home ideas:**
<ul>
<li> Classical SVM fits a hyperplane separating boundary. </li>
<li> The hyperplane is defined to achieve the maximum margin. </li>
<li> If the problem is not linearly separable a new term related to the misclassification performance is introduced that trades-off with the margin. This trade-off is governed by parameter $C$ (or $\nu$ in $\nu$-SVM). </li>
</ul>
</div>
<div class = "alert alert-danger" style = "border-radius:10px">**DELIVERABLE: ** We want to modify the soft-margin SVM to be able to accomodate unbalanced data. Describe how to change the formulation such that we can control the balance of the errors from each class. Code an example and apply it to the following problem.</div>
```python
%matplotlib inline
import numpy as np
m1 = [0.,0.]
s1 = [[0.05,0],[0,0.05]]
m2 = [1.,2.]
s2 = [[1,0],[0,1]]
c1 = np.random.multivariate_normal(m1,s1,20)
c2 = np.random.multivariate_normal(m2,s2,300)
x= np.r_[c1,c2]
y= np.r_[-np.ones(c1.shape[0]),np.ones(c2.shape[0])]
print (x.shape,y.shape)
import matplotlib.pyplot as plt
plt.plot(c1[:,0],c1[:,1],'r.')
plt.plot(c2[:,0],c2[:,1],'b.')
plt.gcf().set_size_inches((9,9))
```
```python
```
```python
```
```python
```
```python
```
|
module OptimBase
using Reexport
using Printf
@reexport using NLSolversBase
import Base.summary
export OptimizationOptions,
OptimizationState,
OptimizationTrace,
Optimizer,
UnivariateOptimizationResults,
MultivariateOptimizationResults,
# API
minimizer,
converged
include("types.jl")
include("api.jl")
end # module
|
function p=lin2pcmu(x,s)
%LIN2PCMU Convert linear to Mu-law PCM P=(X,S)
% pcmu = lin2pcmu(lin) where lin contains a vector
% or matrix of signal values within a range determined by
% the scale factor s (see table below).
% Values outside this range will be clipped.
% The input values will be converted to integer
% Mu-law pcm vlues in the range 0 to 255.
%
% Input values are multiplied by the scale factor s:
%
% s Input Range
%
% 1 +-8159
% 4004.189931 +-2.03761563 (default)
% 8159 +-1
%
% The default input scaling factor 4004.189931 is equal to
% sqrt((2207^2 + 5215^2)/2) and follows ITU standard G.711.
% The sine wave with PCM-Mu values [158 139 139 158 30 11 11 30]
% has a mean square value of unity corresponding to 0 dBm0.
% Copyright (C) Mike Brookes 1998
% Version: $Id: lin2pcmu.m,v 1.4 2007/05/04 07:01:38 dmb Exp $
%
% VOICEBOX is a MATLAB toolbox for speech processing.
% Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You can obtain a copy of the GNU General Public License from
% http://www.gnu.org/copyleft/gpl.html or by writing to
% Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if nargin < 2 s=4004.189931; end
y=x*s;
y=(abs(y+8031)-abs(y-8031))/2;
q=floor((y+8032)/8032);
[m,e]=log2(abs(y)+33);
p=175+128*q-8*(e+abs(e-6))-floor(32*m-16);
|
-- --------------------------------------------------------------- [ Stack.idr ]
-- Module : Stack.idr
-- Copyright : (c) 2015,2016 See CONTRIBUTORS.md
-- License : see LICENSE
-- --------------------------------------------------------------------- [ EOH ]
||| Helper functions to treat lists like a stack.
|||
||| A collection of aliases so that working on `List` which is used
||| like a stack, actually feels like working on a stack.
|||
||| This module is here as a convince than anything else.
module Data.Stack
-- TODO Make popS and peekS 'safe' using the magic of proofs
%access export
%default total
||| A Stack containing items of type `ty`.
|||
||| @ty The type of elements in the stack.
public export
Stack : (ty : Type) -> Type
Stack ty = List ty
||| Create an empty stack.
mkStack : Stack ty
mkStack = Nil
||| Push an element on the stack.
pushS : ty -> Stack ty -> Stack ty
pushS e Nil = [e]
pushS e xs = e::xs
||| Initialise the stack with the given element.
initS : ty -> Stack ty
initS e = pushS e $ mkStack
||| Mass push the list of elements onto the stack.
pushSThings : List ty -> Stack ty -> Stack ty
pushSThings xs s = xs ++ s
||| Remove an element from the stack, returning the pair (head, tail).
popS : (s : Stack ty) -> {auto ok : isCons s = True} -> (ty, Stack ty)
popS Nil {ok=Refl} impossible
popS (x::xs) {ok=p} = (x,xs)
||| Remove an element from the stack, returning the pair (head, tail).
popS' : (s : Stack ty) -> Maybe (ty, Stack ty)
popS' Nil = Nothing
popS' (x::xs) = Just (x,xs)
||| See what is at the top of the stack.
peekS' : (s : Stack ty) -> Maybe ty
peekS' Nil = Nothing
peekS' (x::xs) = Just x
||| See what is at the top of the stack.
peekS : (s : Stack ty) -> {auto ok : isCons s = True} -> ty
peekS Nil {ok=Refl} impossible
peekS (x::xs) {ok=p} = x
clear : Stack ty -> Stack ty
clear _ = mkStack
isSEmpty : Stack ty -> Bool
isSEmpty xs = isNil xs
-- --------------------------------------------------------------------- [ EOF ]
|
State Before: ι : Type ?u.338842
α : Type u_1
inst✝ : OrderedCommGroup α
s t : NonemptyInterval α
⊢ s * t = 1 ↔ ∃ a b, s = pure a ∧ t = pure b ∧ a * b = 1 State After: case refine'_1
ι : Type ?u.338842
α : Type u_1
inst✝ : OrderedCommGroup α
s t : NonemptyInterval α
h : s * t = 1
⊢ ∃ a b, s = pure a ∧ t = pure b ∧ a * b = 1
case refine'_2
ι : Type ?u.338842
α : Type u_1
inst✝ : OrderedCommGroup α
s t : NonemptyInterval α
⊢ (∃ a b, s = pure a ∧ t = pure b ∧ a * b = 1) → s * t = 1 Tactic: refine' ⟨fun h => _, _⟩ State Before: case refine'_1
ι : Type ?u.338842
α : Type u_1
inst✝ : OrderedCommGroup α
s t : NonemptyInterval α
h : s * t = 1
⊢ ∃ a b, s = pure a ∧ t = pure b ∧ a * b = 1 State After: case refine'_1
ι : Type ?u.338842
α : Type u_1
inst✝ : OrderedCommGroup α
s t : NonemptyInterval α
h : (s * t).fst = 1.fst ∧ (s * t).snd = 1.snd
⊢ ∃ a b, s = pure a ∧ t = pure b ∧ a * b = 1 Tactic: rw [ext_iff, Prod.ext_iff] at h State Before: case refine'_1
ι : Type ?u.338842
α : Type u_1
inst✝ : OrderedCommGroup α
s t : NonemptyInterval α
h : (s * t).fst = 1.fst ∧ (s * t).snd = 1.snd
⊢ ∃ a b, s = pure a ∧ t = pure b ∧ a * b = 1 State After: case refine'_1
ι : Type ?u.338842
α : Type u_1
inst✝ : OrderedCommGroup α
s t : NonemptyInterval α
h : (s * t).fst = 1.fst ∧ (s * t).snd = 1.snd
this : s.fst = s.snd ∧ t.fst = t.snd
⊢ ∃ a b, s = pure a ∧ t = pure b ∧ a * b = 1 Tactic: have := (mul_le_mul_iff_of_ge s.fst_le_snd t.fst_le_snd).1 (h.2.trans h.1.symm).le State Before: case refine'_1
ι : Type ?u.338842
α : Type u_1
inst✝ : OrderedCommGroup α
s t : NonemptyInterval α
h : (s * t).fst = 1.fst ∧ (s * t).snd = 1.snd
this : s.fst = s.snd ∧ t.fst = t.snd
⊢ ∃ a b, s = pure a ∧ t = pure b ∧ a * b = 1 State After: case refine'_1.refine'_1.h
ι : Type ?u.338842
α : Type u_1
inst✝ : OrderedCommGroup α
s t : NonemptyInterval α
h : (s * t).fst = 1.fst ∧ (s * t).snd = 1.snd
this : s.fst = s.snd ∧ t.fst = t.snd
⊢ s.toProd = (s.fst, s.fst)
case refine'_1.refine'_2.h
ι : Type ?u.338842
α : Type u_1
inst✝ : OrderedCommGroup α
s t : NonemptyInterval α
h : (s * t).fst = 1.fst ∧ (s * t).snd = 1.snd
this : s.fst = s.snd ∧ t.fst = t.snd
⊢ t.toProd = (t.fst, t.fst) Tactic: refine' ⟨s.fst, t.fst, _, _, h.1⟩ <;> apply NonemptyInterval.ext <;> dsimp [pure] State Before: case refine'_1.refine'_1.h
ι : Type ?u.338842
α : Type u_1
inst✝ : OrderedCommGroup α
s t : NonemptyInterval α
h : (s * t).fst = 1.fst ∧ (s * t).snd = 1.snd
this : s.fst = s.snd ∧ t.fst = t.snd
⊢ s.toProd = (s.fst, s.fst) State After: no goals Tactic: nth_rw 2 [this.1] State Before: case refine'_1.refine'_2.h
ι : Type ?u.338842
α : Type u_1
inst✝ : OrderedCommGroup α
s t : NonemptyInterval α
h : (s * t).fst = 1.fst ∧ (s * t).snd = 1.snd
this : s.fst = s.snd ∧ t.fst = t.snd
⊢ t.toProd = (t.fst, t.fst) State After: no goals Tactic: nth_rw 2 [this.2] State Before: case refine'_2
ι : Type ?u.338842
α : Type u_1
inst✝ : OrderedCommGroup α
s t : NonemptyInterval α
⊢ (∃ a b, s = pure a ∧ t = pure b ∧ a * b = 1) → s * t = 1 State After: case refine'_2.intro.intro.intro.intro
ι : Type ?u.338842
α : Type u_1
inst✝ : OrderedCommGroup α
b c : α
h : b * c = 1
⊢ pure b * pure c = 1 Tactic: rintro ⟨b, c, rfl, rfl, h⟩ State Before: case refine'_2.intro.intro.intro.intro
ι : Type ?u.338842
α : Type u_1
inst✝ : OrderedCommGroup α
b c : α
h : b * c = 1
⊢ pure b * pure c = 1 State After: no goals Tactic: rw [pure_mul_pure, h, pure_one] |
/-
Copyright (c) 2018 Ellen Arlt. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ellen Arlt, Blair Shi, Sean Leather, Mario Carneiro, Johan Commelin, Lu-Ming Zhang
-/
import algebra.algebra.basic
import algebra.big_operators.pi
import algebra.big_operators.ring
import algebra.module.linear_map
import algebra.module.pi
import algebra.star.pi
import data.equiv.ring
import data.fintype.card
/-!
# Matrices
This file defines basic properties of matrices.
## TODO
Under various conditions, multiplication of infinite matrices makes sense.
These have not yet been implemented.
-/
universes u u' v w
open_locale big_operators
/-- `matrix m n` is the type of matrices whose rows are indexed by `m`
and whose columns are indexed by `n`. -/
def matrix (m : Type u) (n : Type u') (α : Type v) : Type (max u u' v) :=
m → n → α
variables {l m n o : Type*} {m' : o → Type*} {n' : o → Type*}
variables {R : Type*} {S : Type*} {α : Type v} {β : Type w} {γ : Type*}
namespace matrix
section ext
variables {M N : matrix m n α}
theorem ext_iff : (∀ i j, M i j = N i j) ↔ M = N :=
⟨λ h, funext $ λ i, funext $ h i, λ h, by simp [h]⟩
@[ext]
end ext
/-- `M.map f` is the matrix obtained by applying `f` to each entry of the matrix `M`.
This is available in bundled forms as:
* `add_monoid_hom.map_matrix`
* `linear_map.map_matrix`
* `ring_hom.map_matrix`
* `alg_hom.map_matrix`
* `equiv.map_matrix`
* `add_equiv.map_matrix`
* `linear_equiv.map_matrix`
* `ring_equiv.map_matrix`
* `alg_equiv.map_matrix`
-/
def map (M : matrix m n α) (f : α → β) : matrix m n β := λ i j, f (M i j)
@[simp]
lemma map_apply {M : matrix m n α} {f : α → β} {i : m} {j : n} :
M.map f i j = f (M i j) := rfl
@[simp]
lemma map_id (M : matrix m n α) : M.map id = M :=
by { ext, refl, }
@[simp]
lemma map_map {M : matrix m n α} {β γ : Type*} {f : α → β} {g : β → γ} :
(M.map f).map g = M.map (g ∘ f) :=
by { ext, refl, }
/-- The transpose of a matrix. -/
def transpose (M : matrix m n α) : matrix n m α
| x y := M y x
localized "postfix `ᵀ`:1500 := matrix.transpose" in matrix
/-- The conjugate transpose of a matrix defined in term of `star`. -/
def conj_transpose [has_star α] (M : matrix m n α) : matrix n m α :=
M.transpose.map star
localized "postfix `ᴴ`:1500 := matrix.conj_transpose" in matrix
/-- `matrix.col u` is the column matrix whose entries are given by `u`. -/
def col (w : m → α) : matrix m unit α
| x y := w x
/-- `matrix.row u` is the row matrix whose entries are given by `u`. -/
def row (v : n → α) : matrix unit n α
| x y := v y
instance [inhabited α] : inhabited (matrix m n α) := pi.inhabited _
instance [has_add α] : has_add (matrix m n α) := pi.has_add
instance [add_semigroup α] : add_semigroup (matrix m n α) := pi.add_semigroup
instance [add_comm_semigroup α] : add_comm_semigroup (matrix m n α) := pi.add_comm_semigroup
instance [has_zero α] : has_zero (matrix m n α) := pi.has_zero
instance [add_zero_class α] : add_zero_class (matrix m n α) := pi.add_zero_class
instance [add_monoid α] : add_monoid (matrix m n α) := pi.add_monoid
instance [add_comm_monoid α] : add_comm_monoid (matrix m n α) := pi.add_comm_monoid
instance [has_neg α] : has_neg (matrix m n α) := pi.has_neg
instance [has_sub α] : has_sub (matrix m n α) := pi.has_sub
instance [add_group α] : add_group (matrix m n α) := pi.add_group
instance [add_comm_group α] : add_comm_group (matrix m n α) := pi.add_comm_group
instance [unique α] : unique (matrix m n α) := pi.unique
instance [subsingleton α] : subsingleton (matrix m n α) := pi.subsingleton
instance [nonempty m] [nonempty n] [nontrivial α] : nontrivial (matrix m n α) :=
function.nontrivial
instance [has_scalar R α] : has_scalar R (matrix m n α) := pi.has_scalar
instance [has_scalar R α] [has_scalar S α] [smul_comm_class R S α] :
smul_comm_class R S (matrix m n α) := pi.smul_comm_class
instance [has_scalar R S] [has_scalar R α] [has_scalar S α] [is_scalar_tower R S α] :
is_scalar_tower R S (matrix m n α) := pi.is_scalar_tower
instance [monoid R] [mul_action R α] :
mul_action R (matrix m n α) := pi.mul_action _
instance [monoid R] [add_monoid α] [distrib_mul_action R α] :
distrib_mul_action R (matrix m n α) := pi.distrib_mul_action _
instance [semiring R] [add_comm_monoid α] [module R α] :
module R (matrix m n α) := pi.module _ _ _
@[simp] lemma map_zero [has_zero α] [has_zero β] (f : α → β) (h : f 0 = 0) :
(0 : matrix m n α).map f = 0 :=
by { ext, simp [h], }
lemma map_add [has_add α] [has_add β] (f : α → β) (hf : ∀ a₁ a₂, f (a₁ + a₂) = f a₁ + f a₂)
(M N : matrix m n α) : (M + N).map f = M.map f + N.map f :=
ext $ λ _ _, hf _ _
lemma map_sub [has_sub α] [has_sub β] (f : α → β) (hf : ∀ a₁ a₂, f (a₁ - a₂) = f a₁ - f a₂)
(M N : matrix m n α) : (M - N).map f = M.map f - N.map f :=
ext $ λ _ _, hf _ _
lemma map_smul [has_scalar R α] [has_scalar R β] (f : α → β) (r : R)
(hf : ∀ a, f (r • a) = r • f a) (M : matrix m n α) : (r • M).map f = r • (M.map f) :=
ext $ λ _ _, hf _
lemma _root_.is_smul_regular.matrix [has_scalar R S] {k : R} (hk : is_smul_regular S k) :
is_smul_regular (matrix m n S) k :=
is_smul_regular.pi $ λ _, is_smul_regular.pi $ λ _, hk
lemma _root_.is_left_regular.matrix [has_mul α] {k : α} (hk : is_left_regular k) :
is_smul_regular (matrix m n α) k :=
hk.is_smul_regular.matrix
-- TODO[gh-6025]: make this an instance once safe to do so
lemma subsingleton_of_empty_left [is_empty m] : subsingleton (matrix m n α) :=
⟨λ M N, by { ext, exact is_empty_elim i }⟩
-- TODO[gh-6025]: make this an instance once safe to do so
lemma subsingleton_of_empty_right [is_empty n] : subsingleton (matrix m n α) :=
⟨λ M N, by { ext, exact is_empty_elim j }⟩
end matrix
open_locale matrix
namespace matrix
section diagonal
variables [decidable_eq n]
/-- `diagonal d` is the square matrix such that `(diagonal d) i i = d i` and `(diagonal d) i j = 0`
if `i ≠ j`.
Note that bundled versions exist as:
* `matrix.diagonal_add_monoid_hom`
* `matrix.diagonal_linear_map`
* `matrix.diagonal_ring_hom`
* `matrix.diagonal_alg_hom`
-/
def diagonal [has_zero α] (d : n → α) : matrix n n α
| i j := if i = j then d i else 0
@[simp] theorem diagonal_apply_eq [has_zero α] {d : n → α} (i : n) : (diagonal d) i i = d i :=
by simp [diagonal]
@[simp] theorem diagonal_apply_ne [has_zero α] {d : n → α} {i j : n} (h : i ≠ j) :
(diagonal d) i j = 0 := by simp [diagonal, h]
theorem diagonal_apply_ne' [has_zero α] {d : n → α} {i j : n} (h : j ≠ i) :
(diagonal d) i j = 0 := diagonal_apply_ne h.symm
lemma diagonal_injective [has_zero α] : function.injective (diagonal : (n → α) → matrix n n α) :=
λ d₁ d₂ h, funext $ λ i, by simpa using matrix.ext_iff.mpr h i i
@[simp] theorem diagonal_zero [has_zero α] : (diagonal (λ _, 0) : matrix n n α) = 0 :=
by { ext, simp [diagonal] }
@[simp] lemma diagonal_transpose [has_zero α] (v : n → α) :
(diagonal v)ᵀ = diagonal v :=
begin
ext i j,
by_cases h : i = j,
{ simp [h, transpose] },
{ simp [h, transpose, diagonal_apply_ne' h] }
end
@[simp] theorem diagonal_add [add_zero_class α] (d₁ d₂ : n → α) :
diagonal d₁ + diagonal d₂ = diagonal (λ i, d₁ i + d₂ i) :=
by ext i j; by_cases h : i = j; simp [h]
@[simp] theorem diagonal_smul [monoid R] [add_monoid α] [distrib_mul_action R α] (r : R)
(d : n → α) :
diagonal (r • d) = r • diagonal d :=
by ext i j; by_cases h : i = j; simp [h]
variables (n α)
/-- `matrix.diagonal` as an `add_monoid_hom`. -/
@[simps]
def diagonal_add_monoid_hom [add_zero_class α] : (n → α) →+ matrix n n α :=
{ to_fun := diagonal,
map_zero' := diagonal_zero,
map_add' := λ x y, (diagonal_add x y).symm,}
variables (R)
/-- `matrix.diagonal` as a `linear_map`. -/
@[simps]
def diagonal_linear_map [semiring R] [add_comm_monoid α] [module R α] :
(n → α) →ₗ[R] matrix n n α :=
{ map_smul' := diagonal_smul,
.. diagonal_add_monoid_hom n α,}
variables {n α R}
@[simp] lemma diagonal_map [has_zero α] [has_zero β] {f : α → β} (h : f 0 = 0) {d : n → α} :
(diagonal d).map f = diagonal (λ m, f (d m)) :=
by { ext, simp only [diagonal, map_apply], split_ifs; simp [h], }
@[simp] lemma diagonal_conj_transpose [semiring α] [star_ring α] (v : n → α) :
(diagonal v)ᴴ = diagonal (star v) :=
begin
rw [conj_transpose, diagonal_transpose, diagonal_map (star_zero _)],
refl,
end
section one
variables [has_zero α] [has_one α]
instance : has_one (matrix n n α) := ⟨diagonal (λ _, 1)⟩
@[simp] theorem diagonal_one : (diagonal (λ _, 1) : matrix n n α) = 1 := rfl
theorem one_apply {i j} : (1 : matrix n n α) i j = if i = j then 1 else 0 := rfl
@[simp] theorem one_apply_eq (i) : (1 : matrix n n α) i i = 1 := diagonal_apply_eq i
@[simp] theorem one_apply_ne {i j} : i ≠ j → (1 : matrix n n α) i j = 0 :=
diagonal_apply_ne
theorem one_apply_ne' {i j} : j ≠ i → (1 : matrix n n α) i j = 0 :=
diagonal_apply_ne'
@[simp] lemma map_one [has_zero β] [has_one β]
(f : α → β) (h₀ : f 0 = 0) (h₁ : f 1 = 1) :
(1 : matrix n n α).map f = (1 : matrix n n β) :=
by { ext, simp only [one_apply, map_apply], split_ifs; simp [h₀, h₁], }
lemma one_eq_pi_single {i j} : (1 : matrix n n α) i j = pi.single i 1 j :=
by simp only [one_apply, pi.single_apply, eq_comm]; congr -- deal with decidable_eq
end one
section numeral
@[simp] lemma bit0_apply [has_add α] (M : matrix m m α) (i : m) (j : m) :
(bit0 M) i j = bit0 (M i j) := rfl
variables [add_monoid α] [has_one α]
lemma bit1_apply (M : matrix n n α) (i : n) (j : n) :
(bit1 M) i j = if i = j then bit1 (M i j) else bit0 (M i j) :=
by dsimp [bit1]; by_cases h : i = j; simp [h]
@[simp]
lemma bit1_apply_eq (M : matrix n n α) (i : n) :
(bit1 M) i i = bit1 (M i i) :=
by simp [bit1_apply]
@[simp]
lemma bit1_apply_ne (M : matrix n n α) {i j : n} (h : i ≠ j) :
(bit1 M) i j = bit0 (M i j) :=
by simp [bit1_apply, h]
end numeral
end diagonal
section dot_product
variable [fintype m]
/-- `dot_product v w` is the sum of the entrywise products `v i * w i` -/
def dot_product [has_mul α] [add_comm_monoid α] (v w : m → α) : α :=
∑ i, v i * w i
lemma dot_product_assoc [fintype n] [non_unital_semiring α] (u : m → α) (w : n → α)
(v : matrix m n α) :
dot_product (λ j, dot_product u (λ i, v i j)) w = dot_product u (λ i, dot_product (v i) w) :=
by simpa [dot_product, finset.mul_sum, finset.sum_mul, mul_assoc] using finset.sum_comm
lemma dot_product_comm [comm_semiring α] (v w : m → α) :
dot_product v w = dot_product w v :=
by simp_rw [dot_product, mul_comm]
@[simp] lemma dot_product_punit [add_comm_monoid α] [has_mul α] (v w : punit → α) :
dot_product v w = v ⟨⟩ * w ⟨⟩ :=
by simp [dot_product]
section non_unital_non_assoc_semiring
variables [non_unital_non_assoc_semiring α] (u v w : m → α)
@[simp] lemma dot_product_zero : dot_product v 0 = 0 := by simp [dot_product]
@[simp] lemma dot_product_zero' : dot_product v (λ _, 0) = 0 := dot_product_zero v
@[simp] lemma zero_dot_product : dot_product 0 v = 0 := by simp [dot_product]
@[simp] lemma zero_dot_product' : dot_product (λ _, (0 : α)) v = 0 := zero_dot_product v
@[simp] lemma add_dot_product : dot_product (u + v) w = dot_product u w + dot_product v w :=
by simp [dot_product, add_mul, finset.sum_add_distrib]
@[simp] lemma dot_product_add : dot_product u (v + w) = dot_product u v + dot_product u w :=
by simp [dot_product, mul_add, finset.sum_add_distrib]
end non_unital_non_assoc_semiring
section non_unital_non_assoc_semiring_decidable
variables [decidable_eq m] [non_unital_non_assoc_semiring α] (u v w : m → α)
@[simp] lemma diagonal_dot_product (i : m) : dot_product (diagonal v i) w = v i * w i :=
have ∀ j ≠ i, diagonal v i j * w j = 0 := λ j hij, by simp [diagonal_apply_ne' hij],
by convert finset.sum_eq_single i (λ j _, this j) _ using 1; simp
@[simp] lemma dot_product_diagonal (i : m) : dot_product v (diagonal w i) = v i * w i :=
have ∀ j ≠ i, v j * diagonal w i j = 0 := λ j hij, by simp [diagonal_apply_ne' hij],
by convert finset.sum_eq_single i (λ j _, this j) _ using 1; simp
@[simp] lemma dot_product_diagonal' (i : m) : dot_product v (λ j, diagonal w j i) = v i * w i :=
have ∀ j ≠ i, v j * diagonal w j i = 0 := λ j hij, by simp [diagonal_apply_ne hij],
by convert finset.sum_eq_single i (λ j _, this j) _ using 1; simp
@[simp] lemma single_dot_product (x : α) (i : m) : dot_product (pi.single i x) v = x * v i :=
have ∀ j ≠ i, pi.single i x j * v j = 0 := λ j hij, by simp [pi.single_eq_of_ne hij],
by convert finset.sum_eq_single i (λ j _, this j) _ using 1; simp
@[simp] lemma dot_product_single (x : α) (i : m) : dot_product v (pi.single i x) = v i * x :=
have ∀ j ≠ i, v j * pi.single i x j = 0 := λ j hij, by simp [pi.single_eq_of_ne hij],
by convert finset.sum_eq_single i (λ j _, this j) _ using 1; simp
end non_unital_non_assoc_semiring_decidable
section ring
variables [ring α] (u v w : m → α)
@[simp] lemma neg_dot_product : dot_product (-v) w = - dot_product v w := by simp [dot_product]
@[simp] lemma dot_product_neg : dot_product v (-w) = - dot_product v w := by simp [dot_product]
@[simp] lemma sub_dot_product : dot_product (u - v) w = dot_product u w - dot_product v w :=
by simp [sub_eq_add_neg]
@[simp] lemma dot_product_sub : dot_product u (v - w) = dot_product u v - dot_product u w :=
by simp [sub_eq_add_neg]
end ring
section distrib_mul_action
variables [monoid R] [has_mul α] [add_comm_monoid α] [distrib_mul_action R α]
@[simp] lemma smul_dot_product [is_scalar_tower R α α] (x : R) (v w : m → α) :
dot_product (x • v) w = x • dot_product v w :=
by simp [dot_product, finset.smul_sum, smul_mul_assoc]
@[simp] lemma dot_product_smul [smul_comm_class R α α] (x : R) (v w : m → α) :
dot_product v (x • w) = x • dot_product v w :=
by simp [dot_product, finset.smul_sum, mul_smul_comm]
end distrib_mul_action
section star_ring
variables [semiring α] [star_ring α] (v w : m → α)
lemma star_dot_product_star : dot_product (star v) (star w) = star (dot_product w v) :=
by simp [dot_product]
lemma star_dot_product : dot_product (star v) w = star (dot_product (star w) v) :=
by simp [dot_product]
lemma dot_product_star : dot_product v (star w) = star (dot_product w (star v)) :=
by simp [dot_product]
end star_ring
end dot_product
/-- `M ⬝ N` is the usual product of matrices `M` and `N`, i.e. we have that
`(M ⬝ N) i k` is the dot product of the `i`-th row of `M` by the `k`-th column of `N`.
This is currently only defined when `m` is finite. -/
protected def mul [fintype m] [has_mul α] [add_comm_monoid α]
(M : matrix l m α) (N : matrix m n α) : matrix l n α :=
λ i k, dot_product (λ j, M i j) (λ j, N j k)
localized "infixl ` ⬝ `:75 := matrix.mul" in matrix
theorem mul_apply [fintype m] [has_mul α] [add_comm_monoid α]
{M : matrix l m α} {N : matrix m n α} {i k} : (M ⬝ N) i k = ∑ j, M i j * N j k := rfl
instance [fintype n] [has_mul α] [add_comm_monoid α] : has_mul (matrix n n α) := ⟨matrix.mul⟩
@[simp] theorem mul_eq_mul [fintype n] [has_mul α] [add_comm_monoid α] (M N : matrix n n α) :
M * N = M ⬝ N := rfl
theorem mul_apply' [fintype m] [has_mul α] [add_comm_monoid α]
{M : matrix l m α} {N : matrix m n α} {i k} : (M ⬝ N) i k = dot_product (λ j, M i j) (λ j, N j k)
:= rfl
@[simp] theorem diagonal_neg [decidable_eq n] [add_group α] (d : n → α) :
-diagonal d = diagonal (λ i, -d i) :=
((diagonal_add_monoid_hom n α).map_neg d).symm
lemma sum_apply [add_comm_monoid α] (i : m) (j : n)
(s : finset β) (g : β → matrix m n α) :
(∑ c in s, g c) i j = ∑ c in s, g c i j :=
(congr_fun (s.sum_apply i g) j).trans (s.sum_apply j _)
section non_unital_non_assoc_semiring
variables [non_unital_non_assoc_semiring α]
@[simp] protected theorem mul_zero [fintype n] (M : matrix m n α) : M ⬝ (0 : matrix n o α) = 0 :=
by { ext i j, apply dot_product_zero }
@[simp] protected theorem zero_mul [fintype m] (M : matrix m n α) : (0 : matrix l m α) ⬝ M = 0 :=
by { ext i j, apply zero_dot_product }
protected theorem mul_add [fintype n] (L : matrix m n α) (M N : matrix n o α) :
L ⬝ (M + N) = L ⬝ M + L ⬝ N := by { ext i j, apply dot_product_add }
protected theorem add_mul [fintype m] (L M : matrix l m α) (N : matrix m n α) :
(L + M) ⬝ N = L ⬝ N + M ⬝ N := by { ext i j, apply add_dot_product }
instance [fintype n] : non_unital_non_assoc_semiring (matrix n n α) :=
{ mul := (*),
add := (+),
zero := 0,
mul_zero := matrix.mul_zero,
zero_mul := matrix.zero_mul,
left_distrib := matrix.mul_add,
right_distrib := matrix.add_mul,
.. matrix.add_comm_monoid}
@[simp] theorem diagonal_mul [fintype m] [decidable_eq m]
(d : m → α) (M : matrix m n α) (i j) : (diagonal d).mul M i j = d i * M i j :=
diagonal_dot_product _ _ _
@[simp] theorem mul_diagonal [fintype n] [decidable_eq n]
(d : n → α) (M : matrix m n α) (i j) : (M ⬝ diagonal d) i j = M i j * d j :=
by { rw ← diagonal_transpose, apply dot_product_diagonal }
@[simp] theorem diagonal_mul_diagonal [fintype n] [decidable_eq n] (d₁ d₂ : n → α) :
(diagonal d₁) ⬝ (diagonal d₂) = diagonal (λ i, d₁ i * d₂ i) :=
by ext i j; by_cases i = j; simp [h]
theorem diagonal_mul_diagonal' [fintype n] [decidable_eq n] (d₁ d₂ : n → α) :
diagonal d₁ * diagonal d₂ = diagonal (λ i, d₁ i * d₂ i) :=
diagonal_mul_diagonal _ _
/-- Left multiplication by a matrix, as an `add_monoid_hom` from matrices to matrices. -/
@[simps] def add_monoid_hom_mul_left [fintype m] (M : matrix l m α) :
matrix m n α →+ matrix l n α :=
{ to_fun := λ x, M ⬝ x,
map_zero' := matrix.mul_zero _,
map_add' := matrix.mul_add _ }
/-- Right multiplication by a matrix, as an `add_monoid_hom` from matrices to matrices. -/
@[simps] def add_monoid_hom_mul_right [fintype m] (M : matrix m n α) :
matrix l m α →+ matrix l n α :=
{ to_fun := λ x, x ⬝ M,
map_zero' := matrix.zero_mul _,
map_add' := λ _ _, matrix.add_mul _ _ _ }
protected lemma sum_mul [fintype m] (s : finset β) (f : β → matrix l m α)
(M : matrix m n α) : (∑ a in s, f a) ⬝ M = ∑ a in s, f a ⬝ M :=
(add_monoid_hom_mul_right M : matrix l m α →+ _).map_sum f s
protected lemma mul_sum [fintype m] (s : finset β) (f : β → matrix m n α)
(M : matrix l m α) : M ⬝ ∑ a in s, f a = ∑ a in s, M ⬝ f a :=
(add_monoid_hom_mul_left M : matrix m n α →+ _).map_sum f s
end non_unital_non_assoc_semiring
section non_assoc_semiring
variables [non_assoc_semiring α]
@[simp] protected theorem one_mul [fintype m] [decidable_eq m] (M : matrix m n α) :
(1 : matrix m m α) ⬝ M = M :=
by ext i j; rw [← diagonal_one, diagonal_mul, one_mul]
@[simp] protected theorem mul_one [fintype n] [decidable_eq n] (M : matrix m n α) :
M ⬝ (1 : matrix n n α) = M :=
by ext i j; rw [← diagonal_one, mul_diagonal, mul_one]
instance [fintype n] [decidable_eq n] : non_assoc_semiring (matrix n n α) :=
{ one := 1,
one_mul := matrix.one_mul,
mul_one := matrix.mul_one,
.. matrix.non_unital_non_assoc_semiring }
@[simp]
lemma map_mul [fintype n] {L : matrix m n α} {M : matrix n o α} [non_assoc_semiring β]
{f : α →+* β} : (L ⬝ M).map f = L.map f ⬝ M.map f :=
by { ext, simp [mul_apply, ring_hom.map_sum], }
variables (α n)
/-- `matrix.diagonal` as a `ring_hom`. -/
@[simps]
def diagonal_ring_hom [fintype n] [decidable_eq n] : (n → α) →+* matrix n n α :=
{ to_fun := diagonal,
map_one' := diagonal_one,
map_mul' := λ _ _, (diagonal_mul_diagonal' _ _).symm,
.. diagonal_add_monoid_hom n α }
end non_assoc_semiring
section non_unital_semiring
variables [non_unital_semiring α] [fintype m] [fintype n]
protected theorem mul_assoc (L : matrix l m α) (M : matrix m n α) (N : matrix n o α) :
(L ⬝ M) ⬝ N = L ⬝ (M ⬝ N) :=
by { ext, apply dot_product_assoc }
instance : non_unital_semiring (matrix n n α) :=
{ mul_assoc := matrix.mul_assoc, ..matrix.non_unital_non_assoc_semiring }
end non_unital_semiring
section semiring
variables [semiring α]
instance [fintype n] [decidable_eq n] : semiring (matrix n n α) :=
{ ..matrix.non_unital_semiring, ..matrix.non_assoc_semiring }
end semiring
section ring
variables [ring α] [fintype n]
@[simp] theorem neg_mul (M : matrix m n α) (N : matrix n o α) :
(-M) ⬝ N = -(M ⬝ N) :=
by { ext, apply neg_dot_product }
@[simp] theorem mul_neg (M : matrix m n α) (N : matrix n o α) :
M ⬝ (-N) = -(M ⬝ N) :=
by { ext, apply dot_product_neg }
protected theorem sub_mul (M M' : matrix m n α) (N : matrix n o α) :
(M - M') ⬝ N = M ⬝ N - M' ⬝ N :=
by rw [sub_eq_add_neg, matrix.add_mul, neg_mul, sub_eq_add_neg]
protected theorem mul_sub (M : matrix m n α) (N N' : matrix n o α) :
M ⬝ (N - N') = M ⬝ N - M ⬝ N' :=
by rw [sub_eq_add_neg, matrix.mul_add, mul_neg, sub_eq_add_neg]
end ring
instance [fintype n] [decidable_eq n] [ring α] : ring (matrix n n α) :=
{ ..matrix.semiring, ..matrix.add_comm_group }
section semiring
variables [semiring α]
lemma smul_eq_diagonal_mul [fintype m] [decidable_eq m] (M : matrix m n α) (a : α) :
a • M = diagonal (λ _, a) ⬝ M :=
by { ext, simp }
@[simp] lemma smul_mul [fintype n] [monoid R] [distrib_mul_action R α] [is_scalar_tower R α α]
(a : R) (M : matrix m n α) (N : matrix n l α) :
(a • M) ⬝ N = a • M ⬝ N :=
by { ext, apply smul_dot_product }
/-- This instance enables use with `smul_mul_assoc`. -/
instance semiring.is_scalar_tower [fintype n] [monoid R] [distrib_mul_action R α]
[is_scalar_tower R α α] : is_scalar_tower R (matrix n n α) (matrix n n α) :=
⟨λ r m n, matrix.smul_mul r m n⟩
@[simp] lemma mul_smul [fintype n] [monoid R] [distrib_mul_action R α] [smul_comm_class R α α]
(M : matrix m n α) (a : R) (N : matrix n l α) : M ⬝ (a • N) = a • M ⬝ N :=
by { ext, apply dot_product_smul }
/-- This instance enables use with `mul_smul_comm`. -/
instance semiring.smul_comm_class [fintype n] [monoid R] [distrib_mul_action R α]
[smul_comm_class R α α] : smul_comm_class R (matrix n n α) (matrix n n α) :=
⟨λ r m n, (matrix.mul_smul m r n).symm⟩
@[simp] lemma mul_mul_left [fintype n] (M : matrix m n α) (N : matrix n o α) (a : α) :
(λ i j, a * M i j) ⬝ N = a • (M ⬝ N) :=
smul_mul a M N
/--
The ring homomorphism `α →+* matrix n n α`
sending `a` to the diagonal matrix with `a` on the diagonal.
-/
def scalar (n : Type u) [decidable_eq n] [fintype n] : α →+* matrix n n α :=
{ to_fun := λ a, a • 1,
map_one' := by simp,
map_mul' := by { intros, ext, simp [mul_assoc], },
.. (smul_add_hom α _).flip (1 : matrix n n α) }
section scalar
variables [decidable_eq n] [fintype n]
@[simp] lemma coe_scalar : (scalar n : α → matrix n n α) = λ a, a • 1 := rfl
lemma scalar_apply_eq (a : α) (i : n) :
scalar n a i i = a :=
by simp only [coe_scalar, smul_eq_mul, mul_one, one_apply_eq, pi.smul_apply]
lemma scalar_apply_ne (a : α) (i j : n) (h : i ≠ j) :
scalar n a i j = 0 :=
by simp only [h, coe_scalar, one_apply_ne, ne.def, not_false_iff, pi.smul_apply, smul_zero]
lemma scalar_inj [nonempty n] {r s : α} : scalar n r = scalar n s ↔ r = s :=
begin
split,
{ intro h,
inhabit n,
rw [← scalar_apply_eq r (arbitrary n), ← scalar_apply_eq s (arbitrary n), h] },
{ rintro rfl, refl }
end
end scalar
end semiring
section comm_semiring
variables [comm_semiring α] [fintype n]
lemma smul_eq_mul_diagonal [decidable_eq n] (M : matrix m n α) (a : α) :
a • M = M ⬝ diagonal (λ _, a) :=
by { ext, simp [mul_comm] }
@[simp] lemma mul_mul_right (M : matrix m n α) (N : matrix n o α) (a : α) :
M ⬝ (λ i j, a * N i j) = a • (M ⬝ N) :=
mul_smul M a N
lemma scalar.commute [decidable_eq n] (r : α) (M : matrix n n α) : commute (scalar n r) M :=
by simp [commute, semiconj_by]
end comm_semiring
section algebra
variables [fintype n] [decidable_eq n]
variables [comm_semiring R] [semiring α] [semiring β] [algebra R α] [algebra R β]
instance : algebra R (matrix n n α) :=
{ commutes' := λ r x, begin
ext, simp [matrix.scalar, matrix.mul_apply, matrix.one_apply, algebra.commutes, smul_ite], end,
smul_def' := λ r x, begin ext, simp [matrix.scalar, algebra.smul_def r], end,
..((matrix.scalar n).comp (algebra_map R α)) }
lemma algebra_map_matrix_apply {r : R} {i j : n} :
algebra_map R (matrix n n α) r i j = if i = j then algebra_map R α r else 0 :=
begin
dsimp [algebra_map, algebra.to_ring_hom, matrix.scalar],
split_ifs with h; simp [h, matrix.one_apply_ne],
end
lemma algebra_map_eq_diagonal (r : R) :
algebra_map R (matrix n n α) r = diagonal (algebra_map R (n → α) r) :=
matrix.ext $ λ i j, algebra_map_matrix_apply
@[simp] lemma algebra_map_eq_smul (r : R) :
algebra_map R (matrix n n R) r = r • (1 : matrix n n R) := rfl
lemma algebra_map_eq_diagonal_ring_hom :
algebra_map R (matrix n n α) = (diagonal_ring_hom n α).comp (algebra_map R _) :=
ring_hom.ext algebra_map_eq_diagonal
@[simp] lemma map_algebra_map (r : R) (f : α → β) (hf : f 0 = 0)
(hf₂ : f (algebra_map R α r) = algebra_map R β r) :
(algebra_map R (matrix n n α) r).map f = algebra_map R (matrix n n β) r :=
begin
rw [algebra_map_eq_diagonal, algebra_map_eq_diagonal, diagonal_map hf],
congr' 1 with x,
simp only [hf₂, pi.algebra_map_apply]
end
variables (R)
/-- `matrix.diagonal` as an `alg_hom`. -/
@[simps]
def diagonal_alg_hom : (n → α) →ₐ[R] matrix n n α :=
{ to_fun := diagonal,
commutes' := λ r, (algebra_map_eq_diagonal r).symm,
.. diagonal_ring_hom n α }
end algebra
end matrix
/-!
### Bundled versions of `matrix.map`
-/
namespace equiv
/-- The `equiv` between spaces of matrices induced by an `equiv` between their
coefficients. This is `matrix.map` as an `equiv`. -/
@[simps apply]
def map_matrix (f : α ≃ β) : matrix m n α ≃ matrix m n β :=
{ to_fun := λ M, M.map f,
inv_fun := λ M, M.map f.symm,
left_inv := λ M, matrix.ext $ λ _ _, f.symm_apply_apply _,
right_inv := λ M, matrix.ext $ λ _ _, f.apply_symm_apply _, }
@[simp] lemma map_matrix_refl : (equiv.refl α).map_matrix = equiv.refl (matrix m n α) :=
rfl
@[simp] lemma map_matrix_symm (f : α ≃ β) :
f.map_matrix.symm = (f.symm.map_matrix : matrix m n β ≃ _) :=
rfl
@[simp] lemma map_matrix_trans (f : α ≃ β) (g : β ≃ γ) :
f.map_matrix.trans g.map_matrix = ((f.trans g).map_matrix : matrix m n α ≃ _) :=
rfl
end equiv
namespace add_monoid_hom
variables [add_zero_class α] [add_zero_class β] [add_zero_class γ]
/-- The `add_monoid_hom` between spaces of matrices induced by an `add_monoid_hom` between their
coefficients. This is `matrix.map` as an `add_monoid_hom`. -/
@[simps]
def map_matrix (f : α →+ β) : matrix m n α →+ matrix m n β :=
{ to_fun := λ M, M.map f,
map_zero' := matrix.map_zero f f.map_zero,
map_add' := matrix.map_add f f.map_add }
@[simp] lemma map_matrix_id : (add_monoid_hom.id α).map_matrix = add_monoid_hom.id (matrix m n α) :=
rfl
@[simp] lemma map_matrix_comp (f : β →+ γ) (g : α →+ β) :
f.map_matrix.comp g.map_matrix = ((f.comp g).map_matrix : matrix m n α →+ _) :=
rfl
end add_monoid_hom
namespace add_equiv
variables [has_add α] [has_add β] [has_add γ]
/-- The `add_equiv` between spaces of matrices induced by an `add_equiv` between their
coefficients. This is `matrix.map` as an `add_equiv`. -/
@[simps apply]
def map_matrix (f : α ≃+ β) : matrix m n α ≃+ matrix m n β :=
{ to_fun := λ M, M.map f,
inv_fun := λ M, M.map f.symm,
map_add' := matrix.map_add f f.map_add,
.. f.to_equiv.map_matrix }
@[simp] lemma map_matrix_refl : (add_equiv.refl α).map_matrix = add_equiv.refl (matrix m n α) :=
rfl
@[simp] lemma map_matrix_symm (f : α ≃+ β) :
f.map_matrix.symm = (f.symm.map_matrix : matrix m n β ≃+ _) :=
rfl
@[simp] lemma map_matrix_trans (f : α ≃+ β) (g : β ≃+ γ) :
f.map_matrix.trans g.map_matrix = ((f.trans g).map_matrix : matrix m n α ≃+ _) :=
rfl
end add_equiv
namespace linear_map
variables [semiring R] [add_comm_monoid α] [add_comm_monoid β] [add_comm_monoid γ]
variables [module R α] [module R β] [module R γ]
/-- The `linear_map` between spaces of matrices induced by a `linear_map` between their
coefficients. This is `matrix.map` as a `linear_map`. -/
@[simps]
def map_matrix (f : α →ₗ[R] β) : matrix m n α →ₗ[R] matrix m n β :=
{ to_fun := λ M, M.map f,
map_add' := matrix.map_add f f.map_add,
map_smul' := λ r, matrix.map_smul f r (f.map_smul r), }
@[simp] lemma map_matrix_id : linear_map.id.map_matrix = (linear_map.id : matrix m n α →ₗ[R] _) :=
rfl
@[simp] lemma map_matrix_comp (f : β →ₗ[R] γ) (g : α →ₗ[R] β) :
f.map_matrix.comp g.map_matrix = ((f.comp g).map_matrix : matrix m n α →ₗ[R] _) :=
rfl
end linear_map
namespace linear_equiv
variables [semiring R] [add_comm_monoid α] [add_comm_monoid β] [add_comm_monoid γ]
variables [module R α] [module R β] [module R γ]
/-- The `linear_equiv` between spaces of matrices induced by an `linear_equiv` between their
coefficients. This is `matrix.map` as an `linear_equiv`. -/
@[simps apply]
def map_matrix (f : α ≃ₗ[R] β) : matrix m n α ≃ₗ[R] matrix m n β :=
{ to_fun := λ M, M.map f,
inv_fun := λ M, M.map f.symm,
.. f.to_equiv.map_matrix,
.. f.to_linear_map.map_matrix }
@[simp] lemma map_matrix_refl :
(linear_equiv.refl R α).map_matrix = linear_equiv.refl R (matrix m n α) :=
rfl
@[simp] lemma map_matrix_symm (f : α ≃ₗ[R] β) :
f.map_matrix.symm = (f.symm.map_matrix : matrix m n β ≃ₗ[R] _) :=
rfl
@[simp] lemma map_matrix_trans (f : α ≃ₗ[R] β) (g : β ≃ₗ[R] γ) :
f.map_matrix.trans g.map_matrix = ((f.trans g).map_matrix : matrix m n α ≃ₗ[R] _) :=
rfl
end linear_equiv
namespace ring_hom
variables [fintype m] [decidable_eq m]
variables [non_assoc_semiring α] [non_assoc_semiring β] [non_assoc_semiring γ]
/-- The `ring_hom` between spaces of square matrices induced by a `ring_hom` between their
coefficients. This is `matrix.map` as a `ring_hom`. -/
@[simps]
def map_matrix (f : α →+* β) : matrix m m α →+* matrix m m β :=
{ to_fun := λ M, M.map f,
map_one' := by simp,
map_mul' := λ L M, matrix.map_mul,
.. f.to_add_monoid_hom.map_matrix }
@[simp] lemma map_matrix_id : (ring_hom.id α).map_matrix = ring_hom.id (matrix m m α) :=
rfl
@[simp] lemma map_matrix_comp (f : β →+* γ) (g : α →+* β) :
f.map_matrix.comp g.map_matrix = ((f.comp g).map_matrix : matrix m m α →+* _) :=
rfl
end ring_hom
namespace ring_equiv
variables [fintype m] [decidable_eq m]
variables [non_assoc_semiring α] [non_assoc_semiring β] [non_assoc_semiring γ]
/-- The `ring_equiv` between spaces of square matrices induced by a `ring_equiv` between their
coefficients. This is `matrix.map` as a `ring_equiv`. -/
@[simps apply]
def map_matrix (f : α ≃+* β) : matrix m m α ≃+* matrix m m β :=
{ to_fun := λ M, M.map f,
inv_fun := λ M, M.map f.symm,
.. f.to_ring_hom.map_matrix,
.. f.to_add_equiv.map_matrix }
@[simp] lemma map_matrix_refl :
(ring_equiv.refl α).map_matrix = ring_equiv.refl (matrix m m α) :=
rfl
@[simp] lemma map_matrix_symm (f : α ≃+* β) :
f.map_matrix.symm = (f.symm.map_matrix : matrix m m β ≃+* _) :=
rfl
@[simp] lemma map_matrix_trans (f : α ≃+* β) (g : β ≃+* γ) :
f.map_matrix.trans g.map_matrix = ((f.trans g).map_matrix : matrix m m α ≃+* _) :=
rfl
end ring_equiv
namespace alg_hom
variables [fintype m] [decidable_eq m]
variables [comm_semiring R] [semiring α] [semiring β] [semiring γ]
variables [algebra R α] [algebra R β] [algebra R γ]
/-- The `alg_hom` between spaces of square matrices induced by a `alg_hom` between their
coefficients. This is `matrix.map` as a `alg_hom`. -/
@[simps]
def map_matrix (f : α →ₐ[R] β) : matrix m m α →ₐ[R] matrix m m β :=
{ to_fun := λ M, M.map f,
commutes' := λ r, matrix.map_algebra_map r f f.map_zero (f.commutes r),
.. f.to_ring_hom.map_matrix }
@[simp] lemma map_matrix_id : (alg_hom.id R α).map_matrix = alg_hom.id R (matrix m m α) :=
rfl
@[simp] lemma map_matrix_comp (f : β →ₐ[R] γ) (g : α →ₐ[R] β) :
f.map_matrix.comp g.map_matrix = ((f.comp g).map_matrix : matrix m m α →ₐ[R] _) :=
rfl
end alg_hom
namespace alg_equiv
variables [fintype m] [decidable_eq m]
variables [comm_semiring R] [semiring α] [semiring β] [semiring γ]
variables [algebra R α] [algebra R β] [algebra R γ]
/-- The `alg_equiv` between spaces of square matrices induced by a `alg_equiv` between their
coefficients. This is `matrix.map` as a `alg_equiv`. -/
@[simps apply]
def map_matrix (f : α ≃ₐ[R] β) : matrix m m α ≃ₐ[R] matrix m m β :=
{ to_fun := λ M, M.map f,
inv_fun := λ M, M.map f.symm,
.. f.to_alg_hom.map_matrix,
.. f.to_ring_equiv.map_matrix }
@[simp] lemma map_matrix_refl :
alg_equiv.refl.map_matrix = (alg_equiv.refl : matrix m m α ≃ₐ[R] _) :=
rfl
@[simp] lemma map_matrix_symm (f : α ≃ₐ[R] β) :
f.map_matrix.symm = (f.symm.map_matrix : matrix m m β ≃ₐ[R] _) :=
rfl
@[simp] lemma map_matrix_trans (f : α ≃ₐ[R] β) (g : β ≃ₐ[R] γ) :
f.map_matrix.trans g.map_matrix = ((f.trans g).map_matrix : matrix m m α ≃ₐ[R] _) :=
rfl
end alg_equiv
open_locale matrix
namespace matrix
/-- For two vectors `w` and `v`, `vec_mul_vec w v i j` is defined to be `w i * v j`.
Put another way, `vec_mul_vec w v` is exactly `col w ⬝ row v`. -/
def vec_mul_vec [has_mul α] (w : m → α) (v : n → α) : matrix m n α
| x y := w x * v y
section non_unital_non_assoc_semiring
variables [non_unital_non_assoc_semiring α]
/-- `mul_vec M v` is the matrix-vector product of `M` and `v`, where `v` is seen as a column matrix.
Put another way, `mul_vec M v` is the vector whose entries
are those of `M ⬝ col v` (see `col_mul_vec`). -/
def mul_vec [fintype n] (M : matrix m n α) (v : n → α) : m → α
| i := dot_product (λ j, M i j) v
/-- `vec_mul v M` is the vector-matrix product of `v` and `M`, where `v` is seen as a row matrix.
Put another way, `vec_mul v M` is the vector whose entries
are those of `row v ⬝ M` (see `row_vec_mul`). -/
def vec_mul [fintype m] (v : m → α) (M : matrix m n α) : n → α
| j := dot_product v (λ i, M i j)
/-- Left multiplication by a matrix, as an `add_monoid_hom` from vectors to vectors. -/
@[simps] def mul_vec.add_monoid_hom_left [fintype n] (v : n → α) : matrix m n α →+ m → α :=
{ to_fun := λ M, mul_vec M v,
map_zero' := by ext; simp [mul_vec]; refl,
map_add' := λ x y, by { ext m, apply add_dot_product } }
lemma mul_vec_diagonal [fintype m] [decidable_eq m] (v w : m → α) (x : m) :
mul_vec (diagonal v) w x = v x * w x :=
diagonal_dot_product v w x
lemma vec_mul_diagonal [fintype m] [decidable_eq m] (v w : m → α) (x : m) :
vec_mul v (diagonal w) x = v x * w x :=
dot_product_diagonal' v w x
/-- Associate the dot product of `mul_vec` to the left. -/
lemma dot_product_mul_vec [fintype n] [fintype m] [non_unital_semiring R]
(v : m → R) (A : matrix m n R) (w : n → R) :
dot_product v (mul_vec A w) = dot_product (vec_mul v A) w :=
by simp only [dot_product, vec_mul, mul_vec, finset.mul_sum, finset.sum_mul, mul_assoc];
exact finset.sum_comm
@[simp] lemma mul_vec_zero [fintype n] (A : matrix m n α) : mul_vec A 0 = 0 :=
by { ext, simp [mul_vec] }
@[simp] lemma zero_vec_mul [fintype m] (A : matrix m n α) : vec_mul 0 A = 0 :=
by { ext, simp [vec_mul] }
@[simp] lemma zero_mul_vec [fintype n] (v : n → α) : mul_vec (0 : matrix m n α) v = 0 :=
by { ext, simp [mul_vec] }
@[simp] lemma vec_mul_zero [fintype m] (v : m → α) : vec_mul v (0 : matrix m n α) = 0 :=
by { ext, simp [vec_mul] }
lemma vec_mul_vec_eq (w : m → α) (v : n → α) :
vec_mul_vec w v = (col w) ⬝ (row v) :=
by { ext i j, simp [vec_mul_vec, mul_apply], refl }
lemma smul_mul_vec_assoc [fintype n] [monoid R] [distrib_mul_action R α] [is_scalar_tower R α α]
(a : R) (A : matrix m n α) (b : n → α) :
(a • A).mul_vec b = a • (A.mul_vec b) :=
by { ext, apply smul_dot_product, }
lemma mul_vec_add [fintype n] (A : matrix m n α) (x y : n → α) :
A.mul_vec (x + y) = A.mul_vec x + A.mul_vec y :=
by { ext, apply dot_product_add }
lemma add_mul_vec [fintype n] (A B : matrix m n α) (x : n → α) :
(A + B).mul_vec x = A.mul_vec x + B.mul_vec x :=
by { ext, apply add_dot_product }
lemma vec_mul_add [fintype m] (A B : matrix m n α) (x : m → α) :
vec_mul x (A + B) = vec_mul x A + vec_mul x B :=
by { ext, apply dot_product_add }
lemma add_vec_mul [fintype m] (A : matrix m n α) (x y : m → α) :
vec_mul (x + y) A = vec_mul x A + vec_mul y A :=
by { ext, apply add_dot_product }
lemma vec_mul_smul [fintype n] [comm_semiring R] [semiring S] [algebra R S]
(M : matrix n m S) (b : R) (v : n → S) :
M.vec_mul (b • v) = b • M.vec_mul v :=
by { ext i, simp only [vec_mul, dot_product, finset.smul_sum, pi.smul_apply, smul_mul_assoc] }
lemma mul_vec_smul [fintype n] [comm_semiring R] [semiring S] [algebra R S]
(M : matrix m n S) (b : R) (v : n → S) :
M.mul_vec (b • v) = b • M.mul_vec v :=
by { ext i, simp only [mul_vec, dot_product, finset.smul_sum, pi.smul_apply, mul_smul_comm] }
end non_unital_non_assoc_semiring
section non_unital_semiring
variables [non_unital_semiring α] [fintype n]
@[simp] lemma vec_mul_vec_mul [fintype m] (v : m → α) (M : matrix m n α) (N : matrix n o α) :
vec_mul (vec_mul v M) N = vec_mul v (M ⬝ N) :=
by { ext, apply dot_product_assoc }
@[simp] lemma mul_vec_mul_vec [fintype o] (v : o → α) (M : matrix m n α) (N : matrix n o α) :
mul_vec M (mul_vec N v) = mul_vec (M ⬝ N) v :=
by { ext, symmetry, apply dot_product_assoc }
end non_unital_semiring
section non_assoc_semiring
variables [fintype m] [decidable_eq m] [non_assoc_semiring α]
@[simp] lemma one_mul_vec (v : m → α) : mul_vec 1 v = v :=
by { ext, rw [←diagonal_one, mul_vec_diagonal, one_mul] }
@[simp] lemma vec_mul_one (v : m → α) : vec_mul v 1 = v :=
by { ext, rw [←diagonal_one, vec_mul_diagonal, mul_one] }
end non_assoc_semiring
section ring
variables [ring α]
lemma neg_vec_mul [fintype m] (v : m → α) (A : matrix m n α) : vec_mul (-v) A = - vec_mul v A :=
by { ext, apply neg_dot_product }
lemma vec_mul_neg [fintype m] (v : m → α) (A : matrix m n α) : vec_mul v (-A) = - vec_mul v A :=
by { ext, apply dot_product_neg }
lemma neg_mul_vec [fintype n] (v : n → α) (A : matrix m n α) : mul_vec (-A) v = - mul_vec A v :=
by { ext, apply neg_dot_product }
lemma mul_vec_neg [fintype n] (v : n → α) (A : matrix m n α) : mul_vec A (-v) = - mul_vec A v :=
by { ext, apply dot_product_neg }
end ring
section comm_semiring
variables [comm_semiring α]
lemma mul_vec_smul_assoc [fintype n] (A : matrix m n α) (b : n → α) (a : α) :
A.mul_vec (a • b) = a • (A.mul_vec b) :=
by { ext, apply dot_product_smul }
lemma mul_vec_transpose [fintype m] (A : matrix m n α) (x : m → α) :
mul_vec Aᵀ x = vec_mul x A :=
by { ext, apply dot_product_comm }
lemma vec_mul_transpose [fintype n] (A : matrix m n α) (x : n → α) :
vec_mul x Aᵀ = mul_vec A x :=
by { ext, apply dot_product_comm }
end comm_semiring
section transpose
open_locale matrix
/--
Tell `simp` what the entries are in a transposed matrix.
Compare with `mul_apply`, `diagonal_apply_eq`, etc.
-/
@[simp] lemma transpose_apply (M : matrix m n α) (i j) : M.transpose j i = M i j := rfl
@[simp] lemma transpose_transpose (M : matrix m n α) :
Mᵀᵀ = M :=
by ext; refl
@[simp] lemma transpose_zero [has_zero α] : (0 : matrix m n α)ᵀ = 0 :=
by ext i j; refl
@[simp] lemma transpose_one [decidable_eq n] [has_zero α] [has_one α] : (1 : matrix n n α)ᵀ = 1 :=
begin
ext i j,
unfold has_one.one transpose,
by_cases i = j,
{ simp only [h, diagonal_apply_eq] },
{ simp only [diagonal_apply_ne h, diagonal_apply_ne (λ p, h (symm p))] }
end
@[simp] lemma transpose_add [has_add α] (M : matrix m n α) (N : matrix m n α) :
(M + N)ᵀ = Mᵀ + Nᵀ :=
by { ext i j, simp }
@[simp] lemma transpose_sub [has_sub α] (M : matrix m n α) (N : matrix m n α) :
(M - N)ᵀ = Mᵀ - Nᵀ :=
by { ext i j, simp }
@[simp] lemma transpose_mul [comm_semiring α] [fintype n] (M : matrix m n α) (N : matrix n l α) :
(M ⬝ N)ᵀ = Nᵀ ⬝ Mᵀ :=
begin
ext i j,
apply dot_product_comm
end
@[simp] lemma transpose_smul {R : Type*} [has_scalar R α] (c : R) (M : matrix m n α) :
(c • M)ᵀ = c • Mᵀ :=
by { ext i j, refl }
@[simp] lemma transpose_neg [has_neg α] (M : matrix m n α) :
(- M)ᵀ = - Mᵀ :=
by ext i j; refl
lemma transpose_map {f : α → β} {M : matrix m n α} : Mᵀ.map f = (M.map f)ᵀ :=
by { ext, refl }
/-- `matrix.transpose` as an `add_equiv` -/
@[simps apply]
def transpose_add_equiv [has_add α] : matrix m n α ≃+ matrix n m α :=
{ to_fun := transpose,
inv_fun := transpose,
left_inv := transpose_transpose,
right_inv := transpose_transpose,
map_add' := transpose_add }
@[simp] lemma transpose_add_equiv_symm [has_add α] :
(transpose_add_equiv : matrix m n α ≃+ matrix n m α).symm = transpose_add_equiv := rfl
lemma transpose_list_sum [add_monoid α] (l : list (matrix m n α)) :
l.sumᵀ = (l.map transpose).sum :=
(transpose_add_equiv : matrix m n α ≃+ matrix n m α).to_add_monoid_hom.map_list_sum l
lemma transpose_multiset_sum [add_comm_monoid α] (s : multiset (matrix m n α)) :
s.sumᵀ = (s.map transpose).sum :=
(transpose_add_equiv : matrix m n α ≃+ matrix n m α).to_add_monoid_hom.map_multiset_sum s
lemma transpose_sum [add_comm_monoid α] {ι : Type*} (s : finset ι) (M : ι → matrix m n α) :
(∑ i in s, M i)ᵀ = ∑ i in s, (M i)ᵀ :=
(transpose_add_equiv : matrix m n α ≃+ matrix n m α).to_add_monoid_hom.map_sum _ s
/-- `matrix.transpose` as a `ring_equiv` to the opposite ring -/
@[simps]
def transpose_ring_equiv [comm_semiring α] [fintype m] : matrix m m α ≃+* (matrix m m α)ᵐᵒᵖ :=
{ to_fun := λ M, mul_opposite.op (Mᵀ),
inv_fun := λ M, M.unopᵀ,
map_mul' := λ M N, (congr_arg mul_opposite.op (transpose_mul M N)).trans
(mul_opposite.op_mul _ _),
..transpose_add_equiv.trans mul_opposite.op_add_equiv }
lemma transpose_list_prod [comm_semiring α] [fintype m] [decidable_eq m] (l : list (matrix m m α)) :
l.prodᵀ = (l.map transpose).reverse.prod :=
(transpose_ring_equiv : matrix m m α ≃+* (matrix m m α)ᵐᵒᵖ).unop_map_list_prod l
end transpose
section conj_transpose
open_locale matrix
/--
Tell `simp` what the entries are in a conjugate transposed matrix.
Compare with `mul_apply`, `diagonal_apply_eq`, etc.
-/
@[simp] lemma conj_transpose_apply [has_star α] (M : matrix m n α) (i j) :
M.conj_transpose j i = star (M i j) := rfl
@[simp] lemma conj_transpose_conj_transpose [has_involutive_star α] (M : matrix m n α) :
Mᴴᴴ = M :=
by ext; simp
@[simp] lemma conj_transpose_zero [semiring α] [star_ring α] : (0 : matrix m n α)ᴴ = 0 :=
by ext i j; simp
@[simp] lemma conj_transpose_one [decidable_eq n] [semiring α] [star_ring α]:
(1 : matrix n n α)ᴴ = 1 :=
by simp [conj_transpose]
@[simp] lemma conj_transpose_add [add_monoid α] [star_add_monoid α] (M N : matrix m n α) :
(M + N)ᴴ = Mᴴ + Nᴴ := by ext i j; simp
@[simp] lemma conj_transpose_sub [add_group α] [star_add_monoid α] (M N : matrix m n α) :
(M - N)ᴴ = Mᴴ - Nᴴ := by ext i j; simp
@[simp] lemma conj_transpose_smul [comm_monoid α] [star_monoid α] (c : α) (M : matrix m n α) :
(c • M)ᴴ = (star c) • Mᴴ :=
by ext i j; simp [mul_comm]
@[simp] lemma conj_transpose_mul [fintype n] [semiring α] [star_ring α]
(M : matrix m n α) (N : matrix n l α) : (M ⬝ N)ᴴ = Nᴴ ⬝ Mᴴ := by ext i j; simp [mul_apply]
@[simp] lemma conj_transpose_neg [ring α] [star_ring α] (M : matrix m n α) :
(- M)ᴴ = - Mᴴ := by ext i j; simp
/-- `matrix.conj_transpose` as an `add_equiv` -/
@[simps apply]
def conj_transpose_add_equiv [add_monoid α] [star_add_monoid α] : matrix m n α ≃+ matrix n m α :=
{ to_fun := conj_transpose,
inv_fun := conj_transpose,
left_inv := conj_transpose_conj_transpose,
right_inv := conj_transpose_conj_transpose,
map_add' := conj_transpose_add }
@[simp] lemma conj_transpose_add_equiv_symm [add_monoid α] [star_add_monoid α] :
(conj_transpose_add_equiv : matrix m n α ≃+ matrix n m α).symm = conj_transpose_add_equiv := rfl
lemma conj_transpose_list_sum [add_monoid α] [star_add_monoid α] (l : list (matrix m n α)) :
l.sumᴴ = (l.map conj_transpose).sum :=
(conj_transpose_add_equiv : matrix m n α ≃+ matrix n m α).to_add_monoid_hom.map_list_sum l
lemma conj_transpose_multiset_sum [add_comm_monoid α] [star_add_monoid α]
(s : multiset (matrix m n α)) :
s.sumᴴ = (s.map conj_transpose).sum :=
(conj_transpose_add_equiv : matrix m n α ≃+ matrix n m α).to_add_monoid_hom.map_multiset_sum s
lemma conj_transpose_sum [add_comm_monoid α] [star_add_monoid α] {ι : Type*} (s : finset ι)
(M : ι → matrix m n α) :
(∑ i in s, M i)ᴴ = ∑ i in s, (M i)ᴴ :=
(conj_transpose_add_equiv : matrix m n α ≃+ matrix n m α).to_add_monoid_hom.map_sum _ s
/-- `matrix.conj_transpose` as a `ring_equiv` to the opposite ring -/
@[simps]
def conj_transpose_ring_equiv [comm_semiring α] [star_ring α] [fintype m] :
matrix m m α ≃+* (matrix m m α)ᵐᵒᵖ :=
{ to_fun := λ M, mul_opposite.op (Mᴴ),
inv_fun := λ M, M.unopᴴ,
map_mul' := λ M N, (congr_arg mul_opposite.op (conj_transpose_mul M N)).trans
(mul_opposite.op_mul _ _),
..conj_transpose_add_equiv.trans mul_opposite.op_add_equiv }
lemma conj_transpose_list_prod [comm_semiring α] [star_ring α] [fintype m] [decidable_eq m]
(l : list (matrix m m α)) :
l.prodᴴ = (l.map conj_transpose).reverse.prod :=
(conj_transpose_ring_equiv : matrix m m α ≃+* (matrix m m α)ᵐᵒᵖ).unop_map_list_prod l
end conj_transpose
section star
/-- When `α` has a star operation, square matrices `matrix n n α` have a star
operation equal to `matrix.conj_transpose`. -/
instance [has_star α] : has_star (matrix n n α) := {star := conj_transpose}
lemma star_eq_conj_transpose [has_star α] (M : matrix m m α) : star M = Mᴴ := rfl
@[simp] lemma star_apply [has_star α] (M : matrix n n α) (i j) :
(star M) i j = star (M j i) := rfl
instance [has_involutive_star α] : has_involutive_star (matrix n n α) :=
{ star_involutive := conj_transpose_conj_transpose }
/-- When `α` is a `*`-additive monoid, `matrix.has_star` is also a `*`-additive monoid. -/
instance [add_monoid α] [star_add_monoid α] : star_add_monoid (matrix n n α) :=
{ star_add := conj_transpose_add }
/-- When `α` is a `*`-(semi)ring, `matrix.has_star` is also a `*`-(semi)ring. -/
instance [fintype n] [decidable_eq n] [semiring α] [star_ring α] : star_ring (matrix n n α) :=
{ star_add := conj_transpose_add,
star_mul := conj_transpose_mul, }
/-- A version of `star_mul` for `⬝` instead of `*`. -/
lemma star_mul [fintype n] [semiring α] [star_ring α] (M N : matrix n n α) :
star (M ⬝ N) = star N ⬝ star M := conj_transpose_mul _ _
end star
/-- Given maps `(r_reindex : l → m)` and `(c_reindex : o → n)` reindexing the rows and columns of
a matrix `M : matrix m n α`, the matrix `M.minor r_reindex c_reindex : matrix l o α` is defined
by `(M.minor r_reindex c_reindex) i j = M (r_reindex i) (c_reindex j)` for `(i,j) : l × o`.
Note that the total number of row and columns does not have to be preserved. -/
def minor (A : matrix m n α) (r_reindex : l → m) (c_reindex : o → n) : matrix l o α :=
λ i j, A (r_reindex i) (c_reindex j)
@[simp] lemma minor_apply (A : matrix m n α) (r_reindex : l → m) (c_reindex : o → n) (i j) :
A.minor r_reindex c_reindex i j = A (r_reindex i) (c_reindex j) := rfl
@[simp] lemma minor_id_id (A : matrix m n α) :
A.minor id id = A :=
ext $ λ _ _, rfl
@[simp] lemma minor_minor {l₂ o₂ : Type*} (A : matrix m n α)
(r₁ : l → m) (c₁ : o → n) (r₂ : l₂ → l) (c₂ : o₂ → o) :
(A.minor r₁ c₁).minor r₂ c₂ = A.minor (r₁ ∘ r₂) (c₁ ∘ c₂) :=
ext $ λ _ _, rfl
@[simp] lemma transpose_minor (A : matrix m n α) (r_reindex : l → m) (c_reindex : o → n) :
(A.minor r_reindex c_reindex)ᵀ = Aᵀ.minor c_reindex r_reindex :=
ext $ λ _ _, rfl
@[simp] lemma conj_transpose_minor
[has_star α] (A : matrix m n α) (r_reindex : l → m) (c_reindex : o → n) :
(A.minor r_reindex c_reindex)ᴴ = Aᴴ.minor c_reindex r_reindex :=
ext $ λ _ _, rfl
lemma minor_add [has_add α] (A B : matrix m n α) :
((A + B).minor : (l → m) → (o → n) → matrix l o α) = A.minor + B.minor := rfl
lemma minor_neg [has_neg α] (A : matrix m n α) :
((-A).minor : (l → m) → (o → n) → matrix l o α) = -A.minor := rfl
lemma minor_sub [has_sub α] (A B : matrix m n α) :
((A - B).minor : (l → m) → (o → n) → matrix l o α) = A.minor - B.minor := rfl
@[simp]
lemma minor_zero [has_zero α] :
((0 : matrix m n α).minor : (l → m) → (o → n) → matrix l o α) = 0 := rfl
lemma minor_smul {R : Type*} [semiring R] [add_comm_monoid α] [module R α] (r : R)
(A : matrix m n α) :
((r • A : matrix m n α).minor : (l → m) → (o → n) → matrix l o α) = r • A.minor := rfl
lemma minor_map (f : α → β) (e₁ : l → m) (e₂ : o → n) (A : matrix m n α) :
(A.map f).minor e₁ e₂ = (A.minor e₁ e₂).map f := rfl
/-- Given a `(m × m)` diagonal matrix defined by a map `d : m → α`, if the reindexing map `e` is
injective, then the resulting matrix is again diagonal. -/
lemma minor_diagonal [has_zero α] [decidable_eq m] [decidable_eq l] (d : m → α) (e : l → m)
(he : function.injective e) :
(diagonal d).minor e e = diagonal (d ∘ e) :=
ext $ λ i j, begin
rw minor_apply,
by_cases h : i = j,
{ rw [h, diagonal_apply_eq, diagonal_apply_eq], },
{ rw [diagonal_apply_ne h, diagonal_apply_ne (he.ne h)], },
end
lemma minor_one [has_zero α] [has_one α] [decidable_eq m] [decidable_eq l] (e : l → m)
(he : function.injective e) :
(1 : matrix m m α).minor e e = 1 :=
minor_diagonal _ e he
lemma minor_mul [fintype n] [fintype o] [semiring α] {p q : Type*}
(M : matrix m n α) (N : matrix n p α)
(e₁ : l → m) (e₂ : o → n) (e₃ : q → p) (he₂ : function.bijective e₂) :
(M ⬝ N).minor e₁ e₃ = (M.minor e₁ e₂) ⬝ (N.minor e₂ e₃) :=
ext $ λ _ _, (he₂.sum_comp _).symm
/-! `simp` lemmas for `matrix.minor`s interaction with `matrix.diagonal`, `1`, and `matrix.mul` for
when the mappings are bundled. -/
@[simp]
lemma minor_diagonal_embedding [has_zero α] [decidable_eq m] [decidable_eq l] (d : m → α)
(e : l ↪ m) :
(diagonal d).minor e e = diagonal (d ∘ e) :=
minor_diagonal d e e.injective
@[simp]
lemma minor_diagonal_equiv [has_zero α] [decidable_eq m] [decidable_eq l] (d : m → α)
(e : l ≃ m) :
(diagonal d).minor e e = diagonal (d ∘ e) :=
minor_diagonal d e e.injective
@[simp]
lemma minor_one_embedding [has_zero α] [has_one α] [decidable_eq m] [decidable_eq l] (e : l ↪ m) :
(1 : matrix m m α).minor e e = 1 :=
minor_one e e.injective
@[simp]
lemma minor_one_equiv [has_zero α] [has_one α] [decidable_eq m] [decidable_eq l] (e : l ≃ m) :
(1 : matrix m m α).minor e e = 1 :=
minor_one e e.injective
lemma minor_mul_equiv [fintype n] [fintype o] [semiring α] {p q : Type*}
(M : matrix m n α) (N : matrix n p α) (e₁ : l → m) (e₂ : o ≃ n) (e₃ : q → p) :
(M ⬝ N).minor e₁ e₃ = (M.minor e₁ e₂) ⬝ (N.minor e₂ e₃) :=
minor_mul M N e₁ e₂ e₃ e₂.bijective
lemma mul_minor_one [fintype n] [fintype o] [semiring α] [decidable_eq o] (e₁ : n ≃ o) (e₂ : l → o)
(M : matrix m n α) : M ⬝ (1 : matrix o o α).minor e₁ e₂ = minor M id (e₁.symm ∘ e₂) :=
begin
let A := M.minor id e₁.symm,
have : M = A.minor id e₁,
{ simp only [minor_minor, function.comp.right_id, minor_id_id, equiv.symm_comp_self], },
rw [this, ←minor_mul_equiv],
simp only [matrix.mul_one, minor_minor, function.comp.right_id, minor_id_id,
equiv.symm_comp_self],
end
lemma one_minor_mul [fintype m] [fintype o] [semiring α] [decidable_eq o] (e₁ : l → o) (e₂ : m ≃ o)
(M : matrix m n α) : ((1 : matrix o o α).minor e₁ e₂).mul M = minor M (e₂.symm ∘ e₁) id :=
begin
let A := M.minor e₂.symm id,
have : M = A.minor e₂ id,
{ simp only [minor_minor, function.comp.right_id, minor_id_id, equiv.symm_comp_self], },
rw [this, ←minor_mul_equiv],
simp only [matrix.one_mul, minor_minor, function.comp.right_id, minor_id_id,
equiv.symm_comp_self],
end
/-- The natural map that reindexes a matrix's rows and columns with equivalent types is an
equivalence. -/
def reindex (eₘ : m ≃ l) (eₙ : n ≃ o) : matrix m n α ≃ matrix l o α :=
{ to_fun := λ M, M.minor eₘ.symm eₙ.symm,
inv_fun := λ M, M.minor eₘ eₙ,
left_inv := λ M, by simp,
right_inv := λ M, by simp, }
@[simp] lemma reindex_apply (eₘ : m ≃ l) (eₙ : n ≃ o) (M : matrix m n α) :
reindex eₘ eₙ M = M.minor eₘ.symm eₙ.symm :=
rfl
@[simp] lemma reindex_refl_refl (A : matrix m n α) :
reindex (equiv.refl _) (equiv.refl _) A = A :=
A.minor_id_id
@[simp] lemma reindex_symm (eₘ : m ≃ l) (eₙ : n ≃ o) :
(reindex eₘ eₙ).symm = (reindex eₘ.symm eₙ.symm : matrix l o α ≃ _) :=
rfl
@[simp] lemma reindex_trans {l₂ o₂ : Type*} (eₘ : m ≃ l) (eₙ : n ≃ o)
(eₘ₂ : l ≃ l₂) (eₙ₂ : o ≃ o₂) : (reindex eₘ eₙ).trans (reindex eₘ₂ eₙ₂) =
(reindex (eₘ.trans eₘ₂) (eₙ.trans eₙ₂) : matrix m n α ≃ _) :=
equiv.ext $ λ A, (A.minor_minor eₘ.symm eₙ.symm eₘ₂.symm eₙ₂.symm : _)
lemma transpose_reindex (eₘ : m ≃ l) (eₙ : n ≃ o) (M : matrix m n α) :
(reindex eₘ eₙ M)ᵀ = (reindex eₙ eₘ Mᵀ) :=
rfl
lemma conj_transpose_reindex [has_star α] (eₘ : m ≃ l) (eₙ : n ≃ o) (M : matrix m n α) :
(reindex eₘ eₙ M)ᴴ = (reindex eₙ eₘ Mᴴ) :=
rfl
/-- The left `n × l` part of a `n × (l+r)` matrix. -/
@[reducible]
def sub_left {m l r : nat} (A : matrix (fin m) (fin (l + r)) α) : matrix (fin m) (fin l) α :=
minor A id (fin.cast_add r)
/-- The right `n × r` part of a `n × (l+r)` matrix. -/
@[reducible]
def sub_right {m l r : nat} (A : matrix (fin m) (fin (l + r)) α) : matrix (fin m) (fin r) α :=
minor A id (fin.nat_add l)
/-- The top `u × n` part of a `(u+d) × n` matrix. -/
@[reducible]
def sub_up {d u n : nat} (A : matrix (fin (u + d)) (fin n) α) : matrix (fin u) (fin n) α :=
minor A (fin.cast_add d) id
/-- The bottom `d × n` part of a `(u+d) × n` matrix. -/
@[reducible]
def sub_down {d u n : nat} (A : matrix (fin (u + d)) (fin n) α) : matrix (fin d) (fin n) α :=
minor A (fin.nat_add u) id
/-- The top-right `u × r` part of a `(u+d) × (l+r)` matrix. -/
@[reducible]
def sub_up_right {d u l r : nat} (A: matrix (fin (u + d)) (fin (l + r)) α) :
matrix (fin u) (fin r) α :=
sub_up (sub_right A)
/-- The bottom-right `d × r` part of a `(u+d) × (l+r)` matrix. -/
@[reducible]
def sub_down_right {d u l r : nat} (A : matrix (fin (u + d)) (fin (l + r)) α) :
matrix (fin d) (fin r) α :=
sub_down (sub_right A)
/-- The top-left `u × l` part of a `(u+d) × (l+r)` matrix. -/
@[reducible]
def sub_up_left {d u l r : nat} (A : matrix (fin (u + d)) (fin (l + r)) α) :
matrix (fin u) (fin (l)) α :=
sub_up (sub_left A)
/-- The bottom-left `d × l` part of a `(u+d) × (l+r)` matrix. -/
@[reducible]
def sub_down_left {d u l r : nat} (A: matrix (fin (u + d)) (fin (l + r)) α) :
matrix (fin d) (fin (l)) α :=
sub_down (sub_left A)
section row_col
/-!
### `row_col` section
Simplification lemmas for `matrix.row` and `matrix.col`.
-/
open_locale matrix
@[simp] lemma col_add [has_add α] (v w : m → α) : col (v + w) = col v + col w := by { ext, refl }
@[simp] lemma col_smul [has_scalar R α] (x : R) (v : m → α) : col (x • v) = x • col v :=
by { ext, refl }
@[simp] lemma row_add [has_add α] (v w : m → α) : row (v + w) = row v + row w := by { ext, refl }
@[simp] lemma row_smul [has_scalar R α] (x : R) (v : m → α) : row (x • v) = x • row v :=
by { ext, refl }
@[simp] lemma col_apply (v : m → α) (i j) : matrix.col v i j = v i := rfl
@[simp] lemma row_apply (v : m → α) (i j) : matrix.row v i j = v j := rfl
@[simp]
lemma transpose_col (v : m → α) : (matrix.col v)ᵀ = matrix.row v := by { ext, refl }
@[simp]
lemma transpose_row (v : m → α) : (matrix.row v)ᵀ = matrix.col v := by { ext, refl }
@[simp]
lemma conj_transpose_col [has_star α] (v : m → α) : (col v)ᴴ = row (star v) := by { ext, refl }
@[simp]
lemma conj_transpose_row [has_star α] (v : m → α) : (row v)ᴴ = col (star v) := by { ext, refl }
lemma row_vec_mul [fintype m] [semiring α] (M : matrix m n α) (v : m → α) :
matrix.row (matrix.vec_mul v M) = matrix.row v ⬝ M := by {ext, refl}
lemma col_vec_mul [fintype m] [semiring α] (M : matrix m n α) (v : m → α) :
matrix.col (matrix.vec_mul v M) = (matrix.row v ⬝ M)ᵀ := by {ext, refl}
lemma col_mul_vec [fintype n] [semiring α] (M : matrix m n α) (v : n → α) :
matrix.col (matrix.mul_vec M v) = M ⬝ matrix.col v := by {ext, refl}
lemma row_mul_vec [fintype n] [semiring α] (M : matrix m n α) (v : n → α) :
matrix.row (matrix.mul_vec M v) = (M ⬝ matrix.col v)ᵀ := by {ext, refl}
@[simp]
lemma row_mul_col_apply [fintype m] [has_mul α] [add_comm_monoid α] (v w : m → α) (i j) :
(row v ⬝ col w) i j = dot_product v w :=
rfl
end row_col
section update
/-- Update, i.e. replace the `i`th row of matrix `A` with the values in `b`. -/
def update_row [decidable_eq n] (M : matrix n m α) (i : n) (b : m → α) : matrix n m α :=
function.update M i b
/-- Update, i.e. replace the `j`th column of matrix `A` with the values in `b`. -/
def update_column [decidable_eq m] (M : matrix n m α) (j : m) (b : n → α) : matrix n m α :=
λ i, function.update (M i) j (b i)
variables {M : matrix n m α} {i : n} {j : m} {b : m → α} {c : n → α}
@[simp] lemma update_row_self [decidable_eq n] : update_row M i b i = b :=
function.update_same i b M
@[simp] lemma update_column_self [decidable_eq m] : update_column M j c i j = c i :=
function.update_same j (c i) (M i)
@[simp] lemma update_row_ne [decidable_eq n] {i' : n} (i_ne : i' ≠ i) :
update_row M i b i' = M i' := function.update_noteq i_ne b M
@[simp] lemma update_column_ne [decidable_eq m] {j' : m} (j_ne : j' ≠ j) :
update_column M j c i j' = M i j' := function.update_noteq j_ne (c i) (M i)
lemma update_row_apply [decidable_eq n] {i' : n} :
update_row M i b i' j = if i' = i then b j else M i' j :=
begin
by_cases i' = i,
{ rw [h, update_row_self, if_pos rfl] },
{ rwa [update_row_ne h, if_neg h] }
end
lemma update_column_apply [decidable_eq m] {j' : m} :
update_column M j c i j' = if j' = j then c i else M i j' :=
begin
by_cases j' = j,
{ rw [h, update_column_self, if_pos rfl] },
{ rwa [update_column_ne h, if_neg h] }
end
@[simp] lemma update_column_subsingleton [subsingleton m] (A : matrix n m R)
(i : m) (b : n → R) :
A.update_column i b = (col b).minor id (function.const m ()) :=
begin
ext x y,
simp [update_column_apply, subsingleton.elim i y]
end
@[simp] lemma update_row_subsingleton [subsingleton n] (A : matrix n m R)
(i : n) (b : m → R) :
A.update_row i b = (row b).minor (function.const n ()) id :=
begin
ext x y,
simp [update_column_apply, subsingleton.elim i x]
end
lemma map_update_row [decidable_eq n] (f : α → β) :
map (update_row M i b) f = update_row (M.map f) i (f ∘ b) :=
begin
ext i' j',
rw [update_row_apply, map_apply, map_apply, update_row_apply],
exact apply_ite f _ _ _,
end
lemma map_update_column [decidable_eq m] (f : α → β) :
map (update_column M j c) f = update_column (M.map f) j (f ∘ c) :=
begin
ext i' j',
rw [update_column_apply, map_apply, map_apply, update_column_apply],
exact apply_ite f _ _ _,
end
lemma update_row_transpose [decidable_eq m] : update_row Mᵀ j c = (update_column M j c)ᵀ :=
begin
ext i' j,
rw [transpose_apply, update_row_apply, update_column_apply],
refl
end
lemma update_column_transpose [decidable_eq n] : update_column Mᵀ i b = (update_row M i b)ᵀ :=
begin
ext i' j,
rw [transpose_apply, update_row_apply, update_column_apply],
refl
end
lemma update_row_conj_transpose [decidable_eq m] [has_star α] :
update_row Mᴴ j (star c) = (update_column M j c)ᴴ :=
begin
rw [conj_transpose, conj_transpose, transpose_map, transpose_map, update_row_transpose,
map_update_column],
refl,
end
lemma update_column_conj_transpose [decidable_eq n] [has_star α] :
update_column Mᴴ i (star b) = (update_row M i b)ᴴ :=
begin
rw [conj_transpose, conj_transpose, transpose_map, transpose_map, update_column_transpose,
map_update_row],
refl,
end
@[simp] lemma update_row_eq_self [decidable_eq m]
(A : matrix m n α) {i : m} :
A.update_row i (A i) = A :=
function.update_eq_self i A
@[simp] lemma update_column_eq_self [decidable_eq n]
(A : matrix m n α) {i : n} :
A.update_column i (λ j, A j i) = A :=
funext $ λ j, function.update_eq_self i (A j)
end update
end matrix
namespace ring_hom
variables [fintype n] [semiring α] [semiring β]
lemma map_matrix_mul (M : matrix m n α) (N : matrix n o α) (i : m) (j : o) (f : α →+* β) :
f (matrix.mul M N i j) = matrix.mul (λ i j, f (M i j)) (λ i j, f (N i j)) i j :=
by simp [matrix.mul_apply, ring_hom.map_sum]
lemma map_dot_product [semiring R] [semiring S] (f : R →+* S) (v w : n → R) :
f (matrix.dot_product v w) = matrix.dot_product (f ∘ v) (f ∘ w) :=
by simp only [matrix.dot_product, f.map_sum, f.map_mul]
lemma map_vec_mul [semiring R] [semiring S]
(f : R →+* S) (M : matrix n m R) (v : n → R) (i : m) :
f (M.vec_mul v i) = ((M.map f).vec_mul (f ∘ v) i) :=
by simp only [matrix.vec_mul, matrix.map_apply, ring_hom.map_dot_product]
lemma map_mul_vec [semiring R] [semiring S]
(f : R →+* S) (M : matrix m n R) (v : n → R) (i : m) :
f (M.mul_vec v i) = ((M.map f).mul_vec (f ∘ v) i) :=
by simp only [matrix.mul_vec, matrix.map_apply, ring_hom.map_dot_product]
end ring_hom
|
{-# LANGUAGE Rank2Types, FlexibleContexts, UndecidableInstances, FlexibleInstances, ScopedTypeVariables, DataKinds #-}
module Lib.Utility.Mnist
(
getMnistData, miniBatch,
TrainingData
) where
import Lib.Utility.Mnist.IO
import qualified Numeric.LinearAlgebra as HMatrix
import qualified Numeric.LinearAlgebra.Static as Static
import Numeric.LinearAlgebra.Devel
import Control.Monad.ST
import Data.Array.ST
import Control.Arrow
import Data.Proxy
import GHC.TypeLits
import Control.Monad.Trans.Maybe
import System.Random
miniBatch :: forall n m. (KnownNat n, KnownNat m) => TrainingData n -> MaybeT IO (TrainingData m)
miniBatch (images, labels) = MaybeT $ do
let allSize = fromIntegral $ natVal (Proxy :: Proxy n)
let size = fromIntegral $ natVal (Proxy :: Proxy m)
gen <- newStdGen
let rs = HMatrix.idxs $ take size $ randomRs (0, allSize - 1) gen
let extr = (HMatrix.Pos rs, HMatrix.All)
return $ do
images' <- (Static.create $ Static.unwrap images HMatrix.?? extr) :: Maybe (Static.L m 784)
labels' <- (Static.create $ Static.unwrap labels HMatrix.?? extr) :: Maybe (Static.L m 10)
return (images', labels')
|
The actors , directors , screenwriters and producers interviewed for the film were :
|
module Main where
import Control.Monad (liftM)
import Data.Array (Array (..), listArray)
import Data.Char (toLower)
import Data.Ratio (Rational (..), (%))
import Data.Complex (Complex (..))
import Numeric (readOct, readHex)
import System.Environment
import Text.ParserCombinators.Parsec hiding (spaces)
data LispVal = Atom String
| List [LispVal]
| DottedList [LispVal] LispVal
| Number Integer
| Ratio Rational
| Float Double
| Complex (Complex Double)
| String String
| Char Char
| Bool Bool
| Vector (Array Int LispVal)
instance Show LispVal where show = showVal
main :: IO ()
main = getArgs >>= print . eval . readExpr . head
readExpr :: String -> LispVal
readExpr input = case parse parseExpr "lisp" input of
Left err -> String $ "No match: " ++ show err
Right val -> val
--
-- LispVal Parsers
--
parseExpr :: Parser LispVal
parseExpr = parseAtom
<|> parseString
<|> try parseChar
<|> try parseComplex
<|> try parseFloat
<|> try parseRatio
<|> try parseNumber
<|> parseBool
<|> parseQuoted
<|> parseQuasiquote
<|> try parseUnquoteSplicing
<|> parseUnquote
<|> parseList
parseAtom :: Parser LispVal
parseAtom = do first <- letter <|> symbol
rest <- many (letter <|> digit <|> symbol)
(return . Atom) (first:rest)
parseList :: Parser LispVal
parseList = char '(' >> parseList1
parseList1 :: Parser LispVal
parseList1 = (char ')' >> (return . List) [])
<|> do expr <- parseExpr
parseList2 [expr]
parseList2 :: [LispVal] -> Parser LispVal
parseList2 expr = (char ')' >> (return . List) (reverse expr))
<|> (spaces >> parseList3 expr)
parseList3 :: [LispVal] -> Parser LispVal
parseList3 expr = do char '.' >> spaces
dotted <- parseExpr
char ')'
return $ DottedList expr dotted
<|> do next <- parseExpr
parseList2 (next:expr)
parseQuoted :: Parser LispVal
parseQuoted = do char '\''
x <- parseExpr
return $ List [Atom "quote", x]
parseNumber :: Parser LispVal
parseNumber = parsePlainNumber <|> parseRadixNumber
parsePlainNumber :: Parser LispVal
parsePlainNumber = (Number . read) <$> many1 digit
parseRadixNumber :: Parser LispVal
parseRadixNumber = char '#' >>
(
parseDecimal
<|> parseBinary
<|> parseOctal
<|> parseHex
)
parseDecimal :: Parser LispVal
parseDecimal = do char 'd'
n <- many1 digit
(return . Number . read) n
parseBinary :: Parser LispVal
parseBinary = do char 'b'
n <- many $ oneOf "01"
(return . Number . bin2int) n
parseOctal :: Parser LispVal
parseOctal = do char 'o'
n <- many $ oneOf "01234567"
(return . Number . (readWith readOct)) n
parseHex :: Parser LispVal
parseHex = do char 'x'
n <- many $ oneOf "0123456789abcdefABCDEF"
(return . Number . (readWith readHex)) n
parseRatio :: Parser LispVal
parseRatio = do num <- fmap read $ many1 digit
char '/'
denom <- fmap read $ many1 digit
(return . Ratio) (num % denom)
parseFloat :: Parser LispVal
parseFloat = do whole <- many1 digit
char '.'
decimal <- many1 digit
return $ Float (read (whole++"."++decimal))
parseComplex :: Parser LispVal
parseComplex = do r <- fmap toDouble (try parseFloat <|> parsePlainNumber)
char '+'
i <- fmap toDouble (try parseFloat <|> parsePlainNumber)
char 'i'
(return . Complex) (r :+ i)
where toDouble (Float x) = x
toDouble (Number x) = fromIntegral x
parseString :: Parser LispVal
parseString = do char '"'
s <- many (escapedChars <|> (noneOf ['\\', '"']))
char '"'
(return . String) s
parseChar :: Parser LispVal
parseChar = do string "#\\"
s <- many1 letter
return $ case (map toLower s) of
"space" -> Char ' '
"newline" -> Char '\n'
[x] -> Char x
parseBool :: Parser LispVal
parseBool = do char '#'
c <- oneOf "tf"
return $ case c of
't' -> Bool True
'f' -> Bool False
parseQuasiquote :: Parser LispVal
parseQuasiquote = do char '`'
expr <- parseExpr
return $ List [Atom "quasiquote", expr]
-- Bug: this allows the unquote to appear outside of a quasiquoted list
parseUnquote :: Parser LispVal
parseUnquote = do char ','
expr <- parseExpr
return $ List [Atom "unquote", expr]
-- Bug: this allows unquote-splicing to appear outside of a quasiquoted list
parseUnquoteSplicing :: Parser LispVal
parseUnquoteSplicing = do string ",@"
expr <- parseExpr
return $ List [Atom "unquote-splicing", expr]
parseVector :: Parser LispVal
parseVector = do string "#("
elems <- sepBy parseExpr spaces
char ')'
return $ Vector (listArray (0, (length elems)-1) elems)
--
-- Show functions
--
showVal :: LispVal -> String
showVal (String s) = "\"" ++ s ++ "\""
showVal (Atom name) = name
showVal (Number n) = show n
showVal (Bool True) = "#t"
showVal (Bool False) = "#f"
showVal (List xs) = "(" ++ unwordsList xs ++ ")"
showVal (DottedList head tail) = "(" ++ unwordsList head ++ " . " ++ showVal tail ++ ")"
--
-- Evaluator
--
eval :: LispVal -> LispVal
eval val@(String _) = val
eval val@(Number _) = val
eval val@(Bool _) = val
eval (List [Atom "quote", val]) = val
eval (List (Atom func : args)) = apply func $ map eval args
--
-- Primitive functions lookup table
--
primitives :: [(String, [LispVal] -> LispVal)]
primitives = [("+", numericBinop (+)),
("-", numericBinop (-)),
("*", numericBinop (*)),
("/", numericBinop div),
("mod", numericBinop mod),
("quotient", numericBinop quot),
("remainder", numericBinop rem),
("not", unaryOp not'),
("boolean?", unaryOp boolP),
("list?", unaryOp listP),
("symbol?", unaryOp symbolP),
("char?", unaryOp charP),
("string?", unaryOp stringP),
("string2symbol", unaryOp string2symbol),
("symbol2string?", unaryOp symbol2string)
]
-- Unary primitive defs all have type
-- LispVal -> LispVal
unaryOp :: (LispVal -> LispVal) -> [LispVal] -> LispVal
unaryOp f [arg] = f arg
not' (Bool x) = (Bool . not) x
not' _ = Bool False
boolP (Bool _) = Bool True
boolP _ = Bool False
listP (List _) = Bool True
listP (DottedList _ _) = Bool True
listP _ = Bool False
symbolP (Atom _) = Bool True
symbolP _ = Bool False
charP (Char _) = Bool True
charP _ = Bool False
stringP (String _) = Bool True
stringP _ = Bool False
symbol2string (Atom s) = String s
symbol2string _ = error "Expecting an atom"
string2symbol (String s) = Atom s
string2symbol _ = error "Expecting a string"
--
-- Helpers
--
escapedChars :: Parser Char
escapedChars = do
char '\\'
c <- oneOf ['\\','"', 'n', 'r', 't']
return $ case c of
'\\' -> c
'"' -> c
'n' -> '\n'
'r' -> '\r'
't' -> '\t'
symbol :: Parser Char
symbol = oneOf "!$%&|*+-/:<=>?@^_~"
spaces :: Parser ()
spaces = skipMany1 space
bin2int :: String -> Integer
bin2int s = sum $ map (\(i,x) -> i*(2^x)) $ zip [0..] $ map p (reverse s)
where p '0' = 0
p '1' = 1
readWith :: (t -> [(a, b)]) -> t -> a
readWith f s = fst $ f s !! 0
unwordsList :: [LispVal] -> String
unwordsList = unwords . map showVal
apply :: String -> [LispVal] -> LispVal
apply func args = maybe (Bool False) ($ args) $ lookup func primitives
numericBinop :: (Integer -> Integer -> Integer) -> [LispVal] -> LispVal
numericBinop op params = Number $ foldl1 op $ map unpackNum params
unpackNum :: LispVal -> Integer
unpackNum (Number n) = n
unpackNum (List [n]) = unpackNum n
unpackNum _ = 0
|
module Golden.Insertion where
open import Agda.Builtin.Nat
open import Agda.Builtin.List
open import Agda.Builtin.Bool
insert : Nat -> List Nat -> List Nat
insert a [] = a ∷ []
insert x (a ∷ b) with x < a
... | true = x ∷ a ∷ b
... | false = a ∷ (insert x b)
lst : List Nat
lst = 2 ∷ []
slst : List Nat
slst = insert 3 lst
atDef : ∀ {a : Set} → a → List a -> Nat -> a
atDef def (x ∷ l) zero = x
atDef def (x ∷ l) (suc ix) = atDef def l ix
atDef def _ _ = def
l0 : Nat
l0 = atDef 0 slst 0
l1 : Nat
l1 = atDef 0 slst 1
|
/*
* _DataDriverFactory.cpp
*
* Created on: 2017年10月7日
* Author: fasiondog
*/
#include <boost/python.hpp>
#include <hikyuu/data_driver/KDataDriver.h>
using namespace hku;
using namespace boost::python;
class KDataDriverWrap : public KDataDriver, public wrapper<KDataDriver> {
public:
KDataDriverWrap() : KDataDriver() {}
KDataDriverWrap(const string& name) : KDataDriver(name) {}
virtual ~KDataDriverWrap() {}
bool _init() {
if (override call = get_override("_init")) {
return call();
} else {
return KDataDriver::_init();
}
}
bool default_init() {
return this->KDataDriver::_init();
}
bool isIndexFirst() {
return this->get_override("isIndexFirst")();
}
size_t getCount(const string& market, const string& code, KQuery::KType ktype) {
if (override call = get_override("getCount")) {
return call(market, code, ktype);
} else {
return KDataDriver::getCount(market, code, ktype);
}
}
size_t default_getCount(const string& market, const string& code, KQuery::KType ktype) {
return this->KDataDriver::getCount(market, code, ktype);
}
virtual object _getIndexRangeByDate(const string& market, const string& code,
const KQuery& query) {
if (override call = get_override("_getIndexRangeByDate")) {
return call(market, code, query);
}
return make_tuple(0, 0);
}
object default_getIndexRangeByDate(const string& market, const string& code,
const KQuery& query) {
return make_tuple(0, 0);
}
bool getIndexRangeByDate(const string& market, const string& code, const KQuery& query,
size_t& out_start, size_t& out_end) {
out_start = 0;
out_end = 0;
object x = _getIndexRangeByDate(market, code, query);
if (x.is_none() || len(x) < 2) {
return false;
}
extract<size_t> start(x[0]);
if (start.check()) {
out_start = start();
} else {
return false;
}
extract<size_t> end(x[1]);
if (end.check()) {
out_end = end();
} else {
out_start = 0;
return false;
}
return true;
}
/* Python 无法 使用指针或引用作为输出参数
bool getIndexRangeByDate(const string& market, const string& code,
const KQuery& query, size_t& out_start, size_t& out_end) {
if (override call = get_override("getIndexRangeByDate")) {
return call(market, code, query, out_start, out_end);
} else {
return KDataDriver::getIndexRangeByDate(market, code,
query, out_start, out_end);
}
}*/
/*bool default_getIndexRangeByDate(const string& market, const string& code,
const KQuery& query, size_t& out_start, size_t& out_end) {
return this->KDataDriver::getIndexRangeByDate(market, code,
query, out_start, out_end);
}*/
KRecordList getKRecordList(const string& market, const string& code, const KQuery& query) {
if (override call = get_override("getKRecordList")) {
return call(market, code, query);
} else {
return KDataDriver::getKRecordList(market, code, query);
}
}
KRecordList default_getKRecordList(const string& market, const string& code,
const KQuery& query) {
return this->KDataDriver::getKRecordList(market, code, query);
}
TimeLineList getTimeLineList(const string& market, const string& code, const KQuery& query) {
if (override call = get_override("getTimeLineList")) {
return call(market, code, query);
} else {
return KDataDriver::getTimeLineList(market, code, query);
}
}
TimeLineList default_getTimeLineList(const string& market, const string& code,
const KQuery& query) {
return this->KDataDriver::getTimeLineList(market, code, query);
}
TransList getTransList(const string& market, const string& code, const KQuery& query) {
if (override call = get_override("getTransList")) {
return call(market, code, query);
} else {
return KDataDriver::getTransList(market, code, query);
}
}
TransList default_getTransList(const string& market, const string& code, const KQuery& query) {
return this->KDataDriver::getTransList(market, code, query);
}
};
void export_KDataDriver() {
class_<KDataDriverWrap, boost::noncopyable>("KDataDriver", init<>())
.def(init<const string&>())
.def(self_ns::str(self))
.add_property("name",
make_function(&KDataDriver::name, return_value_policy<copy_const_reference>()))
.def("getParam", &KDataDriver::getParam<boost::any>)
.def("_init", &KDataDriver::_init, &KDataDriverWrap::default_init)
.def("isIndexFirst", pure_virtual(&KDataDriver::isIndexFirst))
.def("getCount", &KDataDriver::getCount, &KDataDriverWrap::default_getCount)
//.def("getIndexRangeByDate", &KDataDriver::getIndexRangeByDate,
// &KDataDriverWrap::default_getIndexRangeByDate)
.def("_getIndexRangeByDate", &KDataDriverWrap::_getIndexRangeByDate,
&KDataDriverWrap::default_getIndexRangeByDate)
.def("getKRecordList", &KDataDriver::getKRecordList, &KDataDriverWrap::default_getKRecordList)
.def("getTimeLine", &KDataDriver::getTimeLineList, &KDataDriverWrap::default_getTimeLineList)
.def("getTransList", &KDataDriver::getTransList, &KDataDriverWrap::default_getTransList);
register_ptr_to_python<KDataDriverPtr>();
}
|
(* Was raising stack overflow in 8.4 and assertion failed in future 8.5 *)
Set Implicit Arguments.
Require Import List.
Require Import Coq.Program.Equality.
(** Reflexive-transitive closure ( R* ) *)
Inductive rtclosure (A : Type) (R : A-> A->Prop) : A->A->Prop :=
| rtclosure_refl : forall x,
rtclosure R x x
| rtclosure_step : forall y x z,
R x y -> rtclosure R y z -> rtclosure R x z.
(* bug goes away if rtclosure_step is commented out *)
(** The closure of the trivial binary relation [eq] *)
Definition tr (A:Type) := rtclosure (@eq A).
(** The bug *)
Lemma bug : forall A B (l t:list A) (r s:list B),
length l = length r ->
tr (combine l r) (combine t s) -> tr l t.
Proof.
intros * E Hp.
(* bug goes away if [revert E] is called explicitly *)
dependent induction Hp.
|
Formal statement is: lemma complex_eq_0: "z=0 \<longleftrightarrow> (Re z)\<^sup>2 + (Im z)\<^sup>2 = 0" Informal statement is: A complex number $z$ is equal to $0$ if and only if its real part squared plus its imaginary part squared is equal to $0$. |
theory flash31Rev imports flashPub
begin
section{*Main defintions*}
lemma NI_FAckVsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_FAck ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
lemma NI_InvVsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Inv iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
proof -
have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) "
by( cut_tac a1 a2 , auto)
moreover
{assume b1:"(iRule1=iInv1)"
have "?P1 s"
apply(cut_tac a1 a2 b1 , auto)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
moreover
{assume b1:"((iRule1~=iInv1 ))"
have "?P2 s"
apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s"
by metis
qed
lemma NI_InvAck_1VsInv31:
(*Rule2VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iRule2 \<le> N" and a3:"iInv1 \<le> N" and a4:"iRule1~=iRule2 "
shows "invHoldForRule' s (inv31 iInv1 ) (NI_InvAck_1 iRule1 iRule2 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
proof -
have "?P2 s"
by(cut_tac a1 a2 a3 a4, auto)
then show "?P1 s\<or>?P2 s\<or>?P3 s"
by auto
qed
lemma NI_InvAck_1_HomeVsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_InvAck_1_Home iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_InvAck_2VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_InvAck_2 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_GetX_GetXVsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_GetX_GetX iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_GetX_Nak1VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_GetX_Nak1 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_GetX_Nak2VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_GetX_Nak2 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_GetX_Nak3VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_GetX_Nak3 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_GetX_PutX1VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_GetX_PutX1 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_GetX_PutX2VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_GetX_PutX2 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_GetX_PutX3VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_GetX_PutX3 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_GetX_PutX4VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_GetX_PutX4 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_GetX_PutX5VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_GetX_PutX5 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_GetX_PutX6VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_GetX_PutX6 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_GetX_PutX7VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_GetX_PutX7 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_GetX_PutX8VsInv31:
(*Rule2VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iRule2 \<le> N" and a3:"iInv1 \<le> N" and a4:"iRule1~=iRule2 "
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_GetX_PutX8 N iRule1 iRule2 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
proof -
have "?P2 s"
by(cut_tac a1 a2 a3 a4, auto)
then show "?P1 s\<or>?P2 s\<or>?P3 s"
by auto
qed
lemma NI_Local_GetX_PutX8_homeVsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_GetX_PutX8_home N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_GetX_PutX9VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_GetX_PutX9 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_GetX_PutX10VsInv31:
(*Rule2VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iRule2 \<le> N" and a3:"iInv1 \<le> N" and a4:"iRule1~=iRule2 "
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_GetX_PutX10 N iRule1 iRule2 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
proof -
have "?P2 s"
by(cut_tac a1 a2 a3 a4, auto)
then show "?P1 s\<or>?P2 s\<or>?P3 s"
by auto
qed
lemma NI_Local_GetX_PutX10_homeVsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_GetX_PutX10_home N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_GetX_PutX11VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_GetX_PutX11 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_Get_GetVsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_Get_Get iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_Get_Nak1VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_Get_Nak1 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_Get_Nak2VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_Get_Nak2 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_Get_Nak3VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_Get_Nak3 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_Get_Put1VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_Get_Put1 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_Get_Put2VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_Get_Put2 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_Get_Put3VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_Get_Put3 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Local_PutVsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_Put ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
lemma NI_Local_PutXAcksDoneVsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Local_PutXAcksDone ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
lemma NI_NakVsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Nak iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Nak_ClearVsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Nak_Clear ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
lemma NI_Nak_HomeVsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Nak_Home ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
lemma NI_Remote_GetX_NakVsInv31:
(*Rule2VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iRule2 \<le> N" and a3:"iInv1 \<le> N" and a4:"iRule1~=iRule2 "
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Remote_GetX_Nak iRule1 iRule2 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
proof -
have "?P2 s"
by(cut_tac a1 a2 a3 a4, auto)
then show "?P1 s\<or>?P2 s\<or>?P3 s"
by auto
qed
lemma NI_Remote_GetX_Nak_HomeVsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Remote_GetX_Nak_Home iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Remote_GetX_PutXVsInv31:
(*Rule2VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iRule2 \<le> N" and a3:"iInv1 \<le> N" and a4:"iRule1~=iRule2 "
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Remote_GetX_PutX iRule1 iRule2 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
proof -
have allCases:"(iRule1=iInv1\<and>(iRule2~=iInv1 )) \<or>((iRule1~=iInv1 )\<and>iRule2=iInv1) \<or>((iRule1~=iInv1 )\<and>(iRule2~=iInv1 )) "
by( cut_tac a1 a2 a3 a4 , auto)
moreover
{assume b1:"(iRule1=iInv1\<and>(iRule2~=iInv1 ))"
have "?P2 s"
apply(cut_tac a1 a2 a3 a4 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
moreover
{assume b1:"((iRule1~=iInv1 )\<and>iRule2=iInv1)"
have "?P1 s"
apply(cut_tac a1 a2 a3 a4 b1 , auto)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
moreover
{assume b1:"((iRule1~=iInv1 )\<and>(iRule2~=iInv1 ))"
have "?P2 s"
apply(cut_tac a1 a2 a3 a4 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s"
by metis
qed
lemma NI_Remote_GetX_PutX_HomeVsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Remote_GetX_PutX_Home iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
proof -
have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) "
by( cut_tac a1 a2 , auto)
moreover
{assume b1:"(iRule1=iInv1)"
have "?P1 s"
apply(cut_tac a1 a2 b1 , auto)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
moreover
{assume b1:"((iRule1~=iInv1 ))"
have "?P2 s"
apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s"
by metis
qed
lemma NI_Remote_Get_Nak1VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Remote_Get_Nak1 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_Remote_Get_Nak2VsInv31:
(*Rule2VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iRule2 \<le> N" and a3:"iInv1 \<le> N" and a4:"iRule1~=iRule2 "
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Remote_Get_Nak2 iRule1 iRule2 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
proof -
have "?P2 s"
by(cut_tac a1 a2 a3 a4, auto)
then show "?P1 s\<or>?P2 s\<or>?P3 s"
by auto
qed
lemma NI_Remote_Get_Put1VsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Remote_Get_Put1 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
proof -
have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) "
by( cut_tac a1 a2 , auto)
moreover
{assume b1:"(iRule1=iInv1)"
have "?P1 s"
apply(cut_tac a1 a2 b1 , auto)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
moreover
{assume b1:"((iRule1~=iInv1 ))"
have "?P2 s"
apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s"
by metis
qed
lemma NI_Remote_Get_Put2VsInv31:
(*Rule2VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iRule2 \<le> N" and a3:"iInv1 \<le> N" and a4:"iRule1~=iRule2 "
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Remote_Get_Put2 iRule1 iRule2 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
proof -
have allCases:"(iRule1=iInv1\<and>(iRule2~=iInv1 )) \<or>((iRule1~=iInv1 )\<and>iRule2=iInv1) \<or>((iRule1~=iInv1 )\<and>(iRule2~=iInv1 )) "
by( cut_tac a1 a2 a3 a4 , auto)
moreover
{assume b1:"(iRule1=iInv1\<and>(iRule2~=iInv1 ))"
have "?P2 s"
apply(cut_tac a1 a2 a3 a4 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
moreover
{assume b1:"((iRule1~=iInv1 )\<and>iRule2=iInv1)"
have "?P1 s"
apply(cut_tac a1 a2 a3 a4 b1 , auto)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
moreover
{assume b1:"((iRule1~=iInv1 )\<and>(iRule2~=iInv1 ))"
have "?P2 s"
apply(cut_tac a1 a2 a3 a4 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s"
by metis
qed
lemma NI_Remote_PutVsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Remote_Put iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
proof -
have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) "
by( cut_tac a1 a2 , auto)
moreover
{assume b1:"(iRule1=iInv1)"
have allCases:"formEval ( eqn ( IVar ( Para ''InvMarked'' iInv1) ) ( Const true )) s \<or>formEval (neg ( eqn ( IVar ( Para ''InvMarked'' iInv1) ) ( Const true )) ) s "
by auto
moreover
{assume c1:"formEval ( eqn ( IVar ( Para ''InvMarked'' iInv1) ) ( Const true )) s"
have "?P1 s"
apply(cut_tac a1 a2 b1 c1 , auto)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
moreover
{assume c1:"formEval (neg ( eqn ( IVar ( Para ''InvMarked'' iInv1) ) ( Const true )) ) s"
have "?P1 s"
apply(cut_tac a1 a2 b1 c1 , auto)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
ultimately have "?P1 s\<or> ?P2 s\<or> ?P3 s"
by metis
}
moreover
{assume b1:"((iRule1~=iInv1 ))"
have "?P2 s"
apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s"
by metis
qed
lemma NI_Remote_PutXVsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Remote_PutX iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
proof -
have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) "
by( cut_tac a1 a2 , auto)
moreover
{assume b1:"(iRule1=iInv1)"
have "?P3 s"
apply( cut_tac a1 a2 b1 , simp)
apply(rule_tac x=" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) ) ( Const UNI_PutX )) ( eqn ( IVar ( Global ''WbMsg_Cmd'') ) ( Const WB_Wb )) ) ) " in exI,auto)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
moreover
{assume b1:"((iRule1~=iInv1 ))"
have "?P2 s"
apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s"
by metis
qed
lemma NI_ReplaceVsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Replace iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_ReplaceHomeVsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_ReplaceHome ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
lemma NI_ReplaceHomeShrVldVsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_ReplaceHomeShrVld ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
lemma NI_ReplaceShrVldVsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_ReplaceShrVld iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma NI_ShWbVsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_ShWb N ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
lemma NI_WbVsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (NI_Wb ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
proof -
have "?P1 s"
apply(cut_tac a1 , auto)
done
then show "?P1 s\<or> ?P2 s\<or> ?P3 s"
by blast
qed
lemma PI_Local_GetX_GetX1VsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (PI_Local_GetX_GetX1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
lemma PI_Local_GetX_GetX2VsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (PI_Local_GetX_GetX2 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
lemma PI_Local_GetX_PutX1VsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (PI_Local_GetX_PutX1 N ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
lemma PI_Local_GetX_PutX2VsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (PI_Local_GetX_PutX2 N ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
lemma PI_Local_GetX_PutX3VsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (PI_Local_GetX_PutX3 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
lemma PI_Local_GetX_PutX4VsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (PI_Local_GetX_PutX4 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
lemma PI_Local_Get_GetVsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (PI_Local_Get_Get ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
lemma PI_Local_Get_PutVsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (PI_Local_Get_Put ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
lemma PI_Local_PutXVsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (PI_Local_PutX ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
lemma PI_Local_ReplaceVsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (PI_Local_Replace ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
lemma PI_Remote_GetVsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (PI_Remote_Get iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma PI_Remote_GetXVsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (PI_Remote_GetX iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma PI_Remote_PutXVsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (PI_Remote_PutX iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
proof -
have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) "
by( cut_tac a1 a2 , auto)
moreover
{assume b1:"(iRule1=iInv1)"
have "?P1 s"
apply(cut_tac a1 a2 b1 , auto)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
moreover
{assume b1:"((iRule1~=iInv1 ))"
have "?P3 s"
apply( cut_tac a1 a2 b1 , simp)
apply(rule_tac x=" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iRule1) ) ( Const CACHE_E )) ( eqn ( IVar ( Para ''CacheState'' iInv1) ) ( Const CACHE_E )) ) ) " in exI,auto)
done
then have "?P1 s\<or> ?P2 s \<or> ?P3 s"
by blast
}
ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s"
by metis
qed
lemma PI_Remote_ReplaceVsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (PI_Remote_Replace iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma StoreVsInv31:
(*Rule1VsPInv1*)
assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (Store iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 a2 , auto)
lemma StoreHomeVsInv31:
(*Rule0VsPInv1*)
assumes a1:"iInv1 \<le> N"
shows "invHoldForRule' s (inv31 iInv1 ) (StoreHome ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s")
by (cut_tac a1 , auto)
end
|
Best Of Gifts for A Nurse Graduate Photographs - graduate plu the graduate programs at pacific lutheran university are designed to combine practice and theory to prepare graduates to take the next step in their careers . dnp plu the plu doctor of nursing practice degree prepares graduates in one of two advanced practice specialty areas family nurse practitioner fnp psychiatric . amazon com gifts for nurse graduates product features a great gift for any occasion graduation birthday christmas nurses week , gifts for a nurse graduate. forms adult and graduate financial aid indiana residential undergraduate god has gifted you with a unique set of gifts on purpose and for the purpose of changing the world in a way that only you can , gifts for a nurse graduate. the school of nursing university of indianapolis school the uindy school of nursing is known for its leading edge programs at all degree levels that consistently rank among the top in the state with high . , Best Of Gifts for A Nurse Graduate Photographs. |
State Before: F : Type ?u.416774
α : Type u_1
β : Type u_2
γ : Type ?u.416783
ι : Type ?u.416786
κ : Type ?u.416789
inst✝ : DecidableEq α
s : Finset β
f : β → α
⊢ (sup s fun b => {f b}) = image f s State After: case a
F : Type ?u.416774
α : Type u_1
β : Type u_2
γ : Type ?u.416783
ι : Type ?u.416786
κ : Type ?u.416789
inst✝ : DecidableEq α
s : Finset β
f : β → α
a : α
⊢ (a ∈ sup s fun b => {f b}) ↔ a ∈ image f s Tactic: ext a State Before: case a
F : Type ?u.416774
α : Type u_1
β : Type u_2
γ : Type ?u.416783
ι : Type ?u.416786
κ : Type ?u.416789
inst✝ : DecidableEq α
s : Finset β
f : β → α
a : α
⊢ (a ∈ sup s fun b => {f b}) ↔ a ∈ image f s State After: case a
F : Type ?u.416774
α : Type u_1
β : Type u_2
γ : Type ?u.416783
ι : Type ?u.416786
κ : Type ?u.416789
inst✝ : DecidableEq α
s : Finset β
f : β → α
a : α
⊢ (∃ v, v ∈ s ∧ a ∈ {f v}) ↔ ∃ a_1, a_1 ∈ s ∧ f a_1 = a Tactic: rw [mem_sup, mem_image] State Before: case a
F : Type ?u.416774
α : Type u_1
β : Type u_2
γ : Type ?u.416783
ι : Type ?u.416786
κ : Type ?u.416789
inst✝ : DecidableEq α
s : Finset β
f : β → α
a : α
⊢ (∃ v, v ∈ s ∧ a ∈ {f v}) ↔ ∃ a_1, a_1 ∈ s ∧ f a_1 = a State After: no goals Tactic: simp only [mem_singleton, eq_comm] |
{-
Holey congruence for propositional equality.
-}
module Holes.Cong.Propositional where
open import Holes.Prelude
open PropEq using (_≡_; refl; cong; sym; trans)
import Holes.Cong.General as Cong
open Cong (quote cong) (quote sym) public
using (cong!)
|
If $m \neq 0$, then $m x + c = y$ if and only if $x = \frac{1}{m} y - \frac{1}{m} c$. |
lemma ball_subset_ball_iff: fixes a :: "'a :: euclidean_space" shows "ball a r \<subseteq> ball a' r' \<longleftrightarrow> dist a a' + r \<le> r' \<or> r \<le> 0" (is "?lhs = ?rhs") |
'Set up'
##--------------##
from __future__ import division
from math import sin , atan, cos, pi
from numpy import arange
from numpy.testing import assert_almost_equal as aae
import matplotlib.pyplot as plt
#%matplotlib inline
##--------------##
debug = 'false'; #If true, returns linear velocity + accerelation, and angular velcocity + accerelation
'Vehicle Parameters'
##--------------##
mass = 272 #kg
area = 1.50 #m^2 surface area (cross-sectional)
rrad = 0.25 #meters rear wheel radius
frad = 0.25 #meters front wheel radius
effT = 0.80 #powertrain efficiency
pmax = 60.0 #kW cont. power (EmDrive 500)
gear = 4.5 #final drive gear ratio
wdis = 0.65 #Weight distrubtion, % of weight on rear wheels
base = 1.2 #Axle-to-Axle distance in meters
high = 0.25 #Center of Gravity's height in meters
mxRM = 6000#5500 #max motor Rev/min
mxPT = 140.01 #240.02
mxCT = 60.087 #96
#fric = 0.19 #friction coefficient
drag = 0.50 #coefficient of drag
'Constants'
##--------------##
grav = 9.81 #m/s^2
dens = 1.23 #kg/m^3
'Initial Values'
##--------------##
hertz = 25
# angl = 0.00 #initial hill angle in radians
accl = 0.00 #initial accerelaion in m/s^2
mRPM = 0.00 #initial Motor RPM value
wRPM = 0.00 #initial Wheel RPM value
velo = 0.00 #initial velocity in m/s
xpos = 0.00 #initial X-position (total distance)
lpos = 0.00 #initial X-position relative to the current lap
time = 0.00 #initial time in seconds (Start time)
wAcc = 0.00 #initial angular accerelation
thrt = 75
##--------------##
'Motor Torque from Throttle Map'
#Equations were made by inputting points of the torque curves into Excel
##--------------##
'''Emrax 208 Equations'''
def Ctor(rpm):
return (3e-13*rpm**3)-(1e-6*rpm**2)+(0.0059*rpm)+(60.087)
def Ptor(rpm):
return (-1e-14*rpm**4)-(7e-11*rpm**3)+(2e-7*rpm**2)-(0.0002*rpm)+(140.01)
'''Emrax 228 Equations
def Ctor(rpm):
return (-6e-13*rpm**4)+(9e-9*rpm**3)-(5e-5*rpm**2)+(0.1082*rpm)+(96)
def Ptor(rpm):
return (3e-13*rpm**4)-(3e-9*rpm**3)+(6e-6*rpm**2)-(0.0039*rpm)+(240.02)
'''
def motorTorque(rpm, thrt): #Normally all the Torque functions are kept below, but are also above for plotting purposes
def Ctor(rpm):
return (3e-13*rpm**3)-(1e-6*rpm**2)+(0.0059*rpm)+(60.087)
def Ptor(rpm):
return (-1e-14*rpm**4)-(7e-11*rpm**3)+(2e-7*rpm**2)-(0.0002*rpm)+(140.01)
def interpolate(x1,x2,y1,y2,xvalue):
#Linear interpolation between two points x1 and x2 with y values y1 and y2. Finds yvalue corresponding to xvalue
slope = (y2-y1)/(x2-x1)
yvalue = y1 + slope*(xvalue-x1)
return yvalue
if thrt >= 100:
motorTorque = Ptor(rpm)
elif thrt == 50:
motorTorque = Ctor(rpm)
elif thrt <= 0:
motorTorque = 0
elif (thrt > 50) and (thrt < 100):
torque1 = Ctor(rpm)
torque2 = Ptor(rpm)
throttle1 = 50
throttle2 = 100
motorTorque = interpolate(throttle1,throttle2,torque1,torque2,thrt)
elif (thrt > 0) and (thrt < 50):
torque2 = Ctor(rpm)
throttle2 = 50
motorTorque = interpolate(0,throttle2,0,torque2,thrt)
return motorTorque
##--------------##
'Drive Train Torque'
##--------------##
def driveTorque(gear,mRPM,mxRM,thrt):
if mRPM > mxRM:
mRPM = mxRM
return (gear * motorTorque(mRPM, thrt))
##--------------##
'Augular Acceleration in Drive Train'
##--------------##
def AngularAcceleration(DriveTrainTorque):
return DriveTrainTorque / 1 #assumes the Moment of Interia is 1 -- T = I*AngAccereleration
##--------------##
def AngularVelocity(AngAccel,AngVelo,hertz):
return AngVelo + AngAccel*(1/hertz)
'Motor RPM from Forward Velocity'
##--------------##
def motorRPM(gear,rrad,velo):
return ((velo*60)/(2*pi*rrad))*gear
##--------------##
'Slope Calculator'
##--------------##
def slope(base,frad,rrad,xpos):
elevDataFile='elevationdata.txt' #filename (and path if located in a different folder) for elevation data profile
def interpolate(x1,x2,y1,y2,xvalue):
"Linear interpolation between two points x1 and x2 with y values y1 and y2. Finds yvalue corresponding to xvalue"
slope = (y2-y1)/(x2-x1)
yvalue = y1 + slope*(xvalue-x1)
return yvalue
def elevation(xpos):
"Finds the elevation (y coordinate) for each x coordinate. Throws an exception if x-coordinate is out of range for the input file."
import bisect
xylist = []
with open(elevDataFile) as elev:
for line in elev.readlines():
xylist.append([float(line.split(' ')[0]),float(line.split(' ')[1].rstrip())])
xvalues=zip(*xylist)[0]
yvalues=zip(*xylist)[1]
#check that the xPosition value falls within the dataset provided, else return elevation of 0
if xpos >= min(xvalues) and xpos <= max(xvalues):
if xpos in xvalues:
#if xPosition is literally in the list, then just lookup the y value associated with it
elevation=float(yvalues[xvalues.index(xpos)])
##print 'found it in the list'
else:
#use a simple linear interpolation to calculate the elevation between two points.
x1=xvalues[bisect.bisect(xvalues,xpos)-1]
x2=xvalues[bisect.bisect(xvalues,xpos)]
y1=yvalues[bisect.bisect(xvalues,xpos)-1]
y2=yvalues[bisect.bisect(xvalues,xpos)]
elevation = float(interpolate(x1,x2,y1,y2,xpos))
##print 'had to interpolate'
else:
elevation = float(0)
print 'outta bounds'
return(elevation)
def update_angle(xpos,base,fTireDiam,rTireDiam):
##from math import pi, cos
##from numpy.testing import assert_almost_equal as aae
'Update vehicle angle based on current x-position. Returns angle between wheelbase and y=0 line.'
r_elevation = elevation(xpos)
interval1 = (0.002*pi) #Results in 500 loops, 0.01 is 100 loops, 0.001 is 1000 loops
for i in arange(-pi/2, pi/2, interval1):
r_axle = r_elevation + (rrad)
f_axleY = r_axle + base*sin(i)
front_X = xpos + base*cos(i)
Ycon_Pt = f_axleY - (frad)
f_elevation = elevation(front_X)
try:
aae(f_elevation, Ycon_Pt, decimal=2)
except AssertionError:
continue
else:
return i
return update_angle(base,frad,rrad,xpos)
##--------------##
'Normal Forces'
##--------------##
def Norm_f(accl,base,grade,grav,high,mass,wdis):
return mass*grav*((1-wdis)*cos(grade))+(high/base)*sin(grade)-mass*accl*(high/base)
def Norm_r(accl,base,grade,grav,high,mass,wdis):
return mass*grav*((wdis)*cos(grade))-(high/base)*sin(grade)+mass*accl*(high/base)
##--------------##
'Resistance Forces'
##--------------##
def aero(dens,area,velo,drag):
# currently assumes that the wind's velocity = 0, therefore relative velocity = car velocity
return (dens*area*drag*velo**2)/2
def hill(grade,mass,grav):
return mass*grav*sin(grade)
def rres(Fn,velo):
rolling_coeff = (1e-6*velo**3)-(2e-5*velo**2)+(0.0004*velo)+0.005
return Fn*rolling_coeff
##--------------##
'Magic Formula Class'
##--------------##
class Tires:
def __init__(self, rotational_inertia, effective_radius, condition='dry'):
self.J = rotational_inertia
self.r = effective_radius
self.condition = condition
def calculate_slip_ratio(self, vehicle_velocity, hub_angular_velocity, velocity_threshold = 0.1):
'Calcualate the Slip Ratio of the tire. Incorporates a minimum velocity_threshold to avoid singular evolution at zero.'
wheel_slip_velocity = self.r * hub_angular_velocity - vehicle_velocity
if abs(vehicle_velocity) < velocity_threshold:
wheel_slip_ratio = 2 * wheel_slip_velocity / ( velocity_threshold + (vehicle_velocity**2)/velocity_threshold )
else:
wheel_slip_ratio = wheel_slip_velocity / vehicle_velocity
return wheel_slip_ratio
def magic_formula(self, slip_ratio):
'Calculate frictional coefficient mu given condition. Options are dry, wet, snow, or ice.'
if slip_ratio >= 1.0:
slip_ratio = 1.0
if slip_ratio <= -1.0:
slip_ratio = -1.0
if self.condition.lower() == 'wet':
B = 12.0
#C = 2.0
D = 0.82
E = 1.00
##----------##
# From "Simulation of Vehicle Longitudinal Dynamics"
C = 2.3
elif self.condition.lower() == 'snow':
B = 5.00
C = 2.00
D = 0.30
E = 1.00
elif self.condition.lower() == 'ice':
B = 4.00
C = 2.00
D = 0.10
E = 1.00
elif self.condition.lower() == 'wiki':
B = 0.714
C = 1.40
D = 1.00
E = -0.20
else: #dry conditions are assumed if user input is anything other than 'wet' 'snow' or 'ice'
#B = 10.0
#C = 1.5
D = 1.0
#E = 1.0
##----------##
# From "Simulation of Vehicle Longitudinal Dynamics"
B = 10
C = 1.9
E = 0.97
# Calculation (see pacejka '94)
## adhesion_coefficient = D * sin(C* atan(B*(1-E)*slip_ratio+E) * slip_ratio + E * atan(B*slip_ratio))
adhesion_coefficient = D*sin(C*atan(B*slip_ratio-E*(B*slip_ratio-atan(B*slip_ratio))))
## Above equation taken from "Simulation of Vehicle Longitudinal Dynamics" paper.
return adhesion_coefficient
##--------------##
'Slip Ratio'
##--------------##
def slipRatio(mxRM,velo,rrad,wAcc,gear,mxPT):
return ((wAcc*rrad)-velo)/max((mxPT*gear*rrad),(((mxRM/gear)*2*pi*rrad)/60))
##--------------##
'Acceleration Run -- While Loop'
##--------------##
# Resetting Parameters
accl = 0.00 #initial acceleration in m/s^2
mRPM = 0.00 #initial Motor RPM value
wRPM = 0.00 #initial Wheel RPM value
velo = 0.00 #initial velocity in m/s
xpos = 0.00 #initial X-position (total distance)
lpos = 0.00 #initial X-position relative to the current lap
time = 0.00 #initial time in seconds (Start time)
wAcc = 0.00 #initial angular accerelation
wVel = 0.00 #initial angular velocity
n = 0
# Setting up the graphing
tim = []
xvel = []
xpot = []
xacc = []
rpms = []
slip = []
fx = []
fx1 = []
fx2 = []
# Specific values for the acceleration run
thrt = 100
grade = 0
drytire = Tires(rotational_inertia=1.5, effective_radius=rrad)
while (xpos < (75)): # Will run until 75 m is reached
n += 1
t1 = time
t2 = time + (1/hertz)
# Initial position set up
Fn_r = Norm_r(accl,base,grade,grav,high,mass,wdis)
Fn_f = Norm_f(accl,base,grade,grav,high,mass,wdis)
# Resistive forces
AR = aero(dens,area,velo,drag)
HR = hill(grade,mass,grav)
RR_f = rres(Fn_f,velo)
RR_r = rres(Fn_r,velo)
# Drive Forces
DT_t = driveTorque(gear,mRPM,mxRM,thrt)
#Tire Dynamics
wAcc = AngularAcceleration(DT_t)
wVel = AngularVelocity(wAcc,wVel,hertz)
slip_ratio = slipRatio(mxRM,velo,rrad,wAcc,gear,mxPT)
mu = drytire.magic_formula(slip_ratio)
Fx_1 = (DT_t/rrad)-AR-HR-RR_f-RR_r
Fx_2 = mu*Fn_r
Fx = min(Fx_1,Fx_2)
# Kinematics // Update xpos
accler = Fx / mass
velo += accler*(t2-t1)
xpos += velo*(t2-t1)+accler*(t2-t1)**2
# end of loop functions
mRPM = motorRPM(gear,rrad,velo)
time = t2
tim.append(t2)
xpot.append(xpos)
xvel.append(velo)
xacc.append(accler)
slip.append(slip_ratio)
fx.append(Fx)
fx1.append(Fx_1)
fx2.append(Fx_2)
if (debug == 'true'):
print "Velocity: %5.3f, Max Velocity: %5.3f" % (velo,(((mxRM*2*pi*rrad)/(gear*60))))
print "Ang Accerelation: %5.5f, Max Ang: %5.5f" % (wAcc,(mxPT*gear*rrad))
print "Ang Velocity: %5.5f, Max Ang: %5.5f \n" % (wVel,mxPT*gear*(1/hertz))
print 'Acceleration Run\nAt',thrt,'% throttle,',xpos,' m were completed in',t2,' seconds.'
# Plotting the acceleration run info
plt.figure(figsize=(13,16))
plt.subplot(521)
plt.plot(tim,xpot)
plt.xlabel('time (sec)')
plt.ylabel('x-position (meters)')
plt.subplot(522)
plt.plot(tim,xvel)
plt.xlabel('time (sec)')
plt.ylabel('velocity (meters/s)')
plt.subplot(523)
plt.plot(tim,xacc)
plt.xlabel('time (sec)')
plt.ylabel('acceleration (meters/sec^2)')
plt.subplot(524)
plt.plot(tim,[j / 9.81 for j in xacc])
plt.xlabel('time (sec)')
plt.ylabel('Longitudinal G\'s')
plt.subplot(525)
plt.plot(tim,slip)
plt.xlabel('time (sec)')
plt.ylabel('abs - Slip Ratio')
plt.subplot(526)
plt.plot(tim,fx)
plt.xlabel('time (sec)')
plt.ylabel('Fx')
plt.subplot(527)
plt.plot(tim,fx2)
plt.xlabel('time (sec)')
plt.ylabel('Fx2 = mu*Fn_r')
plt.subplot(528)
plt.plot(tim,fx1)
plt.xlabel('time (sec)')
plt.ylabel('Fx1 (Sum of forces)')
wettire = Tires(rotational_inertia=1.5, effective_radius=rrad, condition = 'wet')
snowtire = Tires(rotational_inertia=1.5, effective_radius=rrad, condition = 'snow')
icetire = Tires(rotational_inertia=1.5, effective_radius=rrad, condition = 'ice')
slip=[]
drymulist=[]
wetmulist=[]
snowmulist=[]
icemulist=[]
for i in arange(-1,1,0.01):
drymu = drytire.magic_formula(i)
wetmu = wettire.magic_formula(i)
snowmu = snowtire.magic_formula(i)
icemu = icetire.magic_formula(i)
slip.append(i)
drymulist.append(drymu)
wetmulist.append(wetmu)
snowmulist.append(snowmu)
icemulist.append(icemu)
plt.subplot(529)
plt.plot(slip,drymulist,label='Dry Condition')
plt.plot(slip,wetmulist,label='Wet Condition')
plt.plot(slip,snowmulist,label='Snow Condition')
plt.plot(slip,icemulist,label='Ice Condition')
plt.xlabel('Slip Ratio %')
plt.ylabel('Coefficient of Adhesion')
plt.legend(loc=4)
plt.title('Coef. of Adhesion vs Slip Ratio',size=15)
peak = []
cont = []
for i in range(0,6000):
peak.append(Ptor(i))
cont.append(Ctor(i))
plt.subplot(5,2,10)
plt.plot(peak,label='Peak')
plt.plot(cont,label='Cont')
plt.title('Torque Curves')
plt.xlabel('RPM')
plt.ylabel('Torque (Nm)')
plt.legend()
plt.tight_layout()
plt.draw();
|
Formal statement is: lemma coeff_monom_mult: "coeff (monom c n * p) k = (if k < n then 0 else c * coeff p (k - n))" Informal statement is: The coefficient of $x^k$ in the product of a monomial $cx^n$ and a polynomial $p$ is $0$ if $k < n$, and $c$ times the coefficient of $x^{k-n}$ in $p$ otherwise. |
module PythontexProfiler
export profile
using DataFrames
using PrettyTables
import Base: parse, push!
struct RuntimeData
files::Vector{String}
lines::Vector{Int32}
times::Vector{Float64}
bytes::Vector{Int64}
gctimes::Vector{Float64}
end
RuntimeData() = RuntimeData(String[], Int32[], Float64[], Int64[], Float64[])
function push!(D::RuntimeData, file, line, time, bytes, gctime)
push!(D.files, file)
push!(D.lines, line)
push!(D.times, time)
push!(D.bytes, bytes)
push!(D.gctimes, gctime)
end
function to_df(D::RuntimeData)
d = DataFrame(file=D.files, line=D.lines, time=D.times, bytes=D.bytes, gctime=D.gctimes)
sort!(d, [:time, :bytes, :gctime, :file], rev=true)
return d
end
to_pretty_table(D::RuntimeData) = pretty_table(to_df(D), nosubheader=true)
function profile(filename::String)
D = RuntimeData()
file = ""
line = 0
name3 = ""
o = nothing
open(filename) do file
for ln in eachline(file)
m = match(r"=>PYTHONTEX#\w+#(?<name1>\w+)#(?<name2>\w+)#(?<num>\d+)#(?<name3>\w+)####(?<file>[\w\-\.]*)#(?<line>\d+)#", ln)
if m != nothing
if o != nothing && (name3 == "c" || name3 == "code")
code = String(take!(o))
val, t, bytes, gctime, memallocs = @timed include_string(Main, code)
push!(D, file, line, t, bytes, gctime)
end
file = m[:file]
line = parse(Int32, m[:line])
name3 = m[:name3]
o = IOBuffer()
println("Running $file:$line")
else
if occursin(r"^=>PYTHONTEX:SETTINGS", ln)
if o != nothing && (name3 == "c" || name3 == "code")
code = String(take!(o))
val, t, bytes, gctime, memallocs = @timed include_string(Main, code)
push!(D, file, line, t, bytes, gctime)
end
break
else
println(o, ln)
end
end
end
end
return to_pretty_table(D)
end
end # module
|
Bosi uses molecular gastronomy techniques , such as in the process for making a Savoy cabbage purée , in which the cabbage is freeze dried into a powder and then reconstituted , but he prefers only to enhance the flavours of individual ingredients rather than changing those flavours by using unusual techniques .
|
[tracks]
1=Dopekick, Dopekick_soundslikeabreeze_139.ogg
2=bigMovieScore, BigMovieScore_104.ogg
[options]
loop=false
shuffle=false
|
[STATEMENT]
lemma CACH_INSTR:
"\<lbrakk> ins_is C m l I;
I \<in> { const c, dup, pop, swap, load x, store x, binop f,
unop g, getfield d F, putfield d F, checkcast d};
MST\<down>(C,m)=Some(Mspec,Minv,Anno); Anno\<down>(l) = None;
derivAssum G C m (l+1) (Cachera n) \<rbrakk>
\<Longrightarrow> deriv G C m l (Cachera n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<lbrakk>ins_is C m l I; I \<in> {const c, dup, pop, swap, load x, store x, binop f, unop g, getfield d F, putfield d F, checkcast d}; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; derivAssum G C m (l + 1) (Cachera n)\<rbrakk> \<Longrightarrow> deriv G C m l (Cachera n)
[PROOF STEP]
(*<*)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<lbrakk>ins_is C m l I; I \<in> {const c, dup, pop, swap, load x, store x, binop f, unop g, getfield d F, putfield d F, checkcast d}; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; derivAssum G C m (l + 1) (Cachera n)\<rbrakk> \<Longrightarrow> deriv G C m l (Cachera n)
[PROOF STEP]
apply (simp add: ins_is_def Cachera_def deriv_def derivAssum_def, clarsimp)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; G \<rhd> \<langle> (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n); mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> G \<rhd> \<lbrace> (\<lambda>s0 s. True) \<rbrace> C,m,l \<lbrace> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rbrace> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n)
[PROOF STEP]
apply (rule INSTR)
[PROOF STATE]
proof (prove)
goal (7 subgoals):
1. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; G \<rhd> \<langle> (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n); mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> mbody_is C m (?M4 a aa b)
2. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; G \<rhd> \<langle> (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n); mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> get_ins (?M4 a aa b) l = Some (?ins4 a aa b)
3. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; G \<rhd> \<langle> (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n); mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> MST\<down>(C, m) = Some (?Mspec4 a aa b, ?Minv4 a aa b, ?Anno4 a aa b)
4. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; G \<rhd> \<langle> (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n); mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> \<forall>Q. ?Anno4 a aa b\<down>l = Some Q \<longrightarrow> (\<forall>s0 s. True \<longrightarrow> Q s0 s)
5. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; G \<rhd> \<langle> (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n); mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> \<forall>s0 s. True \<longrightarrow> (case s of (ops, s, h) \<Rightarrow> \<lambda>k. |k| \<le> |h| + n) (heap s)
6. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; G \<rhd> \<langle> (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n); mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> ?ins4 a aa b \<in> {const (?c4 a aa b), dup, pop, swap, load (?x4 a aa b), store (?x4 a aa b), binop (?f4 a aa b), unop (?g4 a aa b), new (?d4 a aa b), getfield (?d4 a aa b) (?F4 a aa b), putfield (?d4 a aa b) (?F4 a aa b), checkcast (?d4 a aa b)}
7. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; G \<rhd> \<langle> (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n); mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> G \<rhd> \<langle> SP_pre (?M4 a aa b) l (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> SP_post (?M4 a aa b) l (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> SP_inv (?M4 a aa b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n)
[PROOF STEP]
apply assumption+
[PROOF STATE]
proof (prove)
goal (4 subgoals):
1. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; G \<rhd> \<langle> (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n); mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> \<forall>Q. Anno\<down>l = Some Q \<longrightarrow> (\<forall>s0 s. True \<longrightarrow> Q s0 s)
2. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; G \<rhd> \<langle> (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n); mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> \<forall>s0 s. True \<longrightarrow> (case s of (ops, s, h) \<Rightarrow> \<lambda>k. |k| \<le> |h| + n) (heap s)
3. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; G \<rhd> \<langle> (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n); mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> I \<in> {const (?c4 a aa b), dup, pop, swap, load (?x4 a aa b), store (?x4 a aa b), binop (?f4 a aa b), unop (?g4 a aa b), new (?d4 a aa b), getfield (?d4 a aa b) (?F4 a aa b), putfield (?d4 a aa b) (?F4 a aa b), checkcast (?d4 a aa b)}
4. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; G \<rhd> \<langle> (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n); mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> G \<rhd> \<langle> SP_pre (a, aa, b) l (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> SP_post (a, aa, b) l (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n)
[PROOF STEP]
apply simp
[PROOF STATE]
proof (prove)
goal (3 subgoals):
1. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; G \<rhd> \<langle> (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n); mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> \<forall>s0 s. True \<longrightarrow> (case s of (ops, s, h) \<Rightarrow> \<lambda>k. |k| \<le> |h| + n) (heap s)
2. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; G \<rhd> \<langle> (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n); mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> I \<in> {const (?c4 a aa b), dup, pop, swap, load (?x4 a aa b), store (?x4 a aa b), binop (?f4 a aa b), unop (?g4 a aa b), new (?d4 a aa b), getfield (?d4 a aa b) (?F4 a aa b), putfield (?d4 a aa b) (?F4 a aa b), checkcast (?d4 a aa b)}
3. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; G \<rhd> \<langle> (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n); mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> G \<rhd> \<langle> SP_pre (a, aa, b) l (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> SP_post (a, aa, b) l (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n)
[PROOF STEP]
apply (simp add: heap_def)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
1. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; G \<rhd> \<langle> (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n); mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> I \<in> {const (?c4 a aa b), dup, pop, swap, load (?x4 a aa b), store (?x4 a aa b), binop (?f4 a aa b), unop (?g4 a aa b), new (?d4 a aa b), getfield (?d4 a aa b) (?F4 a aa b), putfield (?d4 a aa b) (?F4 a aa b), checkcast (?d4 a aa b)}
2. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; G \<rhd> \<langle> (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n); mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> G \<rhd> \<langle> SP_pre (a, aa, b) l (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> SP_post (a, aa, b) l (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n)
[PROOF STEP]
apply fast
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; G \<rhd> \<langle> (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n); mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> G \<rhd> \<langle> SP_pre (a, aa, b) l (\<lambda>s0 s. True) \<rangle> C,m,(l + 1) \<langle> SP_post (a, aa, b) l (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) \<rangle> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n)
[PROOF STEP]
apply (erule CONSEQ)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
1. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> \<forall>s0 s. SP_pre (a, aa, b) l (\<lambda>s0 s. True) s0 s \<longrightarrow> True
2. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> \<forall>s0 s t. (case s of (ops, s, h) \<Rightarrow> \<lambda>(k, v). |k| \<le> |h| + n) t \<longrightarrow> SP_post (a, aa, b) l (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) s0 s t
3. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> \<forall>s0 s k. (case s of (ops, s, h) \<Rightarrow> \<lambda>k. |k| \<le> |h| + n) k \<longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) s0 s k
[PROOF STEP]
apply (simp add: SP_pre_def)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
1. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> \<forall>s0 s t. (case s of (ops, s, h) \<Rightarrow> \<lambda>(k, v). |k| \<le> |h| + n) t \<longrightarrow> SP_post (a, aa, b) l (\<lambda>s0 (ops, s, h) (k, v). |k| \<le> |h| + n) s0 s t
2. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> \<forall>s0 s k. (case s of (ops, s, h) \<Rightarrow> \<lambda>k. |k| \<le> |h| + n) k \<longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) s0 s k
[PROOF STEP]
apply (simp add: SP_post_def)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
1. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> \<forall>ab ac ba ad. |ad| \<le> |ba| + n \<longrightarrow> (\<forall>ae af bb. (\<exists>l1 n. ((a, aa, b), l, (ae, af, bb), n, l1, ab, ac, ba) \<in> Step) \<longrightarrow> |ad| \<le> |bb| + n)
2. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> \<forall>s0 s k. (case s of (ops, s, h) \<Rightarrow> \<lambda>k. |k| \<le> |h| + n) k \<longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) s0 s k
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (2 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I; |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b. \<lbrakk>I = const c \<or> I = dup \<or> I = pop \<or> I = swap \<or> I = load x \<or> I = store x \<or> I = binop f \<or> I = unop g \<or> I = getfield d F \<or> I = putfield d F \<or> I = checkcast d; MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some I\<rbrakk> \<Longrightarrow> \<forall>s0 s k. (case s of (ops, s, h) \<Rightarrow> \<lambda>k. |k| \<le> |h| + n) k \<longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) s0 s k
[PROOF STEP]
apply safe
[PROOF STATE]
proof (prove)
goal (22 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = const c\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = dup\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = pop\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
4. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = swap\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
5. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = load x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
6. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = store x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
7. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = binop f\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
8. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = unop g\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
9. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = getfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
10. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
A total of 22 subgoals...
[PROOF STEP]
apply (drule ConstElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (22 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |ad| \<le> |ba| + n; I = const c; na = Suc 0 \<and> (ab, ac, ba) = (c # ae, af, bb) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = dup\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = pop\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
4. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = swap\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
5. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = load x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
6. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = store x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
7. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = binop f\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
8. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = unop g\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
9. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = getfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
10. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
A total of 22 subgoals...
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (21 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = dup\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = pop\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = swap\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
4. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = load x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
5. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = store x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
6. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = binop f\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
7. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = unop g\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
8. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = getfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
9. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
10. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
A total of 21 subgoals...
[PROOF STEP]
apply (drule DupElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (21 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |ad| \<le> |ba| + n; I = dup; \<exists>v ops. ae = v # ops \<and> na = Suc 0 \<and> (ab, ac, ba) = (v # ae, af, bb) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = pop\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = swap\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
4. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = load x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
5. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = store x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
6. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = binop f\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
7. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = unop g\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
8. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = getfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
9. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
10. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
A total of 21 subgoals...
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (20 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = pop\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = swap\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = load x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
4. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = store x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
5. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = binop f\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
6. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = unop g\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
7. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = getfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
8. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
9. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 20 subgoals...
[PROOF STEP]
apply (drule PopElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (20 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |ad| \<le> |ba| + n; I = pop; \<exists>v ops. ae = v # ops \<and> na = Suc 0 \<and> (ab, ac, ba) = (ops, af, bb) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = swap\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = load x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
4. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = store x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
5. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = binop f\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
6. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = unop g\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
7. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = getfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
8. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
9. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 20 subgoals...
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (19 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = swap\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = load x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = store x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
4. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = binop f\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
5. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = unop g\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
6. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = getfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
7. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
8. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
9. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 19 subgoals...
[PROOF STEP]
apply (drule SwapElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (19 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |ad| \<le> |ba| + n; I = swap; \<exists>v w ops. ae = v # w # ops \<and> na = Suc 0 \<and> (ab, ac, ba) = (w # v # ops, af, bb) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = load x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = store x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
4. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = binop f\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
5. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = unop g\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
6. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = getfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
7. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
8. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
9. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 19 subgoals...
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (18 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = load x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = store x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = binop f\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
4. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = unop g\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
5. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = getfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
6. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
7. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
8. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
9. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 18 subgoals...
[PROOF STEP]
apply (drule LoadElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (18 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |ad| \<le> |ba| + n; I = load x; \<exists>v. af\<down>x = Some v \<and> na = Suc 0 \<and> (ab, ac, ba) = (v # ae, af, bb) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = store x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = binop f\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
4. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = unop g\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
5. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = getfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
6. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
7. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
8. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
9. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 18 subgoals...
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (17 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = store x\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = binop f\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = unop g\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
4. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = getfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
5. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
6. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
7. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
8. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
9. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 17 subgoals...
[PROOF STEP]
apply (drule StoreElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (17 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |ad| \<le> |ba| + n; I = store x; \<exists>v ops. ae = v # ops \<and> na = Suc 0 \<and> (ab, ac, ba) = (ops, af[x\<mapsto>v], bb) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = binop f\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = unop g\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
4. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = getfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
5. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
6. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
7. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
8. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
9. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 17 subgoals...
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (16 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = binop f\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = unop g\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = getfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
4. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
5. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
6. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
7. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
8. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
9. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 16 subgoals...
[PROOF STEP]
apply (drule BinopElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (16 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |ad| \<le> |ba| + n; I = binop f; \<exists>v w ops. ae = v # w # ops \<and> na = Suc 0 \<and> (ab, ac, ba) = (f v w # ops, af, bb) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = unop g\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = getfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
4. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
5. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
6. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
7. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
8. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
9. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 16 subgoals...
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (15 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = unop g\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = getfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
4. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
5. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
6. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
7. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
8. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
9. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 15 subgoals...
[PROOF STEP]
apply (drule UnopElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (15 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |ad| \<le> |ba| + n; I = unop g; \<exists>v ops. ae = v # ops \<and> na = Suc 0 \<and> (ab, ac, ba) = (g v # ops, af, bb) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = getfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
4. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
5. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
6. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
7. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
8. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
9. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 15 subgoals...
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (14 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = getfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
4. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
5. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
6. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
7. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
8. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
9. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 14 subgoals...
[PROOF STEP]
apply (drule GetElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (14 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |ad| \<le> |ba| + n; I = getfield d F; \<exists>a Flds v ops. bb\<down>a = Some (d, Flds) \<and> Flds\<down>F = Some v \<and> ae = RVal (Loc a) # ops \<and> na = Suc 0 \<and> (ab, ac, ba) = (v # ops, af, bb) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
4. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
5. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
6. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
7. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
8. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
9. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 14 subgoals...
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (13 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = putfield d F\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
4. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
5. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
6. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
7. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
8. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
9. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 13 subgoals...
[PROOF STEP]
apply (drule PutElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (13 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |ba| + n; I = putfield d F; \<exists>a Flds v ops. bb\<down>a = Some (d, Flds) \<and> ae = v # RVal (Loc a) # ops \<and> na = Suc 0 \<and> (ab, ac, ba) = (ops, af, bb[a\<mapsto>(d, Flds[F\<mapsto>v])]) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
4. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
5. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
6. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
7. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
8. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
9. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 13 subgoals...
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (13 subgoals):
1. \<And>a aa b ad bb ag Flds v. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |ad| \<le> |bb[ag\<mapsto>(d, Flds[F\<mapsto>v])]| + n; I = putfield d F; bb\<down>ag = Some (d, Flds)\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
3. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
4. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
5. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
6. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
7. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
8. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
9. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 13 subgoals...
[PROOF STEP]
apply (simp add: updSize)
[PROOF STATE]
proof (prove)
goal (12 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; ((a, aa, b), l, (ae, af, bb), na, l1, ab, ac, ba) \<in> Step; I = checkcast d\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
3. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
4. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
5. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
6. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
7. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
8. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
9. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 12 subgoals...
[PROOF STEP]
apply (drule CastElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (12 subgoals):
1. \<And>a aa b ab ac ba ad ae af bb l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |ad| \<le> |ba| + n; I = checkcast d; \<exists>a Flds ops. bb\<down>a = Some (d, Flds) \<and> ae = RVal (Loc a) # ops \<and> na = Suc 0 \<and> (ab, ac, ba) = (RVal (Loc a) # ops, af, bb) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |ad| \<le> |bb| + n
2. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
3. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
4. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
5. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
6. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
7. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
8. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
9. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 12 subgoals...
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (11 subgoals):
1. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
2. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
3. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
4. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
5. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
6. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
7. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
8. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
9. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
10. \<And>a aa b ab ba ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F\<rbrakk> \<Longrightarrow> SP_inv (a, aa, b) l (\<lambda>s0 (ops, s, h) k. |k| \<le> |h| + n) (ab, ba) (ac, ad, bb) k
A total of 11 subgoals...
[PROOF STEP]
apply (simp_all add: SP_inv_def)
[PROOF STATE]
proof (prove)
goal (11 subgoals):
1. \<And>a aa b ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c\<rbrakk> \<Longrightarrow> \<forall>ab ae ba. (\<exists>l1 n. ((a, aa, b), l, (ab, ae, ba), n, l1, ac, ad, bb) \<in> Step) \<longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup\<rbrakk> \<Longrightarrow> \<forall>ab ae ba. (\<exists>l1 n. ((a, aa, b), l, (ab, ae, ba), n, l1, ac, ad, bb) \<in> Step) \<longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop\<rbrakk> \<Longrightarrow> \<forall>ab ae ba. (\<exists>l1 n. ((a, aa, b), l, (ab, ae, ba), n, l1, ac, ad, bb) \<in> Step) \<longrightarrow> |k| \<le> |ba| + n
4. \<And>a aa b ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap\<rbrakk> \<Longrightarrow> \<forall>ab ae ba. (\<exists>l1 n. ((a, aa, b), l, (ab, ae, ba), n, l1, ac, ad, bb) \<in> Step) \<longrightarrow> |k| \<le> |ba| + n
5. \<And>a aa b ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x\<rbrakk> \<Longrightarrow> \<forall>ab ae ba. (\<exists>l1 n. ((a, aa, b), l, (ab, ae, ba), n, l1, ac, ad, bb) \<in> Step) \<longrightarrow> |k| \<le> |ba| + n
6. \<And>a aa b ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x\<rbrakk> \<Longrightarrow> \<forall>ab ae ba. (\<exists>l1 n. ((a, aa, b), l, (ab, ae, ba), n, l1, ac, ad, bb) \<in> Step) \<longrightarrow> |k| \<le> |ba| + n
7. \<And>a aa b ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f\<rbrakk> \<Longrightarrow> \<forall>ab ae ba. (\<exists>l1 n. ((a, aa, b), l, (ab, ae, ba), n, l1, ac, ad, bb) \<in> Step) \<longrightarrow> |k| \<le> |ba| + n
8. \<And>a aa b ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g\<rbrakk> \<Longrightarrow> \<forall>ab ae ba. (\<exists>l1 n. ((a, aa, b), l, (ab, ae, ba), n, l1, ac, ad, bb) \<in> Step) \<longrightarrow> |k| \<le> |ba| + n
9. \<And>a aa b ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F\<rbrakk> \<Longrightarrow> \<forall>ab ae ba. (\<exists>l1 n. ((a, aa, b), l, (ab, ae, ba), n, l1, ac, ad, bb) \<in> Step) \<longrightarrow> |k| \<le> |ba| + n
10. \<And>a aa b ac ad bb k. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F\<rbrakk> \<Longrightarrow> \<forall>ab ae ba. (\<exists>l1 n. ((a, aa, b), l, (ab, ae, ba), n, l1, ac, ad, bb) \<in> Step) \<longrightarrow> |k| \<le> |ba| + n
A total of 11 subgoals...
[PROOF STEP]
apply safe
[PROOF STATE]
proof (prove)
goal (11 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
4. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
5. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
6. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
7. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
8. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
9. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
10. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
A total of 11 subgoals...
[PROOF STEP]
apply (drule ConstElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (11 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (const c); |k| \<le> |bb| + n; I = const c; na = Suc 0 \<and> (ac, ad, bb) = (c # ab, ae, ba) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
4. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
5. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
6. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
7. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
8. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
9. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
10. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
A total of 11 subgoals...
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (10 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
4. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
5. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
6. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
7. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
8. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
9. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
10. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply (drule DupElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (10 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some dup; |k| \<le> |bb| + n; I = dup; \<exists>v ops. ab = v # ops \<and> na = Suc 0 \<and> (ac, ad, bb) = (v # ab, ae, ba) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
4. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
5. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
6. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
7. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
8. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
9. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
10. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (9 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
4. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
5. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
6. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
7. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
8. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
9. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply (drule PopElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (9 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some pop; |k| \<le> |bb| + n; I = pop; \<exists>v ops. ab = v # ops \<and> na = Suc 0 \<and> (ac, ad, bb) = (ops, ae, ba) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
4. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
5. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
6. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
7. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
8. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
9. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (8 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
4. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
5. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
6. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
7. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
8. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply (drule SwapElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (8 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some swap; |k| \<le> |bb| + n; I = swap; \<exists>v w ops. ab = v # w # ops \<and> na = Suc 0 \<and> (ac, ad, bb) = (w # v # ops, ae, ba) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
4. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
5. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
6. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
7. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
8. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (7 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
4. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
5. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
6. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
7. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply (drule LoadElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (7 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (load x); |k| \<le> |bb| + n; I = load x; \<exists>v. ae\<down>x = Some v \<and> na = Suc 0 \<and> (ac, ad, bb) = (v # ab, ae, ba) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
4. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
5. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
6. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
7. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (6 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
4. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
5. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
6. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply (drule StoreElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (6 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (store x); |k| \<le> |bb| + n; I = store x; \<exists>v ops. ab = v # ops \<and> na = Suc 0 \<and> (ac, ad, bb) = (ops, ae[x\<mapsto>v], ba) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
4. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
5. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
6. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (5 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
4. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
5. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply (drule BinopElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (5 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (binop f); |k| \<le> |bb| + n; I = binop f; \<exists>v w ops. ab = v # w # ops \<and> na = Suc 0 \<and> (ac, ad, bb) = (f v w # ops, ae, ba) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
4. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
5. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (4 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
4. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply (drule UnopElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (4 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (unop g); |k| \<le> |bb| + n; I = unop g; \<exists>v ops. ab = v # ops \<and> na = Suc 0 \<and> (ac, ad, bb) = (g v # ops, ae, ba) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
4. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (3 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply (drule GetElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (getfield d F); |k| \<le> |bb| + n; I = getfield d F; \<exists>a Flds v ops. ba\<down>a = Some (d, Flds) \<and> Flds\<down>F = Some v \<and> ab = RVal (Loc a) # ops \<and> na = Suc 0 \<and> (ac, ad, bb) = (v # ops, ae, ba) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
3. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (2 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply (drule PutElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |bb| + n; I = putfield d F; \<exists>a Flds v ops. ba\<down>a = Some (d, Flds) \<and> ab = v # RVal (Loc a) # ops \<and> na = Suc 0 \<and> (ac, ad, bb) = (ops, ae, ba[a\<mapsto>(d, Flds[F\<mapsto>v])]) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (2 subgoals):
1. \<And>a aa b k ba af Flds v. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (putfield d F); |k| \<le> |ba[af\<mapsto>(d, Flds[F\<mapsto>v])]| + n; I = putfield d F; ba\<down>af = Some (d, Flds)\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
2. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply (simp add: updSize)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; ((a, aa, b), l, (ab, ae, ba), na, l1, ac, ad, bb) \<in> Step\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply (drule CastElim1, fastforce)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<And>a aa b ac ad bb k ab ae ba l1 na. \<lbrakk>MST\<down>(C, m) = Some (Mspec, Minv, Anno); Anno\<down>l = None; mbody_is C m (a, aa, b); get_ins (a, aa, b) l = Some (checkcast d); |k| \<le> |bb| + n; I = checkcast d; \<exists>a Flds ops. ba\<down>a = Some (d, Flds) \<and> ab = RVal (Loc a) # ops \<and> na = Suc 0 \<and> (ac, ad, bb) = (RVal (Loc a) # ops, ae, ba) \<and> l1 = l + 1\<rbrakk> \<Longrightarrow> |k| \<le> |ba| + n
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done |
cc ------------ dpmjet3.4 - authors: S.Roesler, R.Engel, J.Ranft -------
cc -------- phojet1.12-40 - authors: S.Roesler, R.Engel, J.Ranft -------
cc - oct'13 -------
cc ----------- pythia-6.4 - authors: Torbjorn Sjostrand, Lund'10 -------
cc ---------------------------------------------------------------------
cc converted for use with FLUKA -------
cc - oct'13 -------
C...PY4JET
C...An interface from a four-parton generator to include
C...parton showers and hadronization.
SUBROUTINE PY4JET(PMAX,IRAD,ICOM)
C...Double precision and integer declarations.
IMPLICIT DOUBLE PRECISION(A-H, O-Z)
IMPLICIT INTEGER(I-N)
C...Commonblocks.
include 'inc/pyjets'
include 'inc/pydat1'
C...Local arrays.
DIMENSION IJOIN(2),PTOT(4),BETA(3)
C...Call PYHEPC to convert input from HEPEVT to PYJETS common.
IF(ICOM.EQ.0) THEN
MSTU(28)=0
CALL PYHEPC(2)
ENDIF
C...Loop through entries and pick up all final partons.
I1=0
I2=0
I3=0
I4=0
DO 100 I=1,N
IF(K(I,1).LE.0.OR.K(I,1).GT.10) GOTO 100
KFA=ABS(K(I,2))
IF((KFA.GE.1.AND.KFA.LE.6).OR.KFA.EQ.21) THEN
IF(K(I,2).GT.0.AND.K(I,2).LE.6) THEN
IF(I1.EQ.0) THEN
I1=I
ELSEIF(I3.EQ.0) THEN
I3=I
ELSE
CALL PYERRM(16,'(PY4JET:) more than two quarks')
ENDIF
ELSEIF(K(I,2).LT.0) THEN
IF(I2.EQ.0) THEN
I2=I
ELSEIF(I4.EQ.0) THEN
I4=I
ELSE
CALL PYERRM(16,'(PY4JET:) more than two antiquarks')
ENDIF
ELSE
IF(I3.EQ.0) THEN
I3=I
ELSEIF(I4.EQ.0) THEN
I4=I
ELSE
CALL PYERRM(16,'(PY4JET:) more than two gluons')
ENDIF
ENDIF
ENDIF
100 CONTINUE
C...Check that event is arranged according to conventions.
IF(I1.EQ.0.OR.I2.EQ.0.OR.I3.EQ.0.OR.I4.EQ.0) THEN
CALL PYERRM(16,'(PY4JET:) event contains too few partons')
ENDIF
IF(I2.LT.I1.OR.I3.LT.I2.OR.I4.LT.I3) THEN
CALL PYERRM(6,'(PY4JET:) partons arranged in wrong order')
ENDIF
C...Check whether second pair are quarks or gluons.
IF(ABS(K(I3,2)).LT.10.AND.ABS(K(I4,2)).LT.10) THEN
IQG34=1
ELSEIF(K(I3,2).EQ.21.AND.K(I4,2).EQ.21) THEN
IQG34=2
ELSE
CALL PYERRM(16,'(PY4JET:) second parton pair inconsistent')
ENDIF
C...Boost partons to their cm frame.
DO 110 J=1,4
PTOT(J)=P(I1,J)+P(I2,J)+P(I3,J)+P(I4,J)
110 CONTINUE
ECM=SQRT(MAX(0D0,PTOT(4)**2-PTOT(1)**2-PTOT(2)**2-PTOT(3)**2))
DO 120 J=1,3
BETA(J)=PTOT(J)/PTOT(4)
120 CONTINUE
CALL PYROBO(I1,I1,0D0,0D0,-BETA(1),-BETA(2),-BETA(3))
CALL PYROBO(I2,I2,0D0,0D0,-BETA(1),-BETA(2),-BETA(3))
CALL PYROBO(I3,I3,0D0,0D0,-BETA(1),-BETA(2),-BETA(3))
CALL PYROBO(I4,I4,0D0,0D0,-BETA(1),-BETA(2),-BETA(3))
NSAV=N
C...Decide and set up shower history for q qbar q' qbar' events.
IF(IQG34.EQ.1) THEN
W1=PY4JTW(0,I1,I3,I4)
W2=PY4JTW(0,I2,I3,I4)
IF(W1.GT.PYR(0)*(W1+W2)) THEN
CALL PY4JTS(0,I1,I3,I4,I2,QMAX)
ELSE
CALL PY4JTS(0,I2,I3,I4,I1,QMAX)
ENDIF
C...Decide and set up shower history for q qbar g g events.
ELSE
W1=PY4JTW(I1,I3,I2,I4)
W2=PY4JTW(I1,I4,I2,I3)
W3=PY4JTW(0,I3,I1,I4)
W4=PY4JTW(0,I4,I1,I3)
W5=PY4JTW(0,I3,I2,I4)
W6=PY4JTW(0,I4,I2,I3)
W7=PY4JTW(0,I1,I3,I4)
W8=PY4JTW(0,I2,I3,I4)
WR=(W1+W2+W3+W4+W5+W6+W7+W8)*PYR(0)
IF(W1.GT.WR) THEN
CALL PY4JTS(I1,I3,I2,I4,0,QMAX)
ELSEIF(W1+W2.GT.WR) THEN
CALL PY4JTS(I1,I4,I2,I3,0,QMAX)
ELSEIF(W1+W2+W3.GT.WR) THEN
CALL PY4JTS(0,I3,I1,I4,I2,QMAX)
ELSEIF(W1+W2+W3+W4.GT.WR) THEN
CALL PY4JTS(0,I4,I1,I3,I2,QMAX)
ELSEIF(W1+W2+W3+W4+W5.GT.WR) THEN
CALL PY4JTS(0,I3,I2,I4,I1,QMAX)
ELSEIF(W1+W2+W3+W4+W5+W6.GT.WR) THEN
CALL PY4JTS(0,I4,I2,I3,I1,QMAX)
ELSEIF(W1+W2+W3+W4+W5+W6+W7.GT.WR) THEN
CALL PY4JTS(0,I1,I3,I4,I2,QMAX)
ELSE
CALL PY4JTS(0,I2,I3,I4,I1,QMAX)
ENDIF
ENDIF
C...Boost back original partons and mark them as deleted.
CALL PYROBO(I1,I1,0D0,0D0,BETA(1),BETA(2),BETA(3))
CALL PYROBO(I2,I2,0D0,0D0,BETA(1),BETA(2),BETA(3))
CALL PYROBO(I3,I3,0D0,0D0,BETA(1),BETA(2),BETA(3))
CALL PYROBO(I4,I4,0D0,0D0,BETA(1),BETA(2),BETA(3))
K(I1,1)=K(I1,1)+10
K(I2,1)=K(I2,1)+10
K(I3,1)=K(I3,1)+10
K(I4,1)=K(I4,1)+10
C...Rotate shower initiating partons to be along z axis.
PHI=PYANGL(P(NSAV+1,1),P(NSAV+1,2))
CALL PYROBO(NSAV+1,NSAV+6,0D0,-PHI,0D0,0D0,0D0)
THE=PYANGL(P(NSAV+1,3),P(NSAV+1,1))
CALL PYROBO(NSAV+1,NSAV+6,-THE,0D0,0D0,0D0,0D0)
C...Set up copy of shower initiating partons as on mass shell.
DO 140 I=N+1,N+2
DO 130 J=1,5
K(I,J)=0
P(I,J)=0D0
V(I,J)=V(I1,J)
130 CONTINUE
K(I,1)=1
K(I,2)=K(I-6,2)
140 CONTINUE
IF(K(NSAV+1,2).EQ.K(I1,2)) THEN
K(N+1,3)=I1
P(N+1,5)=P(I1,5)
K(N+2,3)=I2
P(N+2,5)=P(I2,5)
ELSE
K(N+1,3)=I2
P(N+1,5)=P(I2,5)
K(N+2,3)=I1
P(N+2,5)=P(I1,5)
ENDIF
PABS=SQRT(MAX(0D0,(ECM**2-P(N+1,5)**2-P(N+2,5)**2)**2-
&(2D0*P(N+1,5)*P(N+2,5))**2))/(2D0*ECM)
P(N+1,3)=PABS
P(N+1,4)=SQRT(PABS**2+P(N+1,5)**2)
P(N+2,3)=-PABS
P(N+2,4)=SQRT(PABS**2+P(N+2,5)**2)
N=N+2
C...Decide whether to allow or not photon radiation in showers.
C...Connect up colours.
MSTJ(41)=2
IF(IRAD.EQ.0) MSTJ(41)=1
IJOIN(1)=N-1
IJOIN(2)=N
CALL PYJOIN(2,IJOIN)
C...Decide on maximum virtuality and do parton shower.
IF(PMAX.LT.PARJ(82)) THEN
PQMAX=QMAX
ELSE
PQMAX=PMAX
ENDIF
CALL PYSHOW(NSAV+1,-100,PQMAX)
C...Rotate and boost back system.
CALL PYROBO(NSAV+1,N,THE,PHI,BETA(1),BETA(2),BETA(3))
C...Do fragmentation and decays.
CALL PYEXEC
C...Call PYHEPC to convert output from PYJETS to HEPEVT common.
IF(ICOM.EQ.0) THEN
MSTU(28)=0
CALL PYHEPC(1)
ENDIF
RETURN
END
|
findfactors <- function(num) {
x <- NULL
firstprime<- 2; secondprime <- 3; everyprime <- num
while( everyprime != 1 ) {
while( everyprime%%firstprime == 0 ) {
x <- c(x, firstprime)
everyprime <- floor(everyprime/ firstprime)
}
firstprime <- secondprime
secondprime <- secondprime + 2
}
x
}
print(findfactors(1027*4))
|
(**
Here we define the signature for the group quotient.
We also derive its usual elimination principle.
Given a group `G`, we define the group quotient as follows
HIT group_quot G :=
| base : group_quot G
| loop : ∏ (g : G), base = base
| loop_e : loop e = idpath base
| loop_m : ∏ (g₁ g₂ : G), loop (g₁ · g₂) = loop g₁ @ loop g₂
In addition, this type is 1-truncated.
*)
Require Import UniMath.Foundations.All.
Require Import UniMath.MoreFoundations.All.
Require Import UniMath.CategoryTheory.Core.Categories.
Require Import UniMath.CategoryTheory.Groupoids.
Require Import UniMath.Bicategories.Core.Bicat.
Require Import UniMath.Bicategories.Core.Examples.OneTypes.
Require Import UniMath.Algebra.Monoids.
Require Import UniMath.Algebra.Groups.
Require Import prelude.all.
Require Import signature.hit_signature.
Require Import signature.hit.
Require Import algebra.one_types_polynomials.
Require Import algebra.one_types_endpoints.
Require Import algebra.one_types_homotopies.
Require Import displayed_algebras.displayed_algebra.
Require Import displayed_algebras.globe_over_lem.
Require Import existence.hit_existence.
Local Open Scope cat.
Definition prod_one_type
(A B : one_type)
: one_type.
Proof.
refine (make_one_type (A × B) _).
apply isofhleveldirprod.
- apply A.
- apply B.
Defined.
Section GroupQuotient.
Variable (G : gr).
Definition carrier_G : one_type.
Proof.
refine (make_one_type G _).
apply hlevelntosn ; apply (pr11 G).
Defined.
Definition mult_G : prod_one_type carrier_G carrier_G → carrier_G.
Proof.
cbn ; intros x.
exact (@op G (pr1 x) (pr2 x)).
Defined.
Definition group_quot_point_constr
: poly_code
:= C unit_one_type.
Inductive group_quot_homots : UU :=
| group_quot_ident : group_quot_homots
| group_quot_comp : group_quot_homots.
Definition group_quot_path_label
: UU
:= unit.
Definition group_quot_path_arg
: group_quot_path_label → poly_code
:= λ _, C carrier_G.
Definition group_quot_base_ep
(P : poly_code)
: endpoint group_quot_point_constr P I
:= comp (c P (tt : unit_one_type)) constr.
Definition group_quot_homot_point_arg
: group_quot_homots → poly_code.
Proof.
intro j ; induction j.
- exact (C unit_one_type).
- exact (C (prod_one_type carrier_G carrier_G)).
Defined.
Definition group_quot_homot_path_arg_poly
: group_quot_homots → poly_code
:= λ _, C unit_one_type.
Definition group_quot_homot_path_arg_lr
(j : group_quot_homots)
: endpoint
group_quot_point_constr
(group_quot_homot_point_arg j)
(group_quot_homot_path_arg_poly j).
Proof.
exact (@c _ _ unit_one_type tt).
Defined.
Definition group_quot_homot_lr_endpoint
(j : group_quot_homots)
: endpoint group_quot_point_constr (group_quot_homot_point_arg j) I.
Proof.
induction j.
- exact (group_quot_base_ep _).
- exact (group_quot_base_ep _).
Defined.
Definition group_quot_loop_hp
{P Q : poly_code}
{al ar : endpoint group_quot_point_constr P Q}
(g : endpoint group_quot_point_constr P (C carrier_G))
: homot_endpoint
(λ j0, group_quot_base_ep (group_quot_path_arg j0))
(λ j0, group_quot_base_ep (group_quot_path_arg j0))
al ar
(group_quot_base_ep P) (group_quot_base_ep P).
Proof.
simple refine
(trans_e
_
(trans_e
(path_constr tt g)
_)).
- cbn.
unfold group_quot_base_ep.
refine (trans_e
_
(inv_e (comp_assoc _ _ _))).
apply ap_e.
apply inv_e.
apply comp_constant.
- cbn.
unfold group_quot_base_ep.
refine (trans_e
(comp_assoc _ _ _)
_).
apply ap_e.
apply comp_constant.
Defined.
(*
Local Notation "p ~ q" := (homot_endpoint _ _ _ _ p q).
*)
Definition group_quot_homot_left
(j : group_quot_homots)
: homot_endpoint
(λ j0, group_quot_base_ep (group_quot_path_arg j0))
(λ j0, group_quot_base_ep (group_quot_path_arg j0))
(group_quot_homot_path_arg_lr j) (group_quot_homot_path_arg_lr j)
(group_quot_homot_lr_endpoint j) (group_quot_homot_lr_endpoint j).
Proof.
induction j.
- (* unit *)
apply group_quot_loop_hp.
apply c.
exact (unel G).
- (* multiplication *)
apply group_quot_loop_hp.
exact (fmap mult_G).
Defined.
Definition group_quot_homot_right
(j : group_quot_homots)
: homot_endpoint
(λ j0, group_quot_base_ep (group_quot_path_arg j0))
(λ j0, group_quot_base_ep (group_quot_path_arg j0))
(group_quot_homot_path_arg_lr j) (group_quot_homot_path_arg_lr j)
(group_quot_homot_lr_endpoint j) (group_quot_homot_lr_endpoint j).
Proof.
induction j.
- (* unit *)
apply refl_e.
- (* multiplication *)
refine (trans_e (group_quot_loop_hp (fmap _)) (group_quot_loop_hp (fmap _))).
+ exact pr1.
+ exact pr2.
Defined.
Definition group_quot_signature
: hit_signature.
Proof.
simple refine (_ ,, _ ,, _ ,, _ ,, _ ,, _ ,, _ ,, _ ,, _ ,, _ ,, _ ,, _ ,, _ ,, _).
- exact group_quot_point_constr.
- exact group_quot_path_label.
- exact group_quot_path_arg.
- exact (λ _, group_quot_base_ep _).
- exact (λ _, group_quot_base_ep _).
- exact group_quot_homots.
- exact group_quot_homot_point_arg.
- exact group_quot_homot_path_arg_poly.
- exact group_quot_homot_path_arg_lr.
- exact group_quot_homot_path_arg_lr.
- exact group_quot_homot_lr_endpoint.
- exact group_quot_homot_lr_endpoint.
- exact group_quot_homot_left.
- exact group_quot_homot_right.
Defined.
(** Projections of circle algebra *)
Section AlgebraProjections.
Variable (X : hit_algebra_one_types group_quot_signature).
Definition group_quot_base
: alg_carrier X
:= alg_constr X tt.
Definition group_quot_loop
(g : G)
: group_quot_base = group_quot_base
:= alg_path X tt g.
Definition group_quot_loop_unit
: group_quot_loop (unel G) = idpath group_quot_base.
Proof.
exact (!(pathscomp0rid _) @ alg_homot X group_quot_ident tt (idpath tt)).
Qed.
Definition group_quot_loop_mult
(g₁ g₂ : G)
: group_quot_loop (op g₁ g₂)
=
group_quot_loop g₁ @ group_quot_loop g₂.
Proof.
refine (!(pathscomp0rid _) @ alg_homot X group_quot_comp (g₁ ,, g₂) (idpath tt) @ _).
simpl.
etrans.
{
apply maponpaths.
apply pathscomp0rid.
}
apply maponpaths_2.
apply pathscomp0rid.
Qed.
End AlgebraProjections.
Section GroupQuotInduction.
Context {X : hit_algebra_one_types group_quot_signature}
(Y : alg_carrier X → one_type)
(Ybase : Y (group_quot_base X))
(Yloop : ∏ (g : G),
@PathOver _ _ _ (group_quot_loop X g) Y Ybase Ybase)
(Yunit : globe_over
Y
(group_quot_loop_unit X)
(Yloop (unel G))
(identityPathOver Ybase))
(Ycomp : ∏ (g₁ g₂ : G),
globe_over
Y
(group_quot_loop_mult X g₁ g₂)
(Yloop (op g₁ g₂))
(composePathOver (Yloop g₁) (Yloop g₂))).
Local Definition make_group_quot_disp_algebra_op
: ∏ (x : unit), unit → Y (alg_constr X x).
Proof.
intros x xx.
induction x.
exact Ybase.
Defined.
Local Definition make_group_quot_disp_algebra_path
: ∏ (j : path_label group_quot_signature)
(x : pr1 G),
pr1 G
→
@PathOver _ _ _ (alg_path X j x) Y Ybase Ybase.
Proof.
intros j x y.
induction j.
exact (Yloop x).
Defined.
Local Definition make_group_quot_disp_algebra_unit
(z : unit)
(p : tt = tt)
: globe_over
Y
(alg_homot X group_quot_ident z p)
(composePathOver
(composePathOver
(identityPathOver _)
(identityPathOver _))
(composePathOver
(Yloop 1%multmonoid)
(composePathOver
(identityPathOver _)
(identityPathOver _))))
(identityPathOver _).
Proof.
refine (globe_over_move_globe_one_type _ _).
{ apply (pr111 X). }
exact
(concat_globe_over
(globe_over_compose_left'
_
(concat_globe_over
(globe_over_compose_left'
_
(globe_over_id_left _))
(globe_over_id_right _)))
(concat_globe_over
(globe_over_compose_right
_
(globe_over_id_left _))
(concat_globe_over
(globe_over_id_left _)
Yunit))).
Qed.
Definition make_group_quot_disp_algebra_comp
(g₁ g₂ : G)
(p : tt = tt)
: globe_over
Y
(pr2 X group_quot_comp (g₁ ,, g₂) p)
(composePathOver
(composePathOver
(identityPathOver _)
(identityPathOver _))
(composePathOver
(Yloop (op g₁ g₂))
(composePathOver
(identityPathOver _)
(identityPathOver _))))
(composePathOver
(composePathOver
(composePathOver
(identityPathOver _)
(identityPathOver _))
(composePathOver
(Yloop g₁)
(composePathOver
(identityPathOver _)
(identityPathOver _))))
(composePathOver
(composePathOver
(identityPathOver _)
(identityPathOver _))
(composePathOver
(Yloop g₂)
(composePathOver
(identityPathOver _)
(identityPathOver _))))).
Proof.
refine (globe_over_move_globe_one_type _ _).
{ apply (pr111 X). }
refine
(concat_globe_over
(globe_over_compose_left'
_
(concat_globe_over
(globe_over_compose_left'
_
(globe_over_id_right _))
(globe_over_id_right _)))
(concat_globe_over
(globe_over_compose_right
_
(globe_over_id_right _))
(concat_globe_over
(globe_over_id_left _)
(concat_globe_over
(Ycomp g₁ g₂)
(inv_globe_over
(concat_globe_over
(globe_over_compose_left'
_
(concat_globe_over
(globe_over_compose_left'
_
(concat_globe_over
(globe_over_compose_left'
_
(globe_over_id_right _))
(globe_over_id_right _)))
(concat_globe_over
(globe_over_compose_right
_
(globe_over_id_right _))
(globe_over_id_left _))))
(globe_over_compose_right
_
(concat_globe_over
(globe_over_compose_left'
_
(concat_globe_over
(globe_over_compose_left'
_
(globe_over_id_right _))
(globe_over_id_right _)))
(concat_globe_over
(globe_over_compose_right
_
(globe_over_id_right _))
(globe_over_id_left _)))))))))).
Qed.
Definition make_group_quot_disp_algebra
: disp_algebra X.
Proof.
use make_disp_algebra.
- exact Y.
- exact make_group_quot_disp_algebra_op.
- exact make_group_quot_disp_algebra_path.
- intros j z zz p_arg pp_arg.
induction j.
+ apply make_group_quot_disp_algebra_unit.
+ apply make_group_quot_disp_algebra_comp.
Defined.
Variable (HX : is_HIT group_quot_signature X).
(** Induction principle *)
Definition group_quot_ind_disp_algebra_map
: disp_algebra_map make_group_quot_disp_algebra
:= HX make_group_quot_disp_algebra.
Definition group_quot_ind
: ∏ (x : alg_carrier X), Y x
:= pr1 group_quot_ind_disp_algebra_map.
Definition group_quot_ind_base
: group_quot_ind (group_quot_base X) = Ybase
:= pr12 group_quot_ind_disp_algebra_map tt.
Definition group_quot_ind_loop
(g : G)
: PathOver_square
_
(idpath _)
(apd
(pr1 group_quot_ind_disp_algebra_map)
(group_quot_loop X g))
(Yloop g)
group_quot_ind_base
group_quot_ind_base.
Proof.
pose (pr22 group_quot_ind_disp_algebra_map tt g).
simpl in p.
rewrite pathscomp0rid in p.
exact p.
Qed.
End GroupQuotInduction.
End GroupQuotient.
Definition group_quot (G : gr)
:= pr1 (hit_existence (group_quot_signature G)).
|
open import Data.Nat using (ℕ; suc; zero; _<_; _≤_; z≤n; s≤s; _+_; _⊔_)
open import Data.Bool using (Bool; true; false; not; _∧_)
open import Data.Sum using (inj₁; inj₂; _⊎_; [_,_])
open import Data.Product using (_×_; _,_; -,_; _-,-_; ∃; ∃-syntax; proj₂)
open import Data.String using (String; _≟_; length)
open import Relation.Nullary using (¬_; yes; no)
open import Relation.Nullary.Decidable using (⌊_⌋)
open import Relation.Nullary.Negation using (contradiction)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; cong; trans; cong₂)
open import Data.Nat.Properties hiding (_≤?_; _≟_)
open import IMP
level = ℕ
sec : vname → level
-- We can also temporarily use "sec x" to avoid the
-- automatic expansion of the definition in error messages
sec x = length x
secₐ : aexp → level
secₐ (N n) = 0
secₐ (V x) = sec x
secₐ (Plus a b) = secₐ a ⊔ secₐ b
sec₆ : bexp → level
sec₆ (Bc x) = 0
sec₆ (Not b) = sec₆ b
sec₆ (And b₁ b₂) = sec₆ b₁ ⊔ sec₆ b₂
sec₆ (Less a b) = secₐ a ⊔ secₐ b
_≡_⦅≤_⦆ : state → state → level → Set
s₁ ≡ s₂ ⦅≤ l ⦆ = ∀ x → sec x ≤ l → s₁ x ≡ s₂ x
_≡_⦅<_⦆ : state → state → level → Set
s₁ ≡ s₂ ⦅< l ⦆ = ∀ x → sec x < l → s₁ x ≡ s₂ x
non-interference-aexp : ∀ a {s₁ s₂ l}
→ s₁ ≡ s₂ ⦅≤ l ⦆
→ secₐ a ≤ l
→ aval a s₁ ≡ aval a s₂
non-interference-aexp (N x) r e = refl
non-interference-aexp (V x) r e = r x e
non-interference-aexp (Plus a b) r e =
cong₂ (_+_) (non-interference-aexp a r (m⊔n≤o⇒m≤o _ _ e))
(non-interference-aexp b r (m⊔n≤o⇒n≤o _ _ e))
non-interference-bexp : ∀ a {s₁ s₂ l}
→ s₁ ≡ s₂ ⦅≤ l ⦆
→ sec₆ a ≤ l
→ bval a s₁ ≡ bval a s₂
non-interference-bexp (Bc x) r e = refl
non-interference-bexp (Not a) r e = cong not (non-interference-bexp a r e)
non-interference-bexp (And a b) r e =
cong₂ (_∧_) (non-interference-bexp a r (m⊔n≤o⇒m≤o _ _ e))
(non-interference-bexp b r (m⊔n≤o⇒n≤o _ _ e))
non-interference-bexp (Less a b) r e =
cong₂ (_≤?_) (non-interference-aexp a r (m⊔n≤o⇒m≤o _ _ e))
(non-interference-aexp b r (m⊔n≤o⇒n≤o _ _ e))
data _⊢_ : level → com → Set where
SecSkip : ∀{l}
→ l ⊢ SKIP
SecLoc : ∀{l a x}
→ secₐ a ≤ sec x
→ l ≤ sec x
→ l ⊢ (x ::= a)
SecSeq : ∀{l c₁ c₂}
→ l ⊢ c₁
→ l ⊢ c₂
→ l ⊢ (c₁ :: c₂)
SecIf : ∀{b l c₁ c₂}
→ (l ⊔ sec₆ b) ⊢ c₁
→ (l ⊔ sec₆ b) ⊢ c₂
→ l ⊢ (IF b THEN c₁ ELSE c₂)
SecWhile : ∀{b l c}
→ (l ⊔ sec₆ b) ⊢ c
→ l ⊢ (WHILE b DO c)
anti-monotonicity : ∀{l l′ c}
→ l ⊢ c
→ l′ ≤ l
→ l′ ⊢ c
anti-monotonicity SecSkip s = SecSkip
anti-monotonicity (SecLoc x x₁) s = SecLoc x (≤-trans s x₁)
anti-monotonicity (SecSeq d d₁) s = SecSeq (anti-monotonicity d s) (anti-monotonicity d₁ s)
anti-monotonicity (SecIf d d₁) s = SecIf (anti-monotonicity d (⊔-monoˡ-≤ _ s)) (anti-monotonicity d₁ (⊔-monoˡ-≤ _ s))
anti-monotonicity (SecWhile d) s = SecWhile ((anti-monotonicity d (⊔-monoˡ-≤ _ s)))
data ⦅_,_⦆⇒_ : com → state → state → Set where
Skip : ∀{s} → ⦅ SKIP , s ⦆⇒ s
Loc : ∀{s x a}
→ ⦅ x ::= a , s ⦆⇒ (s [ x ::= aval a s ])
Seq : ∀{c₁ c₂ s₁ s₂ s₃}
→ ⦅ c₁ , s₁ ⦆⇒ s₂
→ ⦅ c₂ , s₂ ⦆⇒ s₃
→ ⦅ c₁ :: c₂ , s₁ ⦆⇒ s₃
IfTrue : ∀{c₁ c₂ b s t}
→ bval b s ≡ true
→ ⦅ c₁ , s ⦆⇒ t
→ ⦅ IF b THEN c₁ ELSE c₂ , s ⦆⇒ t
IfFalse : ∀{c₁ c₂ b s t}
→ bval b s ≡ false
→ ⦅ c₂ , s ⦆⇒ t
→ ⦅ IF b THEN c₁ ELSE c₂ , s ⦆⇒ t
WhileFalse : ∀{c b s}
→ bval b s ≡ false
→ ⦅ WHILE b DO c , s ⦆⇒ s
WhileTrue : ∀{c b s₁ s₂ s₃}
→ bval b s₁ ≡ true
→ ⦅ c , s₁ ⦆⇒ s₂
→ ⦅ WHILE b DO c , s₂ ⦆⇒ s₃
→ ⦅ WHILE b DO c , s₁ ⦆⇒ s₃
confinement : ∀{c s t l}
→ ⦅ c , s ⦆⇒ t
→ l ⊢ c
→ s ≡ t ⦅< l ⦆
confinement Skip SecSkip x₂ x₃ = refl
confinement (Loc {x = x₂}) (SecLoc x x₁) e r with e ≟ x₂
... | yes refl = contradiction x₁ (<⇒≱ r)
... | no _ = refl
confinement (Seq x x₄) (SecSeq x₁ x₅) x₂ x₃ =
trans (confinement x x₁ x₂ x₃)
(confinement x₄ x₅ x₂ x₃)
confinement (IfTrue x x₄) (SecIf x₁ x₅) x₂ x₃ = confinement x₄ x₁ x₂ (m<n⇒m<n⊔o _ x₃)
confinement (IfFalse x x₄) (SecIf x₁ x₅) x₂ x₃ = confinement x₄ x₅ x₂ (m<n⇒m<n⊔o _ x₃)
confinement (WhileFalse x) (SecWhile x₁) x₂ x₃ = refl
confinement {l = l} (WhileTrue x x₄ x₅) (SecWhile x₁) x₂ x₃ =
trans (confinement x₄ (anti-monotonicity x₁ (m≤m⊔n _ _)) x₂ x₃)
(confinement x₅ (SecWhile x₁) x₂ x₃)
true≢false : ¬ (true ≡ false)
true≢false = λ ()
reversal₁ : ∀{b c s₁ s₃}
→ ⦅ WHILE b DO c , s₁ ⦆⇒ s₃
→ bval b s₁ ≡ true
→ ∃[ s₂ ] ( ⦅ c , s₁ ⦆⇒ s₂ × ⦅ WHILE b DO c , s₂ ⦆⇒ s₃)
reversal₁ (WhileFalse x) v = contradiction (trans (sym v) x) true≢false
reversal₁ (WhileTrue x e e₁) v = -, e , e₁
reversal₂ : ∀{b c s₁ s₃}
→ ⦅ WHILE b DO c , s₁ ⦆⇒ s₃
→ bval b s₁ ≡ false
→ s₁ ≡ s₃
reversal₂ (WhileFalse x) v = refl
reversal₂ (WhileTrue x r r₁) v = contradiction (trans (sym x) v) true≢false
level-cong : ∀{l l′ c} → l ≡ l′ → l ⊢ c → l′ ⊢ c
level-cong refl x = x
≤⇒<suc : ∀{a b} → a ≤ b → a < suc b
≤⇒<suc z≤n = s≤s z≤n
≤⇒<suc (s≤s r) = s≤s (≤⇒<suc r)
non-interference : ∀{c s s′ t t′ l}
→ ⦅ c , s ⦆⇒ s′
→ ⦅ c , t ⦆⇒ t′
→ 0 ⊢ c
→ s ≡ t ⦅≤ l ⦆
→ s′ ≡ t′ ⦅≤ l ⦆
non-interference Skip Skip z e = e
non-interference (Loc {x = x₂} {a}) Loc (SecLoc x₃ z≤n) e x x₁ with x ≟ x₂
... | yes refl = non-interference-aexp a e (≤-trans x₃ x₁)
... | no _ = e x x₁
non-interference (Seq x cs) (Seq y ct) (SecSeq z z₁) e =
non-interference cs ct z₁ (non-interference x y z e)
non-interference {l = l} (IfTrue {b = b} x cs) (IfTrue x₁ red) (SecIf w w₁) e r r₁ =
non-interference cs red (anti-monotonicity w z≤n) e r r₁
non-interference {l = l} (IfTrue {b = b} x cs) (IfFalse x₁ red) (SecIf w w₁) e r r₁ =
[ (λ secb≤l →
let wr = non-interference-bexp b e secb≤l
in contradiction (trans (sym x) (trans wr x₁)) true≢false)
, (λ l<secb → let oo₁ = confinement cs w
oo₂ = confinement red w₁
in trans (sym (oo₁ r (<-transʳ r₁ l<secb)))
(trans (e r r₁)
(oo₂ r (<-transʳ r₁ l<secb))))
] (≤-<-connex (sec₆ b) l)
non-interference {l = l} (IfFalse x₁ red) (IfTrue {b = b} x cs) (SecIf w w₁) e r r₁ =
[ (λ secb≤l →
let wr = non-interference-bexp b e secb≤l
in contradiction (trans (sym x) (trans (sym wr) x₁)) true≢false)
, (λ l<secb → let oo₁ = confinement cs w
oo₂ = confinement red w₁
in trans (sym (oo₂ r (<-transʳ r₁ l<secb)))
(trans (e r r₁)
(oo₁ r (<-transʳ r₁ l<secb))))
] (≤-<-connex (sec₆ b) l)
non-interference (IfFalse x₁ red) (IfFalse x cs) (SecIf x₇ x₈) =
non-interference red cs (anti-monotonicity x₈ z≤n)
non-interference (WhileFalse x) (WhileFalse x₁) (SecWhile z) e = e
non-interference {l = l} (WhileFalse {b = b} r) (WhileTrue c ct ct₁) (SecWhile z) e x x₁ =
[ (λ secb≤l →
let wr = non-interference-bexp b e secb≤l
in contradiction (trans (sym c) (trans (sym wr) r)) true≢false)
, (λ l<secb →
let simp = confinement ct z
simp2 = confinement ct₁ (SecWhile (level-cong (sym (m≤n⇒m⊔n≡n l<secb)) z))
in trans (e x x₁) (trans (simp x (<-transʳ x₁ l<secb)) (simp2 x (≤⇒<suc x₁))))
] (≤-<-connex (sec₆ b) l)
non-interference {l = l} (WhileTrue c ct ct₁) (WhileFalse {b = b} r) (SecWhile z) e x x₁ =
[ (λ secb≤l →
let wr = non-interference-bexp b e secb≤l
in contradiction (trans (sym c) (trans wr r)) true≢false)
, (λ l<secb →
let simp = confinement ct z
simp2 = confinement ct₁ (SecWhile (level-cong (sym (m≤n⇒m⊔n≡n l<secb)) z))
in trans (trans (sym (simp2 x (≤⇒<suc x₁))) (sym (simp x ((<-transʳ x₁ l<secb))))) (e x x₁))
] (≤-<-connex (sec₆ b) l)
non-interference {l = l} (WhileTrue {b = b} r cs cs₁) (WhileTrue c ct ct₁) (SecWhile z) e =
let h₁ = non-interference cs ct (anti-monotonicity z z≤n) e
h₂ = non-interference cs₁ ct₁ (SecWhile z) h₁
in h₂
|
Formal statement is: lemma suminf_cmult_indicator: fixes f :: "nat \<Rightarrow> ennreal" assumes "disjoint_family A" "x \<in> A i" shows "(\<Sum>n. f n * indicator (A n) x) = f i" Informal statement is: If $f$ is a function from the natural numbers to the extended nonnegative reals and $A$ is a disjoint family of sets, then $\sum_{n=1}^\infty f(n) \cdot \mathbb{1}_{A_n}(x) = f(i)$ if $x \in A_i$. |
[STATEMENT]
lemma pmf_map_outside: "x \<notin> f ` set_pmf M \<Longrightarrow> pmf (map_pmf f M) x = 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. x \<notin> f ` set_pmf M \<Longrightarrow> pmf (map_pmf f M) x = 0
[PROOF STEP]
unfolding pmf_eq_0_set_pmf
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. x \<notin> f ` set_pmf M \<Longrightarrow> x \<notin> set_pmf (map_pmf f M)
[PROOF STEP]
by simp |
[STATEMENT]
lemma nat_mirror_less_conv: "
a < l + r \<Longrightarrow> (nat_mirror b l r < nat_mirror a l r) = (a < b)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. a < l + r \<Longrightarrow> (nat_mirror b l r < nat_mirror a l r) = (a < b)
[PROOF STEP]
unfolding nat_mirror_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. a < l + r \<Longrightarrow> (l + r - b < l + r - a) = (a < b)
[PROOF STEP]
by fastforce |
import Specdris.Spec
import Document
import Cursor
firstLine : String
firstLine = " line"
filename : String
filename = "afile"
oneLiner : Document
oneLiner = MkDocument [firstLine] filename
secondLine : String
secondLine = " line2"
twoLiner : Document
twoLiner = MkDocument [firstLine, secondLine] filename
main : IO ()
main = spec $ do
describe "document" $ do
describe "insert" $ do
describe "single line" $ do
it "adds a single character to the beginning" $ do
(insert oneLiner (MkCursor Z Z) 'a') `shouldBe` (MkDocument ["a line"] filename)
it "adds a single character to the middle" $ do
(insert oneLiner (MkCursor (S Z) Z) 'a') `shouldBe` (MkDocument [" aline"] filename)
it "adds a single character to the end" $ do
(insert oneLiner (MkCursor (length firstLine) Z) 'a') `shouldBe` (MkDocument [" linea"] filename)
describe "multiple lines" $ do
it "adds a single character to the first line" $ do
(insert twoLiner (MkCursor Z Z) 'a') `shouldBe` (MkDocument ["a line", secondLine] filename)
it "adds a single character to the second line" $ do
(insert twoLiner (MkCursor Z (S Z)) 'a') `shouldBe` (MkDocument [firstLine, "a line2"] filename)
describe "cursor after bounds" $ do
it "should not edit after the end of a line" $ do
(insert oneLiner (MkCursor (1 + length firstLine) Z) 'a') `shouldBe` oneLiner
|
FUNCTION:NAME
:BEGIN 1
-- @@stderr --
dtrace: script 'test/unittest/variables/tvar/tst.pre_inc_lvar.d' matched 1 probe
|
SUBROUTINE MINIMIZE(PAR,CHECK)
**********************************************************************
* Subroutine to compute
* MAFLAG=-5 :
* - MHU, MHD, MS
* MAFLAG=/=-5 :
* - KAPPA (if MAFLAG=-1 or -2) or XIF (if MAFLAG=-3 or -4)
* - MS (if MAFLAG=-1 or -3) or XIS (if MAFLAG=-2 or -4)
* - MU
* at the scales QSTSB and Q2
*
* MU at QSTSB is stored in COMMON/QPAR, MU at Q2 in PAR(4)
* KAPPA at QSTSB is stored in COMMON/QPAR, KAPPA at Q2 in PAR(2)
* MS at QSTSB is stored in COMMON/QMHIGGS, MS at Q2 in OMMON/SUSYMH
* XIF at QSTSB is stored in COMMON/QEXT, XIF at Q2 in OMMON/SUSYEXT
* XIS at QSTSB is stored in COMMON/QEXT, XIS at Q2 in OMMON/SUSYEXT
* MA at QSTSB is stored in PAR(23)
* MP at QSTSB is stored in PAR(24)
*
**********************************************************************
IMPLICIT NONE
INTEGER OMGFLAG,MAFLAG,MOFLAG
DOUBLE PRECISION PAR(*),CHECK,SIGMU,pi,At,Ab,COEF
DOUBLE PRECISION B,MUOLD,KOLD,MSSOLD,XIFOLD,XISOLD
DOUBLE PRECISION mst1,mst2,s2t,msb1,msb2,s2b,XT,XB
DOUBLE PRECISION ct,fmt1,fmt2,fmt,gmt
DOUBLE PRECISION cb,fmb1,fmb2,fmb,gmb
DOUBLE PRECISION MH1S,MH2S,MSS,QSTSB,GM
DOUBLE PRECISION ALSMZ,ALEMMZ,GF,g1,g2,S2TW
DOUBLE PRECISION MS,MC,MB,MBP,MT,MTAU,MMUON,MZ,MW
DOUBLE PRECISION RT1,RT2,RB1,RB2,AM,BM,CM,DETM
DOUBLE PRECISION G1Q,G2Q,GQ,ALSQ
DOUBLE PRECISION ZHU,ZHD,ZS,H1Q,H2Q,TANBQ
DOUBLE PRECISION HTQ,HBQ,MTOPQ,MBOTQ
DOUBLE PRECISION LQ,KQ,ALQ,AKQ,MUQ,NUQ
DOUBLE PRECISION g1s,g2s,g3s,HTOPS,HBOTS,HTAUS
DOUBLE PRECISION LS2,KS2,HTOPS2,HBOTS2,HTAUS2
DOUBLE PRECISION M1,M2,M3,ATAU,MQ3,MU3,MD3
DOUBLE PRECISION MQ,MU,MD,ML3,ME3,ML,ME,AL
DOUBLE PRECISION Q2,MH1Q,MH2Q,MSQ
DOUBLE PRECISION LQSTSB,LM1QSTSB,LM2QSTSB
DOUBLE PRECISION LM3QSTSB,LMQ3QSTSB,LMU3QSTSB
DOUBLE PRECISION LMD3QSTSB,LMQQSTSB,LMUQSTSB,LMDQSTSB
DOUBLE PRECISION LML3QSTSB,LME3QSTSB,LMLQSTSB,LMEQSTSB
DOUBLE PRECISION RL,RTOP,RBOT,RTAU,RG,ANOMQSTSB,MUFAIL
DOUBLE PRECISION XIF,XIS,MUP,MSP,M3H
DOUBLE PRECISION XIFQ,XISQ,MUPQ,MSPQ,M3HQ
COMMON/FLAGS/OMGFLAG,MAFLAG,MOFLAG
COMMON/GAUGE/ALSMZ,ALEMMZ,GF,g1,g2,S2TW
COMMON/SMSPEC/MS,MC,MB,MBP,MT,MTAU,MMUON,MZ,MW
COMMON/STSBSCALE/QSTSB
COMMON/RADCOR/mst1,mst2,s2t,msb1,msb2,s2b,XT,XB
COMMON/QGAUGE/G1Q,G2Q,GQ,ALSQ
COMMON/QHIGGS/ZHU,ZHD,ZS,H1Q,H2Q,TANBQ
COMMON/QQUARK/HTQ,HBQ,MTOPQ,MBOTQ
COMMON/QPAR/LQ,KQ,ALQ,AKQ,MUQ,NUQ
COMMON/SIGMU/SIGMU
COMMON/SUSYCOUP/g1s,g2s,g3s,HTOPS,HBOTS,HTAUS
COMMON/RENSCALE/Q2
COMMON/QMHIGGS/MH1Q,MH2Q,MSQ
COMMON/SUSYMH/MH1S,MH2S,MSS
COMMON/SUSYEXT/XIF,XIS,MUP,MSP,M3H
COMMON/QEXT/XIFQ,XISQ,MUPQ,MSPQ,M3HQ
COMMON/DETM/DETM
COMMON/MUFAIL/MUFAIL
pi=4d0*DATAN(1d0)
COEF=1d0/(16d0*PI**2)
! WRITE(0,*)"CALL MINIMIZE"
! WRITE(0,*)""
* (S)top/(S)/bottom loop corrections to the minimization equations:
At=PAR(12)
ct=3d0*htq**2*COEF
fmt1=mst1*(DLOG(mst1/QSTSB)-1d0)
fmt2=mst2*(DLOG(mst2/QSTSB)-1d0)
fmt=mtopq**2*(DLOG(mtopq**2/QSTSB)-1d0)
IF(mst1-mst2.NE.0d0)THEN
gmt=(fmt2-fmt1)/(mst2-mst1)
ELSE
gmt=DLOG(mst1/QSTSB)
ENDIF
Ab=PAR(13)
cb=3d0*hbq**2*COEF
fmb1=msb1*(DLOG(msb1/QSTSB)-1d0)
fmb2=msb2*(DLOG(msb2/QSTSB)-1d0)
fmb=mbotq**2*(DLOG(mbotq**2/QSTSB)-1d0)
IF(msb1-msb2.NE.0d0)THEN
gmb=(fmb2-fmb1)/(msb2-msb1)
ELSE
gmb=DLOG(msb1/QSTSB)
ENDIF
RT1=CT*(FMT1+FMT2-2d0*FMT+AT*XT*GMT)
RT2=CT*XT*GMT
RB1=CB*(FMB1+FMB2-2d0*FMB+AB*XB*GMB)
RB2=CB*XB*GMB
* If MU is an input parameters MH1Q, MH2Q, MSQ are computed
IF(MAFLAG.EQ.-5)THEN
B=ALQ+NUQ
GM= LQ*XIFQ+MUPQ*MUQ+M3HQ
MH1Q=-LQ**2*H2Q**2 - MUQ**2 + (MUQ*B+GM)/TANBQ
. +GQ/2d0*(H2Q**2-H1Q**2)
. -RT1+RB2*MUQ/TANBQ
MH2Q=-LQ**2*H1Q**2 - MUQ**2 + (MUQ*B+GM)*TANBQ
. +GQ/2d0*(H1Q**2-H2Q**2)
. -RB1+RT2*MUQ*TANBQ
MSQ=-LQ**2*(H1Q**2+H2Q**2) - 2d0*NUQ**2
. +LQ**2*H1Q*H2Q/MUQ*(ALQ+2d0*NUQ+MUPQ) - NUQ*AKQ
. -XIFQ*(2d0*KQ+LQ*MUPQ/MUQ)-MUPQ**2-3d0*MUPQ*NUQ
. -MSPQ-LQ*XISQ/MUQ
. +RT2*LQ**2*H1Q*H2Q/MUQ
. +RB2*LQ**2*H1Q*H2Q/MUQ
ENDIF
* MH1, MH2 are integrated between Q2 and QSTSB:
LS2=PAR(1)**2
KS2=PAR(2)**2
HTOPS2=HTOPS**2
HBOTS2=HBOTS**2
HTAUS2=HTAUS**2
M1=PAR(20)
M2=PAR(21)
M3=PAR(22)
ATAU=PAR(14)
AL=PAR(5)
MQ3=PAR(7)
MU3=PAR(8)
MD3=PAR(9)
ML3=PAR(10)
ME3=PAR(11)
MQ=PAR(15)
MU=PAR(16)
MD=PAR(17)
ML=PAR(18)
ME=PAR(19)
* Useful logarithms:
LQSTSB=DLOG(Q2/QSTSB)
LM1QSTSB=DLOG(Q2/MAX(M1**2,QSTSB))
LM2QSTSB=DLOG(Q2/MAX(M2**2,QSTSB))
LM3QSTSB=DLOG(Q2/MAX(M3**2,QSTSB))
LMQ3QSTSB=DLOG(Q2/MAX(MQ3,QSTSB))
LMU3QSTSB=DLOG(Q2/MAX(MU3,QSTSB))
LMD3QSTSB=DLOG(Q2/MAX(MD3,QSTSB))
LMQQSTSB=DLOG(Q2/MAX(MQ,QSTSB))
LMUQSTSB=DLOG(Q2/MAX(MU,QSTSB))
LMDQSTSB=DLOG(Q2/MAX(MD,QSTSB))
LML3QSTSB=DLOG(Q2/MAX(ML3,QSTSB))
LME3QSTSB=DLOG(Q2/MAX(ME3,QSTSB))
LMLQSTSB=DLOG(Q2/MAX(ML,QSTSB))
LMEQSTSB=DLOG(Q2/MAX(ME,QSTSB))
ANOMQSTSB=G1S*(-MH2S*LQSTSB+MQ3*LMQ3QSTSB
. -2d0*MU3*LMU3QSTSB
. +MD3*LMD3QSTSB+2d0*(MQ*LMQQSTSB
. -2d0*MU*LMUQSTSB+MD*LMDQSTSB)
. +ME3*LME3QSTSB-ML3*LML3QSTSB
. +2d0*(ME*LMEQSTSB-ML*LMLQSTSB))
RTOP=HTOPS2*(MQ3*LMQ3QSTSB+MU3*LMU3QSTSB
. +AT**2*LQSTSB)
RBOT=HBOTS2*(MH2S*LQSTSB+MQ3*LMQ3QSTSB+MD3*LMD3QSTSB
. +AB**2*LQSTSB)
RTAU=HTAUS2*(MH2S*LQSTSB+ML3*LML3QSTSB+ME3*LME3QSTSB
. +ATAU**2*LME3QSTSB)
RL=LS2*(MH2S+MSS+AL**2)*LQSTSB
RG=G1S*M1**2*LM1QSTSB+3d0*G2S*M2**2*LM2QSTSB
* Running MH1, MH2
* from QSTSB to Q2:
IF(MAFLAG.EQ.-5)THEN
MH1S=(MH1Q+COEF*(RL+3d0*RTOP-RG+ANOMQSTSB/2d0))
. *(Q2/QSTSB)**(COEF*(LS2+3d0*HTOPS2+G1S/2d0))
MH2S=MH2Q+COEF*(RL+3d0*RBOT+RTAU-RG-ANOMQSTSB/2d0
. +(LS2-G1S/2d0)*MH1S*LQSTSB)
MSS=MSQ+COEF*(2d0*LQ**2*(MH1Q+MH2Q+MSQ+ALQ**2)
. +2d0*KQ**2*(3d0*MSQ+AKQ**2))*LQSTSB
! WRITE(0,*)"MH1S =",MH1S
! WRITE(0,*)"MH2S =",MH2S
! WRITE(0,*)"MSS =",MSS
CHECK=0d0
* or from Q2 to QSTSB:
ELSE
MH1Q=MH1S*(QSTSB/Q2)**(COEF*(LS2+3d0*HTOPS2+G1S/2d0))
. -COEF*(RL+3d0*RTOP-RG+ANOMQSTSB/2d0)
MH2Q=MH2S-COEF*(RL+3d0*RBOT+RTAU-RG-ANOMQSTSB/2d0
. +(LS2-G1S/2d0)*MH1S*LQSTSB)
* Store the previous value of MU, (K or XIF) and (MS or XIS) for CHECK:
MUOLD=PAR(4)
KOLD=PAR(2)
MSSOLD=MSS
XIFOLD=XIF
XISOLD=XIS
* Prepare the computation of MU:
am=tanbq-1d0/tanbq
bm=rt2-rb2
cm=gq/2d0*(H1Q**2+H2Q**2)*(tanbq-1d0/tanbq)
. +(rt1+MH1Q)*tanbq-(rb1+MH2Q)/tanbq
detm=bm**2-4d0*am*cm
* MU at QSTSB is computed here:
IF(DETM.GE.0d0)THEN
MUQ=(-BM+SIGMU*DSQRT(DETM))/(2d0*AM)
ELSE
! WRITE(0,*)"DETM < 0"
! WRITE(0,*)""
MUQ=MUFAIL
ENDIF
IF(DABS(MUQ).LT.DABS(MUFAIL)) THEN
! WRITE(0,*)"DETM = 0"
! WRITE(0,*)""
DETM=0d0
MUQ=MUFAIL
ENDIF
* PAR(4) = MU at Q2, MU at QSTSB = MUQ is stored in COMMON/QPAR
PAR(4)=MUQ*(1d0+COEF/2d0*(2d0*LQ**2+3d0*(HTQ**2+HBQ**2)
. +(MTAU/H2Q)**2-G1Q-3d0*G2Q)*LQSTSB)
! WRITE(0,*)"MUS =",MUOLD,PAR(4)
* Effective B parameter:
B=TANBQ/((1d0+TANBQ**2)*MUQ)*(MH1Q+MH2Q+2d0*MUQ**2
. +LQ**2*(H1Q**2+H2Q**2)+RT1+RB1-MUQ*(RT2*TANBQ+RB2/TANBQ))
* If MAFLAG=-1,-2:
* Compute KQ = Kappa at QSTSB, then PAR(2) = KAPPA at Q2
IF(MAFLAG.EQ.-1 .OR. MAFLAG.EQ.-2)THEN
KQ=LQ*(B-ALQ-MUPQ-(LQ*XIFQ+M3HQ)/MUQ)/MUQ
PAR(2)=KQ*(1d0+3d0*COEF*(LQ**2+KQ**2)*LQSTSB)
NUQ=MUQ*KQ/LQ
! WRITE(0,*)"KS =",KOLD,PAR(2)
* Else compute XIF
ELSE
XIFQ=(MUQ*(B-ALQ-NUQ-MUPQ)-M3HQ)/LQ
XIF=XIFQ*(1d0+COEF*(LQ**2+KQ**2)*LQSTSB)
! WRITE(0,*)"XIF =",XIFOLD,XIF
ENDIF
* If MAFLAG=-1,-3:
* Compute MSSX = MS at QSTSB, then MSS = MS at Q2
IF(MAFLAG.EQ.-1 .OR. MAFLAG.EQ.-3)THEN
MSQ=-LQ**2*(H1Q**2+H2Q**2) - 2d0*NUQ**2
. +LQ**2*H1Q*H2Q/MUQ*(ALQ+2d0*NUQ+MUPQ) - NUQ*AKQ
. -XIFQ*(2d0*KQ+LQ*MUPQ/MUQ)-MUPQ**2-3d0*MUPQ*NUQ
. -MSPQ-LQ*XISQ/MUQ
. +ct*LQ**2*H1Q*H2Q/MUQ*Xt*gmt
. +cb*LQ**2*H1Q*H2Q/MUQ*Xb*gmb
MSS=MSQ+COEF*(2d0*LQ**2*(MH1Q+MH2Q+MSQ+ALQ**2)
. +2d0*KQ**2*(3d0*MSQ+AKQ**2))*LQSTSB
! WRITE(0,*)"MSS =",MSSOLD,MSS
* Else compute XIS
ELSE
MSQ=MSS-COEF*(2d0*LQ**2*(MH1Q+MH2Q+MSS+ALQ**2)
. +2d0*KQ**2*(3d0*MSS+AKQ**2))*LQSTSB
XISQ=LQ*(H1Q*H2Q*(ALQ+2d0*NUQ+MUPQ)-MUQ*(H1Q**2+H2Q**2))
. -MUQ/LQ*(MSQ+2d0*NUQ**2+NUQ*AKQ
. +XIFQ*(2d0*KQ+LQ*MUPQ/MUQ)
. +MUPQ**2+3d0*MUPQ*NUQ+MSPQ
. -ct*LQ**2*H1Q*H2Q/MUQ*Xt*gmt
. -cb*LQ**2*H1Q*H2Q/MUQ*Xb*gmb)
XIS=XISQ+COEF*(LQ**2*(XISQ+2d0*ALQ*XIFQ)
. +KQ**2*(XISQ+2d0*AKQ*XIFQ)
. +2d0*LQ*M3HQ*(ALQ+MUPQ)
. +KQ*MSPQ*(AKQ+MUPQ))*LQSTSB
! WRITE(0,*)"XIS =",XISOLD,XIS
ENDIF
* CHECK of MU, K or XIF, MS or XIS against the previous value
CHECK=(MUOLD-PAR(4))**2/(MUOLD**2+1d2)
CHECK=CHECK+(KOLD-PAR(2))**2/(KOLD**2+1d-12)
CHECK=CHECK+(XIFOLD-XIF)**2/(XIFOLD**2+1d4)
CHECK=CHECK+(MSSOLD-MSS)**2/(MSSOLD**2+1d4)
CHECK=CHECK+(XISOLD-XIS)**2/(XISOLD**2+1d6)
ENDIF
* Approximate value for the MSSM-like CP odd Higgs mass MA:
PAR(23)=DSQRT(MAX((MUQ*B+M3HQ+MUQ*MUPQ+LQ*XIFQ)
. *(tanbQ+1d0/tanbQ),1d0))
* Approximate value for the singlet-like CP odd Higgs mass MP:
PAR(24)=DSQRT(MAX(LQ**2*(B+3d0*NUQ+MUPQ)*H1Q*H2Q/MUQ
. -3d0*AKQ*NUQ-MUPQ*NUQ-2d0*MSPQ-4d0*KQ*XIFQ-LQ/MUQ
. *(XIFQ*MUPQ+XISQ),1d0))
! WRITE(0,*)"MA =",PAR(23)
! WRITE(0,*)"MP =",PAR(24)
! WRITE(0,*)""
! WRITE(0,*)"CHECK =",CHECK
! WRITE(0,*)""
! WRITE(0,*)""
END
|
If $f$ is holomorphic on a punctured neighborhood of $z$, then the residue of $f(z)/c$ at $z$ is equal to the residue of $f$ at $z$ divided by $c$. |
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c : CU X
n : ℕ
x : X
hx : x ∈ c.C
⊢ approx n c x = 0
[PROOFSTEP]
induction' n with n ihn generalizing c
[GOAL]
case zero
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
hx✝ : x ∈ c✝.C
c : CU X
hx : x ∈ c.C
⊢ approx Nat.zero c x = 0
[PROOFSTEP]
exact indicator_of_not_mem (fun (hU : x ∈ c.Uᶜ) => hU <| c.subset hx) _
[GOAL]
case succ
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
hx✝ : x ∈ c✝.C
n : ℕ
ihn : ∀ (c : CU X), x ∈ c.C → approx n c x = 0
c : CU X
hx : x ∈ c.C
⊢ approx (Nat.succ n) c x = 0
[PROOFSTEP]
simp only [approx]
[GOAL]
case succ
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
hx✝ : x ∈ c✝.C
n : ℕ
ihn : ∀ (c : CU X), x ∈ c.C → approx n c x = 0
c : CU X
hx : x ∈ c.C
⊢ midpoint ℝ (approx n (left c) x) (approx n (right c) x) = 0
[PROOFSTEP]
rw [ihn, ihn, midpoint_self]
[GOAL]
case succ.hx
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
hx✝ : x ∈ c✝.C
n : ℕ
ihn : ∀ (c : CU X), x ∈ c.C → approx n c x = 0
c : CU X
hx : x ∈ c.C
⊢ x ∈ (right c).C
case succ.hx
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
hx✝ : x ∈ c✝.C
n : ℕ
ihn : ∀ (c : CU X), x ∈ c.C → approx n c x = 0
c : CU X
hx : x ∈ c.C
⊢ x ∈ (left c).C
[PROOFSTEP]
exacts [c.subset_right_C hx, hx]
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c : CU X
n : ℕ
x : X
hx : ¬x ∈ c.U
⊢ approx n c x = 1
[PROOFSTEP]
induction' n with n ihn generalizing c
[GOAL]
case zero
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
hx✝ : ¬x ∈ c✝.U
c : CU X
hx : ¬x ∈ c.U
⊢ approx Nat.zero c x = 1
[PROOFSTEP]
rw [← mem_compl_iff] at hx
[GOAL]
case zero
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
hx✝ : ¬x ∈ c✝.U
c : CU X
hx : x ∈ c.Uᶜ
⊢ approx Nat.zero c x = 1
[PROOFSTEP]
exact indicator_of_mem hx _
[GOAL]
case succ
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
hx✝ : ¬x ∈ c✝.U
n : ℕ
ihn : ∀ (c : CU X), ¬x ∈ c.U → approx n c x = 1
c : CU X
hx : ¬x ∈ c.U
⊢ approx (Nat.succ n) c x = 1
[PROOFSTEP]
simp only [approx]
[GOAL]
case succ
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
hx✝ : ¬x ∈ c✝.U
n : ℕ
ihn : ∀ (c : CU X), ¬x ∈ c.U → approx n c x = 1
c : CU X
hx : ¬x ∈ c.U
⊢ midpoint ℝ (approx n (left c) x) (approx n (right c) x) = 1
[PROOFSTEP]
rw [ihn, ihn, midpoint_self]
[GOAL]
case succ.hx
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
hx✝ : ¬x ∈ c✝.U
n : ℕ
ihn : ∀ (c : CU X), ¬x ∈ c.U → approx n c x = 1
c : CU X
hx : ¬x ∈ c.U
⊢ ¬x ∈ (right c).U
case succ.hx
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
hx✝ : ¬x ∈ c✝.U
n : ℕ
ihn : ∀ (c : CU X), ¬x ∈ c.U → approx n c x = 1
c : CU X
hx : ¬x ∈ c.U
⊢ ¬x ∈ (left c).U
[PROOFSTEP]
exacts [hx, fun hU => hx <| c.left_U_subset hU]
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c : CU X
n : ℕ
x : X
⊢ 0 ≤ approx n c x
[PROOFSTEP]
induction' n with n ihn generalizing c
[GOAL]
case zero
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
c : CU X
⊢ 0 ≤ approx Nat.zero c x
[PROOFSTEP]
exact indicator_nonneg (fun _ _ => zero_le_one) _
[GOAL]
case succ
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
n : ℕ
ihn : ∀ (c : CU X), 0 ≤ approx n c x
c : CU X
⊢ 0 ≤ approx (Nat.succ n) c x
[PROOFSTEP]
simp only [approx, midpoint_eq_smul_add, invOf_eq_inv]
[GOAL]
case succ
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
n : ℕ
ihn : ∀ (c : CU X), 0 ≤ approx n c x
c : CU X
⊢ 0 ≤ 2⁻¹ • (approx n (left c) x + approx n (right c) x)
[PROOFSTEP]
refine' mul_nonneg (inv_nonneg.2 zero_le_two) (add_nonneg _ _)
[GOAL]
case succ.refine'_1
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
n : ℕ
ihn : ∀ (c : CU X), 0 ≤ approx n c x
c : CU X
⊢ 0 ≤ approx n (left c) x
[PROOFSTEP]
apply ihn
[GOAL]
case succ.refine'_2
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
n : ℕ
ihn : ∀ (c : CU X), 0 ≤ approx n c x
c : CU X
⊢ 0 ≤ approx n (right c) x
[PROOFSTEP]
apply ihn
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c : CU X
n : ℕ
x : X
⊢ approx n c x ≤ 1
[PROOFSTEP]
induction' n with n ihn generalizing c
[GOAL]
case zero
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
c : CU X
⊢ approx Nat.zero c x ≤ 1
[PROOFSTEP]
exact indicator_apply_le' (fun _ => le_rfl) fun _ => zero_le_one
[GOAL]
case succ
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
n : ℕ
ihn : ∀ (c : CU X), approx n c x ≤ 1
c : CU X
⊢ approx (Nat.succ n) c x ≤ 1
[PROOFSTEP]
simp only [approx, midpoint_eq_smul_add, invOf_eq_inv, smul_eq_mul, ← div_eq_inv_mul]
[GOAL]
case succ
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
n : ℕ
ihn : ∀ (c : CU X), approx n c x ≤ 1
c : CU X
⊢ (approx n (left c) x + approx n (right c) x) / 2 ≤ 1
[PROOFSTEP]
have := add_le_add (ihn (left c)) (ihn (right c))
[GOAL]
case succ
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
n : ℕ
ihn : ∀ (c : CU X), approx n c x ≤ 1
c : CU X
this : approx n (left c) x + approx n (right c) x ≤ 1 + 1
⊢ (approx n (left c) x + approx n (right c) x) / 2 ≤ 1
[PROOFSTEP]
norm_num at this
[GOAL]
case succ
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
n : ℕ
ihn : ∀ (c : CU X), approx n c x ≤ 1
c : CU X
this : approx n (left c) x + approx n (right c) x ≤ 2
⊢ (approx n (left c) x + approx n (right c) x) / 2 ≤ 1
[PROOFSTEP]
exact Iff.mpr (div_le_one zero_lt_two) this
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c₁ c₂ : CU X
h : c₁.U ⊆ c₂.C
n₁ n₂ : ℕ
x : X
⊢ approx n₂ c₂ x ≤ approx n₁ c₁ x
[PROOFSTEP]
by_cases hx : x ∈ c₁.U
[GOAL]
case pos
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c₁ c₂ : CU X
h : c₁.U ⊆ c₂.C
n₁ n₂ : ℕ
x : X
hx : x ∈ c₁.U
⊢ approx n₂ c₂ x ≤ approx n₁ c₁ x
[PROOFSTEP]
calc
approx n₂ c₂ x = 0 := approx_of_mem_C _ _ (h hx)
_ ≤ approx n₁ c₁ x := approx_nonneg _ _ _
[GOAL]
case neg
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c₁ c₂ : CU X
h : c₁.U ⊆ c₂.C
n₁ n₂ : ℕ
x : X
hx : ¬x ∈ c₁.U
⊢ approx n₂ c₂ x ≤ approx n₁ c₁ x
[PROOFSTEP]
calc
approx n₂ c₂ x ≤ 1 := approx_le_one _ _ _
_ = approx n₁ c₁ x := (approx_of_nmem_U _ _ hx).symm
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c : CU X
n : ℕ
x : X
⊢ approx n c x ∈ Icc (approx n (right c) x) (approx n (left c) x)
[PROOFSTEP]
induction' n with n ihn generalizing c
[GOAL]
case zero
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
c : CU X
⊢ approx Nat.zero c x ∈ Icc (approx Nat.zero (right c) x) (approx Nat.zero (left c) x)
[PROOFSTEP]
exact ⟨le_rfl, indicator_le_indicator_of_subset (compl_subset_compl.2 c.left_U_subset) (fun _ => zero_le_one) _⟩
[GOAL]
case succ
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
n : ℕ
ihn : ∀ (c : CU X), approx n c x ∈ Icc (approx n (right c) x) (approx n (left c) x)
c : CU X
⊢ approx (Nat.succ n) c x ∈ Icc (approx (Nat.succ n) (right c) x) (approx (Nat.succ n) (left c) x)
[PROOFSTEP]
simp only [approx, mem_Icc]
[GOAL]
case succ
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
n : ℕ
ihn : ∀ (c : CU X), approx n c x ∈ Icc (approx n (right c) x) (approx n (left c) x)
c : CU X
⊢ midpoint ℝ (approx n (left (right c)) x) (approx n (right (right c)) x) ≤
midpoint ℝ (approx n (left c) x) (approx n (right c) x) ∧
midpoint ℝ (approx n (left c) x) (approx n (right c) x) ≤
midpoint ℝ (approx n (left (left c)) x) (approx n (right (left c)) x)
[PROOFSTEP]
refine' ⟨midpoint_le_midpoint _ (ihn _).1, midpoint_le_midpoint (ihn _).2 _⟩
[GOAL]
case succ.refine'_1
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
n : ℕ
ihn : ∀ (c : CU X), approx n c x ∈ Icc (approx n (right c) x) (approx n (left c) x)
c : CU X
⊢ approx n (left (right c)) x ≤ approx n (left c) x
[PROOFSTEP]
apply approx_le_approx_of_U_sub_C
[GOAL]
case succ.refine'_2
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
n : ℕ
ihn : ∀ (c : CU X), approx n c x ∈ Icc (approx n (right c) x) (approx n (left c) x)
c : CU X
⊢ approx n (right c) x ≤ approx n (right (left c)) x
[PROOFSTEP]
apply approx_le_approx_of_U_sub_C
[GOAL]
case succ.refine'_1.h
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
n : ℕ
ihn : ∀ (c : CU X), approx n c x ∈ Icc (approx n (right c) x) (approx n (left c) x)
c : CU X
⊢ (left c).U ⊆ (left (right c)).C
case succ.refine'_2.h
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
n : ℕ
ihn : ∀ (c : CU X), approx n c x ∈ Icc (approx n (right c) x) (approx n (left c) x)
c : CU X
⊢ (right (left c)).U ⊆ (right c).C
[PROOFSTEP]
exacts [subset_closure, subset_closure]
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c : CU X
n : ℕ
x : X
⊢ approx n c x ≤ approx (n + 1) c x
[PROOFSTEP]
induction' n with n ihn generalizing c
[GOAL]
case zero
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
c : CU X
⊢ approx Nat.zero c x ≤ approx (Nat.zero + 1) c x
[PROOFSTEP]
simp only [approx, right_U, right_le_midpoint]
[GOAL]
case zero
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
c : CU X
⊢ indicator c.Uᶜ 1 x ≤ indicator (left c).Uᶜ 1 x
[PROOFSTEP]
exact (approx_mem_Icc_right_left c 0 x).2
[GOAL]
case succ
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
n : ℕ
ihn : ∀ (c : CU X), approx n c x ≤ approx (n + 1) c x
c : CU X
⊢ approx (Nat.succ n) c x ≤ approx (Nat.succ n + 1) c x
[PROOFSTEP]
rw [approx, approx]
[GOAL]
case succ
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
x : X
n : ℕ
ihn : ∀ (c : CU X), approx n c x ≤ approx (n + 1) c x
c : CU X
⊢ midpoint ℝ (approx n (left c) x) (approx n (right c) x) ≤
midpoint ℝ (approx (n + 1) (left c) x) (approx (n + 1) (right c) x)
[PROOFSTEP]
exact midpoint_le_midpoint (ihn _) (ihn _)
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c : CU X
x : X
h : x ∈ c.C
⊢ CU.lim c x = 0
[PROOFSTEP]
simp only [CU.lim, approx_of_mem_C, h, ciSup_const]
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c : CU X
x : X
h : ¬x ∈ c.U
⊢ CU.lim c x = 1
[PROOFSTEP]
simp only [CU.lim, approx_of_nmem_U c _ h, ciSup_const]
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c : CU X
x : X
⊢ CU.lim c x = midpoint ℝ (CU.lim (left c) x) (CU.lim (right c) x)
[PROOFSTEP]
refine' tendsto_nhds_unique (c.tendsto_approx_atTop x) ((tendsto_add_atTop_iff_nat 1).1 _)
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c : CU X
x : X
⊢ Tendsto (fun n => approx (n + 1) c x) atTop (𝓝 (midpoint ℝ (CU.lim (left c) x) (CU.lim (right c) x)))
[PROOFSTEP]
simp only [approx]
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c : CU X
x : X
⊢ Tendsto (fun n => midpoint ℝ (approx (Nat.add n 0) (left c) x) (approx (Nat.add n 0) (right c) x)) atTop
(𝓝 (midpoint ℝ (CU.lim (left c) x) (CU.lim (right c) x)))
[PROOFSTEP]
exact (c.left.tendsto_approx_atTop x).midpoint (c.right.tendsto_approx_atTop x)
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c : CU X
⊢ Continuous (CU.lim c)
[PROOFSTEP]
obtain ⟨h0, h1234, h1⟩ : 0 < (2⁻¹ : ℝ) ∧ (2⁻¹ : ℝ) < 3 / 4 ∧ (3 / 4 : ℝ) < 1 := by norm_num
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c : CU X
⊢ 0 < 2⁻¹ ∧ 2⁻¹ < 3 / 4 ∧ 3 / 4 < 1
[PROOFSTEP]
norm_num
[GOAL]
case intro.intro
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
⊢ Continuous (CU.lim c)
[PROOFSTEP]
refine'
continuous_iff_continuousAt.2 fun x =>
(Metric.nhds_basis_closedBall_pow (h0.trans h1234) h1).tendsto_right_iff.2 fun n _ => _
[GOAL]
case intro.intro
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
n : ℕ
x✝ : True
⊢ ∀ᶠ (x_1 : X) in 𝓝 x, CU.lim c x_1 ∈ Metric.closedBall (CU.lim c x) ((3 / 4) ^ n)
[PROOFSTEP]
simp only [Metric.mem_closedBall]
[GOAL]
case intro.intro
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
n : ℕ
x✝ : True
⊢ ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
[PROOFSTEP]
induction' n with n ihn generalizing c
[GOAL]
case intro.intro.zero
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
c : CU X
⊢ ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ Nat.zero
[PROOFSTEP]
refine' eventually_of_forall fun y => _
[GOAL]
case intro.intro.zero
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
c : CU X
y : X
⊢ dist (CU.lim c y) (CU.lim c x) ≤ (3 / 4) ^ Nat.zero
[PROOFSTEP]
rw [pow_zero]
[GOAL]
case intro.intro.zero
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
c : CU X
y : X
⊢ dist (CU.lim c y) (CU.lim c x) ≤ 1
[PROOFSTEP]
exact Real.dist_le_of_mem_Icc_01 (c.lim_mem_Icc _) (c.lim_mem_Icc _)
[GOAL]
case intro.intro.succ
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
⊢ ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ Nat.succ n
[PROOFSTEP]
by_cases hxl : x ∈ c.left.U
[GOAL]
case pos
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
hxl : x ∈ (left c).U
⊢ ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ Nat.succ n
[PROOFSTEP]
filter_upwards [IsOpen.mem_nhds c.left.open_U hxl, ihn c.left] with _ hyl hyd
[GOAL]
case h
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
hxl : x ∈ (left c).U
a✝ : X
hyl : a✝ ∈ (left c).U
hyd : dist (CU.lim (left c) a✝) (CU.lim (left c) x) ≤ (3 / 4) ^ n
⊢ dist (CU.lim c a✝) (CU.lim c x) ≤ (3 / 4) ^ Nat.succ n
[PROOFSTEP]
rw [pow_succ, c.lim_eq_midpoint, c.lim_eq_midpoint, c.right.lim_of_mem_C _ (c.left_U_subset_right_C hyl),
c.right.lim_of_mem_C _ (c.left_U_subset_right_C hxl)]
[GOAL]
case h
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
hxl : x ∈ (left c).U
a✝ : X
hyl : a✝ ∈ (left c).U
hyd : dist (CU.lim (left c) a✝) (CU.lim (left c) x) ≤ (3 / 4) ^ n
⊢ dist (midpoint ℝ (CU.lim (left c) a✝) 0) (midpoint ℝ (CU.lim (left c) x) 0) ≤ 3 / 4 * (3 / 4) ^ n
[PROOFSTEP]
refine' (dist_midpoint_midpoint_le _ _ _ _).trans _
[GOAL]
case h
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
hxl : x ∈ (left c).U
a✝ : X
hyl : a✝ ∈ (left c).U
hyd : dist (CU.lim (left c) a✝) (CU.lim (left c) x) ≤ (3 / 4) ^ n
⊢ (dist (CU.lim (left c) a✝) (CU.lim (left c) x) + dist 0 0) / 2 ≤ 3 / 4 * (3 / 4) ^ n
[PROOFSTEP]
rw [dist_self, add_zero, div_eq_inv_mul]
[GOAL]
case h
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
hxl : x ∈ (left c).U
a✝ : X
hyl : a✝ ∈ (left c).U
hyd : dist (CU.lim (left c) a✝) (CU.lim (left c) x) ≤ (3 / 4) ^ n
⊢ 2⁻¹ * dist (CU.lim (left c) a✝) (CU.lim (left c) x) ≤ 3 / 4 * (3 / 4) ^ n
[PROOFSTEP]
gcongr
[GOAL]
case neg
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
hxl : ¬x ∈ (left c).U
⊢ ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ Nat.succ n
[PROOFSTEP]
replace hxl : x ∈ c.left.right.Cᶜ
[GOAL]
case hxl
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
hxl : ¬x ∈ (left c).U
⊢ x ∈ (right (left c)).Cᶜ
case neg
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
hxl : x ∈ (right (left c)).Cᶜ
⊢ ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ Nat.succ n
[PROOFSTEP]
exact compl_subset_compl.2 c.left.right.subset hxl
[GOAL]
case neg
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
hxl : x ∈ (right (left c)).Cᶜ
⊢ ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ Nat.succ n
[PROOFSTEP]
filter_upwards [IsOpen.mem_nhds (isOpen_compl_iff.2 c.left.right.closed_C) hxl, ihn c.left.right, ihn c.right] with y
hyl hydl hydr
[GOAL]
case h
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
hxl : x ∈ (right (left c)).Cᶜ
y : X
hyl : y ∈ (right (left c)).Cᶜ
hydl : dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x) ≤ (3 / 4) ^ n
hydr : dist (CU.lim (right c) y) (CU.lim (right c) x) ≤ (3 / 4) ^ n
⊢ dist (CU.lim c y) (CU.lim c x) ≤ (3 / 4) ^ Nat.succ n
[PROOFSTEP]
replace hxl : x ∉ c.left.left.U
[GOAL]
case hxl
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
hxl : x ∈ (right (left c)).Cᶜ
y : X
hyl : y ∈ (right (left c)).Cᶜ
hydl : dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x) ≤ (3 / 4) ^ n
hydr : dist (CU.lim (right c) y) (CU.lim (right c) x) ≤ (3 / 4) ^ n
⊢ ¬x ∈ (left (left c)).U
case h
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
y : X
hyl : y ∈ (right (left c)).Cᶜ
hydl : dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x) ≤ (3 / 4) ^ n
hydr : dist (CU.lim (right c) y) (CU.lim (right c) x) ≤ (3 / 4) ^ n
hxl : ¬x ∈ (left (left c)).U
⊢ dist (CU.lim c y) (CU.lim c x) ≤ (3 / 4) ^ Nat.succ n
[PROOFSTEP]
exact compl_subset_compl.2 c.left.left_U_subset_right_C hxl
[GOAL]
case h
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
y : X
hyl : y ∈ (right (left c)).Cᶜ
hydl : dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x) ≤ (3 / 4) ^ n
hydr : dist (CU.lim (right c) y) (CU.lim (right c) x) ≤ (3 / 4) ^ n
hxl : ¬x ∈ (left (left c)).U
⊢ dist (CU.lim c y) (CU.lim c x) ≤ (3 / 4) ^ Nat.succ n
[PROOFSTEP]
replace hyl : y ∉ c.left.left.U
[GOAL]
case hyl
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
y : X
hyl : y ∈ (right (left c)).Cᶜ
hydl : dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x) ≤ (3 / 4) ^ n
hydr : dist (CU.lim (right c) y) (CU.lim (right c) x) ≤ (3 / 4) ^ n
hxl : ¬x ∈ (left (left c)).U
⊢ ¬y ∈ (left (left c)).U
case h
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
y : X
hydl : dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x) ≤ (3 / 4) ^ n
hydr : dist (CU.lim (right c) y) (CU.lim (right c) x) ≤ (3 / 4) ^ n
hxl : ¬x ∈ (left (left c)).U
hyl : ¬y ∈ (left (left c)).U
⊢ dist (CU.lim c y) (CU.lim c x) ≤ (3 / 4) ^ Nat.succ n
[PROOFSTEP]
exact compl_subset_compl.2 c.left.left_U_subset_right_C hyl
[GOAL]
case h
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
y : X
hydl : dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x) ≤ (3 / 4) ^ n
hydr : dist (CU.lim (right c) y) (CU.lim (right c) x) ≤ (3 / 4) ^ n
hxl : ¬x ∈ (left (left c)).U
hyl : ¬y ∈ (left (left c)).U
⊢ dist (CU.lim c y) (CU.lim c x) ≤ (3 / 4) ^ Nat.succ n
[PROOFSTEP]
simp only [pow_succ, c.lim_eq_midpoint, c.left.lim_eq_midpoint, c.left.left.lim_of_nmem_U _ hxl,
c.left.left.lim_of_nmem_U _ hyl]
[GOAL]
case h
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
y : X
hydl : dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x) ≤ (3 / 4) ^ n
hydr : dist (CU.lim (right c) y) (CU.lim (right c) x) ≤ (3 / 4) ^ n
hxl : ¬x ∈ (left (left c)).U
hyl : ¬y ∈ (left (left c)).U
⊢ dist (midpoint ℝ (midpoint ℝ 1 (CU.lim (right (left c)) y)) (CU.lim (right c) y))
(midpoint ℝ (midpoint ℝ 1 (CU.lim (right (left c)) x)) (CU.lim (right c) x)) ≤
3 / 4 * (3 / 4) ^ n
[PROOFSTEP]
refine' (dist_midpoint_midpoint_le _ _ _ _).trans _
[GOAL]
case h
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
y : X
hydl : dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x) ≤ (3 / 4) ^ n
hydr : dist (CU.lim (right c) y) (CU.lim (right c) x) ≤ (3 / 4) ^ n
hxl : ¬x ∈ (left (left c)).U
hyl : ¬y ∈ (left (left c)).U
⊢ (dist (midpoint ℝ 1 (CU.lim (right (left c)) y)) (midpoint ℝ 1 (CU.lim (right (left c)) x)) +
dist (CU.lim (right c) y) (CU.lim (right c) x)) /
2 ≤
3 / 4 * (3 / 4) ^ n
[PROOFSTEP]
refine' (div_le_div_of_le_of_nonneg (add_le_add_right (dist_midpoint_midpoint_le _ _ _ _) _) zero_le_two).trans _
[GOAL]
case h
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
y : X
hydl : dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x) ≤ (3 / 4) ^ n
hydr : dist (CU.lim (right c) y) (CU.lim (right c) x) ≤ (3 / 4) ^ n
hxl : ¬x ∈ (left (left c)).U
hyl : ¬y ∈ (left (left c)).U
⊢ ((dist 1 1 + dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x)) / 2 +
dist (CU.lim (right c) y) (CU.lim (right c) x)) /
2 ≤
3 / 4 * (3 / 4) ^ n
[PROOFSTEP]
rw [dist_self, zero_add]
[GOAL]
case h
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ (3 / 4) ^ n
c : CU X
y : X
hydl : dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x) ≤ (3 / 4) ^ n
hydr : dist (CU.lim (right c) y) (CU.lim (right c) x) ≤ (3 / 4) ^ n
hxl : ¬x ∈ (left (left c)).U
hyl : ¬y ∈ (left (left c)).U
⊢ (dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x) / 2 + dist (CU.lim (right c) y) (CU.lim (right c) x)) /
2 ≤
3 / 4 * (3 / 4) ^ n
[PROOFSTEP]
set r := (3 / 4 : ℝ) ^ n
[GOAL]
case h
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
c : CU X
y : X
hxl : ¬x ∈ (left (left c)).U
hyl : ¬y ∈ (left (left c)).U
r : ℝ := (3 / 4) ^ n
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ r
hydl : dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x) ≤ r
hydr : dist (CU.lim (right c) y) (CU.lim (right c) x) ≤ r
⊢ (dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x) / 2 + dist (CU.lim (right c) y) (CU.lim (right c) x)) /
2 ≤
3 / 4 * r
[PROOFSTEP]
calc
_ ≤ (r / 2 + r) / 2 := by gcongr
_ = _ := by field_simp; ring
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
c : CU X
y : X
hxl : ¬x ∈ (left (left c)).U
hyl : ¬y ∈ (left (left c)).U
r : ℝ := (3 / 4) ^ n
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ r
hydl : dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x) ≤ r
hydr : dist (CU.lim (right c) y) (CU.lim (right c) x) ≤ r
⊢ (dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x) / 2 + dist (CU.lim (right c) y) (CU.lim (right c) x)) /
2 ≤
(r / 2 + r) / 2
[PROOFSTEP]
gcongr
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
c : CU X
y : X
hxl : ¬x ∈ (left (left c)).U
hyl : ¬y ∈ (left (left c)).U
r : ℝ := (3 / 4) ^ n
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ r
hydl : dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x) ≤ r
hydr : dist (CU.lim (right c) y) (CU.lim (right c) x) ≤ r
⊢ (r / 2 + r) / 2 = 3 / 4 * r
[PROOFSTEP]
field_simp
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
c✝ : CU X
h0 : 0 < 2⁻¹
h1234 : 2⁻¹ < 3 / 4
h1 : 3 / 4 < 1
x : X
x✝ : True
n : ℕ
c : CU X
y : X
hxl : ¬x ∈ (left (left c)).U
hyl : ¬y ∈ (left (left c)).U
r : ℝ := (3 / 4) ^ n
ihn : ∀ (c : CU X), ∀ᶠ (x_1 : X) in 𝓝 x, dist (CU.lim c x_1) (CU.lim c x) ≤ r
hydl : dist (CU.lim (right (left c)) y) (CU.lim (right (left c)) x) ≤ r
hydr : dist (CU.lim (right c) y) (CU.lim (right c) x) ≤ r
⊢ (3 ^ n * 4 ^ n + 3 ^ n * (4 ^ n * 2)) * (4 * 4 ^ n) = 3 * 3 ^ n * (4 ^ n * 2 * 4 ^ n * 2)
[PROOFSTEP]
ring
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
s t : Set X
hs : IsClosed s
ht : IsClosed t
hd : Disjoint s t
⊢ ∃ f, EqOn (↑f) 0 s ∧ EqOn (↑f) 1 t ∧ ∀ (x : X), ↑f x ∈ Icc 0 1
[PROOFSTEP]
set c : Urysohns.CU X := ⟨s, tᶜ, hs, ht.isOpen_compl, disjoint_left.1 hd⟩
[GOAL]
X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
s t : Set X
hs : IsClosed s
ht : IsClosed t
hd : Disjoint s t
c : Urysohns.CU X :=
{ C := s, U := tᶜ, closed_C := hs, open_U := (_ : IsOpen tᶜ), subset := (_ : ∀ ⦃a : X⦄, a ∈ s → ¬a ∈ t) }
⊢ ∃ f, EqOn (↑f) 0 s ∧ EqOn (↑f) 1 t ∧ ∀ (x : X), ↑f x ∈ Icc 0 1
[PROOFSTEP]
exact ⟨⟨c.lim, c.continuous_lim⟩, c.lim_of_mem_C, fun x hx => c.lim_of_nmem_U _ fun h => h hx, c.lim_mem_Icc⟩
|
//
// Created by weitao on 3/5/16.
//
#include <cstdint>
#include <iostream>
#include <chrono>
#include <tuple>
#include <vector>
#include <boost/optional.hpp>
#include <string>
#include "snow.hpp"
class echo_session : public snow::session<uint32_t, uint32_t> {
public:
explicit echo_session(boost::asio::io_service &ios)
: snow::session<uint32_t, uint32_t>{ios} {
}
virtual boost::optional<uint32_t> process(const uint32_t &req) override {
SNOW_LOG_TRACE("req {}", req);
return {req + 10};
}
};
class server : public snow::server<echo_session> {
public:
virtual int check(const char *data, std::size_t size) const override {
if (size >= 4) {
return 4;
} else {
return 0;
}
}
virtual std::string encode(const response_t &rsp) const override {
SNOW_LOG_TRACE("rsp {}", rsp);
return std::string((char *) &rsp, sizeof(rsp));
}
virtual request_t decode(const char *data, std::size_t size) const override {
return *(uint32_t *) (data);
}
};
int main(int argc, char *argv[]) {
SNOW_LOG_INFO("test1 begin");
try {
server the_server;
the_server.start();
} catch (std::exception &e) {
SNOW_LOG_INFO("Exception: {}", e.what());
}
SNOW_LOG_INFO("test1 end");
return 0;
} |
\title{Addition in myHDL (In Progress)}
\author{Steven K Armour}
\maketitle
# Refrances
https://www.geeksforgeeks.org/digital-logic-carry-look-ahead-adder/
http://faculty.kfupm.edu.sa/COE/abouh/Lesson3_3.pdf
# Libraries and Helper functions
```python
from myhdl import *
from myhdlpeek import Peeker
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
from sympy import *
init_printing()
import itertools
#https://github.com/jrjohansson/version_information
%load_ext version_information
%version_information myhdl, myhdlpeek, numpy, pandas, matplotlib, sympy, random, itertools
```
<table><tr><th>Software</th><th>Version</th></tr><tr><td>Python</td><td>3.6.5 64bit [GCC 7.2.0]</td></tr><tr><td>IPython</td><td>6.4.0</td></tr><tr><td>OS</td><td>Linux 4.15.0 30 generic x86_64 with debian buster sid</td></tr><tr><td>myhdl</td><td>0.10</td></tr><tr><td>myhdlpeek</td><td>0.0.7</td></tr><tr><td>numpy</td><td>1.14.3</td></tr><tr><td>pandas</td><td>0.23.0</td></tr><tr><td>matplotlib</td><td>2.2.2</td></tr><tr><td>sympy</td><td>1.1.1</td></tr><tr><td>random</td><td>The 'random' distribution was not found and is required by the application</td></tr><tr><td>itertools</td><td>The 'itertools' distribution was not found and is required by the application</td></tr><tr><td colspan='2'>Tue Aug 21 12:52:12 2018 MDT</td></tr></table>
```python
#helper functions to read in the .v and .vhd generated files into python
def VerilogTextReader(loc, printresult=True):
with open(f'{loc}.v', 'r') as vText:
VerilogText=vText.read()
if printresult:
print(f'***Verilog modual from {loc}.v***\n\n', VerilogText)
return VerilogText
def VHDLTextReader(loc, printresult=True):
with open(f'{loc}.vhd', 'r') as vText:
VerilogText=vText.read()
if printresult:
print(f'***VHDL modual from {loc}.vhd***\n\n', VerilogText)
return VerilogText
```
```python
BitVals=[0,1]
```
# Half Adder
## myHDL Code
```python
@block
def HalfAdder(x1, x2, s, c):
"""
Half Adder
Input:
x1(bool): bit signal to be added
x2(bool): bit signal to be added
Output:
s(bool): Half Adder Sum
c(bool): Half Adder Carry
"""
@always_comb
def logic():
s.next=x1 ^ x2
c.next=x1 & x2
return instances()
```
## myHDL Testing
```python
Peeker.clear()
x1=Signal(bool(0)); Peeker(x1, 'x1')
x2=Signal(bool(0)); Peeker(x2, 'x2')
s=Signal(bool(0)); Peeker(s, 's')
c=Signal(bool(0)); Peeker(c, 'c')
#generate test values
x1TVals=[i[0] for i in itertools.product(BitVals, repeat=len(BitVals))]
x2TVals=[i[1] for i in itertools.product(BitVals, repeat=len(BitVals))]
DUT=HalfAdder(x1, x2, s, c)
def HalfAdder_TB():
"""
myHDL only Testbench for module "HalfAdder"
"""
@instance
def stimules():
for i, j in zip(x1TVals, x2TVals):
x1.next=i; x2.next=j
yield delay(1)
raise StopSimulation()
return instances()
sim=Simulation(DUT, HalfAdder_TB(), *Peeker.instances()).run()
```
```python
Peeker.to_wavedrom('x1', 'x2', 's', 'c')
```
<div></div>
```python
HalfAdderData=Peeker.to_dataframe()
HalfAdderData=HalfAdderData[['x1', 'x2', 's', 'c']]
HalfAdderData
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>x1</th>
<th>x2</th>
<th>s</th>
<th>c</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<th>1</th>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>2</th>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>3</th>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
```python
HalfAdderData['sCheck']=HalfAdderData.apply(lambda row: row['x1']^row['x2'], axis=1)
HalfAdderData['cCheck']=HalfAdderData.apply(lambda row: row['x1']&row['x2'], axis=1)
HalfAdderData
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>x1</th>
<th>x2</th>
<th>s</th>
<th>c</th>
<th>sCheck</th>
<th>cCheck</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<th>1</th>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>2</th>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>3</th>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
```python
SumCheck=(HalfAdderData['s']==HalfAdderData['sCheck']).all()
CarryCheck=(HalfAdderData['c']==HalfAdderData['cCheck']).all()
print(f'Sum Result Check: {SumCheck}; Carry Result Check: {CarryCheck}')
```
Sum Result Check: True; Carry Result Check: True
## Verilog Code
```python
DUT.convert()
VerilogTextReader('HalfAdder');
```
***Verilog modual from HalfAdder.v***
// File: HalfAdder.v
// Generated by MyHDL 0.10
// Date: Tue Aug 21 12:52:14 2018
`timescale 1ns/10ps
module HalfAdder (
x1,
x2,
s,
c
);
// Half Adder
// Input:
// x1(bool): bit signal to be added
// x2(bool): bit signal to be added
//
// Output:
// s(bool): Half Adder Sum
// c(bool): Half Adder Carry
input x1;
input x2;
output s;
wire s;
output c;
wire c;
assign s = (x1 ^ x2);
assign c = (x1 & x2);
endmodule
## Verilog Testbench
```python
#generate test values
x1TVals=[i[0] for i in itertools.product(BitVals, repeat=len(BitVals))]
x2TVals=[i[1] for i in itertools.product(BitVals, repeat=len(BitVals))]
#create single value representation of Test Inputs
x1TVal=intbv(int(''.join([str(i) for i in x1TVals]), 2))[len(x1TVals):]
x2TVal=intbv(int(''.join([str(i) for i in x2TVals]), 2))[len(x2TVals):]
```
```python
print(f'x1Test: {x1TVals}, {x1TVal}, {[int(i) for i in x1TVal]}')
print(f'x2Test: {x2TVals}, {x2TVal}, {[int(i) for i in x2TVal]}')
```
x1Test: [0, 0, 1, 1], 3, [0, 0, 1, 1]
x2Test: [0, 1, 0, 1], 5, [0, 1, 0, 1]
```python
@block
def HalfAdder_TBV():
"""
myHDL -> Verilog Testbench for module "HalfAdder"
"""
x1=Signal(bool(0))
x2=Signal(bool(0))
s=Signal(bool(0))
c=Signal(bool(0))
#test stimuli
x1TVals=Signal(x1TVal)
x2TVals=Signal(x2TVal)
@always_comb
def print_data():
print(x1, x2, s, c)
DUT=HalfAdder(x1, x2, s, c)
@instance
def stimules():
for i in range(len(x1TVal)):
x1.next=x1TVals[i]; x2.next=x2TVals[i]
yield delay(1)
raise StopSimulation()
return instances()
TB=HalfAdder_TBV()
TB.convert(hdl="Verilog", initial_values=True)
VerilogTextReader('HalfAdder_TBV');
```
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
***Verilog modual from HalfAdder_TBV.v***
// File: HalfAdder_TBV.v
// Generated by MyHDL 0.10
// Date: Tue Aug 21 12:52:14 2018
`timescale 1ns/10ps
module HalfAdder_TBV (
);
// myHDL -> Verilog Testbench for module "HalfAdder"
reg x1 = 0;
reg x2 = 0;
wire s;
wire c;
wire [3:0] x1TVals;
wire [3:0] x2TVals;
assign x1TVals = 4'd3;
assign x2TVals = 4'd5;
always @(s, x2, c, x1) begin: HALFADDER_TBV_PRINT_DATA
$write("%h", x1);
$write(" ");
$write("%h", x2);
$write(" ");
$write("%h", s);
$write(" ");
$write("%h", c);
$write("\n");
end
assign s = (x1 ^ x2);
assign c = (x1 & x2);
initial begin: HALFADDER_TBV_STIMULES
integer i;
for (i=0; i<4; i=i+1) begin
x1 <= x1TVals[i];
x2 <= x2TVals[i];
# 1;
end
$finish;
end
endmodule
/home/iridium/anaconda3/lib/python3.6/site-packages/myhdl/conversion/_toVerilog.py:349: ToVerilogWarning: Signal is not driven: x1TVals
category=ToVerilogWarning
/home/iridium/anaconda3/lib/python3.6/site-packages/myhdl/conversion/_toVerilog.py:349: ToVerilogWarning: Signal is not driven: x2TVals
category=ToVerilogWarning
# Full Adder From Exspresion
## myHDL Code
```python
@block
def FullAdder(x1, x2, cin, s, c):
"""
Full Adder 2bit+1 input from exspresion
Input:
x1(bool): bit signal to be added
x2(bool): bit signal to be added
cin(bool): carry in bit signal
Output:
s(bool): Full Adder Sum
c(bool): Full Adder Carry
"""
@always_comb
def logic():
s.next=x1^x2^cin
c.next=(x1&x2) | (x1&cin) | (x2&cin)
return instances()
```
## myHDL Testing
```python
Peeker.clear()
x1=Signal(bool(0)); Peeker(x1, 'x1')
x2=Signal(bool(0)); Peeker(x2, 'x2')
cin=Signal(bool(0)); Peeker(cin, 'cin')
s=Signal(bool(0)); Peeker(s, 's')
c=Signal(bool(0)); Peeker(c, 'c')
#generate test values
x1TVals=[i[0] for i in itertools.product(BitVals, repeat=len(BitVals)+1)]
x2TVals=[i[1] for i in itertools.product(BitVals, repeat=len(BitVals)+1)]
cinTVals=[i[2] for i in itertools.product(BitVals, repeat=len(BitVals)+1)]
DUT=FullAdder(x1, x2, cin, s, c)
def FullAdder_TB():
"""
myHDL only Testbench for module "FullAdder"
"""
@instance
def stimules():
for i, j, k in zip(x1TVals, x2TVals, cinTVals):
x1.next=i; x2.next=j; cin.next=k
yield delay(1)
raise StopSimulation()
return instances()
sim=Simulation(DUT, FullAdder_TB(), *Peeker.instances()).run()
```
```python
Peeker.to_wavedrom('x1', 'x2', 'cin', 's', 'c')
```
<div></div>
```python
FullAdderData=Peeker.to_dataframe()
FullAdderData=FullAdderData[['x1', 'x2', 'cin', 's', 'c']]
FullAdderData
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>x1</th>
<th>x2</th>
<th>cin</th>
<th>s</th>
<th>c</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<th>1</th>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>2</th>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>3</th>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<th>4</th>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>5</th>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<th>6</th>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<th>7</th>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
```python
FullAdderData['sCheck']=FullAdderData.apply(lambda row: row['x1']^row['x2']^row['cin'], axis=1)
FullAdderData['cCheck']=FullAdderData.apply(lambda row: (row['x1']&row['x2'])|(row['cin']*(row['x1']^row['x2'])), axis=1)
FullAdderData
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>x1</th>
<th>x2</th>
<th>cin</th>
<th>s</th>
<th>c</th>
<th>sCheck</th>
<th>cCheck</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<th>1</th>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>2</th>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>3</th>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<th>4</th>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>5</th>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<th>6</th>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<th>7</th>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
```python
SumCheck=(FullAdderData['s']==FullAdderData['sCheck']).all()
CarryCheck=(FullAdderData['c']==FullAdderData['cCheck']).all()
print(f'Sum Result Check: {SumCheck}; Carry Result Check: {CarryCheck}')
```
Sum Result Check: True; Carry Result Check: True
## Verilog Code
```python
DUT.convert()
VerilogTextReader('FullAdder');
```
***Verilog modual from FullAdder.v***
// File: FullAdder.v
// Generated by MyHDL 0.10
// Date: Tue Aug 21 12:52:15 2018
`timescale 1ns/10ps
module FullAdder (
x1,
x2,
cin,
s,
c
);
// Full Adder 2bit+1 input from exspresion
// Input:
// x1(bool): bit signal to be added
// x2(bool): bit signal to be added
// cin(bool): carry in bit signal
//
// Output:
// s(bool): Full Adder Sum
// c(bool): Full Adder Carry
input x1;
input x2;
input cin;
output s;
wire s;
output c;
wire c;
assign s = ((x1 ^ x2) ^ cin);
assign c = (((x1 & x2) | (x1 & cin)) | (x2 & cin));
endmodule
## Verilog Testbench
```python
#generate test values
x1TVals=[i[0] for i in itertools.product(BitVals, repeat=len(BitVals)+1)]
x2TVals=[i[1] for i in itertools.product(BitVals, repeat=len(BitVals)+1)]
cinTVals=[i[2] for i in itertools.product(BitVals, repeat=len(BitVals)+1)]
#create single value representation of Test Inputs
x1TVal=intbv(int(''.join([str(i) for i in x1TVals]), 2))[len(x1TVals):]
x2TVal=intbv(int(''.join([str(i) for i in x2TVals]), 2))[len(x2TVals):]
cinTVal=intbv(int(''.join([str(i) for i in cinTVals]), 2))[len(cinTVals):]
```
```python
print(f'x1Test: {x1TVals}, {x1TVal}, {[int(i) for i in x1TVal]}')
print(f'x2Test: {x2TVals}, {x2TVal}, {[int(i) for i in x2TVal]}')
print(f'cinTest: {cinTVals}, {cinTVal}, {[int(i) for i in cinTVal]}')
```
x1Test: [0, 0, 0, 0, 1, 1, 1, 1], 0f, [0, 0, 0, 0, 1, 1, 1, 1]
x2Test: [0, 0, 1, 1, 0, 0, 1, 1], 33, [0, 0, 1, 1, 0, 0, 1, 1]
cinTest: [0, 1, 0, 1, 0, 1, 0, 1], 55, [0, 1, 0, 1, 0, 1, 0, 1]
```python
@block
def FullAdder_TBV():
"""
myHDL -> Verilog Testbench for module "FullAdder"
"""
x1=Signal(bool(0))
x2=Signal(bool(0))
cin=Signal(bool(0))
s=Signal(bool(0))
c=Signal(bool(0))
#test stimuli
x1TVals=Signal(x1TVal)
x2TVals=Signal(x2TVal)
cinTVals=Signal(cinTVal)
@always_comb
def print_data():
print(x1, x2, cin, s, c)
DUT=FullAdder(x1, x2, cin, s, c)
@instance
def stimules():
for i in range(len(x1TVal)):
x1.next=x1TVals[i]; x2.next=x2TVals[i]; cin.next=cinTVals[i]
yield delay(1)
raise StopSimulation()
return instances()
TB=FullAdder_TBV()
TB.convert(hdl="Verilog", initial_values=True)
VerilogTextReader('FullAdder_TBV');
```
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
***Verilog modual from FullAdder_TBV.v***
// File: FullAdder_TBV.v
// Generated by MyHDL 0.10
// Date: Tue Aug 21 12:52:16 2018
`timescale 1ns/10ps
module FullAdder_TBV (
);
// myHDL -> Verilog Testbench for module "FullAdder"
reg x1 = 0;
reg x2 = 0;
wire s;
wire c;
wire [7:0] x1TVals;
wire [7:0] x2TVals;
reg cin = 0;
wire [7:0] cinTVals;
assign x1TVals = 8'd15;
assign x2TVals = 8'd51;
assign cinTVals = 8'd85;
always @(x2, c, s, cin, x1) begin: FULLADDER_TBV_PRINT_DATA
$write("%h", x1);
$write(" ");
$write("%h", x2);
$write(" ");
$write("%h", cin);
$write(" ");
$write("%h", s);
$write(" ");
$write("%h", c);
$write("\n");
end
assign s = ((x1 ^ x2) ^ cin);
assign c = (((x1 & x2) | (x1 & cin)) | (x2 & cin));
initial begin: FULLADDER_TBV_STIMULES
integer i;
for (i=0; i<8; i=i+1) begin
x1 <= x1TVals[i];
x2 <= x2TVals[i];
cin <= cinTVals[i];
# 1;
end
$finish;
end
endmodule
/home/iridium/anaconda3/lib/python3.6/site-packages/myhdl/conversion/_toVerilog.py:349: ToVerilogWarning: Signal is not driven: x1TVals
category=ToVerilogWarning
/home/iridium/anaconda3/lib/python3.6/site-packages/myhdl/conversion/_toVerilog.py:349: ToVerilogWarning: Signal is not driven: x2TVals
category=ToVerilogWarning
/home/iridium/anaconda3/lib/python3.6/site-packages/myhdl/conversion/_toVerilog.py:349: ToVerilogWarning: Signal is not driven: cinTVals
category=ToVerilogWarning
# Full Adder via HalfAdders
## myHDL Code
```python
@block
def FullAdderViaHAs(x1, x2, cin, s, c):
"""
Full Adder 2bit+1 input from Half Adders
Input:
x1(bool): bit signal to be added
x2(bool): bit signal to be added
cin(bool): carry in bit signal
Output:
s(bool): Full Adder Sum
c(bool): Full Adder Carry
"""
#create ouput wires from first HA (HA1) to next HA and
#`CarryLogic`
s_HA1HA2=Signal(bool(0)); c_HA1CL=Signal(bool(0))
#create first HA and wire it
HA1_x1x2=HalfAdder(x1=x1, x2=x2, s=s_HA1HA2, c=c_HA1CL)
#create output wire for seconed HA (HA2) to `CarryLogic`
c_HA2CL=Signal(bool(0))
HA2_HA1cin=HalfAdder(x1=cin, x2=s_HA1HA2, s=s, c=c_HA2CL)
@always_comb
def CarryLogic():
c.next= c_HA1CL|c_HA2CL
return instances()
```
## myHDL Testing
```python
Peeker.clear()
x1=Signal(bool(0)); Peeker(x1, 'x1')
x2=Signal(bool(0)); Peeker(x2, 'x2')
cin=Signal(bool(0)); Peeker(cin, 'cin')
s=Signal(bool(0)); Peeker(s, 's')
c=Signal(bool(0)); Peeker(c, 'c')
#generate test values
x1TVals=[i[0] for i in itertools.product(BitVals, repeat=len(BitVals)+1)]
x2TVals=[i[1] for i in itertools.product(BitVals, repeat=len(BitVals)+1)]
cinTVals=[i[2] for i in itertools.product(BitVals, repeat=len(BitVals)+1)]
DUT=FullAdderViaHAs(x1, x2, cin, s, c)
def FullAdderViaHAs_TB():
"""
myHDL only Testbench for module "FullAdderViaHAs"
"""
@instance
def stimules():
for i, j, k in zip(x1TVals, x2TVals, cinTVals):
x1.next=i; x2.next=j; cin.next=k
yield delay(1)
raise StopSimulation()
return instances()
sim=Simulation(DUT, FullAdder_TB(), *Peeker.instances()).run()
```
```python
Peeker.to_wavedrom('x1', 'x2', 'cin', 's', 'c')
```
<div></div>
```python
FullAdderHAData=Peeker.to_dataframe()
FullAdderHAData=FullAdderHAData[['x1', 'x2', 'cin', 's', 'c']]
FullAdderHAData
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>x1</th>
<th>x2</th>
<th>cin</th>
<th>s</th>
<th>c</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<th>1</th>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>2</th>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>3</th>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<th>4</th>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>5</th>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<th>6</th>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<th>7</th>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
```python
FullAdderHAData['sCheck']=FullAdderHAData.apply(lambda row: row['x1']^row['x2']^row['cin'], axis=1)
FullAdderHAData['cCheck']=FullAdderHAData.apply(lambda row: (row['x1']&row['x2'])|(row['cin']*(row['x1']^row['x2'])), axis=1)
FullAdderHAData
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>x1</th>
<th>x2</th>
<th>cin</th>
<th>s</th>
<th>c</th>
<th>sCheck</th>
<th>cCheck</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<th>1</th>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>2</th>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>3</th>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<th>4</th>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>5</th>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<th>6</th>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<th>7</th>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
```python
SumCheck=(FullAdderHAData['s']==FullAdderHAData['sCheck']).all()
CarryCheck=(FullAdderHAData['c']==FullAdderHAData['cCheck']).all()
print(f'Sum Result Check: {SumCheck}; Carry Result Check: {CarryCheck}')
```
Sum Result Check: True; Carry Result Check: True
```python
(FullAdderData==FullAdderHAData).all()
```
x1 True
x2 True
cin True
s True
c True
sCheck True
cCheck True
dtype: bool
## Verilog Code
```python
DUT.convert()
VerilogTextReader('FullAdderViaHAs');
```
***Verilog modual from FullAdderViaHAs.v***
// File: FullAdderViaHAs.v
// Generated by MyHDL 0.10
// Date: Tue Aug 21 12:52:18 2018
`timescale 1ns/10ps
module FullAdderViaHAs (
x1,
x2,
cin,
s,
c
);
// Full Adder 2bit+1 input from Half Adders
// Input:
// x1(bool): bit signal to be added
// x2(bool): bit signal to be added
// cin(bool): carry in bit signal
//
// Output:
// s(bool): Full Adder Sum
// c(bool): Full Adder Carry
input x1;
input x2;
input cin;
output s;
wire s;
output c;
wire c;
wire s_HA1HA2;
wire c_HA1CL;
wire c_HA2CL;
assign s_HA1HA2 = (x1 ^ x2);
assign c_HA1CL = (x1 & x2);
assign s = (cin ^ s_HA1HA2);
assign c_HA2CL = (cin & s_HA1HA2);
assign c = (c_HA1CL | c_HA2CL);
endmodule
## Verilog Testbench
```python
#generate test values
x1TVals=[i[0] for i in itertools.product(BitVals, repeat=len(BitVals)+1)]
x2TVals=[i[1] for i in itertools.product(BitVals, repeat=len(BitVals)+1)]
cinTVals=[i[2] for i in itertools.product(BitVals, repeat=len(BitVals)+1)]
#create single value representation of Test Inputs
x1TVal=intbv(int(''.join([str(i) for i in x1TVals]), 2))[len(x1TVals):]
x2TVal=intbv(int(''.join([str(i) for i in x2TVals]), 2))[len(x2TVals):]
cinTVal=intbv(int(''.join([str(i) for i in cinTVals]), 2))[len(cinTVals):]
```
```python
print(f'x1Test: {x1TVals}, {x1TVal}, {[int(i) for i in x1TVal]}')
print(f'x2Test: {x2TVals}, {x2TVal}, {[int(i) for i in x2TVal]}')
print(f'cinTest: {cinTVals}, {cinTVal}, {[int(i) for i in cinTVal]}')
```
x1Test: [0, 0, 0, 0, 1, 1, 1, 1], 0f, [0, 0, 0, 0, 1, 1, 1, 1]
x2Test: [0, 0, 1, 1, 0, 0, 1, 1], 33, [0, 0, 1, 1, 0, 0, 1, 1]
cinTest: [0, 1, 0, 1, 0, 1, 0, 1], 55, [0, 1, 0, 1, 0, 1, 0, 1]
```python
@block
def FullAdderViaHAs_TBV():
"""
myHDL -> Verilog Testbench for module "FullAdderViaHAs"
"""
x1=Signal(bool(0))
x2=Signal(bool(0))
cin=Signal(bool(0))
s=Signal(bool(0))
c=Signal(bool(0))
#test stimuli
x1TVals=Signal(x1TVal)
x2TVals=Signal(x2TVal)
cinTVals=Signal(cinTVal)
@always_comb
def print_data():
print(x1, x2, cin, s, c)
DUT=FullAdderViaHAs(x1, x2, cin, s, c)
@instance
def stimules():
for i in range(len(x1TVal)):
x1.next=x1TVals[i]; x2.next=x2TVals[i]; cin.next=cinTVals[i]
yield delay(1)
raise StopSimulation()
return instances()
TB=FullAdderViaHAs_TBV()
TB.convert(hdl="Verilog", initial_values=True)
VerilogTextReader('FullAdderViaHAs_TBV');
```
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
***Verilog modual from FullAdderViaHAs_TBV.v***
// File: FullAdderViaHAs_TBV.v
// Generated by MyHDL 0.10
// Date: Tue Aug 21 12:52:20 2018
`timescale 1ns/10ps
module FullAdderViaHAs_TBV (
);
// myHDL -> Verilog Testbench for module "FullAdderViaHAs"
reg x1 = 0;
reg x2 = 0;
wire s;
wire c;
wire [7:0] x1TVals;
wire [7:0] x2TVals;
reg cin = 0;
wire [7:0] cinTVals;
wire FullAdderViaHAs0_0_s_HA1HA2;
wire FullAdderViaHAs0_0_c_HA1CL;
wire FullAdderViaHAs0_0_c_HA2CL;
assign x1TVals = 8'd15;
assign x2TVals = 8'd51;
assign cinTVals = 8'd85;
always @(x2, c, s, cin, x1) begin: FULLADDERVIAHAS_TBV_PRINT_DATA
$write("%h", x1);
$write(" ");
$write("%h", x2);
$write(" ");
$write("%h", cin);
$write(" ");
$write("%h", s);
$write(" ");
$write("%h", c);
$write("\n");
end
assign FullAdderViaHAs0_0_s_HA1HA2 = (x1 ^ x2);
assign FullAdderViaHAs0_0_c_HA1CL = (x1 & x2);
assign s = (cin ^ FullAdderViaHAs0_0_s_HA1HA2);
assign FullAdderViaHAs0_0_c_HA2CL = (cin & FullAdderViaHAs0_0_s_HA1HA2);
assign c = (FullAdderViaHAs0_0_c_HA1CL | FullAdderViaHAs0_0_c_HA2CL);
initial begin: FULLADDERVIAHAS_TBV_STIMULES
integer i;
for (i=0; i<8; i=i+1) begin
x1 <= x1TVals[i];
x2 <= x2TVals[i];
cin <= cinTVals[i];
# 1;
end
$finish;
end
endmodule
/home/iridium/anaconda3/lib/python3.6/site-packages/myhdl/conversion/_toVerilog.py:349: ToVerilogWarning: Signal is not driven: x1TVals
category=ToVerilogWarning
/home/iridium/anaconda3/lib/python3.6/site-packages/myhdl/conversion/_toVerilog.py:349: ToVerilogWarning: Signal is not driven: x2TVals
category=ToVerilogWarning
/home/iridium/anaconda3/lib/python3.6/site-packages/myhdl/conversion/_toVerilog.py:349: ToVerilogWarning: Signal is not driven: cinTVals
category=ToVerilogWarning
# 4 Bit Ripple Carry
## myHDL Code
```python
@block
def RippleCarry4Bit(X1, X2, cin, S, c):
"""
4 Bit Ripple Carray Adder
Input:
Output:
"""
S_i = [Signal(bool(0)) for _ in range(len(S))] # Sum bit for each stage.
#create intercontect wire between FA0 and FA1 and intialze FA0 and wire up
c_FA0FA1=Signal(bool(0))
FA0=FullAdder(x1=X1(0), x2=X2(0), cin=cin, s=S_i[0], c=c_FA0FA1)
c_FA1FA2=Signal(bool(0))
FA1=FullAdder(x1=X1(1), x2=X2(1), cin=c_FA0FA1, s=S_i[1], c=c_FA1FA2)
c_FA2FA3=Signal(bool(0))
FA2=FullAdder(x1=X1(2), x2=X2(2), cin=c_FA1FA2, s=S_i[2], c=c_FA2FA3)
FA3=FullAdder(x1=X1(3), x2=X2(3), cin=c_FA2FA3, s=S_i[3], c=c)
#concat bus wires to single bitvec wire
@always_comb
def ConCatSum():
S.next=concat(S_i[3], S_i[2], S_i[1], S_i[0])
return instances()
```
## myHDL Testing
```python
BitSize=4
np.random.seed(12)
X1TVals=np.random.randint(0, 2**BitSize, 2**BitSize)
X2TVals=np.random.randint(0, 2**BitSize, 2**BitSize)
cinTVals=np.random.randint(0,2,2**BitSize)
print(X1TVals)
print(X2TVals)
print(cinTVals)
```
[11 11 6 13 1 2 3 3 12 0 6 1 4 5 13 9]
[ 2 11 6 10 0 5 8 12 13 2 9 3 14 4 3 1]
[0 1 1 0 0 0 0 0 0 0 1 1 1 1 0 0]
```python
Peeker.clear()
X1=Signal(intbv(0)[BitSize:]); Peeker(X1, 'X1')
X2=Signal(intbv(0)[BitSize:]); Peeker(X2, 'X2')
cin=Signal(bool(0)); Peeker(cin, 'cin')
S=Signal(intbv(0)[BitSize:]); Peeker(S, 'S')
c=Signal(bool(0)); Peeker(c, 'c')
DUT = RippleCarry4Bit(X1=X1, X2=X2, cin=cin, S=S, c=c)
def RippleCarry4Bit_TB():
@instance
def stimules():
for i in range(len(X1TVals)):
X1.next=int(X1TVals[i])
X2.next=int(X2TVals[i])
cin.next=int(cinTVals[i])
yield delay(1)
raise StopSimulation()
return instances()
sim=Simulation(DUT, RippleCarry4Bit_TB(), *Peeker.instances()).run()
```
```python
Peeker.to_wavedrom('cin', 'X1', 'X2', 'S', 'c')
```
<div></div>
```python
RC4BData=Peeker.to_dataframe()
RC4BData=RC4BData[['cin', 'X1', 'X2', 'S', 'c']]
RC4BData
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>cin</th>
<th>X1</th>
<th>X2</th>
<th>S</th>
<th>c</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>0</td>
<td>11</td>
<td>2</td>
<td>13</td>
<td>0</td>
</tr>
<tr>
<th>1</th>
<td>1</td>
<td>11</td>
<td>11</td>
<td>7</td>
<td>1</td>
</tr>
<tr>
<th>2</th>
<td>1</td>
<td>6</td>
<td>6</td>
<td>13</td>
<td>0</td>
</tr>
<tr>
<th>3</th>
<td>0</td>
<td>13</td>
<td>10</td>
<td>7</td>
<td>1</td>
</tr>
<tr>
<th>4</th>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>5</th>
<td>0</td>
<td>2</td>
<td>5</td>
<td>7</td>
<td>0</td>
</tr>
<tr>
<th>6</th>
<td>0</td>
<td>3</td>
<td>8</td>
<td>11</td>
<td>0</td>
</tr>
<tr>
<th>7</th>
<td>0</td>
<td>3</td>
<td>12</td>
<td>15</td>
<td>0</td>
</tr>
<tr>
<th>8</th>
<td>0</td>
<td>12</td>
<td>13</td>
<td>9</td>
<td>1</td>
</tr>
<tr>
<th>9</th>
<td>0</td>
<td>0</td>
<td>2</td>
<td>2</td>
<td>0</td>
</tr>
<tr>
<th>10</th>
<td>1</td>
<td>6</td>
<td>9</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<th>11</th>
<td>1</td>
<td>1</td>
<td>3</td>
<td>5</td>
<td>0</td>
</tr>
<tr>
<th>12</th>
<td>1</td>
<td>4</td>
<td>14</td>
<td>3</td>
<td>1</td>
</tr>
<tr>
<th>13</th>
<td>1</td>
<td>5</td>
<td>4</td>
<td>10</td>
<td>0</td>
</tr>
<tr>
<th>14</th>
<td>0</td>
<td>13</td>
<td>3</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<th>15</th>
<td>0</td>
<td>9</td>
<td>1</td>
<td>10</td>
<td>0</td>
</tr>
</tbody>
</table>
</div>
```python
def RC4B_SCheck(cin, X1, X2):
S=cin+X1+X2
if S<16:
return S
else:
return S-16
def RC4B_cCheck(cin, X1, X2):
S=cin+X1+X2
if S<16:
return 0
else:
return 1
RC4BData['SCheck']=RC4BData.apply(lambda row: RC4B_SCheck(row['cin'], row['X1'], row['X2']), axis=1)
RC4BData['cCheck']=RC4BData.apply(lambda row: RC4B_cCheck(row['cin'], row['X1'], row['X2']), axis=1)
RC4BData
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>cin</th>
<th>X1</th>
<th>X2</th>
<th>S</th>
<th>c</th>
<th>SCheck</th>
<th>cCheck</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>0</td>
<td>11</td>
<td>2</td>
<td>13</td>
<td>0</td>
<td>13</td>
<td>0</td>
</tr>
<tr>
<th>1</th>
<td>1</td>
<td>11</td>
<td>11</td>
<td>7</td>
<td>1</td>
<td>7</td>
<td>1</td>
</tr>
<tr>
<th>2</th>
<td>1</td>
<td>6</td>
<td>6</td>
<td>13</td>
<td>0</td>
<td>13</td>
<td>0</td>
</tr>
<tr>
<th>3</th>
<td>0</td>
<td>13</td>
<td>10</td>
<td>7</td>
<td>1</td>
<td>7</td>
<td>1</td>
</tr>
<tr>
<th>4</th>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>5</th>
<td>0</td>
<td>2</td>
<td>5</td>
<td>7</td>
<td>0</td>
<td>7</td>
<td>0</td>
</tr>
<tr>
<th>6</th>
<td>0</td>
<td>3</td>
<td>8</td>
<td>11</td>
<td>0</td>
<td>11</td>
<td>0</td>
</tr>
<tr>
<th>7</th>
<td>0</td>
<td>3</td>
<td>12</td>
<td>15</td>
<td>0</td>
<td>15</td>
<td>0</td>
</tr>
<tr>
<th>8</th>
<td>0</td>
<td>12</td>
<td>13</td>
<td>9</td>
<td>1</td>
<td>9</td>
<td>1</td>
</tr>
<tr>
<th>9</th>
<td>0</td>
<td>0</td>
<td>2</td>
<td>2</td>
<td>0</td>
<td>2</td>
<td>0</td>
</tr>
<tr>
<th>10</th>
<td>1</td>
<td>6</td>
<td>9</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<th>11</th>
<td>1</td>
<td>1</td>
<td>3</td>
<td>5</td>
<td>0</td>
<td>5</td>
<td>0</td>
</tr>
<tr>
<th>12</th>
<td>1</td>
<td>4</td>
<td>14</td>
<td>3</td>
<td>1</td>
<td>3</td>
<td>1</td>
</tr>
<tr>
<th>13</th>
<td>1</td>
<td>5</td>
<td>4</td>
<td>10</td>
<td>0</td>
<td>10</td>
<td>0</td>
</tr>
<tr>
<th>14</th>
<td>0</td>
<td>13</td>
<td>3</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<th>15</th>
<td>0</td>
<td>9</td>
<td>1</td>
<td>10</td>
<td>0</td>
<td>10</td>
<td>0</td>
</tr>
</tbody>
</table>
</div>
```python
SumCheck=(RC4BData['S']==RC4BData['SCheck']).all()
CarryCheck=(RC4BData['c']==RC4BData['cCheck']).all()
print(f'Sum Result Check: {SumCheck}; Carry Result Check: {CarryCheck}')
```
Sum Result Check: True; Carry Result Check: True
```python
DUT.convert()
VerilogTextReader('RippleCarry4Bit');
```
***Verilog modual from RippleCarry4Bit.v***
// File: RippleCarry4Bit.v
// Generated by MyHDL 0.10
// Date: Tue Aug 21 12:52:22 2018
`timescale 1ns/10ps
module RippleCarry4Bit (
X1,
X2,
cin,
S,
c
);
// 4 Bit Ripple Carray Adder
// Input:
// Output:
input [3:0] X1;
input [3:0] X2;
input cin;
output [3:0] S;
wire [3:0] S;
output c;
wire c;
wire c_FA0FA1;
wire FullAdder1_0_c;
wire FullAdder2_c;
wire S_i [0:4-1];
assign S_i[0] = ((X1[0] ^ X2[0]) ^ cin);
assign c_FA0FA1 = (((X1[0] & X2[0]) | (X1[0] & cin)) | (X2[0] & cin));
assign S_i[1] = ((X1[1] ^ X2[1]) ^ c_FA0FA1);
assign FullAdder1_0_c = (((X1[1] & X2[1]) | (X1[1] & c_FA0FA1)) | (X2[1] & c_FA0FA1));
assign S_i[2] = ((X1[2] ^ X2[2]) ^ FullAdder1_0_c);
assign FullAdder2_c = (((X1[2] & X2[2]) | (X1[2] & FullAdder1_0_c)) | (X2[2] & FullAdder1_0_c));
assign S_i[3] = ((X1[3] ^ X2[3]) ^ FullAdder2_c);
assign c = (((X1[3] & X2[3]) | (X1[3] & FullAdder2_c)) | (X2[3] & FullAdder2_c));
assign S = {S_i[3], S_i[2], S_i[1], S_i[0]};
endmodule
## Verilog Testbench
### Conversion Issue
Values are not beeing set to `X1TVals` and `X1TVals` in `RippleCarry4Bit_TBV` thus the running the simultion results in High **Z** values for each time stamp
```python
X1TVal=[intbv(int(i))[BitSize:] for i in X1TVals]
X2TVal=[intbv(int(i))[BitSize:] for i in X2TVals]
cinTVal=intbv(int(''.join([str(i) for i in cinTVals]), 2))[len(cinTVals):]
print(X1TVal)
print(X2TVal)
print(cinTVal)
```
[intbv(11), intbv(11), intbv(6), intbv(13), intbv(1), intbv(2), intbv(3), intbv(3), intbv(12), intbv(0), intbv(6), intbv(1), intbv(4), intbv(5), intbv(13), intbv(9)]
[intbv(2), intbv(11), intbv(6), intbv(10), intbv(0), intbv(5), intbv(8), intbv(12), intbv(13), intbv(2), intbv(9), intbv(3), intbv(14), intbv(4), intbv(3), intbv(1)]
603c
```python
@block
def RippleCarry4Bit_TBV():
"""
myHDL -> Verilog Testbench for module "FullAdderViaHAs"
"""
X1=Signal(intbv(0)[BitSize:])
X2=Signal(intbv(0)[BitSize:])
cin=Signal(bool(0))
S=Signal(intbv(0)[BitSize:])
c=Signal(bool(0))
#test stimuli
X1TVals=[Signal(i) for i in X1TVal]
X2TVals=[Signal(i) for i in X2TVal]
cinTVals=Signal(cinTVal)
@always_comb
def print_data():
print(X1, X2, cin, S, c)
DUT=RippleCarry4Bit(X1=X1, X2=X2, cin=cin, S=S, c=c)
@instance
def stimules():
for i in range(len(X1TVals)):
X1.next=X1TVals[i]
X2.next=X2TVals[i]
cin.next=cinTVals[i]
yield delay(1)
raise StopSimulation()
return instances()
TB=RippleCarry4Bit_TBV()
TB.convert(hdl="Verilog", initial_values=True)
VerilogTextReader('RippleCarry4Bit_TBV');
```
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
***Verilog modual from RippleCarry4Bit_TBV.v***
// File: RippleCarry4Bit_TBV.v
// Generated by MyHDL 0.10
// Date: Tue Aug 21 12:52:25 2018
`timescale 1ns/10ps
module RippleCarry4Bit_TBV (
);
// myHDL -> Verilog Testbench for module "FullAdderViaHAs"
wire [3:0] S;
wire c;
reg cin = 0;
wire [15:0] cinTVals;
reg [3:0] X1 = 0;
reg [3:0] X2 = 0;
wire RippleCarry4Bit0_0_c_FA0FA1;
wire RippleCarry4Bit0_0_FullAdder1_0_1_c;
wire RippleCarry4Bit0_0_FullAdder2_0_c;
wire [3:0] X1TVals [0:16-1];
wire [3:0] X2TVals [0:16-1];
wire RippleCarry4Bit0_0_S_i [0:4-1];
assign cinTVals = 16'd24636;
always @(c, X1, cin, X2, S) begin: RIPPLECARRY4BIT_TBV_PRINT_DATA
$write("%h", X1);
$write(" ");
$write("%h", X2);
$write(" ");
$write("%h", cin);
$write(" ");
$write("%h", S);
$write(" ");
$write("%h", c);
$write("\n");
end
assign RippleCarry4Bit0_0_S_i[0] = ((X1[0] ^ X2[0]) ^ cin);
assign RippleCarry4Bit0_0_c_FA0FA1 = (((X1[0] & X2[0]) | (X1[0] & cin)) | (X2[0] & cin));
assign RippleCarry4Bit0_0_S_i[1] = ((X1[1] ^ X2[1]) ^ RippleCarry4Bit0_0_c_FA0FA1);
assign RippleCarry4Bit0_0_FullAdder1_0_1_c = (((X1[1] & X2[1]) | (X1[1] & RippleCarry4Bit0_0_c_FA0FA1)) | (X2[1] & RippleCarry4Bit0_0_c_FA0FA1));
assign RippleCarry4Bit0_0_S_i[2] = ((X1[2] ^ X2[2]) ^ RippleCarry4Bit0_0_FullAdder1_0_1_c);
assign RippleCarry4Bit0_0_FullAdder2_0_c = (((X1[2] & X2[2]) | (X1[2] & RippleCarry4Bit0_0_FullAdder1_0_1_c)) | (X2[2] & RippleCarry4Bit0_0_FullAdder1_0_1_c));
assign RippleCarry4Bit0_0_S_i[3] = ((X1[3] ^ X2[3]) ^ RippleCarry4Bit0_0_FullAdder2_0_c);
assign c = (((X1[3] & X2[3]) | (X1[3] & RippleCarry4Bit0_0_FullAdder2_0_c)) | (X2[3] & RippleCarry4Bit0_0_FullAdder2_0_c));
assign S = {RippleCarry4Bit0_0_S_i[3], RippleCarry4Bit0_0_S_i[2], RippleCarry4Bit0_0_S_i[1], RippleCarry4Bit0_0_S_i[0]};
initial begin: RIPPLECARRY4BIT_TBV_STIMULES
integer i;
for (i=0; i<16; i=i+1) begin
X1 <= X1TVals[i];
X2 <= X2TVals[i];
cin <= cinTVals[i];
# 1;
end
$finish;
end
endmodule
/home/iridium/anaconda3/lib/python3.6/site-packages/myhdl/conversion/_toVerilog.py:349: ToVerilogWarning: Signal is not driven: cinTVals
category=ToVerilogWarning
# N Bit Ripple Carray Adder
```python
@block
def RippleCarryNBit(X1, X2, cin, S, c):
"""
N Bit Ripple Carray Adder
Input:
Output:
"""
S_i = [Signal(bool(0)) for _ in range(len(S))] # Sum bit for each stage.
c_FAiFAj=[Signal(bool(0)) for _ in range(len(S)-1)]
FAStages=[]
for i in range(len(S)):
if i==0:
FAStages.append(FullAdder(x1=X1(i), x2=X2(i), cin=cin, s=S_i[i], c=c_FAiFAj[i]))
elif i<(len(S)-1):
FAStages.append(FullAdder(x1=X1(i), x2=X2(i), cin=c_FAiFAj[i-1], s=S_i[i], c=c_FAiFAj[i]))
else:
FAStages.append(FullAdder(x1=X1(i), x2=X2(i), cin=c_FAiFAj[i-1], s=S_i[i], c=c))
#concat bus wires to single bitvec wire
@always_comb
def ConCatSum():
S.next=concat(*reversed(S_i))
return instances()
```
## myHDL Testing
```python
BitSize=16
np.random.seed(12)
X1TVals=np.random.randint(0, 2**BitSize, 2**4)
X2TVals=np.random.randint(0, 2**BitSize, 2**4)
cinTVals=np.random.randint(0,2,2**4)
print(X1TVals)
print(X2TVals)
print(cinTVals)
```
[14155 38555 58758 19709 40177 36482 9475 63427 12108 61872 278 57393
16308 49029 20109 20953]
[41378 8651 9846 5194 63872 11637 17512 19660 48397 36946 57433 9507
4030 48228 4515 40353]
[0 1 1 0 0 0 0 0 0 0 1 1 1 1 0 0]
```python
Peeker.clear()
X1=Signal(intbv(0)[BitSize:]); Peeker(X1, 'X1')
X2=Signal(intbv(0)[BitSize:]); Peeker(X2, 'X2')
cin=Signal(bool(0)); Peeker(cin, 'cin')
S=Signal(intbv(0)[BitSize:]); Peeker(S, 'S')
c=Signal(bool(0)); Peeker(c, 'c')
DUT = RippleCarryNBit(X1=X1, X2=X2, cin=cin, S=S, c=c)
def RippleCarryNBit_TB():
@instance
def stimules():
for i in range(len(X1TVals)):
X1.next=int(X1TVals[i])
X2.next=int(X2TVals[i])
cin.next=int(cinTVals[i])
yield delay(1)
raise StopSimulation()
return instances()
sim=Simulation(DUT, RippleCarryNBit_TB(), *Peeker.instances()).run()
```
```python
Peeker.to_wavedrom('cin', 'X1', 'X2', 'S', 'c')
```
<div></div>
```python
RCNBData=Peeker.to_dataframe()
RCNBData=RCNBData[['cin', 'X1', 'X2', 'S', 'c']]
RCNBData
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>cin</th>
<th>X1</th>
<th>X2</th>
<th>S</th>
<th>c</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>0</td>
<td>14155</td>
<td>41378</td>
<td>55533</td>
<td>0</td>
</tr>
<tr>
<th>1</th>
<td>1</td>
<td>38555</td>
<td>8651</td>
<td>47207</td>
<td>0</td>
</tr>
<tr>
<th>2</th>
<td>1</td>
<td>58758</td>
<td>9846</td>
<td>3069</td>
<td>1</td>
</tr>
<tr>
<th>3</th>
<td>0</td>
<td>19709</td>
<td>5194</td>
<td>24903</td>
<td>0</td>
</tr>
<tr>
<th>4</th>
<td>0</td>
<td>40177</td>
<td>63872</td>
<td>38513</td>
<td>1</td>
</tr>
<tr>
<th>5</th>
<td>0</td>
<td>36482</td>
<td>11637</td>
<td>48119</td>
<td>0</td>
</tr>
<tr>
<th>6</th>
<td>0</td>
<td>9475</td>
<td>17512</td>
<td>26987</td>
<td>0</td>
</tr>
<tr>
<th>7</th>
<td>0</td>
<td>63427</td>
<td>19660</td>
<td>17551</td>
<td>1</td>
</tr>
<tr>
<th>8</th>
<td>0</td>
<td>12108</td>
<td>48397</td>
<td>60505</td>
<td>0</td>
</tr>
<tr>
<th>9</th>
<td>0</td>
<td>61872</td>
<td>36946</td>
<td>33282</td>
<td>1</td>
</tr>
<tr>
<th>10</th>
<td>1</td>
<td>278</td>
<td>57433</td>
<td>57712</td>
<td>0</td>
</tr>
<tr>
<th>11</th>
<td>1</td>
<td>57393</td>
<td>9507</td>
<td>1365</td>
<td>1</td>
</tr>
<tr>
<th>12</th>
<td>1</td>
<td>16308</td>
<td>4030</td>
<td>20339</td>
<td>0</td>
</tr>
<tr>
<th>13</th>
<td>1</td>
<td>49029</td>
<td>48228</td>
<td>31722</td>
<td>1</td>
</tr>
<tr>
<th>14</th>
<td>0</td>
<td>20109</td>
<td>4515</td>
<td>24624</td>
<td>0</td>
</tr>
<tr>
<th>15</th>
<td>0</td>
<td>20953</td>
<td>40353</td>
<td>61306</td>
<td>0</td>
</tr>
</tbody>
</table>
</div>
```python
def RCNB_SCheck(cin, X1, X2):
S=cin+X1+X2
if S<2**BitSize:
return S
else:
return S-(2**BitSize)
def RCNB_cCheck(cin, X1, X2):
S=cin+X1+X2
if S<2**BitSize:
return 0
else:
return 1
RCNBData['SCheck']=RCNBData.apply(lambda row: RCNB_SCheck(row['cin'], row['X1'], row['X2']), axis=1)
RCNBData['cCheck']=RCNBData.apply(lambda row: RCNB_cCheck(row['cin'], row['X1'], row['X2']), axis=1)
RCNBData
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>cin</th>
<th>X1</th>
<th>X2</th>
<th>S</th>
<th>c</th>
<th>SCheck</th>
<th>cCheck</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>0</td>
<td>14155</td>
<td>41378</td>
<td>55533</td>
<td>0</td>
<td>55533</td>
<td>0</td>
</tr>
<tr>
<th>1</th>
<td>1</td>
<td>38555</td>
<td>8651</td>
<td>47207</td>
<td>0</td>
<td>47207</td>
<td>0</td>
</tr>
<tr>
<th>2</th>
<td>1</td>
<td>58758</td>
<td>9846</td>
<td>3069</td>
<td>1</td>
<td>3069</td>
<td>1</td>
</tr>
<tr>
<th>3</th>
<td>0</td>
<td>19709</td>
<td>5194</td>
<td>24903</td>
<td>0</td>
<td>24903</td>
<td>0</td>
</tr>
<tr>
<th>4</th>
<td>0</td>
<td>40177</td>
<td>63872</td>
<td>38513</td>
<td>1</td>
<td>38513</td>
<td>1</td>
</tr>
<tr>
<th>5</th>
<td>0</td>
<td>36482</td>
<td>11637</td>
<td>48119</td>
<td>0</td>
<td>48119</td>
<td>0</td>
</tr>
<tr>
<th>6</th>
<td>0</td>
<td>9475</td>
<td>17512</td>
<td>26987</td>
<td>0</td>
<td>26987</td>
<td>0</td>
</tr>
<tr>
<th>7</th>
<td>0</td>
<td>63427</td>
<td>19660</td>
<td>17551</td>
<td>1</td>
<td>17551</td>
<td>1</td>
</tr>
<tr>
<th>8</th>
<td>0</td>
<td>12108</td>
<td>48397</td>
<td>60505</td>
<td>0</td>
<td>60505</td>
<td>0</td>
</tr>
<tr>
<th>9</th>
<td>0</td>
<td>61872</td>
<td>36946</td>
<td>33282</td>
<td>1</td>
<td>33282</td>
<td>1</td>
</tr>
<tr>
<th>10</th>
<td>1</td>
<td>278</td>
<td>57433</td>
<td>57712</td>
<td>0</td>
<td>57712</td>
<td>0</td>
</tr>
<tr>
<th>11</th>
<td>1</td>
<td>57393</td>
<td>9507</td>
<td>1365</td>
<td>1</td>
<td>1365</td>
<td>1</td>
</tr>
<tr>
<th>12</th>
<td>1</td>
<td>16308</td>
<td>4030</td>
<td>20339</td>
<td>0</td>
<td>20339</td>
<td>0</td>
</tr>
<tr>
<th>13</th>
<td>1</td>
<td>49029</td>
<td>48228</td>
<td>31722</td>
<td>1</td>
<td>31722</td>
<td>1</td>
</tr>
<tr>
<th>14</th>
<td>0</td>
<td>20109</td>
<td>4515</td>
<td>24624</td>
<td>0</td>
<td>24624</td>
<td>0</td>
</tr>
<tr>
<th>15</th>
<td>0</td>
<td>20953</td>
<td>40353</td>
<td>61306</td>
<td>0</td>
<td>61306</td>
<td>0</td>
</tr>
</tbody>
</table>
</div>
```python
SumCheck=(RCNBData['S']==RCNBData['SCheck']).all()
CarryCheck=(RCNBData['c']==RCNBData['cCheck']).all()
print(f'Sum Result Check: {SumCheck}; Carry Result Check: {CarryCheck}')
```
Sum Result Check: True; Carry Result Check: True
## Verilog Code
### Conversion Error
there is a conversion error in that the converter does not know how to translate as least the `*` unpacking operator in line 27 of `RippleCarryNBit`
```
S.next=ConcatSignal(*reversed(S_i))
```
There is also a high liklyhood that the converter also does not know how to handle the `reversed` operator
```python
#DUT.convert()
#VerilogTextReader('RippleCarryNBit');
```
## myHDL Testbench (ToDo)
To be done when Testbench conversion is improved
# Carry Look Ahead 4 Bit
https://www.geeksforgeeks.org/digital-logic-carry-look-ahead-adder/
http://faculty.kfupm.edu.sa/COE/abouh/Lesson3_3.pdf
## Stage One
$$p_i=A_i \oplus B_i$$
$$G_i=A_i \cdot B_i$$
### myHDL Code
```python
@block
def CLAS1(x1, x2, p, g):
"""
Carry Look Ahead Adder Stage One
Input:
x1(bool): x1 input
x2(bool): x2 input
Output:
p(bool):carry propagate
g(bool):carry generate
"""
@always_comb
def logic():
p.next=x1^x2
g.next=x1&x2
return instances()
```
### myHDL Testing
```python
Peeker.clear()
x1=Signal(bool(0)); Peeker(x1, 'x1')
x2=Signal(bool(0)); Peeker(x2, 'x2')
p=Signal(bool(0)); Peeker(p, 'p')
g=Signal(bool(0)); Peeker(g, 'g')
#generate test values
x1TVals=[i[0] for i in itertools.product(BitVals, repeat=len(BitVals))]
x2TVals=[i[1] for i in itertools.product(BitVals, repeat=len(BitVals))]
DUT=CLAS1(x1, x2, p, g)
def CLAS1_TB():
"""
myHDL only Testbench for module "CL"
"""
@instance
def stimules():
for i, j in zip(x1TVals, x2TVals):
x1.next=i; x2.next=j
yield delay(1)
raise StopSimulation()
return instances()
sim=Simulation(DUT, CLAS1_TB(), *Peeker.instances()).run()
```
```python
Peeker.to_wavedrom('x1', 'x2', 'p', 'g')
```
<div></div>
```python
CLAS1Data=Peeker.to_dataframe()
CLAS1Data=CLAS1Data[['x1', 'x2', 'p', 'g']]
CLAS1Data
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>x1</th>
<th>x2</th>
<th>p</th>
<th>g</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<th>1</th>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>2</th>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>3</th>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
```python
CLAS1Data['pCheck']=CLAS1Data.apply(lambda row: row['x1']^row['x2'], axis=1)
CLAS1Data['gCheck']=CLAS1Data.apply(lambda row: row['x1']&row['x2'], axis=1)
CLAS1Data
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>x1</th>
<th>x2</th>
<th>p</th>
<th>g</th>
<th>pCheck</th>
<th>gCheck</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<th>1</th>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>2</th>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<th>3</th>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
```python
pCheck=(CLAS1Data['p']==CLAS1Data['pCheck']).all()
gCheck=(CLAS1Data['g']==CLAS1Data['gCheck']).all()
print(f'p Result Check: {pCheck}; g Result Check: {gCheck}')
```
p Result Check: True; g Result Check: True
### Verilog Code
```python
DUT.convert()
VerilogTextReader('CLAS1');
```
***Verilog modual from CLAS1.v***
// File: CLAS1.v
// Generated by MyHDL 0.10
// Date: Tue Aug 21 12:52:29 2018
`timescale 1ns/10ps
module CLAS1 (
x1,
x2,
p,
g
);
// Carry Look Ahead Adder Stage One
// Input:
// x1(bool): x1 input
// x2(bool): x2 input
//
// Output:
// p(bool):carry propagate
// g(bool):carry generate
input x1;
input x2;
output p;
wire p;
output g;
wire g;
assign p = (x1 ^ x2);
assign g = (x1 & x2);
endmodule
### Verilog Testbench
```python
#generate test values
x1TVals=[i[0] for i in itertools.product(BitVals, repeat=len(BitVals))]
x2TVals=[i[1] for i in itertools.product(BitVals, repeat=len(BitVals))]
#create single value representation of Test Inputs
x1TVal=intbv(int(''.join([str(i) for i in x1TVals]), 2))[len(x1TVals):]
x2TVal=intbv(int(''.join([str(i) for i in x2TVals]), 2))[len(x2TVals):]
```
```python
print(f'x1Test: {x1TVals}, {x1TVal}, {[int(i) for i in x1TVal]}')
print(f'x2Test: {x2TVals}, {x2TVal}, {[int(i) for i in x2TVal]}')
```
x1Test: [0, 0, 1, 1], 3, [0, 0, 1, 1]
x2Test: [0, 1, 0, 1], 5, [0, 1, 0, 1]
```python
@block
def CLAS1_TBV():
"""
myHDL -> Verilog Testbench for module "CLAS1"
"""
x1=Signal(bool(0))
x2=Signal(bool(0))
p=Signal(bool(0))
g=Signal(bool(0))
#test stimuli
x1TVals=Signal(x1TVal)
x2TVals=Signal(x2TVal)
@always_comb
def print_data():
print(x1, x2, p, g)
DUT=CLAS1(x1, x2, p, g)
@instance
def stimules():
for i in range(len(x1TVal)):
x1.next=x1TVals[i]; x2.next=x2TVals[i]
yield delay(1)
raise StopSimulation()
return instances()
TB=CLAS1_TBV()
TB.convert(hdl="Verilog", initial_values=True)
VerilogTextReader('CLAS1_TBV');
```
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
***Verilog modual from CLAS1_TBV.v***
// File: CLAS1_TBV.v
// Generated by MyHDL 0.10
// Date: Tue Aug 21 12:52:30 2018
`timescale 1ns/10ps
module CLAS1_TBV (
);
// myHDL -> Verilog Testbench for module "CLAS1"
reg x1 = 0;
reg x2 = 0;
wire [3:0] x1TVals;
wire [3:0] x2TVals;
wire p;
wire g;
assign x1TVals = 4'd3;
assign x2TVals = 4'd5;
always @(p, x2, g, x1) begin: CLAS1_TBV_PRINT_DATA
$write("%h", x1);
$write(" ");
$write("%h", x2);
$write(" ");
$write("%h", p);
$write(" ");
$write("%h", g);
$write("\n");
end
assign p = (x1 ^ x2);
assign g = (x1 & x2);
initial begin: CLAS1_TBV_STIMULES
integer i;
for (i=0; i<4; i=i+1) begin
x1 <= x1TVals[i];
x2 <= x2TVals[i];
# 1;
end
$finish;
end
endmodule
/home/iridium/anaconda3/lib/python3.6/site-packages/myhdl/conversion/_toVerilog.py:349: ToVerilogWarning: Signal is not driven: x1TVals
category=ToVerilogWarning
/home/iridium/anaconda3/lib/python3.6/site-packages/myhdl/conversion/_toVerilog.py:349: ToVerilogWarning: Signal is not driven: x2TVals
category=ToVerilogWarning
## Stage Three
$$S_i=P_i \oplus C_i $$
### myHDL Code
```python
@block
def CLAS3(p, c, s):
"""
Carrry Look Ahead Adder Stage 3
Input:
p(bool):carry propagate
c(bool): carry
Output:
s(bool): sum
"""
@always_comb
def logic():
s.next=p^c
return instances()
```
### myHDL Testing
```python
Peeker.clear()
p=Signal(bool(0)); Peeker(p, 'p')
c=Signal(bool(0)); Peeker(c, 'c')
s=Signal(bool(0)); Peeker(s, 's')
#generate test values
pTVals=[i[0] for i in itertools.product(BitVals, repeat=len(BitVals))]
cTVals=[i[1] for i in itertools.product(BitVals, repeat=len(BitVals))]
DUT=CLAS3(p, c, s)
def CLAS3_TB():
"""
myHDL only Testbench for module "CLAS3"
"""
@instance
def stimules():
for i, j in zip(pTVals, cTVals):
p.next=i; c.next=j
yield delay(1)
raise StopSimulation()
return instances()
sim=Simulation(DUT, CLAS3_TB(), *Peeker.instances()).run()
```
```python
Peeker.to_wavedrom('p', 'c', 's')
```
<div></div>
```python
CLAS3Data=Peeker.to_dataframe()
CLAS3Data=CLAS3Data[['p', 'c', 's']]
CLAS3Data
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>p</th>
<th>c</th>
<th>s</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<th>1</th>
<td>0</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<th>2</th>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<th>3</th>
<td>1</td>
<td>1</td>
<td>0</td>
</tr>
</tbody>
</table>
</div>
```python
CLAS3Data['sCheck']=CLAS3Data.apply(lambda row: row['p']^row['c'], axis=1)
CLAS3Data
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>p</th>
<th>c</th>
<th>s</th>
<th>sCheck</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<th>1</th>
<td>0</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<th>2</th>
<td>1</td>
<td>0</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<th>3</th>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
</tr>
</tbody>
</table>
</div>
```python
sCheck=(CLAS3Data['s']==CLAS3Data['sCheck']).all()
print(f's Result Check: {sCheck}')
```
s Result Check: True
### Verilog Code
```python
DUT.convert()
VerilogTextReader('CLAS3');
```
***Verilog modual from CLAS3.v***
// File: CLAS3.v
// Generated by MyHDL 0.10
// Date: Tue Aug 21 12:52:30 2018
`timescale 1ns/10ps
module CLAS3 (
p,
c,
s
);
// Carrry Look Ahead Adder Stage 3
// Input:
// p(bool):carry propagate
// c(bool): carry
//
// Output:
// s(bool): sum
input p;
input c;
output s;
wire s;
assign s = (p ^ c);
endmodule
### Verilog Testbench
```python
#generate test values
pTVals=[i[0] for i in itertools.product(BitVals, repeat=len(BitVals))]
cTVals=[i[1] for i in itertools.product(BitVals, repeat=len(BitVals))]
#create single value representation of Test Inputs
pTVal=intbv(int(''.join([str(i) for i in pTVals]), 2))[len(pTVals):]
cTVal=intbv(int(''.join([str(i) for i in cTVals]), 2))[len(cTVals):]
```
```python
print(f'pTest: {pTVals}, {pTVal}, {[int(i) for i in pTVal]}')
print(f'cTest: {cTVals}, {cTVal}, {[int(i) for i in cTVal]}')
```
pTest: [0, 0, 1, 1], 3, [0, 0, 1, 1]
cTest: [0, 1, 0, 1], 5, [0, 1, 0, 1]
```python
@block
def CLAS3_TBV():
"""
myHDL -> Verilog Testbench for module "CLAS3"
"""
p=Signal(bool(0))
c=Signal(bool(0))
s=Signal(bool(0))
#test stimuli
pTVals=Signal(pTVal)
cTVals=Signal(cTVal)
@always_comb
def print_data():
print(p, c, s)
DUT=CLAS3(p, c, s)
@instance
def stimules():
for i in range(len(pTVal)):
p.next=pTVals[i]; c.next=cTVals[i]
yield delay(1)
raise StopSimulation()
return instances()
TB=CLAS3_TBV()
TB.convert(hdl="Verilog", initial_values=True)
VerilogTextReader('CLAS3_TBV');
```
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
<class 'myhdl._Signal._Signal'> <class '_ast.Name'>
***Verilog modual from CLAS3_TBV.v***
// File: CLAS3_TBV.v
// Generated by MyHDL 0.10
// Date: Tue Aug 21 12:52:32 2018
`timescale 1ns/10ps
module CLAS3_TBV (
);
// myHDL -> Verilog Testbench for module "CLAS3"
wire s;
reg c = 0;
reg p = 0;
wire [3:0] pTVals;
wire [3:0] cTVals;
assign pTVals = 4'd3;
assign cTVals = 4'd5;
always @(p, s, c) begin: CLAS3_TBV_PRINT_DATA
$write("%h", p);
$write(" ");
$write("%h", c);
$write(" ");
$write("%h", s);
$write("\n");
end
assign s = (p ^ c);
initial begin: CLAS3_TBV_STIMULES
integer i;
for (i=0; i<4; i=i+1) begin
p <= pTVals[i];
c <= cTVals[i];
# 1;
end
$finish;
end
endmodule
/home/iridium/anaconda3/lib/python3.6/site-packages/myhdl/conversion/_toVerilog.py:349: ToVerilogWarning: Signal is not driven: pTVals
category=ToVerilogWarning
/home/iridium/anaconda3/lib/python3.6/site-packages/myhdl/conversion/_toVerilog.py:349: ToVerilogWarning: Signal is not driven: cTVals
category=ToVerilogWarning
## Stage Two
$$C_i+1=G_i+P_i\cdot C_i$$
And is thus a recursion formula, so for a exsample a 4 bit Carray Lock Ahead Adder would have the following carry exspersions
$$C_1=G_0+P_0\cdot C_{in}$$
$$C_2=G_1+P_1\cdot C_1=G_1+P_1G_0+P_1P_0C_{in}$$
$$C_3=G_2+P_2\cdot C_2=G_2+P_2G_1+P_2P_1G_0+P_2P_1P_0C_{in}$$
$$C_4=G_3+P_3\cdot C_3=G_3+P_3G_2+P_3P_2G_1+P_3P_2P_1G_0+P_3P_2P_1P_0C_{in}$$
### myHDL Code (ToDo)
### myHDL Testing (ToDo)
```python
def CLAS2B4_TestFunc(P, G, cin):
P=[int(i) for i in reversed(bin(P,4))]
G=[int(i) for i in reversed(bin(G,4))]
C=[]
for i in range(4):
if i==0:
C.append(int(G[i]) | (P[i]&cin))
else:
C.append(int(G[i]) | (P[i] &C[i-1]))
C=int(''.join(str(i) for i in C[::-1]),2)
return C
CLAS2B4_TestFunc(8,6,1)
```
```python
```
|
-- M40002 (Analysis I) Chapter 7. Darboux Integration
import M40002.M40002_C6
namespace M40002
variables {a₁ a₂ : ℝ}
-- Definition of partitions
structure darboux_partition (n : ℕ) (a b : ℝ) :=
(xₖ : ℕ → ℝ)
(seq_min : xₖ 0 = a)
(seq_max : xₖ n = b)
(increasing : strict_mono xₖ)
#check darboux_partition
--theorem lower_inf_exists {n : ℕ} {a b : ℝ} (f : ℝ → ℝ) (xₖ : darboux_partition n a b) : ∀ i ∈ finset.range n, ∃ l : ℝ, inf {t : ℝ | xₖ i < t ∧ }
end M40002 |
(* Title: HOL/Auth/n_g2kAbsAfter_lemma_on_inv__88.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_g2kAbsAfter Protocol Case Study*}
theory n_g2kAbsAfter_lemma_on_inv__88 imports n_g2kAbsAfter_base
begin
section{*All lemmas on causal relation between inv__88 and some rule r*}
lemma n_n_RecvReq_i1Vsinv__88:
assumes a1: "(r=n_n_RecvReq_i1 )" and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
have "?P3 s"
apply (cut_tac a1 a2 , simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Ident ''Chan3_1'') ''Cmd'')) (Const InvAck)) (eqn (IVar (Ident ''CurCmd'')) (Const Empty))))" in exI, auto) done
then show "invHoldForRule s f r (invariants N)" by auto
qed
lemma n_n_SendInvAck_i1Vsinv__88:
assumes a1: "(r=n_n_SendInvAck_i1 )" and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
have "?P3 s"
apply (cut_tac a1 a2 , simp, rule_tac x="(neg (andForm (andForm (eqn (IVar (Field (Ident ''Chan2_1'') ''Cmd'')) (Const Inv)) (eqn (IVar (Ident ''CurCmd'')) (Const ReqS))) (eqn (IVar (Ident ''ExGntd'')) (Const false))))" in exI, auto) done
then show "invHoldForRule s f r (invariants N)" by auto
qed
lemma n_n_RecvInvAck_i1Vsinv__88:
assumes a1: "(r=n_n_RecvInvAck_i1 )" and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
have "((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\<or>((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))" by auto
moreover {
assume c1: "((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))"
have "?P1 s"
proof(cut_tac a1 a2 c1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume c1: "((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))"
have "?P1 s"
proof(cut_tac a1 a2 c1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_n_SendGntS_i1Vsinv__88:
assumes a1: "(r=n_n_SendGntS_i1 )" and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
have "?P1 s"
proof(cut_tac a1 a2 , auto) qed
then show "invHoldForRule s f r (invariants N)" by auto
qed
lemma n_n_SendGntE_i1Vsinv__88:
assumes a1: "(r=n_n_SendGntE_i1 )" and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
have "?P1 s"
proof(cut_tac a1 a2 , auto) qed
then show "invHoldForRule s f r (invariants N)" by auto
qed
lemma n_n_ARecvReq_i1Vsinv__88:
assumes a1: "(r=n_n_ARecvReq_i1 )" and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
have "?P3 s"
apply (cut_tac a1 a2 , simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Ident ''Chan3_1'') ''Cmd'')) (Const InvAck)) (eqn (IVar (Ident ''CurCmd'')) (Const Empty))))" in exI, auto) done
then show "invHoldForRule s f r (invariants N)" by auto
qed
lemma n_n_ARecvInvAck_i1Vsinv__88:
assumes a1: "(r=n_n_ARecvInvAck_i1 )" and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
have "((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\<or>((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))" by auto
moreover {
assume c1: "((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))"
have "?P3 s"
apply (cut_tac a1 a2 c1, simp, rule_tac x="(neg (andForm (andForm (eqn (IVar (Field (Ident ''Chan3_1'') ''Cmd'')) (Const InvAck)) (eqn (IVar (Ident ''CurCmd'')) (Const ReqS))) (eqn (IVar (Field (Ident ''AChan3_1'') ''Cmd'')) (Const InvAck))))" in exI, auto) done
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume c1: "((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))"
have "?P2 s"
proof(cut_tac a1 a2 c1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_n_ASendGntS_i1Vsinv__88:
assumes a1: "(r=n_n_ASendGntS_i1 )" and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
have "?P1 s"
proof(cut_tac a1 a2 , auto) qed
then show "invHoldForRule s f r (invariants N)" by auto
qed
lemma n_n_ASendGntE_i1Vsinv__88:
assumes a1: "(r=n_n_ASendGntE_i1 )" and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
have "?P1 s"
proof(cut_tac a1 a2 , auto) qed
then show "invHoldForRule s f r (invariants N)" by auto
qed
lemma n_n_SendInvS_i1Vsinv__88:
assumes a1: "r=n_n_SendInvS_i1 " and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_n_SendReqEI_i1Vsinv__88:
assumes a1: "r=n_n_SendReqEI_i1 " and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_n_ASendReqEI_i1Vsinv__88:
assumes a1: "r=n_n_ASendReqEI_i1 " and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_n_ASendReqIS_j1Vsinv__88:
assumes a1: "r=n_n_ASendReqIS_j1 " and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_n_ASendReqES_i1Vsinv__88:
assumes a1: "r=n_n_ASendReqES_i1 " and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_n_ARecvGntE_i1Vsinv__88:
assumes a1: "r=n_n_ARecvGntE_i1 " and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_n_ARecvGntS_i1Vsinv__88:
assumes a1: "r=n_n_ARecvGntS_i1 " and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_n_ASendInvE_i1Vsinv__88:
assumes a1: "r=n_n_ASendInvE_i1 " and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_n_ASendInvS_i1Vsinv__88:
assumes a1: "r=n_n_ASendInvS_i1 " and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_n_SendReqES_i1Vsinv__88:
assumes a1: "r=n_n_SendReqES_i1 " and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_n_SendInvE_i1Vsinv__88:
assumes a1: "r=n_n_SendInvE_i1 " and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_n_ASendReqSE_j1Vsinv__88:
assumes a1: "r=n_n_ASendReqSE_j1 " and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_n_RecvGntS_i1Vsinv__88:
assumes a1: "r=n_n_RecvGntS_i1 " and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_n_SendReqEE_i1Vsinv__88:
assumes a1: "r=n_n_SendReqEE_i1 " and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_n_RecvGntE_i1Vsinv__88:
assumes a1: "r=n_n_RecvGntE_i1 " and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_n_Store_i1Vsinv__88:
assumes a1: "\<exists> d. d\<le>N\<and>r=n_n_Store_i1 d" and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_n_AStore_i1Vsinv__88:
assumes a1: "\<exists> d. d\<le>N\<and>r=n_n_AStore_i1 d" and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_n_SendReqS_j1Vsinv__88:
assumes a1: "r=n_n_SendReqS_j1 " and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_n_ASendInvAck_i1Vsinv__88:
assumes a1: "r=n_n_ASendInvAck_i1 " and
a2: "(f=inv__88 )"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
end
|
//This does CELL (~soma) stage of LSTM (long short-term memory) model.
//This requires each neuron to have 4 input time series, Xc, Xi, Xf, Xo,
//where Xc is the usual (or "cellular") input and Xi, Xf, Xo the inputs for the input, forget, output gates.
//Xc, Xi, Xf, Xo are the output of separate linear IN stages (weights and baises).
//For dim=0, C[:,t] = tanh{Xc[:,t] + Uc*Y[:,t-1]} \n";
// I[:,t] = sig{Xi[:,t] + Ui*Y[:,t-1]} \n";
// F[:,t] = sig{Xf[:,t] + Uf*Y[:,t-1]} \n";
// O[:,t] = sig{Xo[:,t] + Uo*Y[:,t-1]} \n";
// H[:,t] = I[:,t].*C[:,t] + F[:,t].*H[:,t-1] \n";
// Y[:,t] = O[:,t].*tanh{H[:,t]} \n";
//with sizes Xc, Xi, Xf, Xo: N x T \n";
// Uc, Ui, Uf, Uo: N x N \n";
// Y : N x T \n";
//
//For dim=1, C[t,:] = tanh{Xc[t,:] + Y[t-1,:]*Uc} \n";
// I[t,:] = sig{Xi[t,:] + Y[t-1,:]*Ui} \n";
// F[t,:] = sig{Xf[t,:] + Y[t-1,:]*Uf} \n";
// O[t,:] = sig{Xo[t,:] + Y[t-1,:]*Uo} \n";
// H[t,:] = I[t,:].*C[t,:] + F[t,:].*H[t-1,:] \n";
// Y[t,:] = O[t,:].*tanh{H[t,:]} \n";
//with sizes Xc, Xi, Xf, Xo: T x N \n";
// Uc, Ui, Uf, Uo: N x N \n";
// Y : T x N \n";
//
//where sig is the logistic (sigmoid) nonlinearity = 1/(1+exp(-x)),
//I is the input gate, F is the forget gate, O is the output gate,
//C is the "cell input activation vector",
//H is an intermediate (hidden) vector (sometimes called the "cell state vector"),
//Uc, Ui, Uf, Uo are NxN matrices, and Y is the final output (sometimes called the "hidden state vector").
//Note that, the neurons of a layer are independent only if Uc, Ui, Uf, Uo are diagonal matrices.
//This is only really a CELL (~soma) stage in that case.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cblas.h>
#ifdef I
#undef I
#endif
#ifdef __cplusplus
namespace codee {
extern "C" {
#endif
int lstm4_s (float *Y, const float *Xc, const float *Xi, const float *Xf, const float *Xo, const float *Uc, const float *Ui, const float *Uf, const float *Uo, const size_t N, const size_t T, const char iscolmajor, const size_t dim);
int lstm4_d (double *Y, const double *Xc, const double *Xi, const double *Xf, const double *Xo, const double *Uc, const double *Ui, const double *Uf, const double *Uo, const size_t N, const size_t T, const char iscolmajor, const size_t dim);
int lstm4_inplace_s (float *Xc, const float *Xi, const float *Xf, const float *Xo, const float *Uc, const float *Ui, const float *Uf, const float *Uo, const size_t N, const size_t T, const char iscolmajor, const size_t dim);
int lstm4_inplace_d (double *Xc, const double *Xi, const double *Xf, const double *Xo, const double *Uc, const double *Ui, const double *Uf, const double *Uo, const size_t N, const size_t T, const char iscolmajor, const size_t dim);
int lstm4_s (float *Y, const float *Xc, const float *Xi, const float *Xf, const float *Xo, const float *Uc, const float *Ui, const float *Uf, const float *Uo, const size_t N, const size_t T, const char iscolmajor, const size_t dim)
{
const float o = 1.0f;
size_t nT, tN;
float *C, *I, *F, *O, *H;
if (!(C=(float *)malloc(N*sizeof(float)))) { fprintf(stderr,"error in lstm4_s: problem with malloc. "); perror("malloc"); return 1; }
if (!(I=(float *)malloc(N*sizeof(float)))) { fprintf(stderr,"error in lstm4_s: problem with malloc. "); perror("malloc"); return 1; }
if (!(F=(float *)malloc(N*sizeof(float)))) { fprintf(stderr,"error in lstm4_s: problem with malloc. "); perror("malloc"); return 1; }
if (!(O=(float *)malloc(N*sizeof(float)))) { fprintf(stderr,"error in lstm4_s: problem with malloc. "); perror("malloc"); return 1; }
if (!(H=(float *)malloc(N*sizeof(float)))) { fprintf(stderr,"error in lstm4_s: problem with malloc. "); perror("malloc"); return 1; }
if (N==1u)
{
//C[0] = tanhf(Xc[0]);
//I[0] = 1.0f / (1.0f+expf(-Xi[0]));
//F[0] = 1.0f / (1.0f+expf(-Xf[0]));
//O[0] = 1.0f / (1.0f+expf(-Xo[0]));
//H[0] = I[0] * C[0];
//Y[0] = O[0] * tanhf(H[0]);
H[0] = tanhf(Xc[0]) / (1.0f+expf(-Xi[0]));
Y[0] = tanhf(H[0]) / (1.0f+expf(-Xo[0]));
for (size_t t=1; t<T; ++t)
{
//C[0] = tanhf(Xc[t]+Uc[0]*Y[t-1]);
//I[0] = 1.0f / (1.0f+expf(-Xi[t]-Ui[0]*Y[t-1]));
//F[0] = 1.0f / (1.0f+expf(-Xf[t]-Uf[0]*Y[t-1]));
//O[0] = 1.0f / (1.0f+expf(-Xo[t]-Uo[0]*Y[t-1]));
//H[0] = I[0]*C[0] + F[0]*H[0];
//Y[t] = O[0] * tanhf(H[0]);
H[0] = tanhf(Xc[t]+Uc[0]*Y[t-1])/(1.0f+expf(-Xi[t]-Ui[0]*Y[t-1])) + H[0]/(1.0f+expf(-Xf[t]-Uf[0]*Y[t-1]));
Y[t] = tanhf(H[0]) / (1.0f+expf(-Xo[t]-Uo[0]*Y[t-1]));
}
}
else if (dim==0u)
{
if (iscolmajor)
{
for (size_t n=0u; n<N; ++n)
{
//C[n] = tanhf(Xc[n]);
//I[n] = 1.0f / (1.0f+expf(-Xi[n]));
//F[n] = 1.0f / (1.0f+expf(-Xf[n]));
//O[n] = 1.0f / (1.0f+expf(-Xo[n]));
//H[n] = I[n] * C[n];
//Y[n] = O[n] * tanhf(H[n]);
H[n] = tanhf(Xc[n]) / (1.0f+expf(-Xi[n]));
Y[n] = tanhf(H[n]) / (1.0f+expf(-Xo[n]));
}
for (size_t t=1; t<T; ++t)
{
tN = t*N;
cblas_scopy((int)N,&Xc[tN],1,C,1); cblas_scopy((int)N,&Xi[tN],1,I,1);
cblas_scopy((int)N,&Xf[tN],1,F,1); cblas_scopy((int)N,&Xo[tN],1,O,1);
cblas_sgemv(CblasColMajor,CblasNoTrans,(int)N,(int)N,o,Uc,(int)N,&Y[tN-N],1,o,C,1);
cblas_sgemv(CblasColMajor,CblasNoTrans,(int)N,(int)N,o,Ui,(int)N,&Y[tN-N],1,o,I,1);
cblas_sgemv(CblasColMajor,CblasNoTrans,(int)N,(int)N,o,Uf,(int)N,&Y[tN-N],1,o,F,1);
cblas_sgemv(CblasColMajor,CblasNoTrans,(int)N,(int)N,o,Uo,(int)N,&Y[tN-N],1,o,O,1);
for (size_t n=0u; n<N; ++n)
{
//C[n] = tanhf(C[n]);
//I[n] = 1.0f / (1.0f+expf(-I[n]));
//F[n] = 1.0f / (1.0f+expf(-F[n]));
//O[n] = 1.0f / (1.0f+expf(-O[n]));
//H[n] = I[n]*C[n] + F[n]*H[n];
//Y[tN+n] = O[n] * tanhf(H[n]);
H[n] = tanhf(C[n])/(1.0f+expf(-I[n])) + H[n]/(1.0f+expf(-F[n]));
Y[tN+n] = tanhf(H[n]) / (1.0f+expf(-O[n]));
}
}
}
else
{
for (size_t n=0u; n<N; ++n)
{
nT = n*T;
//C[n] = tanhf(Xc[nT])
//I[n] = 1.0f / (1.0f+expf(-Xi[nT]));
//F[n] = 1.0f / (1.0f+expf(-Xf[nT]));
//O[n] = 1.0f / (1.0f+expf(-Xo[nT]));
//H[n] = I[n] * C[n];
//Y[nT] = O[n] * tanhf(H[n]);
H[n] = tanhf(Xc[nT]) / (1.0f+expf(-Xi[nT]));
Y[nT] = tanhf(H[n]) / (1.0f+expf(-Xo[nT]));
}
for (size_t t=1; t<T; ++t)
{
cblas_scopy((int)N,&Xc[t],(int)T,C,1); cblas_scopy((int)N,&Xi[t],(int)T,I,1);
cblas_scopy((int)N,&Xf[t],(int)T,F,1); cblas_scopy((int)N,&Xo[t],(int)T,O,1);
cblas_sgemv(CblasRowMajor,CblasNoTrans,(int)N,(int)N,o,Uc,(int)N,&Y[t-1],(int)T,o,C,1);
cblas_sgemv(CblasRowMajor,CblasNoTrans,(int)N,(int)N,o,Ui,(int)N,&Y[t-1],(int)T,o,I,1);
cblas_sgemv(CblasRowMajor,CblasNoTrans,(int)N,(int)N,o,Uf,(int)N,&Y[t-1],(int)T,o,F,1);
cblas_sgemv(CblasRowMajor,CblasNoTrans,(int)N,(int)N,o,Uo,(int)N,&Y[t-1],(int)T,o,O,1);
for (size_t n=0u; n<N; ++n)
{
//C[n] = tanhf(C[n]);
//I[n] = 1.0f / (1.0f+expf(-I[n]));
//F[n] = 1.0f / (1.0f+expf(-F[n]));
//O[n] = 1.0f / (1.0f+expf(-O[n]));
//H[n] = I[n]*C[n] + F[n]*H[n];
//Y[t+n*T] = O[n] * tanhf(H[n]);
H[n] = tanhf(C[n])/(1.0f+expf(-I[n])) + H[n]/(1.0f+expf(-F[n]));
Y[t+n*T] = tanhf(H[n]) / (1.0f+expf(-O[n]));
}
}
}
}
else if (dim==1u)
{
if (iscolmajor)
{
for (size_t n=0u; n<N; ++n)
{
nT = n*T;
H[n] = tanhf(Xc[nT]) / (1.0f+expf(-Xi[nT]));
Y[nT] = tanhf(H[n]) / (1.0f+expf(-Xo[nT]));
}
for (size_t t=1; t<T; ++t)
{
cblas_scopy((int)N,&Xc[t],(int)T,C,1); cblas_scopy((int)N,&Xi[t],(int)T,I,1);
cblas_scopy((int)N,&Xf[t],(int)T,F,1); cblas_scopy((int)N,&Xo[t],(int)T,O,1);
cblas_sgemv(CblasColMajor,CblasTrans,(int)N,(int)N,o,Uc,(int)N,&Y[t-1],(int)T,o,C,1);
cblas_sgemv(CblasColMajor,CblasTrans,(int)N,(int)N,o,Ui,(int)N,&Y[t-1],(int)T,o,I,1);
cblas_sgemv(CblasColMajor,CblasTrans,(int)N,(int)N,o,Uf,(int)N,&Y[t-1],(int)T,o,F,1);
cblas_sgemv(CblasColMajor,CblasTrans,(int)N,(int)N,o,Uo,(int)N,&Y[t-1],(int)T,o,O,1);
for (size_t n=0u; n<N; ++n)
{
H[n] = tanhf(C[n])/(1.0f+expf(-I[n])) + H[n]/(1.0f+expf(-F[n]));
Y[t+n*T] = tanhf(H[n]) / (1.0f+expf(-O[n]));
}
}
}
else
{
for (size_t n=0u; n<N; ++n)
{
H[n] = tanhf(Xc[n]) / (1.0f+expf(-Xi[n]));
Y[n] = tanhf(H[n]) / (1.0f+expf(-Xo[n]));
}
for (size_t t=1; t<T; ++t)
{
tN = t*N;
cblas_scopy((int)N,&Xc[tN],1,C,1); cblas_scopy((int)N,&Xi[tN],1,I,1);
cblas_scopy((int)N,&Xf[tN],1,F,1); cblas_scopy((int)N,&Xo[tN],1,O,1);
cblas_sgemv(CblasRowMajor,CblasTrans,(int)N,(int)N,o,Uc,(int)N,&Y[tN-N],1,o,C,1);
cblas_sgemv(CblasRowMajor,CblasTrans,(int)N,(int)N,o,Ui,(int)N,&Y[tN-N],1,o,I,1);
cblas_sgemv(CblasRowMajor,CblasTrans,(int)N,(int)N,o,Uf,(int)N,&Y[tN-N],1,o,F,1);
cblas_sgemv(CblasRowMajor,CblasTrans,(int)N,(int)N,o,Uo,(int)N,&Y[tN-N],1,o,O,1);
for (size_t n=0u; n<N; ++n)
{
H[n] = tanhf(C[n])/(1.0f+expf(-I[n])) + H[n]/(1.0f+expf(-F[n]));
Y[tN+n] = tanhf(H[n]) / (1.0f+expf(-O[n]));
}
}
}
}
else
{
fprintf(stderr,"error in lstm4_s: dim must be 0 or 1.\n"); return 1;
}
return 0;
}
int lstm4_d (double *Y, const double *Xc, const double *Xi, const double *Xf, const double *Xo, const double *Uc, const double *Ui, const double *Uf, const double *Uo, const size_t N, const size_t T, const char iscolmajor, const size_t dim)
{
const double o = 1.0;
size_t nT, tN;
double *C, *I, *F, *O, *H;
if (!(C=(double *)malloc(N*sizeof(double)))) { fprintf(stderr,"error in lstm4_d: problem with malloc. "); perror("malloc"); return 1; }
if (!(I=(double *)malloc(N*sizeof(double)))) { fprintf(stderr,"error in lstm4_d: problem with malloc. "); perror("malloc"); return 1; }
if (!(F=(double *)malloc(N*sizeof(double)))) { fprintf(stderr,"error in lstm4_d: problem with malloc. "); perror("malloc"); return 1; }
if (!(O=(double *)malloc(N*sizeof(double)))) { fprintf(stderr,"error in lstm4_d: problem with malloc. "); perror("malloc"); return 1; }
if (!(H=(double *)malloc(N*sizeof(double)))) { fprintf(stderr,"error in lstm4_d: problem with malloc. "); perror("malloc"); return 1; }
if (N==1u)
{
H[0] = tanh(Xc[0]) / (1.0+exp(-Xi[0]));
Y[0] = tanh(H[0]) / (1.0+exp(-Xo[0]));
for (size_t t=1; t<T; ++t)
{
H[0] = tanh(Xc[t]+Uc[0]*Y[t-1])/(1.0+exp(-Xi[t]-Ui[0]*Y[t-1])) + H[0]/(1.0+exp(-Xf[t]-Uf[0]*Y[t-1]));
Y[t] = tanh(H[0]) / (1.0+exp(-Xo[t]-Uo[0]*Y[t-1]));
}
}
else if (dim==0u)
{
if (iscolmajor)
{
for (size_t n=0u; n<N; ++n)
{
H[n] = tanh(Xc[n]) / (1.0+exp(-Xi[n]));
Y[n] = tanh(H[n]) / (1.0+exp(-Xo[n]));
}
for (size_t t=1; t<T; ++t)
{
tN = t*N;
cblas_dcopy((int)N,&Xc[tN],1,C,1); cblas_dcopy((int)N,&Xi[tN],1,I,1);
cblas_dcopy((int)N,&Xf[tN],1,F,1); cblas_dcopy((int)N,&Xo[tN],1,O,1);
cblas_dgemv(CblasColMajor,CblasNoTrans,(int)N,(int)N,o,Uc,(int)N,&Y[tN-N],1,o,C,1);
cblas_dgemv(CblasColMajor,CblasNoTrans,(int)N,(int)N,o,Ui,(int)N,&Y[tN-N],1,o,I,1);
cblas_dgemv(CblasColMajor,CblasNoTrans,(int)N,(int)N,o,Uf,(int)N,&Y[tN-N],1,o,F,1);
cblas_dgemv(CblasColMajor,CblasNoTrans,(int)N,(int)N,o,Uo,(int)N,&Y[tN-N],1,o,O,1);
for (size_t n=0u; n<N; ++n)
{
H[n] = tanh(C[n])/(1.0+exp(-I[n])) + H[n]/(1.0+exp(-F[n]));
Y[tN+n] = tanh(H[n]) / (1.0+exp(-O[n]));
}
}
}
else
{
for (size_t n=0u; n<N; ++n)
{
nT = n*T;
H[n] = tanh(Xc[nT]) / (1.0+exp(-Xi[nT]));
Y[nT] = tanh(H[n]) / (1.0+exp(-Xo[nT]));
}
for (size_t t=1; t<T; ++t)
{
cblas_dcopy((int)N,&Xc[t],(int)T,C,1); cblas_dcopy((int)N,&Xi[t],(int)T,I,1);
cblas_dcopy((int)N,&Xf[t],(int)T,F,1); cblas_dcopy((int)N,&Xo[t],(int)T,O,1);
cblas_dgemv(CblasRowMajor,CblasNoTrans,(int)N,(int)N,o,Uc,(int)N,&Y[t-1],(int)T,o,C,1);
cblas_dgemv(CblasRowMajor,CblasNoTrans,(int)N,(int)N,o,Ui,(int)N,&Y[t-1],(int)T,o,I,1);
cblas_dgemv(CblasRowMajor,CblasNoTrans,(int)N,(int)N,o,Uf,(int)N,&Y[t-1],(int)T,o,F,1);
cblas_dgemv(CblasRowMajor,CblasNoTrans,(int)N,(int)N,o,Uo,(int)N,&Y[t-1],(int)T,o,O,1);
for (size_t n=0u; n<N; ++n)
{
H[n] = tanh(C[n])/(1.0+exp(-I[n])) + H[n]/(1.0+exp(-F[n]));
Y[t+n*T] = tanh(H[n]) / (1.0+exp(-O[n]));
}
}
}
}
else if (dim==1u)
{
if (iscolmajor)
{
for (size_t n=0u; n<N; ++n)
{
nT = n*T;
H[n] = tanh(Xc[nT]) / (1.0+exp(-Xi[nT]));
Y[nT] = tanh(H[n]) / (1.0+exp(-Xo[nT]));
}
for (size_t t=1; t<T; ++t)
{
cblas_dcopy((int)N,&Xc[t],(int)T,C,1); cblas_dcopy((int)N,&Xi[t],(int)T,I,1);
cblas_dcopy((int)N,&Xf[t],(int)T,F,1); cblas_dcopy((int)N,&Xo[t],(int)T,O,1);
cblas_dgemv(CblasColMajor,CblasTrans,(int)N,(int)N,o,Uc,(int)N,&Y[t-1],(int)T,o,C,1);
cblas_dgemv(CblasColMajor,CblasTrans,(int)N,(int)N,o,Ui,(int)N,&Y[t-1],(int)T,o,I,1);
cblas_dgemv(CblasColMajor,CblasTrans,(int)N,(int)N,o,Uf,(int)N,&Y[t-1],(int)T,o,F,1);
cblas_dgemv(CblasColMajor,CblasTrans,(int)N,(int)N,o,Uo,(int)N,&Y[t-1],(int)T,o,O,1);
for (size_t n=0u; n<N; ++n)
{
H[n] = tanh(C[n])/(1.0+exp(-I[n])) + H[n]/(1.0+exp(-F[n]));
Y[t+n*T] = tanh(H[n]) / (1.0+exp(-O[n]));
}
}
}
else
{
for (size_t n=0u; n<N; ++n)
{
H[n] = tanh(Xc[n]) / (1.0+exp(-Xi[n]));
Y[n] = tanh(H[n]) / (1.0+exp(-Xo[n]));
}
for (size_t t=1; t<T; ++t)
{
tN = t*N;
cblas_dcopy((int)N,&Xc[tN],1,C,1); cblas_dcopy((int)N,&Xi[tN],1,I,1);
cblas_dcopy((int)N,&Xf[tN],1,F,1); cblas_dcopy((int)N,&Xo[tN],1,O,1);
cblas_dgemv(CblasRowMajor,CblasTrans,(int)N,(int)N,o,Uc,(int)N,&Y[tN-N],1,o,C,1);
cblas_dgemv(CblasRowMajor,CblasTrans,(int)N,(int)N,o,Ui,(int)N,&Y[tN-N],1,o,I,1);
cblas_dgemv(CblasRowMajor,CblasTrans,(int)N,(int)N,o,Uf,(int)N,&Y[tN-N],1,o,F,1);
cblas_dgemv(CblasRowMajor,CblasTrans,(int)N,(int)N,o,Uo,(int)N,&Y[tN-N],1,o,O,1);
for (size_t n=0u; n<N; ++n)
{
H[n] = tanh(C[n])/(1.0+exp(-I[n])) + H[n]/(1.0+exp(-F[n]));
Y[tN+n] = tanh(H[n]) / (1.0+exp(-O[n]));
}
}
}
}
else
{
fprintf(stderr,"error in lstm4_d: dim must be 0 or 1.\n"); return 1;
}
return 0;
}
int lstm4_inplace_s (float *Xc, const float *Xi, const float *Xf, const float *Xo, const float *Uc, const float *Ui, const float *Uf, const float *Uo, const size_t N, const size_t T, const char iscolmajor, const size_t dim)
{
const float o = 1.0f;
size_t nT, tN;
float *C, *I, *F, *O, *H;
if (!(C=(float *)malloc(N*sizeof(float)))) { fprintf(stderr,"error in lstm4_inplace_s: problem with malloc. "); perror("malloc"); return 1; }
if (!(I=(float *)malloc(N*sizeof(float)))) { fprintf(stderr,"error in lstm4_inplace_s: problem with malloc. "); perror("malloc"); return 1; }
if (!(F=(float *)malloc(N*sizeof(float)))) { fprintf(stderr,"error in lstm4_inplace_s: problem with malloc. "); perror("malloc"); return 1; }
if (!(O=(float *)malloc(N*sizeof(float)))) { fprintf(stderr,"error in lstm4_inplace_s: problem with malloc. "); perror("malloc"); return 1; }
if (!(H=(float *)malloc(N*sizeof(float)))) { fprintf(stderr,"error in lstm4_inplace_s: problem with malloc. "); perror("malloc"); return 1; }
if (N==1u)
{
H[0] = tanhf(Xc[0]) / (1.0f+expf(-Xi[0]));
Xc[0] = tanhf(H[0]) / (1.0f+expf(-Xo[0]));
for (size_t t=1; t<T; ++t)
{
H[0] = tanhf(Xc[t]+Uc[0]*Xc[t-1])/(1.0f+expf(-Xi[t]-Ui[0]*Xc[t-1])) + H[0]/(1.0f+expf(-Xf[t]-Uf[0]*Xc[t-1]));
Xc[t] = tanhf(H[0]) / (1.0f+expf(-Xo[t]-Uo[0]*Xc[t-1]));
}
}
else if (dim==0u)
{
if (iscolmajor)
{
for (size_t n=0u; n<N; ++n)
{
H[n] = tanhf(Xc[n]) / (1.0f+expf(-Xi[n]));
Xc[n] = tanhf(H[n]) / (1.0f+expf(-Xo[n]));
}
for (size_t t=1; t<T; ++t)
{
tN = t*N;
cblas_scopy((int)N,&Xc[tN],1,C,1); cblas_scopy((int)N,&Xi[tN],1,I,1);
cblas_scopy((int)N,&Xf[tN],1,F,1); cblas_scopy((int)N,&Xo[tN],1,O,1);
cblas_sgemv(CblasColMajor,CblasNoTrans,(int)N,(int)N,o,Uc,(int)N,&Xc[tN-N],1,o,C,1);
cblas_sgemv(CblasColMajor,CblasNoTrans,(int)N,(int)N,o,Ui,(int)N,&Xc[tN-N],1,o,I,1);
cblas_sgemv(CblasColMajor,CblasNoTrans,(int)N,(int)N,o,Uf,(int)N,&Xc[tN-N],1,o,F,1);
cblas_sgemv(CblasColMajor,CblasNoTrans,(int)N,(int)N,o,Uo,(int)N,&Xc[tN-N],1,o,O,1);
for (size_t n=0u; n<N; ++n)
{
H[n] = tanhf(C[n])/(1.0f+expf(-I[n])) + H[n]/(1.0f+expf(-F[n]));
Xc[tN+n] = tanhf(H[n]) / (1.0f+expf(-O[n]));
}
}
}
else
{
for (size_t n=0u; n<N; ++n)
{
nT = n*T;
H[n] = tanhf(Xc[nT]) / (1.0f+expf(-Xi[nT]));
Xc[nT] = tanhf(H[n]) / (1.0f+expf(-Xo[nT]));
}
for (size_t t=1; t<T; ++t)
{
cblas_scopy((int)N,&Xc[t],(int)T,C,1); cblas_scopy((int)N,&Xi[t],(int)T,I,1);
cblas_scopy((int)N,&Xf[t],(int)T,F,1); cblas_scopy((int)N,&Xo[t],(int)T,O,1);
cblas_sgemv(CblasRowMajor,CblasNoTrans,(int)N,(int)N,o,Uc,(int)N,&Xc[t-1],(int)T,o,C,1);
cblas_sgemv(CblasRowMajor,CblasNoTrans,(int)N,(int)N,o,Ui,(int)N,&Xc[t-1],(int)T,o,I,1);
cblas_sgemv(CblasRowMajor,CblasNoTrans,(int)N,(int)N,o,Uf,(int)N,&Xc[t-1],(int)T,o,F,1);
cblas_sgemv(CblasRowMajor,CblasNoTrans,(int)N,(int)N,o,Uo,(int)N,&Xc[t-1],(int)T,o,O,1);
for (size_t n=0u; n<N; ++n)
{
H[n] = tanhf(C[n])/(1.0f+expf(-I[n])) + H[n]/(1.0f+expf(-F[n]));
Xc[t+n*T] = tanhf(H[n]) / (1.0f+expf(-O[n]));
}
}
}
}
else if (dim==1u)
{
if (iscolmajor)
{
for (size_t n=0u; n<N; ++n)
{
nT = n*T;
H[n] = tanhf(Xc[nT]) / (1.0f+expf(-Xi[nT]));
Xc[nT] = tanhf(H[n]) / (1.0f+expf(-Xo[nT]));
}
for (size_t t=1; t<T; ++t)
{
cblas_scopy((int)N,&Xc[t],(int)T,C,1); cblas_scopy((int)N,&Xi[t],(int)T,I,1);
cblas_scopy((int)N,&Xf[t],(int)T,F,1); cblas_scopy((int)N,&Xo[t],(int)T,O,1);
cblas_sgemv(CblasColMajor,CblasTrans,(int)N,(int)N,o,Uc,(int)N,&Xc[t-1],(int)T,o,C,1);
cblas_sgemv(CblasColMajor,CblasTrans,(int)N,(int)N,o,Ui,(int)N,&Xc[t-1],(int)T,o,I,1);
cblas_sgemv(CblasColMajor,CblasTrans,(int)N,(int)N,o,Uf,(int)N,&Xc[t-1],(int)T,o,F,1);
cblas_sgemv(CblasColMajor,CblasTrans,(int)N,(int)N,o,Uo,(int)N,&Xc[t-1],(int)T,o,O,1);
for (size_t n=0u; n<N; ++n)
{
H[n] = tanhf(C[n])/(1.0f+expf(-I[n])) + H[n]/(1.0f+expf(-F[n]));
Xc[t+n*T] = tanhf(H[n]) / (1.0f+expf(-O[n]));
}
}
}
else
{
for (size_t n=0u; n<N; ++n)
{
H[n] = tanhf(Xc[n]) / (1.0f+expf(-Xi[n]));
Xc[n] = tanhf(H[n]) / (1.0f+expf(-Xo[n]));
}
for (size_t t=1; t<T; ++t)
{
tN = t*N;
cblas_scopy((int)N,&Xc[tN],1,C,1); cblas_scopy((int)N,&Xi[tN],1,I,1);
cblas_scopy((int)N,&Xf[tN],1,F,1); cblas_scopy((int)N,&Xo[tN],1,O,1);
cblas_sgemv(CblasRowMajor,CblasTrans,(int)N,(int)N,o,Uc,(int)N,&Xc[tN-N],1,o,C,1);
cblas_sgemv(CblasRowMajor,CblasTrans,(int)N,(int)N,o,Ui,(int)N,&Xc[tN-N],1,o,I,1);
cblas_sgemv(CblasRowMajor,CblasTrans,(int)N,(int)N,o,Uf,(int)N,&Xc[tN-N],1,o,F,1);
cblas_sgemv(CblasRowMajor,CblasTrans,(int)N,(int)N,o,Uo,(int)N,&Xc[tN-N],1,o,O,1);
for (size_t n=0u; n<N; ++n)
{
H[n] = tanhf(C[n])/(1.0f+expf(-I[n])) + H[n]/(1.0f+expf(-F[n]));
Xc[tN+n] = tanhf(H[n]) / (1.0f+expf(-O[n]));
}
}
}
}
else
{
fprintf(stderr,"error in lstm4_inplace_s: dim must be 0 or 1.\n"); return 1;
}
return 0;
}
int lstm4_inplace_d (double *Xc, const double *Xi, const double *Xf, const double *Xo, const double *Uc, const double *Ui, const double *Uf, const double *Uo, const size_t N, const size_t T, const char iscolmajor, const size_t dim)
{
const double o = 1.0;
size_t nT, tN;
double *C, *I, *F, *O, *H;
if (!(C=(double *)malloc(N*sizeof(double)))) { fprintf(stderr,"error in lstm4_inplace_d: problem with malloc. "); perror("malloc"); return 1; }
if (!(I=(double *)malloc(N*sizeof(double)))) { fprintf(stderr,"error in lstm4_inplace_d: problem with malloc. "); perror("malloc"); return 1; }
if (!(F=(double *)malloc(N*sizeof(double)))) { fprintf(stderr,"error in lstm4_inplace_d: problem with malloc. "); perror("malloc"); return 1; }
if (!(O=(double *)malloc(N*sizeof(double)))) { fprintf(stderr,"error in lstm4_inplace_d: problem with malloc. "); perror("malloc"); return 1; }
if (!(H=(double *)malloc(N*sizeof(double)))) { fprintf(stderr,"error in lstm4_inplace_d: problem with malloc. "); perror("malloc"); return 1; }
if (N==1u)
{
H[0] = tanh(Xc[0]) / (1.0+exp(-Xi[0]));
Xc[0] = tanh(H[0]) / (1.0+exp(-Xo[0]));
for (size_t t=1; t<T; ++t)
{
H[0] = tanh(Xc[t]+Uc[0]*Xc[t-1])/(1.0+exp(-Xi[t]-Ui[0]*Xc[t-1])) + H[0]/(1.0+exp(-Xf[t]-Uf[0]*Xc[t-1]));
Xc[t] = tanh(H[0]) / (1.0+exp(-Xo[t]-Uo[0]*Xc[t-1]));
}
}
else if (dim==0u)
{
if (iscolmajor)
{
for (size_t n=0u; n<N; ++n)
{
H[n] = tanh(Xc[n]) / (1.0+exp(-Xi[n]));
Xc[n] = tanh(H[n]) / (1.0+exp(-Xo[n]));
}
for (size_t t=1; t<T; ++t)
{
tN = t*N;
cblas_dcopy((int)N,&Xc[tN],1,C,1); cblas_dcopy((int)N,&Xi[tN],1,I,1);
cblas_dcopy((int)N,&Xf[tN],1,F,1); cblas_dcopy((int)N,&Xo[tN],1,O,1);
cblas_dgemv(CblasColMajor,CblasNoTrans,(int)N,(int)N,o,Uc,(int)N,&Xc[tN-N],1,o,C,1);
cblas_dgemv(CblasColMajor,CblasNoTrans,(int)N,(int)N,o,Ui,(int)N,&Xc[tN-N],1,o,I,1);
cblas_dgemv(CblasColMajor,CblasNoTrans,(int)N,(int)N,o,Uf,(int)N,&Xc[tN-N],1,o,F,1);
cblas_dgemv(CblasColMajor,CblasNoTrans,(int)N,(int)N,o,Uo,(int)N,&Xc[tN-N],1,o,O,1);
for (size_t n=0u; n<N; ++n)
{
H[n] = tanh(C[n])/(1.0+exp(-I[n])) + H[n]/(1.0+exp(-F[n]));
Xc[tN+n] = tanh(H[n]) / (1.0+exp(-O[n]));
}
}
}
else
{
for (size_t n=0u; n<N; ++n)
{
nT = n*T;
H[n] = tanh(Xc[nT]) / (1.0+exp(-Xi[nT]));
Xc[nT] = tanh(H[n]) / (1.0+exp(-Xo[nT]));
}
for (size_t t=1; t<T; ++t)
{
cblas_dcopy((int)N,&Xc[t],(int)T,C,1); cblas_dcopy((int)N,&Xi[t],(int)T,I,1);
cblas_dcopy((int)N,&Xf[t],(int)T,F,1); cblas_dcopy((int)N,&Xo[t],(int)T,O,1);
cblas_dgemv(CblasRowMajor,CblasNoTrans,(int)N,(int)N,o,Uc,(int)N,&Xc[t-1],(int)T,o,C,1);
cblas_dgemv(CblasRowMajor,CblasNoTrans,(int)N,(int)N,o,Ui,(int)N,&Xc[t-1],(int)T,o,I,1);
cblas_dgemv(CblasRowMajor,CblasNoTrans,(int)N,(int)N,o,Uf,(int)N,&Xc[t-1],(int)T,o,F,1);
cblas_dgemv(CblasRowMajor,CblasNoTrans,(int)N,(int)N,o,Uo,(int)N,&Xc[t-1],(int)T,o,O,1);
for (size_t n=0u; n<N; ++n)
{
H[n] = tanh(C[n])/(1.0+exp(-I[n])) + H[n]/(1.0+exp(-F[n]));
Xc[t+n*T] = tanh(H[n]) / (1.0+exp(-O[n]));
}
}
}
}
else if (dim==1u)
{
if (iscolmajor)
{
for (size_t n=0u; n<N; ++n)
{
nT = n*T;
H[n] = tanh(Xc[nT]) / (1.0+exp(-Xi[nT]));
Xc[nT] = tanh(H[n]) / (1.0+exp(-Xo[nT]));
}
for (size_t t=1; t<T; ++t)
{
cblas_dcopy((int)N,&Xc[t],(int)T,C,1); cblas_dcopy((int)N,&Xi[t],(int)T,I,1);
cblas_dcopy((int)N,&Xf[t],(int)T,F,1); cblas_dcopy((int)N,&Xo[t],(int)T,O,1);
cblas_dgemv(CblasColMajor,CblasTrans,(int)N,(int)N,o,Uc,(int)N,&Xc[t-1],(int)T,o,C,1);
cblas_dgemv(CblasColMajor,CblasTrans,(int)N,(int)N,o,Ui,(int)N,&Xc[t-1],(int)T,o,I,1);
cblas_dgemv(CblasColMajor,CblasTrans,(int)N,(int)N,o,Uf,(int)N,&Xc[t-1],(int)T,o,F,1);
cblas_dgemv(CblasColMajor,CblasTrans,(int)N,(int)N,o,Uo,(int)N,&Xc[t-1],(int)T,o,O,1);
for (size_t n=0u; n<N; ++n)
{
H[n] = tanh(C[n])/(1.0+exp(-I[n])) + H[n]/(1.0+exp(-F[n]));
Xc[t+n*T] = tanh(H[n]) / (1.0+exp(-O[n]));
}
}
}
else
{
for (size_t n=0u; n<N; ++n)
{
H[n] = tanh(Xc[n]) / (1.0+exp(-Xi[n]));
Xc[n] = tanh(H[n]) / (1.0+exp(-Xo[n]));
}
for (size_t t=1; t<T; ++t)
{
tN = t*N;
cblas_dcopy((int)N,&Xc[tN],1,C,1); cblas_dcopy((int)N,&Xi[tN],1,I,1);
cblas_dcopy((int)N,&Xf[tN],1,F,1); cblas_dcopy((int)N,&Xo[tN],1,O,1);
cblas_dgemv(CblasRowMajor,CblasTrans,(int)N,(int)N,o,Uc,(int)N,&Xc[tN-N],1,o,C,1);
cblas_dgemv(CblasRowMajor,CblasTrans,(int)N,(int)N,o,Ui,(int)N,&Xc[tN-N],1,o,I,1);
cblas_dgemv(CblasRowMajor,CblasTrans,(int)N,(int)N,o,Uf,(int)N,&Xc[tN-N],1,o,F,1);
cblas_dgemv(CblasRowMajor,CblasTrans,(int)N,(int)N,o,Uo,(int)N,&Xc[tN-N],1,o,O,1);
for (size_t n=0u; n<N; ++n)
{
H[n] = tanh(C[n])/(1.0+exp(-I[n])) + H[n]/(1.0+exp(-F[n]));
Xc[tN+n] = tanh(H[n]) / (1.0+exp(-O[n]));
}
}
}
}
else
{
fprintf(stderr,"error in lstm4_inplace_d: dim must be 0 or 1.\n"); return 1;
}
return 0;
}
#ifdef __cplusplus
}
}
#endif
|
module ListAppend where
open import Prelude
append : forall {A} -> List A -> List A -> List A
append xs ys = {!!}
appendP1 : forall {x l l'} -> append (cons x l) l' == cons x (append l l')
appendP1 = refl
appendP2 : forall {l} -> append nil l == l
appendP2 = refl
|
module EditorMode
%default total
public export
data EditorMode = Insert | Normal | Quit
|
Address(Muir Woods Place) is a residential double ended Culdesacs culdesac in West Davis. It is split by Denali Drive, and runs into Aspen Greenbelt at its east end.
|
% EJEMPLO SENCILLO DE INTERFAZ ENTRE ARTE Y COPPELIA.
function irb140_abb_pick_and_place()
% init basic data. Robots and number of collision objects.
coppelia = [];
coppelia.n_collision_objects = 0;
coppelia.robot.name = 'R1';
coppelia.robot.n_joints = 6;
coppelia.robot.end_effector.n_joints = 2;
coppelia = coppelia_start(coppelia);
% escribid una funcion que este entre coppelia start y coppelia_stop
pick_and_place(coppelia)
coppelia_stop(coppelia);
end
function pick_and_place(coppelia)
%load in arte
global robot
robot = load_robot('ABB', 'IRB140');
%T1, pre pick point
T1 = [0 1 0 0.52;
1 0 0 -0.1;
0 0 -1 0.45;
0 0 0 1];
% pick point
T2 = [0 1 0 0.52;
1 0 0 -0.1;
0 0 -1 0.33;
0 0 0 1];
% Release point
T3 = [-1 0 0 0.1;
0 1 0 -0.5;
0 0 -1 0.6;
0 0 0 1];
T4 = [-1 0 0 0.1;
0 1 0 -0.5;
0 0 -1 0.5;
0 0 0 1];
% Podeis ir a una posicion q arbitraria
q = [0.1 0.1 0.1 0.8 0.8 0.8]';
set_joint_target_trajectory(coppelia, q)
%podeis ir a una posicion que sea la cinematica inversa deseada
qinv = inversekinematic(robot, T1);
set_joint_target_trajectory(coppelia, qinv(:,1))
% Esto abre la pinza
open_gripper(coppelia);
% podéis esparar un múltiplo del dt de Coppelia (step size de simulación de
% coppelia, tip. 50 ms. Esperar a que se abra la pinza
coppelia_wait(coppelia, 10)
%podeis ir a una posicion que sea la cinematica inversa deseada
qinv = inversekinematic(robot, T2);
set_joint_target_trajectory(coppelia, qinv(:,1))
% cerrar pinza
close_gripper(coppelia);
% Esperar a que se cierre
coppelia_wait(coppelia, 5)
% subir
qinv = inversekinematic(robot, T1);
set_joint_target_trajectory(coppelia, qinv(:,1))
qinv = inversekinematic(robot, T3);
set_joint_target_trajectory(coppelia, qinv(:,1))
qinv = inversekinematic(robot, T4);
set_joint_target_trajectory(coppelia, qinv(:,1))
% Esto abre la pinza
open_gripper(coppelia);
coppelia_wait(coppelia, 5)
% VOLVEMOS A la posicion inicial
set_joint_target_trajectory(coppelia, q)
end
|
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{book}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
pdftitle={A Minimal Book Example},
pdfauthor={Yihui Xie},
hidelinks,
pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\usepackage{longtable,booktabs}
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{5}
\usepackage{booktabs}
\usepackage{amsthm}
\makeatletter
\def\thm@space@setup{%
\thm@preskip=8pt plus 2pt minus 4pt
\thm@postskip=\thm@preskip
}
\makeatother
\usepackage[]{natbib}
\bibliographystyle{apalike}
\title{A Minimal Book Example}
\author{Yihui Xie}
\date{2020-12-13}
\begin{document}
\maketitle
{
\setcounter{tocdepth}{1}
\tableofcontents
}
\hypertarget{prerequisites}{%
\chapter{Prerequisites}\label{prerequisites}}
This is a \emph{sample} book written in \textbf{Markdown}. You can use anything that Pandoc's Markdown supports, e.g., a math equation \(a^2 + b^2 = c^2\).
The \textbf{bookdown} package can be installed from CRAN or Github:
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{install.packages}\NormalTok{(}\StringTok{"bookdown"}\NormalTok{)}
\CommentTok{# or the development version}
\CommentTok{# devtools::install_github("rstudio/bookdown")}
\end{Highlighting}
\end{Shaded}
Remember each Rmd file contains one and only one chapter, and a chapter is defined by the first-level heading \texttt{\#}.
To compile this example to PDF, you need XeLaTeX. You are recommended to install TinyTeX (which includes XeLaTeX): \url{https://yihui.name/tinytex/}.
\hypertarget{intro}{%
\chapter{Introduction}\label{intro}}
\hypertarget{literature}{%
\chapter{Literature}\label{literature}}
Here is a review of existing methods.
\hypertarget{methods}{%
\chapter{Methods}\label{methods}}
We describe our methods in this chapter.
\hypertarget{applications}{%
\chapter{Applications}\label{applications}}
Some \emph{significant} applications are demonstrated in this chapter.
\hypertarget{example-one}{%
\section{Example one}\label{example-one}}
\hypertarget{example-two}{%
\section{Example two}\label{example-two}}
\hypertarget{final-words}{%
\chapter{Final Words}\label{final-words}}
We have finished a nice book.
\hypertarget{my-file}{%
\chapter{My File}\label{my-file}}
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{library}\NormalTok{(plotly)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Loading required package: ggplot2
\end{verbatim}
\begin{verbatim}
##
## Attaching package: 'plotly'
\end{verbatim}
\begin{verbatim}
## The following object is masked from 'package:ggplot2':
##
## last_plot
\end{verbatim}
\begin{verbatim}
## The following object is masked from 'package:stats':
##
## filter
\end{verbatim}
\begin{verbatim}
## The following object is masked from 'package:graphics':
##
## layout
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{# volcano is a numeric matrix that ships with R}
\NormalTok{fig <-}\StringTok{ }\KeywordTok{plot_ly}\NormalTok{(}\DataTypeTok{z =} \OperatorTok{~}\NormalTok{volcano) }\OperatorTok{%>%}\StringTok{ }\KeywordTok{add_surface}\NormalTok{(}
\DataTypeTok{contours =} \KeywordTok{list}\NormalTok{(}
\DataTypeTok{z =} \KeywordTok{list}\NormalTok{(}
\DataTypeTok{show=}\OtherTok{TRUE}\NormalTok{,}
\DataTypeTok{usecolormap=}\OtherTok{TRUE}\NormalTok{,}
\DataTypeTok{highlightcolor=}\StringTok{"#ff0000"}\NormalTok{,}
\DataTypeTok{project=}\KeywordTok{list}\NormalTok{(}\DataTypeTok{z=}\OtherTok{TRUE}\NormalTok{)}
\NormalTok{ )}
\NormalTok{ )}
\NormalTok{ )}
\NormalTok{fig <-}\StringTok{ }\NormalTok{fig }\OperatorTok{%>%}\StringTok{ }\KeywordTok{layout}\NormalTok{(}
\DataTypeTok{scene =} \KeywordTok{list}\NormalTok{(}
\DataTypeTok{camera=}\KeywordTok{list}\NormalTok{(}
\DataTypeTok{eye =} \KeywordTok{list}\NormalTok{(}\DataTypeTok{x=}\FloatTok{1.87}\NormalTok{, }\DataTypeTok{y=}\FloatTok{0.88}\NormalTok{, }\DataTypeTok{z=}\OperatorTok{-}\FloatTok{0.64}\NormalTok{)}
\NormalTok{ )}
\NormalTok{ )}
\NormalTok{ )}
\NormalTok{fig}
\end{Highlighting}
\end{Shaded}
\includegraphics{bookdown-demo_files/figure-latex/unnamed-chunk-3-1.pdf}
\begin{verbatim}
## Warning: `arrange_()` is deprecated as of dplyr 0.7.0.
## Please use `arrange()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
\end{verbatim}
\includegraphics{bookdown-demo_files/figure-latex/unnamed-chunk-4-1.pdf}
\begin{verbatim}
## Loading required package: igraph
\end{verbatim}
\begin{verbatim}
##
## Attaching package: 'igraph'
\end{verbatim}
\begin{verbatim}
## The following object is masked from 'package:plotly':
##
## groups
\end{verbatim}
\begin{verbatim}
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
\end{verbatim}
\begin{verbatim}
## The following object is masked from 'package:base':
##
## union
\end{verbatim}
\includegraphics{bookdown-demo_files/figure-latex/unnamed-chunk-5-1.pdf}
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{set.seed}\NormalTok{(}\DecValTok{324}\NormalTok{)}
\NormalTok{data <-}\StringTok{ }\KeywordTok{data.frame}\NormalTok{(}
\DataTypeTok{day =} \KeywordTok{paste0}\NormalTok{(}\StringTok{"day"}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{),}
\DataTypeTok{A =} \KeywordTok{runif}\NormalTok{(}\DecValTok{10}\NormalTok{, }\DecValTok{0}\NormalTok{, }\DecValTok{10}\NormalTok{),}
\DataTypeTok{B =} \KeywordTok{runif}\NormalTok{(}\DecValTok{10}\NormalTok{, }\DecValTok{0}\NormalTok{, }\DecValTok{10}\NormalTok{),}
\DataTypeTok{C =} \KeywordTok{runif}\NormalTok{(}\DecValTok{10}\NormalTok{, }\DecValTok{0}\NormalTok{, }\DecValTok{10}\NormalTok{)}
\NormalTok{)}
\CommentTok{# NSE version}
\NormalTok{chartist}\OperatorTok{::}\KeywordTok{chartist}\NormalTok{(data, day)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Warning: `select_()` is deprecated as of dplyr 0.7.0.
## Please use `select()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
\end{verbatim}
\includegraphics{bookdown-demo_files/figure-latex/unnamed-chunk-6-1.pdf}
The sum of a geometric series:
\[
g(r) = \sum^{\infty}_{k=0}ar^k = a + ar + ar^2 + ar^3 + \cdots = \frac{a}{1-r}.
\]
Taking the derivative of both sides of the equation yields the first derivative:
\[
g'(r) = \sum^{\infty}_{k=0}akr^{k-1} = a + 2ar + 3ar^2 + 4ar^3 + \cdots = \frac{a}{(1-r)^2}.
\]
The probability mass function
\[f(x) = P(X=x) = (1-p)^{x-1} p \]
for \(0 < p < 1\), \(x=1, 2, 3,...\) for a geometric random variable \(X\) is a valid p.m.f. {[}1{]}
The expected value of the geometric distribution is given by the expression
\begin{align}
\mathbb{E}[X] = & \ \sum^{\infty}_{x=0} x (1-p)^{x-1} p \\
= & \ \sum^{\infty}_{x=0} p x (1-p)^{x-1}. \\
\end{align}
Eqs. (1) and (3) are equivalent if we substitute \(p\) for \(a\), \(x\) for \(k\), and \((1-p)\) for \(r.\) In so doing, Eq (3) reduces to the following expression
\begin{align}
\mathbb{E}[X] = & \ \frac{p}{(1-(1-p))^2} \\
= & \ \frac 1p
\end{align}
\hypertarget{r-markdown}{%
\section{R Markdown}\label{r-markdown}}
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see \url{http://rmarkdown.rstudio.com}.
When you click the \textbf{Knit} button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
\begin{verbatim}
## ([<matplotlib.patches.Wedge object at 0x7f8479d05c50>, <matplotlib.patches.Wedge object at 0x7f8479d1b5c0>, <matplotlib.patches.Wedge object at 0x7f8479d1bef0>, <matplotlib.patches.Wedge object at 0x7f8479d2b860>], [Text(-1.099434838359691, -0.035256718522858485, 'Individual'), Text(0.3804818342784377, -1.4509423054636308, 'Corp'), Text(1.054534622791617, -0.3129803976828931, 'Payroll'), Text(0.539789386868472, 0.958450529669716, 'GDP')], [Text(-0.5996917300143769, -0.019230937376104627, '51.0%'), Text(0.2536545561856251, -0.9672948703090871, '6.1%'), Text(0.575200703340882, -0.1707165805543053, '26.5%'), Text(0.29443057465553013, 0.5227911980016632, '16.3%')])
\end{verbatim}
\begin{verbatim}
## (-1.1044516302221532, 1.1102879400935806, -1.504106509974362, 1.1192431671416363)
\end{verbatim}
\includegraphics{bookdown-demo_files/figure-latex/unnamed-chunk-7-1.pdf}
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{summary}\NormalTok{(cars)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
\end{verbatim}
\hypertarget{including-plots}{%
\section{Including Plots}\label{including-plots}}
You can also embed plots, for example:
\includegraphics{bookdown-demo_files/figure-latex/pressure-1.pdf}
Note that the \texttt{echo\ =\ FALSE} parameter was added to the code chunk to prevent printing of the R code that generated the plot.
\bibliography{book.bib,packages.bib}
\end{document}
|
[STATEMENT]
lemma subcls_of_Obj: "\<lbrakk> P \<turnstile> C \<preceq>\<^sup>* Object; P \<turnstile> C \<preceq>\<^sup>* D \<rbrakk> \<Longrightarrow> P \<turnstile> D \<preceq>\<^sup>* Object"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<lbrakk>P \<turnstile> C \<preceq>\<^sup>* Object; P \<turnstile> C \<preceq>\<^sup>* D\<rbrakk> \<Longrightarrow> P \<turnstile> D \<preceq>\<^sup>* Object
[PROOF STEP]
by(auto dest: subcls_confluent) |
\nocite{*}
\defbibheading{bibliography}{
\section{Full publication list} \label{sec:publications}
}
\printbibheading[heading=bibliography]
\printbibliography[
title={Journal papers},
type=article,
heading=subbibnumbered]
\printbibliography[
title={Conferences (oral presentations \& posters)},
type=inproceedings,
heading=subbibnumbered]
\printbibliography[
title={Thesis (see section~\ref{sec:education})},
type=thesis,
heading=subbibnumbered]
\printbibliography[
title={Other},
nottype=article,nottype=inproceedings,nottype=thesis,
heading=subbibnumbered]
|
Formal statement is: lemma lipschitz_on_cmult_nonneg [lipschitz_intros]: fixes f::"'a::metric_space \<Rightarrow> 'b::real_normed_vector" assumes "C-lipschitz_on U f" "a \<ge> 0" shows "(a * C)-lipschitz_on U (\<lambda>x. a *\<^sub>R f x)" Informal statement is: If $f$ is $C$-Lipschitz on $U$, then $a f$ is $(a C)$-Lipschitz on $U$ for any $a \geq 0$. |
Officially licensed Harry Potter cartoon keychain. Keychain measures 2.75" long from the end of the fob to the end of the ring and the fob measures 1.5" in diameter. Features a cute “Ravenclaw” house crest. |
Formal statement is: lemma div_poly_less: fixes x :: "'a::field poly" assumes "degree x < degree y" shows "x div y = 0" Informal statement is: If the degree of $x$ is less than the degree of $y$, then $x$ divided by $y$ is zero. |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Patrick Massot, Yury Kudryashov
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.group.hom
import Mathlib.data.equiv.mul_add
import Mathlib.data.prod
import Mathlib.PostPort
universes u_5 u_6 u_3 u_4 u_1 u_2 u_7 u_8 u_9
namespace Mathlib
/-!
# Monoid, group etc structures on `M × N`
In this file we define one-binop (`monoid`, `group` etc) structures on `M × N`. We also prove
trivial `simp` lemmas, and define the following operations on `monoid_hom`s:
* `fst M N : M × N →* M`, `snd M N : M × N →* N`: projections `prod.fst` and `prod.snd`
as `monoid_hom`s;
* `inl M N : M →* M × N`, `inr M N : N →* M × N`: inclusions of first/second monoid
into the product;
* `f.prod g : `M →* N × P`: sends `x` to `(f x, g x)`;
* `f.coprod g : M × N →* P`: sends `(x, y)` to `f x * g y`;
* `f.prod_map g : M × N → M' × N'`: `prod.map f g` as a `monoid_hom`,
sends `(x, y)` to `(f x, g y)`.
-/
namespace prod
protected instance has_add {M : Type u_5} {N : Type u_6} [Add M] [Add N] : Add (M × N) :=
{ add := fun (p q : M × N) => (fst p + fst q, snd p + snd q) }
@[simp] theorem fst_add {M : Type u_5} {N : Type u_6} [Add M] [Add N] (p : M × N) (q : M × N) :
fst (p + q) = fst p + fst q :=
rfl
@[simp] theorem snd_add {M : Type u_5} {N : Type u_6} [Add M] [Add N] (p : M × N) (q : M × N) :
snd (p + q) = snd p + snd q :=
rfl
@[simp] theorem mk_add_mk {M : Type u_5} {N : Type u_6} [Add M] [Add N] (a₁ : M) (a₂ : M) (b₁ : N)
(b₂ : N) : (a₁, b₁) + (a₂, b₂) = (a₁ + a₂, b₁ + b₂) :=
rfl
protected instance has_one {M : Type u_5} {N : Type u_6} [HasOne M] [HasOne N] : HasOne (M × N) :=
{ one := (1, 1) }
@[simp] theorem fst_zero {M : Type u_5} {N : Type u_6} [HasZero M] [HasZero N] : fst 0 = 0 := rfl
@[simp] theorem snd_one {M : Type u_5} {N : Type u_6} [HasOne M] [HasOne N] : snd 1 = 1 := rfl
theorem zero_eq_mk {M : Type u_5} {N : Type u_6} [HasZero M] [HasZero N] : 0 = (0, 0) := rfl
@[simp] theorem mk_eq_zero {M : Type u_5} {N : Type u_6} [HasZero M] [HasZero N] {x : M} {y : N} :
(x, y) = 0 ↔ x = 0 ∧ y = 0 :=
mk.inj_iff
theorem fst_mul_snd {M : Type u_5} {N : Type u_6} [monoid M] [monoid N] (p : M × N) :
(fst p, 1) * (1, snd p) = p :=
ext (mul_one (fst p)) (one_mul (snd p))
protected instance has_inv {M : Type u_5} {N : Type u_6} [has_inv M] [has_inv N] :
has_inv (M × N) :=
has_inv.mk fun (p : M × N) => (fst p⁻¹, snd p⁻¹)
@[simp] theorem fst_inv {G : Type u_3} {H : Type u_4} [has_inv G] [has_inv H] (p : G × H) :
fst (p⁻¹) = (fst p⁻¹) :=
rfl
@[simp] theorem snd_neg {G : Type u_3} {H : Type u_4} [Neg G] [Neg H] (p : G × H) :
snd (-p) = -snd p :=
rfl
@[simp] theorem inv_mk {G : Type u_3} {H : Type u_4} [has_inv G] [has_inv H] (a : G) (b : H) :
(a, b)⁻¹ = (a⁻¹, b⁻¹) :=
rfl
protected instance has_sub {M : Type u_5} {N : Type u_6} [Sub M] [Sub N] : Sub (M × N) :=
{ sub := fun (p q : M × N) => (fst p - fst q, snd p - snd q) }
@[simp] theorem fst_sub {A : Type u_1} {B : Type u_2} [add_group A] [add_group B] (a : A × B)
(b : A × B) : fst (a - b) = fst a - fst b :=
rfl
@[simp] theorem snd_sub {A : Type u_1} {B : Type u_2} [add_group A] [add_group B] (a : A × B)
(b : A × B) : snd (a - b) = snd a - snd b :=
rfl
@[simp] theorem mk_sub_mk {A : Type u_1} {B : Type u_2} [add_group A] [add_group B] (x₁ : A)
(x₂ : A) (y₁ : B) (y₂ : B) : (x₁, y₁) - (x₂, y₂) = (x₁ - x₂, y₁ - y₂) :=
rfl
protected instance semigroup {M : Type u_5} {N : Type u_6} [semigroup M] [semigroup N] :
semigroup (M × N) :=
semigroup.mk Mul.mul sorry
protected instance add_monoid {M : Type u_5} {N : Type u_6} [add_monoid M] [add_monoid N] :
add_monoid (M × N) :=
add_monoid.mk add_semigroup.add sorry 0 sorry sorry
protected instance group {G : Type u_3} {H : Type u_4} [group G] [group H] : group (G × H) :=
group.mk monoid.mul sorry monoid.one sorry sorry has_inv.inv Div.div sorry
protected instance add_comm_semigroup {G : Type u_3} {H : Type u_4} [add_comm_semigroup G]
[add_comm_semigroup H] : add_comm_semigroup (G × H) :=
add_comm_semigroup.mk add_semigroup.add sorry sorry
protected instance left_cancel_semigroup {G : Type u_3} {H : Type u_4} [left_cancel_semigroup G]
[left_cancel_semigroup H] : left_cancel_semigroup (G × H) :=
left_cancel_semigroup.mk semigroup.mul sorry sorry
protected instance right_cancel_semigroup {G : Type u_3} {H : Type u_4} [right_cancel_semigroup G]
[right_cancel_semigroup H] : right_cancel_semigroup (G × H) :=
right_cancel_semigroup.mk semigroup.mul sorry sorry
protected instance add_comm_monoid {M : Type u_5} {N : Type u_6} [add_comm_monoid M]
[add_comm_monoid N] : add_comm_monoid (M × N) :=
add_comm_monoid.mk add_comm_semigroup.add sorry add_monoid.zero sorry sorry sorry
protected instance comm_group {G : Type u_3} {H : Type u_4} [comm_group G] [comm_group H] :
comm_group (G × H) :=
comm_group.mk comm_semigroup.mul sorry group.one sorry sorry group.inv group.div sorry sorry
end prod
namespace monoid_hom
/-- Given monoids `M`, `N`, the natural projection homomorphism from `M × N` to `M`.-/
def fst (M : Type u_5) (N : Type u_6) [monoid M] [monoid N] : M × N →* M := mk prod.fst sorry sorry
/-- Given monoids `M`, `N`, the natural projection homomorphism from `M × N` to `N`.-/
def Mathlib.add_monoid_hom.snd (M : Type u_5) (N : Type u_6) [add_monoid M] [add_monoid N] :
M × N →+ N :=
add_monoid_hom.mk prod.snd sorry sorry
/-- Given monoids `M`, `N`, the natural inclusion homomorphism from `M` to `M × N`. -/
def Mathlib.add_monoid_hom.inl (M : Type u_5) (N : Type u_6) [add_monoid M] [add_monoid N] :
M →+ M × N :=
add_monoid_hom.mk (fun (x : M) => (x, 0)) sorry sorry
/-- Given monoids `M`, `N`, the natural inclusion homomorphism from `N` to `M × N`. -/
def Mathlib.add_monoid_hom.inr (M : Type u_5) (N : Type u_6) [add_monoid M] [add_monoid N] :
N →+ M × N :=
add_monoid_hom.mk (fun (y : N) => (0, y)) sorry sorry
@[simp] theorem Mathlib.add_monoid_hom.coe_fst {M : Type u_5} {N : Type u_6} [add_monoid M]
[add_monoid N] : ⇑(add_monoid_hom.fst M N) = prod.fst :=
rfl
@[simp] theorem Mathlib.add_monoid_hom.coe_snd {M : Type u_5} {N : Type u_6} [add_monoid M]
[add_monoid N] : ⇑(add_monoid_hom.snd M N) = prod.snd :=
rfl
@[simp] theorem inl_apply {M : Type u_5} {N : Type u_6} [monoid M] [monoid N] (x : M) :
coe_fn (inl M N) x = (x, 1) :=
rfl
@[simp] theorem inr_apply {M : Type u_5} {N : Type u_6} [monoid M] [monoid N] (y : N) :
coe_fn (inr M N) y = (1, y) :=
rfl
@[simp] theorem Mathlib.add_monoid_hom.fst_comp_inl {M : Type u_5} {N : Type u_6} [add_monoid M]
[add_monoid N] :
add_monoid_hom.comp (add_monoid_hom.fst M N) (add_monoid_hom.inl M N) = add_monoid_hom.id M :=
rfl
@[simp] theorem Mathlib.add_monoid_hom.snd_comp_inl {M : Type u_5} {N : Type u_6} [add_monoid M]
[add_monoid N] : add_monoid_hom.comp (add_monoid_hom.snd M N) (add_monoid_hom.inl M N) = 0 :=
rfl
@[simp] theorem Mathlib.add_monoid_hom.fst_comp_inr {M : Type u_5} {N : Type u_6} [add_monoid M]
[add_monoid N] : add_monoid_hom.comp (add_monoid_hom.fst M N) (add_monoid_hom.inr M N) = 0 :=
rfl
@[simp] theorem Mathlib.add_monoid_hom.snd_comp_inr {M : Type u_5} {N : Type u_6} [add_monoid M]
[add_monoid N] :
add_monoid_hom.comp (add_monoid_hom.snd M N) (add_monoid_hom.inr M N) = add_monoid_hom.id N :=
rfl
/-- Combine two `monoid_hom`s `f : M →* N`, `g : M →* P` into `f.prod g : M →* N × P`
given by `(f.prod g) x = (f x, g x)` -/
protected def prod {M : Type u_5} {N : Type u_6} {P : Type u_7} [monoid M] [monoid N] [monoid P]
(f : M →* N) (g : M →* P) : M →* N × P :=
mk (fun (x : M) => (coe_fn f x, coe_fn g x)) sorry sorry
@[simp] theorem prod_apply {M : Type u_5} {N : Type u_6} {P : Type u_7} [monoid M] [monoid N]
[monoid P] (f : M →* N) (g : M →* P) (x : M) :
coe_fn (monoid_hom.prod f g) x = (coe_fn f x, coe_fn g x) :=
rfl
@[simp] theorem fst_comp_prod {M : Type u_5} {N : Type u_6} {P : Type u_7} [monoid M] [monoid N]
[monoid P] (f : M →* N) (g : M →* P) : comp (fst N P) (monoid_hom.prod f g) = f :=
ext fun (x : M) => rfl
@[simp] theorem snd_comp_prod {M : Type u_5} {N : Type u_6} {P : Type u_7} [monoid M] [monoid N]
[monoid P] (f : M →* N) (g : M →* P) : comp (snd N P) (monoid_hom.prod f g) = g :=
ext fun (x : M) => rfl
@[simp] theorem Mathlib.add_monoid_hom.prod_unique {M : Type u_5} {N : Type u_6} {P : Type u_7}
[add_monoid M] [add_monoid N] [add_monoid P] (f : M →+ N × P) :
add_monoid_hom.prod (add_monoid_hom.comp (add_monoid_hom.fst N P) f)
(add_monoid_hom.comp (add_monoid_hom.snd N P) f) =
f :=
sorry
/-- `prod.map` as a `monoid_hom`. -/
def Mathlib.add_monoid_hom.prod_map {M : Type u_5} {N : Type u_6} [add_monoid M] [add_monoid N]
{M' : Type u_8} {N' : Type u_9} [add_monoid M'] [add_monoid N'] (f : M →+ M') (g : N →+ N') :
M × N →+ M' × N' :=
add_monoid_hom.prod (add_monoid_hom.comp f (add_monoid_hom.fst M N))
(add_monoid_hom.comp g (add_monoid_hom.snd M N))
theorem Mathlib.add_monoid_hom.prod_map_def {M : Type u_5} {N : Type u_6} [add_monoid M]
[add_monoid N] {M' : Type u_8} {N' : Type u_9} [add_monoid M'] [add_monoid N'] (f : M →+ M')
(g : N →+ N') :
add_monoid_hom.prod_map f g =
add_monoid_hom.prod (add_monoid_hom.comp f (add_monoid_hom.fst M N))
(add_monoid_hom.comp g (add_monoid_hom.snd M N)) :=
rfl
@[simp] theorem coe_prod_map {M : Type u_5} {N : Type u_6} [monoid M] [monoid N] {M' : Type u_8}
{N' : Type u_9} [monoid M'] [monoid N'] (f : M →* M') (g : N →* N') :
⇑(prod_map f g) = prod.map ⇑f ⇑g :=
rfl
theorem prod_comp_prod_map {M : Type u_5} {N : Type u_6} {P : Type u_7} [monoid M] [monoid N]
{M' : Type u_8} {N' : Type u_9} [monoid M'] [monoid N'] [monoid P] (f : P →* M) (g : P →* N)
(f' : M →* M') (g' : N →* N') :
comp (prod_map f' g') (monoid_hom.prod f g) = monoid_hom.prod (comp f' f) (comp g' g) :=
rfl
/-- Coproduct of two `monoid_hom`s with the same codomain:
`f.coprod g (p : M × N) = f p.1 * g p.2`. -/
def coprod {M : Type u_5} {N : Type u_6} {P : Type u_7} [monoid M] [monoid N] [comm_monoid P]
(f : M →* P) (g : N →* P) : M × N →* P :=
comp f (fst M N) * comp g (snd M N)
@[simp] theorem coprod_apply {M : Type u_5} {N : Type u_6} {P : Type u_7} [monoid M] [monoid N]
[comm_monoid P] (f : M →* P) (g : N →* P) (p : M × N) :
coe_fn (coprod f g) p = coe_fn f (prod.fst p) * coe_fn g (prod.snd p) :=
rfl
@[simp] theorem Mathlib.add_monoid_hom.coprod_comp_inl {M : Type u_5} {N : Type u_6} {P : Type u_7}
[add_monoid M] [add_monoid N] [add_comm_monoid P] (f : M →+ P) (g : N →+ P) :
add_monoid_hom.comp (add_monoid_hom.coprod f g) (add_monoid_hom.inl M N) = f :=
sorry
@[simp] theorem Mathlib.add_monoid_hom.coprod_comp_inr {M : Type u_5} {N : Type u_6} {P : Type u_7}
[add_monoid M] [add_monoid N] [add_comm_monoid P] (f : M →+ P) (g : N →+ P) :
add_monoid_hom.comp (add_monoid_hom.coprod f g) (add_monoid_hom.inr M N) = g :=
sorry
@[simp] theorem Mathlib.add_monoid_hom.coprod_unique {M : Type u_5} {N : Type u_6} {P : Type u_7}
[add_monoid M] [add_monoid N] [add_comm_monoid P] (f : M × N →+ P) :
add_monoid_hom.coprod (add_monoid_hom.comp f (add_monoid_hom.inl M N))
(add_monoid_hom.comp f (add_monoid_hom.inr M N)) =
f :=
sorry
@[simp] theorem coprod_inl_inr {M : Type u_1} {N : Type u_2} [comm_monoid M] [comm_monoid N] :
coprod (inl M N) (inr M N) = id (M × N) :=
coprod_unique (id (M × N))
theorem comp_coprod {M : Type u_5} {N : Type u_6} {P : Type u_7} [monoid M] [monoid N]
[comm_monoid P] {Q : Type u_1} [comm_monoid Q] (h : P →* Q) (f : M →* P) (g : N →* P) :
comp h (coprod f g) = coprod (comp h f) (comp h g) :=
sorry
end monoid_hom
namespace mul_equiv
/-- The equivalence between `M × N` and `N × M` given by swapping the components is multiplicative. -/
def prod_comm {M : Type u_5} {N : Type u_6} [monoid M] [monoid N] : M × N ≃* N × M :=
mk (equiv.to_fun (equiv.prod_comm M N)) (equiv.inv_fun (equiv.prod_comm M N)) sorry sorry sorry
@[simp] theorem coe_prod_comm {M : Type u_5} {N : Type u_6} [monoid M] [monoid N] :
⇑prod_comm = prod.swap :=
rfl
@[simp] theorem coe_prod_comm_symm {M : Type u_5} {N : Type u_6} [monoid M] [monoid N] :
⇑(symm prod_comm) = prod.swap :=
rfl
/-- The monoid equivalence between units of a product of two monoids, and the product of the
units of each monoid. -/
def prod_units {M : Type u_5} {N : Type u_6} [monoid M] [monoid N] :
units (M × N) ≃* units M × units N :=
mk (⇑(monoid_hom.prod (units.map (monoid_hom.fst M N)) (units.map (monoid_hom.snd M N))))
(fun (u : units M × units N) =>
units.mk (↑(prod.fst u), ↑(prod.snd u)) (↑(prod.fst u⁻¹), ↑(prod.snd u⁻¹)) sorry sorry)
sorry sorry sorry
end Mathlib |
Formal statement is: lemma pderiv_power_Suc: "pderiv (p ^ Suc n) = smult (of_nat (Suc n)) (p ^ n) * pderiv p" Informal statement is: The $n$th derivative of $p^n$ is $n p^{n-1} p'$. |
module ObjCWrap
include("primitives.jl")
include("methods.jl")
include("call.jl")
include("syntax.jl")
include("foundation.jl")
include("classes.jl")
end
|
/-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Bhavik Mehta
-/
import category_theory.pempty
import category_theory.limits.has_limits
import category_theory.epi_mono
import category_theory.category.preorder
/-!
# Initial and terminal objects in a category.
## References
* [Stacks: Initial and final objects](https://stacks.math.columbia.edu/tag/002B)
-/
noncomputable theory
universes w w' v v₁ v₂ u u₁ u₂
open category_theory
namespace category_theory.limits
variables {C : Type u₁} [category.{v₁} C]
local attribute [tidy] tactic.discrete_cases
/-- Construct a cone for the empty diagram given an object. -/
@[simps] def as_empty_cone (X : C) : cone (functor.empty.{0} C) := { X := X, π := by tidy }
/-- Construct a cocone for the empty diagram given an object. -/
@[simps] def as_empty_cocone (X : C) : cocone (functor.empty.{0} C) := { X := X, ι := by tidy }
/-- `X` is terminal if the cone it induces on the empty diagram is limiting. -/
abbreviation is_terminal (X : C) := is_limit (as_empty_cone X)
/-- `X` is initial if the cocone it induces on the empty diagram is colimiting. -/
abbreviation is_initial (X : C) := is_colimit (as_empty_cocone X)
/-- An object `Y` is terminal iff for every `X` there is a unique morphism `X ⟶ Y`. -/
def is_terminal_equiv_unique (F : discrete.{0} pempty.{1} ⥤ C) (Y : C) :
is_limit (⟨Y, by tidy⟩ : cone F) ≃ ∀ X : C, unique (X ⟶ Y) :=
{ to_fun := λ t X, { default := t.lift ⟨X, by tidy⟩,
uniq := λ f, t.uniq ⟨X, by tidy⟩ f (by tidy) },
inv_fun := λ u, { lift := λ s, (u s.X).default, uniq' := λ s _ _, (u s.X).2 _ },
left_inv := by tidy,
right_inv := by tidy }
/-- An object `Y` is terminal if for every `X` there is a unique morphism `X ⟶ Y`
(as an instance). -/
def is_terminal.of_unique (Y : C) [h : Π X : C, unique (X ⟶ Y)] : is_terminal Y :=
{ lift := λ s, (h s.X).default }
/-- If `α` is a preorder with top, then `⊤` is a terminal object. -/
def is_terminal_top {α : Type*} [preorder α] [order_top α] : is_terminal (⊤ : α) :=
is_terminal.of_unique _
/-- Transport a term of type `is_terminal` across an isomorphism. -/
def is_terminal.of_iso {Y Z : C} (hY : is_terminal Y) (i : Y ≅ Z) : is_terminal Z :=
is_limit.of_iso_limit hY
{ hom := { hom := i.hom },
inv := { hom := i.inv } }
/-- An object `X` is initial iff for every `Y` there is a unique morphism `X ⟶ Y`. -/
def is_initial_equiv_unique (F : discrete.{0} pempty.{1} ⥤ C) (X : C) :
is_colimit (⟨X, by tidy⟩ : cocone F) ≃ ∀ Y : C, unique (X ⟶ Y) :=
{ to_fun := λ t X, { default := t.desc ⟨X, by tidy⟩,
uniq := λ f, t.uniq ⟨X, by tidy⟩ f (by tidy) },
inv_fun := λ u, { desc := λ s, (u s.X).default, uniq' := λ s _ _, (u s.X).2 _ },
left_inv := by tidy,
right_inv := by tidy }
/-- An object `X` is initial if for every `Y` there is a unique morphism `X ⟶ Y`
(as an instance). -/
def is_initial.of_unique (X : C) [h : Π Y : C, unique (X ⟶ Y)] : is_initial X :=
{ desc := λ s, (h s.X).default }
/-- If `α` is a preorder with bot, then `⊥` is an initial object. -/
def is_initial_bot {α : Type*} [preorder α] [order_bot α] : is_initial (⊥ : α) :=
is_initial.of_unique _
/-- Transport a term of type `is_initial` across an isomorphism. -/
def is_initial.of_iso {X Y : C} (hX : is_initial X) (i : X ≅ Y) : is_initial Y :=
is_colimit.of_iso_colimit hX
{ hom := { hom := i.hom },
inv := { hom := i.inv } }
/-- Give the morphism to a terminal object from any other. -/
def is_terminal.from {X : C} (t : is_terminal X) (Y : C) : Y ⟶ X :=
t.lift (as_empty_cone Y)
/-- Any two morphisms to a terminal object are equal. -/
lemma is_terminal.hom_ext {X Y : C} (t : is_terminal X) (f g : Y ⟶ X) : f = g :=
t.hom_ext (by tidy)
@[simp] lemma is_terminal.comp_from {Z : C} (t : is_terminal Z) {X Y : C} (f : X ⟶ Y) :
f ≫ t.from Y = t.from X :=
t.hom_ext _ _
@[simp] lemma is_terminal.from_self {X : C} (t : is_terminal X) : t.from X = 𝟙 X :=
t.hom_ext _ _
/-- Give the morphism from an initial object to any other. -/
def is_initial.to {X : C} (t : is_initial X) (Y : C) : X ⟶ Y :=
t.desc (as_empty_cocone Y)
/-- Any two morphisms from an initial object are equal. -/
lemma is_initial.hom_ext {X Y : C} (t : is_initial X) (f g : X ⟶ Y) : f = g :=
t.hom_ext (by tidy)
@[simp] lemma is_initial.to_comp {X : C} (t : is_initial X) {Y Z : C} (f : Y ⟶ Z) :
t.to Y ≫ f = t.to Z :=
t.hom_ext _ _
@[simp] lemma is_initial.to_self {X : C} (t : is_initial X) : t.to X = 𝟙 X :=
t.hom_ext _ _
/-- Any morphism from a terminal object is split mono. -/
def is_terminal.split_mono_from {X Y : C} (t : is_terminal X) (f : X ⟶ Y) : split_mono f :=
⟨t.from _, t.hom_ext _ _⟩
/-- Any morphism to an initial object is split epi. -/
def is_initial.split_epi_to {X Y : C} (t : is_initial X) (f : Y ⟶ X) : split_epi f :=
⟨t.to _, t.hom_ext _ _⟩
/-- Any morphism from a terminal object is mono. -/
lemma is_terminal.mono_from {X Y : C} (t : is_terminal X) (f : X ⟶ Y) : mono f :=
by haveI := t.split_mono_from f; apply_instance
/-- Any morphism to an initial object is epi. -/
lemma is_initial.epi_to {X Y : C} (t : is_initial X) (f : Y ⟶ X) : epi f :=
by haveI := t.split_epi_to f; apply_instance
/-- If `T` and `T'` are terminal, they are isomorphic. -/
@[simps]
def is_terminal.unique_up_to_iso {T T' : C} (hT : is_terminal T) (hT' : is_terminal T') : T ≅ T' :=
{ hom := hT'.from _,
inv := hT.from _ }
/-- If `I` and `I'` are initial, they are isomorphic. -/
@[simps]
def is_initial.unique_up_to_iso {I I' : C} (hI : is_initial I) (hI' : is_initial I') : I ≅ I' :=
{ hom := hI.to _,
inv := hI'.to _ }
variable (C)
/--
A category has a terminal object if it has a limit over the empty diagram.
Use `has_terminal_of_unique` to construct instances.
-/
abbreviation has_terminal := has_limits_of_shape (discrete.{0} pempty) C
/--
A category has an initial object if it has a colimit over the empty diagram.
Use `has_initial_of_unique` to construct instances.
-/
abbreviation has_initial := has_colimits_of_shape (discrete.{0} pempty) C
section univ
variables (X : C) {F₁ : discrete.{w} pempty ⥤ C} {F₂ : discrete.{w'} pempty ⥤ C}
/-- Being terminal is independent of the empty diagram, its universe, and the cone over it,
as long as the cone points are isomorphic. -/
def is_limit_change_empty_cone {c₁ : cone F₁} (hl : is_limit c₁)
(c₂ : cone F₂) (hi : c₁.X ≅ c₂.X) : is_limit c₂ :=
{ lift := λ c, hl.lift ⟨c.X, by tidy⟩ ≫ hi.hom,
fac' := λ _ j, j.as.elim,
uniq' := λ c f _, by { erw ← hl.uniq ⟨c.X, by tidy⟩ (f ≫ hi.inv) (λ j, j.as.elim), simp } }
/-- Replacing an empty cone in `is_limit` by another with the same cone point
is an equivalence. -/
def is_limit_empty_cone_equiv (c₁ : cone F₁) (c₂ : cone F₂) (h : c₁.X ≅ c₂.X) :
is_limit c₁ ≃ is_limit c₂ :=
{ to_fun := λ hl, is_limit_change_empty_cone C hl c₂ h,
inv_fun := λ hl, is_limit_change_empty_cone C hl c₁ h.symm,
left_inv := by tidy,
right_inv := by tidy }
lemma has_terminal_change_diagram (h : has_limit F₁) : has_limit F₂ :=
⟨⟨⟨⟨limit F₁, by tidy⟩, is_limit_change_empty_cone C (limit.is_limit F₁) _ (eq_to_iso rfl)⟩⟩⟩
lemma has_terminal_change_universe [h : has_limits_of_shape (discrete.{w} pempty) C] :
has_limits_of_shape (discrete.{w'} pempty) C :=
{ has_limit := λ J, has_terminal_change_diagram C (let f := h.1 in f (functor.empty C)) }
/-- Being initial is independent of the empty diagram, its universe, and the cocone over it,
as long as the cocone points are isomorphic. -/
def is_colimit_change_empty_cocone {c₁ : cocone F₁} (hl : is_colimit c₁)
(c₂ : cocone F₂) (hi : c₁.X ≅ c₂.X) : is_colimit c₂ :=
{ desc := λ c, hi.inv ≫ hl.desc ⟨c.X, by tidy⟩,
fac' := λ _ j, j.as.elim,
uniq' := λ c f _, by { erw ← hl.uniq ⟨c.X, by tidy⟩ (hi.hom ≫ f) (λ j, j.as.elim), simp } }
/-- Replacing an empty cocone in `is_colimit` by another with the same cocone point
is an equivalence. -/
def is_colimit_empty_cocone_equiv (c₁ : cocone F₁) (c₂ : cocone F₂) (h : c₁.X ≅ c₂.X) :
is_colimit c₁ ≃ is_colimit c₂ :=
{ to_fun := λ hl, is_colimit_change_empty_cocone C hl c₂ h,
inv_fun := λ hl, is_colimit_change_empty_cocone C hl c₁ h.symm,
left_inv := by tidy,
right_inv := by tidy }
lemma has_initial_change_diagram (h : has_colimit F₁) : has_colimit F₂ :=
⟨⟨⟨⟨colimit F₁, by tidy⟩,
is_colimit_change_empty_cocone C (colimit.is_colimit F₁) _ (eq_to_iso rfl)⟩⟩⟩
lemma has_initial_change_universe [h : has_colimits_of_shape (discrete.{w} pempty) C] :
has_colimits_of_shape (discrete.{w'} pempty) C :=
{ has_colimit := λ J, has_initial_change_diagram C (let f := h.1 in f (functor.empty C)) }
end univ
/--
An arbitrary choice of terminal object, if one exists.
You can use the notation `⊤_ C`.
This object is characterized by having a unique morphism from any object.
-/
abbreviation terminal [has_terminal C] : C := limit (functor.empty.{0} C)
/--
An arbitrary choice of initial object, if one exists.
You can use the notation `⊥_ C`.
This object is characterized by having a unique morphism to any object.
-/
abbreviation initial [has_initial C] : C := colimit (functor.empty.{0} C)
notation `⊤_ ` C:20 := terminal C
notation `⊥_ ` C:20 := initial C
section
variables {C}
/-- We can more explicitly show that a category has a terminal object by specifying the object,
and showing there is a unique morphism to it from any other object. -/
lemma has_terminal_of_unique (X : C) [h : Π Y : C, unique (Y ⟶ X)] : has_terminal C :=
{ has_limit := λ F, has_limit.mk ⟨_, (is_terminal_equiv_unique F X).inv_fun h⟩ }
/-- We can more explicitly show that a category has an initial object by specifying the object,
and showing there is a unique morphism from it to any other object. -/
lemma has_initial_of_unique (X : C) [h : Π Y : C, unique (X ⟶ Y)] : has_initial C :=
{ has_colimit := λ F, has_colimit.mk ⟨_, (is_initial_equiv_unique F X).inv_fun h⟩ }
/-- The map from an object to the terminal object. -/
abbreviation terminal.from [has_terminal C] (P : C) : P ⟶ ⊤_ C :=
limit.lift (functor.empty C) (as_empty_cone P)
/-- The map to an object from the initial object. -/
abbreviation initial.to [has_initial C] (P : C) : ⊥_ C ⟶ P :=
colimit.desc (functor.empty C) (as_empty_cocone P)
/-- A terminal object is terminal. -/
def terminal_is_terminal [has_terminal C] : is_terminal (⊤_ C) :=
{ lift := λ s, terminal.from _ }
/-- An initial object is initial. -/
def initial_is_initial [has_initial C] : is_initial (⊥_ C) :=
{ desc := λ s, initial.to _ }
instance unique_to_terminal [has_terminal C] (P : C) : unique (P ⟶ ⊤_ C) :=
is_terminal_equiv_unique _ (⊤_ C) terminal_is_terminal P
instance unique_from_initial [has_initial C] (P : C) : unique (⊥_ C ⟶ P) :=
is_initial_equiv_unique _ (⊥_ C) initial_is_initial P
@[simp] lemma terminal.comp_from [has_terminal C] {P Q : C} (f : P ⟶ Q) :
f ≫ terminal.from Q = terminal.from P :=
by tidy
@[simp] lemma initial.to_comp [has_initial C] {P Q : C} (f : P ⟶ Q) :
initial.to P ≫ f = initial.to Q :=
by tidy
/-- The (unique) isomorphism between the chosen initial object and any other initial object. -/
@[simp] def initial_iso_is_initial [has_initial C] {P : C} (t : is_initial P) : ⊥_ C ≅ P :=
initial_is_initial.unique_up_to_iso t
/-- The (unique) isomorphism between the chosen terminal object and any other terminal object. -/
@[simp] def terminal_iso_is_terminal [has_terminal C] {P : C} (t : is_terminal P) : ⊤_ C ≅ P :=
terminal_is_terminal.unique_up_to_iso t
/-- Any morphism from a terminal object is split mono. -/
instance terminal.split_mono_from {Y : C} [has_terminal C] (f : ⊤_ C ⟶ Y) : split_mono f :=
is_terminal.split_mono_from terminal_is_terminal _
/-- Any morphism to an initial object is split epi. -/
instance initial.split_epi_to {Y : C} [has_initial C] (f : Y ⟶ ⊥_ C) : split_epi f :=
is_initial.split_epi_to initial_is_initial _
/-- An initial object is terminal in the opposite category. -/
def terminal_op_of_initial {X : C} (t : is_initial X) : is_terminal (opposite.op X) :=
{ lift := λ s, (t.to s.X.unop).op,
uniq' := λ s m w, quiver.hom.unop_inj (t.hom_ext _ _) }
/-- An initial object in the opposite category is terminal in the original category. -/
def terminal_unop_of_initial {X : Cᵒᵖ} (t : is_initial X) : is_terminal X.unop :=
{ lift := λ s, (t.to (opposite.op s.X)).unop,
uniq' := λ s m w, quiver.hom.op_inj (t.hom_ext _ _) }
/-- A terminal object is initial in the opposite category. -/
def initial_op_of_terminal {X : C} (t : is_terminal X) : is_initial (opposite.op X) :=
{ desc := λ s, (t.from s.X.unop).op,
uniq' := λ s m w, quiver.hom.unop_inj (t.hom_ext _ _) }
/-- A terminal object in the opposite category is initial in the original category. -/
def initial_unop_of_terminal {X : Cᵒᵖ} (t : is_terminal X) : is_initial X.unop :=
{ desc := λ s, (t.from (opposite.op s.X)).unop,
uniq' := λ s m w, quiver.hom.op_inj (t.hom_ext _ _) }
instance {J : Type*} [category J] {C : Type*} [category C] [has_terminal C] :
has_limit ((category_theory.functor.const J).obj (⊤_ C)) :=
has_limit.mk
{ cone :=
{ X := ⊤_ C,
π := { app := λ _, terminal.from _, }, },
is_limit :=
{ lift := λ s, terminal.from _, }, }
/-- The limit of the constant `⊤_ C` functor is `⊤_ C`. -/
@[simps hom]
def limit_const_terminal {J : Type*} [category J] {C : Type*} [category C] [has_terminal C] :
limit ((category_theory.functor.const J).obj (⊤_ C)) ≅ ⊤_ C :=
{ hom := terminal.from _,
inv := limit.lift ((category_theory.functor.const J).obj (⊤_ C))
{ X := ⊤_ C, π := { app := λ j, terminal.from _, }}, }
@[simp, reassoc] lemma limit_const_terminal_inv_π
{J : Type*} [category J] {C : Type*} [category C] [has_terminal C] {j : J} :
limit_const_terminal.inv ≫ limit.π ((category_theory.functor.const J).obj (⊤_ C)) j =
terminal.from _ :=
by ext ⟨⟨⟩⟩
instance {J : Type*} [category J] {C : Type*} [category C] [has_initial C] :
has_colimit ((category_theory.functor.const J).obj (⊥_ C)) :=
has_colimit.mk
{ cocone :=
{ X := ⊥_ C,
ι := { app := λ _, initial.to _, }, },
is_colimit :=
{ desc := λ s, initial.to _, }, }
/-- The colimit of the constant `⊥_ C` functor is `⊥_ C`. -/
@[simps inv]
def colimit_const_initial {J : Type*} [category J] {C : Type*} [category C] [has_initial C] :
colimit ((category_theory.functor.const J).obj (⊥_ C)) ≅ ⊥_ C :=
{ hom := colimit.desc ((category_theory.functor.const J).obj (⊥_ C))
{ X := ⊥_ C, ι := { app := λ j, initial.to _, }, },
inv := initial.to _, }
@[simp, reassoc] lemma ι_colimit_const_initial_hom
{J : Type*} [category J] {C : Type*} [category C] [has_initial C] {j : J} :
colimit.ι ((category_theory.functor.const J).obj (⊥_ C)) j ≫ colimit_const_initial.hom =
initial.to _ :=
by ext ⟨⟨⟩⟩
/-- A category is a `initial_mono_class` if the canonical morphism of an initial object is a
monomorphism. In practice, this is most useful when given an arbitrary morphism out of the chosen
initial object, see `initial.mono_from`.
Given a terminal object, this is equivalent to the assumption that the unique morphism from initial
to terminal is a monomorphism, which is the second of Freyd's axioms for an AT category.
TODO: This is a condition satisfied by categories with zero objects and morphisms.
-/
class initial_mono_class (C : Type u₁) [category.{v₁} C] : Prop :=
(is_initial_mono_from : ∀ {I} (X : C) (hI : is_initial I), mono (hI.to X))
lemma is_initial.mono_from [initial_mono_class C] {I} {X : C} (hI : is_initial I) (f : I ⟶ X) :
mono f :=
begin
rw hI.hom_ext f (hI.to X),
apply initial_mono_class.is_initial_mono_from,
end
@[priority 100]
instance initial.mono_from [has_initial C] [initial_mono_class C] (X : C) (f : ⊥_ C ⟶ X) :
mono f :=
initial_is_initial.mono_from f
/-- To show a category is a `initial_mono_class` it suffices to give an initial object such that
every morphism out of it is a monomorphism. -/
lemma initial_mono_class.of_is_initial {I : C} (hI : is_initial I) (h : ∀ X, mono (hI.to X)) :
initial_mono_class C :=
{ is_initial_mono_from := λ I' X hI',
begin
rw hI'.hom_ext (hI'.to X) ((hI'.unique_up_to_iso hI).hom ≫ hI.to X),
apply mono_comp,
end }
/-- To show a category is a `initial_mono_class` it suffices to show every morphism out of the
initial object is a monomorphism. -/
lemma initial_mono_class.of_initial [has_initial C] (h : ∀ X : C, mono (initial.to X)) :
initial_mono_class C :=
initial_mono_class.of_is_initial initial_is_initial h
/-- To show a category is a `initial_mono_class` it suffices to show the unique morphism from an
initial object to a terminal object is a monomorphism. -/
lemma initial_mono_class.of_is_terminal {I T : C} (hI : is_initial I) (hT : is_terminal T)
(f : mono (hI.to T)) :
initial_mono_class C :=
initial_mono_class.of_is_initial hI (λ X, mono_of_mono_fac (hI.hom_ext (_ ≫ hT.from X) (hI.to T)))
/-- To show a category is a `initial_mono_class` it suffices to show the unique morphism from the
initial object to a terminal object is a monomorphism. -/
lemma initial_mono_class.of_terminal [has_initial C] [has_terminal C]
(h : mono (initial.to (⊤_ C))) :
initial_mono_class C :=
initial_mono_class.of_is_terminal initial_is_initial terminal_is_terminal h
section comparison
variables {D : Type u₂} [category.{v₂} D] (G : C ⥤ D)
/--
The comparison morphism from the image of a terminal object to the terminal object in the target
category.
This is an isomorphism iff `G` preserves terminal objects, see
`category_theory.limits.preserves_terminal.of_iso_comparison`.
-/
def terminal_comparison [has_terminal C] [has_terminal D] :
G.obj (⊤_ C) ⟶ ⊤_ D :=
terminal.from _
/--
The comparison morphism from the initial object in the target category to the image of the initial
object.
-/
-- TODO: Show this is an isomorphism if and only if `G` preserves initial objects.
def initial_comparison [has_initial C] [has_initial D] :
⊥_ D ⟶ G.obj (⊥_ C) :=
initial.to _
end comparison
variables {J : Type u} [category.{v} J]
/-- From a functor `F : J ⥤ C`, given an initial object of `J`, construct a cone for `J`.
In `limit_of_diagram_initial` we show it is a limit cone. -/
@[simps]
def cone_of_diagram_initial
{X : J} (tX : is_initial X) (F : J ⥤ C) : cone F :=
{ X := F.obj X,
π :=
{ app := λ j, F.map (tX.to j),
naturality' := λ j j' k,
begin
dsimp,
rw [← F.map_comp, category.id_comp, tX.hom_ext (tX.to j ≫ k) (tX.to j')],
end } }
/-- From a functor `F : J ⥤ C`, given an initial object of `J`, show the cone
`cone_of_diagram_initial` is a limit. -/
def limit_of_diagram_initial
{X : J} (tX : is_initial X) (F : J ⥤ C) :
is_limit (cone_of_diagram_initial tX F) :=
{ lift := λ s, s.π.app X,
uniq' := λ s m w,
begin
rw [← w X, cone_of_diagram_initial_π_app, tX.hom_ext (tX.to X) (𝟙 _)],
dsimp, simp -- See note [dsimp, simp]
end}
-- This is reducible to allow usage of lemmas about `cone_point_unique_up_to_iso`.
/-- For a functor `F : J ⥤ C`, if `J` has an initial object then the image of it is isomorphic
to the limit of `F`. -/
@[reducible]
def limit_of_initial (F : J ⥤ C)
[has_initial J] [has_limit F] :
limit F ≅ F.obj (⊥_ J) :=
is_limit.cone_point_unique_up_to_iso
(limit.is_limit _)
(limit_of_diagram_initial initial_is_initial F)
/-- From a functor `F : J ⥤ C`, given a terminal object of `J`, construct a cone for `J`,
provided that the morphisms in the diagram are isomorphisms.
In `limit_of_diagram_terminal` we show it is a limit cone. -/
@[simps]
def cone_of_diagram_terminal {X : J} (hX : is_terminal X)
(F : J ⥤ C) [∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] : cone F :=
{ X := F.obj X,
π :=
{ app := λ i, inv (F.map (hX.from _)),
naturality' := begin
intros i j f,
dsimp,
simp only [is_iso.eq_inv_comp, is_iso.comp_inv_eq, category.id_comp,
← F.map_comp, hX.hom_ext (hX.from i) (f ≫ hX.from j)],
end } }
/-- From a functor `F : J ⥤ C`, given a terminal object of `J` and that the morphisms in the
diagram are isomorphisms, show the cone `cone_of_diagram_terminal` is a limit. -/
def limit_of_diagram_terminal {X : J} (hX : is_terminal X)
(F : J ⥤ C) [∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] :
is_limit (cone_of_diagram_terminal hX F) :=
{ lift := λ S, S.π.app _ }
-- This is reducible to allow usage of lemmas about `cone_point_unique_up_to_iso`.
/-- For a functor `F : J ⥤ C`, if `J` has a terminal object and all the morphisms in the diagram
are isomorphisms, then the image of the terminal object is isomorphic to the limit of `F`. -/
@[reducible]
def limit_of_terminal (F : J ⥤ C)
[has_terminal J] [has_limit F] [∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] :
limit F ≅ F.obj (⊤_ J) :=
is_limit.cone_point_unique_up_to_iso
(limit.is_limit _)
(limit_of_diagram_terminal terminal_is_terminal F)
/-- From a functor `F : J ⥤ C`, given a terminal object of `J`, construct a cocone for `J`.
In `colimit_of_diagram_terminal` we show it is a colimit cocone. -/
@[simps]
def cocone_of_diagram_terminal
{X : J} (tX : is_terminal X) (F : J ⥤ C) : cocone F :=
{ X := F.obj X,
ι :=
{ app := λ j, F.map (tX.from j),
naturality' := λ j j' k,
begin
dsimp,
rw [← F.map_comp, category.comp_id, tX.hom_ext (k ≫ tX.from j') (tX.from j)],
end } }
/-- From a functor `F : J ⥤ C`, given a terminal object of `J`, show the cocone
`cocone_of_diagram_terminal` is a colimit. -/
def colimit_of_diagram_terminal
{X : J} (tX : is_terminal X) (F : J ⥤ C) :
is_colimit (cocone_of_diagram_terminal tX F) :=
{ desc := λ s, s.ι.app X,
uniq' := λ s m w,
by { rw [← w X, cocone_of_diagram_terminal_ι_app, tX.hom_ext (tX.from X) (𝟙 _)], simp } }
-- This is reducible to allow usage of lemmas about `cocone_point_unique_up_to_iso`.
/-- For a functor `F : J ⥤ C`, if `J` has a terminal object then the image of it is isomorphic
to the colimit of `F`. -/
@[reducible]
def colimit_of_terminal (F : J ⥤ C)
[has_terminal J] [has_colimit F] :
colimit F ≅ F.obj (⊤_ J) :=
is_colimit.cocone_point_unique_up_to_iso
(colimit.is_colimit _)
(colimit_of_diagram_terminal terminal_is_terminal F)
/-- From a functor `F : J ⥤ C`, given an initial object of `J`, construct a cocone for `J`,
provided that the morphisms in the diagram are isomorphisms.
In `colimit_of_diagram_initial` we show it is a colimit cocone. -/
@[simps]
def cocone_of_diagram_initial {X : J} (hX : is_initial X) (F : J ⥤ C)
[∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] : cocone F :=
{ X := F.obj X,
ι :=
{ app := λ i, inv (F.map (hX.to _)),
naturality' := begin
intros i j f,
dsimp,
simp only [is_iso.eq_inv_comp, is_iso.comp_inv_eq, category.comp_id,
← F.map_comp, hX.hom_ext (hX.to i ≫ f) (hX.to j)],
end } }
/-- From a functor `F : J ⥤ C`, given an initial object of `J` and that the morphisms in the
diagram are isomorphisms, show the cone `cocone_of_diagram_initial` is a colimit. -/
def colimit_of_diagram_initial {X : J} (hX : is_initial X) (F : J ⥤ C)
[∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] : is_colimit (cocone_of_diagram_initial hX F) :=
{ desc := λ S, S.ι.app _ }
-- This is reducible to allow usage of lemmas about `cocone_point_unique_up_to_iso`.
/-- For a functor `F : J ⥤ C`, if `J` has an initial object and all the morphisms in the diagram
are isomorphisms, then the image of the initial object is isomorphic to the colimit of `F`. -/
@[reducible]
def colimit_of_initial (F : J ⥤ C)
[has_initial J] [has_colimit F] [∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] :
colimit F ≅ F.obj (⊥_ J) :=
is_colimit.cocone_point_unique_up_to_iso
(colimit.is_colimit _)
(colimit_of_diagram_initial initial_is_initial _)
/--
If `j` is initial in the index category, then the map `limit.π F j` is an isomorphism.
-/
lemma is_iso_π_of_is_initial {j : J} (I : is_initial j) (F : J ⥤ C) [has_limit F] :
is_iso (limit.π F j) :=
⟨⟨limit.lift _ (cone_of_diagram_initial I F), ⟨by { ext, simp }, by simp⟩⟩⟩
instance is_iso_π_initial [has_initial J] (F : J ⥤ C) [has_limit F] :
is_iso (limit.π F (⊥_ J)) :=
is_iso_π_of_is_initial (initial_is_initial) F
lemma is_iso_π_of_is_terminal {j : J} (I : is_terminal j) (F : J ⥤ C)
[has_limit F] [∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] : is_iso (limit.π F j) :=
⟨⟨limit.lift _ (cone_of_diagram_terminal I F), by { ext, simp }, by simp ⟩⟩
instance is_iso_π_terminal [has_terminal J] (F : J ⥤ C) [has_limit F]
[∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] : is_iso (limit.π F (⊤_ J)) :=
is_iso_π_of_is_terminal terminal_is_terminal F
/--
If `j` is terminal in the index category, then the map `colimit.ι F j` is an isomorphism.
-/
lemma is_iso_ι_of_is_terminal {j : J} (I : is_terminal j) (F : J ⥤ C) [has_colimit F] :
is_iso (colimit.ι F j) :=
⟨⟨colimit.desc _ (cocone_of_diagram_terminal I F), ⟨by simp, by { ext, simp }⟩⟩⟩
instance is_iso_ι_terminal [has_terminal J] (F : J ⥤ C) [has_colimit F] :
is_iso (colimit.ι F (⊤_ J)) :=
is_iso_ι_of_is_terminal (terminal_is_terminal) F
lemma is_iso_ι_of_is_initial {j : J} (I : is_initial j) (F : J ⥤ C)
[has_colimit F] [∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] : is_iso (colimit.ι F j) :=
⟨⟨colimit.desc _ (cocone_of_diagram_initial I F), ⟨by tidy, by { ext, simp }⟩⟩⟩
instance is_iso_ι_initial [has_initial J] (F : J ⥤ C) [has_colimit F]
[∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] : is_iso (colimit.ι F (⊥_ J)) :=
is_iso_ι_of_is_initial initial_is_initial F
end
end category_theory.limits
|
{-# OPTIONS --cubical --safe #-}
module Cubical.Structures.Rng where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
open import Cubical.Foundations.SIP renaming (SNS-PathP to SNS)
open import Cubical.Structures.NAryOp
open import Cubical.Structures.Semigroup hiding (⟨_⟩)
open import Cubical.Structures.AbGroup
private
variable
ℓ ℓ' : Level
raw-rng-structure : Type ℓ → Type ℓ
raw-rng-structure X = (X → X → X) × (X → X → X)
raw-rng-is-SNS : SNS {ℓ} raw-rng-structure _
raw-rng-is-SNS = join-SNS (nAryFunIso 2) (nAryFunSNS 2) (nAryFunIso 2) (nAryFunSNS 2)
rng-axioms : (X : Type ℓ) (s : raw-rng-structure X) → Type ℓ
rng-axioms X (_·_ , _+_) = abelian-group-axioms X _·_ ×
semigroup-axioms X _+_ ×
((x y z : X) → x · (y + z) ≡ (x · y) + (x · z)) ×
((x y z : X) → (x + y) · z ≡ (x · z) + (y · z))
rng-structure : Type ℓ → Type ℓ
rng-structure = add-to-structure raw-rng-structure rng-axioms
Rngs : Type (ℓ-suc ℓ)
Rngs {ℓ} = TypeWithStr ℓ rng-structure
rng-iso : StrIso rng-structure ℓ
rng-iso = add-to-iso (join-iso (nAryFunIso 2) (nAryFunIso 2)) rng-axioms
rng-axioms-isProp : (X : Type ℓ) (s : raw-rng-structure X) → isProp (rng-axioms X s)
rng-axioms-isProp X (_·_ , _+_) = isPropΣ (abelian-group-axioms-isProp X _·_)
λ _ → isPropΣ (semigroup-axiom-isProp X _+_)
λ { (isSetX , _) → isPropΣ (isPropΠ3 (λ _ _ _ → isSetX _ _))
λ _ → isPropΠ3 (λ _ _ _ → isSetX _ _)}
rng-is-SNS : SNS {ℓ} rng-structure rng-iso
rng-is-SNS = add-axioms-SNS _ rng-axioms-isProp raw-rng-is-SNS
RngPath : (M N : Rngs {ℓ}) → (M ≃[ rng-iso ] N) ≃ (M ≡ N)
RngPath = SIP rng-is-SNS
|
(** Coq coding by choukh, Sep 2021 **)
Require Export ZFC.LargeOrdinals.SidedTetration.
Require Import ZFC.LargeOrdinals.GeneralEpsilon.
Import OrdinalClass 𝐎𝐍Operation.
Local Hint Resolve
add_ran mul_ran exp_ran ordAdd_ran ordMul_ran
preOrdExp_ran ordExp_ran ordTetL_ran ordTet0_ran
ε_operative bunion_of_ords_is_ord : core.
(** 迭代幂次 **)
(** Tetration **)
(* adapted from https://math.stackexchange.com/a/3768438/815418 *)
Definition OrdTet := λ α, Operation 1 (λ ξ, α ^ ξ ∪ ξ ^ α).
Notation "α ^^ β" := (OrdTet α β) (at level 25) : OrdArith_scope.
Theorem ordTet_0_r : ∀α ⋵ 𝐎𝐍, α ^^ 0 = 1.
Proof. intros α H. apply operation_0; auto. Qed.
Theorem ordTet_suc : ∀ α β ⋵ 𝐎𝐍, α ^^ β⁺ = α ^ (α ^^ β) ∪ (α ^^ β) ^ α.
Proof. intros α Hα β Hβ. apply operation_suc; auto. Qed.
Theorem ordTet_limit : ∀α ⋵ 𝐎𝐍, continuous (OrdTet α).
Proof. intros α Hα. apply operation_limit; auto. Qed.
Theorem ordTet_ran : ∀ α β ⋵ 𝐎𝐍, α ^^ β ⋵ 𝐎𝐍.
Proof with nauto.
intros α Hα β Hβ. apply operation_operative...
Qed.
Local Hint Resolve ordTet_ran : core.
Theorem ordTet_0_l : ∀α ⋵ 𝐎𝐍, 0 ^^ α = 1.
Proof with neauto.
ord_induction. intros α Hα IH.
ord_destruct α.
- subst. apply ordTet_0_r...
- destruct Hsuc as [γ [Hγ H]]. subst.
rewrite ordTet_suc, IH, ordExp_0_l, ordExp_0_r, ord_max_r...
- rewrite ordTet_limit... ext.
+ apply FUnionE in H as [β [Hβ H]]. rewrite IH in H...
+ apply EmptyNE in H0 as [β Hβ]. eapply FUnionI... rewrite IH...
Qed.
Theorem ordTet_1_r : ∀α ⋵ 𝐎𝐍, α ≠ 0 → α ^^ 1 = α.
Proof with nauto.
intros α H H0. rewrite pred, ordTet_suc...
rewrite ordTet_0_r, ordExp_1_r, ordExp_1_l, ord_max_l...
apply ord_suc_correct...
Qed.
Theorem ordTet_1_l : ∀α ⋵ 𝐎𝐍, 1 ^^ α = 1.
Proof with neauto.
ord_induction. intros α Hα IH.
ord_destruct α.
- subst. apply ordTet_0_r...
- destruct Hsuc as [γ [Hγ H]]. subst.
rewrite ordTet_suc, IH, ordExp_1_r, ord_max_r...
- rewrite ordTet_limit... ext.
+ apply FUnionE in H as [β [Hβ H]]. rewrite IH in H...
+ apply EmptyNE in H0 as [β Hβ]. eapply FUnionI... rewrite IH...
Qed.
Theorem ordTet_2_r : ∀α ⋵ 𝐎𝐍, α ≠ 0 → α ^^ 2 = α ^ α.
Proof.
intros α Hα Hα0.
rewrite pred, ordTet_suc, ordTet_1_r, ord_max_r; nauto.
Qed.
Theorem ordTet_eq_L : ∀α ⋵ 𝐎𝐍, α ≠ 0 → ∀n ∈ ω, α ^^ n⁺ = α ^^ᴸ n.
Proof with nauto.
intros α Hα Hα0 n Hn.
destruct (classic (α = 1)) as [|Hα1]. {
subst. rewrite ordTet_1_l, ordTetL_1_l...
}
destruct (classic (α = 2)) as [|Hα2]. {
subst. ω_induction n.
- rewrite ordTet_1_r, ordTetL_0...
- destruct (classic (m = 0)) as [|Hm0]. {
subst. rewrite ordTet_suc, IH...
rewrite ordTetL_suc, ordTetL_0, ord_max_l...
}
rewrite ordTet_suc, IH, ordTetL_suc, ord_max_l...
apply ordTetL_exp_r_le_l...
}
ω_induction n.
- rewrite ordTet_1_r, ordTetL_0...
- destruct (classic (m = 0)) as [|Hm0]. {
subst. rewrite ordTet_suc, IH...
rewrite ordTetL_suc, ordTetL_0, ord_max_l...
}
rewrite ordTet_suc, IH, ordTetL_suc, ord_max_l...
left. apply ordTetL_exp_r_lt_l... contra.
apply ord_le_iff_not_gt in H as []...
rewrite two in H. apply TwoE in H as []... rewrite <- one in H...
Qed.
Theorem ordTet_suc_l : ∀α ⋵ 𝐎𝐍, α ≠ 0 → ∀n ∈ ω, α ^^ n⁺ = α ^ (α ^^ n).
Proof with auto.
intros α Hα Hα0 n Hn.
destruct (classic (α = 1)) as [|Hα1]. {
subst. rewrite ordTet_1_l, ordTet_1_l, ordExp_1_r...
}
ω_induction n.
- rewrite ordTet_1_r, ordTet_0_r, ordExp_1_r...
- rewrite ordTet_eq_L, ordTet_eq_L, ordTetL_suc...
apply ω_inductive...
Qed.
Theorem ordTet_ω_eq_ε_0 : ∀α ⋵ 𝐎𝐍, 1 ∈ α → α ^^ ω = ε α 0.
Proof with neauto.
intros α Hα Hα1.
apply ord_gt_1_neq_0_1 in Hα1 as [Hα0 Hα1]...
rewrite ordTet_limit... ext.
- apply FUnionE in H as [n [Hn Hx]].
ω_destruct n.
+ rewrite ordTet_0_r, one in Hx...
apply SingE in Hx. subst. apply ε_has_n...
+ rewrite ε_0... rewrite ordTet_eq_L in Hx... eapply FUnionI...
- rewrite ε_0 in H... apply FUnionE in H as [n [Hn Hx]].
rewrite <- ordTet_eq_L in Hx...
apply (FUnionI _ _ n⁺)... apply ω_inductive...
Qed.
Lemma ordTet_neq_0 : ∀ α β ⋵ 𝐎𝐍, α ^^ β ≠ 0.
Proof with eauto.
intros α Hα. ord_induction. intros β Hβ IH H.
ord_destruct β.
- subst. rewrite ordTet_0_r in H...
- destruct Hsuc as [γ [Hγ Heq]]. subst.
rewrite ordTet_suc in H...
apply union_eq_empty in H as [].
+ apply EmptyNI in H... exists (α ^ α ^^ γ)... apply PairI1.
+ symmetry in H. apply single_eq_pair in H as [H Heq].
symmetry in H. apply ordExp_eq_0 in H...
subst. rewrite ordExp_0_l, ordExp_0_r in Heq...
- rewrite ordTet_limit in H...
apply union_eq_empty in H as [].
+ apply repl_eq_empty in H. exfalso...
+ apply EmptyNE in H0 as [γ Hγ].
assert (Hoγ: γ ⋵ 𝐎𝐍). eapply ord_is_ords...
apply sucord_in_limord in Hγ...
eapply repl_eq_1 in Hγ as H0... eapply IH...
Qed.
Local Hint Resolve ordTet_neq_0 : core.
Lemma ordTet_gt_1 : ∀ α β ⋵ 𝐎𝐍, 1 ∈ α → β ≠ 0 → 1 ∈ α ^^ β.
Proof with neauto.
intros α Hα. ord_induction. intros β Hβ IH Hα1 Hβ0.
ord_destruct β.
- subst...
- destruct Hsuc as [γ [Hγ Heq]]. subst.
destruct (classic (γ = 0)) as [|Hγ0]. {
subst. rewrite ordTet_1_r... apply ord_gt_1_neq_0_1...
}
rewrite ordTet_suc... eapply ord_trans... auto.
apply BUnionI1. apply ordExp_enlarge_r...
- rewrite ordTet_limit...
apply EmptyNE in H0 as [γ Hγ].
assert (Hoγ: γ ⋵ 𝐎𝐍). eapply ord_is_ords...
eapply FUnionI. apply sucord_in_limord...
destruct (classic (γ = 0)) as [|Hγ0]. {
subst. rewrite ordTet_1_r... apply ord_gt_1_neq_0_1...
}
eapply ord_trans_lt_le. auto. apply IH...
rewrite ordTet_suc... left. apply BUnionI2. apply ordExp_enlarge_r...
Qed.
Local Hint Resolve ordTet_gt_1 : core.
Theorem ordTet_eq_1 : ∀ α β ⋵ 𝐎𝐍, α ^^ β = 1 → α = 0 ∨ α = 1 ∨ β = 0.
Proof with neauto.
intros α Hα β Hβ H.
destruct (classic (α = 0))...
destruct (classic (α = 1))...
destruct (classic (β = 0))... exfalso.
apply (ord_irrefl 1)... rewrite <- H at 2.
apply ordTet_gt_1...
Qed.
Theorem ordTet_normal : ∀α ⋵ 𝐎𝐍, 1 ∈ α → normal (OrdTet α).
Proof with nauto.
intros α Hα Hα1. apply operation_normal...
fold (OrdTet α). intros x Hx.
destruct (classic (x = 0)) as [|Hx0]. {
subst. rewrite ordTet_0_r, ordTet_1_r... apply ord_gt_1_neq_0_1...
}
rewrite ordTet_suc... apply BUnionI2.
apply ordExp_enlarge_r...
Qed.
Fact ordTet_is_limord_r : ∀α ⋵ 𝐎𝐍, ∀𝜆 ⋵ 𝐎𝐍ˡⁱᵐ, 1 ∈ α → 𝜆 ≠ 0 → α ^^ 𝜆 ⋵ 𝐎𝐍ˡⁱᵐ.
Proof with neauto.
intros α Hα 𝜆 H𝜆 H1 H2.
apply normal_operation_limit_is_limit...
apply ordTet_normal...
Qed.
Fact ordTet_is_limord_l : ∀α ⋵ 𝐎𝐍, ∀𝜆 ⋵ 𝐎𝐍ˡⁱᵐ, α ≠ 0 → 𝜆 ≠ 0 → 𝜆 ^^ α ⋵ 𝐎𝐍ˡⁱᵐ.
Proof with neauto.
ord_induction. intros α Hα IH 𝜆 H𝜆 Hα0 H𝜆0.
ord_destruct α.
- subst...
- destruct Hsuc as [β [Hβ Heq]]. subst.
destruct (classic (β = 0)) as [|Hβ0]. {
subst. rewrite ordTet_1_r...
}
assert (H1: 1 ∈ 𝜆 ^^ β). {
apply ord_neq_0_1_gt_1...
intros H. apply ordTet_eq_1 in H as [|[]]...
apply (limord_iff_not_sucord 𝜆)... exists 0...
}
rewrite ordTet_suc...
epose proof (ord_comparability (𝜆 ^ 𝜆 ^^ β) _ (𝜆 ^^ β ^ 𝜆)) as []...
+ rewrite ord_max_r... apply ordExp_is_limord_r...
+ rewrite ord_max_l... apply ordExp_is_limord_l...
- rewrite ordTet_limit...
replace (sup {𝜆 ^^ α0 | α0 ∊ α}) with (sup {𝜆 ^^ α0 | α0 ∊ α - {0,}}).
+ apply union_of_limords_is_limord. intros x Hx.
apply ReplAx in Hx as [β [Hβ Hx]]. subst x.
apply SepE in Hβ as [Hβ Hβ']. apply SingNE in Hβ'. apply IH...
+ ext.
* apply FUnionE in H as [β [Hβ Hx]].
apply SepE1 in Hβ. eapply FUnionI...
* apply FUnionE in H as [β [Hβ Hx]].
assert (Hoβ: β ⋵ 𝐎𝐍). apply (ord_is_ords α)...
apply (FUnionI _ _ β⁺). apply SepI.
apply sucord_in_limord... apply SingNI. apply suc_neq_0.
eapply ord_trans... apply ordTet_normal...
eapply ord_trans_lt_le. auto. apply embed_ran. apply limord_ge_ω...
Unshelve. auto.
Qed.
Corollary ordTet_preserve_lt : ∀ α β γ ⋵ 𝐎𝐍, 1 ∈ α →
β ∈ γ ↔ α ^^ β ∈ α ^^ γ.
Proof with eauto.
intros α Hα β Hβ γ Hγ Hα1. split; intros H.
apply ordTet_normal...
destruct (classic (β = γ)).
- subst. exfalso. eapply ord_irrefl; revgoals...
- apply ord_connected in H0 as []...
apply (proj1 (ordTet_normal α Hα Hα1)) in H0...
exfalso. eapply ord_not_lt_gt; revgoals...
Qed.
Corollary ordTet_cancel : ∀ α β γ ⋵ 𝐎𝐍, 1 ∈ α → α ^^ β = α ^^ γ → β = γ.
Proof with eauto.
intros α Hα β Hβ γ Hγ H1 Heq.
contra. apply ord_connected in H as [Hlt|Hlt]...
- assert (α ^^ β ∈ α ^^ γ). apply ordTet_normal...
rewrite Heq in H. eapply ord_irrefl; revgoals...
- assert (α ^^ γ ∈ α ^^ β). apply ordTet_normal...
rewrite Heq in H. eapply ord_irrefl; revgoals...
Qed.
Theorem ordTet_preserve_le_l : ∀ α β γ ⋵ 𝐎𝐍,
α ⋸ β → α ^^ γ ⋸ β ^^ γ.
Proof with eauto.
intros α Hα β Hβ γ Hγ Hle.
generalize dependent γ.
ord_induction; intros γ Hγ IH.
ord_destruct γ.
- subst. rewrite ordTet_0_r, ordTet_0_r...
- destruct Hsuc as [δ [Hδ Heq]]. subst.
destruct Hle; [|subst; right]...
destruct (classic (β = 0)) as [|Hβ0]. {
subst. exfalso0.
}
destruct (classic (β = 1)) as [|Hβ1]. {
subst. rewrite one in H. apply SingE in H. subst.
rewrite ordTet_0_l, ordTet_1_l...
}
destruct (classic (α = 0)) as [|Hα0]. {
subst. rewrite ordTet_0_l...
}
destruct (classic (α = 1)) as [|Hα1]. {
subst. rewrite ordTet_1_l...
}
destruct (classic (δ = 0)) as [|Hδ0]. {
subst. rewrite ordTet_1_r, ordTet_1_r...
}
apply ord_le_iff_sub... rewrite ordTet_suc, ordTet_suc...
intros x Hx. apply BUnionE in Hx as [Hx|Hx].
+ apply BUnionI1. eapply ord_trans_lt_le... clear Hx.
eapply ord_trans_le. auto.
apply ordExp_preserve_le_r. 5: apply IH. 1-5: auto.
apply ordExp_preserve_le_l...
+ apply BUnionI2. eapply ord_trans_lt_le... clear Hx.
eapply ord_trans_le. auto.
apply ordExp_preserve_le_l. 4: apply IH. 1-4: auto.
apply ordExp_preserve_le_r...
- apply ord_le_iff_sub...
rewrite ordTet_limit, ordTet_limit...
intros x Hx. apply FUnionE in Hx as [δ [Hδ Hx]].
assert (Hoδ: δ ⋵ 𝐎𝐍). eapply ord_is_ords...
eapply FUnionI... apply IH in Hδ as []...
eapply ord_trans... congruence.
Qed.
Fact ordTet_preserve_le_r : ∀ α β γ ⋵ 𝐎𝐍, 1 ∈ γ →
α ⋸ β → γ ^^ α ⋸ γ ^^ β.
Proof.
intros α Hα β Hβ γ Hγ H0 [].
left. apply ordTet_preserve_lt; auto.
right. congruence.
Qed.
Lemma ordTet_enlarge_r : ∀ α β ⋵ 𝐎𝐍, 1 ∈ α → 1 ∈ β → α ∈ α ^^ β.
Proof with nauto.
intros α Hα β Hβ Hα1 Hβ1. rewrite <- ordTet_1_r at 1...
apply ordTet_preserve_lt... apply ord_gt_1_neq_0_1...
Qed.
Lemma ordTet_enlarge_l : ∀ α β ⋵ 𝐎𝐍, 1 ∈ β → α ⋸ β ^^ α.
Proof with auto.
intros α Hα β Hβ Hβ1.
apply monotone_operation_weakly_increasing...
apply ordTet_normal...
Qed.
Lemma ordTet_enlarge_lt : ∀ α β γ ⋵ 𝐎𝐍, γ ≠ 0 → α ∈ β → α ∈ β ^^ γ.
Proof with neauto.
intros α Hα β Hβ γ Hγ H0 Hle.
destruct (classic (β = 0)). subst. exfalso0.
destruct (classic (β = 1)). {
subst. rewrite one in Hle. apply SingE in Hle.
subst. apply ord_neq_0_gt_0...
}
destruct (classic (γ = 1)). subst. rewrite ordTet_1_r...
rewrite <- (ordTet_1_r β) in Hle...
eapply (ord_trans (β ^^ γ))...
apply ordTet_preserve_lt...
Qed.
Lemma ordTet_enlarge_le : ∀ α β γ ⋵ 𝐎𝐍, γ ≠ 0 → α ⋸ β → α ⋸ β ^^ γ.
Proof with neauto.
intros α Hα β Hβ γ Hγ H0 Hle.
destruct (classic (β = 0)). {
subst. rewrite ordTet_0_l...
destruct Hle. exfalso0. subst...
}
destruct (classic (β = 1)). subst. rewrite ordTet_1_l...
rewrite <- (ordTet_1_r β) in Hle...
eapply ord_trans_le. auto. apply Hle.
apply ordTet_preserve_le_r...
apply ord_le_iff_not_gt... intros Hγ1.
rewrite one in Hγ1. apply SingE in Hγ1...
Qed.
Section Epsilon.
Local Notation ε := (ε ω).
Local Hint Resolve ε_has_n ε_neq_0 : core.
Theorem ω_tet_ω : ω ^^ ω = ε 0.
Proof. apply ordTet_ω_eq_ε_0; nauto. Qed.
Lemma ε_exp_ω : ∀α ⋵ 𝐎𝐍, (ε α) ^ ω = (ω ^^⁰ 2) (ε α)⁺.
Proof with nauto.
intros α Hα.
rewrite (pred 2), ordTet0_suc...
rewrite (pred 1), ordTet0_suc...
rewrite ordTet0_0, <- ordAdd_1_r, <- ordExp_add, ordExp_1_r...
rewrite epsilon, <- ordExp_mul, epsilon...
Qed.
Fact ωtω_1 : ω ^^ (ω + 1) = (ω ^^⁰ 2) (ε 0)⁺.
Proof with nauto.
rewrite (pred 1), ordAdd_suc, ordTet_suc, ordAdd_0_r...
rewrite ordTet_ω_eq_ε_0, <- ε_exp_ω, ord_max_r...
rewrite epsilon... left. apply ordExp_enlarge_r...
Qed.
Fact ωtω_2 : ω ^^ (ω + 2) = (ω ^^⁰ 3) (ε 0)⁺.
Proof with nauto.
rewrite (pred 2), ordAdd_suc, ordTet_suc, ord_max_l...
- rewrite (pred 3), ordTet0_suc, ωtω_1...
- rewrite ωtω_1, <- ε_exp_ω... left.
rewrite <- (epsilon) at 1...
rewrite ordExp_mul, ordExp_mul...
apply ordExp_preserve_lt...
apply (ord_trans_le_lt _ (ε 0 ⋅ ε 0))...
apply ordMul_preserve_le_r... rewrite <- epsilon_mul...
apply ordMul_preserve_le_r... apply ε_ge_ω...
rewrite <- (ordExp_2_r)... apply ordExp_preserve_lt...
Qed.
Lemma ωtω_n_gt_ω : ∀n ∈ ω, n ≠ 0 → ω ∈ ω ^^ (ω + n).
Proof with nauto.
intros n Hn Hn0. apply ordTet_enlarge_r...
eapply ord_trans. auto. apply embed_ran. apply ordAdd_enlarge_r...
Qed.
Lemma ωtω_exp_ω_r_lt_l : ∀n ∈ ω, n ≠ 0 → ω ^^ (ω + n) ^ ω ⋸ ω ^ ω ^^ (ω + n).
Proof with nauto.
intros n Hn. ω_induction n; intros Hn0. exfalso...
destruct (classic (m = 0)) as [|Hm0].
- subst. rewrite suc, add_0_l, ωtω_1...
rewrite (pred 2), ordTet0_suc, ordTet0_1...
assert (Hε: ε 0 ⋵ 𝐎𝐍)... left.
rewrite ordExp_mul... apply ordExp_preserve_lt...
rewrite <- (ordExp_1_r ω) at 3...
rewrite ordExp_add... apply ordExp_preserve_lt...
rewrite ordExp_suc, epsilon...
rewrite <- ordAdd_1_r, ordAdd_assoc, ordAdd_1_1...
eapply (ord_trans _ _ _ (ε 0 + ε 0)).
apply ordAdd_preserve_lt... rewrite <- ordMul_2_r...
apply ordMul_preserve_lt...
- rewrite ordAdd_suc, ordTet_suc, ord_max_l...
rewrite ordExp_mul... apply ordExp_preserve_le_r...
eapply ord_trans_le; revgoals... left.
eapply (ord_trans _ _ _ (ω ^^ (ω + m) ⋅ ω ^^ (ω + m))).
apply ordMul_preserve_lt... apply ωtω_n_gt_ω...
rewrite <- ordExp_2_r... apply ordExp_preserve_lt...
eapply ord_trans. auto. apply embed_ran. apply ωtω_n_gt_ω...
Unshelve. 1-2: auto.
Qed.
Theorem ωtω_n : ∀n ∈ ω, n ≠ 0 → ω ^^ (ω + n) = (ω ^^⁰ n⁺) (ε 0)⁺.
Proof with nauto.
intros n Hn. ω_induction n; intros Hn0. exfalso...
destruct (classic (m = 0)) as [|Hm0]. subst. apply ωtω_1.
rewrite ordAdd_suc, ordTet0_suc, <- IH...
rewrite ordTet_suc, ord_max_l, IH...
apply ωtω_exp_ω_r_lt_l...
Qed.
Lemma ε_tet0_n : ∀α ⋵ 𝐎𝐍, ∀n ∈ ω, n ≠ 0 → (ε α ^^⁰ n) ω = (ω ^^⁰ n⁺) (ε α)⁺.
Proof with nauto.
intros α Hα n Hn. ω_induction n; intros H0. exfalso...
destruct (classic (m = 0)) as [Hm0|Hm0].
- subst. rewrite ordTet0_1, ε_exp_ω...
- rewrite ordTet0_suc, ordTet0_suc, IH, ordTet0_suc...
rewrite <- epsilon at 1...
rewrite ordExp_mul... 2: apply ordExp_ran... f_equal.
rewrite <- epsilon at 1... rewrite ordExp_add... f_equal.
ω_destruct m. exfalso...
rewrite <- epsilon at 1... rewrite ordTet0_suc...
apply ordAdd_ω_pow_absorption...
clear Hn n Hm0 H0 IH Hm. rename m into n.
ω_induction n.
+ rewrite ordTet0_0...
+ rewrite ordTet0_suc... eapply ord_trans_lt_le; revgoals.
apply ordExp_enlarge_l... apply IH. apply ordExp_ran...
Qed.
Theorem ωtω_ω : ω ^^ (ω + ω) = ε 1.
Proof with neauto.
rewrite pred, ε_suc...
erewrite <- (ordTet0_eq_ordTetL_ω (ε 0) _ ω)... 2: {
rewrite ε_0... apply (FUnionI _ _ 1)...
rewrite ordTetL_1_r... apply ordExp_enlarge_r...
}
rewrite ordTet_limit, ordTet0_limit...
2: apply ordAdd_is_limord...
2: intros H; apply ordAdd_eq_0 in H as []...
ext.
- apply FUnionE in H as [α [Hα H]].
assert (Hoα: α ⋵ 𝐎𝐍). apply (ord_is_ords (ω + ω))...
rewrite ordAdd_limit in Hα...
apply FUnionE in Hα as [n [Hn Hα]].
ω_destruct n.
+ apply (FUnionI _ _ 1)... rewrite ordTet0_1...
eapply ord_trans... rewrite <- ω_tet_ω.
eapply ord_trans. auto. apply ordTet_preserve_lt; revgoals...
rewrite ordAdd_0_r... apply ordExp_enlarge_r...
+ apply (FUnionI _ _ n⁺)... rewrite ε_tet0_n, <- ωtω_n...
eapply ord_trans... apply ordTet_preserve_lt...
- apply FUnionE in H as [n [Hn H]].
ω_destruct n.
+ rewrite ordTet0_0 in H...
apply (FUnionI _ _ 1)... 2: rewrite ordTet_1_r...
eapply ord_trans. auto. apply embed_ran.
apply ordAdd_enlarge_r...
+ rewrite ε_tet0_n, <- ωtω_n in H...
eapply FUnionI... apply ordAdd_preserve_lt...
Unshelve. apply ε_operative...
Qed.
Definition ε_k := λ k, ε k = ω ^^ (ω ⋅ k⁺).
Lemma ωtωk_1 : ∀k ∈ ω, ε_k k → ω ^^ (ω ⋅ k⁺ + 1) = (ω ^^⁰ 2) (ε k)⁺.
Proof with nauto.
intros k Hk IH.
rewrite (pred 1), ordAdd_suc, ordTet_suc, ordAdd_0_r...
repeat rewrite <- IH. rewrite <- ε_exp_ω, ord_max_r...
rewrite epsilon... left. apply ordExp_enlarge_r...
Qed.
Lemma ωtωk_exp_ω_r_lt_l : ∀ k n ∈ ω, ε_k k → n ≠ 0 → ω ^^ (ω ⋅ k⁺ + n) ^ ω ⋸ ω ^ ω ^^ (ω ⋅ k⁺ + n).
Proof with nauto.
intros k Hk n Hn IHk. ω_induction n; intros Hn0. exfalso...
destruct (classic (m = 0)) as [|Hm0].
- subst. rewrite ωtωk_1, <- ordTet0_suc...
repeat rewrite pred... repeat rewrite ordTet0_suc...
rewrite ordTet0_0... left. rewrite ordExp_mul...
assert (Hran: ω ^ (ε k)⁺ ⋵ 𝐎𝐍). apply ordExp_ran...
apply ordExp_preserve_lt...
rewrite <- (ordExp_1_r ω) at 3... rewrite ordExp_add...
apply ordExp_preserve_lt...
rewrite <- ordAdd_1_r, ordAdd_assoc, ordAdd_1_1...
eapply (ord_trans _ _ _ (ε k + ε k)).
apply ordAdd_preserve_lt... rewrite <- ordMul_2_r...
rewrite <- ordExp_add, epsilon, ordExp_1_r...
apply ordMul_preserve_lt...
- assert (Hran: ω ^^ (ω ⋅ k⁺ + m) ⋵ 𝐎𝐍). apply ordTet_ran...
assert (Hsum0: ω ⋅ k⁺ + m ≠ 0). {
intros H. apply ordAdd_eq_0 in H as []...
}
assert (Hsum1: ω ⋅ k⁺ + m ≠ 1). {
intros H. apply ordAdd_eq_1 in H as [[H _]|[]]...
apply ordMul_eq_0 in H as []... apply (suc_neq_0 k)...
}
assert (Htet1: 1 ∈ ω ^^ (ω ⋅ k⁺ + m)). apply ordTet_gt_1...
rewrite ordAdd_suc, ordTet_suc, ord_max_l...
rewrite ordExp_mul... apply ordExp_preserve_le_r...
eapply ord_trans_le; revgoals... left.
eapply (ord_trans _ _ _ (ω ^^ (ω ⋅ k⁺ + m) ⋅ ω ^^ (ω ⋅ k⁺ + m))).
apply ordMul_preserve_lt... apply ord_gt_1_neq_0_1...
apply ordTet_enlarge_r... apply ord_neq_0_1_gt_1...
rewrite <- ordExp_2_r... apply ordExp_preserve_lt...
Unshelve. apply ordExp_ran... auto.
Qed.
Lemma ωtωk_n : ∀ k n ∈ ω, ε_k k → n ≠ 0 → ω ^^ (ω ⋅ k⁺ + n) = (ω ^^⁰ n⁺) (ε k)⁺.
Proof with nauto.
intros k Hk n Hn IHk. ω_induction n; intros Hn0. exfalso...
destruct (classic (m = 0)) as [|Hm0].
- subst. apply ωtωk_1...
- rewrite ordAdd_suc, ordTet0_suc, <- IH...
rewrite ordTet_suc, ord_max_l, IH...
apply ordExp_ran... apply ordTet_ran...
apply ordExp_ran... apply ordTet_ran...
apply ωtωk_exp_ω_r_lt_l...
Qed.
Theorem ε_n : ∀n ∈ ω, ε n = ω ^^ (ω ⋅ n⁺).
Proof with neauto.
intros n Hn. ω_induction n.
- subst. rewrite ordMul_1_r, ω_tet_ω...
- assert (H0: ω ⋅ m⁺ ≠ 0). {
intros H. apply ordMul_eq_0 in H as []... eapply suc_neq_0...
}
rewrite ε_suc, ordMul_suc...
erewrite <- (ordTet0_eq_ordTetL_ω (ε m) _ ω)... 2: {
rewrite IH. apply ordTet_enlarge_r...
apply ord_neq_0_1_gt_1... intros H.
apply ordMul_eq_1 in H as []...
apply (nat_irrefl 1)... rewrite <- H at 2...
}
rewrite ordTet0_limit, ordTet_limit...
2: apply ordAdd_is_limord...
2: intros H; apply ordAdd_eq_0 in H as []...
ext.
+ apply FUnionE in H as [k [Hk H]].
ω_destruct k.
* rewrite ordTet0_0 in H...
apply (FUnionI _ _ 1)... 2: rewrite ordTet_1_r...
eapply ord_trans_lt_le. auto. apply embed_ran.
apply ordAdd_enlarge_l...
* rewrite ε_tet0_n, <- ωtωk_n in H...
eapply FUnionI... apply ordAdd_preserve_lt...
+ apply FUnionE in H as [α [Hα Hx]].
assert (Hoα: α ⋵ 𝐎𝐍). apply (ord_is_ords (ω ⋅ m⁺ + ω))...
rewrite ordAdd_limit in Hα...
apply FUnionE in Hα as [k [Hk Hα]].
ω_destruct k.
* apply (FUnionI _ _ 1)... rewrite ordTet0_1...
eapply ord_trans... eapply ord_trans. nauto.
apply ordTet_preserve_lt; revgoals...
rewrite ordAdd_0_r, IH... apply ordExp_enlarge_r...
* apply (FUnionI _ _ k⁺)... rewrite ε_tet0_n, <- ωtωk_n...
eapply ord_trans... apply ordTet_ran... apply ordAdd_ran...
apply ordTet_preserve_lt... apply ordAdd_ran...
Unshelve. apply ε_operative...
Qed.
Corollary ε_ω : ε ω = ω ^^ (ω ^ 2).
Proof with neauto.
rewrite ε_limit, ordExp_2_r, ordTet_limit...
2: apply ordMul_is_limord_l...
2: intros H; apply ordMul_eq_0 in H as []...
ext.
- apply FUnionE in H as [n [Hn H]]. rewrite ε_n in H...
apply (FUnionI _ _ (ω ⋅ n⁺))... apply ordMul_preserve_lt...
apply ω_inductive...
- apply FUnionE in H as [α [Hα H]].
assert (Hoα: α ⋵ 𝐎𝐍). apply (ord_is_ords (ω ⋅ ω))...
rewrite ordMul_limit in Hα...
apply FUnionE in Hα as [n [Hn Hα]].
apply (FUnionI _ _ n)... rewrite ε_n...
eapply ord_trans... apply ordTet_preserve_lt...
eapply ord_trans... apply ordMul_preserve_lt...
Qed.
End Epsilon.
|
(* Property from Case-Analysis for Rippling and Inductive Proof,
Moa Johansson, Lucas Dixon and Alan Bundy, ITP 2010.
This Isabelle theory is produced using the TIP tool offered at the following website:
https://github.com/tip-org/tools
This file was originally provided as part of TIP benchmark at the following website:
https://github.com/tip-org/benchmarks
Yutaka Nagashima at CIIRC, CTU changed the TIP output theory file slightly
to make it compatible with Isabelle2017.
Some proofs were added by Yutaka Nagashima.*)
theory TIP_prop_52
imports "../../Test_Base"
begin
datatype 'a list = nil2 | cons2 "'a" "'a list"
datatype Nat = Z | S "Nat"
fun y :: "'a list => 'a list => 'a list" where
"y (nil2) y2 = y2"
| "y (cons2 z2 xs) y2 = cons2 z2 (y xs y2)"
fun x :: "Nat => Nat => bool" where
"x (Z) (Z) = True"
| "x (Z) (S z2) = False"
| "x (S x2) (Z) = False"
| "x (S x2) (S y22) = x x2 y22"
fun rev :: "'a list => 'a list" where
"rev (nil2) = nil2"
| "rev (cons2 y2 xs) = y (rev xs) (cons2 y2 (nil2))"
fun count :: "Nat => Nat list => Nat" where
"count z (nil2) = Z"
| "count z (cons2 z2 ys) =
(if x z z2 then S (count z ys) else count z ys)"
theorem property0 :
"((count n xs) = (count n (rev xs)))"
oops
end |
(* Title: HOL/Auth/n_german_lemma_on_inv__30.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_german Protocol Case Study*}
theory n_german_lemma_on_inv__30 imports n_german_base
begin
section{*All lemmas on causal relation between inv__30 and some rule r*}
lemma n_RecvReqSVsinv__30:
assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__30 p__Inv2)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvReqS N i" apply fastforce done
from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__30 p__Inv2" apply fastforce done
have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(i=p__Inv2)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv2)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_RecvReqEVsinv__30:
assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqE N i)" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__30 p__Inv2)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvReqE N i" apply fastforce done
from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__30 p__Inv2" apply fastforce done
have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(i=p__Inv2)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv2)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_SendInv__part__0Vsinv__30:
assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__30 p__Inv2)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain i where a1:"i\<le>N\<and>r=n_SendInv__part__0 i" apply fastforce done
from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__30 p__Inv2" apply fastforce done
have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(i=p__Inv2)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv2)"
have "?P2 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_SendInv__part__1Vsinv__30:
assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__30 p__Inv2)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain i where a1:"i\<le>N\<and>r=n_SendInv__part__1 i" apply fastforce done
from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__30 p__Inv2" apply fastforce done
have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(i=p__Inv2)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv2)"
have "?P2 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_RecvInvAckVsinv__30:
assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__30 p__Inv2)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvInvAck i" apply fastforce done
from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__30 p__Inv2" apply fastforce done
have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(i=p__Inv2)"
have "?P3 s"
apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Para (Ident ''InvSet'') p__Inv2)) (Const true)) (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv2) ''Cmd'')) (Const InvAck))))" in exI, auto) done
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv2)"
have "?P2 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_SendGntSVsinv__30:
assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendGntS i)" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__30 p__Inv2)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain i where a1:"i\<le>N\<and>r=n_SendGntS i" apply fastforce done
from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__30 p__Inv2" apply fastforce done
have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(i=p__Inv2)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv2)"
have "?P2 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_SendGntEVsinv__30:
assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendGntE N i)" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__30 p__Inv2)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain i where a1:"i\<le>N\<and>r=n_SendGntE N i" apply fastforce done
from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__30 p__Inv2" apply fastforce done
have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(i=p__Inv2)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv2)"
have "?P2 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_SendReqE__part__1Vsinv__30:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__30 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_StoreVsinv__30:
assumes a1: "\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__30 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_RecvGntSVsinv__30:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvGntS i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__30 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_RecvGntEVsinv__30:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvGntE i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__30 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_SendInvAckVsinv__30:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendInvAck i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__30 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_SendReqE__part__0Vsinv__30:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__30 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_SendReqSVsinv__30:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqS i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__30 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
end
|
module Incrementer
import public RealizedFunction
%default total
-- Realized incrementer
public export
incrementer : Int -> Int
incrementer = (+1)
public export
incrementer_attrs : RealizedAttributes
incrementer_attrs = MkRealizedAttributes (MkCosts 100 10 1) 1
public export
rlz_incrementer : RealizedFunction (Int -> Int) Incrementer.incrementer_attrs
rlz_incrementer = MkRealizedFunction incrementer incrementer_attrs
|
Media & Events - CH2O Inc.
"Our irrigation water has high iron and mineral content that plugs irrigation emitters, which kill plants. This season we didn't have any issues with plugged drip emitters like we have had before, and that's big. That's why it's important to use a product like Sure Flow."
"When we sell the plant, I can now guarantee that it is a healthy plant." |
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝⁶ : LinearOrderedCommMonoidWithZero α
β : Type u_2
inst✝⁵ : Zero β
inst✝⁴ : One β
inst✝³ : Mul β
inst✝² : Pow β ℕ
inst✝¹ : Sup β
inst✝ : Inf β
f : β → α
hf : Injective f
zero : f 0 = 0
one : f 1 = 1
mul : ∀ (x y : β), f (x * y) = f x * f y
npow : ∀ (x : β) (n : ℕ), f (x ^ n) = f x ^ n
hsup : ∀ (x y : β), f (x ⊔ y) = max (f x) (f y)
hinf : ∀ (x y : β), f (x ⊓ y) = min (f x) (f y)
src✝² : LinearOrder β := LinearOrder.lift f hf hsup hinf
src✝¹ : OrderedCommMonoid β := orderedCommMonoid f hf one mul npow
src✝ : CommMonoidWithZero β := Injective.commMonoidWithZero f hf zero one mul npow
⊢ f 0 ≤ f 1
[PROOFSTEP]
simp only [zero, one, LinearOrderedCommMonoidWithZero.zero_le_one]
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommMonoidWithZero α
⊢ 0 ≤ a
[PROOFSTEP]
simpa only [mul_zero, mul_one] using mul_le_mul_left' zero_le_one a
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
h : c ≠ 0
hab : a * c ≤ b * c
⊢ a ≤ b
[PROOFSTEP]
simpa only [mul_inv_cancel_right₀ h] using mul_le_mul_right' hab c⁻¹
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
h : c ≠ 0
hab : a * c ≤ b
⊢ a * c ≤ b * c⁻¹ * c
[PROOFSTEP]
simpa [h] using hab
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
hab : a ≤ b * c
⊢ a * c⁻¹ ≤ b
[PROOFSTEP]
by_cases h : c = 0
[GOAL]
case pos
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
hab : a ≤ b * c
h : c = 0
⊢ a * c⁻¹ ≤ b
[PROOFSTEP]
simp [h]
[GOAL]
case neg
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
hab : a ≤ b * c
h : ¬c = 0
⊢ a * c⁻¹ ≤ b
[PROOFSTEP]
exact le_of_le_mul_right h (by simpa [h] using hab)
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
hab : a ≤ b * c
h : ¬c = 0
⊢ a * c⁻¹ * c ≤ b * c
[PROOFSTEP]
simpa [h] using hab
[GOAL]
α : Type u_1
a✝ b✝ c✝ d✝ x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
a b c d : α
hb : b ≠ 0
hd : d ≠ 0
⊢ a * b⁻¹ ≤ c * d⁻¹ ↔ a * d ≤ c * b
[PROOFSTEP]
rw [mul_inv_le_iff₀ hb, mul_right_comm, le_mul_inv_iff₀ hd]
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
hab : a ≤ b
hb : b ≠ 0
hcd : c < d
hd : d ≠ 0
ha : a = 0
⊢ a * c < b * d
[PROOFSTEP]
rw [ha, zero_mul, zero_lt_iff]
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
hab : a ≤ b
hb : b ≠ 0
hcd : c < d
hd : d ≠ 0
ha : a = 0
⊢ b * d ≠ 0
[PROOFSTEP]
exact mul_ne_zero hb hd
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
hab : a ≤ b
hb : b ≠ 0
hcd : c < d
hd : d ≠ 0
ha : ¬a = 0
hc : c = 0
⊢ a * c < b * d
[PROOFSTEP]
rw [hc, mul_zero, zero_lt_iff]
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
hab : a ≤ b
hb : b ≠ 0
hcd : c < d
hd : d ≠ 0
ha : ¬a = 0
hc : c = 0
⊢ b * d ≠ 0
[PROOFSTEP]
exact mul_ne_zero hb hd
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
h : x < y * z
⊢ x * z⁻¹ < y
[PROOFSTEP]
contrapose! h
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
h : y ≤ x * z⁻¹
⊢ y * z ≤ x
[PROOFSTEP]
simpa only [inv_inv] using mul_inv_le_of_le_mul h
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
h : x < y * z
⊢ y⁻¹ * x < z
[PROOFSTEP]
rw [mul_comm] at *
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
h : x < z * y
⊢ x * y⁻¹ < z
[PROOFSTEP]
exact mul_inv_lt_of_lt_mul₀ h
[GOAL]
α : Type u_1
a b c✝ d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
c : α
h : a < b
hc : c ≠ 0
⊢ a * c < b * c
[PROOFSTEP]
contrapose! h
[GOAL]
α : Type u_1
a b c✝ d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
c : α
hc : c ≠ 0
h : b * c ≤ a * c
⊢ b ≤ a
[PROOFSTEP]
exact le_of_le_mul_right hc h
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
h : a * b < c * d
hc : 0 < c
hh : c ≤ a
⊢ b < d
[PROOFSTEP]
have ha : a ≠ 0 := ne_of_gt (lt_of_lt_of_le hc hh)
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
h : a * b < c * d
hc : 0 < c
hh : c ≤ a
ha : a ≠ 0
⊢ b < d
[PROOFSTEP]
simp_rw [← inv_le_inv₀ ha (ne_of_gt hc)] at hh
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
h : a * b < c * d
hc : 0 < c
ha : a ≠ 0
hh : a⁻¹ ≤ c⁻¹
⊢ b < d
[PROOFSTEP]
have := mul_lt_mul_of_lt_of_le₀ hh (inv_ne_zero (ne_of_gt hc)) h
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
h : a * b < c * d
hc : 0 < c
ha : a ≠ 0
hh : a⁻¹ ≤ c⁻¹
this : a⁻¹ * (a * b) < c⁻¹ * (c * d)
⊢ b < d
[PROOFSTEP]
simpa [inv_mul_cancel_left₀ ha, inv_mul_cancel_left₀ (ne_of_gt hc)] using this
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
ha : a ≠ 0
⊢ a * b ≤ a * c ↔ b ≤ c
[PROOFSTEP]
simp only [mul_comm a]
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
ha : a ≠ 0
⊢ b * a ≤ c * a ↔ b ≤ c
[PROOFSTEP]
exact mul_le_mul_right₀ ha
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
hc : c ≠ 0
⊢ a / c ≤ b / c ↔ a ≤ b
[PROOFSTEP]
rw [div_eq_mul_inv, div_eq_mul_inv, mul_le_mul_right₀ (inv_ne_zero hc)]
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
ha : a ≠ 0
hb : b ≠ 0
hc : c ≠ 0
⊢ a / b ≤ a / c ↔ c ≤ b
[PROOFSTEP]
simp only [div_eq_mul_inv, mul_le_mul_left₀ ha, inv_le_inv₀ hb hc]
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
hc : c ≠ 0
⊢ a ≤ b / c ↔ a * c ≤ b
[PROOFSTEP]
rw [div_eq_mul_inv, le_mul_inv_iff₀ hc]
[GOAL]
α : Type u_1
a b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
hc : c ≠ 0
⊢ a / c ≤ b ↔ a ≤ b * c
[PROOFSTEP]
rw [div_eq_mul_inv, mul_inv_le_iff₀ hc]
[GOAL]
α : Type u_1
a✝ b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
a : α
ha : a ≠ 0
⊢ symm (mulLeft₀' ha) = mulLeft₀' (_ : a⁻¹ ≠ 0)
[PROOFSTEP]
ext
[GOAL]
case h.h
α : Type u_1
a✝ b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
a : α
ha : a ≠ 0
x✝ : α
⊢ ↑(symm (mulLeft₀' ha)) x✝ = ↑(mulLeft₀' (_ : a⁻¹ ≠ 0)) x✝
[PROOFSTEP]
rfl
[GOAL]
α : Type u_1
a✝ b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
a : α
ha : a ≠ 0
⊢ symm (mulRight₀' ha) = mulRight₀' (_ : a⁻¹ ≠ 0)
[PROOFSTEP]
ext
[GOAL]
case h.h
α : Type u_1
a✝ b c d x y z : α
inst✝ : LinearOrderedCommGroupWithZero α
a : α
ha : a ≠ 0
x✝ : α
⊢ ↑(symm (mulRight₀' ha)) x✝ = ↑(mulRight₀' (_ : a⁻¹ ≠ 0)) x✝
[PROOFSTEP]
rfl
|
module lib where
open import datatypes public
open import logic public
open import thms public
open import termination public
open import error public
open import io public
|
`is_element/real_functions` := (A::set) -> proc(x)
local a;
global reason;
if not(is_table_on(A)(x)) then
reason := [convert(procname,string),"x is not a table on A",x,A];
return false;
fi;
for a in A do
if not `is_element/RR`(x[a]) then
reason := [convert(procname,string),"x[a] is not in R",a,x[a]];
return false;
fi;
od;
return true;
end;
######################################################################
`is_equal/real_functions` := (A::set) -> proc(x,y)
local a;
global reason;
for a in A do
if not(`is_equal/RR`(x[a],y[a])) then
reason := [convert(procname,string),"x[a] <> y[a]",a,x,y];
return false;
fi;
od;
return true;
end;
######################################################################
`random_element/real_functions` := (A::set) -> proc()
local x,a;
x := table();
for a in A do
x[a] := `random_element/RR`();
od:
return eval(x);
end;
######################################################################
`list_elements/real_functions` := NULL;
`count_elements/real_functions` := NULL;
######################################################################
`is_nonnegative/real_functions` := (A::set) -> proc(x)
local a;
for a in A do
if is(x[a] < 0) then
return false;
fi;
od;
return true;
end:
######################################################################
`is_leq/real_functions` := (A::set) -> proc(x,y)
local a;
for a in A do
if is(x[a] > y[a]) then
return false;
fi;
od;
return true;
end:
######################################################################
`norm/real_functions` := (A::set) -> proc(x)
local a,n;
n := 0;
for a in A do n := n + x[a]^2; od;
return sqrt(n);
end:
######################################################################
`sum/real_functions` := (A::set) -> proc(x)
local a,u;
u := 0;
for a in A do u := u + x[a]; od;
return u;
end:
######################################################################
`max/real_functions` := (A::set) -> proc(x)
local a,u;
u := -infinity;
for a in A do u := max(u,x[a]); od;
return u;
end:
######################################################################
`min/real_functions` := (A::set) -> proc(x)
local a,u;
u := infinity;
for a in A do u := min(u,x[a]); od;
return u;
end:
######################################################################
`dist/real_functions` := (A::set) -> proc(x,y)
local a,n;
n := 0;
for a in A do n := n + (x[a]-y[a])^2; od;
return sqrt(n);
end:
######################################################################
`dot/real_functions` := (A::set) -> proc(x,y)
local a,d;
d := 0;
for a in A do d := d + x[a]*y[a]; od;
return d;
end:
######################################################################
`width/real_functions` := (A::set) -> proc(x)
local V;
V := map(a -> x[a],A);
return max(op(V)) - min(op(V));
end:
######################################################################
`gap/real_functions` := (A::set) -> proc(x)
local V,n,i;
V := sort([op(map(a -> x[a],A))]);
n := nops(V);
return max(0,seq(V[i+1]-V[i],i=1..n-1));
end:
######################################################################
`relative_gap/real_functions` := (A::set) -> proc(x)
return `gap/real_functions`(A)(x)/`width/real_functions`(A)(x);
end:
|
If $f$ is convex on the interval $[x,y]$, then for any $c \in [x,y]$, we have $f(c) \leq \frac{f(y) - f(x)}{y-x}(c-x) + f(x)$. |
[STATEMENT]
lemma mult_less_multiset\<^sub>H\<^sub>O: "(M, N) \<in> mult {(x, y). x < y} \<longleftrightarrow> less_multiset\<^sub>H\<^sub>O M N"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. ((M, N) \<in> mult {(x, y). x < y}) = less_multiset\<^sub>H\<^sub>O M N
[PROOF STEP]
unfolding multp_def[of "(<)", symmetric]
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. multp (<) M N = less_multiset\<^sub>H\<^sub>O M N
[PROOF STEP]
using multp_eq_multp\<^sub>H\<^sub>O[of "(<)", simplified]
[PROOF STATE]
proof (prove)
using this:
multp (<) = multp\<^sub>H\<^sub>O (<)
goal (1 subgoal):
1. multp (<) M N = less_multiset\<^sub>H\<^sub>O M N
[PROOF STEP]
by (simp add: multp\<^sub>H\<^sub>O_def less_multiset\<^sub>H\<^sub>O_def) |
\section{Concluding remarks}
At present, LiDAR datasets still differ in quality, content and accessibility across and within countries. Therefore, object identification methods developed should overcome these inconsistencies. The quality of the AHN3 dataset of the Netherlands is sufficient to correctly identify linear vegetation objects with our method. In addition, multi-temporal LiDAR datasets can effectively be analyzed for change in the spatial distribution of linear vegetation objects using such a generic classifier. Initiatives to upscale the classification of linear vegetation objects, reed beds and selected forest metrics to national and European scale, based on classification of LiDAR point clouds, and using efficient cloud computing facilities are being made \citep{kissling2017eecolidar}.
The ecological value of providing such large a dataset of linear vegetation objects lies in the broad extent and fine-scale locational details, which is a powerful quality that can be used in the (3D) characterization of ecosystem structure. Existing ecosystem and biodiversity assessment projects, such as the MAES (Mapping and Assessment of Ecosystems and their Services) project \citep{maes2013mapping}, the SEBI (Streamlining European Biodiversity Indicators) project \citep{biala2012streamlining}, and the high nature value farmland assessment \citep{paracchini2008high} on a European scale and assessments of Planbureau voor de Leefomgeving (PBL) on a national level \citep{bouwma2014biodiversiteit}, could profit from the new details. |
#ifndef RANDOM_H
#define RANDOM_H
extern "C" {
#include <gsl/gsl_rng.h>
#include <gsl/gsl_const_mksa.h>
}
#include <math.h>
#include <mkl.h>
#include <iostream>
#include "matrix.h"
#include "file_IO.h"
// note that the RANDOM package should not has the dependency with lib_traj.h
class RNG_BOOST
{
public:
MKL_LONG N_THREADS_BD;
MKL_LONG N_THREADS_SS;
gsl_rng **BOOST_BD;
gsl_rng **BOOST_SS;
bool INITIALIZATION_BD;
bool INITIALIZATION_SS;
RNG_BOOST()
{
std::cout<< "ERR: basic constructor for RNG_BOOST class is not allowed\n";
}
RNG_BOOST
(COND& given_condition)
{
INITIALIZATION_BD = TRUE;
const gsl_rng_type *T_boost;
N_THREADS_BD = atol(given_condition("N_THREADS_BD").c_str());
BOOST_BD = new gsl_rng* [N_THREADS_BD];
gsl_rng_env_setup();
T_boost = gsl_rng_default;
for(MKL_LONG i=0; i<N_THREADS_BD; i++)
{
BOOST_BD[i] = gsl_rng_alloc(T_boost);
MKL_LONG seed_BD = atol(given_condition("basic_random_seed").c_str());
gsl_rng_set(BOOST_BD[i], seed_BD + i); // it set the seed with index i
}
INITIALIZATION_SS = FALSE; // default
if(given_condition("Method") == "NAPLE_ASSOCIATION")
if(given_condition("Step") != "EQUILIBRATION")
/* given_condition("Step")!="EQUILIBRATION" && given_condition("Method")=="NAPLE_ASSOCIATION") */
// identify the NAPLE_ASSOCIATION topological evolution with equilibration condtion or not
{
INITIALIZATION_SS = TRUE;
N_THREADS_SS = atol(given_condition("N_THREADS_SS").c_str());
/* BOOST_SS = (gsl_rng**)mkl_malloc(N_THREADS_SS*sizeof(gsl_rng*), BIT); */
BOOST_SS = new gsl_rng* [N_THREADS_SS];
for(MKL_LONG i=0; i<N_THREADS_SS; i++)
{
BOOST_SS[i] = gsl_rng_alloc(T_boost);
MKL_LONG seed_SS = atol(given_condition("basic_random_seed_SS").c_str());
gsl_rng_set(BOOST_SS[i], seed_SS + i);
}
}
}
~RNG_BOOST()
{
if(INITIALIZATION_BD)
{
for(MKL_LONG i=0; i<N_THREADS_BD; i++)
{
gsl_rng_free(BOOST_BD[i]);
}
delete[] BOOST_BD;
if(INITIALIZATION_SS)
{
for(MKL_LONG i=0; i<N_THREADS_SS; i++)
{
gsl_rng_free(BOOST_SS[i]);
}
delete[] BOOST_SS;
}
}
}
};
namespace RANDOM
{
MKL_LONG
random_vector_generator
(MATRIX& R_VEC_TRANS);
MKL_LONG
single_random_vector_generator
(MATRIX& given_vec);
MKL_LONG
single_random_vector_generator_variance
(MATRIX& given_vec, double s_2);
MKL_LONG
single_random_vector_generator_boost
(MATRIX& given_vec, gsl_rng* r_boost);
MKL_LONG
single_random_vector_generator_variance_boost
(MATRIX& given_vec, double s_2, gsl_rng* r_boost);
MKL_LONG
single_unit_random_vector_generator
(MATRIX& given_vec);
MKL_LONG
unit_random_vector_generator
(MATRIX& R_VEC_TRANS);
MKL_LONG
unit_random_vector_generator_2D
(MATRIX& R_VEC_TRANS);
MKL_LONG
return_LONG_INT_rand
(MKL_LONG SUP);
MKL_LONG
return_LONG_INT_rand_boost
(gsl_rng* r, MKL_LONG SUP);
double
return_double_rand_SUP1();
double
return_double_rand_SUP1_boost
(gsl_rng* r);
MKL_LONG
get_LONG_ARR_rand_boost
(gsl_rng* r, MKL_LONG SUP, MKL_LONG* given_long_arr, MKL_LONG N_arr);
MKL_LONG
get_DOUBLE_ARR_rand_boost
(gsl_rng* r, double* given_double_arr, MKL_LONG N_arr);
}
#endif
|
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import data.matrix.basic
/-!
# Trace of a matrix
This file defines the trace of a matrix, the map sending a matrix to the sum of its diagonal
entries.
See also `linear_algebra.trace` for the trace of an endomorphism.
## Tags
matrix, trace, diagonal
-/
open_locale big_operators matrix
namespace matrix
variables {ι m n p : Type*} {α R S : Type*}
variables [fintype m] [fintype n] [fintype p]
section add_comm_monoid
variables [add_comm_monoid R]
/-- The trace of a square matrix. For more bundled versions, see:
* `matrix.trace_add_monoid_hom`
* `matrix.trace_linear_map`
-/
def trace (A : matrix n n R) : R := ∑ i, diag A i
variables (n R)
@[simp] lemma trace_zero : trace (0 : matrix n n R) = 0 :=
(finset.sum_const (0 : R)).trans $ smul_zero _
variables {n R}
@[simp] lemma trace_add (A B : matrix n n R) : trace (A + B) = trace A + trace B :=
finset.sum_add_distrib
@[simp] lemma trace_smul [monoid α] [distrib_mul_action α R] (r : α) (A : matrix n n R) :
trace (r • A) = r • trace A :=
finset.smul_sum.symm
@[simp] lemma trace_transpose (A : matrix n n R) : trace Aᵀ = trace A := rfl
@[simp] lemma trace_conj_transpose [star_add_monoid R] (A : matrix n n R) :
trace Aᴴ = star (trace A) :=
(star_sum _ _).symm
variables (n α R)
/-- `matrix.trace` as an `add_monoid_hom` -/
@[simps]
def trace_add_monoid_hom : matrix n n R →+ R :=
{ to_fun := trace, map_zero' := trace_zero n R, map_add' := trace_add }
/-- `matrix.trace` as a `linear_map` -/
@[simps]
def trace_linear_map [semiring α] [module α R] : matrix n n R →ₗ[α] R :=
{ to_fun := trace, map_add' := trace_add, map_smul' := trace_smul }
variables {n α R}
@[simp] lemma trace_list_sum (l : list (matrix n n R)) : trace l.sum = (l.map trace).sum :=
map_list_sum (trace_add_monoid_hom n R) l
@[simp] lemma trace_multiset_sum (s : multiset (matrix n n R)) : trace s.sum = (s.map trace).sum :=
map_multiset_sum (trace_add_monoid_hom n R) s
@[simp] lemma trace_sum (s : finset ι) (f : ι → matrix n n R) :
trace (∑ i in s, f i) = ∑ i in s, trace (f i) :=
map_sum (trace_add_monoid_hom n R) f s
end add_comm_monoid
section add_comm_group
variables [add_comm_group R]
@[simp] lemma trace_sub (A B : matrix n n R) : trace (A - B) = trace A - trace B :=
finset.sum_sub_distrib
@[simp] lemma trace_neg (A : matrix n n R) : trace (-A) = -trace A :=
finset.sum_neg_distrib
end add_comm_group
section one
variables [decidable_eq n] [add_comm_monoid_with_one R]
@[simp] lemma trace_one : trace (1 : matrix n n R) = fintype.card n :=
by simp_rw [trace, diag_one, pi.one_def, finset.sum_const, nsmul_one, finset.card_univ]
end one
section mul
@[simp] lemma trace_transpose_mul [add_comm_monoid R] [has_mul R]
(A : matrix m n R) (B : matrix n m R) : trace (Aᵀ ⬝ Bᵀ) = trace (A ⬝ B) := finset.sum_comm
lemma trace_mul_comm [add_comm_monoid R] [comm_semigroup R] (A : matrix m n R) (B : matrix n m R) :
trace (A ⬝ B) = trace (B ⬝ A) :=
by rw [←trace_transpose, ←trace_transpose_mul, transpose_mul]
lemma trace_mul_cycle [non_unital_comm_semiring R]
(A : matrix m n R) (B : matrix n p R) (C : matrix p m R) :
trace (A ⬝ B ⬝ C) = trace (C ⬝ A ⬝ B) :=
by rw [trace_mul_comm, matrix.mul_assoc]
lemma trace_mul_cycle' [non_unital_comm_semiring R]
(A : matrix m n R) (B : matrix n p R) (C : matrix p m R) :
trace (A ⬝ (B ⬝ C)) = trace (C ⬝ (A ⬝ B)) :=
by rw [←matrix.mul_assoc, trace_mul_comm]
@[simp] lemma trace_col_mul_row [non_unital_non_assoc_semiring R] (a b : n → R) :
trace (col a ⬝ row b) = dot_product a b :=
by simp [dot_product, trace]
end mul
section fin
variables [add_comm_monoid R]
/-! ### Special cases for `fin n`
While `simp [fin.sum_univ_succ]` can prove these, we include them for convenience and consistency
with `matrix.det_fin_two` etc.
-/
@[simp] lemma trace_fin_zero (A : matrix (fin 0) (fin 0) R) : trace A = 0 :=
rfl
lemma trace_fin_one (A : matrix (fin 1) (fin 1) R) : trace A = A 0 0 :=
add_zero _
lemma trace_fin_two (A : matrix (fin 2) (fin 2) R) : trace A = A 0 0 + A 1 1 :=
congr_arg ((+) _) (add_zero (A 1 1))
lemma trace_fin_three (A : matrix (fin 3) (fin 3) R) : trace A = A 0 0 + A 1 1 + A 2 2 :=
by { rw [← add_zero (A 2 2), add_assoc], refl }
end fin
end matrix
|
\chapter{Providers}
\section{General remark}
For this project, we needed some providers for the different required technologies. We had to find a SIP provider and a private server to host our applications.
\section{Server hosting}
Because we were already customer at \textit{OVH} before this internship, we used their services. We bought a tiny \textit{V.P.S.} \begin{tiny}(Virtual Private Server)\end{tiny} at a cheap cost. This server had these following specifications:
\begin{itemize}
\item 2.4 GHz
\item 2 GB RAM
\item 10 GB SSD
\item OpenStack KVM technology
\end{itemize}
\section{SIP provider}
Because we made this project in Scotland, we needed to find a phone number located in Glasgow, to allows our tutors to call our service for free. We also used \textit{OVH} services which purposes the location of a phone number, located in Glasgow.
We also found an other provider which purposes to receive calls for free. It was perfectly designed to our needs. Furthermore, this provider gives also the ability to call Skype account, something which was a really great thing for our project. So we chose to use the \textit{IPPI} service.
\newpage |
(* Title: CoreC++
Author: Daniel Wasserrab
Maintainer: Daniel Wasserrab <wasserra at fmi.uni-passau.de>
Based on the Jinja theory Common/Objects.thy by Tobias Nipkow
*)
header {* \isaheader{Objects and the Heap} *}
theory Objects imports SubObj begin
section{* Objects *}
type_synonym
subo = "(path \<times> (vname \<rightharpoonup> val))" -- "subobjects realized on the heap"
type_synonym
obj = "cname \<times> subo set" -- "mdc and subobject"
definition init_class_fieldmap :: "prog \<Rightarrow> cname \<Rightarrow> (vname \<rightharpoonup> val)" where
"init_class_fieldmap P C \<equiv>
map_of (map (\<lambda>(F,T).(F,default_val T)) (fst(snd(the(class P C)))) )"
inductive
init_obj :: "prog \<Rightarrow> cname \<Rightarrow> (path \<times> (vname \<rightharpoonup> val)) \<Rightarrow> bool"
for P :: prog and C :: cname
where
"Subobjs P C Cs \<Longrightarrow> init_obj P C (Cs,init_class_fieldmap P (last Cs))"
lemma init_obj_nonempty: "init_obj P C (Cs,fs) \<Longrightarrow> Cs \<noteq> []"
by (fastforce elim:init_obj.cases dest:Subobjs_nonempty)
lemma init_obj_no_Ref:
"\<lbrakk>init_obj P C (Cs,fs); fs F = Some(Ref(a',Cs'))\<rbrakk> \<Longrightarrow> False"
by (fastforce elim:init_obj.cases default_val_no_Ref
simp:init_class_fieldmap_def map_of_map)
lemma SubobjsSet_init_objSet:
"{Cs. Subobjs P C Cs} = {Cs. \<exists>vmap. init_obj P C (Cs,vmap)}"
by ( fastforce intro:init_obj.intros elim:init_obj.cases)
definition obj_ty :: "obj \<Rightarrow> ty" where
"obj_ty obj \<equiv> Class (fst obj)"
-- "a new, blank object with default values in all fields:"
definition blank :: "prog \<Rightarrow> cname \<Rightarrow> obj" where
"blank P C \<equiv> (C, Collect (init_obj P C))"
section{* Heap *}
type_synonym heap = "addr \<rightharpoonup> obj"
abbreviation
cname_of :: "heap \<Rightarrow> addr \<Rightarrow> cname" where
"cname_of hp a == fst (the (hp a))"
definition new_Addr :: "heap \<Rightarrow> addr option" where
"new_Addr h \<equiv> if \<exists>a. h a = None then Some(SOME a. h a = None) else None"
lemma new_Addr_SomeD:
"new_Addr h = Some a \<Longrightarrow> h a = None"
by(fastforce simp add:new_Addr_def split:if_splits intro:someI)
end
|
Require Export ct04.
Section DivConq.
Variable A : Type.
Implicit Type l : list A.
(* div_conq_pair:
* - works similar to induction (i.e. list_rect), but instead of cutting just
* head of the list in each recursive step, this induction principle cut two
* heads of the list in each recursive step.
* - To prove some proposition P holds for all lists ls, one needs to prove the
* following:
* 1. P holds for empty list, nil.
* 2. P holds for one-element list, (a :: nil).
* 3. P holds for two-elements list, (a1 :: a2 :: nil).
* 4. If P hold (a1 :: a2 :: nil) and l, then P must also hold for
* (a1 :: a2 :: l).
*)
Lemma div_conq_pair : forall (P : list A -> Type),
P nil -> (forall (a : A), P (a :: nil))
-> (forall (a1 a2 : A), P (a1 :: a2 :: nil))
-> (forall (a1 a2 : A) (l : list A), P (a1 :: a2 :: nil) -> P l
-> P (a1 :: a2 :: l))
-> forall (l : list A), P l.
Proof.
intros; eapply well_founded_induction_type. eapply lengthOrder_wf.
destruct x; auto; destruct x; auto. intros; apply X2; auto.
apply X3; unfold lengthOrder; simpl; auto.
Defined.
End DivConq.
Ltac div_conq_pair := eapply div_conq_pair.
|
87, of Waianae, died in Waianae on July 9, 2018. She was born in Lahaina, Maui. Visitation: 10 AM; Services: 11 AM on Saturday, August 4, 2018 at Sacred Heart - Waianae. Burial: 3 PM at Hawaiian Memorial Park Cemetery. |
import shutil
import os
import glob
import lmdb
import numpy as np
import cv2 as cv
from os.path import basename
import sys
sys.path.append('/Users/caolele/Documents/caffe/python/')
import caffe
if __name__ == '__main__':
# Example CLI:
# python gen_lmdb_googlenet.py
# ../../data/dataset/images ../../data/dataset/labels ../../data/lmdb/gneti_data ../../data/lmdb/gneti_label 10
num_args = len(sys.argv) - 1
if num_args < 4:
print('Usage: python gen_lmdb_googlenet.py ori_dir lbl_dir ori_lmdb_dir lbl_lmdb_dir max_files')
exit(0)
max_files = 0
if num_args == 5:
max_files = int(sys.argv[5])
# input folders
ori_dir = sys.argv[1]
lbl_dir = sys.argv[2]
# output folders
ori_lmdb_dir = sys.argv[3]
lbl_lmdb_dir = sys.argv[4]
# get file names and reshuffle
fns = np.asarray(sorted(glob.glob('%s/*.png*' % lbl_dir)))
index = np.arange(len(fns))
np.random.shuffle(index)
fns = fns[index]
if max_files > 0:
n_all_files = max_files
else:
n_all_files = len(fns)
print('total images: ', n_all_files)
# create file list for ori and lbl
ori_fns = []
lbl_fns = []
for line in fns:
bname = basename(line)
ori_fns.append(os.path.join(ori_dir, os.path.splitext(bname)[0] + ".jpg"))
lbl_fns.append(os.path.join(lbl_dir, bname))
# init output folders
if os.path.exists(ori_lmdb_dir):
shutil.rmtree(ori_lmdb_dir)
if os.path.exists(lbl_lmdb_dir):
shutil.rmtree(lbl_lmdb_dir)
os.makedirs(ori_lmdb_dir)
os.makedirs(lbl_lmdb_dir)
# config lmdb
sat_env = lmdb.Environment(ori_lmdb_dir, map_size=1099511627776)
sat_txn = sat_env.begin(write=True, buffers=True)
map_env = lmdb.Environment(lbl_lmdb_dir, map_size=1099511627776)
map_txn = map_env.begin(write=True, buffers=True)
keys = np.arange(15000000)
np.random.shuffle(keys)
# set cut params
patch_size = 512
stride = 256
print('patch size: ', patch_size)
print('stride: ', stride)
# start process one file at a time
n_patches = 0
for file_i, (ori_fn, lbl_fn) in enumerate(zip(ori_fns, lbl_fns)):
ori_im = cv.imread(ori_fn, cv.IMREAD_COLOR)
ori_im = cv.bilateralFilter(ori_im, 5, 5 * 2, 5 / 2)
lbl_im = cv.imread(lbl_fn, cv.IMREAD_GRAYSCALE)
if ori_im is None or lbl_im is None:
continue
for y in range(0, ori_im.shape[0] + stride, stride):
for x in range(0, ori_im.shape[1] + stride, stride):
if (y + patch_size) > ori_im.shape[0]:
y = ori_im.shape[0] - patch_size
if (x + patch_size) > ori_im.shape[1]:
x = ori_im.shape[1] - patch_size
ori_patch = np.copy(ori_im[y:y + patch_size, x:x + patch_size])
lbl_patch = np.copy(lbl_im[y:y + patch_size, x:x + patch_size])
# exclude patch including big white/black region
tmpsum = np.sum(ori_patch, axis=2)
if np.sum(tmpsum == (255 * 3)) > 64 or np.sum(tmpsum == 0) > 16:
continue
# get a random key of 10 digits
key = '%010d' % keys[n_patches]
cv.imwrite('./tmp/' + key + '.jpg', ori_patch)
# ori db
ori_patch = ori_patch.swapaxes(0, 2).swapaxes(1, 2)
datum = caffe.io.array_to_datum(ori_patch, 0)
value = datum.SerializeToString()
sat_txn.put(key, value)
# map db
lbl_patch = lbl_patch.reshape((1, lbl_patch.shape[0],
lbl_patch.shape[1]))
datum = caffe.io.array_to_datum(lbl_patch, 0)
value = datum.SerializeToString()
map_txn.put(key, value)
n_patches += 1
if n_patches % 10000 == 0:
sat_txn.commit()
sat_txn = sat_env.begin(write=True, buffers=True)
map_txn.commit()
map_txn = map_env.begin(write=True, buffers=True)
print(file_i + 1, '/', n_all_files, ': n_patches=', n_patches)
if max_files > 0 and max_files - file_i == 1:
break
sat_txn.commit()
sat_env.close()
map_txn.commit()
map_env.close()
print("LMDB generation done!\n Total patches: ", n_patches)
|
(*
* Copyright 2014, NICTA
*
* This software may be distributed and modified according to the terms of
* the BSD 2-Clause license. Note that NO WARRANTY is provided.
* See "LICENSE_BSD2.txt" for details.
*
* @TAG(NICTA_BSD)
*)
theory list_reverse
imports "../CTranslation" "$L4V_ARCH/imports/MachineWords"
begin
declare hrs_simps [simp add]
declare exists_left [simp add]
declare sep_conj_ac [simp add]
primrec
list :: "machine_word list \<Rightarrow> machine_word ptr \<Rightarrow> heap_state \<Rightarrow> bool"
where
"list [] i = (\<lambda>s. i=NULL \<and> \<box> s)"
| "list (x#xs) i = (\<lambda>s. i=Ptr x \<and> x\<noteq>0 \<and> (\<exists>j. ((i \<mapsto> j) \<and>\<^sup>* list xs (Ptr j)) s))"
lemma list_empty [simp]:
shows "list xs NULL = (\<lambda>s. xs = [] \<and> \<box> s)"
by (cases xs) (auto intro: ext dest!: sep_conj_mapD)
declare sep_conj_com [simp del]
declare sep_conj_left_com [simp del]
install_C_file memsafe "list_reverse.c"
thm list_reverse_global_addresses.reverse_body_def
lemma (in list_reverse_global_addresses)
shows "reverse_spec"
apply (unfold reverse_spec_def)
apply (hoare_rule HoarePartial.ProcNoRec1)
apply (hoare_rule anno = "reverse_invs_body zs" in HoarePartial.annotateI)
prefer 2
apply (simp add: whileAnno_def reverse_invs_body_def)
apply(subst reverse_invs_body_def)
apply(unfold sep_app_def)
apply vcg
apply (fold lift_def)
apply(force simp: sep_conj_com)
apply clarsimp
apply(case_tac xs)
apply clarsimp
apply clarsimp
apply sep_exists_tac
apply clarsimp
apply sep_point_tac
apply rule
apply(erule sep_map'_g)
apply rule
apply(erule sep_map'_ptr_safe)
apply(rule_tac x="lista" in exI)
apply (simp add: ucast_id)
apply sep_exists_tac
apply(rule_tac x=j in exI)
apply simp
apply(rule sep_heap_update_global)
apply(erule sep_conj_impl)
apply simp
apply(sep_select_tac "list lista _")
apply(erule sep_conj_impl)
apply(subgoal_tac "lift a (Ptr aa) = ja")
apply simp
apply(erule_tac d=b in sep_map'_lift)
apply simp
apply(simp add: sep_conj_com)
done
declare hrs_simps [simp del]
lemma (in list_reverse_global_addresses) mem_safe_reverse_invs_body:
"mem_safe (reverse_invs_body \<alpha>) \<Gamma>"
apply(unfold reverse_invs_body_def creturn_def)
apply(subst mem_safe_restrict)
apply(rule intra_mem_safe)
apply(auto simp: whileAnno_def intra_sc)
done
declare hrs_simps [simp add]
lemma (in list_reverse_global_addresses) sep_frame_reverse_invs_body:
"\<lbrakk> \<forall>\<sigma>. \<Gamma> \<turnstile> \<lbrace>\<sigma>. (P (f \<acute>(\<lambda>x. x)))\<^bsup>sep\<^esup> \<rbrace> reverse_invs_body \<alpha> \<lbrace> (Q (g \<sigma> \<acute>(\<lambda>x. x)))\<^bsup>sep\<^esup> \<rbrace>;
htd_ind f; htd_ind g; \<forall>s. htd_ind (g s) \<rbrakk> \<Longrightarrow>
\<forall>\<sigma>. \<Gamma> \<turnstile> \<lbrace>\<sigma>. (P (f \<acute>(\<lambda>x. x)) \<and>\<^sup>* R (h \<acute>(\<lambda>x. x)))\<^bsup>sep\<^esup> \<rbrace> reverse_invs_body \<alpha>
\<lbrace> (Q (g \<sigma> \<acute>(\<lambda>x. x)) \<and>\<^sup>* R (h \<sigma>))\<^bsup>sep\<^esup> \<rbrace>"
apply(simp only: sep_app_def)
apply(rule sep_frame)
apply simp+
apply(rule mem_safe_reverse_invs_body)
done
end
|
/-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Bhavik Mehta, Adam Topaz
-/
import category_theory.functor.category
import category_theory.functor.fully_faithful
import category_theory.functor.reflects_isomorphisms
/-!
# Monads
We construct the categories of monads and comonads, and their forgetful functors to endofunctors.
(Note that these are the category theorist's monads, not the programmers monads.
For the translation, see the file `category_theory.monad.types`.)
For the fact that monads are "just" monoids in the category of endofunctors, see the file
`category_theory.monad.equiv_mon`.
-/
namespace category_theory
open category
universes v₁ u₁ -- morphism levels before object levels. See note [category_theory universes].
variables (C : Type u₁) [category.{v₁} C]
/--
The data of a monad on C consists of an endofunctor T together with natural transformations
η : 𝟭 C ⟶ T and μ : T ⋙ T ⟶ T satisfying three equations:
- T μ_X ≫ μ_X = μ_(TX) ≫ μ_X (associativity)
- η_(TX) ≫ μ_X = 1_X (left unit)
- Tη_X ≫ μ_X = 1_X (right unit)
-/
structure monad extends C ⥤ C :=
(η' [] : 𝟭 _ ⟶ to_functor)
(μ' [] : to_functor ⋙ to_functor ⟶ to_functor)
(assoc' : ∀ X, to_functor.map (nat_trans.app μ' X) ≫ μ'.app _ = μ'.app _ ≫ μ'.app _ . obviously)
(left_unit' : ∀ X : C, η'.app (to_functor.obj X) ≫ μ'.app _ = 𝟙 _ . obviously)
(right_unit' : ∀ X : C, to_functor.map (η'.app X) ≫ μ'.app _ = 𝟙 _ . obviously)
/--
The data of a comonad on C consists of an endofunctor G together with natural transformations
ε : G ⟶ 𝟭 C and δ : G ⟶ G ⋙ G satisfying three equations:
- δ_X ≫ G δ_X = δ_X ≫ δ_(GX) (coassociativity)
- δ_X ≫ ε_(GX) = 1_X (left counit)
- δ_X ≫ G ε_X = 1_X (right counit)
-/
structure comonad extends C ⥤ C :=
(ε' [] : to_functor ⟶ 𝟭 _)
(δ' [] : to_functor ⟶ to_functor ⋙ to_functor)
(coassoc' : ∀ X, nat_trans.app δ' _ ≫ to_functor.map (δ'.app X) = δ'.app _ ≫ δ'.app _ . obviously)
(left_counit' : ∀ X : C, δ'.app X ≫ ε'.app (to_functor.obj X) = 𝟙 _ . obviously)
(right_counit' : ∀ X : C, δ'.app X ≫ to_functor.map (ε'.app X) = 𝟙 _ . obviously)
variables {C} (T : monad C) (G : comonad C)
instance coe_monad : has_coe (monad C) (C ⥤ C) := ⟨λ T, T.to_functor⟩
instance coe_comonad : has_coe (comonad C) (C ⥤ C) := ⟨λ G, G.to_functor⟩
@[simp] lemma monad_to_functor_eq_coe : T.to_functor = T := rfl
@[simp] lemma comonad_to_functor_eq_coe : G.to_functor = G := rfl
/-- The unit for the monad `T`. -/
def monad.η : 𝟭 _ ⟶ (T : C ⥤ C) := T.η'
/-- The multiplication for the monad `T`. -/
def monad.μ : (T : C ⥤ C) ⋙ (T : C ⥤ C) ⟶ T := T.μ'
/-- The counit for the comonad `G`. -/
def comonad.ε : (G : C ⥤ C) ⟶ 𝟭 _ := G.ε'
/-- The comultiplication for the comonad `G`. -/
def comonad.δ : (G : C ⥤ C) ⟶ (G : C ⥤ C) ⋙ G := G.δ'
/-- A custom simps projection for the functor part of a monad, as a coercion. -/
def monad.simps.coe := (T : C ⥤ C)
/-- A custom simps projection for the unit of a monad, in simp normal form. -/
def monad.simps.η : 𝟭 _ ⟶ (T : C ⥤ C) := T.η
/-- A custom simps projection for the multiplication of a monad, in simp normal form. -/
def monad.simps.μ : (T : C ⥤ C) ⋙ (T : C ⥤ C) ⟶ (T : C ⥤ C) := T.μ
/-- A custom simps projection for the functor part of a comonad, as a coercion. -/
def comonad.simps.coe := (G : C ⥤ C)
/-- A custom simps projection for the counit of a comonad, in simp normal form. -/
def comonad.simps.ε : (G : C ⥤ C) ⟶ 𝟭 _ := G.ε
/-- A custom simps projection for the comultiplication of a comonad, in simp normal form. -/
def comonad.simps.δ : (G : C ⥤ C) ⟶ (G : C ⥤ C) ⋙ (G : C ⥤ C) := G.δ
initialize_simps_projections category_theory.monad (to_functor → coe, η' → η, μ' → μ)
initialize_simps_projections category_theory.comonad (to_functor → coe, ε' → ε, δ' → δ)
@[reassoc]
lemma monad.assoc (T : monad C) (X : C) :
(T : C ⥤ C).map (T.μ.app X) ≫ T.μ.app _ = T.μ.app _ ≫ T.μ.app _ :=
T.assoc' X
@[simp, reassoc] lemma monad.left_unit (T : monad C) (X : C) :
T.η.app ((T : C ⥤ C).obj X) ≫ T.μ.app X = 𝟙 ((T : C ⥤ C).obj X) :=
T.left_unit' X
@[simp, reassoc] lemma monad.right_unit (T : monad C) (X : C) :
(T : C ⥤ C).map (T.η.app X) ≫ T.μ.app X = 𝟙 ((T : C ⥤ C).obj X) :=
T.right_unit' X
@[reassoc]
lemma comonad.coassoc (G : comonad C) (X : C) :
G.δ.app _ ≫ (G : C ⥤ C).map (G.δ.app X) = G.δ.app _ ≫ G.δ.app _ :=
G.coassoc' X
@[simp, reassoc] lemma comonad.left_counit (G : comonad C) (X : C) :
G.δ.app X ≫ G.ε.app ((G : C ⥤ C).obj X) = 𝟙 ((G : C ⥤ C).obj X) :=
G.left_counit' X
@[simp, reassoc] lemma comonad.right_counit (G : comonad C) (X : C) :
G.δ.app X ≫ (G : C ⥤ C).map (G.ε.app X) = 𝟙 ((G : C ⥤ C).obj X) :=
G.right_counit' X
/-- A morphism of monads is a natural transformation compatible with η and μ. -/
@[ext]
structure monad_hom (T₁ T₂ : monad C) extends nat_trans (T₁ : C ⥤ C) T₂ :=
(app_η' : ∀ X, T₁.η.app X ≫ app X = T₂.η.app X . obviously)
(app_μ' : ∀ X, T₁.μ.app X ≫ app X = ((T₁ : C ⥤ C).map (app X) ≫ app _) ≫ T₂.μ.app X . obviously)
/-- A morphism of comonads is a natural transformation compatible with ε and δ. -/
@[ext]
structure comonad_hom (M N : comonad C) extends nat_trans (M : C ⥤ C) N :=
(app_ε' : ∀ X, app X ≫ N.ε.app X = M.ε.app X . obviously)
(app_δ' : ∀ X, app X ≫ N.δ.app X = M.δ.app X ≫ app _ ≫ (N : C ⥤ C).map (app X) . obviously)
restate_axiom monad_hom.app_η'
restate_axiom monad_hom.app_μ'
attribute [simp, reassoc] monad_hom.app_η monad_hom.app_μ
restate_axiom comonad_hom.app_ε'
restate_axiom comonad_hom.app_δ'
attribute [simp, reassoc] comonad_hom.app_ε comonad_hom.app_δ
instance : category (monad C) :=
{ hom := monad_hom,
id := λ M, { to_nat_trans := 𝟙 (M : C ⥤ C) },
comp := λ _ _ _ f g,
{ to_nat_trans := { app := λ X, f.app X ≫ g.app X } } }
instance : category (comonad C) :=
{ hom := comonad_hom,
id := λ M, { to_nat_trans := 𝟙 (M : C ⥤ C) },
comp := λ M N L f g,
{ to_nat_trans := { app := λ X, f.app X ≫ g.app X } } }
instance {T : monad C} : inhabited (monad_hom T T) := ⟨𝟙 T⟩
@[simp]
instance {G : comonad C} : inhabited (comonad_hom G G) := ⟨𝟙 G⟩
@[simp] lemma comonad_hom.id_to_nat_trans (T : comonad C) :
(𝟙 T : T ⟶ T).to_nat_trans = 𝟙 (T : C ⥤ C) :=
rfl
@[simp] lemma comp_to_nat_trans {T₁ T₂ T₃ : comonad C} (f : T₁ ⟶ T₂) (g : T₂ ⟶ T₃) :
(f ≫ g).to_nat_trans =
((f.to_nat_trans : _ ⟶ (T₂ : C ⥤ C)) ≫ g.to_nat_trans : (T₁ : C ⥤ C) ⟶ T₃) :=
rfl
/-- Construct a monad isomorphism from a natural isomorphism of functors where the forward
direction is a monad morphism. -/
@[simps]
def monad_iso.mk {M N : monad C} (f : (M : C ⥤ C) ≅ N) (f_η f_μ) :
M ≅ N :=
{ hom := { to_nat_trans := f.hom, app_η' := f_η, app_μ' := f_μ },
inv :=
{ to_nat_trans := f.inv,
app_η' := λ X, by simp [←f_η],
app_μ' := λ X,
begin
rw ←nat_iso.cancel_nat_iso_hom_right f,
simp only [nat_trans.naturality, iso.inv_hom_id_app, assoc, comp_id, f_μ,
nat_trans.naturality_assoc, iso.inv_hom_id_app_assoc, ←functor.map_comp_assoc],
simp,
end } }
/-- Construct a comonad isomorphism from a natural isomorphism of functors where the forward
direction is a comonad morphism. -/
@[simps]
def comonad_iso.mk {M N : comonad C} (f : (M : C ⥤ C) ≅ N) (f_ε f_δ) :
M ≅ N :=
{ hom := { to_nat_trans := f.hom, app_ε' := f_ε, app_δ' := f_δ },
inv :=
{ to_nat_trans := f.inv,
app_ε' := λ X, by simp [←f_ε],
app_δ' := λ X,
begin
rw ←nat_iso.cancel_nat_iso_hom_left f,
simp only [reassoc_of (f_δ X), iso.hom_inv_id_app_assoc, nat_trans.naturality_assoc],
rw [←functor.map_comp, iso.hom_inv_id_app, functor.map_id],
apply (comp_id _).symm
end } }
variable (C)
/--
The forgetful functor from the category of monads to the category of endofunctors.
-/
@[simps]
def monad_to_functor : monad C ⥤ (C ⥤ C) :=
{ obj := λ T, T,
map := λ M N f, f.to_nat_trans }
instance : faithful (monad_to_functor C) := {}.
@[simp]
lemma monad_to_functor_map_iso_monad_iso_mk {M N : monad C} (f : (M : C ⥤ C) ≅ N) (f_η f_μ) :
(monad_to_functor _).map_iso (monad_iso.mk f f_η f_μ) = f :=
by { ext, refl }
instance : reflects_isomorphisms (monad_to_functor C) :=
{ reflects := λ M N f i,
begin
resetI,
convert is_iso.of_iso (monad_iso.mk (as_iso ((monad_to_functor C).map f)) f.app_η f.app_μ),
ext; refl,
end }
/--
The forgetful functor from the category of comonads to the category of endofunctors.
-/
@[simps]
def comonad_to_functor : comonad C ⥤ (C ⥤ C) :=
{ obj := λ G, G,
map := λ M N f, f.to_nat_trans }
instance : faithful (comonad_to_functor C) := {}.
@[simp]
lemma comonad_to_functor_map_iso_comonad_iso_mk {M N : comonad C} (f : (M : C ⥤ C) ≅ N) (f_ε f_δ) :
(comonad_to_functor _).map_iso (comonad_iso.mk f f_ε f_δ) = f :=
by { ext, refl }
instance : reflects_isomorphisms (comonad_to_functor C) :=
{ reflects := λ M N f i,
begin
resetI,
convert is_iso.of_iso (comonad_iso.mk (as_iso ((comonad_to_functor C).map f)) f.app_ε f.app_δ),
ext; refl,
end }
variable {C}
/--
An isomorphism of monads gives a natural isomorphism of the underlying functors.
-/
@[simps {rhs_md := semireducible}]
def monad_iso.to_nat_iso {M N : monad C} (h : M ≅ N) : (M : C ⥤ C) ≅ N :=
(monad_to_functor C).map_iso h
/--
An isomorphism of comonads gives a natural isomorphism of the underlying functors.
-/
@[simps {rhs_md := semireducible}]
def comonad_iso.to_nat_iso {M N : comonad C} (h : M ≅ N) : (M : C ⥤ C) ≅ N :=
(comonad_to_functor C).map_iso h
variable (C)
namespace monad
/-- The identity monad. -/
@[simps]
def id : monad C :=
{ to_functor := 𝟭 C,
η' := 𝟙 (𝟭 C),
μ' := 𝟙 (𝟭 C) }
instance : inhabited (monad C) := ⟨monad.id C⟩
end monad
namespace comonad
/-- The identity comonad. -/
@[simps]
def id : comonad C :=
{ to_functor := 𝟭 _,
ε' := 𝟙 (𝟭 C),
δ' := 𝟙 (𝟭 C) }
instance : inhabited (comonad C) := ⟨comonad.id C⟩
end comonad
end category_theory
|
import data.set.lattice
/-!
# Order theoretic results
-/
open function set
variables {ι α β : Type*}
lemma csupr_neg [complete_lattice α] {p : Prop} {f : p → α} (hp : ¬ p) : (⨆ h, f h) = ⊥ :=
supr_eq_bot.2 $ λ h, (hp h).elim
namespace set
variables (f : α → β) {s t : set α}
@[simp] lemma compl_eq_empty : sᶜ = ∅ ↔ s = univ := compl_eq_bot
@[simp] lemma compl_eq_univ : sᶜ = univ ↔ s = ∅ := compl_eq_top
lemma image_sUnion (f : α → β) (S : set (set α)) : f '' ⋃₀ S = ⋃ s ∈ S, f '' s :=
by rw [sUnion_eq_bUnion, image_Union₂]
--TODO: Rename `Union_neg` to `neg_Union`
@[simp] lemma Union_pos {p : Prop} {f : p → set α} (hp : p) : (⋃ h, f h) = f hp := supr_pos hp
@[simp] lemma Union_neg' {p : Prop} {f : p → set α} (hp : ¬ p) : (⋃ h, f h) = ∅ := csupr_neg hp
variables (s)
@[simp] lemma empty_symm_diff : ∅ ∆ s = s := bot_symm_diff _
@[simp] lemma symm_diff_empty : s ∆ ∅ = s := symm_diff_bot _
end set
|
[STATEMENT]
lemma Above_decr: "A \<le> B \<Longrightarrow> Above r B \<le> Above r A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. A \<subseteq> B \<Longrightarrow> Above r B \<subseteq> Above r A
[PROOF STEP]
by(unfold Above_def, auto) |
(* Title: HOL/Auth/n_german_lemma_on_inv__8.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_german Protocol Case Study*}
theory n_german_lemma_on_inv__8 imports n_german_base
begin
section{*All lemmas on causal relation between inv__8 and some rule r*}
lemma n_SendInvAckVsinv__8:
assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__8 p__Inv2)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain i where a1:"i\<le>N\<and>r=n_SendInvAck i" apply fastforce done
from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__8 p__Inv2" apply fastforce done
have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(i=p__Inv2)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv2)"
have "?P2 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_RecvInvAckVsinv__8:
assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__8 p__Inv2)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvInvAck i" apply fastforce done
from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__8 p__Inv2" apply fastforce done
have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(i=p__Inv2)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv2)"
have "?P2 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_RecvGntSVsinv__8:
assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntS i)" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__8 p__Inv2)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvGntS i" apply fastforce done
from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__8 p__Inv2" apply fastforce done
have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(i=p__Inv2)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv2)"
have "?P2 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_RecvGntEVsinv__8:
assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__8 p__Inv2)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvGntE i" apply fastforce done
from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__8 p__Inv2" apply fastforce done
have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(i=p__Inv2)"
have "?P3 s"
apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Chan2'') p__Inv2) ''Cmd'')) (Const GntE)) (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv2) ''Cmd'')) (Const InvAck))))" in exI, auto) done
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv2)"
have "?P2 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_SendReqE__part__1Vsinv__8:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__8 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_StoreVsinv__8:
assumes a1: "\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__8 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_SendGntSVsinv__8:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendGntS i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__8 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_RecvReqEVsinv__8:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvReqE N i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__8 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_SendInv__part__0Vsinv__8:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__8 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_SendReqE__part__0Vsinv__8:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__8 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_SendInv__part__1Vsinv__8:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__8 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_SendReqSVsinv__8:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqS i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__8 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_SendGntEVsinv__8:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendGntE N i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__8 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_RecvReqSVsinv__8:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvReqS N i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__8 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
end
|
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
! This file was ported from Lean 3 source module analysis.box_integral.partition.additive
! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathbin.Analysis.BoxIntegral.Partition.Split
import Mathbin.Analysis.NormedSpace.OperatorNorm
/-!
# Box additive functions
We say that a function `f : box ι → M` from boxes in `ℝⁿ` to a commutative additive monoid `M` is
*box additive* on subboxes of `I₀ : with_top (box ι)` if for any box `J`, `↑J ≤ I₀`, and a partition
`π` of `J`, `f J = ∑ J' in π.boxes, f J'`. We use `I₀ : with_top (box ι)` instead of `I₀ : box ι` to
use the same definition for functions box additive on subboxes of a box and for functions box
additive on all boxes.
Examples of box-additive functions include the measure of a box and the integral of a fixed
integrable function over a box.
In this file we define box-additive functions and prove that a function such that
`f J = f (J ∩ {x | x i < y}) + f (J ∩ {x | y ≤ x i})` is box-additive.
### Tags
rectangular box, additive function
-/
noncomputable section
open Classical BigOperators
open Function Set
namespace BoxIntegral
variable {ι M : Type _} {n : ℕ}
/-- A function on `box ι` is called box additive if for every box `J` and a partition `π` of `J`
we have `f J = ∑ Ji in π.boxes, f Ji`. A function is called box additive on subboxes of `I : box ι`
if the same property holds for `J ≤ I`. We formalize these two notions in the same definition
using `I : with_bot (box ι)`: the value `I = ⊤` corresponds to functions box additive on the whole
space. -/
structure BoxAdditiveMap (ι M : Type _) [AddCommMonoid M] (I : WithTop (Box ι)) where
toFun : Box ι → M
sum_partition_boxes' :
∀ J : Box ι,
↑J ≤ I → ∀ π : Prepartition J, π.IsPartition → (∑ Ji in π.boxes, to_fun Ji) = to_fun J
#align box_integral.box_additive_map BoxIntegral.BoxAdditiveMap
-- mathport name: box_integral.box_additive_map.top
scoped notation:25 ι " →ᵇᵃ " M => BoxIntegral.BoxAdditiveMap ι M ⊤
-- mathport name: box_integral.box_additive_map
scoped notation:25 ι " →ᵇᵃ[" I "] " M => BoxIntegral.BoxAdditiveMap ι M I
namespace BoxAdditiveMap
open Box Prepartition Finset
variable {N : Type _} [AddCommMonoid M] [AddCommMonoid N] {I₀ : WithTop (Box ι)} {I J : Box ι}
{i : ι}
instance : CoeFun (ι →ᵇᵃ[I₀] M) fun _ => Box ι → M :=
⟨toFun⟩
initialize_simps_projections box_integral.box_additive_map (toFun → apply)
@[simp]
theorem toFun_eq_coe (f : ι →ᵇᵃ[I₀] M) : f.toFun = f :=
rfl
#align box_integral.box_additive_map.to_fun_eq_coe BoxIntegral.BoxAdditiveMap.toFun_eq_coe
@[simp]
theorem coe_mk (f h) : ⇑(mk f h : ι →ᵇᵃ[I₀] M) = f :=
rfl
#align box_integral.box_additive_map.coe_mk BoxIntegral.BoxAdditiveMap.coe_mk
theorem coe_injective : Injective fun (f : ι →ᵇᵃ[I₀] M) x => f x :=
by
rintro ⟨f, hf⟩ ⟨g, hg⟩ (rfl : f = g)
rfl
#align box_integral.box_additive_map.coe_injective BoxIntegral.BoxAdditiveMap.coe_injective
@[simp]
theorem coe_inj {f g : ι →ᵇᵃ[I₀] M} : (f : Box ι → M) = g ↔ f = g :=
coe_injective.eq_iff
#align box_integral.box_additive_map.coe_inj BoxIntegral.BoxAdditiveMap.coe_inj
theorem sum_partition_boxes (f : ι →ᵇᵃ[I₀] M) (hI : ↑I ≤ I₀) {π : Prepartition I}
(h : π.IsPartition) : (∑ J in π.boxes, f J) = f I :=
f.sum_partition_boxes' I hI π h
#align box_integral.box_additive_map.sum_partition_boxes BoxIntegral.BoxAdditiveMap.sum_partition_boxes
@[simps (config := { fullyApplied := false })]
instance : Zero (ι →ᵇᵃ[I₀] M) :=
⟨⟨0, fun I hI π hπ => sum_const_zero⟩⟩
instance : Inhabited (ι →ᵇᵃ[I₀] M) :=
⟨0⟩
instance : Add (ι →ᵇᵃ[I₀] M) :=
⟨fun f g =>
⟨f + g, fun I hI π hπ => by
simp only [Pi.add_apply, sum_add_distrib, sum_partition_boxes _ hI hπ]⟩⟩
instance {R} [Monoid R] [DistribMulAction R M] : SMul R (ι →ᵇᵃ[I₀] M) :=
⟨fun r f =>
⟨r • f, fun I hI π hπ => by simp only [Pi.smul_apply, ← smul_sum, sum_partition_boxes _ hI hπ]⟩⟩
instance : AddCommMonoid (ι →ᵇᵃ[I₀] M) :=
Function.Injective.addCommMonoid _ coe_injective rfl (fun _ _ => rfl) fun _ _ => rfl
@[simp]
theorem map_split_add (f : ι →ᵇᵃ[I₀] M) (hI : ↑I ≤ I₀) (i : ι) (x : ℝ) :
(I.splitLower i x).elim 0 f + (I.splitUpper i x).elim 0 f = f I := by
rw [← f.sum_partition_boxes hI (is_partition_split I i x), sum_split_boxes]
#align box_integral.box_additive_map.map_split_add BoxIntegral.BoxAdditiveMap.map_split_add
/-- If `f` is box-additive on subboxes of `I₀`, then it is box-additive on subboxes of any
`I ≤ I₀`. -/
@[simps]
def restrict (f : ι →ᵇᵃ[I₀] M) (I : WithTop (Box ι)) (hI : I ≤ I₀) : ι →ᵇᵃ[I] M :=
⟨f, fun J hJ => f.2 J (hJ.trans hI)⟩
#align box_integral.box_additive_map.restrict BoxIntegral.BoxAdditiveMap.restrict
/-- If `f : box ι → M` is box additive on partitions of the form `split I i x`, then it is box
additive. -/
def ofMapSplitAdd [Fintype ι] (f : Box ι → M) (I₀ : WithTop (Box ι))
(hf :
∀ I : Box ι,
↑I ≤ I₀ →
∀ {i x},
x ∈ Ioo (I.lower i) (I.upper i) →
(I.splitLower i x).elim 0 f + (I.splitUpper i x).elim 0 f = f I) :
ι →ᵇᵃ[I₀] M := by
refine' ⟨f, _⟩
replace hf : ∀ I : box ι, ↑I ≤ I₀ → ∀ s, (∑ J in (split_many I s).boxes, f J) = f I
· intro I hI s
induction' s using Finset.induction_on with a s ha ihs
· simp
rw [split_many_insert, inf_split, ← ihs, bUnion_boxes, sum_bUnion_boxes]
refine' Finset.sum_congr rfl fun J' hJ' => _
by_cases h : a.2 ∈ Ioo (J'.lower a.1) (J'.upper a.1)
· rw [sum_split_boxes]
exact hf _ ((WithTop.coe_le_coe.2 <| le_of_mem _ hJ').trans hI) h
· rw [split_of_not_mem_Ioo h, top_boxes, Finset.sum_singleton]
intro I hI π hπ
have Hle : ∀ J ∈ π, ↑J ≤ I₀ := fun J hJ => (WithTop.coe_le_coe.2 <| π.le_of_mem hJ).trans hI
rcases hπ.exists_split_many_le with ⟨s, hs⟩
rw [← hf _ hI, ← inf_of_le_right hs, inf_split_many, bUnion_boxes, sum_bUnion_boxes]
exact Finset.sum_congr rfl fun J hJ => (hf _ (Hle _ hJ) _).symm
#align box_integral.box_additive_map.of_map_split_add BoxIntegral.BoxAdditiveMap.ofMapSplitAdd
/-- If `g : M → N` is an additive map and `f` is a box additive map, then `g ∘ f` is a box additive
map. -/
@[simps (config := { fullyApplied := false })]
def map (f : ι →ᵇᵃ[I₀] M) (g : M →+ N) : ι →ᵇᵃ[I₀] N
where
toFun := g ∘ f
sum_partition_boxes' I hI π hπ := by rw [← g.map_sum, f.sum_partition_boxes hI hπ]
#align box_integral.box_additive_map.map BoxIntegral.BoxAdditiveMap.map
/-- If `f` is a box additive function on subboxes of `I` and `π₁`, `π₂` are two prepartitions of
`I` that cover the same part of `I`, then `∑ J in π₁.boxes, f J = ∑ J in π₂.boxes, f J`. -/
theorem sum_boxes_congr [Finite ι] (f : ι →ᵇᵃ[I₀] M) (hI : ↑I ≤ I₀) {π₁ π₂ : Prepartition I}
(h : π₁.unionᵢ = π₂.unionᵢ) : (∑ J in π₁.boxes, f J) = ∑ J in π₂.boxes, f J :=
by
rcases exists_split_many_inf_eq_filter_of_finite {π₁, π₂} ((finite_singleton _).insert _) with
⟨s, hs⟩
simp only [inf_split_many] at hs
rcases hs _ (Or.inl rfl), hs _ (Or.inr rfl) with ⟨h₁, h₂⟩; clear hs
rw [h] at h₁
calc
(∑ J in π₁.boxes, f J) = ∑ J in π₁.boxes, ∑ J' in (split_many J s).boxes, f J' :=
Finset.sum_congr rfl fun J hJ => (f.sum_partition_boxes _ (is_partition_split_many _ _)).symm
_ = ∑ J in (π₁.bUnion fun J => split_many J s).boxes, f J := (sum_bUnion_boxes _ _ _).symm
_ = ∑ J in (π₂.bUnion fun J => split_many J s).boxes, f J := by rw [h₁, h₂]
_ = ∑ J in π₂.boxes, ∑ J' in (split_many J s).boxes, f J' := (sum_bUnion_boxes _ _ _)
_ = ∑ J in π₂.boxes, f J :=
Finset.sum_congr rfl fun J hJ => f.sum_partition_boxes _ (is_partition_split_many _ _)
exacts[(WithTop.coe_le_coe.2 <| π₁.le_of_mem hJ).trans hI,
(WithTop.coe_le_coe.2 <| π₂.le_of_mem hJ).trans hI]
#align box_integral.box_additive_map.sum_boxes_congr BoxIntegral.BoxAdditiveMap.sum_boxes_congr
section ToSmul
variable {E : Type _} [NormedAddCommGroup E] [NormedSpace ℝ E]
/-- If `f` is a box-additive map, then so is the map sending `I` to the scalar multiplication
by `f I` as a continuous linear map from `E` to itself. -/
def toSmul (f : ι →ᵇᵃ[I₀] ℝ) : ι →ᵇᵃ[I₀] E →L[ℝ] E :=
f.map (ContinuousLinearMap.lsmul ℝ ℝ).toLinearMap.toAddMonoidHom
#align box_integral.box_additive_map.to_smul BoxIntegral.BoxAdditiveMap.toSmul
@[simp]
theorem toSmul_apply (f : ι →ᵇᵃ[I₀] ℝ) (I : Box ι) (x : E) : f.toSmul I x = f I • x :=
rfl
#align box_integral.box_additive_map.to_smul_apply BoxIntegral.BoxAdditiveMap.toSmul_apply
end ToSmul
/-- Given a box `I₀` in `ℝⁿ⁺¹`, `f x : box (fin n) → G` is a family of functions indexed by a real
`x` and for `x ∈ [I₀.lower i, I₀.upper i]`, `f x` is box-additive on subboxes of the `i`-th face of
`I₀`, then `λ J, f (J.upper i) (J.face i) - f (J.lower i) (J.face i)` is box-additive on subboxes of
`I₀`. -/
@[simps]
def upperSubLower.{u} {G : Type u} [AddCommGroup G] (I₀ : Box (Fin (n + 1))) (i : Fin (n + 1))
(f : ℝ → Box (Fin n) → G) (fb : Icc (I₀.lower i) (I₀.upper i) → Fin n →ᵇᵃ[I₀.face i] G)
(hf : ∀ (x) (hx : x ∈ Icc (I₀.lower i) (I₀.upper i)) (J), f x J = fb ⟨x, hx⟩ J) :
Fin (n + 1) →ᵇᵃ[I₀] G :=
ofMapSplitAdd (fun J : Box (Fin (n + 1)) => f (J.upper i) (J.face i) - f (J.lower i) (J.face i))
I₀
(by
intro J hJ j
rw [WithTop.coe_le_coe] at hJ
refine' i.succ_above_cases _ _ j
· intro x hx
simp only [box.split_lower_def hx, box.split_upper_def hx, update_same, ←
WithBot.some_eq_coe, Option.elim', box.face, (· ∘ ·), update_noteq (Fin.succAbove_ne _ _)]
abel
· clear j
intro j x hx
have : (J.face i : WithTop (box (Fin n))) ≤ I₀.face i :=
WithTop.coe_le_coe.2 (face_mono hJ i)
rw [le_iff_Icc, @box.Icc_eq_pi _ I₀] at hJ
rw [hf _ (hJ J.upper_mem_Icc _ trivial), hf _ (hJ J.lower_mem_Icc _ trivial), ←
(fb _).map_split_add this j x, ← (fb _).map_split_add this j x]
have hx' : x ∈ Ioo ((J.face i).lower j) ((J.face i).upper j) := hx
simp only [box.split_lower_def hx, box.split_upper_def hx, box.split_lower_def hx',
box.split_upper_def hx', ← WithBot.some_eq_coe, Option.elim', box.face_mk,
update_noteq (Fin.succAbove_ne _ _).symm, sub_add_sub_comm,
update_comp_eq_of_injective _ i.succ_above.injective j x, ← hf]
simp only [box.face])
#align box_integral.box_additive_map.upper_sub_lower BoxIntegral.BoxAdditiveMap.upperSubLower
end BoxAdditiveMap
end BoxIntegral
|
-- ------------------------------------------------------ [ Tree.idr<RedBlack> ]
-- Module : Tree.idr
-- License : see LICENSE
-- --------------------------------------------------------------------- [ EOH ]
-- http://www.cs.kent.ac.uk/people/staff/smk/redblack/Untyped.hs
module Data.RedBlack.Tree
%access export
private
data Colour = R | B
data Tree : Type -> Type where
Empty : Tree a
Node : Colour -> a -> Tree a -> Tree a -> Tree a
balance : a -> Tree a -> Tree a -> Tree a
balance y (Node R x a b) (Node R z c d) = Node R y (Node B x a b) (Node B z c d)
balance z (Node R y (Node R x a b) c) d = Node R y (Node B x a b) (Node B z c d)
balance z (Node R x a (Node R y b c)) d = Node R y (Node B x a b) (Node B z c d)
balance x a (Node R y b (Node R z c d)) = Node R y (Node B x a b) (Node B z c d)
balance x a (Node R z (Node R y b c) d) = Node R y (Node B x a b) (Node B z c d)
balance x a b = Node B x a b
private
ins : Ord a => a -> Tree a -> Tree a
ins x Empty = Node R x Empty Empty
ins x t@(Node B y a b) =
case compare x y of
LT => balance y (ins x a) b
GT => balance y a (ins x b)
EQ => t
ins x t@(Node R y a b) =
case compare x y of
LT => Node R y (ins x a) b
GT => Node R y a (ins x b)
EQ => t
foldr : (step : a -> p -> p) -> (init : p) -> Tree a -> p
foldr step init n = foldr' step init n
where
foldr' : (a -> p -> p) -> p -> Tree a -> p
foldr' step' init' Empty = init'
foldr' step' init' (Node _ val l r) = foldr' step' (step' val (foldr' step' init' r)) l
size : Tree a -> Nat
size t = Tree.foldr (\_,res => S res) Z t
contains : Ord a => a -> Tree a -> Bool
contains x Empty = False
contains x (Node _ y l r) =
case compare x y of
LT => contains x l
GT => contains x r
EQ => True
empty : Tree a
empty = Empty
insert : Ord a => a -> Tree a -> Tree a
insert x s = let Node _ z l r = ins x s in Node B z l r
toList : Tree a -> List a
toList Empty = Nil
toList (Node _ y l r) = Tree.toList l ++ [y] ++ Tree.toList r
fromList : Ord a => List a -> Tree a
fromList xs = foldl (flip $ insert) empty xs
|
/-
Copyright (c) 2020 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
! This file was ported from Lean 3 source module control.lawful_fix
! leanprover-community/mathlib commit 92ca63f0fb391a9ca5f22d2409a6080e786d99f7
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathlib.Data.Stream.Init
import Mathlib.Tactic.ApplyFun
import Mathlib.Control.Fix
import Mathlib.Order.OmegaCompletePartialOrder
import Mathlib.Tactic.WLOG
/-!
# Lawful fixed point operators
This module defines the laws required of a `Fix` instance, using the theory of
omega complete partial orders (ωCPO). Proofs of the lawfulness of all `Fix` instances in
`Control.Fix` are provided.
## Main definition
* class `LawfulFix`
-/
universe u v
open Classical
variable {α : Type _} {β : α → Type _}
open OmegaCompletePartialOrder
/- Porting note: in `#align`s, mathport is putting some `fix`es where `Fix`es should be. -/
/-- Intuitively, a fixed point operator `fix` is lawful if it satisfies `fix f = f (fix f)` for all
`f`, but this is inconsistent / uninteresting in most cases due to the existence of "exotic"
functions `f`, such as the function that is defined iff its argument is not, familiar from the
halting problem. Instead, this requirement is limited to only functions that are `continuous` in the
sense of `ω`-complete partial orders, which excludes the example because it is not monotone
(making the input argument less defined can make `f` more defined). -/
class LawfulFix (α : Type _) [OmegaCompletePartialOrder α] extends Fix α where
fix_eq : ∀ {f : α →o α}, Continuous f → Fix.fix f = f (Fix.fix f)
#align lawful_fix LawfulFix
theorem LawfulFix.fix_eq' {α} [OmegaCompletePartialOrder α] [LawfulFix α] {f : α → α}
(hf : Continuous' f) : Fix.fix f = f (Fix.fix f) :=
LawfulFix.fix_eq (hf.to_bundled _)
#align lawful_fix.fix_eq' LawfulFix.fix_eq'
namespace Part
open Part Nat Nat.Upto
namespace Fix
variable (f : ((a : _) → Part <| β a) →o (a : _) → Part <| β a)
theorem approx_mono' {i : ℕ} : Fix.approx f i ≤ Fix.approx f (succ i) := by
induction i with
| zero => dsimp [approx]; apply @bot_le _ _ _ (f ⊥)
| succ _ i_ih => intro ; apply f.monotone; apply i_ih
#align part.fix.approx_mono' Part.Fix.approx_mono'
theorem approx_mono ⦃i j : ℕ⦄ (hij : i ≤ j) : approx f i ≤ approx f j := by
induction' j with j ih
· cases hij
exact le_rfl
cases hij; · exact le_rfl
exact le_trans (ih ‹_›) (approx_mono' f)
#align part.fix.approx_mono Part.Fix.approx_mono
theorem mem_iff (a : α) (b : β a) : b ∈ Part.fix f a ↔ ∃ i, b ∈ approx f i a := by
by_cases h₀ : ∃ i : ℕ, (approx f i a).Dom
· simp only [Part.fix_def f h₀]
constructor <;> intro hh
· exact ⟨_, hh⟩
have h₁ := Nat.find_spec h₀
rw [dom_iff_mem] at h₁
cases' h₁ with y h₁
replace h₁ := approx_mono' f _ _ h₁
suffices : y = b
· subst this
exact h₁
cases' hh with i hh
revert h₁; generalize succ (Nat.find h₀) = j; intro h₁
wlog case : i ≤ j
· cases' le_total i j with H H <;> [skip, symm] <;> apply_assumption <;> assumption
replace hh := approx_mono f case _ _ hh
apply Part.mem_unique h₁ hh
· simp only [fix_def' (⇑f) h₀, not_exists, false_iff_iff, not_mem_none]
simp only [dom_iff_mem, not_exists] at h₀
intro; apply h₀
#align part.fix.mem_iff Part.Fix.mem_iff
theorem approx_le_fix (i : ℕ) : approx f i ≤ Part.fix f := fun a b hh ↦ by
rw [mem_iff f]
exact ⟨_, hh⟩
#align part.fix.approx_le_fix Part.Fix.approx_le_fix
/-- The series of approximations of `fix f` (see `approx`) as a `Chain` -/
def approxChain : Chain ((a : _) → Part <| β a) :=
⟨approx f, approx_mono f⟩
#align part.fix.approx_chain Part.Fix.approxChain
theorem le_f_of_mem_approx {x} : x ∈ approxChain f → x ≤ f x := by
simp only [(· ∈ ·), forall_exists_index]
rintro i rfl
apply approx_mono'
#align part.fix.le_f_of_mem_approx Part.Fix.le_f_of_mem_approx
theorem approx_mem_approxChain {i} : approx f i ∈ approxChain f :=
Stream'.mem_of_nth_eq rfl
#align part.fix.approx_mem_approx_chain Part.Fix.approx_mem_approxChain
end Fix
open Fix
variable {α : Type _}
variable (f : ((a : _) → Part <| β a) →o (a : _) → Part <| β a)
open OmegaCompletePartialOrder
open Part hiding ωSup
open Nat
open Nat.Upto OmegaCompletePartialOrder
theorem fix_eq_ωSup : Part.fix f = ωSup (approxChain f) := by
apply le_antisymm
· intro x
cases' exists_fix_le_approx f x with i hx
trans approx f i.succ x
· trans
apply hx
apply approx_mono' f
apply le_ωSup_of_le i.succ
dsimp [approx]
rfl
· apply ωSup_le _ _ _
simp only [Fix.approxChain, OrderHom.coe_fun_mk]
intro y x
apply approx_le_fix f
#align part.fix_eq_ωSup Part.fix_eq_ωSup
theorem fix_le {X : (a : _) → Part <| β a} (hX : f X ≤ X) : Part.fix f ≤ X := by
rw [fix_eq_ωSup f]
apply ωSup_le _ _ _
simp only [Fix.approxChain, OrderHom.coe_fun_mk]
intro i
induction i with
| zero => dsimp [Fix.approx]; apply bot_le
| succ _ i_ih => trans f X; apply f.monotone i_ih ; apply hX
#align part.fix_le Part.fix_le
variable {f} (hc : Continuous f)
theorem fix_eq : Part.fix f = f (Part.fix f) := by
rw [fix_eq_ωSup f, hc]
apply le_antisymm
· apply ωSup_le_ωSup_of_le _
intro i
exists i
intro x
-- intros x y hx,
apply le_f_of_mem_approx _ ⟨i, rfl⟩
· apply ωSup_le_ωSup_of_le _
intro i
exists i.succ
#align part.fix_eq Part.fix_eq
end Part
namespace Part
/-- `toUnit` as a monotone function -/
@[simps]
def toUnitMono (f : Part α →o Part α) : (Unit → Part α) →o Unit → Part α where
toFun x u := f (x u)
monotone' x y (h : x ≤ y) u := f.monotone <| h u
#align part.to_unit_mono Part.toUnitMono
theorem to_unit_cont (f : Part α →o Part α) (hc : Continuous f) : Continuous (toUnitMono f)
| _ => by
ext ⟨⟩ : 1
dsimp [OmegaCompletePartialOrder.ωSup]
erw [hc, Chain.map_comp]; rfl
#align part.to_unit_cont Part.to_unit_cont
-- Porting note: `noncomputable` is required because the code generator does not support recursor
-- `Acc.rec` yet.
noncomputable instance lawfulFix : LawfulFix (Part α) :=
⟨fun {f : Part α →o Part α} hc ↦ show Part.fix (toUnitMono f) () = _ by
rw [Part.fix_eq (to_unit_cont f hc)]; rfl⟩
#align part.lawful_fix Part.lawfulFix
end Part
open Sigma
namespace Pi
-- Porting note: `noncomputable` is required because the code generator does not support recursor
-- `Acc.rec` yet.
noncomputable instance lawfulFix {β} : LawfulFix (α → Part β) :=
⟨fun {_f} ↦ Part.fix_eq⟩
#align pi.lawful_fix Pi.lawfulFix
variable {γ : ∀ a : α, β a → Type _}
section Monotone
variable (α β γ)
/-- `Sigma.curry` as a monotone function. -/
@[simps]
def monotoneCurry [(x y : _) → Preorder <| γ x y] :
(∀ x : Σa, β a, γ x.1 x.2) →o ∀ (a) (b : β a), γ a b where
toFun := curry
monotone' _x _y h a b := h ⟨a, b⟩
#align pi.monotone_curry Pi.monotoneCurry
/-- `Sigma.uncurry` as a monotone function. -/
@[simps]
def monotoneUncurry [(x y : _) → Preorder <| γ x y] :
(∀ (a) (b : β a), γ a b) →o ∀ x : Σa, β a, γ x.1 x.2 where
toFun := uncurry
monotone' _x _y h a := h a.1 a.2
#align pi.monotone_uncurry Pi.monotoneUncurry
variable [(x y : _) → OmegaCompletePartialOrder <| γ x y]
open OmegaCompletePartialOrder.Chain
theorem continuous_curry : Continuous <| monotoneCurry α β γ := fun c ↦ by
ext (x y)
dsimp [curry, ωSup]
rw [map_comp, map_comp]
rfl
#align pi.continuous_curry Pi.continuous_curry
theorem continuous_uncurry : Continuous <| monotoneUncurry α β γ := fun c ↦ by
ext (x y)
dsimp [uncurry, ωSup]
rw [map_comp, map_comp]
rfl
#align pi.continuous_uncurry Pi.continuous_uncurry
end Monotone
open Fix
instance hasFix [Fix <| (x : Sigma β) → γ x.1 x.2] : Fix ((x : _) → (y : β x) → γ x y) :=
⟨fun f ↦ curry (fix <| uncurry ∘ f ∘ curry)⟩
#align pi.has_fix Pi.hasFix
variable [∀ x y, OmegaCompletePartialOrder <| γ x y]
section Curry
variable {f : ((x : _) → (y : β x) → γ x y) →o (x : _) → (y : β x) → γ x y}
variable (hc : Continuous f)
theorem uncurry_curry_continuous :
Continuous <| (monotoneUncurry α β γ).comp <| f.comp <| monotoneCurry α β γ :=
continuous_comp _ _ (continuous_comp _ _ (continuous_curry _ _ _) hc) (continuous_uncurry _ _ _)
#align pi.uncurry_curry_continuous Pi.uncurry_curry_continuous
end Curry
instance Pi.lawfulFix' [LawfulFix <| (x : Sigma β) → γ x.1 x.2] :
LawfulFix ((x y : _) → γ x y) where
fix_eq {_f} hc := by
dsimp [fix]
conv =>
lhs
erw [LawfulFix.fix_eq (uncurry_curry_continuous hc)]
#align pi.pi.lawful_fix' Pi.Pi.lawfulFix'
end Pi
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.