Datasets:
AI4M
/

text
stringlengths
0
3.34M
Formal statement is: lemma divideR_right: fixes x y :: "'a::real_normed_vector" shows "r \<noteq> 0 \<Longrightarrow> y = x /\<^sub>R r \<longleftrightarrow> r *\<^sub>R y = x" Informal statement is: If $r \neq 0$, then $y = x/r$ if and only if $r \cdot y = x$.
\subsection{Binary sequence types} % Binary Sequence Types -- bytes, bytearray, memoryview %
## 01강. 선형성 정의 및 1차 연립방정식 의미 ### 00. Linearity 선형성 - - - - Linearity 행렬로 표현되는 것이 기본적으로 선형성을 만족해야 함 - $f(x)$, x라는 변수에 대해서 function/operation 을 가지느냐 #### 조건 2가지를 만족할 때 Linearity 성립 - Superposition(중첩의 원리) : $f(x_{1}+x_{2}) = f(x_{1}) + f(x_{2})$ - Homogeniety $f(ax) = af(x)$ , a는 constant - $f(a_{1}x_{1}+a_{2}x_{2})=a_{1}f(x_{1})+a_{2}f(x_{2})$ : 이 조건을 만족할 때 선형성이 있다고 함, 이런 것들 선형대수에서 다룬다. - $ y = mx = f(x) $ : 위 두 조건을 만족하며 linear 하다 - $ y = mx + n $ : 원점을 지나지 않는 직선은 x와 y사이에 linearity 가 존재하지 않음, linear equation이라고 다 linearity를 가지는 것은 아니다. 하지만 변화량에는 선형성이 존재 #### operation의 linearity : differentiation, integration - $x_{1}(t), x_{2}(t) $ 에 대한 diff, inte의 선형성 알아보자 $\frac{d}{dt}(a_{1}x_{1}(t)+a_{2}x_{2}(t)) = a_{1}\frac{d}{dt}x_{1}(t)+a_{2}\frac{d}{dt}x_{2}(t)$ : linear 하다 - integration 해도 마찬가지로 만족된다. - 미분 적분 linearity 가지기 때문에 매트릭스 폼으로 바꿔서 연산 수행 가능 #### matrix의 linearity : 행렬 A에 벡터 $x_{1}, x_{2}$을 곱할 때 새로운 형태의 벡터 y가 나오는데 - $A(a_{1}x_{1}+a_{2}x_{2}) = a_{1}Ax_{1} + a_{2}Ax_{2}$ ### Before getting started : Basic Notations of Matrix - - - Vector v = (a, b, c) row vec 아니라 col vec 으로 쓰자 \begin{align} v = \begin{bmatrix} a \\ b \\ c \end{bmatrix} \end{align} - transpose(전치) : row와 column의 값을 interchange하는 것 ### 01. Linear Combination(선형결합) - - - \begin{align} v = \begin{bmatrix} a_{1} \\ b_{1} \\ c_{1} \end{bmatrix} \end{align} \begin{align} w = \begin{bmatrix} a_{2} \\ b_{2} \\ c_{2} \end{bmatrix} \end{align} $\alpha v + \beta w$를 계산한다 possible to express linear combination with multiplication of matrix and vector \begin{align} \begin{bmatrix} v \ w \end{bmatrix} = \begin{bmatrix} a_{1} \ a_{2} \\ b_{1} \ b_{2} \\ c_{1} \ c_{2} \\ \end{bmatrix} \end{align} \begin{align} \begin{bmatrix} a_{1} \ a_{2} \\ b_{1} \ b_{2} \\ c_{1} \ c_{2} \\ \end{bmatrix} \begin{bmatrix} \alpha \\ \beta \\ \end{bmatrix} \end{align} ### 02. What is Matrix? - - - - matrix is a set of number arranged in m x n (rows x columns) - matrix calculation : + - * (by using inverse matrix) - identitiy matrix : I - inverse matrix : right and left inverse - 2x2 matrix can be defined by using determinant! $\frac{1}{ad-bc}$ ### 03. What is Vector? - - - \begin{align} v = \begin{bmatrix} a \\ b \\ c \end{bmatrix} \end{align} geometrically addition of vector is drawn like parallelogram subtraction of vector $v_{1}-v_{2}$ is defined as a arrow from $v_{2}$ to $v_{1}$ - inner product(내적) $|v_{1}||v_{2}| cos\theta$ ### Chap1. Gauss Elimination - - - how to solve linear system sgn(부호함수) : 가우스 소거법으로 풀자 \begin{align} \begin{bmatrix} 1 \ \ 2 \\ 4 \ \ 5 \\ \end{bmatrix} \begin{bmatrix} x \\ y \\ \end{bmatrix} = \begin{bmatrix} 3 \\ 6 \\ \end{bmatrix} \end{align} geometically meaning of solution is intersection of two lines however, question could be solved with linear combination of two column vectors as well. #### For 3D 4D vector row form - intersection column form - linear combination of column vectors
{-# OPTIONS --cubical --no-import-sorts --guardedness --safe #-} module Cubical.Codata.M.AsLimit.itree where open import Cubical.Data.Unit open import Cubical.Data.Prod open import Cubical.Data.Nat as ℕ using (ℕ ; suc ; _+_ ) open import Cubical.Data.Sum open import Cubical.Data.Empty open import Cubical.Data.Bool open import Cubical.Foundations.Function open import Cubical.Foundations.Prelude open import Cubical.Codata.M.AsLimit.Container open import Cubical.Codata.M.AsLimit.M open import Cubical.Codata.M.AsLimit.Coalg -- Delay monad defined as an M-type delay-S : (R : Type₀) -> Container ℓ-zero delay-S R = (Unit ⊎ R) , λ { (inr _) -> ⊥ ; (inl tt) -> Unit } delay : (R : Type₀) -> Type₀ delay R = M (delay-S R) delay-ret : {R : Type₀} -> R -> delay R delay-ret r = in-fun (inr r , λ ()) delay-tau : {R : Type₀} -> delay R -> delay R delay-tau S = in-fun (inl tt , λ x → S) -- Bottom element raised data ⊥₁ : Type₁ where -- TREES tree-S : (E : Type₀ -> Type₁) (R : Type₀) -> Container (ℓ-suc ℓ-zero) tree-S E R = (R ⊎ (Σ[ A ∈ Type₀ ] (E A))) , (λ { (inl _) -> ⊥₁ ; (inr (A , e)) -> Lift A } ) tree : (E : Type₀ -> Type₁) (R : Type₀) -> Type₁ tree E R = M (tree-S E R) tree-ret : ∀ {E} {R} -> R -> tree E R tree-ret {E} {R} r = in-fun (inl r , λ ()) tree-vis : ∀ {E} {R} -> ∀ {A} -> E A -> (A -> tree E R) -> tree E R tree-vis {A = A} e k = in-fun (inr (A , e) , λ { (lift x) -> k x } ) -- ITrees (and buildup examples) -- https://arxiv.org/pdf/1906.00046.pdf -- Interaction Trees: Representing Recursive and Impure Programs in Coq -- Li-yao Xia, Yannick Zakowski, Paul He, Chung-Kil Hur, Gregory Malecha, Benjamin C. Pierce, Steve Zdancewic itree-S : ∀ (E : Type₀ -> Type₁) (R : Type₀) -> Container (ℓ-suc ℓ-zero) itree-S E R = ((Unit ⊎ R) ⊎ (Σ[ A ∈ Type₀ ] (E A))) , (λ { (inl (inl _)) -> Lift Unit ; (inl (inr _)) -> ⊥₁ ; (inr (A , e)) -> Lift A } ) itree : ∀ (E : Type₀ -> Type₁) (R : Type₀) -> Type₁ itree E R = M (itree-S E R) ret' : ∀ {E} {R} -> R -> P₀ (itree-S E R) (itree E R) ret' {E} {R} r = inl (inr r) , λ () tau' : {E : Type₀ -> Type₁} -> {R : Type₀} -> itree E R -> P₀ (itree-S E R) (itree E R) tau' t = inl (inl tt) , λ x → t vis' : ∀ {E} {R} -> ∀ {A : Type₀} -> E A -> (A -> itree E R) -> P₀ (itree-S E R) (itree E R) vis' {A = A} e k = inr (A , e) , λ { (lift x) -> k x } ret : ∀ {E} {R} -> R -> itree E R ret = in-fun ∘ ret' tau : {E : Type₀ -> Type₁} -> {R : Type₀} -> itree E R -> itree E R tau = in-fun ∘ tau' vis : ∀ {E} {R} -> ∀ {A : Type₀} -> E A -> (A -> itree E R) -> itree E R vis {A = A} e = in-fun ∘ (vis' {A = A} e)
[STATEMENT] lemma distinct_set_conv_list: "distinct xs \<Longrightarrow> set.F g (set xs) = list.F (map g xs)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. distinct xs \<Longrightarrow> set.F g (set xs) = list.F (map g xs) [PROOF STEP] by (induct xs) simp_all
#include <boost/logic/tribool_fwd.hpp> #include <boost/logic/tribool.hpp> #include <boost/logic/tribool_io.hpp> int main () { return 0; }
#!../venv/bin/python3 # -*- coding: utf-8 -*- """ +============================================================+ - Tác Giả: Hoàng Thành - Viện Toán Ứng dụng và Tin học(SAMI - HUST) - Email: [email protected] - Github: https://github.com/thanhhoangvan +============================================================+ """ import os import sys import time import threading from multiprocessing import Process, Lock, Array, Value, Queue import cv2 import numpy as np from .core import Camera camera_config = { 'number_of_cameras': 2, 'resolution': (720, 1080, 3), 'fps': 30, 'flip_mode': 2, } class BKAR: def __init__(self): self.CameraFrame = [] self.Speed = Value("f", -1.0) self.Light = Array("I", [0, 0, 0, 0]) self.Sensor = Array("f", [0., 0., 0.]) self.ContorlProcess = None self.CameraProcess = None self.ServerProcess = None self.driver_mode = Value("I", 0) # 0-REMOTE, 1-AI self.mp_logs_queue = Queue(maxsize=100) def start(self): # init camera: for cam in range(camera_config['number_of_cameras']): self.CameraFrame.append(Array("I", int(np.prod(camera_config['resolution'])), lock=Lock())) self.CameraProcess = Process(target=self.CameraManager, args=(camera_config, self.CameraFrame, self.mp_logs_queue,)) self.CameraProcess.start() # init control: def run(self): pass def stop(self): pass def driverByHand(self): pass pass def driverByAI(self): pass def CameraManager(self, config, mp_frames): pass if __name__=='__main__': pass
[STATEMENT] lemma ntr_is_tr_s: "(c,w,c')\<in>ntr fg \<Longrightarrow> (c,w,c')\<in>trcl (tr fg)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (c, w, c') \<in> ntr fg \<Longrightarrow> (c, w, c') \<in> trcl (tr fg) [PROOF STEP] by (erule gtrE) (auto dest: ntrs_is_trss_s intro: gtrI)
(* Title: HOL/Auth/n_german_lemma_inv__1_on_rules.thy Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences *) header{*The n_german Protocol Case Study*} theory n_german_lemma_inv__1_on_rules imports n_german_lemma_on_inv__1 begin section{*All lemmas on causal relation between inv__1*} lemma lemma_inv__1_on_rules: assumes b1: "r \<in> rules N" and b2: "(f=inv__1 )" shows "invHoldForRule s f r (invariants N)" proof - have c1: "(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)\<or> (\<exists> i. i\<le>N\<and>r=n_SendReqS i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvReqE N i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInvAck i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendGntS i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendGntE N i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvGntS i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" apply (cut_tac b1, auto) done moreover { assume d1: "(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_StoreVsinv__1) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendReqSVsinv__1) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendReqE__part__0Vsinv__1) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendReqE__part__1Vsinv__1) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvReqSVsinv__1) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqE N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvReqEVsinv__1) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInv__part__0Vsinv__1) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInv__part__1Vsinv__1) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInvAckVsinv__1) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvInvAckVsinv__1) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendGntS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendGntSVsinv__1) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendGntE N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendGntEVsinv__1) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvGntSVsinv__1) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvGntEVsinv__1) done } ultimately show "invHoldForRule s f r (invariants N)" by satx qed end
module VecFlip where open import AgdaPrelude goodNil : Vec Nat Zero goodNil = Nil Nat badNil : Vec Zero Nat badNil = Nil Nat
From iris.algebra Require Import mono_nat mono_list gmap_view gset. From Perennial.base_logic Require Import ghost_map mono_nat saved_prop. From Perennial.program_proof.mvcc Require Import mvcc_prelude. (* RA definitions. *) Local Definition vchainR := mono_listR dbvalO. Local Definition key_vchainR := gmapR u64 vchainR. Local Definition tidsR := gmap_viewR nat unitO. Local Definition sid_tidsR := gmapR u64 tidsR. Local Definition sid_min_tidR := gmapR u64 mono_natR. Local Definition sid_ownR := gmapR u64 (exclR unitO). Lemma sids_all_lookup (sid : u64) : int.Z sid < N_TXN_SITES -> sids_all !! (int.nat sid) = Some sid. Proof. intros H. unfold sids_all. rewrite list_lookup_fmap. rewrite lookup_seqZ_lt; last word. simpl. f_equal. word. Qed. (* Global ghost states. *) Class mvcc_ghostG Σ := { (* SST *) mvcc_ptupleG :> inG Σ key_vchainR; mvcc_ltupleG :> inG Σ key_vchainR; mvcc_abort_tids_ncaG :> ghost_mapG Σ nat unit; mvcc_abort_tids_faG :> ghost_mapG Σ nat unit; mvcc_abort_tids_fciG :> ghost_mapG Σ (nat * dbmap) unit; mvcc_abort_tids_fccG :> ghost_mapG Σ (nat * dbmap) unit; mvcc_commit_tidsG :> ghost_mapG Σ (nat * dbmap) unit; mvcc_dbmapG :> ghost_mapG Σ u64 dbval; (* GenTID *) mvcc_tsG :> mono_natG Σ; mvcc_sidG :> inG Σ sid_ownR; mvcc_gentid_reservedG :> ghost_mapG Σ u64 gname; mvcc_gentid_predG :> savedPredG Σ val; (* GC *) mvcc_sid_tidsG :> inG Σ sid_tidsR; mvcc_sid_min_tidG :> inG Σ sid_min_tidR; }. Definition mvcc_ghostΣ := #[ GFunctor key_vchainR; GFunctor key_vchainR; mono_natΣ; ghost_mapΣ nat unit; ghost_mapΣ nat unit; ghost_mapΣ (nat * dbmap) unit; ghost_mapΣ (nat * dbmap) unit; ghost_mapΣ (nat * dbmap) unit; ghost_mapΣ u64 dbval; GFunctor sid_ownR; ghost_mapΣ u64 gname; savedPredΣ val; GFunctor sid_tidsR; GFunctor sid_min_tidR ]. #[global] Instance subG_mvcc_ghostG {Σ} : subG mvcc_ghostΣ Σ → mvcc_ghostG Σ. Proof. solve_inG. Qed. Record mvcc_names := { mvcc_ptuple : gname; mvcc_ltuple : gname; mvcc_abort_tids_nca : gname; mvcc_abort_tids_fa : gname; mvcc_abort_tmods_fci : gname; mvcc_abort_tmods_fcc : gname; mvcc_cmt_tmods : gname; mvcc_dbmap : gname; mvcc_sids : gname; mvcc_ts : gname; mvcc_gentid_reserved : gname; mvcc_sid_tids : gname; mvcc_sid_min_tid : gname }. (* Per-txn ghost state. *) Class mvcc_txn_ghostG Σ := { mvcc_txnmapG :> ghost_mapG Σ u64 dbval; }. Definition mvcc_txn_ghostΣ := #[ ghost_mapΣ u64 dbval ]. #[global] Instance subG_mvcc_txn_ghostG {Σ} : subG mvcc_txn_ghostΣ Σ → mvcc_txn_ghostG Σ. Proof. solve_inG. Qed. Section definitions. Context `{!mvcc_ghostG Σ}. (* TODO: Make it [k q phys]. *) Definition ptuple_auth_def γ q (k : u64) (phys : list dbval) : iProp Σ := own γ (A:=key_vchainR) {[k := ●ML{# q } phys]}. Definition ptuple_auth γ q (k : u64) (phys : list dbval) : iProp Σ := ptuple_auth_def γ.(mvcc_ptuple) q k phys. Definition ptuple_lb γ (k : u64) (phys : list dbval) : iProp Σ := own γ.(mvcc_ptuple) {[k := ◯ML phys]}. Definition ltuple_auth_def γ (k : u64) (logi : list dbval) : iProp Σ := own γ {[k := ●ML logi]}. Definition ltuple_auth γ (k : u64) (logi : list dbval) : iProp Σ := ltuple_auth_def γ.(mvcc_ltuple) k logi. Definition ltuple_lb γ (k : u64) (logi : list dbval) : iProp Σ := own γ.(mvcc_ltuple) {[k := ◯ML logi]}. Definition ptuple_ptsto γ (k : u64) (v : dbval) (ts : nat) : iProp Σ := ∃ phys, ptuple_lb γ k phys ∗ ⌜phys !! ts = Some v⌝. Definition mods_token γ (k : u64) (ts : nat) : iProp Σ := ∃ phys, ptuple_auth γ (1/4) k phys ∗ ⌜(length phys ≤ S ts)%nat⌝. Definition ltuple_ptsto γ (k : u64) (v : dbval) (ts : nat) : iProp Σ := ∃ logi, ltuple_lb γ k logi ∗ ⌜logi !! ts = Some v⌝. Definition ltuple_ptstos γ (m : dbmap) (ts : nat) : iProp Σ := [∗ map] k ↦ v ∈ m, ltuple_ptsto γ k v ts. (* Definitions about GC-related resources. *) Definition site_active_tids_auth_def γ (sid : u64) q (tids : gset nat) : iProp Σ := own γ {[sid := (gmap_view_auth (DfracOwn q) (gset_to_gmap tt tids))]}. Definition site_active_tids_auth γ sid tids : iProp Σ := site_active_tids_auth_def γ.(mvcc_sid_tids) sid 1 tids. Definition site_active_tids_half_auth γ sid tids : iProp Σ := site_active_tids_auth_def γ.(mvcc_sid_tids) sid (1 / 2) tids. Definition site_active_tids_frag_def γ (sid : u64) tid : iProp Σ := own γ {[sid := (gmap_view_frag tid (DfracOwn 1) tt)]}. Definition site_active_tids_frag γ (sid : u64) tid : iProp Σ := site_active_tids_frag_def γ.(mvcc_sid_tids) sid tid. Definition active_tid γ (tid sid : u64) : iProp Σ := (site_active_tids_frag γ sid (int.nat tid) ∧ ⌜int.Z sid < N_TXN_SITES⌝) ∧ ⌜(0 < int.Z tid < 2 ^ 64 - 1)⌝ . Definition site_min_tid_auth_def γ (sid : u64) q tid : iProp Σ := own γ {[sid := (●MN{# q} tid)]}. Definition site_min_tid_auth γ (sid : u64) tid : iProp Σ := site_min_tid_auth_def γ.(mvcc_sid_min_tid) sid 1 tid. Definition site_min_tid_lb γ (sid : u64) tid : iProp Σ := own γ.(mvcc_sid_min_tid) {[sid := (◯MN tid)]}. Definition min_tid_lb γ tid : iProp Σ := [∗ list] sid ∈ sids_all, site_min_tid_lb γ sid tid. (* Definitions about SST-related resources. *) Definition ts_auth γ (ts : nat) : iProp Σ := mono_nat_auth_own γ.(mvcc_ts) (1/2) ts. Definition ts_lb γ (ts : nat) : iProp Σ := mono_nat_lb_own γ.(mvcc_ts) ts. Definition sid_own γ (sid : u64) : iProp Σ := own γ.(mvcc_sids) ({[ sid := Excl () ]}). Definition nca_tids_auth γ (tids : gset nat) : iProp Σ := ghost_map_auth γ.(mvcc_abort_tids_nca) 1 (gset_to_gmap tt tids). Definition nca_tids_frag γ (tid : nat) : iProp Σ := ghost_map_elem γ.(mvcc_abort_tids_nca) tid (DfracOwn 1) tt. Definition fa_tids_auth γ (tids : gset nat) : iProp Σ := ghost_map_auth γ.(mvcc_abort_tids_fa) 1 (gset_to_gmap tt tids). Definition fa_tids_frag γ (tid : nat) : iProp Σ := ghost_map_elem γ.(mvcc_abort_tids_fa) tid (DfracOwn 1) tt. Definition fci_tmods_auth (γ : mvcc_names) (tmods : gset (nat * dbmap)) : iProp Σ := ghost_map_auth γ.(mvcc_abort_tmods_fci) 1 (gset_to_gmap tt tmods). Definition fci_tmods_frag γ (tmod : nat * dbmap) : iProp Σ := ghost_map_elem γ.(mvcc_abort_tmods_fci) tmod (DfracOwn 1) tt. Definition fcc_tmods_auth (γ : mvcc_names) (tmods : gset (nat * dbmap)) : iProp Σ := ghost_map_auth γ.(mvcc_abort_tmods_fcc) 1 (gset_to_gmap tt tmods). Definition fcc_tmods_frag γ (tmod : nat * dbmap) : iProp Σ := ghost_map_elem γ.(mvcc_abort_tmods_fcc) tmod (DfracOwn 1) tt. Definition cmt_tmods_auth (γ : mvcc_names) (tmods : gset (nat * dbmap)) : iProp Σ := ghost_map_auth γ.(mvcc_cmt_tmods) 1 (gset_to_gmap tt tmods). Definition cmt_tmods_frag γ (tmod : nat * dbmap) : iProp Σ := ghost_map_elem γ.(mvcc_cmt_tmods) tmod (DfracOwn 1) tt. Definition dbmap_auth γ (m : dbmap) : iProp Σ := ghost_map_auth γ.(mvcc_dbmap) 1 m. Definition dbmap_ptsto γ k q (v : dbval) : iProp Σ := ghost_map_elem γ.(mvcc_dbmap) k (DfracOwn q) v. Definition dbmap_ptstos γ q (m : dbmap) : iProp Σ := [∗ map] k ↦ v ∈ m, dbmap_ptsto γ k q v. (* Definitions about per-txn resources. *) Definition txnmap_auth τ (m : dbmap) : iProp Σ := ghost_map_auth τ 1 m. Definition txnmap_ptsto τ k (v : dbval) : iProp Σ := ghost_map_elem τ k (DfracOwn 1) v. Definition txnmap_ptstos τ (m : dbmap) : iProp Σ := [∗ map] k ↦ v ∈ m, txnmap_ptsto τ k v. End definitions. Section lemmas. Context `{!heapGS Σ, !mvcc_ghostG Σ}. (* TODO: Renmae [vchain_] to [ptuple_] *) Lemma vchain_combine {γ} q {q1 q2 key vchain1 vchain2} : (q1 + q2 = q)%Qp -> ptuple_auth γ q1 key vchain1 -∗ ptuple_auth γ q2 key vchain2 -∗ ptuple_auth γ q key vchain1 ∧ ⌜vchain2 = vchain1⌝. Proof. iIntros "%Hq Hv1 Hv2". iCombine "Hv1 Hv2" as "Hv". iDestruct (own_valid with "Hv") as %Hvalid. rewrite singleton_valid mono_list_auth_dfrac_op_valid_L in Hvalid. destruct Hvalid as [_ <-]. rewrite -mono_list_auth_dfrac_op dfrac_op_own Hq. naive_solver. Qed. Lemma vchain_split {γ q} q1 q2 {key vchain} : (q1 + q2 = q)%Qp -> ptuple_auth γ q key vchain -∗ ptuple_auth γ q1 key vchain ∗ ptuple_auth γ q2 key vchain. Proof. iIntros "%Hq Hv". subst q. iDestruct "Hv" as "[Hv1 Hv2]". iFrame. Qed. Lemma vchain_witness γ q k vchain : ptuple_auth γ q k vchain -∗ ptuple_lb γ k vchain. Proof. iApply own_mono. apply singleton_mono, mono_list_included. Qed. Lemma ptuple_prefix γ q k l l' : ptuple_auth γ q k l -∗ ptuple_lb γ k l' -∗ ⌜prefix l' l⌝. Proof. iIntros "Hl Hl'". iDestruct (own_valid_2 with "Hl Hl'") as %Hvalid. iPureIntro. revert Hvalid. rewrite singleton_op singleton_valid. rewrite mono_list_both_dfrac_valid_L. by intros [_ H]. Qed. Lemma vchain_update {γ key vchain} vchain' : prefix vchain vchain' → ptuple_auth γ (1 / 2) key vchain -∗ ptuple_auth γ (1 / 2) key vchain ==∗ ptuple_auth γ (1 / 2) key vchain' ∗ ptuple_auth γ (1 / 2) key vchain'. Proof. iIntros "%Hprefix Hv1 Hv2". iAssert (ptuple_auth γ 1 key vchain') with "[> Hv1 Hv2]" as "[Hv1 Hv2]". { iCombine "Hv1 Hv2" as "Hv". iApply (own_update with "Hv"). apply singleton_update, mono_list_update. done. } by iFrame. Qed. Lemma vchain_false {γ q key vchain} : (1 < q)%Qp -> ptuple_auth γ q key vchain -∗ False. Proof. iIntros (Hq) "Hv". iDestruct (own_valid with "Hv") as %Hvalid. rewrite singleton_valid mono_list_auth_dfrac_valid dfrac_valid_own in Hvalid. apply Qp.lt_nge in Hq. done. Qed. Lemma ptuple_agree {γ q1 q2 key vchain1 vchain2} : ptuple_auth γ q1 key vchain1 -∗ ptuple_auth γ q2 key vchain2 -∗ ⌜vchain1 = vchain2⌝. Proof. iIntros "Hv1 Hv2". iDestruct (own_valid_2 with "Hv1 Hv2") as %Hvalid. rewrite singleton_op singleton_valid mono_list_auth_dfrac_op_valid_L in Hvalid. by destruct Hvalid as [_ Hv]. Qed. Lemma ltuple_update {γ key l} l' : prefix l l' → ltuple_auth γ key l ==∗ ltuple_auth γ key l'. Proof. iIntros "%Hprefix Hl". iApply (own_update with "Hl"). apply singleton_update, mono_list_update. done. Qed. Lemma ltuple_witness γ k l : ltuple_auth γ k l -∗ ltuple_lb γ k l. Proof. iApply own_mono. apply singleton_mono, mono_list_included. Qed. Lemma ltuple_prefix γ k l l' : ltuple_auth γ k l -∗ ltuple_lb γ k l' -∗ ⌜prefix l' l⌝. Proof. iIntros "Hl Hl'". iDestruct (own_valid_2 with "Hl Hl'") as %Hval. iPureIntro. revert Hval. rewrite singleton_op singleton_valid. by rewrite mono_list_both_valid_L. Qed. Lemma site_active_tids_elem_of γ (sid : u64) tids tid : site_active_tids_half_auth γ sid tids -∗ site_active_tids_frag γ sid tid -∗ ⌜tid ∈ tids⌝. Proof. iIntros "Hauth Helem". iDestruct (own_valid_2 with "Hauth Helem") as %Hvalid. rewrite singleton_op singleton_valid gmap_view_both_dfrac_valid_L in Hvalid. destruct Hvalid as (_ & _ & Hlookup). apply elem_of_dom_2 in Hlookup. rewrite dom_gset_to_gmap in Hlookup. done. Qed. Lemma site_active_tids_agree γ (sid : u64) tids tids' : site_active_tids_half_auth γ sid tids -∗ site_active_tids_half_auth γ sid tids' -∗ ⌜tids = tids'⌝. Proof. iIntros "Hauth1 Hauth2". iDestruct (own_valid_2 with "Hauth1 Hauth2") as %Hvalid. rewrite singleton_op singleton_valid gmap_view_auth_dfrac_op_valid_L in Hvalid. destruct Hvalid as [_ Etids]. rewrite -(dom_gset_to_gmap tids ()) -(dom_gset_to_gmap tids' ()). by rewrite Etids. Qed. Lemma site_active_tids_insert {γ sid tids} tid : tid ∉ tids -> site_active_tids_half_auth γ sid tids -∗ site_active_tids_half_auth γ sid tids ==∗ site_active_tids_half_auth γ sid ({[ tid ]} ∪ tids) ∗ site_active_tids_half_auth γ sid ({[ tid ]} ∪ tids) ∗ site_active_tids_frag γ sid tid. Proof. iIntros "%Hdom Hauth1 Hauth2". iAssert (site_active_tids_auth γ sid ({[ tid ]} ∪ tids) ∗ site_active_tids_frag γ sid tid)%I with "[> Hauth1 Hauth2]" as "[[Hauth1 Hauth2] Hfrag]". { iCombine "Hauth1 Hauth2" as "Hauth". rewrite -own_op singleton_op. iApply (own_update with "Hauth"). apply singleton_update. rewrite gset_to_gmap_union_singleton. (* Q: What's the difference between [apply] (which fails here) and [apply:]? *) apply: gmap_view_alloc; last done. by rewrite lookup_gset_to_gmap_None. } by iFrame. Qed. Lemma site_active_tids_delete {γ sid tids} tid : site_active_tids_frag γ sid tid -∗ site_active_tids_half_auth γ sid tids -∗ site_active_tids_half_auth γ sid tids ==∗ site_active_tids_half_auth γ sid (tids ∖ {[ tid ]}) ∗ site_active_tids_half_auth γ sid (tids ∖ {[ tid ]}). Proof. iIntros "Hfrag Hauth1 Hauth2". iAssert (site_active_tids_auth γ sid (tids ∖ {[ tid ]}))%I with "[> Hfrag Hauth1 Hauth2]" as "[Hauth1 Hauth2]". { iCombine "Hauth1 Hauth2" as "Hauth". iApply (own_update_2 with "Hauth Hfrag"). rewrite singleton_op. rewrite gset_to_gmap_difference_singleton. apply singleton_update. apply: gmap_view_delete. } by iFrame. Qed. Lemma site_min_tid_valid γ (sid : u64) tidN tidlbN : site_min_tid_auth γ sid tidN -∗ site_min_tid_lb γ sid tidlbN -∗ ⌜(tidlbN ≤ tidN)%nat⌝. Proof. iIntros "Hauth Hlb". iDestruct (own_valid_2 with "Hauth Hlb") as %Hvalid. rewrite singleton_op singleton_valid mono_nat_both_dfrac_valid in Hvalid. by destruct Hvalid as [_ Hle]. Qed. Lemma site_min_tid_lb_weaken γ (sid : u64) tidN tidN' : (tidN' ≤ tidN)%nat -> site_min_tid_lb γ sid tidN -∗ site_min_tid_lb γ sid tidN'. Proof. iIntros "%Hle Hlb". iApply (own_mono with "Hlb"). rewrite singleton_included. right. apply mono_nat_lb_mono. done. Qed. Lemma site_min_tid_update {γ sid tid} tid' : (tid ≤ tid')%nat -> site_min_tid_auth γ sid tid ==∗ site_min_tid_auth γ sid tid'. Proof. iIntros "%Hle Hauth". iApply (own_update with "Hauth"). apply singleton_update, mono_nat_update. done. Qed. Lemma site_min_tid_witness {γ sid tid} : site_min_tid_auth γ sid tid -∗ site_min_tid_lb γ sid tid. Proof. iApply own_mono. apply singleton_mono, mono_nat_included. Qed. Lemma min_tid_lb_zero γ : ([∗ list] sid ∈ sids_all, ∃ tid, site_min_tid_auth γ sid tid) -∗ min_tid_lb γ 0%nat. Proof. iApply big_sepL_mono. iIntros (sidN sid) "%Hlookup Hauth". iDestruct "Hauth" as (tid) "Hauth". iDestruct (site_min_tid_witness with "Hauth") as "Hlb". iRevert "Hlb". iApply site_min_tid_lb_weaken. lia. Qed. Lemma ts_witness {γ ts} : ts_auth γ ts -∗ ts_lb γ ts. Proof. iApply mono_nat_lb_own_get. Qed. Lemma ts_lb_weaken {γ ts} ts' : (ts' ≤ ts)%nat -> ts_lb γ ts -∗ ts_lb γ ts'. Proof. iIntros "%Hle Hlb". iApply mono_nat_lb_own_le; done. Qed. Lemma ts_auth_lb_le {γ ts ts'} : ts_auth γ ts -∗ ts_lb γ ts' -∗ ⌜(ts' ≤ ts)%nat⌝. Proof. iIntros "Hauth Hlb". iDestruct (mono_nat_lb_own_valid with "Hauth Hlb") as %[_ Hle]. done. Qed. Lemma ptuples_alloc : ⊢ |==> ∃ γ, ([∗ set] key ∈ keys_all, ptuple_auth_def γ (1 / 2) key [Nil; Nil]) ∗ ([∗ set] key ∈ keys_all, ptuple_auth_def γ (1 / 2) key [Nil; Nil]). Proof. set m := gset_to_gmap (●ML ([Nil; Nil])) keys_all. iMod (own_alloc m) as (γ) "Htpls". { intros k. rewrite lookup_gset_to_gmap option_guard_True; last apply elem_of_fin_to_set. rewrite Some_valid. apply mono_list_auth_valid. } iModIntro. iExists γ. iAssert ([∗ set] key ∈ keys_all, ptuple_auth_def γ 1 key [Nil; Nil])%I with "[Htpls]" as "Htpls". { rewrite -(big_opM_singletons m). rewrite big_opM_own_1. replace keys_all with (dom m); last by by rewrite dom_gset_to_gmap. iApply big_sepM_dom. iApply (big_sepM_impl with "Htpls"). iIntros "!>" (k v). subst m. rewrite lookup_gset_to_gmap_Some. iIntros ([_ <-]) "Htpls". done. } rewrite -big_sepS_sep. iApply (big_sepS_mono with "Htpls"). iIntros (k Helem) "[Htpl1 Htpl2]". iFrame. Qed. Lemma ltuples_alloc : ⊢ |==> ∃ γ, ([∗ set] key ∈ keys_all, ltuple_auth_def γ key [Nil; Nil]). Proof. set m := gset_to_gmap (●ML ([Nil; Nil])) keys_all. iMod (own_alloc m) as (γ) "Htpls". { intros k. rewrite lookup_gset_to_gmap option_guard_True; last apply elem_of_fin_to_set. rewrite Some_valid. apply mono_list_auth_valid. } iModIntro. iExists γ. rewrite -(big_opM_singletons m). rewrite big_opM_own_1. replace keys_all with (dom m); last by by rewrite dom_gset_to_gmap. iApply big_sepM_dom. iApply (big_sepM_impl with "Htpls"). iIntros "!>" (k v). subst m. rewrite lookup_gset_to_gmap_Some. iIntros ([_ <-]) "Htpls". done. Qed. Lemma site_active_tids_alloc : ⊢ |==> ∃ γ, ([∗ list] sid ∈ sids_all, site_active_tids_auth_def γ sid (1 / 2) ∅) ∗ ([∗ list] sid ∈ sids_all, site_active_tids_auth_def γ sid (1 / 2) ∅). Proof. set u64_all : gset u64 := (fin_to_set u64). set m := gset_to_gmap (gmap_view_auth (DfracOwn 1) (∅ : gmap nat unit)) u64_all. iMod (own_alloc m) as (γ) "Hown". { intros k. rewrite lookup_gset_to_gmap option_guard_True; last apply elem_of_fin_to_set. rewrite Some_valid. apply gmap_view_auth_valid. } iModIntro. iExists γ. iAssert ([∗ set] sid ∈ u64_all, site_active_tids_auth_def γ sid 1 ∅)%I with "[Hown]" as "Hown". { rewrite -(big_opM_singletons m). rewrite big_opM_own_1. replace u64_all with (dom m); last by by rewrite dom_gset_to_gmap. iApply big_sepM_dom. iApply (big_sepM_impl with "Hown"). iIntros "!>" (k v). subst m. rewrite lookup_gset_to_gmap_Some. iIntros ([_ <-]) "Hown". unfold site_active_tids_auth_def. iFrame. rewrite gset_to_gmap_empty. done. } set sids : gset u64 := list_to_set sids_all. iDestruct (big_sepS_subseteq _ _ sids with "Hown") as "Hown"; first set_solver. subst sids. rewrite big_sepS_list_to_set; last first. { unfold sids_all. unfold N_TXN_SITES. apply seq_U64_NoDup; word. } rewrite -big_sepL_sep. iApply (big_sepL_mono with "Hown"). iIntros (sid sidN Helem) "[H1 H2]". iFrame. Qed. Lemma site_min_tid_alloc : ⊢ |==> ∃ γ, ([∗ list] sid ∈ sids_all, site_min_tid_auth_def γ sid 1 0). Proof. set u64_all : gset u64 := (fin_to_set u64). set m := gset_to_gmap (●MN 0) u64_all. iMod (own_alloc m) as (γ) "Hown". { intros k. rewrite lookup_gset_to_gmap option_guard_True; last apply elem_of_fin_to_set. rewrite Some_valid. apply mono_nat_auth_valid. } iModIntro. iExists γ. iAssert ([∗ set] sid ∈ u64_all, site_min_tid_auth_def γ sid 1 0)%I with "[Hown]" as "Hown". { rewrite -(big_opM_singletons m). rewrite big_opM_own_1. replace u64_all with (dom m); last by by rewrite dom_gset_to_gmap. iApply big_sepM_dom. iApply (big_sepM_impl with "Hown"). iIntros "!>" (k v). subst m. rewrite lookup_gset_to_gmap_Some. iIntros ([_ <-]) "Hown". done. } set sids : gset u64 := list_to_set sids_all. iDestruct (big_sepS_subseteq _ _ sids with "Hown") as "Hown"; first set_solver. subst sids. rewrite big_sepS_list_to_set; last first. { unfold sids_all. unfold N_TXN_SITES. apply seq_U64_NoDup; word. } done. Qed. Definition mvcc_gentid_init γ : iProp Σ := ts_auth γ 0%nat ∗ ghost_map_auth γ.(mvcc_gentid_reserved) 1 (∅ : gmap u64 gname). Lemma mvcc_ghost_alloc : ⊢ |==> ∃ γ, (* SST-related. *) ([∗ set] key ∈ keys_all, ptuple_auth γ (1/2) key [Nil; Nil]) ∗ ([∗ set] key ∈ keys_all, ptuple_auth γ (1/2) key [Nil; Nil]) ∗ ([∗ set] key ∈ keys_all, ltuple_auth γ key [Nil; Nil]) ∗ ts_auth γ 0%nat ∗ ([∗ list] sid ∈ sids_all, sid_own γ sid) ∗ nca_tids_auth γ ∅ ∗ fa_tids_auth γ ∅ ∗ fci_tmods_auth γ ∅ ∗ fcc_tmods_auth γ ∅ ∗ cmt_tmods_auth γ ∅ ∗ let dbmap_init := (gset_to_gmap Nil keys_all) in dbmap_auth γ dbmap_init ∗ ([∗ map] k ↦ v ∈ dbmap_init, dbmap_ptsto γ k 1 v) ∗ mvcc_gentid_init γ ∗ (* GC-related. *) ([∗ list] sid ∈ sids_all, site_active_tids_half_auth γ sid ∅) ∗ ([∗ list] sid ∈ sids_all, site_active_tids_half_auth γ sid ∅) ∗ ([∗ list] sid ∈ sids_all, site_min_tid_auth γ sid 0). Proof. iMod ptuples_alloc as (γptuple) "[Hptpls1 Hptpls2]". iMod ltuples_alloc as (γltuple) "Hltpls". iMod (mono_nat_own_alloc 0) as (γts) "[[Hts1 Hts2] _]". set sids : gset u64 := list_to_set sids_all. iMod (own_alloc (A:=sid_ownR) (gset_to_gmap (Excl tt) sids)) as (γsids) "Hsids". { intros k. rewrite lookup_gset_to_gmap. destruct (decide (k ∈ sids)). - rewrite option_guard_True //. - rewrite option_guard_False //. } iMod (ghost_map_alloc (∅ : gmap nat unit)) as (γnca) "[Hnca _]". iMod (ghost_map_alloc (∅ : gmap nat unit)) as (γfa) "[Hfa _]". iMod (ghost_map_alloc (∅ : gmap (nat * dbmap) unit)) as (γfci) "[Hfci _]". iMod (ghost_map_alloc (∅ : gmap (nat * dbmap) unit)) as (γfcc) "[Hfcc _]". iMod (ghost_map_alloc (∅ : gmap (nat * dbmap) unit)) as (γcmt) "[Hcmt _]". iMod (ghost_map_alloc (gset_to_gmap Nil keys_all)) as (γm) "[Hm Hpts]". iMod (ghost_map_alloc (∅ : gmap u64 gname)) as (γres) "[Hres _]". iMod site_active_tids_alloc as (γactive) "[Hacts1 Hacts2]". iMod site_min_tid_alloc as (γmin) "Hmin". set γ := {| mvcc_ptuple := γptuple; mvcc_ltuple := γltuple; mvcc_ts := γts; mvcc_sids := γsids; mvcc_abort_tids_nca := γnca; mvcc_abort_tids_fa := γfa; mvcc_abort_tmods_fci := γfci; mvcc_abort_tmods_fcc := γfcc; mvcc_cmt_tmods := γcmt; mvcc_dbmap := γm; mvcc_gentid_reserved := γres; mvcc_sid_tids := γactive; mvcc_sid_min_tid := γmin |}. iExists γ. rewrite /mvcc_gentid_init. iAssert ([∗ list] sid ∈ sids_all, sid_own γ sid)%I with "[Hsids]" as "Hsids". { iEval (rewrite -[gset_to_gmap _ _]big_opM_singletons) in "Hsids". rewrite big_opM_own_1. rewrite big_opM_map_to_list. rewrite map_to_list_gset_to_gmap. subst sids. rewrite big_sepL_fmap elements_list_to_set. 2:{ unfold sids_all. apply NoDup_fmap_2_strong, NoDup_seqZ. Set Printing Coercions. clear. intros x y Hx%elem_of_seqZ Hy%elem_of_seqZ Heq. unfold N_TXN_SITES in *. rewrite -(Z_u64 x); last lia. rewrite -(Z_u64 y); last lia. rewrite Heq. done. Unset Printing Coercions. } iFrame. } iFrame. unfold nca_tids_auth, fa_tids_auth, fci_tmods_auth, fcc_tmods_auth, cmt_tmods_auth. do 2 rewrite gset_to_gmap_empty. by iFrame. Qed. (** * Lemma [ghost_map_lookup_big] is not helpful here since we want to * specify the fraction of fragmentary elements. *) Lemma dbmap_lookup_big {γ q m} m' : dbmap_auth γ m -∗ dbmap_ptstos γ q m' -∗ ⌜m' ⊆ m⌝. Proof. iIntros "Hauth Hpts". rewrite map_subseteq_spec. iIntros (k v Hm0). iDestruct (ghost_map_lookup with "Hauth [Hpts]") as %->. { rewrite /dbmap_ptstos big_sepM_lookup; done. } done. Qed. Lemma dbmap_update_big {γ m} m0 m1 : dom m0 = dom m1 → dbmap_auth γ m -∗ dbmap_ptstos γ 1 m0 ==∗ dbmap_auth γ (m1 ∪ m) ∗ dbmap_ptstos γ 1 m1. Proof. iIntros "%Hdom Hauth Hpts". iApply (ghost_map_update_big with "Hauth Hpts"). done. Qed. Lemma dbmap_elem_split {γ k q} q1 q2 v : (q1 + q2 = q)%Qp -> dbmap_ptsto γ k q v -∗ dbmap_ptsto γ k q1 v ∗ dbmap_ptsto γ k q2 v. Proof. iIntros "%Hq Hpt". subst q. iDestruct "Hpt" as "[Hpt1 Hpt2]". iFrame. Qed. Lemma dbmap_elem_combine {γ k} q1 q2 v1 v2 : dbmap_ptsto γ k q1 v1 -∗ dbmap_ptsto γ k q2 v2 -∗ dbmap_ptsto γ k (q1 + q2) v1 ∗ ⌜v1 = v2⌝. Proof. iIntros "Hpt1 Hpt2". iDestruct (ghost_map_elem_combine with "Hpt1 Hpt2") as "[Hpt %Eqv]". rewrite dfrac_op_own. by iFrame. Qed. Lemma txnmap_lookup τ m k v : txnmap_auth τ m -∗ txnmap_ptsto τ k v -∗ ⌜m !! k = Some v⌝. Proof. apply: ghost_map_lookup. Qed. Lemma txnmap_lookup_big τ m m' : txnmap_auth τ m -∗ txnmap_ptstos τ m' -∗ ⌜m' ⊆ m⌝. Proof. apply: ghost_map_lookup_big. Qed. Lemma txnmap_update {τ m k v} w : txnmap_auth τ m -∗ txnmap_ptsto τ k v ==∗ txnmap_auth τ (<[ k := w ]> m) ∗ txnmap_ptsto τ k w. Proof. apply: ghost_map_update. Qed. Lemma txnmap_alloc m : ⊢ |==> ∃ τ, txnmap_auth τ m ∗ ([∗ map] k ↦ v ∈ m, txnmap_ptsto τ k v). Proof. apply: ghost_map_alloc. Qed. Lemma nca_tids_insert {γ tids} tid : tid ∉ tids -> nca_tids_auth γ tids ==∗ nca_tids_auth γ ({[ tid ]} ∪ tids) ∗ nca_tids_frag γ tid. Proof. iIntros "%Hnotin Hauth". unfold nca_tids_auth. rewrite gset_to_gmap_union_singleton. iApply (ghost_map_insert with "Hauth"). rewrite lookup_gset_to_gmap_None. done. Qed. Lemma nca_tids_delete {γ tids} tid : nca_tids_auth γ tids -∗ nca_tids_frag γ tid ==∗ nca_tids_auth γ (tids ∖ {[ tid ]}). Proof. iIntros "Hauth Helem". unfold nca_tids_auth. rewrite gset_to_gmap_difference_singleton. iApply (ghost_map_delete with "Hauth Helem"). Qed. Lemma nca_tids_lookup {γ tids} tid : nca_tids_auth γ tids -∗ nca_tids_frag γ tid -∗ ⌜tid ∈ tids⌝. Proof. iIntros "Hauth Helem". iDestruct (ghost_map_lookup with "Hauth Helem") as "%Hlookup". apply lookup_gset_to_gmap_Some in Hlookup as [Helem _]. done. Qed. Lemma fa_tids_insert {γ tids} tid : tid ∉ tids -> fa_tids_auth γ tids ==∗ fa_tids_auth γ ({[ tid ]} ∪ tids) ∗ fa_tids_frag γ tid. Proof. iIntros "%Hnotin Hauth". unfold fa_tids_auth. rewrite gset_to_gmap_union_singleton. iApply (ghost_map_insert with "Hauth"). rewrite lookup_gset_to_gmap_None. done. Qed. Lemma fa_tids_delete {γ tids} tid : fa_tids_auth γ tids -∗ fa_tids_frag γ tid ==∗ fa_tids_auth γ (tids ∖ {[ tid ]}). Proof. iIntros "Hauth Helem". unfold fa_tids_auth. rewrite gset_to_gmap_difference_singleton. iApply (ghost_map_delete with "Hauth Helem"). Qed. Lemma fa_tids_lookup {γ tids} tid : fa_tids_auth γ tids -∗ fa_tids_frag γ tid -∗ ⌜tid ∈ tids⌝. Proof. iIntros "Hauth Helem". iDestruct (ghost_map_lookup with "Hauth Helem") as "%Hlookup". apply lookup_gset_to_gmap_Some in Hlookup as [Helem _]. done. Qed. Lemma fci_tmods_insert {γ : mvcc_names} {tmods : gset (nat * dbmap)} tmod : tmod ∉ tmods -> fci_tmods_auth γ tmods ==∗ fci_tmods_auth γ ({[ tmod ]} ∪ tmods) ∗ fci_tmods_frag γ tmod. Proof. iIntros "%Hnotin Hauth". unfold fci_tmods_auth. rewrite gset_to_gmap_union_singleton. iApply (ghost_map_insert with "Hauth"). rewrite lookup_gset_to_gmap_None. done. Qed. Lemma fci_tmods_delete {γ tmods} tmod : fci_tmods_auth γ tmods -∗ fci_tmods_frag γ tmod ==∗ fci_tmods_auth γ (tmods ∖ {[ tmod ]}). Proof. iIntros "Hauth Helem". unfold fci_tmods_auth. rewrite gset_to_gmap_difference_singleton. iApply (ghost_map_delete with "Hauth Helem"). Qed. Lemma fci_tmods_lookup {γ tmods} tmod : fci_tmods_auth γ tmods -∗ fci_tmods_frag γ tmod -∗ ⌜tmod ∈ tmods⌝. Proof. iIntros "Hauth Helem". iDestruct (ghost_map_lookup with "Hauth Helem") as "%Hlookup". apply lookup_gset_to_gmap_Some in Hlookup as [Helem _]. done. Qed. Lemma fcc_tmods_insert {γ tmods} tmod : tmod ∉ tmods -> fcc_tmods_auth γ tmods ==∗ fcc_tmods_auth γ ({[ tmod ]} ∪ tmods) ∗ fcc_tmods_frag γ tmod. Proof. iIntros "%Hnotin Hauth". unfold fcc_tmods_auth. rewrite gset_to_gmap_union_singleton. iApply (ghost_map_insert with "Hauth"). rewrite lookup_gset_to_gmap_None. done. Qed. Lemma fcc_tmods_delete {γ tmods} tmod : fcc_tmods_auth γ tmods -∗ fcc_tmods_frag γ tmod ==∗ fcc_tmods_auth γ (tmods ∖ {[ tmod ]}). Proof. iIntros "Hauth Helem". unfold fcc_tmods_auth. rewrite gset_to_gmap_difference_singleton. iApply (ghost_map_delete with "Hauth Helem"). Qed. Lemma fcc_tmods_lookup {γ tmods} tmod : fcc_tmods_auth γ tmods -∗ fcc_tmods_frag γ tmod -∗ ⌜tmod ∈ tmods⌝. Proof. iIntros "Hauth Helem". iDestruct (ghost_map_lookup with "Hauth Helem") as "%Hlookup". apply lookup_gset_to_gmap_Some in Hlookup as [Helem _]. done. Qed. Lemma cmt_tmods_insert {γ tmods} tmod : tmod ∉ tmods -> cmt_tmods_auth γ tmods ==∗ cmt_tmods_auth γ ({[ tmod ]} ∪ tmods) ∗ cmt_tmods_frag γ tmod. Proof. iIntros "%Hnotin Hauth". unfold cmt_tmods_auth. rewrite gset_to_gmap_union_singleton. iApply (ghost_map_insert with "Hauth"). rewrite lookup_gset_to_gmap_None. done. Qed. Lemma cmt_tmods_delete {γ tmods} tmod : cmt_tmods_auth γ tmods -∗ cmt_tmods_frag γ tmod ==∗ cmt_tmods_auth γ (tmods ∖ {[ tmod ]}). Proof. iIntros "Hauth Helem". unfold cmt_tmods_auth. rewrite gset_to_gmap_difference_singleton. iApply (ghost_map_delete with "Hauth Helem"). Qed. Lemma cmt_tmods_lookup {γ tmods} tmod : cmt_tmods_auth γ tmods -∗ cmt_tmods_frag γ tmod -∗ ⌜tmod ∈ tmods⌝. Proof. iIntros "Hauth Helem". iDestruct (ghost_map_lookup with "Hauth Helem") as "%Hlookup". apply lookup_gset_to_gmap_Some in Hlookup as [Helem _]. done. Qed. End lemmas. (** * Consider using Typeclass Opaque to improve performance. *)
[GOAL] E : Type u_1 inst✝² : NormedAddCommGroup E inst✝¹ : NormedSpace ℝ E inst✝ : CompleteSpace E f : ℝ → E a b : ℝ ⊢ ⨍ (x : ℝ) in a..b, f x = ⨍ (x : ℝ) in b..a, f x [PROOFSTEP] rw [setAverage_eq, setAverage_eq, uIoc_comm] [GOAL] E : Type u_1 inst✝² : NormedAddCommGroup E inst✝¹ : NormedSpace ℝ E inst✝ : CompleteSpace E f : ℝ → E a b : ℝ ⊢ ⨍ (x : ℝ) in a..b, f x = (b - a)⁻¹ • ∫ (x : ℝ) in a..b, f x [PROOFSTEP] cases' le_or_lt a b with h h [GOAL] case inl E : Type u_1 inst✝² : NormedAddCommGroup E inst✝¹ : NormedSpace ℝ E inst✝ : CompleteSpace E f : ℝ → E a b : ℝ h : a ≤ b ⊢ ⨍ (x : ℝ) in a..b, f x = (b - a)⁻¹ • ∫ (x : ℝ) in a..b, f x [PROOFSTEP] rw [setAverage_eq, uIoc_of_le h, Real.volume_Ioc, intervalIntegral.integral_of_le h, ENNReal.toReal_ofReal (sub_nonneg.2 h)] [GOAL] case inr E : Type u_1 inst✝² : NormedAddCommGroup E inst✝¹ : NormedSpace ℝ E inst✝ : CompleteSpace E f : ℝ → E a b : ℝ h : b < a ⊢ ⨍ (x : ℝ) in a..b, f x = (b - a)⁻¹ • ∫ (x : ℝ) in a..b, f x [PROOFSTEP] rw [setAverage_eq, uIoc_of_lt h, Real.volume_Ioc, intervalIntegral.integral_of_ge h.le, ENNReal.toReal_ofReal (sub_nonneg.2 h.le), smul_neg, ← neg_smul, ← inv_neg, neg_sub] [GOAL] E : Type u_1 inst✝² : NormedAddCommGroup E inst✝¹ : NormedSpace ℝ E inst✝ : CompleteSpace E f : ℝ → ℝ a b : ℝ ⊢ ⨍ (x : ℝ) in a..b, f x = (∫ (x : ℝ) in a..b, f x) / (b - a) [PROOFSTEP] rw [interval_average_eq, smul_eq_mul, div_eq_inv_mul]
# Execution control # copied from CUDAdrv/src/execution.jl export ROCDim, ROCModule, ROCFunction, roccall mutable struct ROCModule #data::String data::Vector{UInt8} options::Dict{Any,Any} end mutable struct ROCFunction mod::ROCModule entry::String end """ ROCDim3(x) ROCDim3((x,)) ROCDim3((x, y)) ROCDim3((x, y, x)) A type used to specify dimensions, consisting of 3 integers for respectively the `x`, `y` and `z` dimension. Unspecified dimensions default to `1`. Often accepted as argument through the `ROCDim` type alias, eg. in the case of [`roccall`](@ref) or [`launch`](@ref), allowing to pass dimensions as a plain integer or a tuple without having to construct an explicit `ROCDim3` object. """ struct ROCDim3 x::Cuint y::Cuint z::Cuint end ROCDim3(dims::Integer) = ROCDim3(dims, Cuint(1), Cuint(1)) ROCDim3(dims::NTuple{1,<:Integer}) = ROCDim3(dims[1], Cuint(1), Cuint(1)) ROCDim3(dims::NTuple{2,<:Integer}) = ROCDim3(dims[1], dims[2], Cuint(1)) ROCDim3(dims::NTuple{3,<:Integer}) = ROCDim3(dims[1], dims[2], dims[3]) # Type alias for conveniently specifying the dimensions # (e.g. `(len, 2)` instead of `ROCDim3((len, 2))`) const ROCDim = Union{Integer, Tuple{Integer}, Tuple{Integer, Integer}, Tuple{Integer, Integer, Integer}} function Base.getindex(dims::ROCDim3, idx::Int) return idx == 1 ? dims.x : idx == 2 ? dims.y : idx == 3 ? dims.z : error("Invalid dimension: $idx") end """ launch(queue::HSAQueue, signal::HSASignal, f::ROCFunction, groupsize::ROCDim, gridsize::ROCDim, args...) Low-level call to launch a ROC function `f` on the GPU, using `groupsize` and `gridsize` as respectively the grid and block configuration. The kernel is launched on queue `queue` and is waited on by signal `signal`. Arguments to a kernel should either be bitstype, in which case they will be copied to the internal kernel parameter buffer, or a pointer to device memory. This is a low-level call, prefer to use [`roccall`](@ref) instead. """ @inline function launch(queue::HSAQueue, signal::HSASignal, f::ROCFunction, groupsize::ROCDim, gridsize::ROCDim, args...) groupsize = ROCDim3(groupsize) gridsize = ROCDim3(gridsize) (groupsize.x>0 && groupsize.y>0 && groupsize.z>0) || throw(ArgumentError("Group dimensions should be non-null")) (gridsize.x>0 && gridsize.y>0 && gridsize.z>0) || throw(ArgumentError("Grid dimensions should be non-null")) _launch(queue, signal, f, groupsize, gridsize, args...) end # we need a generated function to get an args array, # without having to inspect the types at runtime @generated function _launch(queue::HSAQueue, signal::HSASignal, f::ROCFunction, groupsize::ROCDim3, gridsize::ROCDim3, args::NTuple{N,Any}) where N all(isbitstype, args.parameters) || throw(ArgumentError("Arguments to kernel should be bitstype.")) ex = Expr(:block) push!(ex.args, :(Base.@_inline_meta)) # If f has N parameters, then kernelParams needs to be an array of N # pointers. Each of kernelParams[0] through kernelParams[N-1] must point # to a region of memory from which the actual kernel parameter will be # copied. # put arguments in Ref boxes so that we can get a pointers to them arg_refs = Vector{Symbol}(undef, N) for i in 1:N arg_refs[i] = gensym() push!(ex.args, :($(arg_refs[i]) = Base.RefValue(args[$i]))) end # generate an array with pointers arg_ptrs = [:(Base.unsafe_convert(Ptr{Cvoid}, $(arg_refs[i]))) for i in 1:N] append!(ex.args, (quote GC.@preserve $(arg_refs...) begin kernelParams = [$(arg_ptrs...)] # link with ld.lld ld_path = HSARuntime.ld_lld_path @assert ld_path != "" "ld.lld was not found; cannot link kernel" # TODO: Do this more idiomatically io = open("/tmp/amdgpu-dump.o", "w") write(io, f.mod.data) close(io) run(`$ld_path -shared -o /tmp/amdgpu.exe /tmp/amdgpu-dump.o`) io = open("/tmp/amdgpu.exe", "r") data = read(io) close(io) # generate executable and kernel instance exe = HSAExecutable(queue.agent, data, f.entry) kern = HSAKernelInstance(queue.agent, exe, f.entry, args) HSARuntime.launch!(queue, kern, signal; workgroup_size=groupsize, grid_size=gridsize) end end).args) return ex end """ roccall(queue::HSAQueue, signal::HSASignal, f::ROCFunction, types, values...; groupsize::ROCDim, gridsize::ROCDim) `ccall`-like interface for launching a ROC function `f` on a GPU. For example: vadd = ROCFunction(md, "vadd") a = rand(Float32, 10) b = rand(Float32, 10) ad = Mem.upload(a) bd = Mem.upload(b) c = zeros(Float32, 10) cd = Mem.alloc(c) roccall(vadd, (Ptr{Cfloat},Ptr{Cfloat},Ptr{Cfloat}), ad, bd, cd; gridsize=10) Mem.download!(c, cd) The `groupsize` and `gridsize` arguments control the launch configuration, and should both consist of either an integer, or a tuple of 1 to 3 integers (omitted dimensions default to 1). The `types` argument can contain both a tuple of types, and a tuple type, the latter being slightly faster. """ roccall @inline function roccall(queue::HSAQueue, signal::HSASignal, f::ROCFunction, types::NTuple{N,DataType}, values::Vararg{Any,N}; kwargs...) where N # this cannot be inferred properly (because types only contains `DataType`s), # which results in the call `@generated _roccall` getting expanded upon first use _roccall(queue, signal, f, Tuple{types...}, values; kwargs...) end @inline function roccall(queue::HSAQueue, signal::HSASignal, f::ROCFunction, tt::Type, values::Vararg{Any,N}; kwargs...) where N # in this case, the type of `tt` is `Tuple{<:DataType,...}`, # which means the generated function can be expanded earlier _roccall(queue, signal, f, tt, values; kwargs...) end # we need a generated function to get a tuple of converted arguments (using unsafe_convert), # without having to inspect the types at runtime @generated function _roccall(queue::HSAQueue, signal::HSASignal, f::ROCFunction, tt::Type, args::NTuple{N,Any}; groupsize::ROCDim=1, gridsize::ROCDim=1) where N types = tt.parameters[1].parameters # the type of `tt` is Type{Tuple{<:DataType...}} ex = Expr(:block) push!(ex.args, :(Base.@_inline_meta)) # convert the argument values to match the kernel's signature (specified by the user) # (this mimics `lower-ccall` in julia-syntax.scm) converted_args = Vector{Symbol}(undef, N) arg_ptrs = Vector{Symbol}(undef, N) for i in 1:N converted_args[i] = gensym() arg_ptrs[i] = gensym() push!(ex.args, :($(converted_args[i]) = Base.cconvert($(types[i]), args[$i]))) push!(ex.args, :($(arg_ptrs[i]) = Base.unsafe_convert($(types[i]), $(converted_args[i])))) end append!(ex.args, (quote GC.@preserve $(converted_args...) begin launch(queue, signal, f, groupsize, gridsize, ($(arg_ptrs...),)) end end).args) return ex end
# Mass Definitions ``hmf``, as of v3.1, provides a simple way of converting between halo mass definitions, which serves two basic purposes: 1. the mass of a halo in one definition can be converted to its appropriate mass under another definition 2. the halo mass function can be converted between mass definitions. ## Introduction By "mass definition" we mean the way the extent of a halo is defined. In ``hmf``, we support two main kinds of definition, which themselves can contain different models. In brief, ``hmf`` supports Friends-of-Friends (FoF) halos, which are defined via their linking length, $b$, and spherical-overdensity (SO) halos, which are defined by two criteria: an overdensity $\Delta_h$, and an indicator of what that overdensity is with respect to (usually mean background density $\rho_m$, or critical density $\rho_c$). In addition to being able to provide a precise overdensity for a SO halo, ``hmf`` provides a way to use the so-called "virial" overdensity, as defined in Bryan and Norman (1998). Converting between SO mass definitions is relatively simple: given a halo profile and concentration for the given halo mass, determine the concentration required to make that profile contain the desired density, and then compute the mass of the halo under such a concentration. There is no clear way to perform such a conversion for FoF halos. Nevertheless, if one assumes that all linked particles are the same mass, and that halos are spherical and singular isothermal spheres (cf. White (2001)), one can approximate an FoF halo by an SO halo of density $9 \rho_m /(2\pi b^3)$. ``hmf`` will make this approximation if a conversion between mass definitions is desired. ## Changing Mass Definitions Most of the functionality concerning mass definitions is defined in the ``hmf.halos.mass_definitions`` module: ```python %load_ext autoreload %autoreload 2 import hmf from hmf.halos import mass_definitions as md print("Using hmf version v%s"%hmf.__version__) ``` Using hmf version v3.3.4.dev14+g9a9b63c.d20210610 While we're at it, import matplotlib and co: ```python import matplotlib.pyplot as plt %matplotlib inline import inspect ``` Different mass definitions exist inside the ``mass_definitions`` module as ``Components``. All definitions are subclassed from the abstract ``MassDefinition`` class: ```python [x[1] for x in inspect.getmembers(md, inspect.isclass) if issubclass(x[1], md.MassDefinition)] ``` [hmf.halos.mass_definitions.FOF, hmf.halos.mass_definitions.MassDefinition, hmf.halos.mass_definitions.SOCritical, hmf.halos.mass_definitions.SOGeneric, hmf.halos.mass_definitions.SOMean, hmf.halos.mass_definitions.SOVirial, hmf.halos.mass_definitions.SphericalOverdensity] ### The Mass Definition Component To create an instance of any class, optional ``cosmo`` and ``z`` arguments can be specified. By default, these are the ``Planck15`` cosmology at redshift 0. We'll leave them as default for this example. Let's define two mass definitions, both spherical-overdensity definitions with respect to the mean background density: ```python mdef_1 = md.SOMean(overdensity=200) mdef_2 = md.SOMean(overdensity=500) ``` Each mass definition has its own ``model_parameters``, which define the exact overdensity. For both the ``SOMean`` and ``SOCritical`` definitions, the ``overdensity`` can be provided, as above (default is 200). This must be passed as a named argument. For the ``FOF`` definition, the ``linking_length`` can be passed (default 0.2). For the ``SOVirial``, no parameters are available. Available parameters and their defaults can be checked the same way as *any* ``Component`` within ``hmf``: ```python md.SOMean._defaults ``` {'overdensity': 200} The explicit halo density for a given mass definition can be accessed: ```python mdef_1.halo_density(), mdef_1.halo_density()/mdef_1.mean_density() ``` (17068502575484.854, 200.0) ### Converting Masses To convert a mass in one definition to a mass in another, use the following: ```python mnew, rnew, cnew = mdef_1.change_definition(m=1e12, mdef=mdef_2) print("Mass in new definition is %.2f x 10^12 Msun / h"%(mnew/1e12)) print("Radius of halo in new definition is %.2f Mpc/h"%rnew) print("Concentration of halo in new definition is %.2f"%cnew) ``` Mass in new definition is 0.76 x 10^12 Msun / h Radius of halo in new definition is 0.16 Mpc/h Concentration of halo in new definition is 4.81 /home/steven/miniconda3/envs/hmf/lib/python3.7/site-packages/halomod/halo_exclusion.py:17: UserWarning: Warning: Some Halo-Exclusion models have significant speedup when using Numba "Warning: Some Halo-Exclusion models have significant speedup when using Numba" The input mass argument can be a list or array of masses also. To convert between masses, the concentration of the input halos, and their density profile, must be known. By default, an NFW profile is assumed, with a concentration-mass relation from Duffy et al. (2008). One can alternatively pass a concentration directly: ```python mnew, rnew, cnew = mdef_1.change_definition(m=1e12, mdef=mdef_2, c = 5.0) print("Mass in new definition is %.2f x 10^12 Msun / h"%(mnew/1e12)) print("Radius of halo in new definition is %.2f Mpc/h"%rnew) print("Concentration of halo in new definition is %.2f"%cnew) ``` Mass in new definition is 0.72 x 10^12 Msun / h Radius of halo in new definition is 0.16 Mpc/h Concentration of halo in new definition is 3.31 If you have ``halomod`` installed, you can also pass any ``halomod.profiles.Profile`` instance (which itself includes a concentration-mass relation) as the ``profile`` argument. ### Converting Mass Functions All halo mass function fits are measured using halos found using some halo definition. While some fits explicitly include a parameterization for the spherical overdensity of the halo (eg. ``Tinker08``, ``Watson`` and ``Bocquet``), others do not. By passing a mass definition to the ``MassFunction`` constructor, ``hmf`` can attempt to convert the mass function defined by the chosen fitting function to the appropriate mass definition, using ([Bocquet et al, 2016](http://adsabs.harvard.edu/abs/2016MNRAS.456.2361B)): \begin{equation} \frac{dn}{dm'} = \frac{dn}{dm}\frac{dm}{dm'} = f(\nu)\frac{\rho_0}{m'}\frac{d\nu}{dm'} \times \frac{m'}{m} \end{equation} where the last factor captures all the evolution with mass definition. You should note that this is only ever approximate -- it doesn't account for scatter in the profile of individual halos, nor does it preserve the halo model condition that all mass resides in halos (even if the original mass function did). In effect, the new $m'/m$ term is modifying the $f(\nu)$. By default, the mass definition is ``None``, which uses whatever mass definition was employed by the chosen fit. Nevertheless, care should be taken here: many of the different fits have different mass definitions, and should not be compared without some form of mass conversion (and possibly not even then). To see the mass definition intrinsic to the measurement of each fit, use the following: ```python from hmf.mass_function.fitting_functions import SMT, Tinker08, Jenkins ``` ```python print(SMT.sim_definition.halo_finder_type, SMT.sim_definition.halo_overdensity) print(Tinker08.sim_definition.halo_finder_type, Tinker08.sim_definition.halo_overdensity) print(Jenkins.sim_definition.halo_finder_type, Jenkins.sim_definition.halo_overdensity) ``` SO vir SO *(200m) FoF 0.2 Here "vir" corresponds to the virial definition of Bryan and Norman (1998), an asterisk indicates that the fit is itself parameterized for SO mass definitions, and 0.2 is the FoF linking length. Let's convert the mass definition of ``Tinker08``, which has an intrinsic parameterization: ```python # Default mass function object mf = hmf.MassFunction() dndm0 = mf.dndm # Change the mass definition to 300rho_mean mf.update( mdef_model = "SOMean", mdef_params = { "overdensity": 300 } ) plt.plot(mf.m, mf.dndm/dndm0, label=r"300 $\rho_m$", lw=3) # Change the mass definition to 500rho_crit mf.update( mdef_model = "SOCritical", mdef_params = { "overdensity": 500 } ) plt.plot(mf.m, mf.dndm/dndm0, label=r"500 $\rho_c$", lw=3) plt.xscale('log') plt.yscale('log') plt.xlabel(r"Mass, $M_\odot/h$", fontsize=15) plt.ylabel(r"Ratio of $dn/dm$ to $200 \rho_m$", fontsize=15) plt.grid(True) plt.legend(); ``` This did not require any internal conversion, since the `Tinker08` function is able to deal natively with multiple definitions. Let's try converting a fit that has no explicit parameterization for overdensity: ```python # Default mass function object. mf = hmf.MassFunction(hmf_model = "SMT", Mmax=15, disable_mass_conversion=False) dndm0 = mf.dndm # Change the mass definition to 300rho_mean mf.update( mdef_model = "SOMean", mdef_params = { "overdensity": 300 } ) plt.plot(mf.m, mf.dndm/dndm0, label=r"300 $\rho_m$", lw=3) # Change the mass definition to 500rho_crit mf.update( mdef_model = "SOCritical", mdef_params = { "overdensity": 500 } ) plt.plot(mf.m, mf.dndm/dndm0, label=r"500 $\rho_c$", lw=3) plt.xscale('log') plt.yscale('log') plt.xlabel(r"Mass, $M_\odot/h$", fontsize=15) plt.ylabel(r"Ratio of $dn/dm$ to virial", fontsize=15) plt.grid(True) plt.legend(); ``` Here, the measured mass function uses "virial" halos, which have an overdensity of ~330$\rho_m$, so that converting to 300$\rho_m$ is a down-conversion of density. Finally, we convert a FoF mass function: ```python # Default mass function object. mf = hmf.MassFunction(hmf_model = "Jenkins", disable_mass_conversion=False) dndm0 = mf.dndm # Change the mass definition to 300rho_mean mf.update( mdef_model = "FOF", mdef_params = { "linking_length": 0.3 } ) plt.plot(mf.m, mf.dndm/dndm0, label=r"FoF $b=0.3$", lw=3) # Change the mass definition to 500rho_crit mf.update( mdef_model = "SOVirial", mdef_params = {} # NOTE: we need to pass an empty dict here # so that the "linking_length" argument is removed. ) plt.plot(mf.m, mf.dndm/dndm0, label=r"SO Virial", lw=3) plt.xscale('log') plt.yscale('log') plt.xlabel(r"Mass, $M_\odot/h$", fontsize=15) plt.ylabel(r"Ratio of $dn/dm$ to FoF $b=0.2$", fontsize=15) plt.grid(True) plt.legend(); ``` To see the difference between an assumed mass conversion and a properly re-fit mass function, we can compute an automatically-converted mass function for `Bocquet2016`, and compare to the refit: ```python # Default mass function object. mf200c_conv = hmf.MassFunction(hmf_model = "Bocquet200mDMOnly", mdef_model='SOCritical', mdef_params={'overdensity': 200}, disable_mass_conversion=False) mf500c_conv = hmf.MassFunction(hmf_model = "Bocquet200mDMOnly", mdef_model='SOCritical', mdef_params={'overdensity': 500}, disable_mass_conversion=False) mf200c_refit = hmf.MassFunction(hmf_model = "Bocquet200cDMOnly") mf500c_refit = hmf.MassFunction(hmf_model = "Bocquet500cDMOnly") m = mf200c_conv.m fig, ax = plt.subplots(1, 1, sharex=True) ax = [ax] ax[0].plot(m, mf200c_conv.dndm/mf200c_refit.dndm - 1, color='k', label='200c') ax[0].plot(m, mf200c_conv.fsigma/(mf200c_refit.fsigma/mf200c_refit.hmf.convert_mass()) - 1, color='r') ax[0].plot(m, mf500c_conv.dndm/mf500c_refit.dndm - 1, ls='--', color='k', label='500c') ax[0].plot(m, mf500c_conv.fsigma/(mf500c_refit.fsigma/mf500c_refit.hmf.convert_mass()) - 1, color='r', ls='--') ax[0].set_xscale('log') ax[0].set_xlabel(r"Mass, $M_\odot/h$", fontsize=15) ax[0].set_ylabel(r"dn/dm", fontsize=15) ax[0].grid(True) ax[0].legend(); ax[0].set_ylim(-0.5, 0.5) ax[0].set_ylabel("Fractional Diff.") ax[0].set_title("Comparison of Mass Conversion to Refit"); plt.savefig("/home/steven/Desktop/comparison_of_massconv_to_refit.pdf") ``` We see that the conversion is only accurate to ~20% at lower masses, and blows up at high masses. The red lines here are directly using the fits for $m'/m$ given in Bocquet et al (2016) (instead of actually converting mass definitions using a halo profile). There is some discrepancy between that fit and the conversion, resulting in the discrepancy here.
\newcommand{\appref}[1]{Appendix \ref{#1}} \newcommand{\fnref}[1]{Footnote \ref{#1}} \newcommand{\textstylehigh}[1]{{\color{red}#1}} \newcommand{\textgreek}[1]{{\color{blue}#1}} \defbibheading{primary}{\chapter{Primary sources}} \defbibheading{secondary}{\chapter{Secondary literature}} \patchcmd{\mkbibindexname}{\ifdefvoid{#3}{}{\MakeCapital{#3} }}{\ifdefvoid{#3}{}{#3 }}{}{\AtEndDocument{\typeout{mkbibindexname could not be patched.}}}
-- Andreas, 2018-06-10, issue #2797 -- Analysis and test case by Ulf -- Relevance check was missing for overloaded projections. {-# OPTIONS --irrelevant-projections #-} -- {-# OPTIONS -v tc.proj.amb:30 #-} open import Agda.Builtin.Nat record Dummy : Set₁ where field nat : Set open Dummy record S : Set where field .nat : Nat open S mkS : Nat → S mkS n .nat = n -- The following should not pass, as projection -- .nat is irrelevant for record type S unS : S → Nat unS s = s .nat -- Error NOW, could be better: -- Cannot resolve overloaded projection nat because no matching candidate found -- when checking that the expression s .nat has type Nat viaS : Nat → Nat viaS n = unS (mkS n) idN : Nat → Nat idN zero = zero idN (suc n) = suc n canonicity-fail : Nat canonicity-fail = idN (viaS 17) -- C-c C-n canonicity-fail -- idN .(17)
using PtFEM using Test: @test data = Dict( # Rod(nels, np_types, nip, finite_element(nod, nodof)) :struc_el => Rod(4, 2, 1, Line(2, 1)), :properties => [2.0e3; 1.0e3], :etype => [2, 2, 1, 1], :x_coords => range(0, stop=1, length=5), :support => [ (1, [0]) ], :fixed_freedoms => [ (5, 1, 0.05) ] ) @time fem, dis_df, fm_df = p41(data) println("\nTesting: round.(fem.displacements, digits=7) == [0.0 0.0166667 0.0333333 0.0416667 0.05]' \n") @test round.(fem.displacements, digits=7) == [0.0 0.0166667 0.0333333 0.0416667 0.05]'
\section{Overall description} \label{sec:overdesc} \subsection{Product perspective} \texttt{Data4Help} is a service oriented to data acquisition and data sharing. Its software nature rises the necessity to combine it with another service able to directly retrive raw data from the \textit{world}. Today we can find for sale multiple wearables that can acquire data from users and make it readable from software side. \texttt{Data4Help} users should already own these devices in order to exploit the data acquisition functionality (Section~\ref{sec:sharedp}: \textbf{\texttt{S.1}}). Once the user registered to the service, its interface will gather the last data collected and organize it in a chart view, that can be filtered by date or type and rendered by the user interface (Section~\ref{sec:sharedp}: \textbf{\texttt{S.4}}; Section~\ref{sec:userinterfaces}). It is mandatory for the user's wearable or device to provide a GPS signal, if the user wants to apply to the \texttt{AutomatedSOS} service. GPS will be used to track the user's location in case of health danger and the signal will be shared to the SOS service that already exists in the \textit{world} (Section~\ref{sec:sharedp}: \textbf{\texttt{S.3}}, \textbf{\texttt{S.5}}). This SOS service accepts messages that contain the GPS location of the person in health danger and an emergency log that \texttt{AutomatedSOS} generates from the acquired data. The log explains the suspected health danger and the data that passed the defined thresholds. Third party organization are interested in data gathering. In order to allow them to make requests for specific types of data, \texttt{Data4Help} provides a user interface that is in charge of composing their request, to make it understendable by the software (Section~\ref{sec:sharedp}: \textbf{\texttt{S.2}}; Section~\ref{sec:userinterfaces}). The interface provides all the possible options that the third party can compose in order to provide the closest data request to its needs. \subsection{Product functions} Here we present the major functions that our product will offer. Some of them will entirely be handled internally by our system, but for others it will rely on external services. In the latter case, we will specify that the system will not directly provide the service and we will add examples of existing systems that can collaborate with ours, in order to guarantee the feasibility of the functions. \subsubsection{Profile management} The system will provide a registration form at which users and third parties can apply. Once registered, they will have a uniquely identifiable account, provided the requested information for its creation (Table~\ref{tab:login}). Once the account has been successfully created, its owner can exploit the system's functionalities. Note that accounts for users and third parties must be distinguishable from the system perspective, as it should offer different functionalities to different account types, in order to reflect the account owners'needs. \begin{table}[h!] \centering \begin{tabularx}{\linewidth}{|c|X|X|} \hline \textbf{Account type} & \textbf{Required information} & \textbf{Optional information} \\ \hline User & \textit{email, password, fiscal code, date of birth, weight, height} & \textit{social status, address, hours of work per day, hours of sport per week} \\ \hline Third party & \textit{email, password, third party name, third party description} & \textit{website, research interests} \\ \hline \end{tabularx} \caption{Example of registration form information} \label{tab:login} \end{table} \subsubsection{Data gathering} \label{sec:datagathering} Data gathering is exploited through physical wearables that users wear and that can communicate with our software by API calls (ex. Google Fit API \cite{googlefitapi}). Data entries can be identified with a timestamp and the owner user. Collected data types depend on wearables. For example, the most common sensors for health parameters that we find on smart clothing \cite{sensors} are pulse, body temperature, electrocardiogram, myocardial and blood oxygen. \subsubsection{Data sharing} \label{sec:datasharing} \texttt{Data4Help} relies on a database for data storage. Once data has just been added to the system, only the user that produced it will have access. Data sharing is exploited by granting access to required data also to third parties, if their requests have been accepted. Third parties can retrive these data by visualizing or downloading them from their inteface. Third party requests are encoded in the system by filling a form that contains information like Table~\ref{tab:tprequest}. They can be accepted or rejected. In the former case the third party is granted access to the data, while in the latter it is not granted access. \begin{table}[h!] \centering \begin{tabularx}{\linewidth}{|l|X|X|} \hline \textbf{Request type} & \textbf{Accept condition} & \textbf{Filters} \\ \hline Single user & Target user should accept the request through his/her account & \textit{fiscal code of target user, from-date, to-date, data types (weight, heart rate, etc.), time granularity (seconds, minutes, hours, etc.)} \\ \hline Anonymous & Every user should have accepted the automatic sharing of requested data & \textit{size, from-date, to-date, data types (weight, heart rate, etc.), user characteristics (age interval, weight interval, etc.)} \\ \hline \end{tabularx} \caption{Example of third party request form} \label{tab:tprequest} \end{table} \subsubsection{Data management} Once a user collected some data, he/she can organize it by changing the view options in the user interface. These options depend on the device the user is working on, but will always provide basic filters such as time interval or data type. Once filters have been selected by the user, the graphical interface will render a chart that organizes collected data according to them (see Section~\ref{sec:userinterfaces}). % TODO maybe add something here on third parties \subsubsection{Payment handling} \label{sec:payment} When third parties initialize requests, they are asked for payment by the system. Payment details are defined by TrackMe policy, so they won't be discussed in this document. Our system will only initialize payment requests as the effective payment operation will entirely be handled by an external software. This software should \begin{itemize} \item instanciate payment processes \item check if the payment is feasible and, if not, notify to our system \item handle the payment operation \item notify to our system if the operation has concluded correctly, otherwise notify the error occurred \end{itemize} There are plenty of payment handlers that exist in our \textit{world} and can be paired to our system (ex. PayPal API \cite{paypal}). \subsubsection{SOS handling} \label{sec:sossystem} This function is heavily dependant on the country in which the SOS will be handled. Our system will only communicate to the external emergency service that already exists in the \textit{world} through automatic API calls (ex. RapidSOS Emergency system for US \cite{sos}). Calls to SOS are handled by \texttt{AutomatedSOS} that signals users GPS position and health status feedback. Calls occur, if the user previously subscribed to \texttt{AutomatedSOS}, when his/her health parameters are above certain thresholds. The time between health danger detection and emergency call must be less than 5 seconds. \subsection{User characteristics} \label{sec:usercharacteristics} The following list contains the actors that are involved in the system functions: \begin{description} \item [User] Person interested in the \texttt{Data4Help} \textbf{data management} service; he/she is required to register to the \texttt{Data4Help} service in order to exploit its functionalities; he/she can also apply to the \texttt{AutomatedSOS} service; every user owns an appropriate device for \texttt{Data4Help} acquisition service that can monitor at least GPS location \\ % TODO occhio all'assunzione qua sopra ex. \textit{an athlet that wants to monitor his/her physical status during sport activity, an old person that suffers from heart diseases or a sedentary worker that wants to keep track of his health parameters in the working hours} \item [Third Party] Entity interested in the \texttt{Data4Help} \textbf{data sharing} service; it is required to register to the \texttt{Data4Help} service in order to exploit its functionalities; according to the scope of its requests, it may be interested on the data of a particular user or in aggregated chunks of data \\ ex. \textit{the physician of a person that suffers from heart diseases or a statistical institute} \end{description} \subsection{Assumptions, dependencies, constraints} \subsubsection{Domain assumptions} \label{sec:domainassumptions} \begin{description} \item[World] \item[\texttt{D.W1}] Signals processed by wearables are encoded correctly and represent the status of the \textit{world} \item[\texttt{D.W2}] Given certain health parameters\footnote{ Section~\ref{sec:datagathering} discusses which parameters are current wearables able to detect; we won't discuss regarding which parameters should be taken into account to determine the health status of an individual and which thresholds should be defined, as it is a topic strictly related to medical research % TODO reference this or add articles }, it is possible to decide if a person is in health danger just by checking wether the parameters are above or below certain thresholds \item[Existing systems] \item[\texttt{D.E1}] In the \textit{world} already exists a SOS system that is able to dispatch ambulances and accepts emergency calls through an API \item[\texttt{D.E2}] In the \textit{world} already exists a payment handler that is able to deliver money payments and accepts calls through an API \item[\texttt{D.E3}] In the \textit{world} already exist wearables that encode signals for health status; these encoded signals are accessible from the software side % TODO questi 3 non credo siano assunzioni, forse si possono togliere \item[Legal constraints] \item[\texttt{D.L1}] Acquired data can be sold to third parties \end{description} \subsubsection{Dependencies} \texttt{Data4Help} relies on \begin{itemize} \item \textbf{payment handler}, to deal with payment of third parties (Section~\ref{sec:payment}) \item \textbf{wearables}, to encode users'data (Section~\ref{sec:datagathering}) \end{itemize} \texttt{AutomatedSOS} relies on \begin{itemize} \item \textbf{wearables}, to encode GPS signals and users'parameters \item \textbf{SOS system}, for ambulance dispatching (Section~\ref{sec:sossystem}) \end{itemize} \subsubsection{Constraints} \label{sec:constraints} \texttt{Data4Help} acquires data through external devices owned by other companies, so it must be legally authorized to sell the data it acquires. In this document we assume that there are no legal issues for the selling activity, as TrackMe will develop contracts with the wearables companies in order to solve this issue. % TODO ricontrollare questo
#1 SAF Instant Yeast, Gold Label – is The World’s Best-Selling Instant Yeast. A professional-grade yeast designed to give a strong and steady rise to sweet doughs and breads with high sugar content. It is a perfect partner for bakers who want to improve Filipino favorites, such as Pandesal, Ensaymada, Siopao and Donuts. #2 Superb Cocoa Powder – is 100% Bensdorp DSR Cocoa Powder a Dutch treated cocoa powder from Holland. It offers a rich chocolate taste and brings a darker color to your baked treats. Bensdorp cocoa powder makes the best chocolate cakes, cupcakes and brownies that your loved ones will surely enjoy. Get one now and taste the World’s finest cocoa. The Premium Brand SAF-Instant Gold is for sweet dough (above 10% sugar level based on flour weight), for classic Filipino favorites, such as pandesal, siopao, ensaymada and donuts. Suitable for all kinds of bread making processes. Instant Success Gold does not need to be rehydrated like active dry yeast and offers a fast and uniformed absorption within the dough. Calcium Propionate resistant. Its high fermentation power remains stable during its 2 years shelf-life. Suitable for all kinds of bread making processes. Instant Success Silver does not need to be rehydrated like active dry yeast and offers a fast and uniformed absorption within the dough. Its high fermentation power remains stable during its 2 years shelf-life. A bread softener and volume enhancer that also helps retain the softness and moisture of bread. Perfect for individual soft breads and sweet dough. A do-it-all bread improver. It specializes in basic breads like sandwich breads, hamburger buns and monay by giving it a better mixing tolerance (dough), extra softness, increased volume and good structure. Mainly increases volume of bread, while also improving the bread’s softness and crumb texture. Use for better pan flow for a simplify production, enabling bakers to prepare quality, standardized end products. Taste the world’s finest cocoa powder popular among all kinds of chefs and confectioners. Experience the rich flavour, colour and aroma of cocoa on bread, cakes and fillings. Superb Cocoa Powder is 100% Bensdorp DSR Cocoa Powder, a Dutch treated alkalized cocoa powder which has a 10/12% fat content from Holland. A moisture-resistant decorative powder. Stays on the product for a long period and does not easily melt on moist products. Vanilla-flavoured instant pastry cream powder. Mainly used for filling breads, doughnuts and éclairs. Premium Hazelnut paste perfect for Italian gelato and pastries. Premium Pistachio paste perfect for Italian gelato and pastries. Powdered instant chocolate mousse mix perfect for filling and decorating delightful desserts. Premier product of Martin Braun. Powdered instant white chocolate mousse mix. Your perfect partner for filling and decorating lovely desserts. Mohrenglanz Vanilla is a block of solid vanilla chocolate mainly used to coat all kinds of cakes, biscuits, breads, danish pastries, wafers and other various desserts. The delicious flavor of Mohrenglanz is what sets it apart from the others. Mohrenglanz Dark is a block of solid chocolate mainly used to coat all kinds of cakes, biscuits, breads, danish pastries, wafers and other various desserts. The delicious chocolate flavor of Mohrenglanz is what sets it apart from the others. White glossy icing for mousses, parfaits and semifreddo. Very shiny appearance, perfect even for vertical use, without palm oil or gelatin. Glossy dark chocolate icing for mousses, parfaits and semifreddo. Very shiny appearance, perfect even for vertical use, without palm oil or gelatin. A smooth white chocolate flavoured cream. Commonly used to coat tortes, cakes, biscuits, or as an edible dessert decoration. Can be also used as filling in slices, biscuits, desserts, and chocolates. A smooth chocolate flavoured cream similar to chocolate ganache. Commonly used as coating for cakes, biscuits, tortes or as an edible dessert decoration. Can be also used as filling in slices, biscuits, chocolates and other various desserts. A smooth, cream based nut-nougat. It is good for coating tortes and can be flavoured with dessert pastes, whipped with butter or margarine, and re-whipped. Used for filling and decorating tortes, slices, Swiss rolls, desserts, chocolates, and biscuits. Bianka MB is a basic cream with has a neutral flavour, long shelf life, and is quick and easy to use. Bianka MB is used in the production of fat cream fillings, including light and fluffy butter or fat creams. Frio is a powdered baking mix with fine custard flavour. It is cold soluble and freeze-stable. Mainly used as a filling, but also can be used in tortes, desserts, puff, choux, and Danish pastries. Bon Caramel is a sticky soft caramel filling with a fine caramel flavour. Good for piping, bake-proof, freeze-stable and has no added preservatives. Bon Caramel is used in the production of various baking applications, mainly used as a filling or topping in pastries and other desserts. Ready-to-use crunchy filling with 4% chocolate, roasted hazelnuts and almonds and 20% biscuits in flakes to fill truffles and pralines, put a crunchy layer on sponges and pound cakes, create special desserts and mousses, fill everything else. Ready-to-use crunchy filling with 12% roasted pistachios and 20% biscuits in flakes to fill truffles and pralines, put a crunchy layer on sponges and pound cakes, create special desserts and mousses, fill everything else. Pasteurized egg white powder used for preparing special meringues, macarrons, vanilla cream and other dishes that require egg white. J-Forte Vanilla Seeds Paste is a bake stable, highly concentrated dessert paste with rich vanilla taste and real vanilla seeds. High quality green tea powder with strong aroma that contains Kyoto-Uji Maccha—the most historic maccha origin in Japan. The Uji Maccha Mix Powder contains 15% chlorella to prevent loss of color. Suitable for baking sweets. Powdered whipped topping used for piping on top of cakes and desserts. Produces a light and fluffy cream which has a good flavour to complement cakes and desserts. S-Mix Cake Emulsifier is a premium cake stabilizer from a blend of high quality emulsifier and other functional ingredients. It provides an all-in-one mixing method, making the process more convenient. It is ideal for cake products like chiffon, sponge, rolls, taisan and cupcake. Superior Vegetable Shortening is a specialty prepared from a blend of specially processed vegetable oils. It maintains an excellent plasticity and good creaming performance which ensures optimum product quality and higher consumer acceptance. It is best for breads, biscuits and other baked goods. FreshFields Diced Apple in a pouch contains fresh 100% New Zealand apples, offering a versatile, nutritious ingredient for a wide range of catering applications. No added preservatives, sugar or water. Powdered fine baking ingredient for production of Muffins, Cupcakes, pound cakes etc. Enjoy the combination of ube flavour and colouring in one package. Simple and economical combination of ube flavouring and colouring. Enjoy the flavour and colour of Buko Pandan in one package. Simple and economical combination of flavouring and colouring. Enjoy the rich mocha flavour and colour in one package. Simple and economical combination of mocha flavouring and colouring. Enjoy the delicious flavour and colour of Chocolate in one package. Simple and economical combination of chocolate flavouring and colouring. Concentrated crystals with strong citrus flavour (lemon). Mainly used for flavouring yeast dough, cakes, creams, biscuits and other various pastries. Concentrated crystals with strong citrus and natural orange flavour. Mainly used for flavouring yeast dough, cakes, creams, biscuits and other various pastries. Dessert Paste Mocca is a concentrated dessert paste flavouring compound with a rich mocha flavour. It is easy to use, bake proof, and retains it’s full taste even after freezing. Mainly used to flavour fresh cream, butter cream, ice cream, milk shakes, fillings, pound cakes, sponges, coatings, toppings, and other various desserts. Dessert Paste Strawberry is a concentrated dessert paste flavouring compound with a rich strawberry flavour and colour. It is easy to use, bake proof and retains it’s taste even after freezing. Mainly used to flavour fresh cream, butter cream, ice cream, milk shakes, fillings, pound cakes, sponges, coatings, toppings, and other various desserts. Combani Vanilla Essence is a thick liquid flavouring compound with real bourbon-vanilla flavour. It is bake proof, freeze stable, and is suitable to use for diabetics. Mainly used to flavour cake batters, biscuits, cookies, sponges, fresh creams, butter cream, sweet doughs, yeast doughs, and other various desserts. Powdered fresh cream stabilizer with freeze-dried mascarpone powder for the production of typical Italian cream tortes, slices, desserts, Swiss rolls, omelettes etc. Martin Braun’s signature cream stabilizer. Mainly used for the production of mousse cakes and glass desserts. Gives whipped topping needed stability. Powdered fresh cream stabilizer with freeze-dried strawberry fruit pieces. For cream tortes, slices, desserts, Swiss rolls, omelettes etc. Bring out your creative side with the rose patterned dessert baking mats brought to you by Demarle Flexipan (for use on baking trays). Your hidden talent in baking will surely be found when you use Demarle’s Labyrinth patterned baking trays. Make baking more enjoyable with Demarle Flexipan. Express your creativity with Venetian Cane patterned baking trays brought to you by Demarle Flexipan. Make baking more fun with Demarle. Silpain mats are the perforated version of the Silpat. Heat gets transferred more efficiently with the mat’s perforation making it the ideal choice for baking breads, choux, tarts and other products. Highly durable (with over 3000 baking times or 10 years). Silpat non-stick baking mats are the most recognized baking sheet in the industry. It is ideal for baking cookies, pastries, and meringue. Highly durable (with over 3000 baking times or 10 years). Bond with your kids and friends while baking delicious treats with playful teddy bear moulds made by Demarle. Demarle Flexipan is a non stick pastry mould suited to all types of applications. Tired of circles, squares and triangles? Use the Hexagon patterned moulds by Demarle. Demarle Flexipans are non stick flexible baking trays suited for everyday use. Change the way you do your pastry with Flexipan Square Savarins flexible moulds. Make baking extra fun with Demarle Flexipan. Spread the love with heart-shaped pastries and goodes made possible with Demarle Flexipan Interlacing Hearts mould/tray. It is non stick and is suited to all types of applications. Serve your loved ones with perfectly shaped pastries as their delightful snack using Demarle Flexipan Mini Squares pastry moulds. Demarle moulds are non stick and is suited to all types of applications. Treat your guests and loved ones with shaped goodies during snack time. Demarle Champagne Biscuit patterned moulds are non stick and is suited for everyday use. Make snack time more fun with half sphere shaped treats and goodies using Demarle Flexipan Half-Sphere patterned baking moulds. Baking is fun with Demarle. Bake your loved ones oval-shaped treats and goodies using Demarle Flexipan oval patterned pastry moulds. Flexipan is non stick and suited to all types of applications. Make someone’s day better with lozenges-shaped pastries. These moulds are non stick and is suited for everyday use. Treat your loved ones with triangle shaped pastries made possible with Demarle Flexipan Moulds. These moulds are non stick and is suited to all types of applications. Have a taste of Egypt with every pastry shaped like a pyramid. Demarle Flexipan pastry moulds are non stick and is suited to all types of applications. Lighten up the look of your pastries with star shaped moulds made by Demarle. Demarle Flexipan is a non stick pastry mould perfect to use on special occasions. Make well-shaped pastry bases to decorate your baked goodies using Demarle Flexipan moulds. Flexipan are non stick flexible trays perfect for baking. Clear gel glaze that has a neutral flavour, and can be flavoured and coloured with dessert pastes. Mainly used for decorating and glazing of cakes, pastries, fruits, and other various desserts. Caramel gel glaze that has fine caramel flavour and appearance. It is freeze stable is mainly used for decorating and glazing cakes, pastries, and fruits. A gel glaze that has a mild chocolate flavour. Can be flavoured and coloured with dessert pastes and is mainly used for decorating and glazing of cakes, pastries, fruits, and other various desserts. A cold setting gel. This product has a strawberry flavour and a red appearance. Freeze stable is mainly used for decorating and glazing cakes, pastries, fruits, and other various desserts. Concentrated gold coloured food colour paste for colouring and decorating. Ready to use on chocolate coatings, mix or marble with any water based glazes, cakes or desserts, decorate fruits, mix and twist with topping’s decorations and also decorate cream pastries, when mixed with toppings. Shiny red pearls used as substitutes for cherries. Mainly used for decorating cakes, pastries and other desserts. A croquant in the form of small crunchy pieces. Has a nutty flavour and contains hazelnut kernels. It is bake proof and non-sticky. Mainly used for decorating and coating baked goods, ice cream, chocolate, fillings, toppings, and other various desserts. Sprinkle size pieces with a sweet chocolate flavour. Bake proof and is mainly used for decorating and spreading sweet pastries, cakes, sponges, and other various desserts. A non-dairy whipped topping with fine flavour. Extra stable and is easy to use. A local product by Sonlie International. Butter Dreams Margarine is specially formulated to provide consistency and flavors to dishes and to conserve their freshness for longer. Best for making breads, cookies, pastries, icings and all kinds of cakes. The ideal raising agent for making quick breads, biscuits and all kinds of cakes.
State Before: α : Type u_1 β : Type ?u.29967 f fa : α → α fb : β → β x y : α m n : ℕ ⊢ Cycle.length (periodicOrbit f x) = minimalPeriod f x State After: no goals Tactic: rw [periodicOrbit, Cycle.length_coe, List.length_map, List.length_range]
-- 2010-10-15 module Issue331 where record ⊤ : Set where constructor tt data Wrap (I : Set) : Set where wrap : I → Wrap I data B (I : Set) : Wrap I → Set₁ where b₁ : ∀ i → B I (wrap i) b₂ : {w : Wrap I} → B I w → B I w b₃ : (X : Set){w : Wrap I}(f : X → B I w) → B I w ok : B ⊤ (wrap tt) ok = b₂ (b₁ _) -- Issue 331 was: Unsolved meta: _45 : ⊤ bad : Set → B ⊤ (wrap tt) bad X = b₃ X λ x → b₁ _
When you break it down, it’s not content that converts visitors, that compels them to opt-in to your marketing. If it was that easy, quantity and quality would be all you needed. But no, it’s the experience that ties it all together. Can you attract an audience with value, encourage them to interact with content that engages them, and deliver the right call to action at the right time? See how Uberflip can take your interactive content to the next level. Request a demo today. Noah Kagan shares three things you can do today to start generating more subscribers.
module Struts data Rat : Nat -> Nat -> Type where MkRat : (a : Nat) -> (b : Nat) -> Rat a b multRat : Rat a b -> Rat c d -> Rat (a*c) (b*d) multRat (MkRat a b) (MkRat c d) = MkRat (a*c) (b*d) divRat : Rat a b -> Rat c d -> Rat (a*d) (b*c) divRat (MkRat a b) (MkRat c d) = MkRat (a*d) (b*c) addRat : Rat a b -> Rat c d -> Rat (a*d + b*c) (b*d) addRat (MkRat a b) (MkRat c d) = MkRat (a*d + b*c) (b*d) simplify : Rat a b -> Rat (divNat a (gcd a b)) (divNat b (gcd a b)) simplify (MkRat a b) = MkRat (divNat a (gcd a b)) (divNat b (gcd a b)) fromNat : (n : Nat) -> Rat n 1 fromNat n = MkRat n 1 data Pitch = A | B | C | D | E | F | G data Note : (r : Rat a b) -> Type where MkNote : Pitch -> Note r quarter : Pitch -> Note (MkRat 1 4) quarter = MkNote data NoteSequence : (r : Rat a b) -> Type where Empty : NoteSequence (fromNat 0) Append : Note s -> NoteSequence r -> NoteSequence (addRat s r) data Measure : (r : Rat a b) -> Type where MkMeasure : NoteSequence r -> Measure r fin : NoteSequence (fromNat 0) fin = Empty infixr 10 ~> (~>) : Note s -> NoteSequence r -> NoteSequence (addRat s r) (~>) = Append beatMeasure : Measure (MkRat 1 4) beatMeasure = MkMeasure (quarter C ~> fin)
import fundamental_groupoid_product noncomputable theory variables {X : Type*} {Y : Type*} [topological_space X] [topological_space Y] {f g : C(X, Y)} (H : continuous_map.homotopy f g) namespace continuous_map.homotopy def to_path (x : X) : path (f x) (g x) := { to_fun := λ t, H (t, x), source' := by simp only [continuous_map.homotopy.apply_zero], target' := by simp only [continuous_map.homotopy.apply_one], } end continuous_map.homotopy open_locale unit_interval namespace path.homotopic local attribute [instance] path.homotopic.setoid section cast variables {x₀ x₁ x₂ x₃ : X} protected def cast (p₀ : x₀ = x₁) (p₁ : x₂ = x₃) (P : path.homotopic.quotient x₁ x₃) : (path.homotopic.quotient x₀ x₂) := by rwa [p₀, p₁] @[simp] lemma cast_of_eq (P : path.homotopic.quotient x₀ x₁) : path.homotopic.cast rfl rfl P = P := rfl lemma cast_lift (p₀ : x₀ = x₁) (p₁ : x₂ = x₃) (P₀ : path x₁ x₃) : ⟦P₀.cast p₀ p₁⟧ = path.homotopic.cast p₀ p₁ ⟦P₀⟧ := by { subst_vars, rw cast_of_eq, congr, ext, rw path.cast_coe, } lemma path_heq_cast (p₀ : x₀ = x₁) (p₁ : x₂ = x₃) (P : path x₁ x₃) : P.cast p₀ p₁ == P := by { subst_vars, rw heq_iff_eq, ext, rw path.cast_coe, } lemma path.homotopic.heq_cast (p₀ : x₀ = x₁) (p₁ : x₂ = x₃) (P : path.homotopic.quotient x₁ x₃) : path.homotopic.cast p₀ p₁ P == P := by { subst_vars, refl, } end cast variables (x₀ x₁ : X) (p : path.homotopic.quotient x₀ x₁) def straight_path : path (0 : I) (1 : I) := { to_fun := id, source' := rfl, target' := rfl } def diagonal_path : path.homotopic.quotient (H (0, x₀)) (H (1, x₁)) := (path.homotopic.prod ⟦straight_path⟧ p).map_fn H.to_continuous_map def diagonal_path' : path.homotopic.quotient (f x₀) (g x₁) := path.homotopic.cast (H.apply_zero x₀).symm (H.apply_one x₁).symm (diagonal_path H x₀ x₁ p) lemma up_is_f : (p.map_fn f) = path.homotopic.cast (H.apply_zero x₀).symm (H.apply_zero x₁).symm ((path.homotopic.prod ⟦path.refl (0 : I)⟧ p).map_fn H.to_continuous_map) := begin apply quotient.induction_on p, intro p', rw [path.homotopic.prod_lift, ← path.homotopic.map_lift, ← path.homotopic.map_lift, ← cast_lift], congr, ext, simp, end lemma down_is_g : p.map_fn g = path.homotopic.cast (H.apply_one x₀).symm (H.apply_one x₁).symm ((path.homotopic.prod ⟦path.refl (1 : I)⟧ p).map_fn H.to_continuous_map) := begin apply quotient.induction_on p, intro p', rw [path.homotopic.prod_lift, ← path.homotopic.map_lift, ← path.homotopic.map_lift, ← cast_lift], congr, ext, simp, end lemma H_to_path (x : X) : ⟦H.to_path x⟧ = path.homotopic.cast (H.apply_zero x).symm (H.apply_one x).symm ((path.homotopic.prod ⟦straight_path⟧ ⟦path.refl x⟧).map_fn H.to_continuous_map) := by { rw [prod_lift, ← map_lift, ← cast_lift], refl, } lemma up_right_is_diag : (p.map_fn f).comp ⟦H.to_path x₁⟧ = diagonal_path' H x₀ x₁ p := begin rw up_is_f H x₀ x₁ p, sorry, end end path.homotopic
Description: Black History Famous Quotes from the above 500x625 resolutions which is part of the Inspiration Quotes directory. Download this image for free in HD resolution the choice "download button" below. If you do not find the exact resolution you are looking for, then go for a native or higher resolution. or if you are interested in similar pictures of Black History Famous Quotes, you are free to browse through search feature or related post section at below of this post. You can bookmark our site to get more update related to Black History Famous Quotes or any other topic. This Black History Famous Quotes is provided only for personal use as image on computers, smartphones or other display devices. If you found any images copyrighted to yours, please contact us and we will remove it. We don't intend to display any copyright protected images.
State Before: α : Type u_1 β✝ : Type ?u.20888 inst✝¹ : LinearOrder α x y : α β : Type u_2 inst✝ : LinearOrder β x' y' : β h : cmp x y = cmp x' y' ⊢ x = y ↔ x' = y' State After: no goals Tactic: rw [le_antisymm_iff, le_antisymm_iff, le_iff_le_of_cmp_eq_cmp h, le_iff_le_of_cmp_eq_cmp (cmp_eq_cmp_symm.1 h)]
import sys sys.path.append('..') from common.core import * from common.gfxutil import * from common.audio import * from common.mixer import * from common.note import * from common.wavegen import * from common.wavesrc import * from common.writer import * from kivy.core.window import Window from kivy.clock import Clock as kivyClock from kivy.uix.label import Label from kivy.graphics.instructions import InstructionGroup from kivy.graphics import Color, Ellipse, Rectangle from kivy.graphics import PushMatrix, PopMatrix, Translate, Scale, Rotate from kivy.graphics.texture import Texture from kivy.uix.image import Image from random import random, randint, choice import numpy as np # part 1 class MainWidget1(BaseWidget) : def __init__(self): super(MainWidget1, self).__init__() #Setup Graphics self.objects = [] #self.canvas.add(self.objects) self.texture = Image(source='moon.png').texture #self.texture.blit_buffer() #self.add_widget(self.texture) self.rect = CRectangle(texture=self.texture, cpos=(Window.width/2,Window.height/2), csize=(512,512)) self.canvas.add(self.rect) def on_update(self): #self.objects.on_update() pass run(MainWidget1)
(* 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.*) theory TIP_sort_nat_HSortIsSort imports "../../Test_Base" begin datatype 'a list = nil2 | cons2 "'a" "'a list" datatype Nat = Z | S "Nat" datatype Heap = Node "Heap" "Nat" "Heap" | Nil fun toHeap :: "Nat list => Heap list" where "toHeap (nil2) = nil2" | "toHeap (cons2 y z) = cons2 (Node Nil y Nil) (toHeap z)" fun le :: "Nat => Nat => bool" where "le (Z) y = True" | "le (S z) (Z) = False" | "le (S z) (S x2) = le z x2" fun insert :: "Nat => Nat list => Nat list" where "insert x (nil2) = cons2 x (nil2)" | "insert x (cons2 z xs) = (if le x z then cons2 x (cons2 z xs) else cons2 z (insert x xs))" fun isort :: "Nat list => Nat list" where "isort (nil2) = nil2" | "isort (cons2 y xs) = insert y (isort xs)" fun hmerge :: "Heap => Heap => Heap" where "hmerge (Node z x2 x3) (Node x4 x5 x6) = (if le x2 x5 then Node (hmerge x3 (Node x4 x5 x6)) x2 z else Node (hmerge (Node z x2 x3) x6) x5 x4)" | "hmerge (Node z x2 x3) (Nil) = Node z x2 x3" | "hmerge (Nil) y = y" fun hpairwise :: "Heap list => Heap list" where "hpairwise (nil2) = nil2" | "hpairwise (cons2 q (nil2)) = cons2 q (nil2)" | "hpairwise (cons2 q (cons2 r qs)) = cons2 (hmerge q r) (hpairwise qs)" (*fun did not finish the proof*) function hmerging :: "Heap list => Heap" where "hmerging (nil2) = Nil" | "hmerging (cons2 q (nil2)) = q" | "hmerging (cons2 q (cons2 z x2)) = hmerging (hpairwise (cons2 q (cons2 z x2)))" by pat_completeness auto fun toHeap2 :: "Nat list => Heap" where "toHeap2 x = hmerging (toHeap x)" (*fun did not finish the proof*) function toList :: "Heap => Nat list" where "toList (Node q y r) = cons2 y (toList (hmerge q r))" | "toList (Nil) = nil2" by pat_completeness auto fun hsort :: "Nat list => Nat list" where "hsort x = toList (toHeap2 x)" theorem property0 : "((hsort xs) = (isort xs))" oops end
REBOL [ Title: "Vid2mp3" Date: 3-Dec-2014/23:24:37+1:00 Name: none Version: none File: none Home: none Author: "A Rebol" Owner: none Rights: none Needs: none Tabs: none Usage: none Purpose: none Comment: none History: none Language: none Type: none Content: none Email: none require: [ rs-project %cookies-daemon rs-project %url-encode ] ] page: read http://www.vidtomp3.com/ vidurl: https://www.youtube.com/watch?v=vtRTdGm_t9s&list=ALBTKoXRg38BDIvCywpi6Gkfjz8cVRiQzY&index=4 page2: read/custom http://www.vidtomp3.com/process.php reduce [ 'post url-encode vidurl ]
module Data.Profunctor import public Data.Profunctor.Class import public Data.Profunctor.Choice import public Data.Morphisms
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import order.well_founded_set import algebra.big_operators.finprod import ring_theory.valuation.basic import ring_theory.power_series.basic import data.finsupp.pwo import data.finset.mul_antidiagonal import algebra.order.group.with_top /-! # Hahn Series If `Γ` is ordered and `R` has zero, then `hahn_series Γ R` consists of formal series over `Γ` with coefficients in `R`, whose supports are partially well-ordered. With further structure on `R` and `Γ`, we can add further structure on `hahn_series Γ R`, with the most studied case being when `Γ` is a linearly ordered abelian group and `R` is a field, in which case `hahn_series Γ R` is a valued field, with value group `Γ`. These generalize Laurent series (with value group `ℤ`), and Laurent series are implemented that way in the file `ring_theory/laurent_series`. ## Main Definitions * If `Γ` is ordered and `R` has zero, then `hahn_series Γ R` consists of formal series over `Γ` with coefficients in `R`, whose supports are partially well-ordered. * If `R` is a (commutative) additive monoid or group, then so is `hahn_series Γ R`. * If `R` is a (comm_)(semi)ring, then so is `hahn_series Γ R`. * `hahn_series.add_val Γ R` defines an `add_valuation` on `hahn_series Γ R` when `Γ` is linearly ordered. * A `hahn_series.summable_family` is a family of Hahn series such that the union of their supports is well-founded and only finitely many are nonzero at any given coefficient. They have a formal sum, `hahn_series.summable_family.hsum`, which can be bundled as a `linear_map` as `hahn_series.summable_family.lsum`. Note that this is different from `summable` in the valuation topology, because there are topologically summable families that do not satisfy the axioms of `hahn_series.summable_family`, and formally summable families whose sums do not converge topologically. * Laurent series over `R` are implemented as `hahn_series ℤ R` in the file `ring_theory/laurent_series`. ## TODO * Build an API for the variable `X` (defined to be `single 1 1 : hahn_series Γ R`) in analogy to `X : R[X]` and `X : power_series R` ## References - [J. van der Hoeven, *Operators on Generalized Power Series*][van_der_hoeven] -/ open finset function open_locale big_operators classical pointwise polynomial noncomputable theory /-- If `Γ` is linearly ordered and `R` has zero, then `hahn_series Γ R` consists of formal series over `Γ` with coefficients in `R`, whose supports are well-founded. -/ @[ext] structure hahn_series (Γ : Type*) (R : Type*) [partial_order Γ] [has_zero R] := (coeff : Γ → R) (is_pwo_support' : (support coeff).is_pwo) variables {Γ : Type*} {R : Type*} namespace hahn_series section zero variables [partial_order Γ] [has_zero R] lemma coeff_injective : injective (coeff : hahn_series Γ R → (Γ → R)) := ext @[simp] lemma coeff_inj {x y : hahn_series Γ R} : x.coeff = y.coeff ↔ x = y := coeff_injective.eq_iff /-- The support of a Hahn series is just the set of indices whose coefficients are nonzero. Notably, it is well-founded. -/ def support (x : hahn_series Γ R) : set Γ := support x.coeff @[simp] lemma is_pwo_support (x : hahn_series Γ R) : x.support.is_pwo := x.is_pwo_support' @[simp] lemma is_wf_support (x : hahn_series Γ R) : x.support.is_wf := x.is_pwo_support.is_wf @[simp] lemma mem_support (x : hahn_series Γ R) (a : Γ) : a ∈ x.support ↔ x.coeff a ≠ 0 := iff.refl _ instance : has_zero (hahn_series Γ R) := ⟨{ coeff := 0, is_pwo_support' := by simp }⟩ instance : inhabited (hahn_series Γ R) := ⟨0⟩ instance [subsingleton R] : subsingleton (hahn_series Γ R) := ⟨λ a b, a.ext b (subsingleton.elim _ _)⟩ @[simp] lemma zero_coeff {a : Γ} : (0 : hahn_series Γ R).coeff a = 0 := rfl @[simp] lemma coeff_fun_eq_zero_iff {x : hahn_series Γ R} : x.coeff = 0 ↔ x = 0 := coeff_injective.eq_iff' rfl lemma ne_zero_of_coeff_ne_zero {x : hahn_series Γ R} {g : Γ} (h : x.coeff g ≠ 0) : x ≠ 0 := mt (λ x0, (x0.symm ▸ zero_coeff : x.coeff g = 0)) h @[simp] lemma support_zero : support (0 : hahn_series Γ R) = ∅ := function.support_zero @[simp] lemma support_nonempty_iff {x : hahn_series Γ R} : x.support.nonempty ↔ x ≠ 0 := by rw [support, support_nonempty_iff, ne.def, coeff_fun_eq_zero_iff] @[simp] lemma support_eq_empty_iff {x : hahn_series Γ R} : x.support = ∅ ↔ x = 0 := support_eq_empty_iff.trans coeff_fun_eq_zero_iff /-- `single a r` is the Hahn series which has coefficient `r` at `a` and zero otherwise. -/ def single (a : Γ) : zero_hom R (hahn_series Γ R) := { to_fun := λ r, { coeff := pi.single a r, is_pwo_support' := (set.is_pwo_singleton a).mono pi.support_single_subset }, map_zero' := ext _ _ (pi.single_zero _) } variables {a b : Γ} {r : R} @[simp] theorem single_coeff_same (a : Γ) (r : R) : (single a r).coeff a = r := pi.single_eq_same a r @[simp] theorem single_coeff_of_ne (h : b ≠ a) : (single a r).coeff b = 0 := pi.single_eq_of_ne h r theorem single_coeff : (single a r).coeff b = if (b = a) then r else 0 := by { split_ifs with h; simp [h] } @[simp] lemma support_single_of_ne (h : r ≠ 0) : support (single a r) = {a} := pi.support_single_of_ne h lemma support_single_subset : support (single a r) ⊆ {a} := pi.support_single_subset lemma eq_of_mem_support_single {b : Γ} (h : b ∈ support (single a r)) : b = a := support_single_subset h @[simp] lemma single_eq_zero : (single a (0 : R)) = 0 := (single a).map_zero lemma single_injective (a : Γ) : function.injective (single a : R → hahn_series Γ R) := λ r s rs, by rw [← single_coeff_same a r, ← single_coeff_same a s, rs] lemma single_ne_zero (h : r ≠ 0) : single a r ≠ 0 := λ con, h (single_injective a (con.trans single_eq_zero.symm)) @[simp] lemma single_eq_zero_iff {a : Γ} {r : R} : single a r = 0 ↔ r = 0 := begin split, { contrapose!, exact single_ne_zero }, { simp {contextual := tt} } end instance [nonempty Γ] [nontrivial R] : nontrivial (hahn_series Γ R) := ⟨begin obtain ⟨r, s, rs⟩ := exists_pair_ne R, inhabit Γ, refine ⟨single (arbitrary Γ) r, single (arbitrary Γ) s, λ con, rs _⟩, rw [← single_coeff_same (arbitrary Γ) r, con, single_coeff_same], end⟩ section order variable [has_zero Γ] /-- The order of a nonzero Hahn series `x` is a minimal element of `Γ` where `x` has a nonzero coefficient, the order of 0 is 0. -/ def order (x : hahn_series Γ R) : Γ := if h : x = 0 then 0 else x.is_wf_support.min (support_nonempty_iff.2 h) @[simp] lemma order_zero : order (0 : hahn_series Γ R) = 0 := dif_pos rfl lemma order_of_ne {x : hahn_series Γ R} (hx : x ≠ 0) : order x = x.is_wf_support.min (support_nonempty_iff.2 hx) := dif_neg hx lemma coeff_order_ne_zero {x : hahn_series Γ R} (hx : x ≠ 0) : x.coeff x.order ≠ 0 := begin rw order_of_ne hx, exact x.is_wf_support.min_mem (support_nonempty_iff.2 hx) end lemma order_le_of_coeff_ne_zero {Γ} [linear_ordered_cancel_add_comm_monoid Γ] {x : hahn_series Γ R} {g : Γ} (h : x.coeff g ≠ 0) : x.order ≤ g := le_trans (le_of_eq (order_of_ne (ne_zero_of_coeff_ne_zero h))) (set.is_wf.min_le _ _ ((mem_support _ _).2 h)) @[simp] lemma order_single (h : r ≠ 0) : (single a r).order = a := (order_of_ne (single_ne_zero h)).trans (support_single_subset ((single a r).is_wf_support.min_mem (support_nonempty_iff.2 (single_ne_zero h)))) lemma coeff_eq_zero_of_lt_order {x : hahn_series Γ R} {i : Γ} (hi : i < x.order) : x.coeff i = 0 := begin rcases eq_or_ne x 0 with rfl|hx, { simp }, contrapose! hi, rw [←ne.def, ←mem_support] at hi, rw [order_of_ne hx], exact set.is_wf.not_lt_min _ _ hi end end order section domain variables {Γ' : Type*} [partial_order Γ'] /-- Extends the domain of a `hahn_series` by an `order_embedding`. -/ def emb_domain (f : Γ ↪o Γ') : hahn_series Γ R → hahn_series Γ' R := λ x, { coeff := λ (b : Γ'), if h : b ∈ f '' x.support then x.coeff (classical.some h) else 0, is_pwo_support' := (x.is_pwo_support.image_of_monotone f.monotone).mono (λ b hb, begin contrapose! hb, rw [function.mem_support, dif_neg hb, not_not], end) } @[simp] lemma emb_domain_coeff {f : Γ ↪o Γ'} {x : hahn_series Γ R} {a : Γ} : (emb_domain f x).coeff (f a) = x.coeff a := begin rw emb_domain, dsimp only, by_cases ha : a ∈ x.support, { rw dif_pos (set.mem_image_of_mem f ha), exact congr rfl (f.injective (classical.some_spec (set.mem_image_of_mem f ha)).2) }, { rw [dif_neg, not_not.1 (λ c, ha ((mem_support _ _).2 c))], contrapose! ha, obtain ⟨b, hb1, hb2⟩ := (set.mem_image _ _ _).1 ha, rwa f.injective hb2 at hb1 } end @[simp] lemma emb_domain_mk_coeff {f : Γ → Γ'} (hfi : function.injective f) (hf : ∀ g g' : Γ, f g ≤ f g' ↔ g ≤ g') {x : hahn_series Γ R} {a : Γ} : (emb_domain ⟨⟨f, hfi⟩, hf⟩ x).coeff (f a) = x.coeff a := emb_domain_coeff lemma emb_domain_notin_image_support {f : Γ ↪o Γ'} {x : hahn_series Γ R} {b : Γ'} (hb : b ∉ f '' x.support) : (emb_domain f x).coeff b = 0 := dif_neg hb lemma support_emb_domain_subset {f : Γ ↪o Γ'} {x : hahn_series Γ R} : support (emb_domain f x) ⊆ f '' x.support := begin intros g hg, contrapose! hg, rw [mem_support, emb_domain_notin_image_support hg, not_not], end lemma emb_domain_notin_range {f : Γ ↪o Γ'} {x : hahn_series Γ R} {b : Γ'} (hb : b ∉ set.range f) : (emb_domain f x).coeff b = 0 := emb_domain_notin_image_support (λ con, hb (set.image_subset_range _ _ con)) @[simp] lemma emb_domain_zero {f : Γ ↪o Γ'} : emb_domain f (0 : hahn_series Γ R) = 0 := by { ext, simp [emb_domain_notin_image_support] } @[simp] lemma emb_domain_single {f : Γ ↪o Γ'} {g : Γ} {r : R} : emb_domain f (single g r) = single (f g) r := begin ext g', by_cases h : g' = f g, { simp [h] }, rw [emb_domain_notin_image_support, single_coeff_of_ne h], by_cases hr : r = 0, { simp [hr] }, rwa [support_single_of_ne hr, set.image_singleton, set.mem_singleton_iff], end lemma emb_domain_injective {f : Γ ↪o Γ'} : function.injective (emb_domain f : hahn_series Γ R → hahn_series Γ' R) := λ x y xy, begin ext g, rw [ext_iff, function.funext_iff] at xy, have xyg := xy (f g), rwa [emb_domain_coeff, emb_domain_coeff] at xyg, end end domain end zero section addition variable [partial_order Γ] section add_monoid variable [add_monoid R] instance : has_add (hahn_series Γ R) := { add := λ x y, { coeff := x.coeff + y.coeff, is_pwo_support' := (x.is_pwo_support.union y.is_pwo_support).mono (function.support_add _ _) } } instance : add_monoid (hahn_series Γ R) := { zero := 0, add := (+), add_assoc := λ x y z, by { ext, apply add_assoc }, zero_add := λ x, by { ext, apply zero_add }, add_zero := λ x, by { ext, apply add_zero } } @[simp] lemma add_coeff' {x y : hahn_series Γ R} : (x + y).coeff = x.coeff + y.coeff := rfl lemma add_coeff {x y : hahn_series Γ R} {a : Γ} : (x + y).coeff a = x.coeff a + y.coeff a := rfl lemma support_add_subset {x y : hahn_series Γ R} : support (x + y) ⊆ support x ∪ support y := λ a ha, begin rw [mem_support, add_coeff] at ha, rw [set.mem_union, mem_support, mem_support], contrapose! ha, rw [ha.1, ha.2, add_zero], end lemma min_order_le_order_add {Γ} [linear_ordered_cancel_add_comm_monoid Γ] {x y : hahn_series Γ R} (hxy : x + y ≠ 0) : min x.order y.order ≤ (x + y).order := begin by_cases hx : x = 0, { simp [hx], }, by_cases hy : y = 0, { simp [hy], }, rw [order_of_ne hx, order_of_ne hy, order_of_ne hxy], refine le_trans _ (set.is_wf.min_le_min_of_subset support_add_subset), { exact x.is_wf_support.union y.is_wf_support }, { exact set.nonempty.mono (set.subset_union_left _ _) (support_nonempty_iff.2 hx) }, rw set.is_wf.min_union, end /-- `single` as an additive monoid/group homomorphism -/ @[simps] def single.add_monoid_hom (a : Γ) : R →+ (hahn_series Γ R) := { map_add' := λ x y, by { ext b, by_cases h : b = a; simp [h] }, ..single a } /-- `coeff g` as an additive monoid/group homomorphism -/ @[simps] def coeff.add_monoid_hom (g : Γ) : (hahn_series Γ R) →+ R := { to_fun := λ f, f.coeff g, map_zero' := zero_coeff, map_add' := λ x y, add_coeff } section domain variables {Γ' : Type*} [partial_order Γ'] lemma emb_domain_add (f : Γ ↪o Γ') (x y : hahn_series Γ R) : emb_domain f (x + y) = emb_domain f x + emb_domain f y := begin ext g, by_cases hg : g ∈ set.range f, { obtain ⟨a, rfl⟩ := hg, simp }, { simp [emb_domain_notin_range, hg] } end end domain end add_monoid instance [add_comm_monoid R] : add_comm_monoid (hahn_series Γ R) := { add_comm := λ x y, by { ext, apply add_comm } .. hahn_series.add_monoid } section add_group variable [add_group R] instance : add_group (hahn_series Γ R) := { neg := λ x, { coeff := λ a, - x.coeff a, is_pwo_support' := by { rw function.support_neg, exact x.is_pwo_support }, }, add_left_neg := λ x, by { ext, apply add_left_neg }, .. hahn_series.add_monoid } @[simp] lemma neg_coeff' {x : hahn_series Γ R} : (- x).coeff = - x.coeff := rfl lemma neg_coeff {x : hahn_series Γ R} {a : Γ} : (- x).coeff a = - x.coeff a := rfl @[simp] lemma support_neg {x : hahn_series Γ R} : (- x).support = x.support := by { ext, simp } @[simp] lemma sub_coeff' {x y : hahn_series Γ R} : (x - y).coeff = x.coeff - y.coeff := by { ext, simp [sub_eq_add_neg] } lemma sub_coeff {x y : hahn_series Γ R} {a : Γ} : (x - y).coeff a = x.coeff a - y.coeff a := by simp @[simp] lemma order_neg [has_zero Γ] {f : hahn_series Γ R} : (- f).order = f.order := by { by_cases hf : f = 0, { simp only [hf, neg_zero] }, simp only [order, support_neg, neg_eq_zero] } end add_group instance [add_comm_group R] : add_comm_group (hahn_series Γ R) := { .. hahn_series.add_comm_monoid, .. hahn_series.add_group } end addition section distrib_mul_action variables [partial_order Γ] {V : Type*} [monoid R] [add_monoid V] [distrib_mul_action R V] instance : has_smul R (hahn_series Γ V) := ⟨λ r x, { coeff := r • x.coeff, is_pwo_support' := x.is_pwo_support.mono (function.support_smul_subset_right r x.coeff) }⟩ @[simp] lemma smul_coeff {r : R} {x : hahn_series Γ V} {a : Γ} : (r • x).coeff a = r • (x.coeff a) := rfl instance : distrib_mul_action R (hahn_series Γ V) := { smul := (•), one_smul := λ _, by { ext, simp }, smul_zero := λ _, by { ext, simp }, smul_add := λ _ _ _, by { ext, simp [smul_add] }, mul_smul := λ _ _ _, by { ext, simp [mul_smul] } } variables {S : Type*} [monoid S] [distrib_mul_action S V] instance [has_smul R S] [is_scalar_tower R S V] : is_scalar_tower R S (hahn_series Γ V) := ⟨λ r s a, by { ext, simp }⟩ instance [smul_comm_class R S V] : smul_comm_class R S (hahn_series Γ V) := ⟨λ r s a, by { ext, simp [smul_comm] }⟩ end distrib_mul_action section module variables [partial_order Γ] [semiring R] {V : Type*} [add_comm_monoid V] [module R V] instance : module R (hahn_series Γ V) := { zero_smul := λ _, by { ext, simp }, add_smul := λ _ _ _, by { ext, simp [add_smul] }, .. hahn_series.distrib_mul_action } /-- `single` as a linear map -/ @[simps] def single.linear_map (a : Γ) : R →ₗ[R] (hahn_series Γ R) := { map_smul' := λ r s, by { ext b, by_cases h : b = a; simp [h] }, ..single.add_monoid_hom a } /-- `coeff g` as a linear map -/ @[simps] def coeff.linear_map (g : Γ) : (hahn_series Γ R) →ₗ[R] R := { map_smul' := λ r s, rfl, ..coeff.add_monoid_hom g } section domain variables {Γ' : Type*} [partial_order Γ'] lemma emb_domain_smul (f : Γ ↪o Γ') (r : R) (x : hahn_series Γ R) : emb_domain f (r • x) = r • emb_domain f x := begin ext g, by_cases hg : g ∈ set.range f, { obtain ⟨a, rfl⟩ := hg, simp }, { simp [emb_domain_notin_range, hg] } end /-- Extending the domain of Hahn series is a linear map. -/ @[simps] def emb_domain_linear_map (f : Γ ↪o Γ') : hahn_series Γ R →ₗ[R] hahn_series Γ' R := { to_fun := emb_domain f, map_add' := emb_domain_add f, map_smul' := emb_domain_smul f } end domain end module section multiplication variable [ordered_cancel_add_comm_monoid Γ] instance [has_zero R] [has_one R] : has_one (hahn_series Γ R) := ⟨single 0 1⟩ @[simp] lemma one_coeff [has_zero R] [has_one R] {a : Γ} : (1 : hahn_series Γ R).coeff a = if a = 0 then 1 else 0 := single_coeff @[simp] lemma single_zero_one [has_zero R] [has_one R] : (single 0 (1 : R)) = 1 := rfl @[simp] lemma support_one [mul_zero_one_class R] [nontrivial R] : support (1 : hahn_series Γ R) = {0} := support_single_of_ne one_ne_zero @[simp] lemma order_one [mul_zero_one_class R] : order (1 : hahn_series Γ R) = 0 := begin cases subsingleton_or_nontrivial R with h h; haveI := h, { rw [subsingleton.elim (1 : hahn_series Γ R) 0, order_zero] }, { exact order_single one_ne_zero } end instance [non_unital_non_assoc_semiring R] : has_mul (hahn_series Γ R) := { mul := λ x y, { coeff := λ a, ∑ ij in (add_antidiagonal x.is_pwo_support y.is_pwo_support a), x.coeff ij.fst * y.coeff ij.snd, is_pwo_support' := begin have h : {a : Γ | ∑ (ij : Γ × Γ) in add_antidiagonal x.is_pwo_support y.is_pwo_support a, x.coeff ij.fst * y.coeff ij.snd ≠ 0} ⊆ {a : Γ | (add_antidiagonal x.is_pwo_support y.is_pwo_support a).nonempty}, { intros a ha, contrapose! ha, simp [not_nonempty_iff_eq_empty.1 ha] }, exact is_pwo_support_add_antidiagonal.mono h, end, }, } @[simp] lemma mul_coeff [non_unital_non_assoc_semiring R] {x y : hahn_series Γ R} {a : Γ} : (x * y).coeff a = ∑ ij in (add_antidiagonal x.is_pwo_support y.is_pwo_support a), x.coeff ij.fst * y.coeff ij.snd := rfl lemma mul_coeff_right' [non_unital_non_assoc_semiring R] {x y : hahn_series Γ R} {a : Γ} {s : set Γ} (hs : s.is_pwo) (hys : y.support ⊆ s) : (x * y).coeff a = ∑ ij in (add_antidiagonal x.is_pwo_support hs a), x.coeff ij.fst * y.coeff ij.snd := begin rw mul_coeff, apply sum_subset_zero_on_sdiff (add_antidiagonal_mono_right hys) _ (λ _ _, rfl), intros b hb, simp only [not_and, mem_sdiff, mem_add_antidiagonal, mem_support, not_imp_not] at hb, rw [hb.2 hb.1.1 hb.1.2.2, mul_zero], end lemma mul_coeff_left' [non_unital_non_assoc_semiring R] {x y : hahn_series Γ R} {a : Γ} {s : set Γ} (hs : s.is_pwo) (hxs : x.support ⊆ s) : (x * y).coeff a = ∑ ij in (add_antidiagonal hs y.is_pwo_support a), x.coeff ij.fst * y.coeff ij.snd := begin rw mul_coeff, apply sum_subset_zero_on_sdiff (add_antidiagonal_mono_left hxs) _ (λ _ _, rfl), intros b hb, simp only [not_and', mem_sdiff, mem_add_antidiagonal, mem_support, not_ne_iff] at hb, rw [hb.2 ⟨hb.1.2.1, hb.1.2.2⟩, zero_mul], end instance [non_unital_non_assoc_semiring R] : distrib (hahn_series Γ R) := { left_distrib := λ x y z, begin ext a, have hwf := (y.is_pwo_support.union z.is_pwo_support), rw [mul_coeff_right' hwf, add_coeff, mul_coeff_right' hwf (set.subset_union_right _ _), mul_coeff_right' hwf (set.subset_union_left _ _)], { simp only [add_coeff, mul_add, sum_add_distrib] }, { intro b, simp only [add_coeff, ne.def, set.mem_union, set.mem_set_of_eq, mem_support], contrapose!, intro h, rw [h.1, h.2, add_zero], } end, right_distrib := λ x y z, begin ext a, have hwf := (x.is_pwo_support.union y.is_pwo_support), rw [mul_coeff_left' hwf, add_coeff, mul_coeff_left' hwf (set.subset_union_right _ _), mul_coeff_left' hwf (set.subset_union_left _ _)], { simp only [add_coeff, add_mul, sum_add_distrib] }, { intro b, simp only [add_coeff, ne.def, set.mem_union, set.mem_set_of_eq, mem_support], contrapose!, intro h, rw [h.1, h.2, add_zero], }, end, .. hahn_series.has_mul, .. hahn_series.has_add } lemma single_mul_coeff_add [non_unital_non_assoc_semiring R] {r : R} {x : hahn_series Γ R} {a : Γ} {b : Γ} : ((single b r) * x).coeff (a + b) = r * x.coeff a := begin by_cases hr : r = 0, { simp [hr] }, simp only [hr, smul_coeff, mul_coeff, support_single_of_ne, ne.def, not_false_iff, smul_eq_mul], by_cases hx : x.coeff a = 0, { simp only [hx, mul_zero], rw [sum_congr _ (λ _ _, rfl), sum_empty], ext ⟨a1, a2⟩, simp only [not_mem_empty, not_and, set.mem_singleton_iff, not_not, mem_add_antidiagonal, set.mem_set_of_eq, iff_false], rintro rfl h2 h1, rw add_comm at h1, rw ← add_right_cancel h1 at hx, exact h2 hx, }, transitivity ∑ (ij : Γ × Γ) in {(b, a)}, (single b r).coeff ij.fst * x.coeff ij.snd, { apply sum_congr _ (λ _ _, rfl), ext ⟨a1, a2⟩, simp only [set.mem_singleton_iff, prod.mk.inj_iff, mem_add_antidiagonal, mem_singleton, set.mem_set_of_eq], split, { rintro ⟨rfl, h2, h1⟩, rw add_comm at h1, refine ⟨rfl, add_right_cancel h1⟩ }, { rintro ⟨rfl, rfl⟩, exact ⟨rfl, by simp [hx], add_comm _ _⟩ } }, { simp } end lemma mul_single_coeff_add [non_unital_non_assoc_semiring R] {r : R} {x : hahn_series Γ R} {a : Γ} {b : Γ} : (x * (single b r)).coeff (a + b) = x.coeff a * r := begin by_cases hr : r = 0, { simp [hr] }, simp only [hr, smul_coeff, mul_coeff, support_single_of_ne, ne.def, not_false_iff, smul_eq_mul], by_cases hx : x.coeff a = 0, { simp only [hx, zero_mul], rw [sum_congr _ (λ _ _, rfl), sum_empty], ext ⟨a1, a2⟩, simp only [not_mem_empty, not_and, set.mem_singleton_iff, not_not, mem_add_antidiagonal, set.mem_set_of_eq, iff_false], rintro h2 rfl h1, rw ← add_right_cancel h1 at hx, exact h2 hx, }, transitivity ∑ (ij : Γ × Γ) in {(a,b)}, x.coeff ij.fst * (single b r).coeff ij.snd, { apply sum_congr _ (λ _ _, rfl), ext ⟨a1, a2⟩, simp only [set.mem_singleton_iff, prod.mk.inj_iff, mem_add_antidiagonal, mem_singleton, set.mem_set_of_eq], split, { rintro ⟨h2, rfl, h1⟩, refine ⟨add_right_cancel h1, rfl⟩ }, { rintro ⟨rfl, rfl⟩, simp [hx] } }, { simp } end @[simp] lemma mul_single_zero_coeff [non_unital_non_assoc_semiring R] {r : R} {x : hahn_series Γ R} {a : Γ} : (x * (single 0 r)).coeff a = x.coeff a * r := by rw [← add_zero a, mul_single_coeff_add, add_zero] lemma single_zero_mul_coeff [non_unital_non_assoc_semiring R] {r : R} {x : hahn_series Γ R} {a : Γ} : ((single 0 r) * x).coeff a = r * x.coeff a := by rw [← add_zero a, single_mul_coeff_add, add_zero] @[simp] lemma single_zero_mul_eq_smul [semiring R] {r : R} {x : hahn_series Γ R} : (single 0 r) * x = r • x := by { ext, exact single_zero_mul_coeff } theorem support_mul_subset_add_support [non_unital_non_assoc_semiring R] {x y : hahn_series Γ R} : support (x * y) ⊆ support x + support y := begin apply set.subset.trans (λ x hx, _) support_add_antidiagonal_subset_add, { exact x.is_pwo_support }, { exact y.is_pwo_support }, contrapose! hx, simp only [not_nonempty_iff_eq_empty, ne.def, set.mem_set_of_eq] at hx, simp [hx], end lemma mul_coeff_order_add_order {Γ} [linear_ordered_cancel_add_comm_monoid Γ] [non_unital_non_assoc_semiring R] (x y : hahn_series Γ R) : (x * y).coeff (x.order + y.order) = x.coeff x.order * y.coeff y.order := begin by_cases hx : x = 0, { simp [hx], }, by_cases hy : y = 0, { simp [hy], }, rw [order_of_ne hx, order_of_ne hy, mul_coeff, finset.add_antidiagonal_min_add_min, finset.sum_singleton], end private lemma mul_assoc' [non_unital_semiring R] (x y z : hahn_series Γ R) : x * y * z = x * (y * z) := begin ext b, rw [mul_coeff_left' (x.is_pwo_support.add y.is_pwo_support) support_mul_subset_add_support, mul_coeff_right' (y.is_pwo_support.add z.is_pwo_support) support_mul_subset_add_support], simp only [mul_coeff, add_coeff, sum_mul, mul_sum, sum_sigma'], refine sum_bij_ne_zero (λ a has ha0, ⟨⟨a.2.1, a.2.2 + a.1.2⟩, ⟨a.2.2, a.1.2⟩⟩) _ _ _ _, { rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H1 H2, simp only [and_true, set.image2_add, eq_self_iff_true, mem_add_antidiagonal, ne.def, set.image_prod, mem_sigma, set.mem_set_of_eq] at H1 H2 ⊢, obtain ⟨⟨H3, nz, rfl⟩, nx, ny, rfl⟩ := H1, exact ⟨⟨nx, set.add_mem_add ny nz, (add_assoc _ _ _).symm⟩, ny, nz⟩ }, { rintros ⟨⟨i1,j1⟩, k1,l1⟩ ⟨⟨i2,j2⟩, k2,l2⟩ H1 H2 H3 H4 H5, simp only [set.image2_add, prod.mk.inj_iff, mem_add_antidiagonal, ne.def, set.image_prod, mem_sigma, set.mem_set_of_eq, heq_iff_eq] at H1 H3 H5, obtain ⟨⟨rfl, H⟩, rfl, rfl⟩ := H5, simp only [and_true, prod.mk.inj_iff, eq_self_iff_true, heq_iff_eq, ←H1.2.2.2, ←H3.2.2.2] }, { rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H1 H2, simp only [exists_prop, set.image2_add, prod.mk.inj_iff, mem_add_antidiagonal, sigma.exists, ne.def, set.image_prod, mem_sigma, set.mem_set_of_eq, heq_iff_eq, prod.exists] at H1 H2 ⊢, obtain ⟨⟨nx, H, rfl⟩, ny, nz, rfl⟩ := H1, exact ⟨i + k, l, i, k, ⟨⟨set.add_mem_add nx ny, nz, add_assoc _ _ _⟩, nx, ny, rfl⟩, λ con, H2 ((mul_assoc _ _ _).symm.trans con), ⟨rfl, rfl⟩, rfl, rfl⟩ }, { rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H1 H2, simp [mul_assoc], } end instance [non_unital_non_assoc_semiring R] : non_unital_non_assoc_semiring (hahn_series Γ R) := { zero := 0, add := (+), mul := (*), zero_mul := λ _, by { ext, simp }, mul_zero := λ _, by { ext, simp }, .. hahn_series.add_comm_monoid, .. hahn_series.distrib } instance [non_unital_semiring R] : non_unital_semiring (hahn_series Γ R) := { zero := 0, add := (+), mul := (*), mul_assoc := mul_assoc', .. hahn_series.non_unital_non_assoc_semiring } instance [non_assoc_semiring R] : non_assoc_semiring (hahn_series Γ R) := { zero := 0, one := 1, add := (+), mul := (*), one_mul := λ x, by { ext, exact single_zero_mul_coeff.trans (one_mul _) }, mul_one := λ x, by { ext, exact mul_single_zero_coeff.trans (mul_one _) }, .. add_monoid_with_one.unary, .. hahn_series.non_unital_non_assoc_semiring } instance [semiring R] : semiring (hahn_series Γ R) := { zero := 0, one := 1, add := (+), mul := (*), .. hahn_series.non_assoc_semiring, .. hahn_series.non_unital_semiring } instance [non_unital_comm_semiring R] : non_unital_comm_semiring (hahn_series Γ R) := { mul_comm := λ x y, begin ext, simp_rw [mul_coeff, mul_comm], refine sum_bij (λ a ha, a.swap) (λ a ha, _) (λ a ha, rfl) (λ _ _ _ _, prod.swap_inj.1) (λ a ha, ⟨a.swap, _, a.swap_swap.symm⟩); rwa swap_mem_add_antidiagonal, end, .. hahn_series.non_unital_semiring } instance [comm_semiring R] : comm_semiring (hahn_series Γ R) := { .. hahn_series.non_unital_comm_semiring, .. hahn_series.semiring } instance [non_unital_non_assoc_ring R] : non_unital_non_assoc_ring (hahn_series Γ R) := { .. hahn_series.non_unital_non_assoc_semiring, .. hahn_series.add_group } instance [non_unital_ring R] : non_unital_ring (hahn_series Γ R) := { .. hahn_series.non_unital_non_assoc_ring, .. hahn_series.non_unital_semiring } instance [non_assoc_ring R] : non_assoc_ring (hahn_series Γ R) := { .. hahn_series.non_unital_non_assoc_ring, .. hahn_series.non_assoc_semiring } instance [ring R] : ring (hahn_series Γ R) := { .. hahn_series.semiring, .. hahn_series.add_comm_group } instance [non_unital_comm_ring R] : non_unital_comm_ring (hahn_series Γ R) := { .. hahn_series.non_unital_comm_semiring, .. hahn_series.non_unital_ring } instance [comm_ring R] : comm_ring (hahn_series Γ R) := { .. hahn_series.comm_semiring, .. hahn_series.ring } instance {Γ} [linear_ordered_cancel_add_comm_monoid Γ] [non_unital_non_assoc_semiring R] [no_zero_divisors R] : no_zero_divisors (hahn_series Γ R) := { eq_zero_or_eq_zero_of_mul_eq_zero := λ x y xy, begin by_cases hx : x = 0, { left, exact hx }, right, contrapose! xy, rw [hahn_series.ext_iff, function.funext_iff, not_forall], refine ⟨x.order + y.order, _⟩, rw [mul_coeff_order_add_order x y, zero_coeff, mul_eq_zero], simp [coeff_order_ne_zero, hx, xy], end } instance {Γ} [linear_ordered_cancel_add_comm_monoid Γ] [ring R] [is_domain R] : is_domain (hahn_series Γ R) := no_zero_divisors.to_is_domain _ @[simp] lemma order_mul {Γ} [linear_ordered_cancel_add_comm_monoid Γ] [non_unital_non_assoc_semiring R] [no_zero_divisors R] {x y : hahn_series Γ R} (hx : x ≠ 0) (hy : y ≠ 0) : (x * y).order = x.order + y.order := begin apply le_antisymm, { apply order_le_of_coeff_ne_zero, rw [mul_coeff_order_add_order x y], exact mul_ne_zero (coeff_order_ne_zero hx) (coeff_order_ne_zero hy) }, { rw [order_of_ne hx, order_of_ne hy, order_of_ne (mul_ne_zero hx hy), ← set.is_wf.min_add], exact set.is_wf.min_le_min_of_subset (support_mul_subset_add_support) }, end @[simp] lemma order_pow {Γ} [linear_ordered_cancel_add_comm_monoid Γ] [semiring R] [no_zero_divisors R] (x : hahn_series Γ R) (n : ℕ) : (x ^ n).order = n • x.order := begin induction n with h IH, { simp }, rcases eq_or_ne x 0 with rfl|hx, { simp }, rw [pow_succ', order_mul (pow_ne_zero _ hx) hx, succ_nsmul', IH] end section non_unital_non_assoc_semiring variables [non_unital_non_assoc_semiring R] @[simp] lemma single_mul_single {a b : Γ} {r s : R} : single a r * single b s = single (a + b) (r * s) := begin ext x, by_cases h : x = a + b, { rw [h, mul_single_coeff_add], simp }, { rw [single_coeff_of_ne h, mul_coeff, sum_eq_zero], simp_rw mem_add_antidiagonal, rintro ⟨y, z⟩ ⟨hy, hz, rfl⟩, rw [eq_of_mem_support_single hy, eq_of_mem_support_single hz] at h, exact (h rfl).elim } end end non_unital_non_assoc_semiring section non_assoc_semiring variables [non_assoc_semiring R] /-- `C a` is the constant Hahn Series `a`. `C` is provided as a ring homomorphism. -/ @[simps] def C : R →+* (hahn_series Γ R) := { to_fun := single 0, map_zero' := single_eq_zero, map_one' := rfl, map_add' := λ x y, by { ext a, by_cases h : a = 0; simp [h] }, map_mul' := λ x y, by rw [single_mul_single, zero_add] } @[simp] lemma C_zero : C (0 : R) = (0 : hahn_series Γ R) := C.map_zero @[simp] lemma C_one : C (1 : R) = (1 : hahn_series Γ R) := C.map_one lemma C_injective : function.injective (C : R → hahn_series Γ R) := begin intros r s rs, rw [ext_iff, function.funext_iff] at rs, have h := rs 0, rwa [C_apply, single_coeff_same, C_apply, single_coeff_same] at h, end lemma C_ne_zero {r : R} (h : r ≠ 0) : (C r : hahn_series Γ R) ≠ 0 := begin contrapose! h, rw ← C_zero at h, exact C_injective h, end lemma order_C {r : R} : order (C r : hahn_series Γ R) = 0 := begin by_cases h : r = 0, { rw [h, C_zero, order_zero] }, { exact order_single h } end end non_assoc_semiring section semiring variables [semiring R] lemma C_mul_eq_smul {r : R} {x : hahn_series Γ R} : C r * x = r • x := single_zero_mul_eq_smul end semiring section domain variables {Γ' : Type*} [ordered_cancel_add_comm_monoid Γ'] lemma emb_domain_mul [non_unital_non_assoc_semiring R] (f : Γ ↪o Γ') (hf : ∀ x y, f (x + y) = f x + f y) (x y : hahn_series Γ R) : emb_domain f (x * y) = emb_domain f x * emb_domain f y := begin ext g, by_cases hg : g ∈ set.range f, { obtain ⟨g, rfl⟩ := hg, simp only [mul_coeff, emb_domain_coeff], transitivity ∑ ij in (add_antidiagonal x.is_pwo_support y.is_pwo_support g).map (function.embedding.prod_map f.to_embedding f.to_embedding), (emb_domain f x).coeff (ij.1) * (emb_domain f y).coeff (ij.2), { simp }, apply sum_subset, { rintro ⟨i, j⟩ hij, simp only [exists_prop, mem_map, prod.mk.inj_iff, mem_add_antidiagonal, function.embedding.coe_prod_map, mem_support, prod.exists] at hij, obtain ⟨i, j, ⟨hx, hy, rfl⟩, rfl, rfl⟩ := hij, simp [hx, hy, hf], }, { rintro ⟨_, _⟩ h1 h2, contrapose! h2, obtain ⟨i, hi, rfl⟩ := support_emb_domain_subset (ne_zero_and_ne_zero_of_mul h2).1, obtain ⟨j, hj, rfl⟩ := support_emb_domain_subset (ne_zero_and_ne_zero_of_mul h2).2, simp only [exists_prop, mem_map, prod.mk.inj_iff, mem_add_antidiagonal, function.embedding.coe_prod_map, mem_support, prod.exists], simp only [mem_add_antidiagonal, emb_domain_coeff, mem_support, ←hf, order_embedding.eq_iff_eq] at h1, exact ⟨i, j, h1, rfl⟩ } }, { rw [emb_domain_notin_range hg, eq_comm], contrapose! hg, obtain ⟨_, _, hi, hj, rfl⟩ := support_mul_subset_add_support ((mem_support _ _).2 hg), obtain ⟨i, hi, rfl⟩ := support_emb_domain_subset hi, obtain ⟨j, hj, rfl⟩ := support_emb_domain_subset hj, refine ⟨i + j, hf i j⟩, } end lemma emb_domain_one [non_assoc_semiring R] (f : Γ ↪o Γ') (hf : f 0 = 0): emb_domain f (1 : hahn_series Γ R) = (1 : hahn_series Γ' R) := emb_domain_single.trans $ hf.symm ▸ rfl /-- Extending the domain of Hahn series is a ring homomorphism. -/ @[simps] def emb_domain_ring_hom [non_assoc_semiring R] (f : Γ →+ Γ') (hfi : function.injective f) (hf : ∀ g g' : Γ, f g ≤ f g' ↔ g ≤ g') : hahn_series Γ R →+* hahn_series Γ' R := { to_fun := emb_domain ⟨⟨f, hfi⟩, hf⟩, map_one' := emb_domain_one _ f.map_zero, map_mul' := emb_domain_mul _ f.map_add, map_zero' := emb_domain_zero, map_add' := emb_domain_add _} lemma emb_domain_ring_hom_C [non_assoc_semiring R] {f : Γ →+ Γ'} {hfi : function.injective f} {hf : ∀ g g' : Γ, f g ≤ f g' ↔ g ≤ g'} {r : R} : emb_domain_ring_hom f hfi hf (C r) = C r := emb_domain_single.trans (by simp) end domain section algebra variables [comm_semiring R] {A : Type*} [semiring A] [algebra R A] instance : algebra R (hahn_series Γ A) := { to_ring_hom := C.comp (algebra_map R A), smul_def' := λ r x, by { ext, simp }, commutes' := λ r x, by { ext, simp only [smul_coeff, single_zero_mul_eq_smul, ring_hom.coe_comp, ring_hom.to_fun_eq_coe, C_apply, function.comp_app, algebra_map_smul, mul_single_zero_coeff], rw [← algebra.commutes, algebra.smul_def], }, } theorem C_eq_algebra_map : C = (algebra_map R (hahn_series Γ R)) := rfl theorem algebra_map_apply {r : R} : algebra_map R (hahn_series Γ A) r = C (algebra_map R A r) := rfl instance [nontrivial Γ] [nontrivial R] : nontrivial (subalgebra R (hahn_series Γ R)) := ⟨⟨⊥, ⊤, begin rw [ne.def, set_like.ext_iff, not_forall], obtain ⟨a, ha⟩ := exists_ne (0 : Γ), refine ⟨single a 1, _⟩, simp only [algebra.mem_bot, not_exists, set.mem_range, iff_true, algebra.mem_top], intros x, rw [ext_iff, function.funext_iff, not_forall], refine ⟨a, _⟩, rw [single_coeff_same, algebra_map_apply, C_apply, single_coeff_of_ne ha], exact zero_ne_one end⟩⟩ section domain variables {Γ' : Type*} [ordered_cancel_add_comm_monoid Γ'] /-- Extending the domain of Hahn series is an algebra homomorphism. -/ @[simps] def emb_domain_alg_hom (f : Γ →+ Γ') (hfi : function.injective f) (hf : ∀ g g' : Γ, f g ≤ f g' ↔ g ≤ g') : hahn_series Γ A →ₐ[R] hahn_series Γ' A := { commutes' := λ r, emb_domain_ring_hom_C, .. emb_domain_ring_hom f hfi hf } end domain end algebra end multiplication section semiring variables [semiring R] /-- The ring `hahn_series ℕ R` is isomorphic to `power_series R`. -/ @[simps] def to_power_series : hahn_series ℕ R ≃+* power_series R := { to_fun := λ f, power_series.mk f.coeff, inv_fun := λ f, ⟨λ n, power_series.coeff R n f, (nat.lt_wf.is_wf _).is_pwo⟩, left_inv := λ f, by { ext, simp }, right_inv := λ f, by { ext, simp }, map_add' := λ f g, by { ext, simp }, map_mul' := λ f g, begin ext n, simp only [power_series.coeff_mul, power_series.coeff_mk, mul_coeff, is_pwo_support], classical, refine sum_filter_ne_zero.symm.trans ((sum_congr _ $ λ _ _, rfl).trans sum_filter_ne_zero), ext m, simp only [nat.mem_antidiagonal, mem_add_antidiagonal, and.congr_left_iff, mem_filter, mem_support], rintro h, rw [and_iff_right (left_ne_zero_of_mul h), and_iff_right (right_ne_zero_of_mul h)], end } lemma coeff_to_power_series {f : hahn_series ℕ R} {n : ℕ} : power_series.coeff R n f.to_power_series = f.coeff n := power_series.coeff_mk _ _ lemma coeff_to_power_series_symm {f : power_series R} {n : ℕ} : (hahn_series.to_power_series.symm f).coeff n = power_series.coeff R n f := rfl variables (Γ R) [strict_ordered_semiring Γ] /-- Casts a power series as a Hahn series with coefficients from an `strict_ordered_semiring`. -/ def of_power_series : (power_series R) →+* hahn_series Γ R := (hahn_series.emb_domain_ring_hom (nat.cast_add_monoid_hom Γ) nat.strict_mono_cast.injective (λ _ _, nat.cast_le)).comp (ring_equiv.to_ring_hom to_power_series.symm) variables {Γ} {R} lemma of_power_series_injective : function.injective (of_power_series Γ R) := emb_domain_injective.comp to_power_series.symm.injective @[simp] lemma of_power_series_apply (x : power_series R) : of_power_series Γ R x = hahn_series.emb_domain ⟨⟨(coe : ℕ → Γ), nat.strict_mono_cast.injective⟩, λ a b, begin simp only [function.embedding.coe_fn_mk], exact nat.cast_le, end⟩ (to_power_series.symm x) := rfl lemma of_power_series_apply_coeff (x : power_series R) (n : ℕ) : (of_power_series Γ R x).coeff n = power_series.coeff R n x := by simp @[simp] lemma of_power_series_C (r : R) : of_power_series Γ R (power_series.C R r) = hahn_series.C r := begin ext n, simp only [C, single_coeff, of_power_series_apply, ring_hom.coe_mk], split_ifs with hn hn, { subst hn, convert @emb_domain_coeff _ _ _ _ _ _ _ _ 0; simp }, { rw emb_domain_notin_image_support, simp only [not_exists, set.mem_image, to_power_series_symm_apply_coeff, mem_support, power_series.coeff_C], intro, simp [ne.symm hn] {contextual := tt} } end @[simp] lemma of_power_series_X : of_power_series Γ R power_series.X = single 1 1 := begin ext n, simp only [single_coeff, of_power_series_apply, ring_hom.coe_mk], split_ifs with hn hn, { rw hn, convert @emb_domain_coeff _ _ _ _ _ _ _ _ 1; simp }, { rw emb_domain_notin_image_support, simp only [not_exists, set.mem_image, to_power_series_symm_apply_coeff, mem_support, power_series.coeff_X], intro, simp [ne.symm hn] {contextual := tt} } end @[simp] lemma of_power_series_X_pow {R} [comm_semiring R] (n : ℕ) : of_power_series Γ R (power_series.X ^ n) = single (n : Γ) 1 := begin rw ring_hom.map_pow, induction n with n ih, { simp, refl }, rw [pow_succ, ih, of_power_series_X, mul_comm, single_mul_single, one_mul, nat.cast_succ] end -- Lemmas about converting hahn_series over fintype to and from mv_power_series /-- The ring `hahn_series (σ →₀ ℕ) R` is isomorphic to `mv_power_series σ R` for a `fintype` `σ`. We take the index set of the hahn series to be `finsupp` rather than `pi`, even though we assume `fintype σ` as this is more natural for alignment with `mv_power_series`. After importing `algebra.order.pi` the ring `hahn_series (σ → ℕ) R` could be constructed instead. -/ @[simps] def to_mv_power_series {σ : Type*} [fintype σ] : hahn_series (σ →₀ ℕ) R ≃+* mv_power_series σ R := { to_fun := λ f, f.coeff, inv_fun := λ f, ⟨(f : (σ →₀ ℕ) → R), finsupp.is_pwo _⟩, left_inv := λ f, by { ext, simp }, right_inv := λ f, by { ext, simp }, map_add' := λ f g, by { ext, simp }, map_mul' := λ f g, begin ext n, simp only [mv_power_series.coeff_mul], classical, change (f * g).coeff n = _, simp_rw [mul_coeff], refine sum_filter_ne_zero.symm.trans ((sum_congr _ (λ _ _, rfl)).trans sum_filter_ne_zero), ext m, simp only [and.congr_left_iff, mem_add_antidiagonal, mem_filter, mem_support, finsupp.mem_antidiagonal], rintro h, rw [and_iff_right (left_ne_zero_of_mul h), and_iff_right (right_ne_zero_of_mul h)], end } variables {σ : Type*} [fintype σ] lemma coeff_to_mv_power_series {f : hahn_series (σ →₀ ℕ) R} {n : σ →₀ ℕ} : mv_power_series.coeff R n f.to_mv_power_series = f.coeff n := rfl lemma coeff_to_mv_power_series_symm {f : mv_power_series σ R} {n : σ →₀ ℕ} : (hahn_series.to_mv_power_series.symm f).coeff n = mv_power_series.coeff R n f := rfl end semiring section algebra variables (R) [comm_semiring R] {A : Type*} [semiring A] [algebra R A] /-- The `R`-algebra `hahn_series ℕ A` is isomorphic to `power_series A`. -/ @[simps] def to_power_series_alg : (hahn_series ℕ A) ≃ₐ[R] power_series A := { commutes' := λ r, begin ext n, simp only [algebra_map_apply, power_series.algebra_map_apply, ring_equiv.to_fun_eq_coe, C_apply, coeff_to_power_series], cases n, { simp only [power_series.coeff_zero_eq_constant_coeff, single_coeff_same], refl }, { simp only [n.succ_ne_zero, ne.def, not_false_iff, single_coeff_of_ne], rw [power_series.coeff_C, if_neg n.succ_ne_zero] } end, .. to_power_series } variables (Γ R) [strict_ordered_semiring Γ] /-- Casting a power series as a Hahn series with coefficients from an `strict_ordered_semiring` is an algebra homomorphism. -/ @[simps] def of_power_series_alg : (power_series A) →ₐ[R] hahn_series Γ A := (hahn_series.emb_domain_alg_hom (nat.cast_add_monoid_hom Γ) nat.strict_mono_cast.injective (λ _ _, nat.cast_le)).comp (alg_equiv.to_alg_hom (to_power_series_alg R).symm) instance power_series_algebra {S : Type*} [comm_semiring S] [algebra S (power_series R)] : algebra S (hahn_series Γ R) := ring_hom.to_algebra $ (of_power_series Γ R).comp (algebra_map S (power_series R)) variables {R} {S : Type*} [comm_semiring S] [algebra S (power_series R)] lemma algebra_map_apply' (x : S) : algebra_map S (hahn_series Γ R) x = of_power_series Γ R (algebra_map S (power_series R) x) := rfl @[simp] lemma _root_.polynomial.algebra_map_hahn_series_apply (f : R[X]) : algebra_map R[X] (hahn_series Γ R) f = of_power_series Γ R f := rfl lemma _root_.polynomial.algebra_map_hahn_series_injective : function.injective (algebra_map R[X] (hahn_series Γ R)) := of_power_series_injective.comp (polynomial.coe_injective R) end algebra section valuation variables (Γ R) [linear_ordered_cancel_add_comm_monoid Γ] [ring R] [is_domain R] /-- The additive valuation on `hahn_series Γ R`, returning the smallest index at which a Hahn Series has a nonzero coefficient, or `⊤` for the 0 series. -/ def add_val : add_valuation (hahn_series Γ R) (with_top Γ) := add_valuation.of (λ x, if x = (0 : hahn_series Γ R) then (⊤ : with_top Γ) else x.order) (if_pos rfl) ((if_neg one_ne_zero).trans (by simp [order_of_ne])) (λ x y, begin by_cases hx : x = 0, { by_cases hy : y = 0; { simp [hx, hy] } }, { by_cases hy : y = 0, { simp [hx, hy] }, { simp only [hx, hy, support_nonempty_iff, if_neg, not_false_iff, is_wf_support], by_cases hxy : x + y = 0, { simp [hxy] }, rw [if_neg hxy, ← with_top.coe_min, with_top.coe_le_coe], exact min_order_le_order_add hxy } }, end) (λ x y, begin by_cases hx : x = 0, { simp [hx] }, by_cases hy : y = 0, { simp [hy] }, rw [if_neg hx, if_neg hy, if_neg (mul_ne_zero hx hy), ← with_top.coe_add, with_top.coe_eq_coe, order_mul hx hy], end) variables {Γ} {R} lemma add_val_apply {x : hahn_series Γ R} : add_val Γ R x = if x = (0 : hahn_series Γ R) then (⊤ : with_top Γ) else x.order := add_valuation.of_apply _ @[simp] lemma add_val_apply_of_ne {x : hahn_series Γ R} (hx : x ≠ 0) : add_val Γ R x = x.order := if_neg hx lemma add_val_le_of_coeff_ne_zero {x : hahn_series Γ R} {g : Γ} (h : x.coeff g ≠ 0) : add_val Γ R x ≤ g := begin rw [add_val_apply_of_ne (ne_zero_of_coeff_ne_zero h), with_top.coe_le_coe], exact order_le_of_coeff_ne_zero h end end valuation lemma is_pwo_Union_support_powers [linear_ordered_cancel_add_comm_monoid Γ] [ring R] [is_domain R] {x : hahn_series Γ R} (hx : 0 < add_val Γ R x) : (⋃ n : ℕ, (x ^ n).support).is_pwo := begin apply (x.is_wf_support.is_pwo.add_submonoid_closure (λ g hg, _)).mono _, { exact with_top.coe_le_coe.1 (le_trans (le_of_lt hx) (add_val_le_of_coeff_ne_zero hg)) }, refine set.Union_subset (λ n, _), induction n with n ih; intros g hn, { simp only [exists_prop, and_true, set.mem_singleton_iff, set.set_of_eq_eq_singleton, mem_support, ite_eq_right_iff, ne.def, not_false_iff, one_ne_zero, pow_zero, not_forall, one_coeff] at hn, rw [hn, set_like.mem_coe], exact add_submonoid.zero_mem _ }, { obtain ⟨i, j, hi, hj, rfl⟩ := support_mul_subset_add_support hn, exact set_like.mem_coe.2 (add_submonoid.add_mem _ (add_submonoid.subset_closure hi) (ih hj)) } end section variables (Γ) (R) [partial_order Γ] [add_comm_monoid R] /-- An infinite family of Hahn series which has a formal coefficient-wise sum. The requirements for this are that the union of the supports of the series is well-founded, and that only finitely many series are nonzero at any given coefficient. -/ structure summable_family (α : Type*) := (to_fun : α → hahn_series Γ R) (is_pwo_Union_support' : set.is_pwo (⋃ (a : α), (to_fun a).support)) (finite_co_support' : ∀ (g : Γ), ({a | (to_fun a).coeff g ≠ 0}).finite) end namespace summable_family section add_comm_monoid variables [partial_order Γ] [add_comm_monoid R] {α : Type*} instance : has_coe_to_fun (summable_family Γ R α) (λ _, α → hahn_series Γ R):= ⟨to_fun⟩ lemma is_pwo_Union_support (s : summable_family Γ R α) : set.is_pwo (⋃ (a : α), (s a).support) := s.is_pwo_Union_support' lemma finite_co_support (s : summable_family Γ R α) (g : Γ) : (function.support (λ a, (s a).coeff g)).finite := s.finite_co_support' g lemma coe_injective : @function.injective (summable_family Γ R α) (α → hahn_series Γ R) coe_fn | ⟨f1, hU1, hf1⟩ ⟨f2, hU2, hf2⟩ h := begin change f1 = f2 at h, subst h, end @[ext] lemma ext {s t : summable_family Γ R α} (h : ∀ (a : α), s a = t a) : s = t := coe_injective $ funext h instance : has_add (summable_family Γ R α) := ⟨λ x y, { to_fun := x + y, is_pwo_Union_support' := (x.is_pwo_Union_support.union y.is_pwo_Union_support).mono (begin rw ← set.Union_union_distrib, exact set.Union_mono (λ a, support_add_subset) end), finite_co_support' := λ g, ((x.finite_co_support g).union (y.finite_co_support g)).subset begin intros a ha, change (x a).coeff g + (y a).coeff g ≠ 0 at ha, rw [set.mem_union, function.mem_support, function.mem_support], contrapose! ha, rw [ha.1, ha.2, add_zero] end }⟩ instance : has_zero (summable_family Γ R α) := ⟨⟨0, by simp, by simp⟩⟩ instance : inhabited (summable_family Γ R α) := ⟨0⟩ @[simp] lemma coe_add {s t : summable_family Γ R α} : ⇑(s + t) = s + t := rfl lemma add_apply {s t : summable_family Γ R α} {a : α} : (s + t) a = s a + t a := rfl @[simp] lemma coe_zero : ((0 : summable_family Γ R α) : α → hahn_series Γ R) = 0 := rfl lemma zero_apply {a : α} : (0 : summable_family Γ R α) a = 0 := rfl instance : add_comm_monoid (summable_family Γ R α) := { add := (+), zero := 0, zero_add := λ s, by { ext, apply zero_add }, add_zero := λ s, by { ext, apply add_zero }, add_comm := λ s t, by { ext, apply add_comm }, add_assoc := λ r s t, by { ext, apply add_assoc } } /-- The infinite sum of a `summable_family` of Hahn series. -/ def hsum (s : summable_family Γ R α) : hahn_series Γ R := { coeff := λ g, ∑ᶠ i, (s i).coeff g, is_pwo_support' := s.is_pwo_Union_support.mono (λ g, begin contrapose, rw [set.mem_Union, not_exists, function.mem_support, not_not], simp_rw [mem_support, not_not], intro h, rw [finsum_congr h, finsum_zero], end) } @[simp] lemma hsum_coeff {s : summable_family Γ R α} {g : Γ} : s.hsum.coeff g = ∑ᶠ i, (s i).coeff g := rfl lemma support_hsum_subset {s : summable_family Γ R α} : s.hsum.support ⊆ ⋃ (a : α), (s a).support := λ g hg, begin rw [mem_support, hsum_coeff, finsum_eq_sum _ (s.finite_co_support _)] at hg, obtain ⟨a, h1, h2⟩ := exists_ne_zero_of_sum_ne_zero hg, rw [set.mem_Union], exact ⟨a, h2⟩, end @[simp] lemma hsum_add {s t : summable_family Γ R α} : (s + t).hsum = s.hsum + t.hsum := begin ext g, simp only [hsum_coeff, add_coeff, add_apply], exact finsum_add_distrib (s.finite_co_support _) (t.finite_co_support _) end end add_comm_monoid section add_comm_group variables [partial_order Γ] [add_comm_group R] {α : Type*} {s t : summable_family Γ R α} {a : α} instance : add_comm_group (summable_family Γ R α) := { neg := λ s, { to_fun := λ a, - s a, is_pwo_Union_support' := by { simp_rw [support_neg], exact s.is_pwo_Union_support' }, finite_co_support' := λ g, by { simp only [neg_coeff', pi.neg_apply, ne.def, neg_eq_zero], exact s.finite_co_support g } }, add_left_neg := λ a, by { ext, apply add_left_neg }, .. summable_family.add_comm_monoid } @[simp] lemma coe_neg : ⇑(-s) = - s := rfl lemma neg_apply : (-s) a = - (s a) := rfl @[simp] lemma coe_sub : ⇑(s - t) = s - t := rfl lemma sub_apply : (s - t) a = s a - t a := rfl end add_comm_group section semiring variables [ordered_cancel_add_comm_monoid Γ] [semiring R] {α : Type*} instance : has_smul (hahn_series Γ R) (summable_family Γ R α) := { smul := λ x s, { to_fun := λ a, x * (s a), is_pwo_Union_support' := begin apply (x.is_pwo_support.add s.is_pwo_Union_support).mono, refine set.subset.trans (set.Union_mono (λ a, support_mul_subset_add_support)) _, intro g, simp only [set.mem_Union, exists_imp_distrib], exact λ a ha, (set.add_subset_add (set.subset.refl _) (set.subset_Union _ a)) ha, end, finite_co_support' := λ g, begin refine ((add_antidiagonal x.is_pwo_support s.is_pwo_Union_support g).finite_to_set.bUnion' (λ ij hij, _)).subset (λ a ha, _), { exact λ ij hij, function.support (λ a, (s a).coeff ij.2) }, { apply s.finite_co_support }, { obtain ⟨i, j, hi, hj, rfl⟩ := support_mul_subset_add_support ha, simp only [exists_prop, set.mem_Union, mem_add_antidiagonal, mul_coeff, mem_support, is_pwo_support, prod.exists], exact ⟨i, j, mem_coe.2 (mem_add_antidiagonal.2 ⟨hi, set.mem_Union.2 ⟨a, hj⟩, rfl⟩), hj⟩ } end } } @[simp] lemma smul_apply {x : hahn_series Γ R} {s : summable_family Γ R α} {a : α} : (x • s) a = x * (s a) := rfl instance : module (hahn_series Γ R) (summable_family Γ R α) := { smul := (•), smul_zero := λ x, ext (λ a, mul_zero _), zero_smul := λ x, ext (λ a, zero_mul _), one_smul := λ x, ext (λ a, one_mul _), add_smul := λ x y s, ext (λ a, add_mul _ _ _), smul_add := λ x s t, ext (λ a, mul_add _ _ _), mul_smul := λ x y s, ext (λ a, mul_assoc _ _ _) } @[simp] lemma hsum_smul {x : hahn_series Γ R} {s : summable_family Γ R α} : (x • s).hsum = x * s.hsum := begin ext g, simp only [mul_coeff, hsum_coeff, smul_apply], have h : ∀ i, (s i).support ⊆ ⋃ j, (s j).support := set.subset_Union _, refine (eq.trans (finsum_congr (λ a, _)) (finsum_sum_comm (add_antidiagonal x.is_pwo_support s.is_pwo_Union_support g) (λ i ij, x.coeff (prod.fst ij) * (s i).coeff ij.snd) _)).trans _, { refine sum_subset (add_antidiagonal_mono_right (set.subset_Union _ a)) _, rintro ⟨i, j⟩ hU ha, rw mem_add_antidiagonal at *, rw [not_not.1 (λ con, ha ⟨hU.1, con, hU.2.2⟩), mul_zero] }, { rintro ⟨i, j⟩ hij, refine (s.finite_co_support j).subset _, simp_rw [function.support_subset_iff', function.mem_support, not_not], intros a ha, rw [ha, mul_zero] }, { refine (sum_congr rfl _).trans (sum_subset (add_antidiagonal_mono_right _) _).symm, { rintro ⟨i, j⟩ hij, rw mul_finsum, apply s.finite_co_support, }, { intros x hx, simp only [set.mem_Union, ne.def, mem_support], contrapose! hx, simp [hx] }, { rintro ⟨i, j⟩ hU ha, rw mem_add_antidiagonal at *, rw [← hsum_coeff, not_not.1 (λ con, ha ⟨hU.1, con, hU.2.2⟩), mul_zero] } } end /-- The summation of a `summable_family` as a `linear_map`. -/ @[simps] def lsum : (summable_family Γ R α) →ₗ[hahn_series Γ R] (hahn_series Γ R) := { to_fun := hsum, map_add' := λ _ _, hsum_add, map_smul' := λ _ _, hsum_smul } @[simp] lemma hsum_sub {R : Type*} [ring R] {s t : summable_family Γ R α} : (s - t).hsum = s.hsum - t.hsum := by rw [← lsum_apply, linear_map.map_sub, lsum_apply, lsum_apply] end semiring section of_finsupp variables [partial_order Γ] [add_comm_monoid R] {α : Type*} /-- A family with only finitely many nonzero elements is summable. -/ def of_finsupp (f : α →₀ (hahn_series Γ R)) : summable_family Γ R α := { to_fun := f, is_pwo_Union_support' := begin apply (f.support.is_pwo_bUnion.2 $ λ a ha, (f a).is_pwo_support).mono, refine set.Union_subset_iff.2 (λ a g hg, _), have haf : a ∈ f.support, { rw [finsupp.mem_support_iff, ← support_nonempty_iff], exact ⟨g, hg⟩ }, exact set.mem_bUnion haf hg end, finite_co_support' := λ g, begin refine f.support.finite_to_set.subset (λ a ha, _), simp only [coeff.add_monoid_hom_apply, mem_coe, finsupp.mem_support_iff, ne.def, function.mem_support], contrapose! ha, simp [ha] end } @[simp] lemma coe_of_finsupp {f : α →₀ (hahn_series Γ R)} : ⇑(summable_family.of_finsupp f) = f := rfl @[simp] lemma hsum_of_finsupp {f : α →₀ (hahn_series Γ R)} : (of_finsupp f).hsum = f.sum (λ a, id) := begin ext g, simp only [hsum_coeff, coe_of_finsupp, finsupp.sum, ne.def], simp_rw [← coeff.add_monoid_hom_apply, id.def], rw [add_monoid_hom.map_sum, finsum_eq_sum_of_support_subset], intros x h, simp only [coeff.add_monoid_hom_apply, mem_coe, finsupp.mem_support_iff, ne.def], contrapose! h, simp [h] end end of_finsupp section emb_domain variables [partial_order Γ] [add_comm_monoid R] {α β : Type*} /-- A summable family can be reindexed by an embedding without changing its sum. -/ def emb_domain (s : summable_family Γ R α) (f : α ↪ β) : summable_family Γ R β := { to_fun := λ b, if h : b ∈ set.range f then s (classical.some h) else 0, is_pwo_Union_support' := begin refine s.is_pwo_Union_support.mono (set.Union_subset (λ b g h, _)), by_cases hb : b ∈ set.range f, { rw dif_pos hb at h, exact set.mem_Union.2 ⟨classical.some hb, h⟩ }, { contrapose! h, simp [hb] } end, finite_co_support' := λ g, ((s.finite_co_support g).image f).subset begin intros b h, by_cases hb : b ∈ set.range f, { simp only [ne.def, set.mem_set_of_eq, dif_pos hb] at h, exact ⟨classical.some hb, h, classical.some_spec hb⟩ }, { contrapose! h, simp only [ne.def, set.mem_set_of_eq, dif_neg hb, not_not, zero_coeff] } end } variables (s : summable_family Γ R α) (f : α ↪ β) {a : α} {b : β} lemma emb_domain_apply : s.emb_domain f b = if h : b ∈ set.range f then s (classical.some h) else 0 := rfl @[simp] lemma emb_domain_image : s.emb_domain f (f a) = s a := begin rw [emb_domain_apply, dif_pos (set.mem_range_self a)], exact congr rfl (f.injective (classical.some_spec (set.mem_range_self a))) end @[simp] lemma emb_domain_notin_range (h : b ∉ set.range f) : s.emb_domain f b = 0 := by rw [emb_domain_apply, dif_neg h] @[simp] lemma hsum_emb_domain : (s.emb_domain f).hsum = s.hsum := begin ext g, simp only [hsum_coeff, emb_domain_apply, apply_dite hahn_series.coeff, dite_apply, zero_coeff], exact finsum_emb_domain f (λ a, (s a).coeff g) end end emb_domain section powers variables [linear_ordered_cancel_add_comm_monoid Γ] [comm_ring R] [is_domain R] /-- The powers of an element of positive valuation form a summable family. -/ def powers (x : hahn_series Γ R) (hx : 0 < add_val Γ R x) : summable_family Γ R ℕ := { to_fun := λ n, x ^ n, is_pwo_Union_support' := is_pwo_Union_support_powers hx, finite_co_support' := λ g, begin have hpwo := (is_pwo_Union_support_powers hx), by_cases hg : g ∈ ⋃ n : ℕ, {g | (x ^ n).coeff g ≠ 0 }, swap, { exact set.finite_empty.subset (λ n hn, hg (set.mem_Union.2 ⟨n, hn⟩)) }, apply hpwo.is_wf.induction hg, intros y ys hy, refine ((((add_antidiagonal x.is_pwo_support hpwo y).finite_to_set.bUnion (λ ij hij, hy ij.snd _ _)).image nat.succ).union (set.finite_singleton 0)).subset _, { exact (mem_add_antidiagonal.1 (mem_coe.1 hij)).2.1 }, { obtain ⟨hi, hj, rfl⟩ := mem_add_antidiagonal.1 (mem_coe.1 hij), rw [← zero_add ij.snd, ← add_assoc, add_zero], exact add_lt_add_right (with_top.coe_lt_coe.1 (lt_of_lt_of_le hx (add_val_le_of_coeff_ne_zero hi))) _, }, { rintro (_ | n) hn, { exact set.mem_union_right _ (set.mem_singleton 0) }, { obtain ⟨i, j, hi, hj, rfl⟩ := support_mul_subset_add_support hn, refine set.mem_union_left _ ⟨n, set.mem_Union.2 ⟨⟨i, j⟩, set.mem_Union.2 ⟨_, hj⟩⟩, rfl⟩, simp only [and_true, set.mem_Union, mem_add_antidiagonal, mem_coe, eq_self_iff_true, ne.def, mem_support, set.mem_set_of_eq], exact ⟨hi, n, hj⟩ } } end } variables {x : hahn_series Γ R} (hx : 0 < add_val Γ R x) @[simp] lemma coe_powers : ⇑(powers x hx) = pow x := rfl lemma emb_domain_succ_smul_powers : (x • powers x hx).emb_domain ⟨nat.succ, nat.succ_injective⟩ = powers x hx - of_finsupp (finsupp.single 0 1) := begin apply summable_family.ext (λ n, _), cases n, { rw [emb_domain_notin_range, sub_apply, coe_powers, pow_zero, coe_of_finsupp, finsupp.single_eq_same, sub_self], rw [set.mem_range, not_exists], exact nat.succ_ne_zero }, { refine eq.trans (emb_domain_image _ ⟨nat.succ, nat.succ_injective⟩) _, simp only [pow_succ, coe_powers, coe_sub, smul_apply, coe_of_finsupp, pi.sub_apply], rw [finsupp.single_eq_of_ne (n.succ_ne_zero).symm, sub_zero] } end lemma one_sub_self_mul_hsum_powers : (1 - x) * (powers x hx).hsum = 1 := begin rw [← hsum_smul, sub_smul, one_smul, hsum_sub, ← hsum_emb_domain (x • powers x hx) ⟨nat.succ, nat.succ_injective⟩, emb_domain_succ_smul_powers], simp, end end powers end summable_family section inversion variables [linear_ordered_add_comm_group Γ] section is_domain variables [comm_ring R] [is_domain R] lemma unit_aux (x : hahn_series Γ R) {r : R} (hr : r * x.coeff x.order = 1) : 0 < add_val Γ R (1 - C r * (single (- x.order) 1) * x) := begin have h10 : (1 : R) ≠ 0 := one_ne_zero, have x0 : x ≠ 0 := ne_zero_of_coeff_ne_zero (right_ne_zero_of_mul_eq_one hr), refine lt_of_le_of_ne ((add_val Γ R).map_le_sub (ge_of_eq (add_val Γ R).map_one) _) _, { simp only [add_valuation.map_mul], rw [add_val_apply_of_ne x0, add_val_apply_of_ne (single_ne_zero h10), add_val_apply_of_ne _, order_C, order_single h10, with_top.coe_zero, zero_add, ← with_top.coe_add, neg_add_self, with_top.coe_zero], { exact le_refl 0 }, { exact C_ne_zero (left_ne_zero_of_mul_eq_one hr) } }, { rw [add_val_apply, ← with_top.coe_zero], split_ifs, { apply with_top.coe_ne_top }, rw [ne.def, with_top.coe_eq_coe], intro con, apply coeff_order_ne_zero h, rw [← con, mul_assoc, sub_coeff, one_coeff, if_pos rfl, C_mul_eq_smul, smul_coeff, smul_eq_mul, ← add_neg_self x.order, single_mul_coeff_add, one_mul, hr, sub_self] } end end is_domain instance [field R] : field (hahn_series Γ R) := { inv := λ x, if x0 : x = 0 then 0 else (C (x.coeff x.order)⁻¹ * (single (-x.order)) 1 * (summable_family.powers _ (unit_aux x (inv_mul_cancel (coeff_order_ne_zero x0)))).hsum), inv_zero := dif_pos rfl, mul_inv_cancel := λ x x0, begin refine (congr rfl (dif_neg x0)).trans _, have h := summable_family.one_sub_self_mul_hsum_powers (unit_aux x (inv_mul_cancel (coeff_order_ne_zero x0))), rw [sub_sub_cancel] at h, rw [← mul_assoc, mul_comm x, h], end, .. hahn_series.is_domain, .. hahn_series.comm_ring } end inversion end hahn_series
At the end of the Nordnes Peninsula, this aquarium makes a worthwhile trip, especially for families. There are around 60 individual aquaria here, housing lots of interesting marine species from octopi to reef fish, although kids are bound to gravitate to the shark tunnel or the seals and penguins. There's also a tropical zone housing snakes, crocodiles and other reptiles. On foot, you can get there from Torget in 20 minutes; alternatively, take the Vågen ferry or bus 11.
module Inigo.Async.Base import Data.Maybe import Inigo.Async.Promise import Inigo.Async.Util import Inigo.Paths %foreign (promisifyPrim "()=>new Promise((resolve,reject)=>{})") never__prim : promise () %foreign (promisifyPrim "(_,err)=>new Promise((resolve,reject)=>reject(err))") reject__prim : String -> promise a %foreign (promisifyResolve "null" "(text)=>console.log(text)") log__prim : String -> promise () %foreign (promisifyPrim (toArray "(cmd,args,workDir,detached,verbose)=>new Promise((resolve,reject)=>{let opts={detached:detached===1, stdio: ['ignore', process.stdout, process.stderr],cwd:workDir};require('child_process').spawn(cmd, toArray(args), opts).on('close', (code) => resolve(code))})")) system__prim : String -> List String -> String -> Int -> Int -> promise Int %foreign (promisifyPrim (toArray "(cmd,args,detached,verbose)=>new Promise((resolve,reject)=>{let opts={detached:detached===1, stdio: 'inherit'};require('child_process').spawn(cmd, toArray(args), opts).on('close', (code) => resolve(code))})")) systemWithStdIO__prim : String -> List String -> Int -> Int -> promise Int export never : Promise () never = promisify never__prim export reject : String -> Promise a reject err = promisify (reject__prim err) export log : String -> Promise () log text = promisify (log__prim text) export debugLog : String -> Promise () debugLog text = when DEBUG $ log text export system : String -> List String -> Maybe String -> Bool -> Bool -> Promise Int system cmd args cwd detached verbose = promisify (system__prim cmd args (fromMaybe "" cwd) (boolToInt detached) (boolToInt verbose)) export systemWithStdIO : String -> List String -> Bool -> Bool -> Promise Int systemWithStdIO cmd args detached verbose = promisify (systemWithStdIO__prim cmd args (boolToInt detached) (boolToInt verbose)) -- This is here and not in `Promise.idr` since it relies on `reject` export liftEither : Either String a -> Promise a liftEither x = do let Right res = x | Left err => reject err pure res
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Simon Hudon -/ import category_theory.monoidal.braided import category_theory.limits.shapes.binary_products import category_theory.limits.shapes.terminal /-! # The natural monoidal structure on any category with finite (co)products. A category with a monoidal structure provided in this way is sometimes called a (co)cartesian category, although this is also sometimes used to mean a finitely complete category. (See <https://ncatlab.org/nlab/show/cartesian+category>.) As this works with either products or coproducts, and sometimes we want to think of a different monoidal structure entirely, we don't set up either construct as an instance. ## Implementation We had previously chosen to rely on `has_terminal` and `has_binary_products` instead of `has_finite_products`, because we were later relying on the definitional form of the tensor product. Now that `has_limit` has been refactored to be a `Prop`, this issue is irrelevant and we could simplify the construction here. See `category_theory.monoidal.of_chosen_finite_products` for a variant of this construction which allows specifying a particular choice of terminal object and binary products. -/ universes v u noncomputable theory namespace category_theory variables (C : Type u) [category.{v} C] {X Y : C} open category_theory.limits section local attribute [tidy] tactic.case_bash /-- A category with a terminal object and binary products has a natural monoidal structure. -/ def monoidal_of_has_finite_products [has_terminal C] [has_binary_products C] : monoidal_category C := { tensor_unit := ⊤_ C, tensor_obj := λ X Y, X ⨯ Y, tensor_hom := λ _ _ _ _ f g, limits.prod.map f g, associator := prod.associator, left_unitor := λ P, prod.left_unitor P, right_unitor := λ P, prod.right_unitor P, pentagon' := prod.pentagon, triangle' := prod.triangle, associator_naturality' := @prod.associator_naturality _ _ _, } end section local attribute [instance] monoidal_of_has_finite_products open monoidal_category /-- The monoidal structure coming from finite products is symmetric. -/ @[simps] def symmetric_of_has_finite_products [has_terminal C] [has_binary_products C] : symmetric_category C := { braiding := λ X Y, limits.prod.braiding X Y, braiding_naturality' := λ X X' Y Y' f g, by { dsimp [tensor_hom], simp, }, hexagon_forward' := λ X Y Z, by { dsimp [monoidal_of_has_finite_products], simp }, hexagon_reverse' := λ X Y Z, by { dsimp [monoidal_of_has_finite_products], simp }, symmetry' := λ X Y, by { dsimp, simp, refl, }, } end namespace monoidal_of_has_finite_products variables [has_terminal C] [has_binary_products C] local attribute [instance] monoidal_of_has_finite_products @[simp] lemma tensor_obj (X Y : C) : X ⊗ Y = (X ⨯ Y) := rfl @[simp] lemma tensor_hom {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) : f ⊗ g = limits.prod.map f g := rfl @[simp] lemma left_unitor_hom (X : C) : (λ_ X).hom = limits.prod.snd := rfl @[simp] lemma left_unitor_inv (X : C) : (λ_ X).inv = prod.lift (terminal.from X) (𝟙 _) := rfl @[simp] lemma right_unitor_hom (X : C) : (ρ_ X).hom = limits.prod.fst := rfl @[simp] lemma right_unitor_inv (X : C) : (ρ_ X).inv = prod.lift (𝟙 _) (terminal.from X) := rfl -- We don't mark this as a simp lemma, even though in many particular -- categories the right hand side will simplify significantly further. -- For now, we'll plan to create specialised simp lemmas in each particular category. lemma associator_hom (X Y Z : C) : (α_ X Y Z).hom = prod.lift (limits.prod.fst ≫ limits.prod.fst) (prod.lift (limits.prod.fst ≫ limits.prod.snd) limits.prod.snd) := rfl end monoidal_of_has_finite_products section local attribute [tidy] tactic.case_bash /-- A category with an initial object and binary coproducts has a natural monoidal structure. -/ def monoidal_of_has_finite_coproducts [has_initial C] [has_binary_coproducts C] : monoidal_category C := { tensor_unit := ⊥_ C, tensor_obj := λ X Y, X ⨿ Y, tensor_hom := λ _ _ _ _ f g, limits.coprod.map f g, associator := coprod.associator, left_unitor := coprod.left_unitor, right_unitor := coprod.right_unitor, pentagon' := coprod.pentagon, triangle' := coprod.triangle, associator_naturality' := @coprod.associator_naturality _ _ _, } end section local attribute [instance] monoidal_of_has_finite_coproducts open monoidal_category /-- The monoidal structure coming from finite coproducts is symmetric. -/ @[simps] def symmetric_of_has_finite_coproducts [has_initial C] [has_binary_coproducts C] : symmetric_category C := { braiding := limits.coprod.braiding, braiding_naturality' := λ X X' Y Y' f g, by { dsimp [tensor_hom], simp, }, hexagon_forward' := λ X Y Z, by { dsimp [monoidal_of_has_finite_coproducts], simp }, hexagon_reverse' := λ X Y Z, by { dsimp [monoidal_of_has_finite_coproducts], simp }, symmetry' := λ X Y, by { dsimp, simp, refl, }, } end namespace monoidal_of_has_finite_coproducts variables [has_initial C] [has_binary_coproducts C] local attribute [instance] monoidal_of_has_finite_coproducts @[simp] lemma tensor_obj (X Y : C) : X ⊗ Y = (X ⨿ Y) := rfl @[simp] lemma tensor_hom {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) : f ⊗ g = limits.coprod.map f g := rfl @[simp] lemma left_unitor_hom (X : C) : (λ_ X).hom = coprod.desc (initial.to X) (𝟙 _) := rfl @[simp] lemma right_unitor_hom (X : C) : (ρ_ X).hom = coprod.desc (𝟙 _) (initial.to X) := rfl @[simp] lemma left_unitor_inv (X : C) : (λ_ X).inv = limits.coprod.inr := rfl @[simp] lemma right_unitor_inv (X : C) : (ρ_ X).inv = limits.coprod.inl := rfl -- We don't mark this as a simp lemma, even though in many particular -- categories the right hand side will simplify significantly further. -- For now, we'll plan to create specialised simp lemmas in each particular category. lemma associator_hom (X Y Z : C) : (α_ X Y Z).hom = coprod.desc (coprod.desc coprod.inl (coprod.inl ≫ coprod.inr)) (coprod.inr ≫ coprod.inr) := rfl end monoidal_of_has_finite_coproducts end category_theory
C Copyright(C) 1999-2020 National Technology & Engineering Solutions C of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with C NTESS, the U.S. Government retains certain rights in this software. C C See packages/seacas/LICENSE for details C======================================================================= SUBROUTINE EXFCON (IBLK, NUMELB, NUMLNK, LINK, ICONOD) C======================================================================= C --*** DBMIR1 *** (GEN3D) Fixup element connectivity for reflections C -- Written by Greg Sjaardema - revised 02/10/89 C -- Modified from DBOEB1 Written by Amy Gilkey C -- C --Parameters: C -- NUMELB - IN - the number of elements in the block C -- NUMLNK - IN - the number of nodes per element C -- LINK - IN - the element connectivity for this block C -- INTEGER NUMELB, NUMLNK INTEGER LINK(NUMLNK,*) INTEGER ICONOD(*) DO 20 NLNK = 1, NUMLNK DO 10 NE = 1, NUMELB INODE = LINK (NLNK, NE) ICONOD(INODE) = IBLK 10 CONTINUE 20 CONTINUE RETURN END
module Data.Surely %default total %access public export ||| A `Surely a` represents an input value. ||| It can be exactly the value `a`, ||| or anything which matches the type of `a`. ||| ||| It is similar to `Maybe a`, ||| except that `Anything` is equal to every exact value. ||| That means that `Semantics.inputs` can produce `Change` inputs ||| without specifying a specific input value. data Surely a = Exactly a | Anything toMaybe : Surely a -> Maybe a toMaybe (Exactly x) = Just x toMaybe (Anything) = Nothing toSurely : Maybe a -> Surely a toSurely (Just x) = Exactly x toSurely (Nothing) = Anything Eq a => Eq (Surely a) where (Exactly x) == (Exactly y) = x == y (Anything) == (Exactly _) = True (Exactly _) == (Anything) = True (Anything) == (Anything) = True
-- Based on https://www.iana.org/assignments/http-status-codes/http-status-codes.txt module Network.HTTP.Status import Data.Nat import Generics.Derive %language ElabReflection public export record StatusCodeNumber (n : Nat) where constructor Abv100Und600 lte599 : LTE n 599 gte100 : GTE n 100 export is_status_code_number : (n : Nat) -> Dec (StatusCodeNumber n) is_status_code_number n = case isLTE n 599 of Yes ok1 => case isGTE n 100 of Yes ok2 => Yes (Abv100Und600 ok1 ok2) No nope => No (nope . gte100) No nope => No (nope . lte599) public export data StatusCodeClass : Type where Information : StatusCodeClass Successful : StatusCodeClass Redirection : StatusCodeClass ClientError : StatusCodeClass ServerError : StatusCodeClass %runElab derive "StatusCodeClass" [Generic, Meta, Eq, Show] public export data StatusCode : Nat -> Type where Continue : StatusCode 100 SwitchingProtocols : StatusCode 101 Processing : StatusCode 102 EarlyHints : StatusCode 103 OK : StatusCode 200 Created : StatusCode 201 Accepted : StatusCode 202 NonAuthoritativeInformation : StatusCode 203 NoContent : StatusCode 204 ResetContent : StatusCode 205 PartialContent : StatusCode 206 MultiStatus : StatusCode 207 AlreadyReported : StatusCode 208 IMUsed : StatusCode 226 MultipleChoices : StatusCode 300 MovedPermanently : StatusCode 301 Found : StatusCode 302 SeeOther : StatusCode 303 NotModified : StatusCode 304 UseProxy : StatusCode 305 TemporaryRedirect : StatusCode 307 PermanentRedirect : StatusCode 308 Unauthorized : StatusCode 401 PaymentRequired : StatusCode 402 Forbidden : StatusCode 403 NotFound : StatusCode 404 MethodNotAllowed : StatusCode 405 NotAcceptable : StatusCode 406 ProxyAuthenticationRequired : StatusCode 407 RequestTimeout : StatusCode 408 Conflict : StatusCode 409 Gone : StatusCode 410 LengthRequired : StatusCode 411 PreconditionFailed : StatusCode 412 ContentTooLarge : StatusCode 413 URITooLong : StatusCode 414 UnsupportedMediaType : StatusCode 415 RangeNotSatisfiable : StatusCode 416 ExpectationFailed : StatusCode 417 MisdirectedRequest : StatusCode 421 UnprocessableContent : StatusCode 422 Locked : StatusCode 423 FailedDependency : StatusCode 424 TooEarly : StatusCode 425 UpgradeRequired : StatusCode 426 PreconditionRequired : StatusCode 428 TooManyRequests : StatusCode 429 RequestHeaderFieldsTooLarge : StatusCode 431 UnavailableForLegalReasons : StatusCode 451 InternalServerError : StatusCode 500 NotImplemented : StatusCode 501 BadGateway : StatusCode 502 ServiceUnavailable : StatusCode 503 GatewayTimeout : StatusCode 504 HTTPVersionNotSupported : StatusCode 505 VariantAlsoNegotiates : StatusCode 506 InsufficientStorage : StatusCode 507 LoopDetected : StatusCode 508 NetworkAuthenticationRequired : StatusCode 511 UnknownStatusCode : (n : Nat) -> StatusCodeNumber n -> StatusCode n export Show (StatusCode n) where show Continue = "Continue" show SwitchingProtocols = "SwitchingProtocols" show Processing = "Processing" show EarlyHints = "EarlyHints" show OK = "OK" show Created = "Created" show Accepted = "Accepted" show NonAuthoritativeInformation = "NonAuthoritativeInformation" show NoContent = "NoContent" show ResetContent = "ResetContent" show PartialContent = "PartialContent" show MultiStatus = "MultiStatus" show AlreadyReported = "AlreadyReported" show IMUsed = "IMUsed" show MultipleChoices = "MultipleChoices" show MovedPermanently = "MovedPermanently" show Found = "Found" show SeeOther = "SeeOther" show NotModified = "NotModified" show UseProxy = "UseProxy" show TemporaryRedirect = "TemporaryRedirect" show PermanentRedirect = "PermanentRedirect" show Unauthorized = "Unauthorized" show PaymentRequired = "PaymentRequired" show Forbidden = "Forbidden" show NotFound = "NotFound" show MethodNotAllowed = "MethodNotAllowed" show NotAcceptable = "NotAcceptable" show ProxyAuthenticationRequired = "ProxyAuthenticationRequired" show RequestTimeout = "RequestTimeout" show Conflict = "Conflict" show Gone = "Gone" show LengthRequired = "LengthRequired" show PreconditionFailed = "PreconditionFailed" show ContentTooLarge = "ContentTooLarge" show URITooLong = "URITooLong" show UnsupportedMediaType = "UnsupportedMediaType" show RangeNotSatisfiable = "RangeNotSatisfiable" show ExpectationFailed = "ExpectationFailed" show MisdirectedRequest = "MisdirectedRequest" show UnprocessableContent = "UnprocessableContent" show Locked = "Locked" show FailedDependency = "FailedDependency" show TooEarly = "TooEarly" show UpgradeRequired = "UpgradeRequired" show PreconditionRequired = "PreconditionRequired" show TooManyRequests = "TooManyRequests" show RequestHeaderFieldsTooLarge = "RequestHeaderFieldsTooLarge" show UnavailableForLegalReasons = "UnavailableForLegalReasons" show InternalServerError = "InternalServerError" show NotImplemented = "NotImplemented" show BadGateway = "BadGateway" show ServiceUnavailable = "ServiceUnavailable" show GatewayTimeout = "GatewayTimeout" show HTTPVersionNotSupported = "HTTPVersionNotSupported" show VariantAlsoNegotiates = "VariantAlsoNegotiates" show InsufficientStorage = "InsufficientStorage" show LoopDetected = "LoopDetected" show NetworkAuthenticationRequired = "NetworkAuthenticationRequired" show (UnknownStatusCode n _) = "Unknown (" <+> show n <+> ")" export status_code_to_nat : {n : Nat} -> StatusCode n -> Nat status_code_to_nat _ = n export nat_to_status_code : (n : Nat) -> (prf : StatusCodeNumber n) -> StatusCode n nat_to_status_code 100 _ = Continue nat_to_status_code 101 _ = SwitchingProtocols nat_to_status_code 102 _ = Processing nat_to_status_code 103 _ = EarlyHints nat_to_status_code 200 _ = OK nat_to_status_code 201 _ = Created nat_to_status_code 202 _ = Accepted nat_to_status_code 203 _ = NonAuthoritativeInformation nat_to_status_code 204 _ = NoContent nat_to_status_code 205 _ = ResetContent nat_to_status_code 206 _ = PartialContent nat_to_status_code 207 _ = MultiStatus nat_to_status_code 208 _ = AlreadyReported nat_to_status_code 226 _ = IMUsed nat_to_status_code 300 _ = MultipleChoices nat_to_status_code 301 _ = MovedPermanently nat_to_status_code 302 _ = Found nat_to_status_code 303 _ = SeeOther nat_to_status_code 304 _ = NotModified nat_to_status_code 305 _ = UseProxy nat_to_status_code 307 _ = TemporaryRedirect nat_to_status_code 308 _ = PermanentRedirect nat_to_status_code 401 _ = Unauthorized nat_to_status_code 402 _ = PaymentRequired nat_to_status_code 403 _ = Forbidden nat_to_status_code 404 _ = NotFound nat_to_status_code 405 _ = MethodNotAllowed nat_to_status_code 406 _ = NotAcceptable nat_to_status_code 407 _ = ProxyAuthenticationRequired nat_to_status_code 408 _ = RequestTimeout nat_to_status_code 409 _ = Conflict nat_to_status_code 410 _ = Gone nat_to_status_code 411 _ = LengthRequired nat_to_status_code 412 _ = PreconditionFailed nat_to_status_code 413 _ = ContentTooLarge nat_to_status_code 414 _ = URITooLong nat_to_status_code 415 _ = UnsupportedMediaType nat_to_status_code 416 _ = RangeNotSatisfiable nat_to_status_code 417 _ = ExpectationFailed nat_to_status_code 421 _ = MisdirectedRequest nat_to_status_code 422 _ = UnprocessableContent nat_to_status_code 423 _ = Locked nat_to_status_code 424 _ = FailedDependency nat_to_status_code 425 _ = TooEarly nat_to_status_code 426 _ = UpgradeRequired nat_to_status_code 428 _ = PreconditionRequired nat_to_status_code 429 _ = TooManyRequests nat_to_status_code 431 _ = RequestHeaderFieldsTooLarge nat_to_status_code 451 _ = UnavailableForLegalReasons nat_to_status_code 500 _ = InternalServerError nat_to_status_code 501 _ = NotImplemented nat_to_status_code 502 _ = BadGateway nat_to_status_code 503 _ = ServiceUnavailable nat_to_status_code 504 _ = GatewayTimeout nat_to_status_code 505 _ = HTTPVersionNotSupported nat_to_status_code 506 _ = VariantAlsoNegotiates nat_to_status_code 507 _ = InsufficientStorage nat_to_status_code 508 _ = LoopDetected nat_to_status_code 511 _ = NetworkAuthenticationRequired nat_to_status_code n prf = UnknownStatusCode n prf export status_code_class : {n : Nat} -> StatusCode n -> StatusCodeClass status_code_class code = case (status_code_to_nat code) `div` 100 of 1 => Information 2 => Successful 3 => Redirection 4 => ClientError _ => ServerError
[STATEMENT] lemma oldDefs_correct: "defs g n = var g ` defs' g n" [PROOF STATE] proof (prove) goal (1 subgoal): 1. defs g n = var g ` defs' g n [PROOF STEP] by (simp add:defs'_def image_image)
[GOAL] α : Type u inst✝² : Group α inst✝¹ : LE α inst✝ : CovariantClass α α (swap fun x x_1 => x * x_1) fun x x_1 => x ≤ x_1 a✝ b c d a : α ⊢ symm (mulRight a) = mulRight a⁻¹ [PROOFSTEP] ext x [GOAL] case h.h α : Type u inst✝² : Group α inst✝¹ : LE α inst✝ : CovariantClass α α (swap fun x x_1 => x * x_1) fun x x_1 => x ≤ x_1 a✝ b c d a x : α ⊢ ↑(symm (mulRight a)) x = ↑(mulRight a⁻¹) x [PROOFSTEP] rfl [GOAL] α : Type u inst✝² : Group α inst✝¹ : LE α inst✝ : CovariantClass α α (fun x x_1 => x * x_1) fun x x_1 => x ≤ x_1 a : α ⊢ symm (mulLeft a) = mulLeft a⁻¹ [PROOFSTEP] ext x [GOAL] case h.h α : Type u inst✝² : Group α inst✝¹ : LE α inst✝ : CovariantClass α α (fun x x_1 => x * x_1) fun x x_1 => x ≤ x_1 a x : α ⊢ ↑(symm (mulLeft a)) x = ↑(mulLeft a⁻¹) x [PROOFSTEP] rfl
#pragma once #include <tl/expected.hpp> #include <boost/optional.hpp> namespace expected_task { template <class Value, class Error> tl::expected<Value, Error> from_optional(boost::optional<Value> value, Error&& error) { if(value) return tl::expected<Value, Error>{std::forward<Value>(*value)}; else return tl::make_unexpected(std::forward<Error>(error)); } } // namespace expected_task
(* Title: HOL/Auth/n_germanSimp_lemma_on_inv__18.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_germanSimp Protocol Case Study*} theory n_germanSimp_lemma_on_inv__18 imports n_germanSimp_base begin section{*All lemmas on causal relation between inv__18 and some rule r*} lemma n_SendInv__part__0Vsinv__18: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__18 p__Inv4)" 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__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__18 p__Inv4" apply fastforce done have "(i=p__Inv4)\<or>(i~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (andForm (andForm (eqn (IVar (Ident ''ExGntd'')) (Const true)) (neg (eqn (IVar (Field (Para (Ident ''Cache'') p__Inv4) ''State'')) (Const E)))) (eqn (IVar (Field (Para (Ident ''Chan2'') p__Inv4) ''Cmd'')) (Const Empty))) (eqn (IVar (Para (Ident ''InvSet'') p__Inv4)) (Const true))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv4)" 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__18: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__18 p__Inv4)" 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__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__18 p__Inv4" apply fastforce done have "(i=p__Inv4)\<or>(i~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (andForm (andForm (eqn (IVar (Ident ''ExGntd'')) (Const true)) (neg (eqn (IVar (Field (Para (Ident ''Cache'') p__Inv4) ''State'')) (Const E)))) (eqn (IVar (Field (Para (Ident ''Chan2'') p__Inv4) ''Cmd'')) (Const Empty))) (eqn (IVar (Para (Ident ''InvSet'') p__Inv4)) (Const true))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv4)" 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_SendInvAckVsinv__18: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__18 p__Inv4)" 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__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__18 p__Inv4" apply fastforce done have "(i=p__Inv4)\<or>(i~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv4)" 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__Inv4)" 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__18: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__18 p__Inv4)" 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__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__18 p__Inv4" apply fastforce done have "(i=p__Inv4)\<or>(i~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv4)" 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 b1 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 "?P2 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } moreover { assume b1: "(i~=p__Inv4)" 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 b1 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 "?P2 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendGntSVsinv__18: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendGntS i)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__18 p__Inv4)" 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__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__18 p__Inv4" apply fastforce done have "(i=p__Inv4)\<or>(i~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv4)" 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__Inv4)" 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__18: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendGntE N i)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__18 p__Inv4)" 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__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__18 p__Inv4" apply fastforce done have "(i=p__Inv4)\<or>(i~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv4)" 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__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Chan2'') p__Inv4) ''Cmd'')) (Const Inv)) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv4)) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_RecvGntSVsinv__18: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntS i)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__18 p__Inv4)" 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__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__18 p__Inv4" apply fastforce done have "(i=p__Inv4)\<or>(i~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv4)" 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__Inv4)" 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__18: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__18 p__Inv4)" 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__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__18 p__Inv4" apply fastforce done have "(i=p__Inv4)\<or>(i~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv4)" 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__Inv4)" 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_StoreVsinv__18: assumes a1: "\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__18 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_RecvReqE__part__0Vsinv__18: assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvReqE__part__0 N i" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__18 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_RecvReqE__part__1Vsinv__18: assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvReqE__part__1 N i" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__18 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_RecvReqSVsinv__18: assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvReqS N i" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__18 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done end
Complex Laplacian Eigenmodes --- Find the highest spatial corelation values achieved by the best performing eigenmodes for each canonical network: ```python import numpy as np import pandas as pd import matplotlib.pyplot as plt # spectrome imports from spectrome.brain import Brain from spectrome.utils import functions, path from spectrome.forward import eigenmode, runforward ``` ```python # Some house keeping: data_dir = "../data" # Define frequency range of interest fmin = 2 # 2Hz - 45Hz signal range, filter for this with hbp fmax = 45 fvec = np.linspace(fmin, fmax, 40) # Load Pablo's Yeo 2017 canonical network maps fc_dk = np.load("../data/com_dk.npy", allow_pickle=True).item() fc_dk_normalized = pd.read_csv("../data/DK_dictionary_normalized.csv").set_index( "Unnamed: 0" ) # Define variables for analysis: alpha_vec = np.linspace( 0.5, 4.5, 17 ) # np.linspace(0.5,5,10) # coupling strength values we are going to explore #alpha_vec = np.linspace(0.1, 1.5, 15) k_vec = np.linspace(0, 100, 11) # wave numbers we are going to explore num_fc = 7 # 7 canonical networks num_emode = 86 # number of eigenmodes, we are using 86 region DK atlas default_k = 20 # default wave number default_alpha = 0.1 # default alpha # define list of canonical network names and re-order the dictionary using these names: fc_names = [ "Limbic", "Default", "Visual", "Fronto \n parietal", "Somato \n motor", "Dorsal \n Attention", "Ventral \n Attention", ] fc_dk_normalized = fc_dk_normalized.reindex( [ "Limbic", "Default", "Visual", "Frontoparietal", "Somatomotor", "Dorsal_Attention", "Ventral_Attention", ] ).fillna(0) # turbo color map turbo = functions.create_turbo_colormap() ``` Compute Spearman correlation values: ```python # pre-allocate an array for spearman R of best performing eigenmodes: params_bestr = np.zeros((len(alpha_vec), len(k_vec), num_fc)) # Create brain object from spectrome with HCP connectome: hcp_brain = Brain.Brain() hcp_brain.add_connectome(data_dir) hcp_brain.reorder_connectome(hcp_brain.connectome, hcp_brain.distance_matrix) hcp_brain.bi_symmetric_c() hcp_brain.reduce_extreme_dir() # for each network, scan through alpha and k values, compute all eigenmode's spearman R # then select the best performing eigenmode's spearman R for i in np.arange(0, num_fc): print('Computing for {} network'.format(fc_dk_normalized.index[i])) for a_ind in np.arange(0, len(alpha_vec)): for k_ind in np.arange(0, len(k_vec)): # get eigenmodes of complex laplacian: hcp_brain.decompose_complex_laplacian(alpha = alpha_vec[a_ind], k = k_vec[k_ind]) # compute spearman correlation spearman_eig = eigenmode.get_correlation_df( hcp_brain.norm_eigenmodes, fc_dk_normalized.iloc[[i]], method = 'spearman' ) params_bestr[a_ind, k_ind, i] = np.max(spearman_eig.values) ``` Computing for Limbic network Computing for Default network Computing for Visual network Computing for Frontoparietal network Computing for Somatomotor network Computing for Dorsal_Attention network Computing for Ventral_Attention network Visualize in heatmap: ```python dynamic_range = [0.30, 0.70] k_ticks = 11 k_labels = np.linspace(0, 100, 11).astype(int) a_ticks = 3 a_labels = np.linspace(0.5, 4.5, 3) with plt.style.context("seaborn-paper"): corr_fig, corr_ax = plt.subplots(1,7, figsize = (8,5), sharey=True) for i, ax in enumerate(corr_fig.axes): im = ax.imshow(np.transpose(params_bestr[:,:,i]), vmin = 0, vmax = 1, cmap = turbo, aspect = 'auto') ax.yaxis.set_major_locator(plt.LinearLocator(numticks = k_ticks)) ax.xaxis.tick_top() ax.set_yticklabels(k_labels) ax.xaxis.set_major_locator(plt.LinearLocator(numticks = a_ticks)) ax.set_xticklabels(a_labels) im.set_clim(dynamic_range) if i < 3: ax.set_title(fc_names[i], y=-0.08, fontsize=8, weight="bold") else: ax.set_title(fc_names[i], y=-0.12, fontsize=8, weight="bold") plt.suptitle('Coupling Strength', fontsize = 12, y = 1.02) cbar_ax = corr_fig.add_axes([1, 0.15, 0.03, 0.7]) cb = corr_fig.colorbar(im, cax=cbar_ax, extend="both") corr_fig.text(-0.008, 0.35, 'Wave Number', rotation='vertical', fontsize=12) #corr_fig.add_subplot(1, 1, 1, frameon=False) #plt.tick_params(labelcolor="none", top="off", bottom="off", left="off", right="off") #plt.grid(False) #plt.ylabel('Wave Number', fontsize = 12) plt.tight_layout() plt.savefig('../figures/supp/param_bestr.png', dpi = 300, bbox_inches = 'tight') ``` Note - global coupling doesn't affect the best performing eigenmode but may change which eigenmode is the best performing eigenmode as well as the other eigenmodes. Split the wave number parameter into oscillatory frequency and signal transmission velocity since wave number $k$ is defined as $k = \frac{2 \pi f}{\nu}$. Then perform the same exploratory exercise as above: ```python # define parameter ranges: freq_vec = np.linspace(2, 47, 46) nu_vec = np.linspace(1, 20, 21) # define plotting visuals dynamic_range = [0.3, 0.7] f_ticks = 6 f_labels = np.linspace(2, 47, 6).astype(int) nu_ticks = 3 nu_labels = np.linspace(0.5, 20, 3).astype(int) #pre-allocate array for results k_bestr = np.zeros((len(freq_vec), len(nu_vec), num_fc)) # compute spearman Rs: for i in np.arange(0, num_fc): print('Computing for {} network'.format(fc_dk_normalized.index[i])) for f_ind in np.arange(0, len(freq_vec)): for v_ind in np.arange(0, len(nu_vec)): # get eigenmodes of complex laplacian: hcp_brain.decompose_complex_laplacian(alpha = default_alpha, k = None, f = freq_vec[f_ind], speed = nu_vec[v_ind]) # compute spearman correlation spearman_eig = eigenmode.get_correlation_df( hcp_brain.norm_eigenmodes, fc_dk_normalized.iloc[[i]], method = 'spearman' ) k_bestr[f_ind, v_ind, i] = np.max(spearman_eig.values) ``` ```python # Plot as above: with plt.style.context("seaborn-paper"): k_fig, k_ax = plt.subplots(1,7, figsize = (8,4),sharey=True) for i, ax in enumerate(k_fig.axes): im = ax.imshow(k_bestr[:,:,i], vmin = 0, vmax = 1, cmap = turbo, aspect = 'auto') ax.yaxis.set_major_locator(plt.LinearLocator(numticks = f_ticks)) ax.xaxis.tick_top() ax.set_yticklabels(f_labels) ax.xaxis.set_major_locator(plt.LinearLocator(numticks = nu_ticks)) ax.set_xticklabels(nu_labels) im.set_clim(dynamic_range) if i < 3: ax.set_title(fc_names[i], y=-0.08, fontsize=8, weight="bold") else: ax.set_title(fc_names[i], y=-0.12, fontsize=8, weight="bold") plt.suptitle('Transmission Velocity (m/s)', fontsize = 12, y = 1.02) k_fig.text(-0.008, 0.35, 'Frequency (Hz)', rotation='vertical', fontsize=12) #cbar_ax = k_fig.add_axes([1, 0.15, 0.03, 0.7]) #cb = k_fig.colorbar(im, cax=cbar_ax, extend="both") #k_fig.add_subplot(1, 1, 1, frameon=False) #plt.tick_params(labelcolor="none", top="off", bottom="off", left="off", right="off") #plt.grid(False) #plt.ylabel('Frequency (Hz)', fontsize = 12) plt.tight_layout() plt.savefig('../figures/supp/k_bestr.png', dpi = 300, bbox_inches = 'tight') ``` Entropy --- We want to see the entropy for all the Spearman correlation values computed with each parameter combination. The information entropy metric is defined as: \begin{equation} S = - \sum_{i} \pmb{P}_i log \pmb{P}_i \end{equation} Entropy is generally viewed as the uncertainty when making a prediction based on available information. In the case of high entropy, we know the information we have is highly diverse and it is difficult to make any predictions. So we want to look for parameter values providing low entropy, or high fidelity. ```python from scipy.stats import entropy params_entropy = np.zeros((len(alpha_vec), len(k_vec), num_fc)) # using the same parameter values as above for i in np.arange(0, num_fc): print('Computing for {} network'.format(fc_dk_normalized.index[i])) for a_ind in np.arange(0, len(alpha_vec)): for k_ind in np.arange(0, len(k_vec)): # get eigenmodes of complex laplacian: hcp_brain.decompose_complex_laplacian(alpha = alpha_vec[a_ind], k = k_vec[k_ind]) # compute spearman correlation spearman_eig = eigenmode.get_correlation_df( hcp_brain.norm_eigenmodes, fc_dk_normalized.iloc[[i]], method = 'spearman' ) # Create distribution of eigenmode spearman Rs with consistent bins, and turn into probability distribution prob_dist, _ = np.histogram(spearman_eig.values.astype(np.float64), bins = 40, range = (-0.5, 0.8), density = True) #print(np.squeeze(np.asarray(spearman_eig.values))) params_entropy[a_ind, k_ind, i] = entropy(prob_dist, base = 2) ``` Computing for Limbic network Computing for Default network Computing for Visual network Computing for Frontoparietal network Computing for Somatomotor network Computing for Dorsal_Attention network Computing for Ventral_Attention network ```python #entropy_range = [3.3, 3.7] # plot like before: with plt.style.context("seaborn-paper"): corr_fig, corr_ax = plt.subplots(1,7, figsize = (8,4)) for i, ax in enumerate(corr_fig.axes): im = ax.imshow(np.transpose(params_entropy[:,:,i]), cmap = turbo, aspect = 'auto') ax.yaxis.set_major_locator(plt.LinearLocator(numticks = k_ticks)) ax.xaxis.tick_top() ax.set_yticklabels(k_labels) ax.xaxis.set_major_locator(plt.LinearLocator(numticks = a_ticks)) ax.set_xticklabels(a_labels) #im.set_clim(entropy_range) if i < 3: ax.set_title(fc_names[i], y=-0.08, fontsize=8, weight="bold") else: ax.set_title(fc_names[i], y=-0.12, fontsize=8, weight="bold") plt.suptitle('Coupling Strength', fontsize = 12, y = 1) cbar_ax = corr_fig.add_axes([1, 0.15, 0.03, 0.7]) cb = corr_fig.colorbar(im, cax=cbar_ax, extend="both") corr_fig.add_subplot(1, 1, 1, frameon=False) plt.tick_params(labelcolor="none", top="off", bottom="off", left="off", right="off") plt.grid(False) plt.ylabel('Wave Number', fontsize = 12) plt.tight_layout() ```
Thank you for visiting at this website. Listed below is a fantastic graphic for Kristi Will Home Design Facebook. We have been searching for this image through on-line and it came from trustworthy resource. If youre searching for any new fresh plan for your own home then the Kristi Will Home Design Facebook image needs to be on top of resource or you might use it for an alternative concept. This picture has been published by admin tagged in category field. And we also trust it can be the most well liked vote in google vote or event in facebook share. Hopefully you like it as we do. If possible share this Kristi Will Home Design Facebook image to your mates, family through google plus, facebook, twitter, instagram or any other social media site.
[STATEMENT] lemma (in landau_symbol) of_real_cancel: "(\<lambda>x. of_real (f x)) \<in> L F (\<lambda>x. of_real (g x)) \<Longrightarrow> f \<in> Lr F g" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<lambda>x. of_real (f x)) \<in> L F (\<lambda>x. of_real (g x)) \<Longrightarrow> f \<in> Lr F g [PROOF STEP] by (subst (asm) norm_iff [symmetric], subst (asm) (1 2) norm_of_real) simp_all
rm(list=ls()) devtools::load_all() # # algae # my_dataset <- read_data( # id = "neon.ecocomdp.20166.001.001", # site = c('COMO','SUGG'), # startdate = "2017-06", # enddate = "2019-09", # token = Sys.getenv("NEON_TOKEN"), # check.size = FALSE) # macroinverts my_dataset <- read_data( id = "neon.ecocomdp.20120.001.001", site= c('COMO','LECO','SUGG'), startdate = "2017-06", enddate = "2019-09", token = Sys.getenv("NEON_TOKEN"), check.size = FALSE) # detecting data types ecocomDP:::detect_data_type(ants_L1) ecocomDP:::detect_data_type(ants_L1) ecocomDP:::detect_data_type(ants_L1$tables) ecocomDP:::detect_data_type(ants_L1$tables$observation) ecocomDP:::detect_data_type(list(a = ants_L1, b = ants_L1)) ecocomDP:::detect_data_type(list(a = ants_L1, b = ants_L1)) ecocomDP:::detect_data_type(my_dataset) ecocomDP:::detect_data_type(my_dataset) ecocomDP:::detect_data_type(my_dataset$tables) ecocomDP:::detect_data_type(my_dataset$tables$observation) ecocomDP:::detect_data_type(list(a = my_dataset, b = my_dataset)) ecocomDP:::detect_data_type(list(a = my_dataset, b = my_dataset)) # error out with informative message ecocomDP:::detect_data_type(ants_L1$metadata) ecocomDP:::detect_data_type(my_dataset$metadata) ecocomDP:::detect_data_type(list(a="a")) # this detects "list_of_datasets" -- might want to improve logic in the future? ecocomDP:::detect_data_type(list(a = ants_L1, b = ants_L1)) # test new flatten with autodetect flat <- flatten_data(ants_L1) flat <- flatten_data(ants_L1) flat <- flatten_data(ants_L1$tables) flat <- flatten_data(my_dataset) flat <- flatten_data(my_dataset) flat <- flatten_data(my_dataset$tables) # should error with message flat <- flatten_data(ants_L1$validation_issues) flat <- flatten_data(my_dataset$validation_issues) ######################################################### ########################################################### # accum by site plot_taxa_accum_sites(my_dataset) plot_taxa_accum_sites( data = my_dataset %>% flatten_data()) ########################################################### # plot ecocomDP dataset plot_taxa_accum_sites(ants_L1) # plot flattened ecocomDP data plot_taxa_accum_sites(flatten_data(ants_L1)) # plot an ecocomDP observation table plot_taxa_accum_sites( data = ants_L1$tables$observation) # tidy syntax ants_L1 %>% plot_taxa_accum_sites() # tidy syntax, filter data by date ants_L1 %>% flatten_data() %>% dplyr::filter( lubridate::as_date(datetime) > "2003-07-01") %>% plot_taxa_accum_sites() ########################################################### ########################################################### ########################################################### ########################################################### # accum by time # looks weird for SUGG for macroinvert dataset using both methods plot_taxa_accum_time( data = my_dataset) plot_taxa_accum_time( data = my_dataset$tables$observation, id = my_dataset$id) plot_taxa_accum_time( data = my_dataset %>% flatten_data()) ########################################################### # plot ecocomDP formatted dataset plot_taxa_accum_time( data = ants_L1) # plot flattened ecocomDP dataset plot_taxa_accum_time( data = flatten_data(ants_L1)) # plot ecocomDP observation table plot_taxa_accum_time( data = ants_L1$tables$observation) # tidy syntax, filter data by date ants_L1 %>% flatten_data() %>% dplyr::filter( lubridate::as_date(datetime) > "2003-07-01") %>% plot_taxa_accum_time() ########################################################### ########################################################### ########################################################### ########################################################### # richness by time # this is also messed up for macroinverts -- COMO is weird # RENAME from "plot_taxa_diversity" to "plot_richness_time" plot_taxa_diversity( data = my_dataset$tables$observation, id = my_dataset$id) plot_taxa_diversity( data = my_dataset) plot_taxa_diversity( data = my_dataset, time_window_size = "year") plot_taxa_diversity( data = my_dataset, time_window_size = "month") plot_taxa_diversity( data = my_dataset, time_window_size = "day") plot_taxa_diversity( data = my_dataset %>% flatten_data(), time_window_size = "year") plot_taxa_diversity( data = my_dataset %>% flatten_data(), time_window_size = "month") my_dataset %>% plot_taxa_diversity() my_dataset %>% flatten_data() %>% dplyr::filter(grepl("^SUGG",location_id)) %>% plot_taxa_diversity() my_dataset %>% flatten_data() %>% dplyr::filter(grepl("^SUGG",location_id)) %>% plot_taxa_diversity(time_window_size = "day") my_dataset %>% flatten_data() %>% dplyr::filter(grepl("^SUGG",location_id)) %>% plot_taxa_diversity(time_window_size = "month") my_dataset %>% flatten_data() %>% dplyr::filter(grepl("^SUGG",location_id)) %>% plot_taxa_diversity(time_window_size = "year") ########################################################### # plot richness through time for ecocomDP formatted dataset by # observation date plot_taxa_diversity(ants_L1) # plot richness through time for ecocomDP formatted dataset by # aggregating observations within a year plot_taxa_diversity( data = ants_L1, time_window_size = "year") # plot richness through time for ecocomDP observation table plot_taxa_diversity(ants_L1$tables$observation) # plot richness through time for flattened ecocomDP dataset plot_taxa_diversity(flatten_data(ants_L1)) # Using Tidy syntax: # plot ecocomDP formatted dataset richness through time by # observation date ants_L1 %>% plot_taxa_diversity() ants_L1 %>% plot_taxa_diversity(time_window_size = "day") # plot ecocomDP formatted dataset richness through time # aggregating observations within a month ants_L1 %>% plot_taxa_diversity(time_window_size = "month") # plot ecocomDP formatted dataset richness through time # aggregating observations within a year ants_L1 %>% plot_taxa_diversity(time_window_size = "year") # tidy syntax, filter data by date ants_L1 %>% flatten_data() %>% dplyr::filter( lubridate::as_date(datetime) > "2007-01-01") %>% plot_taxa_diversity( time_window_size = "year") ########################################################### ########################################################### ########################################################### ########################################################### # sample coverage by site and time # RENAME plot_sample_space_time( data = my_dataset$tables$observation, id = my_dataset$id) plot_sample_space_time( data = my_dataset) plot_sample_space_time( data = my_dataset %>% flatten_data()) plot_sample_space_time( data = my_dataset$tables$observation, id = names(my_dataset)) plot_sample_space_time( data = ants_L1) my_dataset %>% plot_sample_space_time() # filter location id my_dataset %>% flatten_data() %>% dplyr::filter(grepl("SUGG",location_id)) %>% plot_sample_space_time() ########################################################### # plot ecocomDP formatted dataset plot_sample_space_time(ants_L1) # plot flattened ecocomDP dataset plot_sample_space_time(flatten_data(ants_L1)) # plot ecocomDP observation table plot_sample_space_time(ants_L1$tables$observation) # tidy syntax, filter data by date ants_L1 %>% flatten_data() %>% dplyr::filter( lubridate::as_date(datetime) > "2003-07-01") %>% plot_sample_space_time() # tidy syntax, filter data by site ID ants_L1 %>% flatten_data() %>% dplyr::filter( as.numeric(location_id) > 4) %>% plot_sample_space_time() ########################################################### ########################################################### ########################################################### ########################################################### # plot shared taxa across sites -- this seems to work fine my_dataset <- read_data( id = "neon.ecocomdp.20120.001.001", site= c('COMO','LECO'), startdate = "2017-06", enddate = "2019-09", token = Sys.getenv("NEON_TOKEN"), check.size = FALSE) plot_taxa_shared_sites( data = my_dataset$tables$observation, id = my_dataset$id) plot_taxa_shared_sites( data = my_dataset) plot_taxa_shared_sites( data = ants_L1$tables$observation, id = ants_L1$id) plot_taxa_shared_sites( data = ants_L1) neon_data <- ecocomDP::read_data( id = "neon.ecocomdp.20120.001.001", site = c('ARIK','CARI','MAYF')) plot_taxa_shared_sites(neon_data) ########################################################### # plot ecocomDP formatted dataset plot_taxa_shared_sites(ants_L1) # plot flattened ecocomDP dataset plot_taxa_shared_sites(flatten_data(ants_L1)) # plot ecocomDP observation table plot_taxa_shared_sites(ants_L1$tables$observation) # tidy syntax, filter data by date ants_L1 %>% flatten_data() %>% dplyr::filter( lubridate::as_date(datetime) > "2003-07-01") %>% plot_taxa_shared_sites() # tidy syntax, filter data by site ID ants_L1 %>% flatten_data() %>% dplyr::filter( as.numeric(location_id) > 4) %>% plot_taxa_shared_sites() ########################################################### ########################################################### ########################################################### # plot rank frequencies # this is in taxon table... should we make an option to plot frequencies in the actual data? plot_taxa_rank( data = my_dataset) plot_taxa_rank( data = my_dataset, facet_var = "location_id") #e.g., "location_id", "datetime" must be a column name in observation or taxon table plot_taxa_rank( data = my_dataset, facet_var = "datetime") #e.g., "location_id", "datetime" must be a column name in observation or taxon table plot_taxa_rank( data = ants_L1, facet_var = "datetime") ########################################################### # plot ecocomDP formatted dataset plot_taxa_rank(ants_L1) # download and plot NEON macroinvertebrate data my_dataset <- read_data( id = "neon.ecocomdp.20120.001.001", site= c('COMO','LECO'), startdate = "2017-06", enddate = "2019-09", check.size = FALSE) plot_taxa_rank(my_dataset) # facet by location plot_taxa_rank( data = my_dataset, facet_var = "location_id") # plot flattened ecocomDP dataset plot_taxa_rank( data = flatten_data(my_dataset), facet_var = "location_id") # tidy syntax, filter data by date my_dataset %>% flatten_data() %>% dplyr::filter( lubridate::as_date(datetime) > "2003-07-01") %>% plot_taxa_rank() # tidy syntax, filter data by site ID my_dataset %>% flatten_data() %>% dplyr::filter( grepl("COMO",location_id)) %>% plot_taxa_rank() ########################################################### ########################################################### ########################################################### # Plot stacked taxa by site plot_taxa_occur_freq( data = my_dataset, facet_var = "location_id", color = "location_id", min_occurrence = 5) plot_taxa_occur_freq( data = my_dataset, facet_var = "location_id", min_occurrence = 30) # different ways to make the same plot plot_taxa_occur_freq( data = my_dataset) plot_taxa_occur_freq( data = my_dataset %>% flatten_data()) plot_taxa_occur_freq( data = my_dataset$tables %>% flatten_tables()) ########################################################### # plot ecocomDP formatted dataset plot_taxa_occur_freq(ants_L1) # plot flattened ecocomDP dataset plot_taxa_occur_freq(flatten_data(ants_L1)) # facet by location color by taxon_rank plot_taxa_occur_freq( data = ants_L1, facet_var = "location_id", color_var = "taxon_rank") # color by location, only include taxa with > 10 occurrences plot_taxa_occur_freq( data = ants_L1, facet_var = "location_id", color_var = "location_id", min_occurrence = 5) # tidy syntax, filter data by date ants_L1 %>% flatten_data() %>% dplyr::filter( lubridate::as_date(datetime) > "2003-07-01") %>% plot_taxa_occur_freq() ########################################################### ########################################################### ########################################################### ########################################################### # boxplots # plot ecocomDP formatted dataset plot_taxa_abund(my_dataset) # plot flattened ecocomDP dataset, log(x+1) transform abundances plot_taxa_abund( data = flatten_data(my_dataset), trans = "log1p") # facet by location color by taxon_rank, log 10 transformed plot_taxa_abund( data = my_dataset, facet_var = "location_id", color_var = "taxon_rank", trans = "log10") # facet by location, only plot taxa of rank = "species" plot_taxa_abund( data = my_dataset, facet_var = "location_id", min_relative_abundance = 0.01, trans = "log1p") # color by location, only include taxa with > 10 occurrences plot_taxa_abund( data = my_dataset, color_var = "location_id", trans = "log10") # tidy syntax, filter data by date my_dataset %>% flatten_data() %>% dplyr::filter( !grepl("^SUGG", location_id)) %>% plot_taxa_abund( trans = "log1p", min_relative_abundance = 0.005, facet_var = "location_id") ########################################################### # Read a dataset of interest dataset <- ants_L1 # plot ecocomDP formatted dataset plot_taxa_abund(dataset) # plot flattened ecocomDP dataset, log(x+1) transform abundances plot_taxa_abund( data = flatten_data(dataset), trans = "log1p") # facet by location color by taxon_rank, log 10 transformed plot_taxa_abund( data = dataset, facet_var = "location_id", color_var = "taxon_rank", trans = "log10") # facet by location, minimum rel. abund = 0.05 plot_taxa_abund( data = dataset, facet_var = "location_id", min_relative_abundance = 0.05, trans = "log1p") # color by location, log 10 transform plot_taxa_abund( data = dataset, color_var = "location_id", trans = "log10") # tidy syntax, filter data by date dataset %>% flatten_data() %>% dplyr::filter( lubridate::as_date(datetime) > "2003-07-01") %>% plot_taxa_abund( trans = "log1p", min_relative_abundance = 0.01) ########################################################### ########################################################### # plot map of sites plot_sites(ants_L1) plot_sites(flatten_data(ants_L1)) # download and plot NEON macroinvertebrate data my_dataset <- read_data( id = "neon.ecocomdp.20120.001.001", site= c('COMO','LECO'), startdate = "2017-06", enddate = "2019-09", check.size = FALSE) plot_sites(my_dataset)
/- Copyright (c) 2020 Eric Wieser. All rights reserved. Released under MIT license as described in the file LICENSE. Authors: Eric Wieser -/ import algebra.monoid_algebra.basic /-! # Lemmas for `algebra/monoid_algebra.lean` These are part of upstream PR https://github.com/leanprover-community/mathlib/pull/4321 -/ namespace add_monoid_algebra variables (k : Type*) {G : Type*} /-- The `alg_hom` which maps from a grading of an algebra `A` back to that algebra. -/ noncomputable def sum_id {A : Type*} [comm_semiring k] [semiring A] [algebra k A] [add_monoid G] : add_monoid_algebra A G →ₐ[k] A := lift_nc_alg_hom (alg_hom.id k A) ⟨λ g, 1, by simp, λ a b, by simp⟩ (by simp) lemma sum_id_apply {A : Type*} [comm_semiring k] [semiring A] [algebra k A] [add_monoid G] (g : add_monoid_algebra A G) : sum_id k g = g.sum (λ _ gi, gi) := by simp [sum_id, lift_nc_alg_hom, lift_nc_ring_hom, lift_nc, alg_hom.id, ring_hom.id] -- `monoid_algebra` is missing some of the `finsupp` API: noncomputable def lsingle {k A : Type*} [semiring k] [semiring A] [module k A] (i : G) : A →ₗ[k] add_monoid_algebra A G := finsupp.lsingle i @[simp] lemma lsingle_apply {k A : Type*} [semiring k] [semiring A] [module k A] (i : G) (a : A) : (lsingle i : _ →ₗ[k] _) a = finsupp.single i a := rfl end add_monoid_algebra
library(koRpus) library(koRpus.lang.en) library(tm) #Path path="C:\\Users\\Philipp\\SkyDrive\\Documents\\Thesiswork\\ReadStats\\" #list text files ll.files <- list.files(path = path, pattern = "txt", full.names = TRUE);length(ll.files) #set vectors SMOG.score.vec=rep(0.,length(ll.files)) FleshKincaid.score.vec=rep(0.,length(ll.files)) FOG.score.vec=rep(0.,length(ll.files)) #loop through each file for (i in 1:length(ll.files)){ #tokenize tagged.text <- koRpus::tokenize(ll.files[i], lang="en") #hyphen the word for some of the packages that require it hyph.txt.en <- koRpus::hyphen(tagged.text) #Readability wrapper readbl.txt <- koRpus::readability(tagged.text, hyphen=hyph.txt.en, index="all") #Pull scores, convert to numeric, and update the vectors SMOG.score.vec[i]=as.numeric(summary(readbl.txt)$raw[36]) #SMOG Score FleshKincaid.score.vec[i]=as.numeric(summary(readbl.txt)$raw[11]) #Flesch Reading Ease Score FOG.score.vec[i]=as.numeric(summary(readbl.txt)$raw[22]) #FOG score if (i%%10==0) cat("finished",i,"\n")} #if you wanted to do just one df=cbind(FOG.score.vec,FleshKincaid.score.vec,SMOG.score.vec) colnames(df)=c("FOG", "Flesch Kincaid", "SMOG") write.csv(df,file=paste0(path,"Combo.csv"),row.names=FALSE,col.names=TRUE) # if you wanted to write seperate csvs write.csv(SMOG.score.vec,file=paste0(path,"SMOG.csv"),row.names=FALSE,col.names = "SMOG") write.csv(FOG.score.vec,file=paste0(path,"FOG.csv"),row.names=FALSE,col.names = "FOG") write.csv(FleshKincaid.score.vec,file=paste0(path,"FK.csv"),row.names=FALSE,col.names = "Flesch Kincaid")
Load LFindLoad. From lfind Require Import LFind. From QuickChick Require Import QuickChick. From adtind Require Import goal33. Derive Show for natural. Derive Arbitrary for natural. Instance Dec_Eq_natural : Dec_Eq natural. Proof. dec_eq. Qed. Lemma conj6eqsynthconj5 : forall (lv0 : natural), (@eq natural (lv0) (plus Zero lv0)). Admitted. QuickChick conj6eqsynthconj5.
import numpy as np import time import torch from scipy.stats import norm class Simulator: @staticmethod def simulate_pseudo(spot, r, q, sigma, dt, num_paths, time_steps): np.random.seed(int(time.time())) half_path = int(num_paths / 2) + 1 sqrt_var = sigma * np.sqrt(dt) # start = timeit.default_timer() simu = np.random.normal(0, 1, (half_path, time_steps)) anti_simu = -simu simulation = np.concatenate((simu, anti_simu))[:num_paths, :] growth = (r - q - 0.5 * sigma * sigma) * dt + sqrt_var * simulation factor = np.exp(growth) st = spot * np.cumprod(factor, axis=1) return st @staticmethod def simulate_sobol(spot, r, q, sigma, dt, num_paths, time_steps): sqrt_var = sigma * np.sqrt(dt) st = spot * np.ones((num_paths, time_steps + 1)) soboleng = torch.quasirandom.SobolEngine(dimension=time_steps, scramble=True, seed=int(time.time())) Sobol_Rn = np.array(soboleng.draw(num_paths, dtype=torch.float64)) simulation = norm.ppf(Sobol_Rn) growth = (r - q - 0.5 * sigma * sigma) * dt + sqrt_var * simulation factor = np.exp(growth) st = spot * np.cumprod(factor, axis=1) return st
[STATEMENT] lemma mask_or_not_mask: "x AND mask n OR x AND NOT (mask n) = x" for x :: \<open>'a::len word\<close> [PROOF STATE] proof (prove) goal (1 subgoal): 1. x AND mask n OR x AND NOT (mask n) = x [PROOF STEP] apply (subst word_oa_dist, simp) [PROOF STATE] proof (prove) goal (1 subgoal): 1. x AND (mask n OR x AND NOT (mask n)) = x [PROOF STEP] apply (subst word_oa_dist2, simp) [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] done
Formal statement is: lemma (in Dynkin_system) sigma_algebra_eq_Int_stable: "sigma_algebra \<Omega> M \<longleftrightarrow> Int_stable M" Informal statement is: A Dynkin system is a sigma-algebra if and only if it is closed under intersections.
(* Title: HOL/Auth/n_flash_lemma_on_inv__159.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_flash Protocol Case Study*} theory n_flash_lemma_on_inv__159 imports n_flash_base begin section{*All lemmas on causal relation between inv__159 and some rule r*} lemma n_PI_Remote_GetVsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_PI_Remote_Get src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_PI_Remote_Get src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_PI_Remote_GetXVsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_PI_Remote_GetX src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_PI_Remote_GetX src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_NakVsinv__159: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Nak dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Nak dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" 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_NI_Local_Get_Nak__part__0Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Nak__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_Get_Nak__part__1Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Nak__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_Get_Nak__part__2Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__2 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Nak__part__2 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_Get_Get__part__0Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Get__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Get__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_Get_Get__part__1Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Get__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Get__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_Get_Put_HeadVsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put_Head N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put_Head N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_Get_PutVsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_Get_Put_DirtyVsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put_Dirty src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put_Dirty src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Remote_Get_NakVsinv__159: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Nak src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Nak src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=p__Inv4)" 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_NI_Remote_Get_PutVsinv__159: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Put src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Put src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=p__Inv4)" 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_NI_Local_GetX_Nak__part__0Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_Nak__part__1Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_Nak__part__2Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__2 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__2 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_GetX__part__0Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_GetX__part__1Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_PutX_1Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_PutX_2Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_2 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_2 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_PutX_3Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_3 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_3 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_PutX_4Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_4 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_4 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_PutX_5Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_5 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_5 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_PutX_6Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_6 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_6 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_PutX_7__part__0Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__0 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__0 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_PutX_7__part__1Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_PutX_7_NODE_Get__part__0Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_PutX_7_NODE_Get__part__1Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_PutX_8_HomeVsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_PutX_8_Home_NODE_GetVsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_PutX_8Vsinv__159: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8 N src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8 N src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)" 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_NI_Local_GetX_PutX_8_NODE_GetVsinv__159: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)" 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_NI_Local_GetX_PutX_9__part__0Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__0 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__0 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_PutX_9__part__1Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_PutX_10_HomeVsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_10_Home N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_10_Home N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Local_GetX_PutX_10Vsinv__159: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_10 N src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_10 N src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)" 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_NI_Local_GetX_PutX_11Vsinv__159: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_11 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_11 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" 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_NI_Remote_GetX_NakVsinv__159: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_Nak src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_Nak src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=p__Inv4)" 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_NI_Remote_GetX_PutXVsinv__159: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_PutX src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_PutX src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=p__Inv4)" 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_NI_Remote_PutVsinv__159: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Put dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_Put dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" 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_NI_Remote_PutXVsinv__159: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_PutX dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_PutX dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" 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_NI_FAckVsinv__159: assumes a1: "(r=n_NI_FAck )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__159 p__Inv4" apply fastforce done have "((formEval (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const true)) s))\<or>((formEval (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const true))) s))" by auto moreover { assume c1: "((formEval (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const true)) s))" have "?P3 s" apply (cut_tac a1 a2 c1, simp, rule_tac x="(neg (andForm (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_GetX)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''HomeProc'')) (Const false))) (eqn (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''Cmd'')) (Const SHWB_FAck))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (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_NI_Remote_GetX_PutX_HomeVsinv__159: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_GetX_PutX_Home dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_PutX__part__0Vsinv__159: assumes a1: "r=n_PI_Local_GetX_PutX__part__0 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_WbVsinv__159: assumes a1: "r=n_NI_Wb " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_StoreVsinv__159: assumes a1: "\<exists> src data. src\<le>N\<and>data\<le>N\<and>r=n_Store src data" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_3Vsinv__159: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_3 N src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_1Vsinv__159: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_1 N src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_GetX__part__1Vsinv__159: assumes a1: "r=n_PI_Local_GetX_GetX__part__1 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_GetX__part__0Vsinv__159: assumes a1: "r=n_PI_Local_GetX_GetX__part__0 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Remote_ReplaceVsinv__159: assumes a1: "\<exists> src. src\<le>N\<and>r=n_PI_Remote_Replace src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_Store_HomeVsinv__159: assumes a1: "\<exists> data. data\<le>N\<and>r=n_Store_Home data" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_ReplaceVsinv__159: assumes a1: "r=n_PI_Local_Replace " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_existsVsinv__159: assumes a1: "\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_InvAck_exists src pp" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Remote_PutXVsinv__159: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_PI_Remote_PutX dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Remote_Get_Put_HomeVsinv__159: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Get_Put_Home dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvVsinv__159: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Inv dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_PutXVsinv__159: assumes a1: "r=n_PI_Local_PutX " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_Get_PutVsinv__159: assumes a1: "r=n_PI_Local_Get_Put " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_ShWbVsinv__159: assumes a1: "r=n_NI_ShWb N " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_PutX_HeadVld__part__0Vsinv__159: assumes a1: "r=n_PI_Local_GetX_PutX_HeadVld__part__0 N " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_ReplaceVsinv__159: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Replace src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Remote_GetX_Nak_HomeVsinv__159: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_GetX_Nak_Home dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_PutXAcksDoneVsinv__159: assumes a1: "r=n_NI_Local_PutXAcksDone " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_PutX__part__1Vsinv__159: assumes a1: "r=n_PI_Local_GetX_PutX__part__1 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Remote_Get_Nak_HomeVsinv__159: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Get_Nak_Home dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_exists_HomeVsinv__159: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_exists_Home src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Replace_HomeVsinv__159: assumes a1: "r=n_NI_Replace_Home " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_PutVsinv__159: assumes a1: "r=n_NI_Local_Put " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Nak_ClearVsinv__159: assumes a1: "r=n_NI_Nak_Clear " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_Get_GetVsinv__159: assumes a1: "r=n_PI_Local_Get_Get " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Nak_HomeVsinv__159: assumes a1: "r=n_NI_Nak_Home " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_2Vsinv__159: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_2 N src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_PutX_HeadVld__part__1Vsinv__159: assumes a1: "r=n_PI_Local_GetX_PutX_HeadVld__part__1 N " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__159 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done end
State Before: R : Type u L : Type v M : Type w inst✝⁶ : CommRing R inst✝⁵ : LieRing L inst✝⁴ : LieAlgebra R L inst✝³ : AddCommGroup M inst✝² : Module R M inst✝¹ : LieRingModule L M inst✝ : LieModule R L M k✝ : ℕ N N₁ N₂ : LieSubmodule R L M k : ℕ h : N₁ ≤ N₂ ⊢ ucs k N₁ ≤ ucs k N₂ State After: case zero R : Type u L : Type v M : Type w inst✝⁶ : CommRing R inst✝⁵ : LieRing L inst✝⁴ : LieAlgebra R L inst✝³ : AddCommGroup M inst✝² : Module R M inst✝¹ : LieRingModule L M inst✝ : LieModule R L M k : ℕ N N₁ N₂ : LieSubmodule R L M h : N₁ ≤ N₂ ⊢ ucs Nat.zero N₁ ≤ ucs Nat.zero N₂ case succ R : Type u L : Type v M : Type w inst✝⁶ : CommRing R inst✝⁵ : LieRing L inst✝⁴ : LieAlgebra R L inst✝³ : AddCommGroup M inst✝² : Module R M inst✝¹ : LieRingModule L M inst✝ : LieModule R L M k✝ : ℕ N N₁ N₂ : LieSubmodule R L M h : N₁ ≤ N₂ k : ℕ ih : ucs k N₁ ≤ ucs k N₂ ⊢ ucs (Nat.succ k) N₁ ≤ ucs (Nat.succ k) N₂ Tactic: induction' k with k ih State Before: case succ R : Type u L : Type v M : Type w inst✝⁶ : CommRing R inst✝⁵ : LieRing L inst✝⁴ : LieAlgebra R L inst✝³ : AddCommGroup M inst✝² : Module R M inst✝¹ : LieRingModule L M inst✝ : LieModule R L M k✝ : ℕ N N₁ N₂ : LieSubmodule R L M h : N₁ ≤ N₂ k : ℕ ih : ucs k N₁ ≤ ucs k N₂ ⊢ ucs (Nat.succ k) N₁ ≤ ucs (Nat.succ k) N₂ State After: case succ R : Type u L : Type v M : Type w inst✝⁶ : CommRing R inst✝⁵ : LieRing L inst✝⁴ : LieAlgebra R L inst✝³ : AddCommGroup M inst✝² : Module R M inst✝¹ : LieRingModule L M inst✝ : LieModule R L M k✝ : ℕ N N₁ N₂ : LieSubmodule R L M h : N₁ ≤ N₂ k : ℕ ih : ucs k N₁ ≤ ucs k N₂ ⊢ normalizer (ucs k N₁) ≤ normalizer (ucs k N₂) Tactic: simp only [ucs_succ] State Before: case succ R : Type u L : Type v M : Type w inst✝⁶ : CommRing R inst✝⁵ : LieRing L inst✝⁴ : LieAlgebra R L inst✝³ : AddCommGroup M inst✝² : Module R M inst✝¹ : LieRingModule L M inst✝ : LieModule R L M k✝ : ℕ N N₁ N₂ : LieSubmodule R L M h : N₁ ≤ N₂ k : ℕ ih : ucs k N₁ ≤ ucs k N₂ ⊢ normalizer (ucs k N₁) ≤ normalizer (ucs k N₂) State After: no goals Tactic: apply monotone_normalizer ih State Before: case zero R : Type u L : Type v M : Type w inst✝⁶ : CommRing R inst✝⁵ : LieRing L inst✝⁴ : LieAlgebra R L inst✝³ : AddCommGroup M inst✝² : Module R M inst✝¹ : LieRingModule L M inst✝ : LieModule R L M k : ℕ N N₁ N₂ : LieSubmodule R L M h : N₁ ≤ N₂ ⊢ ucs Nat.zero N₁ ≤ ucs Nat.zero N₂ State After: no goals Tactic: simpa
[STATEMENT] lemma lessaliveI: "\<lbrakk>\<And> x. alive x s \<Longrightarrow> s \<equiv>[x] t; \<And> f. s@@staticLoc f = t@@staticLoc f\<rbrakk> \<Longrightarrow> s \<lless> t" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>\<And>x. alive x s \<Longrightarrow> s \<equiv>[x] t; \<And>f. s@@staticLoc f = t@@staticLoc f\<rbrakk> \<Longrightarrow> s \<lless> t [PROOF STEP] by (simp add: lessalive_def)
# Praca domowa - Dominik Stańczak ```python import sympy sympy.init_printing() t, lambda3a, lambdaa12, N4, N12, N16, dN4, dN12, dN16, dt = sympy.symbols('t, lambda_3a, lambda_a12, N4, N12, N16, dN4, dN12, dN16, dt', real=True) eqs = [ sympy.Eq(dN4/dt, -3*lambda3a * N4 **3 - lambdaa12 * N4 * N12), sympy.Eq(dN12/dt, lambda3a * N4 **3 - lambdaa12 * N4 * N12), sympy.Eq(dN16/dt, lambdaa12 * N4 * N12) ] eqs ``` ```python m, rho = sympy.symbols('m, rho', real=True) X4, X12, X16, dX4, dX12, dX16 = sympy.symbols('X4, X12, X16, dX4, dX12, dX16', real=True) Xeqs = [ sympy.Eq(X4, m/rho*4*N4), sympy.Eq(X12, m/rho*12*N12), sympy.Eq(X16, m/rho*16*N16), ] Xeqs ``` ```python subs = {X4: dX4, X12: dX12, X16: dX16, N4: dN4, N12: dN12, N16: dN16} dXeqs = [eq.subs(subs) for eq in Xeqs] dXeqs ``` ```python full_conservation = [sympy.Eq(X4 + X12 + X16, 1), sympy.Eq(dX4 + dX12 + dX16, 0)] full_conservation ``` ```python all_eqs = eqs + Xeqs + dXeqs + full_conservation all_eqs ``` ```python X_all_eqs = [eq.subs(sympy.solve(Xeqs, [N4, N12, N16])).subs(sympy.solve(dXeqs, [dN4, dN12, dN16])) for eq in eqs] + [full_conservation[1]] X_all_eqs ``` ```python solutions = sympy.solve(X_all_eqs, [dX4, dX12, dX16]) dX12dX4 = solutions[dX12]/solutions[dX4] dX12dX4 ``` ```python q = sympy.symbols('q', real=True) dX12dX4_final = dX12dX4.subs({lambdaa12*m: q * lambda3a * rho}).simplify() dX12dX4_final ``` ```python fX12 = sympy.Function('X12')(X4) diffeq = sympy.Eq(fX12.diff(X4), dX12dX4_final.subs(X12, fX12)) diffeq ``` ```python dX16dX4 = solutions[dX16]/solutions[dX4] dX16dX4 ``` ```python dX16dX4_final = dX16dX4.subs({lambdaa12*m: q * lambda3a * rho}).simplify() dX16dX4_final ``` ```python derivatives_func = sympy.lambdify((X4, X12, X16, q), [dX12dX4_final, dX16dX4_final]) derivatives_func(1, 0, 0, 1) ``` ```python def f(X, X4, q): return derivatives_func(X4, *X, q) f([0, 0], 1, 1) ``` ```python import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt X4 = np.linspace(1, 0, 1000) q_list = np.logspace(-3, np.log10(2), 500) results = [] # fig, (ax1, ax2) = plt.subplots(2, sharex=True, figsize=(10, 8)) # ax1.set_xlim(0, 1) # ax2.set_xlim(0, 1) # ax1.set_ylim(0, 1) # ax2.set_ylim(0, 1) for q in q_list: X = odeint(f, [0, 0], X4, args=(q,)) X12, X16 = X.T # ax1.plot(X4, X12, label=f"q: {q:.1f}") # ax2.plot(X4, X16, label=f"q: {q:.1f}") # ax2.set_xlabel("X4") # ax1.set_ylabel("X12") # ax2.set_ylabel("X16") # plt.plot(X4, X16) # plt.legend() results.append(X[-1]) results = np.array(results) ``` ```python X12, X16 = results.T plt.figure(figsize=(10, 10)) plt.plot(q_list, X12, label="X12") plt.plot(q_list, X16, label="X16") plt.xlabel("q") plt.xscale("log") plt.ylabel("X") plt.legend(loc='best') plt.xlim(q_list.min(), q_list.max()); plt.grid() plt.savefig("Reacts.png") ```
[STATEMENT] lemma keys_minus_higher: "keys (p - higher p v) = {u \<in> keys p. u \<preceq>\<^sub>t v}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. keys (p - higher p v) = {u \<in> keys p. u \<preceq>\<^sub>t v} [PROOF STEP] by (rule set_eqI, simp add: lookup_minus_higher conj_commute flip: lookup_not_eq_zero_eq_in_keys)
module EtaAndMetas where record Functor : Set₁ where field F : Set → Set eta : Functor → Functor eta S = record { F = F } where open Functor S postulate Π : (To : Functor) → Set mkΠ : (B : Functor) → Π (eta B) To : Functor π : Π (eta To) π = mkΠ _
= = = Synthesis of epoxides = = =
module Postfix record Diag (a : Type) where fstt : a sndd : a equal : fstt === sndd val : Diag a -> a val diag = diag .fstt prf : (d : Diag a) -> val d === d.sndd prf = ?a (.val') : Diag a -> a diag .val' = diag .sndd sym : (d : Diag a) -> d .fstt === d .val' sym = ?b
(* Title: Uint8.thy Author: Andreas Lochbihler, ETH Zurich *) header {* Unsigned words of 8 bits *} theory Uint8 imports Word_Misc Bits_Integer begin text {* Restriction for OCaml code generation: OCaml does not provide an int8 type, so no special code generation for this type is set up. If the theory @{text "Code_Target_Bits_Int"} is imported, the type @{text uint8} is emulated via @{typ "8 word"}. *} declare prod.Quotient[transfer_rule] section {* Type definition and primitive operations *} typedef uint8 = "UNIV :: 8 word set" .. setup_lifting type_definition_uint8 text {* Use an abstract type for code generation to disable pattern matching on @{term Abs_uint8}. *} declare Rep_uint8_inverse[code abstype] declare Quotient_uint8[transfer_rule] instantiation uint8 :: "{neg_numeral, Divides.div, comm_monoid_mult, comm_ring}" begin lift_definition zero_uint8 :: uint8 is "0" . lift_definition one_uint8 :: uint8 is "1" . lift_definition plus_uint8 :: "uint8 \<Rightarrow> uint8 \<Rightarrow> uint8" is "op +" . lift_definition minus_uint8 :: "uint8 \<Rightarrow> uint8 \<Rightarrow> uint8" is "op -" . lift_definition uminus_uint8 :: "uint8 \<Rightarrow> uint8" is uminus . lift_definition times_uint8 :: "uint8 \<Rightarrow> uint8 \<Rightarrow> uint8" is "op *" . lift_definition div_uint8 :: "uint8 \<Rightarrow> uint8 \<Rightarrow> uint8" is "op div" . lift_definition mod_uint8 :: "uint8 \<Rightarrow> uint8 \<Rightarrow> uint8" is "op mod" . instance by default (transfer, simp add: algebra_simps)+ end instantiation uint8 :: linorder begin lift_definition less_uint8 :: "uint8 \<Rightarrow> uint8 \<Rightarrow> bool" is "op <" . lift_definition less_eq_uint8 :: "uint8 \<Rightarrow> uint8 \<Rightarrow> bool" is "op \<le>" . instance by(default)(transfer, simp add: less_le_not_le linear)+ end lemmas [code] = less_uint8.rep_eq less_eq_uint8.rep_eq instantiation uint8 :: bitss begin lift_definition bitNOT_uint8 :: "uint8 \<Rightarrow> uint8" is bitNOT . lift_definition bitAND_uint8 :: "uint8 \<Rightarrow> uint8 \<Rightarrow> uint8" is bitAND . lift_definition bitOR_uint8 :: "uint8 \<Rightarrow> uint8 \<Rightarrow> uint8" is bitOR . lift_definition bitXOR_uint8 :: "uint8 \<Rightarrow> uint8 \<Rightarrow> uint8" is bitXOR . lift_definition test_bit_uint8 :: "uint8 \<Rightarrow> nat \<Rightarrow> bool" is test_bit . lift_definition set_bit_uint8 :: "uint8 \<Rightarrow> nat \<Rightarrow> bool \<Rightarrow> uint8" is set_bit . lift_definition set_bits_uint8 :: "(nat \<Rightarrow> bool) \<Rightarrow> uint8" is "set_bits" . lift_definition lsb_uint8 :: "uint8 \<Rightarrow> bool" is lsb . lift_definition shiftl_uint8 :: "uint8 \<Rightarrow> nat \<Rightarrow> uint8" is shiftl . lift_definition shiftr_uint8 :: "uint8 \<Rightarrow> nat \<Rightarrow> uint8" is shiftr . lift_definition msb_uint8 :: "uint8 \<Rightarrow> bool" is msb . instance .. end lemmas [code] = test_bit_uint8.rep_eq lsb_uint8.rep_eq msb_uint8.rep_eq instantiation uint8 :: equal begin lift_definition equal_uint8 :: "uint8 \<Rightarrow> uint8 \<Rightarrow> bool" is "equal_class.equal" . instance by default(transfer, simp add: equal_eq) end lemmas [code] = equal_uint8.rep_eq instantiation uint8 :: size begin lift_definition size_uint8 :: "uint8 \<Rightarrow> nat" is "size" . instance .. end lemmas [code] = size_uint8.rep_eq lift_definition sshiftr_uint8 :: "uint8 \<Rightarrow> nat \<Rightarrow> uint8" (infixl ">>>" 55) is sshiftr . lift_definition uint8_of_int :: "int \<Rightarrow> uint8" is "word_of_int" . definition uint8_of_nat :: "nat \<Rightarrow> uint8" where "uint8_of_nat = uint8_of_int \<circ> int" lift_definition int_of_uint8 :: "uint8 \<Rightarrow> int" is "uint" . lift_definition nat_of_uint8 :: "uint8 \<Rightarrow> nat" is "unat" . definition integer_of_uint8 :: "uint8 \<Rightarrow> integer" where "integer_of_uint8 = integer_of_int o int_of_uint8" text {* Use pretty numerals from integer for pretty printing *} context includes integer.lifting begin lift_definition Uint8 :: "integer \<Rightarrow> uint8" is "word_of_int" . lemma Rep_uint8_numeral [simp]: "Rep_uint8 (numeral n) = numeral n" by(induction n)(simp_all add: one_uint8_def Abs_uint8_inverse numeral.simps plus_uint8_def) lemma numeral_uint8_transfer [transfer_rule]: "(rel_fun op = cr_uint8) numeral numeral" by(auto simp add: cr_uint8_def) lemma numeral_uint8 [code_unfold]: "numeral n = Uint8 (numeral n)" by transfer simp lemma Rep_uint8_neg_numeral [simp]: "Rep_uint8 (- numeral n) = - numeral n" by(simp only: uminus_uint8_def)(simp add: Abs_uint8_inverse) lemma neg_numeral_uint8 [code_unfold]: "- numeral n = Uint8 (- numeral n)" by transfer(simp add: cr_uint8_def) end lemma Abs_uint8_numeral [code_post]: "Abs_uint8 (numeral n) = numeral n" by(induction n)(simp_all add: one_uint8_def numeral.simps plus_uint8_def Abs_uint8_inverse) lemma Abs_uint8_0 [code_post]: "Abs_uint8 0 = 0" by(simp add: zero_uint8_def) lemma Abs_uint8_1 [code_post]: "Abs_uint8 1 = 1" by(simp add: one_uint8_def) section {* Code setup *} code_printing code_module Uint8 \<rightharpoonup> (SML) {*(* Test that words can handle numbers between 0 and 3 *) val _ = if 3 <= Word.wordSize then () else raise (Fail ("wordSize less than 3")); structure Uint8 : sig val set_bit : Word8.word -> IntInf.int -> bool -> Word8.word val shiftl : Word8.word -> IntInf.int -> Word8.word val shiftr : Word8.word -> IntInf.int -> Word8.word val shiftr_signed : Word8.word -> IntInf.int -> Word8.word val test_bit : Word8.word -> IntInf.int -> bool end = struct fun set_bit x n b = let val mask = Word8.<< (0wx1, Word.fromLargeInt (IntInf.toLarge n)) in if b then Word8.orb (x, mask) else Word8.andb (x, Word8.notb mask) end fun shiftl x n = Word8.<< (x, Word.fromLargeInt (IntInf.toLarge n)) fun shiftr x n = Word8.>> (x, Word.fromLargeInt (IntInf.toLarge n)) fun shiftr_signed x n = Word8.~>> (x, Word.fromLargeInt (IntInf.toLarge n)) fun test_bit x n = Word8.andb (x, Word8.<< (0wx1, Word.fromLargeInt (IntInf.toLarge n))) <> Word8.fromInt 0 end; (* struct Uint8 *)*} code_reserved SML Uint8 code_printing code_module Uint8 \<rightharpoonup> (Haskell) {*import qualified Data.Word; import qualified Data.Int; type Int8 = Data.Int.Int8; type Word8 = Data.Word.Word8;*} code_reserved Haskell Uint8 text {* Scala provides only signed 8bit numbers, so we use these and implement sign-sensitive operations like comparisons manually. *} code_printing code_module Uint8 \<rightharpoonup> (Scala) {*object Uint8 { def less(x: Byte, y: Byte) : Boolean = if (x < 0) y < 0 && x < y else y < 0 || x < y def less_eq(x: Byte, y: Byte) : Boolean = if (x < 0) y < 0 && x <= y else y < 0 || x <= y def set_bit(x: Byte, n: BigInt, b: Boolean) : Byte = if (b) (x | (1 << n.intValue)).toByte else (x & (1 << n.intValue).unary_~).toByte def shiftl(x: Byte, n: BigInt) : Byte = (x << n.intValue).toByte def shiftr(x: Byte, n: BigInt) : Byte = ((x & 255) >>> n.intValue).toByte def shiftr_signed(x: Byte, n: BigInt) : Byte = (x >> n.intValue).toByte def test_bit(x: Byte, n: BigInt) : Boolean = (x & (1 << n.intValue)) != 0 } /* object Uint8 */*} code_reserved Scala Uint8 text {* Avoid @{term Abs_uint8} in generated code, use @{term Rep_uint8'} instead. The symbolic implementations for code\_simp use @{term Rep_uint8}. The new destructor @{term Rep_uint8'} is executable. As the simplifier is given the [code abstract] equations literally, we cannot implement @{term Rep_uint8} directly, because that makes code\_simp loop. If code generation raises Match, some equation probably contains @{term Rep_uint8} ([code abstract] equations for @{typ uint8} may use @{term Rep_uint8} because these instances will be folded away.) To convert @{typ "8 word"} values into @{typ uint8}, use @{term "Abs_uint8'"}. *} definition Rep_uint8' where [simp]: "Rep_uint8' = Rep_uint8" lemma Rep_uint8'_transfer [transfer_rule]: "rel_fun cr_uint8 op = (\<lambda>x. x) Rep_uint8'" unfolding Rep_uint8'_def by(rule uint8.rep_transfer) lemma Rep_uint8'_code [code]: "Rep_uint8' x = (BITS n. x !! n)" by transfer simp lift_definition Abs_uint8' :: "8 word \<Rightarrow> uint8" is "\<lambda>x :: 8 word. x" . lemma Abs_uint8'_code [code]: "Abs_uint8' x = Uint8 (integer_of_int (uint x))" including integer.lifting by transfer simp lemma [code, code del]: "term_of_class.term_of = (term_of_class.term_of :: uint8 \<Rightarrow> _)" .. lemma term_of_uint8_code [code]: defines "TR \<equiv> typerep.Typerep" and "bit0 \<equiv> STR ''Numeral_Type.bit0''" shows "term_of_class.term_of x = Code_Evaluation.App (Code_Evaluation.Const (STR ''Uint8.Abs_uint8'') (TR (STR ''fun'') [TR (STR ''Word.word'') [TR bit0 [TR bit0 [TR bit0 [TR (STR ''Numeral_Type.num1'') []]]]], TR (STR ''Uint8.uint8'') []])) (term_of_class.term_of (Rep_uint8' x))" by(simp add: term_of_anything) lemma Uin8_code [code abstract]: "Rep_uint8 (Uint8 i) = word_of_int (int_of_integer_symbolic i)" unfolding Uint8_def int_of_integer_symbolic_def by(simp add: Abs_uint8_inverse) code_printing type_constructor uint8 \<rightharpoonup> (SML) "Word8.word" and (Haskell) "Uint8.Word8" and (Scala) "Byte" | constant Uint8 \<rightharpoonup> (SML) "Word8.fromLargeInt (IntInf.toLarge _)" and (Haskell) "(Prelude.fromInteger _ :: Uint8.Word8)" and (Haskell_Quickcheck) "(Prelude.fromInteger (Prelude.toInteger _) :: Uint8.Word8)" and (Scala) "_.byteValue" | constant "0 :: uint8" \<rightharpoonup> (SML) "(Word8.fromInt 0)" and (Haskell) "(0 :: Uint8.Word8)" and (Scala) "0.toByte" | constant "1 :: uint8" \<rightharpoonup> (SML) "(Word8.fromInt 1)" and (Haskell) "(1 :: Uint8.Word8)" and (Scala) "1.toByte" | constant "plus :: uint8 \<Rightarrow> _ \<Rightarrow> _" \<rightharpoonup> (SML) "Word8.+ ((_), (_))" and (Haskell) infixl 6 "+" and (Scala) "(_ +/ _).toByte" | constant "uminus :: uint8 \<Rightarrow> _" \<rightharpoonup> (SML) "Word8.~" and (Haskell) "negate" and (Scala) "(- _).toByte" | constant "minus :: uint8 \<Rightarrow> _" \<rightharpoonup> (SML) "Word8.- ((_), (_))" and (Haskell) infixl 6 "-" and (Scala) "(_ -/ _).toByte" | constant "times :: uint8 \<Rightarrow> _ \<Rightarrow> _" \<rightharpoonup> (SML) "Word8.* ((_), (_))" and (Haskell) infixl 7 "*" and (Scala) "(_ */ _).toByte" | constant "HOL.equal :: uint8 \<Rightarrow> _ \<Rightarrow> bool" \<rightharpoonup> (SML) "!((_ : Word8.word) = _)" and (Haskell) infix 4 "==" and (Scala) infixl 5 "==" | class_instance uint8 :: equal \<rightharpoonup> (Haskell) - | constant "less_eq :: uint8 \<Rightarrow> _ \<Rightarrow> bool" \<rightharpoonup> (SML) "Word8.<= ((_), (_))" and (Haskell) infix 4 "<=" and (Scala) "Uint8.less'_eq" | constant "less :: uint8 \<Rightarrow> _ \<Rightarrow> bool" \<rightharpoonup> (SML) "Word8.< ((_), (_))" and (Haskell) infix 4 "<" and (Scala) "Uint8.less" | constant "bitNOT :: uint8 \<Rightarrow> _" \<rightharpoonup> (SML) "Word8.notb" and (Haskell) "Data'_Bits.complement" and (Scala) "_.unary'_~.toByte" | constant "bitAND :: uint8 \<Rightarrow> _" \<rightharpoonup> (SML) "Word8.andb ((_),/ (_))" and (Haskell) infixl 7 "Data_Bits..&." and (Scala) "(_ & _).toByte" | constant "bitOR :: uint8 \<Rightarrow> _" \<rightharpoonup> (SML) "Word8.orb ((_),/ (_))" and (Haskell) infixl 5 "Data_Bits..|." and (Scala) "(_ | _).toByte" | constant "bitXOR :: uint8 \<Rightarrow> _" \<rightharpoonup> (SML) "Word8.xorb ((_),/ (_))" and (Haskell) "Data'_Bits.xor" and (Scala) "(_ ^ _).toByte" definition uint8_divmod :: "uint8 \<Rightarrow> uint8 \<Rightarrow> uint8 \<times> uint8" where "uint8_divmod x y = (if y = 0 then (undefined (op div :: uint8 \<Rightarrow> _) x (0 :: uint8), undefined (op mod :: uint8 \<Rightarrow> _) x (0 :: uint8)) else (x div y, x mod y))" definition uint8_div :: "uint8 \<Rightarrow> uint8 \<Rightarrow> uint8" where "uint8_div x y = fst (uint8_divmod x y)" definition uint8_mod :: "uint8 \<Rightarrow> uint8 \<Rightarrow> uint8" where "uint8_mod x y = snd (uint8_divmod x y)" lemma div_uint8_code [code]: "x div y = (if y = 0 then 0 else uint8_div x y)" including undefined_transfer unfolding uint8_divmod_def uint8_div_def by transfer(simp add: word_div_def) lemma mod_uint8_code [code]: "x mod y = (if y = 0 then x else uint8_mod x y)" including undefined_transfer unfolding uint8_mod_def uint8_divmod_def by transfer(simp add: word_mod_def) definition uint8_sdiv :: "uint8 \<Rightarrow> uint8 \<Rightarrow> uint8" where "uint8_sdiv x y = (if y = 0 then undefined (op div :: uint8 \<Rightarrow> _) x (0 :: uint8) else Abs_uint8 (Rep_uint8 x sdiv Rep_uint8 y))" definition div0_uint8 :: "uint8 \<Rightarrow> uint8" where [code del]: "div0_uint8 x = undefined (op div :: uint8 \<Rightarrow> _) x (0 :: uint8)" declare [[code abort: div0_uint8]] definition mod0_uint8 :: "uint8 \<Rightarrow> uint8" where [code del]: "mod0_uint8 x = undefined (op mod :: uint8 \<Rightarrow> _) x (0 :: uint8)" declare [[code abort: mod0_uint8]] lemma uint8_divmod_code [code]: "uint8_divmod x y = (if 0x80 \<le> y then if x < y then (0, x) else (1, x - y) else if y = 0 then (div0_uint8 x, mod0_uint8 x) else let q = (uint8_sdiv (x >> 1) y) << 1; r = x - q * y in if r \<ge> y then (q + 1, r - y) else (q, r))" including undefined_transfer unfolding uint8_divmod_def uint8_sdiv_def div0_uint8_def mod0_uint8_def by transfer(simp add: divmod_via_sdivmod) lemma uint8_sdiv_code [code abstract]: "Rep_uint8 (uint8_sdiv x y) = (if y = 0 then Rep_uint8 (undefined (op div :: uint8 \<Rightarrow> _) x (0 :: uint8)) else Rep_uint8 x sdiv Rep_uint8 y)" unfolding uint8_sdiv_def by(simp add: Abs_uint8_inverse) text {* Note that we only need a translation for signed division, but not for the remainder because @{thm uint8_divmod_code} computes both with division only. *} code_printing constant uint8_div \<rightharpoonup> (SML) "Word8.div ((_), (_))" and (Haskell) "Prelude.div" | constant uint8_mod \<rightharpoonup> (SML) "Word8.mod ((_), (_))" and (Haskell) "Prelude.mod" | constant uint8_divmod \<rightharpoonup> (Haskell) "divmod" | constant uint8_sdiv \<rightharpoonup> (Scala) "(_ '/ _).toByte" definition uint8_test_bit :: "uint8 \<Rightarrow> integer \<Rightarrow> bool" where [code del]: "uint8_test_bit x n = (if n < 0 \<or> 7 < n then undefined (test_bit :: uint8 \<Rightarrow> _) x n else x !! (nat_of_integer n))" lemma test_bit_uint8_code [code]: "test_bit x n \<longleftrightarrow> n < 8 \<and> uint8_test_bit x (integer_of_nat n)" including undefined_transfer integer.lifting unfolding uint8_test_bit_def by transfer(auto cong: conj_cong dest: test_bit_size simp add: word_size) lemma uint8_test_bit_code [code]: "uint8_test_bit w n = (if n < 0 \<or> 7 < n then undefined (test_bit :: uint8 \<Rightarrow> _) w n else Rep_uint8 w !! nat_of_integer n)" unfolding uint8_test_bit_def by(simp add: test_bit_uint8.rep_eq) code_printing constant uint8_test_bit \<rightharpoonup> (SML) "Uint8.test'_bit" and (Haskell) "Data'_Bits.testBitBounded" and (Scala) "Uint8.test'_bit" definition uint8_set_bit :: "uint8 \<Rightarrow> integer \<Rightarrow> bool \<Rightarrow> uint8" where [code del]: "uint8_set_bit x n b = (if n < 0 \<or> 7 < n then undefined (set_bit :: uint8 \<Rightarrow> _) x n b else set_bit x (nat_of_integer n) b)" lemma set_bit_uint8_code [code]: "set_bit x n b = (if n < 8 then uint8_set_bit x (integer_of_nat n) b else x)" including undefined_transfer integer.lifting unfolding uint8_set_bit_def by(transfer)(auto cong: conj_cong simp add: not_less set_bit_beyond word_size) lemma uint8_set_bit_code [code abstract]: "Rep_uint8 (uint8_set_bit w n b) = (if n < 0 \<or> 7 < n then Rep_uint8 (undefined (set_bit :: uint8 \<Rightarrow> _) w n b) else set_bit (Rep_uint8 w) (nat_of_integer n) b)" including undefined_transfer unfolding uint8_set_bit_def by transfer simp code_printing constant uint8_set_bit \<rightharpoonup> (SML) "Uint8.set'_bit" and (Haskell) "Data'_Bits.setBitBounded" and (Scala) "Uint8.set'_bit" lift_definition uint8_set_bits :: "(nat \<Rightarrow> bool) \<Rightarrow> uint8 \<Rightarrow> nat \<Rightarrow> uint8" is set_bits_aux . lemma uint8_set_bits_code [code]: "uint8_set_bits f w n = (if n = 0 then w else let n' = n - 1 in uint8_set_bits f ((w << 1) OR (if f n' then 1 else 0)) n')" by(transfer fixing: n)(cases n, simp_all) lemma set_bits_uint8 [code]: "(BITS n. f n) = uint8_set_bits f 0 8" by transfer(simp add: set_bits_conv_set_bits_aux) lemma lsb_code [code]: fixes x :: uint8 shows "lsb x = x !! 0" by transfer(simp add: word_lsb_def word_test_bit_def) definition uint8_shiftl :: "uint8 \<Rightarrow> integer \<Rightarrow> uint8" where [code del]: "uint8_shiftl x n = (if n < 0 \<or> 8 \<le> n then undefined (shiftl :: uint8 \<Rightarrow> _) x n else x << (nat_of_integer n))" lemma shiftl_uint8_code [code]: "x << n = (if n < 8 then uint8_shiftl x (integer_of_nat n) else 0)" including undefined_transfer integer.lifting unfolding uint8_shiftl_def by transfer(simp add: not_less shiftl_zero_size word_size) lemma uint8_shiftl_code [code abstract]: "Rep_uint8 (uint8_shiftl w n) = (if n < 0 \<or> 8 \<le> n then Rep_uint8 (undefined (shiftl :: uint8 \<Rightarrow> _) w n) else Rep_uint8 w << nat_of_integer n)" including undefined_transfer unfolding uint8_shiftl_def by transfer simp code_printing constant uint8_shiftl \<rightharpoonup> (SML) "Uint8.shiftl" and (Haskell) "Data'_Bits.shiftlBounded" and (Scala) "Uint8.shiftl" definition uint8_shiftr :: "uint8 \<Rightarrow> integer \<Rightarrow> uint8" where [code del]: "uint8_shiftr x n = (if n < 0 \<or> 8 \<le> n then undefined (shiftr :: uint8 \<Rightarrow> _) x n else x >> (nat_of_integer n))" lemma shiftr_uint8_code [code]: "x >> n = (if n < 8 then uint8_shiftr x (integer_of_nat n) else 0)" including undefined_transfer integer.lifting unfolding uint8_shiftr_def by transfer(simp add: not_less shiftr_zero_size word_size) lemma uint8_shiftr_code [code abstract]: "Rep_uint8 (uint8_shiftr w n) = (if n < 0 \<or> 8 \<le> n then Rep_uint8 (undefined (shiftr :: uint8 \<Rightarrow> _) w n) else Rep_uint8 w >> nat_of_integer n)" including undefined_transfer unfolding uint8_shiftr_def by transfer simp code_printing constant uint8_shiftr \<rightharpoonup> (SML) "Uint8.shiftr" and (Haskell) "Data'_Bits.shiftrBounded" and (Scala) "Uint8.shiftr" definition uint8_sshiftr :: "uint8 \<Rightarrow> integer \<Rightarrow> uint8" where [code del]: "uint8_sshiftr x n = (if n < 0 \<or> 8 \<le> n then undefined sshiftr_uint8 x n else sshiftr_uint8 x (nat_of_integer n))" lemma sshiftr_beyond: fixes x :: "'a :: len word" shows "size x \<le> n \<Longrightarrow> x >>> n = (if x !! (size x - 1) then -1 else 0)" by(rule word_eqI)(simp add: nth_sshiftr word_size) lemma sshiftr_uint8_code [code]: "x >>> n = (if n < 8 then uint8_sshiftr x (integer_of_nat n) else if x !! 7 then -1 else 0)" including undefined_transfer integer.lifting unfolding uint8_sshiftr_def by transfer (simp add: not_less sshiftr_beyond word_size) lemma uint8_sshiftr_code [code abstract]: "Rep_uint8 (uint8_sshiftr w n) = (if n < 0 \<or> 8 \<le> n then Rep_uint8 (undefined sshiftr_uint8 w n) else Rep_uint8 w >>> nat_of_integer n)" including undefined_transfer unfolding uint8_sshiftr_def by transfer simp code_printing constant uint8_sshiftr \<rightharpoonup> (SML) "Uint8.shiftr'_signed" and (Haskell) "(Prelude.fromInteger (Prelude.toInteger (Data'_Bits.shiftrBounded (Prelude.fromInteger (Prelude.toInteger _) :: Uint8.Int8) _)) :: Uint8.Word8)" and (Scala) "Uint8.shiftr'_signed" lemma uint8_msb_test_bit: "msb x \<longleftrightarrow> (x :: uint8) !! 7" by transfer(simp add: msb_nth) lemma msb_uint16_code [code]: "msb x \<longleftrightarrow> uint8_test_bit x 7" by(simp add: uint8_test_bit_def uint8_msb_test_bit) lemma uint8_of_int_code [code]: "uint8_of_int i = Uint8 (integer_of_int i)" including integer.lifting by transfer simp lemma int_of_uint8_code [code]: "int_of_uint8 x = int_of_integer (integer_of_uint8 x)" by(simp add: integer_of_uint8_def) lemma nat_of_uint8_code [code]: "nat_of_uint8 x = nat_of_integer (integer_of_uint8 x)" unfolding integer_of_uint8_def including integer.lifting by transfer (simp add: unat_def) definition integer_of_uint8_signed :: "uint8 \<Rightarrow> integer" where "integer_of_uint8_signed n = (if n !! 7 then undefined integer_of_uint8 n else integer_of_uint8 n)" lemma integer_of_uint8_signed_code [code]: "integer_of_uint8_signed n = (if n !! 7 then undefined integer_of_uint8 n else integer_of_int (uint (Rep_uint8' n)))" unfolding integer_of_uint8_signed_def integer_of_uint8_def including undefined_transfer by transfer simp code_printing constant "integer_of_uint8" \<rightharpoonup> (SML) "IntInf.fromLarge (Word8.toLargeInt _)" and (Haskell) "Prelude.toInteger" | constant "integer_of_uint8_signed" \<rightharpoonup> (Scala) "BigInt" section {* Quickcheck setup *} definition uint8_of_natural :: "natural \<Rightarrow> uint8" where "uint8_of_natural x \<equiv> Uint8 (integer_of_natural x)" instantiation uint8 :: "{random, exhaustive, full_exhaustive}" begin definition "random_uint8 \<equiv> qc_random_cnv uint8_of_natural" definition "exhaustive_uint8 \<equiv> qc_exhaustive_cnv uint8_of_natural" definition "full_exhaustive_uint8 \<equiv> qc_full_exhaustive_cnv uint8_of_natural" instance .. end instantiation uint8 :: narrowing begin interpretation quickcheck_narrowing_samples "\<lambda>i. let x = Uint8 i in (x, 0xFF - x)" "0" "Typerep.Typerep (STR ''Uint8.uint8'') []" . definition "narrowing_uint8 d = qc_narrowing_drawn_from (narrowing_samples d) d" declare [[code drop: "partial_term_of :: uint8 itself \<Rightarrow> _"]] lemmas partial_term_of_uint8 [code] = partial_term_of_code instance .. end no_notation sshiftr_uint8 (infixl ">>>" 55) end
(* Title: HOL/Auth/n_german_lemma_on_inv__27.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__27 imports n_german_base begin section{*All lemmas on causal relation between inv__27 and some rule r*} lemma n_RecvReqSVsinv__27: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)" and a2: "(\<exists> p__Inv1 p__Inv2. p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 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__Inv1 p__Inv2 where a2:"p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i=p__Inv1)\<or>(i~=p__Inv1\<and>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 ''Cache'') p__Inv1) ''State'')) (Const E)) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const true))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv1)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Cache'') p__Inv1) ''State'')) (Const E)) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const true))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv1\<and>i~=p__Inv2)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Cache'') p__Inv1) ''State'')) (Const E)) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const true))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_RecvReqEVsinv__27: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqE N i)" and a2: "(\<exists> p__Inv1 p__Inv2. p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 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__Inv1 p__Inv2 where a2:"p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i=p__Inv1)\<or>(i~=p__Inv1\<and>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 ''Cache'') p__Inv1) ''State'')) (Const E)) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const true))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv1)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Cache'') p__Inv1) ''State'')) (Const E)) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const true))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv1\<and>i~=p__Inv2)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Cache'') p__Inv1) ''State'')) (Const E)) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const true))))" in exI, auto) done 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__27: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)" and a2: "(\<exists> p__Inv1 p__Inv2. p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 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__Inv1 p__Inv2 where a2:"p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i=p__Inv1)\<or>(i~=p__Inv1\<and>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__Inv1)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv1\<and>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__27: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)" and a2: "(\<exists> p__Inv1 p__Inv2. p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 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__Inv1 p__Inv2 where a2:"p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i=p__Inv1)\<or>(i~=p__Inv1\<and>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__Inv1)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv1\<and>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_SendInvAckVsinv__27: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)" and a2: "(\<exists> p__Inv1 p__Inv2. p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 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__Inv1 p__Inv2 where a2:"p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i=p__Inv1)\<or>(i~=p__Inv1\<and>i~=p__Inv2)" apply (cut_tac a1 a2, auto) done 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 } moreover { assume b1: "(i=p__Inv1)" 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__Inv1\<and>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__27: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntS i)" and a2: "(\<exists> p__Inv1 p__Inv2. p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 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__Inv1 p__Inv2 where a2:"p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i=p__Inv1)\<or>(i~=p__Inv1\<and>i~=p__Inv2)" apply (cut_tac a1 a2, auto) done 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 } moreover { assume b1: "(i=p__Inv1)" 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__Inv1\<and>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__27: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" and a2: "(\<exists> p__Inv1 p__Inv2. p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 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__Inv1 p__Inv2 where a2:"p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i=p__Inv1)\<or>(i~=p__Inv1\<and>i~=p__Inv2)" apply (cut_tac a1 a2, auto) done 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 } moreover { assume b1: "(i=p__Inv1)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Chan2'') p__Inv1) ''Cmd'')) (Const GntE)) (eqn (IVar (Para (Ident ''InvSet'') p__Inv2)) (Const true))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv1\<and>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__27: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i" and a2: "(\<exists> p__Inv1 p__Inv2. p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_StoreVsinv__27: assumes a1: "\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d" and a2: "(\<exists> p__Inv1 p__Inv2. p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_RecvInvAckVsinv__27: assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvInvAck i" and a2: "(\<exists> p__Inv1 p__Inv2. p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendGntSVsinv__27: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendGntS i" and a2: "(\<exists> p__Inv1 p__Inv2. p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendReqE__part__0Vsinv__27: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i" and a2: "(\<exists> p__Inv1 p__Inv2. p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendReqSVsinv__27: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqS i" and a2: "(\<exists> p__Inv1 p__Inv2. p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendGntEVsinv__27: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendGntE N i" and a2: "(\<exists> p__Inv1 p__Inv2. p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__27 p__Inv1 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done end
Complex Laplacian and its eigenmodes are parameterized by $\alpha$ and $k$. --- Theory and math behind the eigenmodes: The simplest possible dynamic behavior of a damped system is the first order differential equation with one term, and it's rate of exponential decay is governed by a rate contant $\beta$: \begin{equation} \label{dampedSys} \frac{dx_{1}(t)}{dt} = -\beta x_{1}(t) \end{equation} Where $x_{1}(t)$ is the average neuronal activation signal between all neurons within a region of interest. Thus we can interpret the above equation as the refractory period after neural discharge. But when viewing the brain as a network of interconnected regions, we want to introduce activities originating from other regions: \begin{equation} \frac{dx_{i}(t)}{dt} = -\beta (x_{i}(t) - \frac{\alpha}{\pmb{deg_i}} \sum_{i,j} c_{i,j} x_{j}(t-\tau^{\nu}_{i,j})) \end{equation} The above equation introduces a connectivity $c_{i,j}$ term, which is normalized by a diagonal degree matrix and scaled by a coupling term $\alpha$. $\alpha$ acts as both a coupling constant as well as a parameter to distinguish the rate of diffusion from connected regions from $\beta$. By introducing connectivity, we also have to take into account the distance between each connected regions, therefore the term $\tau^{\nu}_{i,j}$ is introduced as delay, and is computed by dividing fiber tract distance between regions and signal transmission velocity. Now if we transform the above equation into the Fourier domain, we obtain the follow complex expression: \begin{equation} \begin{aligned} j\omega X(\omega)_{i} = -\beta X(\omega)_{i} + \frac{\alpha}{\pmb{deg_i}} \sum_j c_{i,j} e^{-j\omega \tau^{\nu}_{i,j}} X(\omega)\\ j\omega \bar{X}(\omega) = -\beta (I - \alpha \Delta^{-\frac{1}{2}} C^{*}(\omega)) \bar{X}(\omega)\\ j\omega \bar{X}(\omega) = -B\mathcal{L}\bar{X}(\omega)\\ \end{aligned} \end{equation} Here, we introduced a complex component to our structural connectivity term as delays become phases in the Fourier domain, specifically, $x(t-\tau^{\nu}_{i,j}) \to e^{-j\omega \tau^{\nu}_{i,j}} X(\omega)$, thus we can define a complex connectivity as a function of angular frequency $\omega$ as $C(\omega) = \frac{1}{\pmb{deg}}C^{*}(\omega)$, where $C^{*}(\omega) = c_{i,j}e^{-j\omega \tau^{\nu}_{i,j}}$. By redefining the connectivity term from above, the complex Laplacian $\mathcal{L}(\omega)$ is then defined as $\mathcal{L}(\omega) = I - \alpha C(\omega)$. Next we decompose the complex Laplacian matrix $\mathcal{L}$ into it's eigen modes and eigen values: \begin{equation} \mathcal{L}(\omega) = \pmb(U)(\omega)\pmb{\Lambda}(\omega)\pmb{U}(\omega)^H \end{equation} Where $\pmb{\Lambda}(\omega) = diag([\lambda_1(\omega), ... , \lambda_N(\omega)])$ is a diagonal matrix consisting of the eigen values of the complex Laplacian matrix at angular frequency $\omega$, and $\pmb{U}(\omega)$ are the eigen modes of the complex Laplacian matrix at angular frequency $\omega$. We are going to see how these eigenmodes behave in their parameter space: ```python import numpy as np import pandas as pd import matplotlib.pyplot as plt # spectrome imports from spectrome.brain import Brain from spectrome.utils import functions, path from spectrome.forward import eigenmode, runforward ``` ```python # Some house keeping: data_dir = "../data" # Define frequency range of interest fmin = 2 # 2Hz - 45Hz signal range, filter for this with hbp fmax = 45 fvec = np.linspace(fmin, fmax, 40) # Load Pablo's Yeo 2017 canonical network maps fc_dk = np.load("../data/com_dk.npy", allow_pickle=True).item() fc_dk_normalized = pd.read_csv("../data/DK_dictionary_normalized.csv").set_index( "Unnamed: 0" ) # Define variables for analysis: alpha_vec = np.linspace( 0.5, 4.5, 17 ) # np.linspace(0.5,5,10) # coupling strength values we are going to explore k_vec = np.linspace(0, 100, 11) # wave numbers we are going to explore num_fc = 7 # 7 canonical networks num_emode = 86 # number of eigenmodes, we are using 86 region DK atlas default_k = 20 # default wave number default_alpha = 0.1 # default alpha # define list of canonical network names and re-order the dictionary using these names: fc_names = [ "Limbic", "Default", "Visual", "Fronto \n parietal", "Somato \n motor", "Dorsal \n Attention", "Ventral \n Attention", ] fc_dk_normalized = fc_dk_normalized.reindex( [ "Limbic", "Default", "Visual", "Frontoparietal", "Somatomotor", "Dorsal_Attention", "Ventral_Attention", ] ).fillna(0) # turbo color map turbo = functions.create_turbo_colormap() ``` #### Explore varying coupling strength while keeping wave number default first ```python ## Create Brain object from spectrome alpha_brain = Brain.Brain() alpha_brain.add_connectome(data_dir) alpha_brain.reorder_connectome(alpha_brain.connectome, alpha_brain.distance_matrix) alpha_brain.bi_symmetric_c() alpha_brain.reduce_extreme_dir() ## Compute correlation values: alpha_corr = np.zeros((num_emode, num_fc, len(alpha_vec))) for a_ind in np.arange(0, len(alpha_vec)): alpha_brain.decompose_complex_laplacian(alpha=alpha_vec[a_ind], k=default_k) alpha_corr[:, :, a_ind] = eigenmode.get_correlation_df( alpha_brain.norm_eigenmodes, fc_dk_normalized, method="spearman" ) ``` ```python ## set-up some visualization details dynamic_range = [0.35, 0.65] # for colormap # for coupling strength labels and number of ticks on x-axis: alpha_labels = np.linspace(0.5, 4.5, 3) n_ticks = 3 ## PLOT with plt.style.context("seaborn-paper"): alpha_corr_fig, alpha_ax = plt.subplots(1, 7, figsize=(7.0, 4.0), sharey=True) for i, ax in enumerate(alpha_corr_fig.axes): im = ax.imshow(alpha_corr[:, i, :], vmin=0, vmax=1, cmap=turbo, aspect="auto") ax.xaxis.set_major_locator( plt.LinearLocator(numticks=n_ticks) ) # LinearLocator(numticks = n_ticks) ax.set_yticklabels([0, 1, 10, 20, 30, 40, 50, 60, 70, 80]) ax.xaxis.tick_top() ax.set_xticklabels(alpha_labels, linespacing=0.2) im.set_clim(dynamic_range) plt.suptitle("Coupling Strength", fontsize=12, fontweight="bold", y=1.025) #cbar_ax = alpha_corr_fig.add_axes([1, 0.15, 0.03, 0.7]) #cb = alpha_corr_fig.colorbar(im, cax=cbar_ax, extend="both") #alpha_corr_fig.add_subplot(1, 1, 1, frameon=False) #plt.tick_params(labelcolor="none", which="both", axis = "both", top="off", bottom="off", left="off", right="off") #plt.grid(False) #plt.ylabel("Eigenmode Number", fontsize=12) alpha_corr_fig.text(-0.008, 0.25, 'Eigenmode Number', rotation = 'vertical', fontsize = 12) plt.tight_layout(w_pad = 0.30) plt.savefig("../figures/fig4/coupling_strength.png", dpi=300, bbox_inches="tight") ``` #### Set to default $\alpha$ and explore wave number now: ```python ## Brain object with spectrome k_brain = Brain.Brain() k_brain.add_connectome(data_dir) k_brain.reorder_connectome(k_brain.connectome, k_brain.distance_matrix) k_brain.bi_symmetric_c() k_brain.reduce_extreme_dir() # preallocate empty correlation df k_corr = np.zeros((num_emode, num_fc, len(k_vec))) ## Compute correlations for k in np.arange(0, len(k_vec)): k_brain.decompose_complex_laplacian(alpha=default_alpha, k=k_vec[k], num_ev=86) k_corr[:, :, k] = eigenmode.get_correlation_df( k_brain.norm_eigenmodes, fc_dk_normalized, method="spearman" ) ``` ```python n_ticks = 3 k_labels = [0, 50, 100] ## PLOT with plt.style.context("seaborn-paper"): k_corr_fig, k_ax = plt.subplots(1, 7, figsize=(6.25, 4.0), sharey=True) for i, ax in enumerate(k_corr_fig.axes): im = ax.imshow(k_corr[:, i, :], vmin=0, vmax=1, cmap=turbo, aspect="auto") ax.xaxis.set_major_locator( plt.LinearLocator(numticks=n_ticks) ) # LinearLocator(numticks = n_ticks) ax.set_yticklabels([0, 1, 10, 20, 30, 40, 50, 60, 70, 80]) ax.xaxis.tick_top() ax.set_xticklabels(k_labels) im.set_clim(dynamic_range) if i < 3: ax.set_title(fc_names[i], y=-0.08, fontsize=8, weight="bold") else: ax.set_title(fc_names[i], y=-0.12, fontsize=8, weight="bold") plt.suptitle("Wave Number", fontsize=12, fontweight="bold", y=1.025) cbar_ax = k_corr_fig.add_axes([1, 0.15, 0.03, 0.7]) cb = k_corr_fig.colorbar(im, cax=cbar_ax, extend="both") cb.set_label(r'Spatial Similarity to $\Psi_{CFN}$') #k_corr_fig.add_subplot(1, 1, 1, frameon=False) #plt.tick_params(labelcolor="none", top="off", bottom="off", left="off", right="off") #plt.grid(False) #plt.ylabel("Eigenmode Number", fontsize=12) k_corr_fig.text(-0.008, 0.35, 'Eigenmode Number', rotation = 'vertical', fontsize = 12) plt.tight_layout(w_pad = 0.25) plt.savefig("../figures/fig4/wave_number.png", dpi=300, bbox_inches="tight") ``` Complex Laplacian Eigenmodes --- Find the highest spatial corelation values achieved by the best performing eigenmodes for each canonical network: Compute Spearman correlation values: ```python # pre-allocate an array for spearman R of best performing eigenmodes: params_bestr = np.zeros((len(alpha_vec), len(k_vec), num_fc)) # Create brain object from spectrome with HCP connectome: hcp_brain = Brain.Brain() hcp_brain.add_connectome(data_dir) hcp_brain.reorder_connectome(hcp_brain.connectome, hcp_brain.distance_matrix) hcp_brain.bi_symmetric_c() hcp_brain.reduce_extreme_dir() # for each network, scan through alpha and k values, compute all eigenmode's spearman R # then select the best performing eigenmode's spearman R for i in np.arange(0, num_fc): print('Computing for {} network'.format(fc_dk_normalized.index[i])) for a_ind in np.arange(0, len(alpha_vec)): for k_ind in np.arange(0, len(k_vec)): # get eigenmodes of complex laplacian: hcp_brain.decompose_complex_laplacian(alpha = alpha_vec[a_ind], k = k_vec[k_ind]) # compute spearman correlation spearman_eig = eigenmode.get_correlation_df( hcp_brain.norm_eigenmodes, fc_dk_normalized.iloc[[i]], method = 'spearman' ) params_bestr[a_ind, k_ind, i] = np.max(spearman_eig.values) ``` Visualize in heatmap: ```python dynamic_range = [0.30, 0.65] k_ticks = 11 k_labels = np.linspace(0, 100, 11).astype(int) a_ticks = 3 a_labels = np.linspace(0.5, 4.5, 3) with plt.style.context("seaborn-paper"): corr_fig, corr_ax = plt.subplots(1,7, figsize = (8,5)) for i, ax in enumerate(corr_fig.axes): im = ax.imshow(np.transpose(params_bestr[:,:,i]), vmin = 0, vmax = 1, cmap = turbo, aspect = 'auto') ax.yaxis.set_major_locator(plt.LinearLocator(numticks = k_ticks)) ax.xaxis.tick_top() ax.set_yticklabels(k_labels) ax.xaxis.set_major_locator(plt.LinearLocator(numticks = a_ticks)) ax.set_xticklabels(a_labels) im.set_clim(dynamic_range) if i < 3: ax.set_title(fc_names[i], y=-0.08, fontsize=8, weight="bold") else: ax.set_title(fc_names[i], y=-0.12, fontsize=8, weight="bold") plt.suptitle('Coupling Strength', fontsize = 12, y = 1) cbar_ax = corr_fig.add_axes([1, 0.15, 0.03, 0.7]) cb = corr_fig.colorbar(im, cax=cbar_ax, extend="both") corr_fig.add_subplot(1, 1, 1, frameon=False) plt.tick_params(labelcolor="none", top="off", bottom="off", left="off", right="off") plt.grid(False) plt.ylabel('Wave Number', fontsize = 12) plt.tight_layout() plt.savefig('../figures/fig5/param_bestr.png', dpi = 300, bbox_inches = 'tight') ``` Note - global coupling doesn't affect the best performing eigenmode but may change which eigenmode is the best performing eigenmode as well as the other eigenmodes. Split the wave number parameter into oscillatory frequency and signal transmission velocity since wave number $k$ is defined as $k = \frac{2 \pi f}{\nu}$. Then perform the same exploratory exercise as above: ```python # define parameter ranges: freq_vec = np.linspace(2, 47, 46) nu_vec = np.linspace(1, 20, 21) # define plotting visuals dynamic_range = [0.3, 0.7] f_ticks = 6 f_labels = np.linspace(2, 47, 6).astype(int) nu_ticks = 3 nu_labels = np.linspace(0.5, 20, 3).astype(int) #pre-allocate array for results k_bestr = np.zeros((len(freq_vec), len(nu_vec), num_fc)) # compute spearman Rs: for i in np.arange(0, num_fc): print('Computing for {} network'.format(fc_dk_normalized.index[i])) for f_ind in np.arange(0, len(freq_vec)): for v_ind in np.arange(0, len(nu_vec)): # get eigenmodes of complex laplacian: hcp_brain.decompose_complex_laplacian(alpha = default_alpha, k = None, f = freq_vec[f_ind], speed = nu_vec[v_ind]) # compute spearman correlation spearman_eig = eigenmode.get_correlation_df( hcp_brain.norm_eigenmodes, fc_dk_normalized.iloc[[i]], method = 'spearman' ) k_bestr[f_ind, v_ind, i] = np.max(spearman_eig.values) # Plot as above: with plt.style.context("seaborn-paper"): k_fig, k_ax = plt.subplots(1,7, figsize = (8,4)) for i, ax in enumerate(k_fig.axes): im = ax.imshow(k_bestr[:,:,i], vmin = 0, vmax = 1, cmap = turbo, aspect = 'auto') ax.yaxis.set_major_locator(plt.LinearLocator(numticks = f_ticks)) ax.xaxis.tick_top() ax.set_yticklabels(f_labels) ax.xaxis.set_major_locator(plt.LinearLocator(numticks = nu_ticks)) ax.set_xticklabels(nu_labels) im.set_clim(dynamic_range) if i < 3: ax.set_title(fc_names[i], y=-0.08, fontsize=8, weight="bold") else: ax.set_title(fc_names[i], y=-0.12, fontsize=8, weight="bold") plt.suptitle('Transmission Velocity (m/s)', fontsize = 12, y = 1) cbar_ax = k_fig.add_axes([1, 0.15, 0.03, 0.7]) cb = k_fig.colorbar(im, cax=cbar_ax, extend="both") k_fig.add_subplot(1, 1, 1, frameon=False) plt.tick_params(labelcolor="none", top="off", bottom="off", left="off", right="off") plt.grid(False) plt.ylabel('Frequency (Hz)', fontsize = 12) plt.tight_layout() plt.savefig('../figures/fig5/k_bestr.png', dpi = 300, bbox_inches = 'tight') ```
(* Title: HOL/Auth/n_germanSymIndex_lemma_inv__27_on_rules.thy Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences *) header{*The n_germanSymIndex Protocol Case Study*} theory n_germanSymIndex_lemma_inv__27_on_rules imports n_germanSymIndex_lemma_on_inv__27 begin section{*All lemmas on causal relation between inv__27*} lemma lemma_inv__27_on_rules: assumes b1: "r \<in> rules N" and b2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__27 p__Inv0 p__Inv2)" shows "invHoldForRule s f r (invariants N)" proof - have c1: "(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)\<or> (\<exists> i. i\<le>N\<and>r=n_SendReqS i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvReqE N i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInvAck i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendGntS i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendGntE N i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvGntS i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" apply (cut_tac b1, auto) done moreover { assume d1: "(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_StoreVsinv__27) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendReqSVsinv__27) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendReqE__part__0Vsinv__27) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendReqE__part__1Vsinv__27) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvReqSVsinv__27) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqE N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvReqEVsinv__27) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInv__part__0Vsinv__27) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInv__part__1Vsinv__27) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInvAckVsinv__27) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvInvAckVsinv__27) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendGntS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendGntSVsinv__27) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendGntE N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendGntEVsinv__27) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvGntSVsinv__27) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvGntEVsinv__27) done } ultimately show "invHoldForRule s f r (invariants N)" by satx qed end
"""PSS_utils.py A place to organize methods used by multiple modules """ from __future__ import (absolute_import, division, print_function, unicode_literals) import numpy as np import scipy as sp from astropy import units as u from pint import models #try: # import pyfftw # use_pyfftw = True #except: # use_pyfftw = False def shift_t(y, shift, dt=1): """ Shift timeseries data in time. Shift array, y, in time by amount, shift. For dt=1 units of samples (including fractional samples) are used. Otherwise, shift and dt are assumed to have the same physical units (i.e. seconds). Parameters ---------- y : array like, shape (N,), real Time series data. shift : int or float Amount to shift dt : float Time spacing of samples in y (aka cadence). Returns ------- out : ndarray Time shifted data. Examples -------- >>>shift_t(y, 20) # shift data by 20 samples >>>shift_t(y, 0.35, dt=0.125) # shift data sampled at 8 Hz by 0.35 sec Uses np.roll() for integer shifts and the Fourier shift theorem with real FFT in general. Defined so positive shift yields a "delay". """ if isinstance(shift, int) and dt == 1: out = np.roll(y, shift) else: yfft = np.fft.rfft(y) # hermicity implicitely enforced by rfft fs = np.fft.rfftfreq(len(y), d=dt) phase = -1j*2*np.pi*fs*shift yfft_sh = yfft * np.exp(phase) out = np.fft.irfft(yfft_sh) return out def down_sample(ar, fact): """down_sample(ar, fact) down sample array, ar, by downsampling factor, fact """ #TODO this is fast, but not as general as possible downsampled = ar.reshape(-1, fact).mean(axis=1) return downsampled def rebin(ar, newlen): """rebin(ar, newlen) down sample array, ar, to newlen number of bins This is a general downsampling rebinner, but is slower than down_sample(). 'ar' must be a 1-d array """ newBins = np.linspace(0, ar.size, newlen, endpoint=False) stride = newBins[1] - newBins[0] maxWid = int(np.ceil(stride)) ar_new = np.empty((newlen, maxWid)) # init empty array ar_new.fill(np.nan) # fill with NaNs (no extra 0s in mean) for ii, lbin in enumerate(newBins): rbin = int(np.ceil(lbin + stride)) # fix for potential last bin rounding error if rbin > ar.size: # Not sure how to force this for test... rbin = ar.size lbin = int(np.ceil(lbin)) ar_new[ii, 0:rbin-lbin] = ar[lbin:rbin] return np.nanmean(ar_new, axis=1) # ingnore NaNs in mean def top_hat_width(subband_df, subband_f0, DM): """top_hat_width(subband_df, subband_f0, DM) Returns width of a top-hat pulse to convolve with pulses for dipsersion broadening. Following Lorimer and Kramer, 2005 (sec 4.1.1 and A2.4) subband_df : subband bandwidth (MHz) subband_f0 : subband center frequency (MHz) DM : dispersion measure (pc/cm^3) return top_hat_width (milliseconds) """ D = 4.148808e3 # sec*MHz^2*pc^-1*cm^3, dispersion const width_sec = 2*D * DM * (subband_df) / (subband_f0)**3 return width_sec * 1.0e+3 # ms def savitzky_golay(y, window_size, order, deriv=0, rate=1): # courtesy scipy recipes r"""Smooth (and optionally differentiate) data with a Savitzky-Golay filter. The Savitzky-Golay filter removes high frequency noise from data. It has the advantage of preserving the original shape and features of the signal better than other types of filtering approaches, such as moving averages techniques. Parameters ---------- y : array_like, shape (N,) the values of the time history of the signal. window_size : int the length of the window. Must be an odd integer number. order : int the order of the polynomial used in the filtering. Must be less then `window_size` - 1. deriv: int the order of the derivative to compute (default = 0 means only smoothing) Returns ------- ys : ndarray, shape (N) the smoothed signal (or it's n-th derivative). Notes ----- The Savitzky-Golay is a type of low-pass filter, particularly suited for smoothing noisy data. The main idea behind this approach is to make for each point a least-square fit with a polynomial of high order over a odd-sized window centered at the point. Examples -------- t = np.linspace(-4, 4, 500) y = np.exp( -t**2 ) + np.random.normal(0, 0.05, t.shape) ysg = savitzky_golay(y, window_size=31, order=4) import matplotlib.pyplot as plt plt.plot(t, y, label='Noisy signal') plt.plot(t, np.exp(-t**2), 'k', lw=1.5, label='Original signal') plt.plot(t, ysg, 'r', label='Filtered signal') plt.legend() plt.show() References ---------- .. [1] A. Savitzky, M. J. E. Golay, Smoothing and Differentiation of Data by Simplified Least Squares Procedures. Analytical Chemistry, 1964, 36 (8), pp 1627-1639. .. [2] Numerical Recipes 3rd Edition: The Art of Scientific Computing W.H. Press, S.A. Teukolsky, W.T. Vetterling, B.P. Flannery Cambridge University Press ISBN-13: 9780521880688 """ from math import factorial try: window_size = np.abs(np.int(window_size)) order = np.abs(np.int(order)) except TypeError: # ValueError, msg: raise ValueError("window_size and order have to be of type int") if window_size % 2 != 1 or window_size < 1: raise TypeError("window_size size must be a positive odd number") if window_size < order + 2: raise TypeError("window_size is too small for the polynomials order") order_range = range(order+1) half_window = int((window_size -1) // 2) # precompute coefficients b = np.array([[k**i for i in order_range] for k in range(-half_window, half_window+1)]) m = np.linalg.pinv(b)[deriv] * rate**deriv * factorial(deriv) # pad the signal at the extremes with # values taken from the signal itself firstvals = y[0] - np.abs(y[1:half_window+1][::-1] - y[0]) lastvals = y[-1] + np.abs(y[-half_window-1:-1][::-1] - y[-1]) y = np.concatenate((firstvals, y, lastvals)) return np.convolve(m[::-1], y, mode='valid') def find_nearest(array, value): """Returns the argument of the element in an array nearest to value. For half width at value use array[max:]. """ diff=np.abs(array-value) idx = diff.argmin() if idx == 0 or array[1] < value: idx = 1 return idx def acf2d(array, speed='fast', mode='full', xlags=None, ylags=None): """Courtesy of Michael Lam's PyPulse Calculate the autocorrelation of a 2 dimensional array. """ from scipy.signal import fftconvolve, correlate if speed == 'fast' or speed == 'slow': ones = np.ones(np.shape(array)) # very close for either speed norm = fftconvolve(ones, ones, mode=mode) if speed=='fast': return fftconvolve(array, np.flipud(np.fliplr(array)), mode=mode)/norm else: return correlate(array, array, mode=mode)/norm elif speed == 'exact': #NOTE: (r,c) convention is flipped from (x,y), # also that increasing c is decreasing y LENX = len(array[0]) LENY = len(array) if xlags is None: xlags = np.arange(-1*LENX+1, LENX) if ylags is None: ylags = np.arange(-1*LENY+1, LENY) retval = np.zeros((len(ylags), len(xlags))) for i, xlag in enumerate(xlags): print(xlag) for j, ylag in enumerate(ylags): if ylag > 0 and xlag > 0: A = array[:-1*ylag, xlag:] # the "stationary" array B = array[ylag:, :-1*xlag] elif ylag < 0 and xlag > 0: A = array[-1*ylag:, xlag:] B = array[:ylag, :-1*xlag] elif ylag > 0 and xlag < 0: # optimize later via symmetries A = array[:-1*ylag, :xlag] B = array[ylag:, -1*xlag:] elif ylag < 0 and xlag < 0: A = array[-1*ylag:, :xlag] B = array[:ylag, -1*xlag:] else: # one of the lags is zero if ylag == 0 and xlag > 0: A = array[-1*ylag:, xlag:] B = array[:, :-1*xlag] elif ylag == 0 and xlag < 0: A = array[-1*ylag:, :xlag] B = array[:, -1*xlag:] elif ylag > 0 and xlag == 0: A = array[:-1*ylag, :] B = array[ylag:, -1*xlag:] elif ylag < 0 and xlag == 0: A = array[-1*ylag:, :] B = array[:ylag, -1*xlag:] else: A = array[:, :] B = array[:, :] #print xlag,ylag,A,B C = A*B C = C.flatten() goodinds = np.where(np.isfinite(C))[0] # check for good values retval[j, i] = np.mean(C[goodinds]) return retval def text_search(search_list, header_values, filepath, header_line=0, file_type='txt'): """ Method for pulling value from a txt file. search_list = list of string-type values that demarcate the line in a txt file from which to pull values header_values = string of column headers or array of column numbers (in Python numbering) the values from which to pull filepath = file path of txt file. (string) header_line = line with headers for values. file_type = 'txt' or 'csv' returns: tuple of values matching header values for the search terms given. """ #TODO Make work for other file types. #if file_type == 'txt': # delimiter = '' #elif file_type == 'csv': # delimiter = ',' check = 0 output_values = list() with open(filepath, 'r') as f: # read file to local memory searchfile = f.readlines() # Find Column Numbers from column names if any(isinstance(elem, str) for elem in header_values): column_num = [] parsed_header = searchfile[header_line].split() for ii, header in enumerate(header_values): column_num.append(parsed_header.index(header)) else: column_num = np.array(header_values) # Find Values using search keys and column numbers. for line in searchfile: if all(ii in line for ii in search_list): info = line.split() for jj, value in enumerate(column_num): output_values.append(info[value]) check += 1 if check == 0: raise ValueError('Combination {0} '.format(search_list)+' not found in \ same line of text file.') if check > 1: raise ValueError('Combination {0} '.format(search_list)+' returned \ multiple results in txt file.') return tuple([float(i) for i in output_values]) def make_quant(param, default_unit): """ Convenience function to intialize a parameter as an astropy quantity. Parameters ---------- param : attribute Parameter to initialize. default_unit : string Name of an astropy unit, set as default for this parameter. Returns ------- An astropy quantity Examples -------- self.f0 = make_quant(f0,'MHz') """ default_unit = u.core.Unit(default_unit) if hasattr(param, 'unit'): try: param.to(default_unit) except u.UnitConversionError: raise ValueError("Quantity {0} with incompatible unit {1}" .format(param, default_unit)) quantity = param else: quantity = param * default_unit return quantity def get_pint_models(psr_name, psr_file_path): """Function that returns pint model given a specific pulsar""" # will need to add section for J1713 T2 file. gls is not file wanted for this specfic pulsar. model_name = "{0}{1}_NANOGrav_11yv1.gls.par".format(psr_file_path,psr_name) par_model = models.get_model(model_name) return par_model def make_par(signal, pulsar, outpar = "simpar.par"): """ Function to create a par file for simulated pulsar. TO DO: Will need to update when additional delays are added Parameters ---------- signal : class PsrSigSim Signal class object pulsar : class PsrSigSim Pulsar class object outpar : string Name of output par file. """ # Get parameters and other things that should go into this file par_lines = [] par_lines.append("PSR %s\n" % (pulsar.name)) par_lines.append("LAMBDA 10.0\n" ) # Default for now par_lines.append("BETA 10.0\n" ) # Default for now par_lines.append("PMLAMBDA 0.0\n" ) # Default for now par_lines.append("PMBETA 0.0\n" ) # Default for now par_lines.append("PX 0.0\n" ) # Default for now par_lines.append("POSEPOCH 56000.0\n" ) # Default for now par_lines.append("F0 %s\n" % (1.0/pulsar.period.value)) par_lines.append("PEPOCH 56000.0\n" ) # Default for now par_lines.append("START 50000.0\n" ) # Default for now par_lines.append("FINISH 60000.0\n" ) # Default for now par_lines.append("DM %s\n" % (signal.dm.value)) par_lines.append("EPHEM DE436\n" ) # Default for now par_lines.append("SOLARN0 0.00\n" ) # Default for now par_lines.append("ECL IERS2010\n" ) # Default for now par_lines.append("CLK TT(BIPM2015) \n" ) # Default for now par_lines.append("UNITS TDB\n" ) # Default for now par_lines.append("TIMEEPH FB90\n" ) # Default for now par_lines.append("T2CMETHOD TEMPO\n" ) # Default for now par_lines.append("CORRECT_TROPOSPHERE N\n" ) # Default for now par_lines.append("PLANET_SHAPIRO N\n" ) # Default for now par_lines.append("DILATEFREQ N\n" ) # Default for now par_lines.append("TZRMJD 56000.0\n" ) # Default for now par_lines.append("TZRFRQ 1500.0\n" ) # Default for now par_lines.append("TZRSITE @\n" ) # Default for now par_lines.append("MODE 1\n" ) # Default for now # Write out the file with open(outpar, 'w') as op: op.writelines(par_lines) op.close()
module Mergesort import Data.Vect import Lecture.Evens --Takes the first m elements from a vector Vecttake : (m:Nat)->Vect n elem->Vect m elem Vecttake Z xs = [] Vecttake (S k) (x::xs) = x::(Vecttake k xs) --Takes the last m elements from a vector Vecttakefromlast :(m:Nat)->Vect n elem ->Vect m elem Vecttakefromlast m xs = reverse (Vecttake m (reverse xs)) insertend : (x:elem)->Vect n elem->Vect (S n) elem insertend x [] = [x] insertend x (y :: xs) = y::(insertend x xs) half : (n: Nat) -> IsEven n -> Nat half Z ZEven = 0 half (S (S k)) (SSEven k x) = S (half k x) nOrSnEven: (n: Nat) -> Either (IsEven n) (IsEven (S n)) nOrSnEven Z = Left ZEven nOrSnEven (S k) = case (nOrSnEven k) of (Left l) => Right (SSEven k l) (Right r) => Left r --Defined in class. This is used to split the input vector into two parts. --The length of the first part is halfRoof n. halfRoof: Nat -> Nat halfRoof n = case (nOrSnEven n) of (Left nEven) => half n nEven (Right snEven) => half (S n) snEven --function that returns (n - halfRoof n) i.e. the length of the second part --after input vector is split. halfRoofComplement : Nat -> Nat halfRoofComplement Z = Z halfRoofComplement (S k) = halfRoof k --function that splits a vector into two parts at its mid point. --if n is even, it gives two halves of length n/2 each. --if n is odd, the first half is (n+1)/2 length and the second half is --(n-1)/2 length halfVect : Vect n elem -> ((Vect (halfRoof n) elem), (Vect (halfRoofComplement n) elem)) halfVect {n} xs = ((Vecttake (halfRoof n) xs), (Vecttakefromlast (halfRoofComplement n) xs)) --this function is to cast a vector from one type to another sillycast: (v1:(Vect ((S k) + j) elem)) ->( Vect (k+ (S j)) elem) sillycast {k} {j} v1 = (Vecttake k v1) ++ (Vecttakefromlast (S j) v1) --function to cast a vector from one type to another. --makes the vector obtained on applying merge to two halves same as --the type of the input vector. sillycast2 : (Vect ((halfRoof n) + (halfRoofComplement n)) elem) -> Vect n elem sillycast2 {n} xs = Vecttake n xs --The merge function merge1 :Ord elem =>Vect n elem ->Vect m elem ->Vect (n+m) elem merge1 [] ys = ys merge1 (x :: xs) [] = (x::xs)++[] merge1 {n= (S k)}{m= (S j)} (x :: xs) (y :: ys) = case x<=y of False => y::(sillycast( (merge1 (x::xs) ys))) True => x::(merge1 xs (y::ys)) --The mergesort function mergesort :Ord elem => Vect n elem -> Vect n elem mergesort [] = [] mergesort [x] = [x] mergesort xs = sillycast2 (merge1 (mergesort (fst(halfVect xs))) (mergesort (snd(halfVect xs))))
theory ComputationCon imports "SmallStepCon" begin type_synonym ('g,'l) c_state = "('g\<times>'l)\<times>('l list)" type_synonym ('g, 'l, 'p,'f,'e) config_gs = "('g\<times>'l,'p,'f,'e)com \<times> (('g,'l) c_state,'f) xstate" (* inductive "step_e"::"[('g\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \<Rightarrow> bool" ("_\<turnstile>\<^sub>c (_ \<rightarrow>\<^sub>e/ _)" [81,81,81] 100) for \<Gamma>::"('g\<times>'l,'p,'f,'e) body" where Env:"(\<forall>ns'. t'\<noteq>Normal ns' \<or> (snd (fst ns) =snd (fst ns') \<and> length (snd ns) = length (snd ns'))) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (Ps, Normal ns) \<rightarrow>\<^sub>e (Ps, t')" |Env_n: "(\<forall>ns. t\<noteq>Normal ns) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (Ps, t) \<rightarrow>\<^sub>e (Ps, t)" inductive "step_e1"::"[('g\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \<Rightarrow> bool" ("_\<turnstile>\<^sub>c (_ \<rightarrow>\<^sub>e\<^sub>1/ _)" [81,81,81] 100) for \<Gamma>::"('g\<times>'l,'p,'f,'e) body" where Env1:"(\<forall>ns'. t'\<noteq>Normal ns') \<or> (\<exists>ns'. t'=Normal ns' \<and> (snd (fst ns) =snd (fst ns') \<and> length (snd ns) = length (snd ns'))) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (Ps, Normal ns) \<rightarrow>\<^sub>e\<^sub>1 (Ps, t')" |Env_n1: "(\<forall>ns. t\<noteq>Normal ns) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (Ps, t) \<rightarrow>\<^sub>e\<^sub>1 (Ps, t)" inductive "step_e2"::"[('g\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \<Rightarrow> bool" ("_\<turnstile>\<^sub>c (_ \<rightarrow>\<^sub>e\<^sub>2/ _)" [81,81,81] 100) for \<Gamma>::"('g\<times>'l,'p,'f,'e) body" where Env:"(\<forall>ns'. t'\<noteq>Normal ns' \<or> t'\<noteq>Abrupt ns') \<or> (\<exists>ns'. t'=Normal ns' \<and> snd (fst ns) =snd (fst ns') \<and> length (snd ns) = length (snd ns')) \<or> (\<exists>ns'. t'=Abrupt ns' \<and> length (snd ns) = length (snd ns')) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (Ps, Normal ns) \<rightarrow>\<^sub>e\<^sub>2 (Ps, t')" |Env_n: "(\<forall>ns. t\<noteq>Normal ns) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (Ps, t) \<rightarrow>\<^sub>e\<^sub>2 (Ps, t)" inductive "step_e3"::"[('g\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \<Rightarrow> bool" ("_\<turnstile>\<^sub>c (_ \<rightarrow>\<^sub>e\<^sub>3/ _)" [81,81,81] 100) for \<Gamma>::"('g\<times>'l,'p,'f,'e) body" where Env:"(\<forall>ns'. (t'\<noteq>Normal ns' \<and> t'\<noteq>Abrupt ns') \<or> (t'=Normal ns' \<and> snd (fst ns) =snd (fst ns') \<and> length (snd ns) = length (snd ns')) \<or> (t'=Abrupt ns' \<and> length (snd ns) = length (snd ns'))) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (Ps, Normal ns) \<rightarrow>\<^sub>e\<^sub>3 (Ps, t')" |Env_n: "(\<forall>ns. t\<noteq>Normal ns) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (Ps, t) \<rightarrow>\<^sub>e\<^sub>3 (Ps, t)" *) inductive "step_e"::"[('g\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \<Rightarrow> bool" ("_\<turnstile>\<^sub>c (_ \<rightarrow>\<^sub>e/ _)" [81,81,81] 100) for \<Gamma>::"('g\<times>'l,'p,'f,'e) body" where Env:"(\<forall>ns'. (t'\<noteq>Normal ns' \<and> t'\<noteq>Abrupt ns') \<or> (t'=Normal ns' \<and> snd (fst ns) =snd (fst ns') \<and> length (snd ns) = length (snd ns')) \<or> (t'=Abrupt ns' \<and> length (snd ns) = length (snd ns'))) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (Ps, Normal ns) \<rightarrow>\<^sub>e (Ps, t')" |Env_n: "(\<forall>ns. t\<noteq>Normal ns) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (Ps, t) \<rightarrow>\<^sub>e (Ps, t)" lemma "(\<forall>ns'. (t'\<noteq>Normal ns' \<and> t'\<noteq>Abrupt ns') \<or> (t'=Normal ns' \<longrightarrow> snd (fst ns) =snd (fst ns') \<and> length (snd ns) = length (snd ns')) \<or> (t'=Abrupt ns' \<longrightarrow> length (snd ns) = length (snd ns'))) = True" by auto (* lemma "(\<forall>ns'. (t'\<noteq>Normal ns' \<and> t'\<noteq>Abrupt ns') \<or> (t'=Normal ns' \<and> snd (fst ns) =snd (fst ns') \<and> length (snd ns) = length (snd ns')) \<or> (t'=Abrupt ns' \<and> length (snd ns) = length (snd ns'))) = True" sorry *) lemma "(\<forall>ns'. t'\<noteq>Normal ns' \<or> t'\<noteq>Abrupt ns') \<or> (\<exists>ns'. t'=Normal ns' \<and> snd (fst ns) =snd (fst ns') \<and> length (snd ns) = length (snd ns')) \<or> (\<exists>ns'. t'=Abrupt ns' \<and> length (snd ns) = length (snd ns')) = (\<forall>ns'. t'\<noteq>Normal ns' \<or> t'\<noteq>Abrupt ns' \<or> (t'=Normal ns' \<longrightarrow> snd (fst ns) =snd (fst ns') \<and> length (snd ns) = length (snd ns')) \<or> (t'=Abrupt ns' \<longrightarrow> length (snd ns) = length (snd ns')))" by auto lemma "(\<forall>ns'. t'\<noteq>Normal ns' \<or> (snd (fst ns) =snd (fst ns') \<and> length (snd ns) = length (snd ns'))) = (\<forall>ns'. t'\<noteq>Normal ns') \<or> (\<exists>ns'. t'=Normal ns' \<and> (snd (fst ns) =snd (fst ns') \<and> length (snd ns) = length (snd ns')))" by auto lemma etranE: "\<Gamma>\<turnstile>\<^sub>c c \<rightarrow>\<^sub>e c' \<Longrightarrow> (\<And>P s t. c = (P, s) \<Longrightarrow> c' = (P, t) \<Longrightarrow> Q) \<Longrightarrow> Q" by (induct c, induct c', erule step_e.cases, blast) inductive_cases stepe_Normal_elim_cases [cases set]: "\<Gamma>\<turnstile>\<^sub>c(Ps,Normal s) \<rightarrow>\<^sub>e (Ps,t)" (* inductive_cases stepe1_Normal_elim_cases [cases set]: "\<Gamma>\<turnstile>\<^sub>c(Ps,Normal s) \<rightarrow>\<^sub>e\<^sub>1 (Ps,t)" inductive_cases stepe2_Normal_elim_cases [cases set]: "\<Gamma>\<turnstile>\<^sub>c(Ps,Normal s) \<rightarrow>\<^sub>e\<^sub>2 (Ps,t)" inductive_cases stepe3_Normal_elim_cases [cases set]: "\<Gamma>\<turnstile>\<^sub>c(Ps,Normal s) \<rightarrow>\<^sub>e\<^sub>3 (Ps,t)" *) inductive_cases stepe_elim_cases [cases set]: "\<Gamma>\<turnstile>\<^sub>c(Ps,s) \<rightarrow>\<^sub>e (Ps,t)" inductive_cases stepe_elim_cases_normal_abrupt [cases set]: "\<Gamma>\<turnstile>\<^sub>c(Ps,Normal s) \<rightarrow>\<^sub>e (Ps,Abrupt t)" inductive_cases stepe_not_norm_elim_cases: "\<Gamma>\<turnstile>\<^sub>c(Ps,s) \<rightarrow>\<^sub>e (Ps,Abrupt t)" "\<Gamma>\<turnstile>\<^sub>c(Ps,s) \<rightarrow>\<^sub>e (Ps,Stuck)" "\<Gamma>\<turnstile>\<^sub>c(Ps,s) \<rightarrow>\<^sub>e (Ps,Fault t)" "\<Gamma>\<turnstile>\<^sub>c(Ps,s) \<rightarrow>\<^sub>e (Ps,Normal t)" thm stepe_Normal_elim_cases lemma env_c_c'_false: assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', s')" shows "~(c=c') \<Longrightarrow> P" using step_m etranE by blast lemma eenv_normal_s'_normal_s: assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', Normal s')" shows "(\<And>s1. s\<noteq>Normal s1) \<Longrightarrow> P" using step_m using env_c_c'_false stepe_not_norm_elim_cases(4) by blast lemma eenv_eq_length: assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, Normal s) \<rightarrow>\<^sub>e (c', Normal s')" and normal_s:"s= ((g,l),ls)" and normal_s':"s'= ((g',l'),ls')" shows "(length ls \<noteq> length ls') \<Longrightarrow> P" using step_m normal_s normal_s' using env_c_c'_false stepe_Normal_elim_cases by fastforce lemma env_normal_s'_normal_s: assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', Normal s') " shows "\<exists>s1. s= Normal s1" using step_m using env_c_c'_false stepe_not_norm_elim_cases(4) by blast lemma env_c_c': assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', s')" shows "(c=c')" using env_c_c'_false step_m by fastforce lemma env_normal_s: assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', s')" and s: "s\<noteq>s'" shows "\<exists>sa. s = Normal sa" using stepe_elim_cases[OF step_m[simplified env_c_c'[OF step_m]]] s by metis lemma env_not_normal_s: assumes a1:"\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', s')" and a2:"(\<forall>t. s\<noteq>Normal t)" shows "s=s'" using a1 a2 by (cases rule:step_e.cases,auto) lemma env_normal_same_local_length: assumes a1:"\<Gamma>\<turnstile>\<^sub>c (c, Normal ((g,l),ls)) \<rightarrow>\<^sub>e (c', Normal ((g',l'),ls'))" shows "l=l' \<and> length ls = length ls'" using a1 by (cases rule:step_e.cases,auto) lemma env_normal_same_local: assumes a1:"\<Gamma>\<turnstile>\<^sub>c (c, Normal ((g,l),ls)) \<rightarrow>\<^sub>e (c', Normal ((g',l'),ls'))" shows "l=l'" using a1 env_normal_same_local_length by fast lemma env_normal_same_length: assumes a1:"\<Gamma>\<turnstile>\<^sub>c (c, Normal ((g,l),ls)) \<rightarrow>\<^sub>e (c', Normal ((g',l'),ls'))" shows "length ls = length ls'" using a1 env_normal_same_local_length by fast lemma env_not_normal_s_not_norma_t: assumes a1:"\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', s')" and a2:"(\<forall>t. s\<noteq>Normal t)" shows "(\<forall>t. s'\<noteq>Normal t)" using a1 a2 env_not_normal_s by blast lemma env_normal_intro: assumes a1:"length ls = length ls'" shows "\<Gamma>\<turnstile>\<^sub>c (c, Normal ((g,l),ls)) \<rightarrow>\<^sub>e (c, Normal ((g',l),ls'))" using a1 by (auto intro: step_e.intros) lemma env_abrupt_intro: assumes a1:"length ls = length ls'" shows "\<Gamma>\<turnstile>\<^sub>c (c, Normal ((g,l),ls)) \<rightarrow>\<^sub>e (c, Abrupt ((g',l),ls'))" using a1 by (auto intro: step_e.intros) thm stepe_elim_cases_normal_abrupt lemma env_len_ls: assumes a0: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c, Abrupt ((g',l),ls'))" shows "\<exists>sn. (s = Normal sn \<or> s =Abrupt sn) \<and> length (snd sn) = length ls'" using a0 by (auto elim: stepe_not_norm_elim_cases(1)) lemma env_intro:"\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (P, t) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (Q, s) \<rightarrow>\<^sub>e (Q, t)" by (auto elim: stepe_elim_cases simp add: Env Env_n) lemma stepe_not_Fault_f_end: assumes step_e: "\<Gamma>\<turnstile>\<^sub>c (c\<^sub>1, s) \<rightarrow>\<^sub>e (c\<^sub>1', s')" shows "s'\<notin> Fault ` f \<Longrightarrow> s \<notin> Fault ` f" proof (cases s) case (Fault f') assume s'_f:"s' \<notin> Fault ` f" and "s = Fault f'" then have "s=s'" using step_e env_normal_s by blast thus ?thesis using s'_f Fault by blast qed (auto) lemma snormal_enviroment: "(\<exists>nsa. s = Normal nsa \<and> (\<forall>nsa'. sa = Normal nsa' \<longrightarrow> snd (fst nsa) =snd (fst nsa') \<and> length (snd nsa) = length (snd nsa')) \<and> (\<forall>nsa'. sa = Abrupt nsa' \<longrightarrow> length (snd nsa) = length (snd nsa'))) \<or> (s = sa \<and> (\<forall>sa. s \<noteq> Normal sa)) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (x, s) \<rightarrow>\<^sub>e (x, sa)" apply (cases s) apply (auto simp add: Env Env_n) apply (cases sa, auto) apply (simp add: env_normal_intro) by (cases s, auto simp add: Env Env_n) lemma not_step_c_env: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c, s') \<Longrightarrow> (\<And>sa. \<not>(s=Normal sa)) \<Longrightarrow> (\<And>sa. \<not>(s'=Normal sa))" by (rule stepe_elim_cases, auto) lemma step_c_env_not_normal_eq_state: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c, s') \<Longrightarrow> (\<And>sa. \<not>(s=Normal sa)) \<Longrightarrow> s=s'" by (fastforce elim:stepe_elim_cases) definition final_glob:: "('g,'l,'p,'f,'e) config_gs \<Rightarrow> bool" where "final_glob cfg \<equiv> (fst cfg=Skip \<or> ((fst cfg=Throw) \<and> (\<exists>s. snd cfg=Normal s)))" lemma final_eq:"snd cfg = Normal s \<Longrightarrow> final_glob cfg = SmallStepCon.final (fst cfg, Normal (fst s))" unfolding final_def final_glob_def SmallStepCon.final_def by auto section \<open> computation with enviroment \<close> primrec toSeq ::"(('g\<times>'l)\<times>('l list),'f) xstate \<Rightarrow> (('g\<times>'l),'f) xstate" where "toSeq (Normal ns) = Normal (fst ns)" |"toSeq (Abrupt ns) = Abrupt (fst ns)" |"toSeq (Fault f) = Fault f" |"toSeq Stuck = Stuck" lemma assumes a0:"\<forall>ns ns'. (s = Normal ns \<or> s = Abrupt ns) \<and> (s' = Normal ns' \<or> s' = Abrupt ns') \<longrightarrow> snd ns = snd ns'" and a1:"toSeq s = toSeq s'" shows eq_toSeq:"s = s'" using a0 a1 apply (cases s) by (cases s', auto)+ lemma toSeq_not_in_fault: "s \<notin> Fault ` f = (toSeq s \<notin> Fault ` f)" by (cases s, auto) lemma toSeq_not_stuck: "s \<noteq> Stuck = (toSeq s \<noteq> Stuck)" by (cases s, auto) lemma toSeq_not_fault: "(\<forall>f. s\<noteq> Fault f) = (\<forall>f. toSeq s \<noteq> Fault f)" by (cases s, auto) lemma toSeq_not_Normal: "(\<forall>na. s\<noteq> Normal na) = (\<forall>na. toSeq s \<noteq> Normal na)" by (cases s, auto) lemma toSeq_not_abrupt: "(\<forall>na. s\<noteq> Abrupt na) = (\<forall>na. toSeq s \<noteq> Abrupt na)" by (cases s, auto) inductive "step_ce"::"[('g\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \<Rightarrow> bool" ("_\<turnstile>\<^sub>c (_ \<rightarrow>\<^sub>c\<^sub>e/ _)" [81,81,81] 100) for \<Gamma>::"('g\<times>'l,'p,'f,'e) body" where c_step: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, (toSeq s)) \<rightarrow> (c', toSeq s'); \<forall>ns ns'. (s = Normal ns \<or> s = Abrupt ns) \<and> (s' = Normal ns' \<or> s' = Abrupt ns') \<longrightarrow> snd ns = snd ns'\<rbrakk> \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (c,s) \<rightarrow>\<^sub>c\<^sub>e (c',s')" |e_step: "\<Gamma>\<turnstile>\<^sub>c (c,s) \<rightarrow>\<^sub>e (c',s') \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (c,s) \<rightarrow>\<^sub>c\<^sub>e (c',s') " (* inductive "step_ce"::"[('g\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \<Rightarrow> bool" ("_\<turnstile>\<^sub>c (_ \<rightarrow>\<^sub>c\<^sub>e/ _)" [81,81,81] 100) for \<Gamma>::"('g\<times>'l,'p,'f,'e) body" where c_stepN: "\<Gamma>\<turnstile>\<^sub>c ((c, (Normal l::(('g\<times>'l),'f) xstate))) \<rightarrow> (c', Normal l') \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (c,Normal (l,ls)) \<rightarrow>\<^sub>c\<^sub>e (c',Normal (l',ls))" |c_stepA: "\<Gamma>\<turnstile>\<^sub>c ((c, (Normal l::(('g\<times>'l),'f) xstate))) \<rightarrow> (c', Abrupt l') \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (c,Normal (l,ls)) \<rightarrow>\<^sub>c\<^sub>e (c',Abrupt (l',ls))" |c_stepF: "\<Gamma>\<turnstile>\<^sub>c ((c, (Normal l::(('g\<times>'l),'f) xstate))) \<rightarrow> (c', Fault F ) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (c,Normal (l,ls)) \<rightarrow>\<^sub>c\<^sub>e (c',Fault F)" |c_stuck: "\<Gamma>\<turnstile>\<^sub>c ((c, (Normal l::(('g\<times>'l),'f) xstate))) \<rightarrow> (c', Stuck) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (c,Normal (l,ls)) \<rightarrow>\<^sub>c\<^sub>e (c',Stuck)" |c_stuck': "\<Gamma>\<turnstile>\<^sub>c ((c,Stuck)) \<rightarrow> (c', s') \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (c,Stuck) \<rightarrow>\<^sub>c\<^sub>e (c',Stuck)" |c_F: "\<Gamma>\<turnstile>\<^sub>c ((c,Fault F)) \<rightarrow> (c', Fault F) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (c,Fault F) \<rightarrow>\<^sub>c\<^sub>e (c',Fault F)" |c_a: "\<Gamma>\<turnstile>\<^sub>c ((c, (Abrupt l::(('g\<times>'l),'f) xstate))) \<rightarrow> (c', Abrupt l) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (c,Abrupt (l,ls)) \<rightarrow>\<^sub>c\<^sub>e (c',Abrupt (l,ls))" |e_step: "\<Gamma>\<turnstile>\<^sub>c (c,s) \<rightarrow>\<^sub>e (c',s') \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (c,s) \<rightarrow>\<^sub>c\<^sub>e (c',s') " *) lemmas step_ce_induct = step_ce.induct [of _ "(c,s)" "(c',s')", split_format (complete), case_names c_step e_step, induct set] inductive_cases step_ce_elim_cases [cases set]: "\<Gamma>\<turnstile>\<^sub>c cf0 \<rightarrow>\<^sub>c\<^sub>e cf1" inductive_cases step_ce_elim_cases1 [cases set]: "\<Gamma>\<turnstile>\<^sub>c (c,Normal (g,l)) \<rightarrow>\<^sub>c\<^sub>e (c',Normal (g',l'))" "\<Gamma>\<turnstile>\<^sub>c (c,Normal (g,l)) \<rightarrow>\<^sub>c\<^sub>e (c',Abrupt(g',l'))" "\<Gamma>\<turnstile>\<^sub>c (c,Normal (g,l)) \<rightarrow>\<^sub>c\<^sub>e (c',Fault f)" "\<Gamma>\<turnstile>\<^sub>c (c,Normal (g,l)) \<rightarrow>\<^sub>c\<^sub>e (c',Stuck)" "\<Gamma>\<turnstile>\<^sub>c (c,Abrupt (g,l)) \<rightarrow>\<^sub>c\<^sub>e (c',Normal (g',l'))" "\<Gamma>\<turnstile>\<^sub>c (c,Abrupt (g,l)) \<rightarrow>\<^sub>c\<^sub>e (c',Stuck)" "\<Gamma>\<turnstile>\<^sub>c (c,Abrupt (g,l)) \<rightarrow>\<^sub>c\<^sub>e (c',Abrupt (g',l'))" thm step_ce_elim_cases1 step_ce_elim_cases lemma step_ce_elim_casesA1[cases set,elim]: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Normal (g, l)) \<rightarrow>\<^sub>c\<^sub>e (c', Normal (g', l')); \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, (Normal g)) \<rightarrow> (c', (Normal g')); l=l' \<rbrakk> \<Longrightarrow> P; \<Gamma>\<turnstile>\<^sub>c (c, Normal (g, l)) \<rightarrow>\<^sub>e (c', Normal (g', l')) \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" by (auto elim: step_ce_elim_cases) lemma step_ce_elim_casesA2[cases set,elim]: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Normal (g, l)) \<rightarrow>\<^sub>c\<^sub>e (c', Abrupt (g', l')); \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, (Normal g)) \<rightarrow> (c', (Abrupt g')); l=l' \<rbrakk> \<Longrightarrow> P; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Normal (g, l)) \<rightarrow>\<^sub>e (c', Abrupt (g', l'))\<rbrakk> \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" by (auto elim: step_ce_elim_cases) lemma step_ce_elim_casesA3[cases set,elim]: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Normal (g, l)) \<rightarrow>\<^sub>c\<^sub>e (c', Stuck); \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, (Normal g)) \<rightarrow> (c', Stuck)\<rbrakk> \<Longrightarrow> P; \<Gamma>\<turnstile>\<^sub>c (c, Normal (g, l)) \<rightarrow>\<^sub>e (c', Stuck) \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" by (auto elim: step_ce_elim_cases) lemma step_ce_elim_casesA4[cases set,elim]: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Normal (g, l)) \<rightarrow>\<^sub>c\<^sub>e (c', Fault f); \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, (Normal g)) \<rightarrow> (c', Fault f)\<rbrakk> \<Longrightarrow> P; \<Gamma>\<turnstile>\<^sub>c (c, Normal (g, l)) \<rightarrow>\<^sub>e (c', Fault f) \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" by (auto elim: step_ce_elim_cases) lemma step_ce_elim_casesA5[cases set,elim]: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Abrupt (g, l)) \<rightarrow>\<^sub>c\<^sub>e (c', Abrupt (g', l')); \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, (Abrupt g)) \<rightarrow> (c', (Abrupt g')); l=l' \<rbrakk> \<Longrightarrow> P; \<Gamma>\<turnstile>\<^sub>c (c, Abrupt (g, l)) \<rightarrow>\<^sub>e (c', Abrupt (g', l')) \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" by (auto elim: step_ce_elim_cases) lemma step_ce_elim_casesA6[cases set,elim]: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Abrupt (g, l)) \<rightarrow>\<^sub>c\<^sub>e (c', Normal (g', l')); \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, (Abrupt g)) \<rightarrow> (c', Normal g'); l=l'\<rbrakk> \<Longrightarrow> P; \<Gamma>\<turnstile>\<^sub>c (c, Abrupt (g, l)) \<rightarrow>\<^sub>e (c', Normal (g', l')) \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" by (auto elim: step_ce_elim_cases) lemma step_ce_elim_casesA7[cases set,elim]: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Abrupt (g, l)) \<rightarrow>\<^sub>c\<^sub>e (c', Fault f); \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, (Abrupt g)) \<rightarrow> (c', Fault f)\<rbrakk> \<Longrightarrow> P; \<Gamma>\<turnstile>\<^sub>c (c, Abrupt (g, l)) \<rightarrow>\<^sub>e (c', Fault f) \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" by (auto elim: step_ce_elim_cases) lemma step_ce_elim_casesA8[cases set,elim]: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Abrupt (g, l)) \<rightarrow>\<^sub>c\<^sub>e (c', Stuck); \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, (Abrupt g)) \<rightarrow> (c', Stuck)\<rbrakk> \<Longrightarrow> P; \<Gamma>\<turnstile>\<^sub>c (c, Abrupt (g, l)) \<rightarrow>\<^sub>e (c', Stuck) \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" by (auto elim: step_ce_elim_cases) lemma step_ce_elim_casesA9[cases set,elim]: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Fault f) \<rightarrow>\<^sub>c\<^sub>e (c', Fault f); \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Fault f) \<rightarrow> (c', Fault f)\<rbrakk> \<Longrightarrow> P; \<Gamma>\<turnstile>\<^sub>c (c, Fault f) \<rightarrow>\<^sub>e (c', Fault f) \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" by (auto elim: step_ce_elim_cases) lemma step_ce_elim_casesA10[cases set,elim]: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Fault f) \<rightarrow>\<^sub>c\<^sub>e (c', Stuck); \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Fault f) \<rightarrow> (c', Stuck)\<rbrakk> \<Longrightarrow> P; \<Gamma>\<turnstile>\<^sub>c (c, Fault f) \<rightarrow>\<^sub>e (c', Stuck) \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" by (auto elim: step_ce_elim_cases) lemma step_ce_elim_casesA11[cases set,elim]: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Fault f) \<rightarrow>\<^sub>c\<^sub>e (c', Normal (g,l)); \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Fault f) \<rightarrow> (c', Normal g)\<rbrakk> \<Longrightarrow> P; \<Gamma>\<turnstile>\<^sub>c (c, Fault f) \<rightarrow>\<^sub>e (c', Normal (g,l)) \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" by (auto elim: step_ce_elim_cases) lemma step_ce_elim_casesA12[cases set,elim]: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Fault f) \<rightarrow>\<^sub>c\<^sub>e (c', Abrupt (g,l)); \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Fault f) \<rightarrow> (c', Abrupt g)\<rbrakk> \<Longrightarrow> P; \<Gamma>\<turnstile>\<^sub>c (c, Fault f) \<rightarrow>\<^sub>e (c', Abrupt (g,l)) \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" by (auto elim: step_ce_elim_cases) lemma step_ce_elim_casesA13[cases set,elim]: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Stuck) \<rightarrow>\<^sub>c\<^sub>e (c', Fault f); \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Stuck) \<rightarrow> (c', Fault f)\<rbrakk> \<Longrightarrow> P; \<Gamma>\<turnstile>\<^sub>c (c, Stuck) \<rightarrow>\<^sub>e (c', Fault f) \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" by (auto elim: step_ce_elim_cases) lemma step_ce_elim_casesA14[cases set,elim]: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Stuck) \<rightarrow>\<^sub>c\<^sub>e (c', Stuck); \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Stuck) \<rightarrow> (c', Stuck)\<rbrakk> \<Longrightarrow> P; \<Gamma>\<turnstile>\<^sub>c (c, Stuck) \<rightarrow>\<^sub>e (c', Stuck) \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" by (auto elim: step_ce_elim_cases) lemma step_ce_elim_casesA15[cases set,elim]: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Stuck) \<rightarrow>\<^sub>c\<^sub>e (c', Normal (g,l)); \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Stuck) \<rightarrow> (c', Normal g)\<rbrakk> \<Longrightarrow> P; \<Gamma>\<turnstile>\<^sub>c (c, Stuck) \<rightarrow>\<^sub>e (c', Normal (g,l)) \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" by (auto elim: step_ce_elim_cases) lemma step_ce_elim_casesA16: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Stuck) \<rightarrow>\<^sub>c\<^sub>e (c', Abrupt (g,l)); \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, Stuck) \<rightarrow> (c', Abrupt g)\<rbrakk> \<Longrightarrow> P; \<Gamma>\<turnstile>\<^sub>c (c, Stuck) \<rightarrow>\<^sub>e (c', Abrupt (g,l)) \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" by (auto elim: step_ce_elim_cases) lemma step_dest: assumes a0:"\<Gamma>\<turnstile>\<^sub>c(P,Normal s) \<rightarrow>\<^sub>c\<^sub>e (Q,t)" shows "\<Gamma>\<turnstile>\<^sub>c(P,Normal s) \<rightarrow>\<^sub>e (Q,t) \<or> (\<Gamma>\<turnstile>\<^sub>c (P, toSeq (Normal s)) \<rightarrow> (Q, toSeq t) \<and> (\<forall>t'. t= Normal t' \<or> t = Abrupt t' \<longrightarrow> (snd s) = (snd t')))" using a0 apply clarsimp apply (erule step_ce_elim_cases) apply auto by (metis (no_types) surjective_pairing)+ lemma step_dest1: assumes a0:"\<Gamma>\<turnstile>\<^sub>c(P,Normal s) \<rightarrow>\<^sub>c\<^sub>e (Q,t)" and a1:"\<Gamma>\<turnstile>\<^sub>c (P, toSeq (Normal s)) \<rightarrow> (Q, toSeq t)" shows"(\<forall>t'. t= Normal t' \<or> t = Abrupt t' \<longrightarrow> (snd s) = (snd t'))" using a0 a1 apply clarsimp apply (erule step_ce_elim_cases) apply auto apply (metis (no_types) prod.exhaust_sel)+ using a1 env_c_c' step_change_p_or_eq_s by blast+ lemma transfer_normal:" \<Gamma>\<turnstile>\<^sub>c (c, Normal s) \<rightarrow> (c', Normal s') \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (c, Normal (s, ls)) \<rightarrow>\<^sub>c\<^sub>e (c', Normal (s', ls))" by (auto intro: c_step) lemma step_c_normal_normal: assumes a1: "\<Gamma>\<turnstile>\<^sub>c cf0 \<rightarrow> cf1" shows "\<And> c\<^sub>1 s s'. \<lbrakk>cf0 = (c\<^sub>1,Normal s);cf1=(c\<^sub>1,s');(\<forall>sa. \<not>(s'=Normal sa))\<rbrakk> \<Longrightarrow> P" using a1 by (induct rule: stepc.induct, induct, auto) lemma normal_not_normal_eq_p: assumes a1: "\<Gamma>\<turnstile>\<^sub>c (cf0) \<rightarrow>\<^sub>c\<^sub>e cf1" shows "\<And> c\<^sub>1 s s'. \<lbrakk>cf0 = (c\<^sub>1,Normal s);cf1=(c\<^sub>1,s');(\<forall>sa. \<not>(s'=Normal sa))\<rbrakk> \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c cf0 \<rightarrow>\<^sub>e cf1 \<and> \<not>( \<Gamma>\<turnstile>\<^sub>c (c\<^sub>1, toSeq (Normal s)) \<rightarrow> (c\<^sub>1, toSeq s'))" apply (meson step_c_normal_normal step_e.intros ) using Env apply (metis assms step_dest ) by (simp add: mod_env_not_component step_dest) lemma call_f_step_ce_not_s_eq_t_env_step: assumes a0:"\<Gamma>\<turnstile>\<^sub>c(P,s) \<rightarrow>\<^sub>c\<^sub>e (Q,t)" and a1:"(redex P = Call fn \<and> \<Gamma> fn = Some bdy \<and> s=Normal s' \<and> (s\<noteq>t)) \<or> (redex P = Call fn \<and> \<Gamma> fn = Some bdy \<and> s=Normal s' \<and> s=t \<and> P=Q \<and> \<Gamma> fn \<noteq> Some (Call fn)) " shows "\<Gamma>\<turnstile>\<^sub>c(P,s) \<rightarrow>\<^sub>e (Q,t)" proof- obtain s' where "\<Gamma>\<turnstile>\<^sub>c(P,s) \<rightarrow>\<^sub>e (Q,t) \<or> (s=Normal s' \<and> \<Gamma>\<turnstile>\<^sub>c (P, toSeq (Normal s')) \<rightarrow> (Q, toSeq t) \<and> (\<forall>t'. t= Normal t' \<longrightarrow> (snd s') = (snd t')))" using step_dest a0 a1 by fast moreover {assume "\<Gamma>\<turnstile>\<^sub>c(P,s) \<rightarrow>\<^sub>e (Q,t)" then have ?thesis by auto } moreover { assume a00:"s=Normal s'" and a01:"\<Gamma>\<turnstile>\<^sub>c (P, toSeq (Normal s')) \<rightarrow> (Q, toSeq t)" and a02:"(\<forall>t'. t= Normal t' \<longrightarrow> (snd s') = (snd t'))" then have ?thesis using call_f_step_not_s_eq_t_false[OF a01] a1 apply (cases t) apply (metis prod.expand toSeq.simps(1) xstate.inject(1)) by fastforce+ } ultimately show ?thesis by auto qed abbreviation "stepce_rtrancl" :: "[('g\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \<Rightarrow> bool" ("_\<turnstile>\<^sub>c (_ \<rightarrow>\<^sub>c\<^sub>e\<^sup>*/ _)" [81,81,81] 100) where "\<Gamma>\<turnstile>\<^sub>c cf0 \<rightarrow>\<^sub>c\<^sub>e\<^sup>* cf1 \<equiv> ((CONST step_ce \<Gamma>))\<^sup>*\<^sup>* cf0 cf1" (* "\<Gamma>\<turnstile>\<^sub>c cf0 \<rightarrow>\<^sup>* cf1 \<equiv> (CONST ((stepc \<Gamma>) \<union> (step_e \<Gamma>)))\<^sup>*\<^sup>* cf0 cf1" *) abbreviation "stepce_trancl" :: "[('g\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \<Rightarrow> bool" ("_\<turnstile>\<^sub>c (_ \<rightarrow>\<^sub>c\<^sub>e\<^sup>+/ _)" [81,81,81] 100) where "\<Gamma>\<turnstile>\<^sub>c cf0 \<rightarrow>\<^sub>c\<^sub>e\<^sup>+ cf1 \<equiv> (CONST step_ce \<Gamma>)\<^sup>+\<^sup>+ cf0 cf1" text \<open> lemmas about single step computation \<close> lemma ce_not_normal_s: assumes a1:"\<Gamma>\<turnstile>\<^sub>c cf0 \<rightarrow>\<^sub>c\<^sub>e cf1" shows "\<And> c\<^sub>1 c\<^sub>2 s s'. \<lbrakk>cf0 = (c\<^sub>1,s);cf1=(c\<^sub>2,s');(\<forall>sa. (s\<noteq>Normal sa))\<rbrakk> \<Longrightarrow> s=s'" using a1 apply (clarify, cases rule:step_ce.cases) apply (metis eq_toSeq prod.sel(1) prod.sel(2) step_not_normal_s_eq_t toSeq.simps xstate.simps(5)) using env_not_normal_s by blast lemma not_eq_not_env: assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e (c', s')" shows "~(c=c') \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', s') \<Longrightarrow> P" using step_m etranE by blast lemma step_ce_not_step_e_step_c: assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e (c', s')" shows "\<not> (\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', s')) \<Longrightarrow>(\<Gamma>\<turnstile>\<^sub>c (c, toSeq s) \<rightarrow> (c', toSeq s'))" using step_m step_ce_elim_cases by blast lemma step_ce_step_c_eq_c: assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e (c', s')" shows "(\<Gamma>\<turnstile>\<^sub>c (c, toSeq s) \<rightarrow> (c', toSeq s')) \<Longrightarrow> c=c' \<Longrightarrow> P" using step_m step_ce_elim_cases step_ce_not_step_e_step_c by (simp add: mod_env_not_component) lemma step_ce_notNormal: assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e (c', s')" shows "(\<forall>sa. \<not>(s=Normal sa)) \<Longrightarrow> s'=s" using step_m proof (induct rule:step_ce_induct) case (e_step a b a' b') thus ?case using env_not_normal_s by blast next case (c_step a b a' b') thus ?case using ce_not_normal_s step_ce.c_step by blast qed lemma steps_ce_not_Normal: assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (c', s')" shows "\<forall>sa. \<not>(s=Normal sa) \<Longrightarrow> s'=s" using step_m proof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans]) case Refl then show ?case by auto next case (Trans a b a' b') thus ?case using step_ce_notNormal by blast qed lemma step_ce_Normal_eq_l: assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, Normal (s,l)) \<rightarrow>\<^sub>c\<^sub>e (c', Normal (s',l'))" and step_ce:"\<Gamma>\<turnstile>\<^sub>c (c, Normal s) \<rightarrow> (c', Normal s')" shows "l=l'" by (metis env_c_c' mod_env_not_component snd_conv step_ce step_dest step_m) lemma step_ce_dest: assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e (c', s')" shows "\<Gamma>\<turnstile>\<^sub>c (c, toSeq s) \<rightarrow> (c', toSeq s') \<or> \<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', s')" using step_ce_not_step_e_step_c step_m by blast lemma steps_not_normal_ce_c: assumes steps: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (c', s')" shows "( \<forall>sa. \<not>(s=Normal sa)) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (c, toSeq s) \<rightarrow>\<^sup>* (c', toSeq s')" using steps proof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans]) case Refl thus ?case by auto next case (Trans a b a' b') then show ?case by (metis (no_types, hide_lams) converse_rtranclp_into_rtranclp env_c_c' step_ce_notNormal step_ce_not_step_e_step_c) qed lemma ce_eq_length: assumes a0:"\<Gamma>\<turnstile>\<^sub>c (P,s) \<rightarrow>\<^sub>c\<^sub>e (Q,t)" and a1:"s= Normal ns \<or> s = Abrupt ns" and a2:"t = Normal nt \<or> t = Abrupt nt" shows "length (snd ns) = length (snd nt)" proof- have "\<Gamma>\<turnstile>\<^sub>c (P,s) \<rightarrow>\<^sub>e (Q,t) \<or> \<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Q, toSeq t)" using a0 step_ce_dest by blast moreover{ assume a00:"\<Gamma>\<turnstile>\<^sub>c (P,s) \<rightarrow>\<^sub>e (Q,t)" then have eq_p:"P=Q" using env_c_c' by blast then have ?thesis using a00 stepe_elim_cases[OF a00[simplified eq_p]] by (metis a1 a2 prod.exhaust_sel xstate.inject(1) xstate.inject(2) xstate.simps(5)) } moreover{ assume a00:" \<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Q, toSeq t)" then have ?thesis by (metis a0 a1 a2 calculation(2) step_ce_notNormal step_dest xstate.inject(2) xstate.simps(5)) } ultimately show ?thesis by auto qed (* lemma steps_c_ce: assumes steps: "\<Gamma>\<turnstile>\<^sub>c (c, s1) \<rightarrow>\<^sup>* (c', s2)" and a0:"s1 = toSeq s" and a0':"s2 = toSeq s'" and a1: "\<forall>ns ns'. (s = Normal ns \<or> s = Abrupt ns) \<and> (s' = Normal ns' \<or> s' = Abrupt ns') \<longrightarrow> snd ns =snd ns'" shows "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (c', s')" using steps a1 a0 a0' thm converse_rtranclp_induct2 [case_names Refl Trans] proof (induct arbitrary: s s' rule: converse_rtranclp_induct2 [case_names Refl Trans]) case Refl thus ?case using eq_toSeq by blast next case (Trans a b a' b') thus ?case proof(cases a) by (simp add: Trans.hyps(3) converse_rtranclp_into_rtranclp) qed lemma steps_not_normal_c_ce: assumes steps: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sup>* (c', s')" shows "( \<forall>sa. \<not>(s=Normal sa)) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (c', s')" by (simp add: steps steps_c_ce) lemma steps_not_normal_c_eq_ce: assumes normal: "( \<forall>sa. \<not>(s=Normal sa))" shows " \<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sup>* (c', s') = \<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (c', s')" using normal using steps_c_ce steps_not_normal_ce_c by auto lemma steps_ce_Fault: "\<Gamma>\<turnstile>\<^sub>c (c, Fault f) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (Skip, Fault f)" by (simp add: SmallStepCon.steps_Fault steps_c_ce) lemma steps_ce_Stuck: "\<Gamma>\<turnstile>\<^sub>c (c, Stuck) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (Skip, Stuck)" by (simp add: SmallStepCon.steps_Stuck steps_c_ce) lemma steps_ce_Abrupt: "\<Gamma>\<turnstile>\<^sub>c (c, Abrupt a) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (Skip, Abrupt a)" by (simp add: SmallStepCon.steps_Abrupt steps_c_ce) *) lemma step_ce_seq_throw_normal: assumes step: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e (c', s')" and c_val: "c=Seq Throw Q \<and> c'=Throw" shows "\<exists>sa. s=Normal sa" using step c_val not_eq_not_env step_ce_not_step_e_step_c step_seq_throw_normal by (metis SemanticCon.isAbr_def SemanticCon.not_isAbrD seq_and_if_not_eq(3) toSeq.simps(2) toSeq.simps(3) toSeq.simps(4) xstate.distinct(3) xstate.simps(5) xstate.simps(9)) lemma step_ce_catch_throw_normal: assumes step: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e (c', s')" and c_val: "c=Catch Throw Q \<and> c'=Throw" shows "\<exists>sa. s=Normal sa" using step c_val not_eq_not_env step_ce_not_step_e_step_c step_catch_throw_normal by (metis SemanticCon.isAbr_def SemanticCon.not_isAbrD seq_and_if_not_eq(11) toSeq.simps(2) toSeq.simps(3) toSeq.simps(4) xstate.distinct(3) xstate.simps(5) xstate.simps(9)) lemma step_ce_normal_to_normal[rule_format]: assumes step:"\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (c', s')" and sn: "s = Normal sa" and finalc':"(\<Gamma>\<turnstile>\<^sub>c (c', s') \<rightarrow>\<^sub>c\<^sub>e\<^sup>*(c1, s1) \<and> (\<exists>sb. s1 = Normal sb))" shows " (\<exists>sc. s'=Normal sc)" using step sn finalc' steps_ce_not_Normal by blast lemma ce_Throw_toSkip: assumes a0:"\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Throw, s) \<rightarrow>\<^sub>c\<^sub>e x" shows "fst x = Skip \<or> fst x = Throw" proof- have "\<Gamma>\<turnstile>\<^sub>c (Throw, toSeq s) \<rightarrow> (fst x, toSeq (snd x)) \<or> \<Gamma>\<turnstile>\<^sub>c (Throw, s) \<rightarrow>\<^sub>e x" using a0 step_ce_dest by (metis prod.collapse) thus ?thesis by (metis env_c_c' prod.collapse prod.inject stepc_elim_cases(11)) qed (* lemma SeqSteps_ce: assumes steps: "\<Gamma>\<turnstile>\<^sub>c cfg\<^sub>1\<rightarrow>\<^sub>c\<^sub>e\<^sup>* cfg\<^sub>2" shows "\<And> c\<^sub>1 s c\<^sub>1' s'. \<lbrakk>cfg\<^sub>1 = (c\<^sub>1,s);cfg\<^sub>2=(c\<^sub>1',s')\<rbrakk> \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c(Seq c\<^sub>1 c\<^sub>2,s) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (Seq c\<^sub>1' c\<^sub>2, s')" using steps proof (induct rule: converse_rtranclp_induct [case_names Refl Trans]) case Refl thus ?case by simp next case (Trans cfg\<^sub>1 cfg'') then have "\<Gamma>\<turnstile>\<^sub>c cfg\<^sub>1 \<rightarrow> cfg'' \<or> \<Gamma>\<turnstile>\<^sub>c cfg\<^sub>1 \<rightarrow>\<^sub>e cfg''" using step_ce_elim_cases by blast thus ?case proof assume a1:"\<Gamma>\<turnstile>\<^sub>c cfg\<^sub>1 \<rightarrow>\<^sub>e cfg''" have "\<forall>f p pa. \<not> f\<turnstile>\<^sub>c p \<rightarrow>\<^sub>e pa \<or> (\<exists>c. (\<exists>x. p = (c::('a, 'b, 'c,'d) LanguageCon.com, x)) \<and> (\<exists>x. pa = (c, x)))" by (meson etranE) then obtain cc :: "('b \<Rightarrow> ('a, 'b, 'c,'d) LanguageCon.com option) \<Rightarrow> ('a, 'b, 'c,'d) LanguageCon.com \<times> ('a, 'c) xstate \<Rightarrow> ('a, 'b, 'c,'d) LanguageCon.com \<times> ('a, 'c) xstate \<Rightarrow> ('a, 'b, 'c,'d) LanguageCon.com" and xx :: "('b \<Rightarrow> ('a, 'b, 'c,'d) LanguageCon.com option) \<Rightarrow> ('a, 'b, 'c,'d) LanguageCon.com \<times> ('a, 'c) xstate \<Rightarrow> ('a, 'b, 'c,'d) LanguageCon.com \<times> ('a, 'c) xstate \<Rightarrow> ('a, 'c) xstate" and xxa :: "('b \<Rightarrow> ('a, 'b, 'c,'d) LanguageCon.com option) \<Rightarrow> ('a, 'b, 'c,'d) LanguageCon.com \<times> ('a, 'c) xstate \<Rightarrow> ('a, 'b, 'c,'d) LanguageCon.com \<times> ('a, 'c) xstate \<Rightarrow> ('a, 'c) xstate" where f1: "\<forall>f p pa. \<not> f\<turnstile>\<^sub>c p \<rightarrow>\<^sub>e pa \<or> p = (cc f p pa, xx f p pa) \<and> pa = (cc f p pa, xxa f p pa)" by (metis (no_types)) have f2: "\<forall>f c x xa. \<not> f\<turnstile>\<^sub>c (c::('a, 'b, 'c,'d) LanguageCon.com, x) \<rightarrow>\<^sub>e (c, xa) \<or> (\<exists>a. x = Normal a) \<or> (\<forall>a. xa \<noteq> Normal a) \<and> x = xa" by (metis stepe_elim_cases) have f3: "(c\<^sub>1, xxa \<Gamma> cfg\<^sub>1 cfg'') = cfg''" using f1 by (metis Trans.prems(1) a1 fst_conv) hence "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Seq c\<^sub>1 c\<^sub>2, xxa \<Gamma> cfg\<^sub>1 cfg'') \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (LanguageCon.com.Seq c\<^sub>1' c\<^sub>2, s')" using Trans.hyps(3) Trans.prems(2) by force thus ?thesis using f3 f2 by (metis (no_types) Env Trans.prems(1) a1 e_step r_into_rtranclp rtranclp.rtrancl_into_rtrancl rtranclp_idemp) next assume "\<Gamma>\<turnstile>\<^sub>c cfg\<^sub>1 \<rightarrow> cfg''" thus ?thesis proof - have "\<forall>p. \<exists>c x. p = (c::('a, 'b, 'c,'d) LanguageCon.com, x::('a, 'c) xstate)" by auto thus ?thesis by (metis (no_types) Seqc Trans.hyps(3) Trans.prems(1) Trans.prems(2) `\<Gamma>\<turnstile>\<^sub>c cfg\<^sub>1 \<rightarrow> cfg''` c_step converse_rtranclp_into_rtranclp) qed qed qed lemma CatchSteps_ce: assumes steps: "\<Gamma>\<turnstile>\<^sub>ccfg\<^sub>1\<rightarrow>\<^sub>c\<^sub>e\<^sup>* cfg\<^sub>2" shows "\<And> c\<^sub>1 s c\<^sub>1' s'. \<lbrakk>cfg\<^sub>1 = (c\<^sub>1,s); cfg\<^sub>2=(c\<^sub>1',s')\<rbrakk> \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c(Catch c\<^sub>1 c\<^sub>2,s) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (Catch c\<^sub>1' c\<^sub>2, s')" using steps proof (induct rule: converse_rtranclp_induct [case_names Refl Trans]) case Refl thus ?case by simp next case (Trans cfg\<^sub>1 cfg'') then have "\<Gamma>\<turnstile>\<^sub>c cfg\<^sub>1 \<rightarrow> cfg'' \<or> \<Gamma>\<turnstile>\<^sub>c cfg\<^sub>1 \<rightarrow>\<^sub>e cfg''" using step_ce_elim_cases by blast thus ?case proof assume a1:"\<Gamma>\<turnstile>\<^sub>c cfg\<^sub>1 \<rightarrow>\<^sub>e cfg''" have "\<forall>f p pa. \<not> f\<turnstile>\<^sub>c p \<rightarrow>\<^sub>e pa \<or> (\<exists>c. (\<exists>x. p = (c::('a, 'b, 'c,'d) LanguageCon.com, x)) \<and> (\<exists>x. pa = (c, x)))" by (meson etranE) then obtain cc :: "('b \<Rightarrow>('a, 'b, 'c, 'd) LanguageCon.com option) \<Rightarrow> ('a, 'b, 'c, 'd) LanguageCon.com \<times> ('a, 'c) xstate \<Rightarrow> ('a, 'b, 'c, 'd) LanguageCon.com \<times> ('a, 'c) xstate \<Rightarrow> ('a, 'b, 'c, 'd) LanguageCon.com" and xx :: "('b \<Rightarrow>('a, 'b, 'c, 'd) LanguageCon.com option) \<Rightarrow> ('a, 'b, 'c, 'd) LanguageCon.com \<times> ('a, 'c) xstate \<Rightarrow> ('a, 'b, 'c, 'd) LanguageCon.com \<times> ('a, 'c) xstate \<Rightarrow> ('a, 'c) xstate" and xxa :: "('b \<Rightarrow>('a, 'b, 'c, 'd) LanguageCon.com option) \<Rightarrow> ('a, 'b, 'c, 'd) LanguageCon.com \<times> ('a, 'c) xstate \<Rightarrow> ('a, 'b, 'c, 'd) LanguageCon.com \<times> ('a, 'c) xstate \<Rightarrow> ('a, 'c) xstate" where f1: "\<forall>f p pa. \<not> f\<turnstile>\<^sub>c p \<rightarrow>\<^sub>e pa \<or> p = (cc f p pa, xx f p pa) \<and> pa = (cc f p pa, xxa f p pa)" by (metis (no_types)) have f2: "\<forall>f c x xa. \<not> f\<turnstile>\<^sub>c (c::('a, 'b, 'c,'d) LanguageCon.com, x) \<rightarrow>\<^sub>e (c, xa) \<or> (\<exists>a. x = Normal a) \<or> (\<forall>a. xa \<noteq> Normal a) \<and> x = xa" by (metis stepe_elim_cases) have f3: "(c\<^sub>1, xxa \<Gamma> cfg\<^sub>1 cfg'') = cfg''" using f1 by (metis Trans.prems(1) a1 fst_conv) hence "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Catch c\<^sub>1 c\<^sub>2, xxa \<Gamma> cfg\<^sub>1 cfg'') \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (LanguageCon.com.Catch c\<^sub>1' c\<^sub>2, s')" using Trans.hyps(3) Trans.prems(2) by force thus ?thesis using f3 f2 by (metis (no_types) Env Trans.prems(1) a1 e_step r_into_rtranclp rtranclp.rtrancl_into_rtrancl rtranclp_idemp) next assume "\<Gamma>\<turnstile>\<^sub>c cfg\<^sub>1 \<rightarrow> cfg''" thus ?thesis proof - obtain cc :: "('a, 'b, 'c, 'd) LanguageCon.com \<times> ('a, 'c) xstate \<Rightarrow> ('a, 'b, 'c, 'd) LanguageCon.com" and xx :: "('a, 'b, 'c, 'd) LanguageCon.com \<times> ('a, 'c) xstate \<Rightarrow> ('a, 'c) xstate" where f1: "\<forall>p. p = (cc p, xx p)" by (meson old.prod.exhaust) hence "\<And>c. \<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Catch c\<^sub>1 c, s) \<rightarrow> (LanguageCon.com.Catch (cc cfg'') c, xx cfg'')" by (metis (no_types) Catchc Trans.prems(1) `\<Gamma>\<turnstile>\<^sub>c cfg\<^sub>1 \<rightarrow> cfg''`) thus ?thesis using f1 by (meson Trans.hyps(3) Trans.prems(2) c_step converse_rtranclp_into_rtranclp) qed qed qed *) subsection \<open>Computations\<close> subsubsection \<open>Sequential computations\<close> type_synonym ('g,'l,'p,'f,'e) confs = "('g\<times>'l,'p,'f,'e) body \<times> (('g, 'l, 'p,'f,'e) config_gs) list" (* inductive_set cptn :: "(('g,'l,'p,'f,'e) confs) set" where CptnOne: " (\<Gamma>, [(P,s)]) \<in> cptn" | CptnEnv: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,s) \<rightarrow>\<^sub>e (P,t); (\<Gamma>,(P, t)#xs) \<in> cptn \<rbrakk> \<Longrightarrow> (\<Gamma>,(P,s)#(P,t)#xs) \<in> cptn" | CptnComp: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,toSeq s) \<rightarrow> (Q,toSeq t); \<forall>ns ns'. (s = Normal ns \<or> s = Abrupt ns) \<and> (t = Normal ns' \<or> t = Abrupt ns') \<longrightarrow> snd ns = snd ns'; (\<Gamma>,(Q, t)#xs) \<in> cptn \<rbrakk> \<Longrightarrow> (\<Gamma>,(P,s)#(Q,t)#xs) \<in> cptn" *) inductive_set cptn :: "(('g,'l,'p,'f,'e) confs) set" where CptnOne: " (\<Gamma>, [(P,s)]) \<in> cptn" | Cptn: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,s) \<rightarrow>\<^sub>c\<^sub>e (Q,t); (\<Gamma>,(Q, t)#xs) \<in> cptn \<rbrakk> \<Longrightarrow> (\<Gamma>,(P,s)#(Q,t)#xs) \<in> cptn" (* lemma c1: assumes a0:"(\<Gamma>,c)\<in>cptn1" shows "(\<Gamma>,c)\<in>cptn" using a0 proof(induct) case (CptnOne1 \<Gamma> P s) then show ?case by (simp add: cptn.CptnOne) next case (Cptn1 \<Gamma> P s Q t xs) moreover { assume " \<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Q, toSeq t)" then have ?case using Cptn1 using cptn.CptnComp step_ce_notNormal step_dest1 by blast } moreover { assume " \<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (Q, t)" then have ?case using calculation(3) cptn.CptnEnv env_c_c' by blast }ultimately show ?case using step_ce_not_step_e_step_c by blast qed lemma c2: assumes a0:"(\<Gamma>,c)\<in>cptn" shows"(\<Gamma>,c)\<in>cptn1" using a0 proof(induct) case (CptnOne \<Gamma> P s) then show ?case by (simp add: cptn1.CptnOne1) next case (CptnEnv \<Gamma> P s t xs) then show ?case by (simp add: cptn1.Cptn1 e_step) next case (CptnComp \<Gamma> P s Q t xs) then show ?case by (simp add: c_step cptn1.Cptn1) qed lemma eq_cptn: "cptn = cptn1" using c1 c2 by auto *) (* inductive_cases cptn_elim_cases [cases set]: "(\<Gamma>, [(P,s)]) \<in> cptn" "(\<Gamma>,(P,s)#(Q,t)#xs) \<in> cptn" "(\<Gamma>,(P,s)#(P,t)#xs) \<in> cptn" *) inductive_cases cptn_elim_cases [cases set]: "(\<Gamma>, [(P,s)]) \<in> cptn" "(\<Gamma>,(P,s)#(Q,t)#xs) \<in> cptn" (* lemma cptn_elim_casesa1[cases set,elim]: "\<lbrakk>(\<Gamma>, (P, Normal ((g,l1), l)) # (Q, Normal ((g',l1'), l')) # xs) \<in> cptn; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Normal ((g,l1), l)) \<rightarrow>\<^sub>e (P, Normal ((g',l1'), l')); (\<Gamma>, (P, Normal ((g',l1'), l')) # xs) \<in> cptn; Q = P\<rbrakk> \<Longrightarrow> Pa; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Normal (g,l1)) \<rightarrow> (Q, Normal (g',l1')); l=l'; (\<Gamma>, (Q, Normal ((g',l1'), l')) # xs) \<in> cptn\<rbrakk> \<Longrightarrow> Pa\<rbrakk> \<Longrightarrow> Pa" by (auto elim:cptn_elim_cases) lemma cptn_elim_casesa2[cases set,elim]: "\<lbrakk>(\<Gamma>, (P, Normal (g, l)) # (Q, Abrupt (g', l')) # xs) \<in> cptn; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Normal (g, l)) \<rightarrow>\<^sub>e (P, Abrupt (g', l')); (\<Gamma>, (P, Abrupt (g', l')) # xs) \<in> cptn; Q = P\<rbrakk> \<Longrightarrow> Pa; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Normal g) \<rightarrow> (Q, Abrupt g'); l=l'; (\<Gamma>, (Q, Abrupt (g', l')) # xs) \<in> cptn\<rbrakk> \<Longrightarrow> Pa\<rbrakk> \<Longrightarrow> Pa" by (auto elim:cptn_elim_cases) lemma cptn_elim_casesa3[cases set,elim]: "\<lbrakk>(\<Gamma>, (P, Normal (g, l)) # (Q, Fault f) # xs) \<in> cptn; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Normal (g, l)) \<rightarrow>\<^sub>e (P, Fault f); (\<Gamma>, (P, Fault f) # xs) \<in> cptn; Q = P\<rbrakk> \<Longrightarrow> Pa; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Normal g) \<rightarrow> (Q, Fault f); (\<Gamma>, (Q, Fault f) # xs) \<in> cptn\<rbrakk> \<Longrightarrow> Pa\<rbrakk> \<Longrightarrow> Pa" by (auto elim:cptn_elim_cases) lemma cptn_elim_casesa4[cases set,elim]: "\<lbrakk>(\<Gamma>, (P, Normal (g, l)) # (Q, Stuck) # xs) \<in> cptn; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Normal (g, l)) \<rightarrow>\<^sub>e (P, Stuck); (\<Gamma>, (P, Stuck) # xs) \<in> cptn; Q = P\<rbrakk> \<Longrightarrow> Pa; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Normal g) \<rightarrow> (Q, Stuck); (\<Gamma>, (Q, Stuck) # xs) \<in> cptn\<rbrakk> \<Longrightarrow> Pa\<rbrakk> \<Longrightarrow> Pa" by (auto elim:cptn_elim_cases) lemma cptn_elim_casesa5[cases set,elim]: "\<lbrakk>(\<Gamma>, (P, Abrupt (g, l)) # (Q, Normal (g', l')) # xs) \<in> cptn; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Abrupt (g, l)) \<rightarrow>\<^sub>e (P, Normal (g', l')); (\<Gamma>, (P, Normal (g', l')) # xs) \<in> cptn; Q = P\<rbrakk> \<Longrightarrow> Pa; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Abrupt g) \<rightarrow> (Q, Normal g'); l=l'; (\<Gamma>, (Q, Normal (g', l')) # xs) \<in> cptn\<rbrakk> \<Longrightarrow> Pa\<rbrakk> \<Longrightarrow> Pa" by (auto elim:cptn_elim_cases) lemma cptn_elim_casesa6[cases set,elim]: "\<lbrakk>(\<Gamma>, (P, Abrupt (g, l)) # (Q, Abrupt (g', l')) # xs) \<in> cptn; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Abrupt (g, l)) \<rightarrow>\<^sub>e (P, Abrupt (g', l')); (\<Gamma>, (P, Abrupt (g', l')) # xs) \<in> cptn; Q = P\<rbrakk> \<Longrightarrow> Pa; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Abrupt g) \<rightarrow> (Q, Abrupt g'); l=l'; (\<Gamma>, (Q, Abrupt (g', l')) # xs) \<in> cptn\<rbrakk> \<Longrightarrow> Pa\<rbrakk> \<Longrightarrow> Pa" by (auto elim:cptn_elim_cases) lemma cptn_elim_casesa7[cases set,elim]: "\<lbrakk>(\<Gamma>, (P, Abrupt (g, l)) # (Q, Fault f) # xs) \<in> cptn; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Abrupt (g, l)) \<rightarrow>\<^sub>e (P, Fault f); (\<Gamma>, (P, Fault f) # xs) \<in> cptn; Q = P\<rbrakk> \<Longrightarrow> Pa; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Abrupt g) \<rightarrow> (Q, Fault f); (\<Gamma>, (Q, Fault f) # xs) \<in> cptn\<rbrakk> \<Longrightarrow> Pa\<rbrakk> \<Longrightarrow> Pa" by (auto elim:cptn_elim_cases) lemma cptn_elim_casesa8[cases set,elim]: "\<lbrakk>(\<Gamma>, (P, Abrupt (g, l)) # (Q, Stuck) # xs) \<in> cptn; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Abrupt (g, l)) \<rightarrow>\<^sub>e (P, Stuck); (\<Gamma>, (P, Stuck) # xs) \<in> cptn; Q = P\<rbrakk> \<Longrightarrow> Pa; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Abrupt g) \<rightarrow> (Q, Stuck); (\<Gamma>, (Q, Stuck) # xs) \<in> cptn\<rbrakk> \<Longrightarrow> Pa\<rbrakk> \<Longrightarrow> Pa" by (auto elim:cptn_elim_cases) lemma cptn_elim_casesa9[cases set,elim]: "\<lbrakk>(\<Gamma>, (P, Fault f) # (Q, Normal (g', l')) # xs) \<in> cptn; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Fault f) \<rightarrow>\<^sub>e (P, Normal (g', l')); (\<Gamma>, (P, Normal (g', l')) # xs) \<in> cptn; Q = P\<rbrakk> \<Longrightarrow> Pa; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Fault f) \<rightarrow> (Q, Normal g'); (\<Gamma>, (Q, Normal (g', l')) # xs) \<in> cptn\<rbrakk> \<Longrightarrow> Pa\<rbrakk> \<Longrightarrow> Pa" by (auto elim:cptn_elim_cases) lemma cptn_elim_casesa10[cases set,elim]: "\<lbrakk>(\<Gamma>, (P, Fault f) # (Q, Abrupt (g', l')) # xs) \<in> cptn; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Fault f) \<rightarrow>\<^sub>e (P, Abrupt (g', l')); (\<Gamma>, (P, Abrupt (g', l')) # xs) \<in> cptn; Q = P\<rbrakk> \<Longrightarrow> Pa; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Fault f) \<rightarrow> (Q, Abrupt g'); (\<Gamma>, (Q, Abrupt (g', l')) # xs) \<in> cptn\<rbrakk> \<Longrightarrow> Pa\<rbrakk> \<Longrightarrow> Pa" by (auto elim:cptn_elim_cases) lemma cptn_elim_casesa11[cases set,elim]: "\<lbrakk>(\<Gamma>, (P, Fault f) # (Q, Fault f') # xs) \<in> cptn; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Fault f) \<rightarrow>\<^sub>e (P, Fault f'); (\<Gamma>, (P, Fault f') # xs) \<in> cptn; Q = P\<rbrakk> \<Longrightarrow> Pa; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Fault f) \<rightarrow> (Q, Fault f'); (\<Gamma>, (Q, Fault f') # xs) \<in> cptn\<rbrakk> \<Longrightarrow> Pa\<rbrakk> \<Longrightarrow> Pa" by (auto elim:cptn_elim_cases) lemma cptn_elim_casesa12[cases set,elim]: "\<lbrakk>(\<Gamma>, (P, Fault f) # (Q, Stuck) # xs) \<in> cptn; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Fault f) \<rightarrow>\<^sub>e (P, Stuck); (\<Gamma>, (P, Stuck) # xs) \<in> cptn; Q = P\<rbrakk> \<Longrightarrow> Pa; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Fault f) \<rightarrow> (Q, Stuck); (\<Gamma>, (Q, Stuck) # xs) \<in> cptn\<rbrakk> \<Longrightarrow> Pa\<rbrakk> \<Longrightarrow> Pa" by (auto elim:cptn_elim_cases) lemma cptn_elim_casesa13[cases set,elim]: "\<lbrakk>(\<Gamma>, (P, Stuck) # (Q, Normal (g', l')) # xs) \<in> cptn; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Stuck) \<rightarrow>\<^sub>e (P, Normal (g', l')); (\<Gamma>, (P, Normal (g', l')) # xs) \<in> cptn; Q = P\<rbrakk> \<Longrightarrow> Pa; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Stuck) \<rightarrow> (Q, Normal g'); (\<Gamma>, (Q, Normal (g', l')) # xs) \<in> cptn\<rbrakk> \<Longrightarrow> Pa\<rbrakk> \<Longrightarrow> Pa" by (auto elim:cptn_elim_cases) lemma cptn_elim_casesa14[cases set,elim]: "\<lbrakk>(\<Gamma>, (P, Stuck) # (Q, Abrupt (g', l')) # xs) \<in> cptn; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Stuck) \<rightarrow>\<^sub>e (P, Abrupt (g', l')); (\<Gamma>, (P, Abrupt (g', l')) # xs) \<in> cptn; Q = P\<rbrakk> \<Longrightarrow> Pa; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Stuck) \<rightarrow> (Q, Abrupt g'); (\<Gamma>, (Q, Abrupt (g', l')) # xs) \<in> cptn\<rbrakk> \<Longrightarrow> Pa\<rbrakk> \<Longrightarrow> Pa" by (auto elim:cptn_elim_cases) lemma cptn_elim_casesa15[cases set,elim]: "\<lbrakk>(\<Gamma>, (P, Stuck) # (Q, Fault f) # xs) \<in> cptn; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Stuck) \<rightarrow>\<^sub>e (P, Fault f); (\<Gamma>, (P, Fault f) # xs) \<in> cptn; Q = P\<rbrakk> \<Longrightarrow> Pa; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Stuck) \<rightarrow> (Q, Fault f); (\<Gamma>, (Q, Fault f) # xs) \<in> cptn\<rbrakk> \<Longrightarrow> Pa\<rbrakk> \<Longrightarrow> Pa" by (auto elim:cptn_elim_cases) lemma cptn_elim_casesa16[cases set,elim]: "\<lbrakk>(\<Gamma>, (P, Stuck) # (Q, Stuck) # xs) \<in> cptn; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Stuck) \<rightarrow>\<^sub>e (P, Stuck); (\<Gamma>, (P, Stuck) # xs) \<in> cptn; Q = P\<rbrakk> \<Longrightarrow> Pa; \<lbrakk>\<Gamma>\<turnstile>\<^sub>c (P, Stuck) \<rightarrow> (Q, Stuck); (\<Gamma>, (Q, Stuck) # xs) \<in> cptn\<rbrakk> \<Longrightarrow> Pa\<rbrakk> \<Longrightarrow> Pa" by (auto elim:cptn_elim_cases) *) inductive_cases cptn_elim_cases_pair [cases set]: "(\<Gamma>, [x]) \<in> cptn" "(\<Gamma>, x#x1#xs) \<in> cptn" lemma cptn_dest:"(\<Gamma>,(P,s)#(Q,t)#xs) \<in> cptn \<Longrightarrow> (\<Gamma>,(Q,t)#xs)\<in> cptn" by (auto dest: cptn_elim_cases) lemma cptn_dest_pair:"(\<Gamma>,x#x1#xs) \<in> cptn \<Longrightarrow> (\<Gamma>,x1#xs)\<in> cptn" proof - assume "(\<Gamma>,x#x1#xs) \<in> cptn" thus ?thesis using cptn_dest prod.collapse by metis qed lemma cptn_dest1:"(\<Gamma>,(P,s)#(Q,t)#xs) \<in> cptn \<Longrightarrow> (\<Gamma>,(P,s)#[(Q,t)])\<in> cptn" proof - assume a1: "(\<Gamma>, (P, s) # (Q, t) # xs) \<in> cptn" have "(\<Gamma>, [(Q, t)]) \<in> cptn" by (meson cptn.CptnOne) thus ?thesis using a1 cptn.Cptn cptn_elim_cases(2) by blast (* proof (cases s) case (Normal s') then obtain g l1 l where f1: "(\<Gamma>, (P, Normal s') # (Q, t) # xs) \<in> cptn \<and> s' = ((g,l1),l)" using Normal a1 by (metis old.prod.exhaust) thus ?thesis apply (cases t) by (auto simp add: Normal cptn.CptnEnv cptn.CptnComp cptn.CptnOne) next case (Abrupt x) then obtain g l1 l where f1: "(\<Gamma>, (P, Abrupt x) # (Q, t) # xs) \<in> cptn \<and> x = ((g,l1),l)" using Abrupt a1 by (metis old.prod.exhaust) thus ?thesis apply (cases t) by (auto simp add: Abrupt cptn.CptnEnv cptn.CptnComp cptn.CptnOne) next case (Stuck) thus ?thesis using a1 apply (cases t) by (auto simp add: cptn.CptnEnv cptn.CptnComp cptn.CptnOne) next case (Fault f) thus ?thesis using a1 apply (cases t,auto) by (auto simp add: Fault cptn.CptnEnv cptn.CptnComp cptn.CptnOne) qed *) qed lemma cptn_dest1_pair:"(\<Gamma>,x#x1#xs) \<in> cptn \<Longrightarrow> (\<Gamma>,x#[x1])\<in> cptn" proof - assume "(\<Gamma>,x#x1#xs) \<in> cptn" thus ?thesis using cptn_dest1 prod.collapse by metis qed lemma cptn_append_is_cptn [rule_format]: "\<forall>b a. (\<Gamma>,b#c1)\<in>cptn \<longrightarrow> (\<Gamma>,a#c2)\<in>cptn \<longrightarrow> (b#c1)!length c1=a \<longrightarrow> (\<Gamma>,b#c1@c2)\<in>cptn" apply(induct c1) apply simp apply clarify apply(erule cptn.cases,simp_all) by (simp add: cptn.Cptn) (* apply (simp add: cptn.CptnEnv) by (simp add: cptn.CptnComp) *) lemma cptn_dest_2: "(\<Gamma>,a#xs@ys) \<in> cptn \<Longrightarrow> (\<Gamma>,a#xs)\<in> cptn" proof (induct "xs" arbitrary: a) case Nil thus ?case using cptn.simps by fastforce next case (Cons x xs') then have "(\<Gamma>,a#[x])\<in>cptn" by (simp add: cptn_dest1_pair) also have "(\<Gamma>, x # xs') \<in> cptn" using Cons.hyps Cons.prems cptn_dest_pair by fastforce ultimately show ?case using cptn_append_is_cptn [of \<Gamma> a "[x]" x xs'] by force qed lemma tl_in_cptn: "\<lbrakk> (g,a#xs) \<in>cptn; xs\<noteq>[] \<rbrakk> \<Longrightarrow> (g,xs)\<in>cptn" by (force elim: cptn.cases) lemma sublist_in_cptn:"(\<Gamma>, ys@ xs) \<in> cptn \<Longrightarrow> xs\<noteq> [] \<Longrightarrow> (\<Gamma>, xs) \<in> cptn" proof(induct ys) case Nil then show ?case by auto next case (Cons a ys) then have "(\<Gamma>, a # (ys @ xs)) \<in> cptn " by auto then show ?case using cptn_elim_cases by (metis Cons.hyps Cons.prems(2) Nil_is_append_conv tl_in_cptn) qed subsection {* Relation between @{term "stepc_rtrancl"} and @{term "cptn"} *} lemma stepc_rtrancl_cptn: assumes step: "\<Gamma>\<turnstile>\<^sub>c (c,s) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (cf,sf)" shows "\<exists>xs. (\<Gamma>,(c, s)#xs) \<in> cptn \<and>(cf,sf) = (last ((c,s)#xs))" using step proof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans]) case Refl thus ?case using cptn.CptnOne by auto next case (Trans c s c' s') have "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', s') \<or> \<Gamma>\<turnstile>\<^sub>c (c, toSeq s) \<rightarrow> (c', toSeq s')" using Trans.hyps(1) step_ce_not_step_e_step_c by blast then show ?case by (metis (no_types) Trans.hyps(1) Trans.hyps(3) cptn.Cptn last_ConsR list.simps(3)) qed (* proof assume prem:"\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', s')" then have ceqc':"c=c'" using prem env_c_c' by auto obtain xs where xs_s:"(\<Gamma>, (c', s') # xs) \<in> cptn \<and> (cf, sf) = last ((c', s') # xs)" using Trans(3) by auto then have xs_f: "(\<Gamma>, (c, s)#(c', s') # xs) \<in> cptn" (* using cptn.CptnEnv ceqc' prem *) by (simp add: Trans.hyps(1) cptn.Cptn) (*by fastforce *) also have "last ((c', s') # xs) = last ((c,s)#(c', s') # xs)" by auto then have "(cf, sf) = last ((c, s) # (c', s') # xs)" using xs_s by auto thus ?thesis using xs_f by blast next assume prem:"\<Gamma>\<turnstile>\<^sub>c (c, toSeq s) \<rightarrow> (c', toSeq s')" obtain xs where xs_s:"(\<Gamma>, (c', s') # xs) \<in> cptn \<and> (cf, sf) = last ((c', s') # xs) " using Trans(3) by auto have "(\<Gamma>, (c, s) # (c', s') # xs) \<in> cptn" using Trans.hyps(1) by (simp add: cptn.Cptn xs_s) (* using cptn1.Cptn1 xs_s by fastforce *) also have "last ((c', s') # xs) = last ((c,s)#(c', s') # xs)" by auto ultimately show ?thesis using xs_s by fastforce qed qed *) lemma cptn_stepc_rtrancl: assumes cptn_step: "(\<Gamma>,(c, s)#xs) \<in> cptn" and cf_last:"(cf,sf) = (last ((c,s)#xs))" shows "\<Gamma>\<turnstile>\<^sub>c (c,s) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (cf,sf)" using cptn_step cf_last proof (induct xs arbitrary: c s) case Nil thus ?case by simp next case (Cons a xs c s) then obtain ca sa where eq_pair: "a=(ca,sa)" and "(cf, sf) = last ((ca,sa) # xs) " using Cons by (fastforce) then have "\<Gamma>\<turnstile>\<^sub>c (ca,sa) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (cf, sf)" using Cons using cptn_dest_pair by blast moreover have "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e (ca, sa)" using Cons eq_pair using cptn_elim_cases(2) by blast ultimately show ?case by auto (* have f1: "\<forall>f p pa. \<not> (f::'a \<Rightarrow> ('b, _, 'c,'d) LanguageCon.com option)\<turnstile>\<^sub>c p \<rightarrow> pa \<or> f\<turnstile>\<^sub>c p \<rightarrow>\<^sub>c\<^sub>e pa" by (simp add: c_step) have f2: "(\<Gamma>, (c, s) # (ca, sa) # xs) \<in> cptn" using `(\<Gamma>, (c, s) # a # xs) \<in> cptn` eq_pair by blast have f3: "\<forall>f p pa. \<not> (f::'a \<Rightarrow> ('b, _, 'c,'d) LanguageCon.com option)\<turnstile>\<^sub>c p \<rightarrow>\<^sub>e pa \<or> f\<turnstile>\<^sub>c p \<rightarrow>\<^sub>c\<^sub>e pa" using e_step by blast have "\<forall>c x. (\<Gamma>, (c, x) # xs) \<notin> cptn \<or> (cf, sf) \<noteq> last ((c, x) # xs) \<or> \<Gamma>\<turnstile>\<^sub>c (c, x) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (cf, sf)" using Cons.hyps by blast thus ?case using f3 f2 f1 by (metis (no_types) `(cf, sf) = last ((ca, sa) # xs)` converse_rtranclp_into_rtranclp cptn_elim_cases(2)) *) qed lemma cptn_stepc_rtran: assumes cptn_step: "(\<Gamma>,x#xs) \<in> cptn" and a1:"Suc i < length (x#xs)" shows "\<Gamma>\<turnstile>\<^sub>c ((x#xs)!i) \<rightarrow>\<^sub>c\<^sub>e ((x#xs)!(Suc i))" using cptn_step a1 proof (induct i arbitrary: x xs) case 0 then obtain x1 xs1 where xs:"xs=x1#xs1" by (metis length_Cons less_not_refl list.exhaust list.size(3)) then have "\<Gamma>\<turnstile>\<^sub>c x \<rightarrow>\<^sub>c\<^sub>e x1" using "0.prems"(1) cptn_elim_cases_pair(2) by blast then show ?case by (simp add: xs) next case (Suc i) then have "Suc i < length xs" by auto moreover obtain x1 xs1 where xs:"xs=x1#xs1" by (metis (full_types) calculation list.exhaust list.size(3) not_less0) moreover have "\<Gamma>\<turnstile>\<^sub>c ((x1 # xs1) ! i) \<rightarrow>\<^sub>c\<^sub>e ((x1 # xs1) ! Suc i)" using Suc using calculation(1) cptn_dest_pair xs by blast thus ?case using xs by auto qed lemma cptn_stepconf_rtrancl: assumes cptn_step: "(\<Gamma>,cfg1#xs) \<in> cptn" and cf_last:"cfg2 = (last (cfg1#xs))" shows "\<Gamma>\<turnstile>\<^sub>c cfg1 \<rightarrow>\<^sub>c\<^sub>e\<^sup>* cfg2" using cptn_step cf_last by (metis cptn_stepc_rtrancl prod.collapse) lemma cptn_all_steps_rtrancl: assumes cptn_step: "(\<Gamma>,cfg1#xs) \<in> cptn" shows "\<forall>i<length (cfg1#xs). \<Gamma>\<turnstile>\<^sub>c cfg1 \<rightarrow>\<^sub>c\<^sub>e\<^sup>* ((cfg1#xs)!i)" using cptn_step proof (induct xs arbitrary: cfg1) case Nil thus ?case by auto next case (Cons x xs1) thus ?case proof - have hyp:"\<forall>i<length (x # xs1). \<Gamma>\<turnstile>\<^sub>c x \<rightarrow>\<^sub>c\<^sub>e\<^sup>* ((x # xs1) ! i)" using Cons.hyps Cons.prems cptn_dest_pair by blast thus ?thesis proof { fix i assume a0:"i<length (cfg1 # x # xs1)" then have "Suc 0 < length (cfg1 # x # xs1)" by simp hence "\<Gamma>\<turnstile>\<^sub>c (cfg1 # x # xs1) ! 0 \<rightarrow>\<^sub>c\<^sub>e ((cfg1 # x # xs1) ! Suc 0)" using Cons.prems cptn_stepc_rtran by blast then have "\<Gamma>\<turnstile>\<^sub>c cfg1 \<rightarrow>\<^sub>c\<^sub>e x" using Cons by simp also have "i < Suc (Suc (length xs1))" using a0 by force ultimately have "\<Gamma>\<turnstile>\<^sub>c cfg1 \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (cfg1 # x # xs1) ! i" using hyp Cons using converse_rtranclp_into_rtranclp hyp less_Suc_eq_0_disj by auto } thus ?thesis by auto qed qed qed lemma last_not_F: assumes a0:"(\<Gamma>,xs)\<in>cptn" shows "snd (last xs) \<notin> Fault ` F \<Longrightarrow> \<forall>i < length xs. snd (xs!i) \<notin> Fault ` F" using a0 proof(induct) print_cases case (CptnOne \<Gamma> p s) thus ?case by auto next case (Cptn \<Gamma> P s t xs) thus ?case by (metis (no_types, hide_lams) ce_not_normal_s image_iff last_ConsR length_Cons less_Suc_eq_0_disj list.simps(3) nth_Cons_0 nth_Cons_Suc snd_conv xstate.distinct(3)) qed lemma Normal_Normal: assumes p1:"(\<Gamma>, (P, Normal s) # a # as) \<in> cptn" and p2:"(\<exists>sb. snd (last ((P, Normal s) # a # as)) = Normal sb)" shows "\<exists>sa. snd a = Normal sa" proof - obtain la1 la2 where last_prod:"last ((P, Normal s)# a#as) = (la1,la2)" by fastforce obtain a1 a2 where a_prod:"a=(a1,a2)" by fastforce from p1 have clos_p_a:"\<Gamma>\<turnstile>\<^sub>c (P,Normal s) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (a1, a2)" using a_prod cptn_elim_cases(2) by blast then have "\<Gamma>\<turnstile>\<^sub>c (fst a, snd a) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (la1,la2)" by (metis cptn_stepconf_rtrancl last_ConsR last_prod list.distinct(1) p1 prod.exhaust_sel tl_in_cptn) moreover obtain bb where "Normal bb = la2" using last_prod p2 by auto ultimately show ?thesis by (metis (no_types) steps_ce_not_Normal) qed lemma skip_all_skip: assumes a0:"(\<Gamma>,cfg)\<in>cptn" and a1:"cfg = (Skip,s)#cfg1" shows "\<forall>i<length cfg. fst(cfg!i) = Skip" using a0 a1 proof(induct cfg1 arbitrary:cfg s) case Nil thus ?case by auto next case (Cons x xs) have cptn:"(\<Gamma>,x#xs)\<in>cptn" using Cons.prems(1) Cons.prems(2) cptn_dest_pair by blast have "\<Gamma>\<turnstile>\<^sub>c(Skip,s) \<rightarrow>\<^sub>e x" using cptn_elim_cases_pair(2)[OF Cons(2)[simplified Cons(3)]] by (metis step_ce_dest stepc_elim_cases(1)) then obtain s' where x:"x = (Skip,s')" by (metis env_c_c' prod.exhaust_sel) moreover have cptn:"(\<Gamma>,x#xs)\<in>cptn" using Cons.prems(1) Cons.prems(2) cptn_dest_pair by blast moreover have xs:"x # xs = (LanguageCon.com.Skip, s') # xs" using x by auto ultimately show ?case using Cons(1)[OF cptn xs] Cons(3) using diff_Suc_1 fstI length_Cons less_Suc_eq_0_disj nth_Cons' by auto qed lemma skip_all_skip_throw: assumes a0:"(\<Gamma>,cfg)\<in>cptn" and a1:"cfg = (Throw,s)#cfg1" shows "\<forall>i<length cfg. fst(cfg!i) = Skip \<or> fst(cfg!i) = Throw" using a0 a1 proof(induct cfg1 arbitrary:cfg s) case Nil thus ?case by auto next case (Cons x xs) have cptn:"(\<Gamma>,x#xs)\<in>cptn" using Cons.prems(1) Cons.prems(2) cptn_dest_pair by blast have ce:"\<Gamma>\<turnstile>\<^sub>c(Throw,s) \<rightarrow>\<^sub>c\<^sub>e x" by (auto intro:cptn_elim_cases_pair(2)[OF Cons(2)[simplified Cons(3)]]) then obtain s' where x:"x = (Skip,s') \<or> x = (Throw, s')" using ce_Throw_toSkip by (metis eq_fst_iff) show ?case using x proof assume "x=(Skip,s')" thus ?thesis using skip_all_skip Cons(3) using cptn fstI length_Cons less_Suc_eq_0_disj nth_Cons' nth_Cons_Suc skip_all_skip by fastforce next assume x:"x=(Throw,s')" moreover have cptn:"(\<Gamma>,x#xs)\<in>cptn" using Cons.prems(1) Cons.prems(2) cptn_dest_pair by blast moreover have xs:"x # xs = (LanguageCon.com.Throw, s') # xs" using x by auto ultimately show ?case using Cons(1)[OF cptn xs] Cons(3) using diff_Suc_1 fstI length_Cons less_Suc_eq_0_disj nth_Cons' by auto qed qed lemma cptn_env_same_prog: assumes a0: "(\<Gamma>, l) \<in> cptn" and a1: "\<forall>k < j. (\<Gamma>\<turnstile>\<^sub>c(l!k) \<rightarrow>\<^sub>e (l!(Suc k)))" and a2: "Suc j < length l" shows "fst (l!j) = fst (l!0)" using a0 a1 a2 proof (induct j arbitrary: l) case 0 thus ?case by auto next case (Suc j) then have "fst (l!j) = fst (l!0)" by fastforce thus ?case using Suc by (metis (no_types) env_c_c' lessI prod.collapse) qed lemma takecptn_is_cptn [rule_format, elim!]: "\<forall>j. (\<Gamma>,c) \<in> cptn \<longrightarrow> (\<Gamma>, take (Suc j) c) \<in> cptn" apply(induct "c") apply(force elim: cptn.cases) apply clarify apply(case_tac j) apply simp apply(rule CptnOne) apply simp apply(force intro:cptn.intros elim:cptn.cases) done lemma dropcptn_is_cptn [rule_format,elim!]: "\<forall>j<length c. (\<Gamma>,c) \<in> cptn \<longrightarrow> (\<Gamma>, drop j c) \<in> cptn" apply(induct "c") apply(force elim: cptn.cases) apply clarify apply(case_tac j,simp+) apply(erule cptn.cases) apply simp apply force done subsection\<open>Modular Definition of Computation\<close> definition lift :: "('g\<times>'l,'p,'f,'e)com \<Rightarrow> ('g, 'l, 'p,'f,'e) config_gs \<Rightarrow> ('g, 'l, 'p,'f,'e) config_gs" where "lift Q \<equiv> \<lambda>(P, s). ((Seq P Q), s)" definition lift_catch :: "('g\<times>'l,'p,'f,'e)com \<Rightarrow> ('g, 'l, 'p,'f,'e) config_gs \<Rightarrow> ('g, 'l, 'p,'f,'e) config_gs" where "lift_catch Q \<equiv> \<lambda>(P, s). (Catch P Q, s)" lemma map_lift_eq_xs_xs':"map (lift a) xs = map (lift a) xs' \<Longrightarrow> xs=xs'" proof (induct xs arbitrary: xs') case Nil thus ?case by auto next case (Cons x xsa) then have a0:"(lift a) x # map (lift a) xsa = map (lift a) (x # xsa)" by fastforce also obtain x' xsa' where xs':"xs' = x'#xsa'" using Cons by auto ultimately have a1:"map (lift a) (x # xsa) =map (lift a) (x' # xsa')" using Cons by auto then have xs:"xsa=xsa'" using a0 a1 Cons by fastforce then have "(lift a) x' = (lift a) x" using a0 a1 by auto then have "x' = x" unfolding lift_def by (metis (no_types, lifting) LanguageCon.com.inject(3) case_prod_beta old.prod.inject prod.collapse) thus ?case using xs xs' by auto qed lemma map_lift_catch_eq_xs_xs':"map (lift_catch a) xs = map (lift_catch a) xs' \<Longrightarrow> xs=xs'" proof (induct xs arbitrary: xs') case Nil thus ?case by auto next case (Cons x xsa) then have a0:"(lift_catch a) x # map (lift_catch a) xsa = map (lift_catch a) (x # xsa)" by auto also obtain x' xsa' where xs':"xs' = x'#xsa'" using Cons by auto ultimately have a1:"map (lift_catch a) (x # xsa) =map (lift_catch a) (x' # xsa')" using Cons by auto then have xs:"xsa=xsa'" using a0 a1 Cons by fastforce then have "(lift_catch a) x' = (lift_catch a) x" using a0 a1 by auto then have "x' = x" unfolding lift_catch_def by (metis (no_types, lifting) LanguageCon.com.inject(9) case_prod_beta old.prod.inject prod.collapse) thus ?case using xs xs' by auto qed lemma map_lift_all_seq: assumes a0:"zs=map (lift a) xs" and a1:"i<length zs" shows "\<exists>b. fst (zs!i) = Seq b a" using a0 a1 proof (induct zs arbitrary: xs i) case Nil thus ?case by auto next case (Cons z1 zsa) thus ?case unfolding lift_def proof - assume a1: "z1 # zsa = map (\<lambda>b. case b of (P, s) \<Rightarrow> (LanguageCon.com.Seq P a, s)) xs" have "\<forall>p c. \<exists>x. \<forall>pa ca xa. (pa \<noteq> (ca::('a, 'b, 'c, 'd) LanguageCon.com, xa::('a, 'c) xstate) \<or> ca = fst pa) \<and> ((c::('a, 'b, 'c, 'd) LanguageCon.com) \<noteq> fst p \<or> (c, x::('a, 'c) xstate) = p)" by fastforce then obtain xx :: "('a, 'b, 'c, 'd) LanguageCon.com \<times> ('a, 'c) xstate \<Rightarrow> ('a, 'b, 'c, 'd) LanguageCon.com \<Rightarrow> ('a, 'c) xstate" where "\<And>p c x ca pa. (p \<noteq> (c::('a, 'b, 'c, 'd) LanguageCon.com, x::('a, 'c) xstate) \<or> c = fst p) \<and> (ca \<noteq> fst pa \<or> (ca, xx pa ca) = pa)" by (metis (full_types)) then show ?thesis using a1 \<open>i < length (z1 # zsa)\<close> by (simp add: Cons.hyps Cons.prems(1) case_prod_beta') qed qed lemma map_lift_catch_all_catch: assumes a0:"zs=map (lift_catch a) xs" and a1:"i<length zs" shows "\<exists>b. fst (zs!i) = Catch b a" using a0 a1 proof (induct zs arbitrary: xs i) case Nil thus ?case by auto next case (Cons z1 zsa) thus ?case unfolding lift_catch_def proof - assume a1: "z1 # zsa = map (\<lambda>b. case b of (P, s) \<Rightarrow> (LanguageCon.com.Catch P a, s)) xs" have "\<forall>p c. \<exists>x. \<forall>pa ca xa. (pa \<noteq> (ca::('a, 'b, 'c, 'd) LanguageCon.com, xa::('a, 'c) xstate) \<or> ca = fst pa) \<and> ((c::('a, 'b, 'c, 'd) LanguageCon.com) \<noteq> fst p \<or> (c, x::('a, 'c) xstate) = p)" by fastforce then obtain xx :: "('a, 'b, 'c, 'd) LanguageCon.com \<times> ('a, 'c) xstate \<Rightarrow> ('a, 'b, 'c, 'd) LanguageCon.com \<Rightarrow> ('a, 'c) xstate" where "\<And>p c x ca pa. (p \<noteq> (c::('a, 'b, 'c, 'd) LanguageCon.com, x::('a, 'c) xstate) \<or> c = fst p) \<and> (ca \<noteq> fst pa \<or> (ca, xx pa ca) = pa)" by (metis (full_types)) then show ?thesis using a1 \<open>i < length (z1 # zsa)\<close> by (simp add: Cons.hyps Cons.prems(1) case_prod_beta') qed qed lemma map_lift_some_eq_pos: assumes a0:"map (lift P) xs @ (P1, s1)#ys = map (lift P) xs'@ (P2, s2)#ys'" and a1:"\<forall>p0. P1\<noteq>Seq p0 P" and a2:"\<forall>p0. P2\<noteq>Seq p0 P" shows "length xs = length xs'" proof - {assume ass:"length xs \<noteq> length xs'" { assume ass:"length xs < length xs'" then have False using a0 map_lift_all_seq a1 a2 by (metis (no_types, lifting) fst_conv length_map nth_append nth_append_length) }note l=this { assume ass:"length xs > length xs'" then have False using a0 map_lift_all_seq a1 a2 by (metis (no_types, lifting) fst_conv length_map nth_append nth_append_length) } then have False using l ass by fastforce } thus ?thesis by auto qed lemma map_lift_some_eq: assumes a0:"map (lift P) xs @ (P1, s1)#ys = map (lift P) xs'@ (P2, s2)#ys'" and a1:"\<forall>p0. P1\<noteq>Seq p0 P" and a2:"\<forall>p0. P2\<noteq>Seq p0 P" shows "xs' = xs \<and> ys = ys'" proof - have "length xs = length xs'" using a0 map_lift_some_eq_pos a1 a2 by blast also have "xs' = xs" using a0 assms calculation map_lift_eq_xs_xs' by fastforce ultimately show ?thesis using a0 by fastforce qed lemma map_lift_catch_some_eq_pos: assumes a0:"map (lift_catch P) xs @ (P1, s1)#ys = map (lift_catch P) xs'@ (P2, s2)#ys'" and a1:"\<forall>p0. P1\<noteq>Catch p0 P" and a2:"\<forall>p0. P2\<noteq>Catch p0 P" shows "length xs = length xs'" proof - {assume ass:"length xs \<noteq> length xs'" { assume ass:"length xs < length xs'" then have False using a0 map_lift_catch_all_catch a1 a2 by (metis (no_types, lifting) fst_conv length_map nth_append nth_append_length) }note l=this { assume ass:"length xs > length xs'" then have False using a0 map_lift_catch_all_catch a1 a2 by (metis (no_types, lifting) fst_conv length_map nth_append nth_append_length) } then have False using l ass by fastforce } thus ?thesis by auto qed lemma map_lift_catch_some_eq: assumes a0:"map (lift_catch P) xs @ (P1, s1)#ys = map (lift_catch P) xs'@ (P2, s2)#ys'" and a1:"\<forall>p0. P1\<noteq>Catch p0 P" and a2:"\<forall>p0. P2\<noteq>Catch p0 P" shows "xs' = xs \<and> ys = ys'" proof - have "length xs = length xs'" using a0 map_lift_catch_some_eq_pos a1 a2 by blast also have "xs' = xs" using a0 assms calculation map_lift_catch_eq_xs_xs' by fastforce ultimately show ?thesis using a0 by fastforce qed inductive_set cptn_mod :: "(('g,'l,'p,'f,'e) confs) set" where CptnModOne: "(\<Gamma>,[(P, s)]) \<in> cptn_mod" | CptnModEnv: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,s) \<rightarrow>\<^sub>e (P,t);(\<Gamma>,(P, t)#xs) \<in> cptn_mod \<rbrakk> \<Longrightarrow> (\<Gamma>,(P, s)#(P, t)#xs) \<in> cptn_mod" | CptnModSkip: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,toSeq s) \<rightarrow> (Skip,toSeq t); redex P = P; \<forall>ns ns'. (s = Normal ns \<or> s = Abrupt ns) \<and> (t = Normal ns' \<or> t = Abrupt ns') \<longrightarrow> snd ns = snd ns'; (\<Gamma>,(Skip, t)#xs) \<in> cptn_mod \<rbrakk> \<Longrightarrow> (\<Gamma>,(P,s)#(Skip, t)#xs) \<in>cptn_mod" | CptnModThrow: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,toSeq s) \<rightarrow> (Throw,toSeq t); redex P = P; \<forall>ns ns'. (s = Normal ns \<or> s = Abrupt ns) \<and> (t = Normal ns' \<or> t = Abrupt ns') \<longrightarrow> snd ns = snd ns'; (\<Gamma>,(Throw, t)#xs) \<in> cptn_mod \<rbrakk> \<Longrightarrow> (\<Gamma>,(P,s)#(Throw, t)#xs) \<in>cptn_mod" | CptnModCondT: "\<lbrakk>(\<Gamma>,(P0, Normal s)#ys) \<in> cptn_mod; fst s \<in> b \<rbrakk> \<Longrightarrow> (\<Gamma>,((Cond b P0 P1), Normal s)#(P0, Normal s)#ys) \<in> cptn_mod" | CptnModCondF: "\<lbrakk>(\<Gamma>,(P1, Normal s)#ys) \<in> cptn_mod; fst s \<notin> b \<rbrakk> \<Longrightarrow> (\<Gamma>,((Cond b P0 P1), Normal s)#(P1, Normal s)#ys) \<in> cptn_mod" | CptnModSeq1: "\<lbrakk>(\<Gamma>,(P0, s)#xs) \<in> cptn_mod; zs=map (lift P1) xs \<rbrakk> \<Longrightarrow> (\<Gamma>,((Seq P0 P1), s)#zs) \<in> cptn_mod" | CptnModSeq2: "\<lbrakk>(\<Gamma>, (P0, s)#xs) \<in> cptn_mod; fst(last ((P0, s)#xs)) = Skip; (\<Gamma>,(P1, snd(last ((P0, s)#xs)))#ys) \<in> cptn_mod; zs=(map (lift P1) xs)@((P1, snd(last ((P0, s)#xs)))#ys) \<rbrakk> \<Longrightarrow> (\<Gamma>,((Seq P0 P1), s)#zs) \<in> cptn_mod" (*| CptnModSeq3: "\<lbrakk> (\<Gamma>,(P1, s)#xs) \<in> cptn_mod\<rbrakk> \<Longrightarrow> (\<Gamma>,((Seq Skip P1), s)#(P1, s)#xs) \<in> cptn_mod"*) | CptnModSeq3: "\<lbrakk>(\<Gamma>, (P0, Normal s)#xs) \<in> cptn_mod; fst(last ((P0, Normal s)#xs)) = Throw; snd(last ((P0, Normal s)#xs)) = Normal s'; (\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod; zs=(map (lift P1) xs)@((Throw,Normal s')#ys) \<rbrakk> \<Longrightarrow> (\<Gamma>,((Seq P0 P1), Normal s)#zs) \<in> cptn_mod" | CptnModWhile1: "\<lbrakk>(\<Gamma>, (P, Normal s)#xs) \<in> cptn_mod; fst s \<in> b; zs=map (lift (While b P)) xs \<rbrakk> \<Longrightarrow> (\<Gamma>, ((While b P), Normal s)# ((Seq P (While b P)),Normal s)#zs) \<in> cptn_mod" | CptnModWhile2: "\<lbrakk> (\<Gamma>, (P, Normal s)#xs) \<in> cptn_mod; fst(last ((P, Normal s)#xs))=Skip; fst s \<in> b; zs=(map (lift (While b P)) xs)@ (While b P, snd(last ((P, Normal s)#xs)))#ys; (\<Gamma>,(While b P, snd(last ((P, Normal s)#xs)))#ys) \<in> cptn_mod\<rbrakk> \<Longrightarrow> (\<Gamma>,(While b P, Normal s)# (Seq P (While b P), Normal s)#zs) \<in> cptn_mod" | CptnModWhile3: "\<lbrakk> (\<Gamma>, (P, Normal s)#xs) \<in> cptn_mod; fst(last ((P, Normal s)#xs))=Throw; fst s \<in> b; snd(last ((P, Normal s)#xs)) = Normal s'; (\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod; zs=(map (lift (While b P)) xs)@((Throw,Normal s')#ys)\<rbrakk> \<Longrightarrow> (\<Gamma>,(While b P, Normal s)# (Seq P (While b P), Normal s)#zs) \<in> cptn_mod" | CptnModCall: "\<lbrakk>(\<Gamma>,(bdy, Normal s)#ys) \<in> cptn_mod;\<Gamma> p = Some bdy; bdy\<noteq>Call p \<rbrakk> \<Longrightarrow> (\<Gamma>,((Call p), Normal s)#(bdy, Normal s)#ys) \<in> cptn_mod" | CptnModDynCom: "\<lbrakk>(\<Gamma>,(c (fst s), Normal s)#ys) \<in> cptn_mod \<rbrakk> \<Longrightarrow> (\<Gamma>,(DynCom c, Normal s)#(c (fst s), Normal s)#ys) \<in> cptn_mod" | CptnModGuard: "\<lbrakk>(\<Gamma>,(c, Normal s)#ys) \<in> cptn_mod; fst s \<in> g \<rbrakk> \<Longrightarrow> (\<Gamma>,(Guard f g c, Normal s)#(c, Normal s)#ys) \<in> cptn_mod" | CptnModCatch1: "\<lbrakk>(\<Gamma>,(P0, s)#xs) \<in> cptn_mod; zs=map (lift_catch P1) xs \<rbrakk> \<Longrightarrow> (\<Gamma>,((Catch P0 P1), s)#zs) \<in> cptn_mod" | CptnModCatch2: "\<lbrakk>(\<Gamma>, (P0, s)#xs) \<in> cptn_mod; fst(last ((P0, s)#xs)) = Skip; (\<Gamma>,(Skip,snd(last ((P0, s)#xs)))#ys) \<in> cptn_mod; zs=(map (lift_catch P1) xs)@((Skip,snd(last ((P0, s)#xs)))#ys) \<rbrakk> \<Longrightarrow> (\<Gamma>,((Catch P0 P1), s)#zs) \<in> cptn_mod" | CptnModCatch3: "\<lbrakk>(\<Gamma>, (P0, Normal s)#xs) \<in> cptn_mod; fst(last ((P0, Normal s)#xs)) = Throw; snd(last ((P0, Normal s)#xs)) = Normal s'; (\<Gamma>,(P1, snd(last ((P0, Normal s)#xs)))#ys) \<in> cptn_mod; zs=(map (lift_catch P1) xs)@((P1, snd(last ((P0, Normal s)#xs)))#ys) \<rbrakk> \<Longrightarrow> (\<Gamma>,((Catch P0 P1), Normal s)#zs) \<in> cptn_mod" lemmas CptnMod_induct = cptn_mod.induct [of _ "[(c,s)]", split_format (complete), case_names CptnModOne CptnModEnv CptnModSkip CptnModThrow CptnModCondT CptnModCondF CptnModSeq1 CptnModSeq2 CptnModSeq3 CptnModSeq4 CptnModWhile1 CptnModWhile2 CptnModWhile3 CptnModCall CptnModDynCom CptnModGuard CptnModCatch1 CptnModCatch2 CptnModCatch3, induct set] inductive_cases CptnMod_elim_cases [cases set]: "(\<Gamma>,(Skip, s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(Guard f g c, s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(Basic f e, s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(Spec r e, s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(Seq c1 c2, s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(Cond b c1 c2, s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(Await b c2 e, s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(Call p, s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(DynCom c,s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(Throw,s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(Catch c1 c2,s)#u#xs) \<in> cptn_mod" inductive_cases CptnMod_Normal_elim_cases [cases set]: "(\<Gamma>,(Skip, Normal s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(Guard f g c, Normal s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(Basic f e, Normal s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(Spec r e, Normal s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(Seq c1 c2, Normal s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(Cond b c1 c2, Normal s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(Await b c2 e, Normal s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(Call p, Normal s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(DynCom c,Normal s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(Throw,Normal s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(Catch c1 c2,Normal s)#u#xs) \<in> cptn_mod" "(\<Gamma>,(P,Normal s)#(P,s')#xs) \<in> cptn_mod" "(\<Gamma>,(P,Abrupt s)#(P,Abrupt s')#xs) \<in> cptn_mod" "(\<Gamma>,(P,Stuck)#(P,Stuck)#xs) \<in> cptn_mod" "(\<Gamma>,(P,Fault f)#(P,Fault f)#xs) \<in> cptn_mod" inductive_cases CptnMod_env_elim_cases [cases set]: "(\<Gamma>,(P,Normal s)#(P,s')#xs) \<in> cptn_mod" "(\<Gamma>,(P,Abrupt s)#(P,Abrupt s')#xs) \<in> cptn_mod" "(\<Gamma>,(P,Stuck)#(P,Stuck)#xs) \<in> cptn_mod" "(\<Gamma>,(P,Fault f)#(P,Fault f)#xs) \<in> cptn_mod" subsection \<open>Equivalence of small semantics and computational\<close> definition catch_cond where "catch_cond zs Q xs P s s'' s' \<Gamma> \<equiv> (zs=(map (lift_catch Q) xs) \<or> ((fst(((P, s)#xs)!length xs)=Throw \<and> snd(last ((P, s)#xs)) = Normal s' \<and> s=Normal s''\<and> (\<exists>ys. (\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod \<and> zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or> ((fst(((P, s)#xs)!length xs)=Skip \<and> (\<exists>ys. (\<Gamma>,(Skip,snd(last ((P, s)#xs)))#ys) \<in> cptn_mod \<and> zs=(map (lift_catch Q) xs)@((Skip,snd(last ((P, s)#xs)))#ys))))) " lemma div_catch: assumes cptn_m:"(\<Gamma>,list) \<in> cptn_mod" shows "(\<forall>s P Q zs. list=(Catch P Q, s)#zs \<longrightarrow> (\<exists>xs s' s''. (\<Gamma>,(P, s)#xs) \<in> cptn_mod \<and> catch_cond zs Q xs P s s'' s' \<Gamma>)) " unfolding catch_cond_def using cptn_m proof (induct rule: cptn_mod.induct) case (CptnModOne \<Gamma> P s) thus ?case using cptn_mod.CptnModOne by blast next case (CptnModSkip \<Gamma> P s t xs) from CptnModSkip.hyps have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Skip, toSeq t)" by auto from CptnModSkip.hyps have noskip: "~(P=Skip)" using stepc_elim_cases(1) by blast have no_catch: "\<forall>p1 p2. \<not>(P=Catch p1 p2)" using CptnModSkip.hyps(2) redex_not_Catch by auto from CptnModSkip.hyps have in_cptn_mod: "(\<Gamma>, (Skip, t) # xs) \<in> cptn_mod" by auto then show ?case using no_catch by simp next case (CptnModThrow \<Gamma> P s t xs) from CptnModThrow.hyps have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Throw, toSeq t)" by auto from CptnModThrow.hyps have in_cptn_mod: "(\<Gamma>, (Throw, t) # xs) \<in> cptn_mod" by auto have no_catch: "\<forall>p1 p2. \<not>(P=Catch p1 p2)" using CptnModThrow.hyps(2) redex_not_Catch by auto then show ?case by auto next case (CptnModCondT \<Gamma> P0 s ys b P1) thus ?case using CptnModOne by blast next case (CptnModCondF \<Gamma> P0 s ys b P1) thus ?case using CptnModOne by blast next case (CptnModCatch1 sa P Q zs) thus ?case by blast next case (CptnModCatch2 \<Gamma> P0 s xs ys zs P1) from CptnModCatch2.hyps(3) have last:"fst (((P0, s) # xs) ! length xs) = Skip" by (simp add: last_length) have P0cptn:"(\<Gamma>, (P0, s) # xs) \<in> cptn_mod" by fact then have "zs = map (lift_catch P1) xs @((Skip,snd(last ((P0, s)#xs)))#ys)" by (simp add:CptnModCatch2.hyps) show ?case proof -{ fix sa P Q zsa assume eq:"(Catch P0 P1, s) # zs = (Catch P Q, sa) # zsa" then have "P0 =P \<and> P1 = Q \<and> s=sa \<and> zs=zsa" by auto then have "(P0, s) = (P, sa)" by auto have "last ((P0, s) # xs) = ((P, sa) # xs) ! length xs" by (simp add: `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa` last_length) then have "zs = (map (lift_catch Q) xs)@((Skip,snd(last ((P0, s)#xs)))#ys)" using `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa` `zs = map (lift_catch P1) xs @ ((Skip,snd(last ((P0, s)#xs)))#ys)` by force then have "(\<exists>xs s' s''. ((\<Gamma>,(P, s)#xs) \<in> cptn_mod \<and> ((zs=(map (lift_catch Q) xs) \<or> ((fst(((P, s)#xs)!length xs)=Throw \<and> snd(last ((P, s)#xs)) = Normal s' \<and> s=Normal s''\<and> (\<exists>ys. (\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod \<and> zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or> (\<exists>ys. ((fst(((P, s)#xs)!length xs)=Skip \<and> (\<Gamma>,(Skip,snd(last ((P, s)#xs)))#ys) \<in> cptn_mod \<and> zs=(map (lift_catch Q) xs)@((Skip,snd(last ((P0, s)#xs)))#ys))))))))" using P0cptn `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa` last CptnModCatch2.hyps(4) by blast } thus ?thesis by auto qed next case (CptnModCatch3 \<Gamma> P0 s xs s' P1 ys zs) from CptnModCatch3.hyps(3) have last:"fst (((P0, Normal s) # xs) ! length xs) = Throw" by (simp add: last_length) from CptnModCatch3.hyps(4) have lastnormal:"snd (last ((P0, Normal s) # xs)) = Normal s'" by (simp add: last_length) have P0cptn:"(\<Gamma>, (P0, Normal s) # xs) \<in> cptn_mod" by fact from CptnModCatch3.hyps(5) have P1cptn:"(\<Gamma>, (P1, snd (((P0, Normal s) # xs) ! length xs)) # ys) \<in> cptn_mod" by (simp add: last_length) then have "zs = map (lift_catch P1) xs @ (P1, snd (last ((P0, Normal s) # xs))) # ys" by (simp add:CptnModCatch3.hyps) show ?case proof -{ fix sa P Q zsa assume eq:"(Catch P0 P1, Normal s) # zs = (Catch P Q, Normal sa) # zsa" then have "P0 =P \<and> P1 = Q \<and> Normal s= Normal sa \<and> zs=zsa" by auto have "last ((P0, Normal s) # xs) = ((P, Normal sa) # xs) ! length xs" by (simp add: `P0 = P \<and> P1 = Q \<and> Normal s = Normal sa \<and> zs = zsa` last_length) then have "zsa = map (lift_catch Q) xs @ (Q, snd (((P, Normal sa) # xs) ! length xs)) # ys" using `P0 = P \<and> P1 = Q \<and> Normal s = Normal sa \<and> zs = zsa` `zs = map (lift_catch P1) xs @ (P1, snd (last ((P0, Normal s) # xs))) # ys` by force then have "(\<Gamma>, (P, Normal s) # xs) \<in> cptn_mod \<and> (fst(((P, Normal s)#xs)!length xs)=Throw \<and> snd(last ((P, Normal s)#xs)) = Normal s' \<and> (\<exists>ys. (\<Gamma>,(Q, snd(((P, Normal s)#xs)!length xs))#ys) \<in> cptn_mod \<and> zs=(map (lift_catch Q) xs)@((Q, snd(((P, Normal s)#xs)!length xs))#ys)))" using lastnormal P1cptn P0cptn `P0 = P \<and> P1 = Q \<and> Normal s = Normal sa \<and> zs = zsa` last by auto }note this [of P0 P1 s zs] thus ?thesis by blast qed next case (CptnModEnv \<Gamma> P s t xs) then have step:"(\<Gamma>, (P, t) # xs) \<in> cptn_mod" by auto have step_e: "\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (P, t)" using CptnModEnv by auto show ?case proof (cases P) case (Catch P1 P2) then have eq_P_Catch:"(P, t) # xs = (LanguageCon.com.Catch P1 P2, t) # xs" by auto then obtain xsa t' t'' where p1:"(\<Gamma>, (P1, t) # xsa) \<in> cptn_mod" and p2:" (xs = map (lift_catch P2) xsa \<or> fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \<and> snd (last ((P1, t) # xsa)) = Normal t' \<and> t = Normal t'' \<and> (\<exists>ys. (\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<in> cptn_mod \<and> xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<or> fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Skip \<and> (\<exists>ys.(\<Gamma>,(Skip,snd(last ((P1, t)#xsa)))#ys) \<in> cptn_mod \<and> xs = map (lift_catch P2) xsa @ ((LanguageCon.com.Skip, snd (last ((P1, t) # xsa)))#ys)))" using CptnModEnv(3) by auto have all_step:"(\<Gamma>, (P1, s)#((P1, t) # xsa)) \<in> cptn_mod" using cptn_mod.CptnModEnv env_intro p1 step_e by blast show ?thesis using p2 proof assume "xs = map (lift_catch P2) xsa" have "(P, t) # xs = map (lift_catch P2) ((P1, t) # xsa)" by (simp add: `xs = map (lift_catch P2) xsa` lift_catch_def local.Catch) thus ?thesis using all_step eq_P_Catch by fastforce next assume "fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \<and> snd (last ((P1, t) # xsa)) = Normal t' \<and> t = Normal t'' \<and> (\<exists>ys. (\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<in> cptn_mod \<and> xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<or> fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Skip \<and> (\<exists>ys. (\<Gamma>,(Skip,snd(last ((P1, t)#xsa)))#ys) \<in> cptn_mod \<and> xs = map (lift_catch P2) xsa @ ((LanguageCon.com.Skip, snd (last ((P1, t) # xsa)))#ys))" then show ?thesis proof assume a1:"fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \<and> snd (last ((P1, t) # xsa)) = Normal t' \<and> t = Normal t'' \<and> (\<exists>ys. (\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<in> cptn_mod \<and> xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys)" then obtain ys where p2_exec:"(\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<in> cptn_mod \<and> xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys" by fastforce from a1 obtain t1 where t_normal: "t=Normal t1" using env_normal_s'_normal_s by blast have f1:"fst (((P1, s)#(P1, t) # xsa) ! length ((P1, t)#xsa)) = LanguageCon.com.Throw" using a1 by fastforce from a1 have last_normal: "snd (last ((P1, s)#(P1, t) # xsa)) = Normal t'" by fastforce then have p2_long_exec: "(\<Gamma>, (P2, snd (((P1, s)#(P1, t) # xsa) ! length ((P1, s)#xsa))) # ys) \<in> cptn_mod \<and> (P, t)#xs = map (lift_catch P2) ((P1, t) # xsa) @ (P2, snd (((P1, s)#(P1, t) # xsa) ! length ((P1, s)#xsa))) # ys" using p2_exec by (simp add: lift_catch_def local.Catch) thus ?thesis using a1 f1 last_normal all_step eq_P_Catch by (clarify, metis (no_types) list.size(4) not_step_c_env step_e) next assume as1:"fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Skip \<and> (\<exists>ys. (\<Gamma>,(Skip,snd(last ((P1, t)#xsa)))#ys) \<in> cptn_mod \<and> xs = map (lift_catch P2) xsa @ ((LanguageCon.com.Skip, snd (last ((P1, t) # xsa)))#ys))" then obtain ys where p1:"(\<Gamma>,(Skip,snd(last ((P1, t)#xsa)))#ys) \<in> cptn_mod \<and> (P, t)#xs = map (lift_catch P2) ((P1, t) # xsa) @ ((LanguageCon.com.Skip, snd (last ((P1, t) # xsa)))#ys)" proof - assume a1: "\<And>ys. (\<Gamma>, (LanguageCon.com.Skip, snd (last ((P1, t) # xsa))) # ys) \<in> cptn_mod \<and> (P, t) # xs = map (lift_catch P2) ((P1, t) # xsa) @ (LanguageCon.com.Skip, snd (last ((P1, t) # xsa))) # ys \<Longrightarrow> thesis" have "(LanguageCon.com.Catch P1 P2, t) # map (lift_catch P2) xsa = map (lift_catch P2) ((P1, t) # xsa)" by (simp add: lift_catch_def) thus ?thesis using a1 as1 eq_P_Catch by moura qed from as1 have p2: "fst (((P1, s)#(P1, t) # xsa) ! length ((P1, t) #xsa)) = LanguageCon.com.Skip" by fastforce thus ?thesis using p1 all_step eq_P_Catch by fastforce qed qed qed (auto) qed(force+) definition seq_cond where "seq_cond zs Q xs P s s'' s' \<Gamma> \<equiv> (zs=(map (lift Q) xs) \<or> ((fst(((P, s)#xs)!length xs)=Skip \<and> (\<exists>ys. (\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod \<and> zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or> ((fst(((P, s)#xs)!length xs)=Throw \<and> snd(last ((P, s)#xs)) = Normal s' \<and> s=Normal s''\<and> (\<exists>ys. (\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod \<and> zs=(map (lift Q) xs)@((Throw,Normal s')#ys))))) " lemma div_seq: assumes cptn_m:"(\<Gamma>,list) \<in> cptn_mod" shows "(\<forall>s P Q zs. list=(Seq P Q, s)#zs \<longrightarrow> (\<exists>xs s' s''. (\<Gamma>,(P, s)#xs) \<in> cptn_mod \<and> seq_cond zs Q xs P s s'' s' \<Gamma>)) " unfolding seq_cond_def using cptn_m proof (induct rule: cptn_mod.induct) case (CptnModOne \<Gamma> P s) thus ?case using cptn_mod.CptnModOne by blast next case (CptnModSkip \<Gamma> P s t xs) from CptnModSkip.hyps have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Skip, toSeq t)" by auto from CptnModSkip.hyps have noskip: "~(P=Skip)" using stepc_elim_cases(1) by blast have x: "\<forall>c c1 c2. redex c = Seq c1 c2 \<Longrightarrow> False" using redex_not_Seq by blast from CptnModSkip.hyps have in_cptn_mod: "(\<Gamma>, (Skip, t) # xs) \<in> cptn_mod" by auto then show ?case using CptnModSkip.hyps(2) SmallStepCon.redex_not_Seq by blast next case (CptnModThrow \<Gamma> P s t xs) from CptnModThrow.hyps have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Throw, toSeq t)" by auto moreover from CptnModThrow.hyps have in_cptn_mod: "(\<Gamma>, (Throw, t) # xs) \<in> cptn_mod" by auto have no_seq: "\<forall>p1 p2. \<not>(P=Seq p1 p2)" using CptnModThrow.hyps(2) redex_not_Seq by auto ultimately show ?case by auto next case (CptnModCondT \<Gamma> P0 s ys b P1) thus ?case by auto next case (CptnModCondF \<Gamma> P0 s ys b P1) thus ?case by auto next case (CptnModSeq1 \<Gamma> P0 s xs zs P1) thus ?case by blast next case (CptnModSeq2 \<Gamma> P0 s xs P1 ys zs) from CptnModSeq2.hyps(3) last_length have last:"fst (((P0, s) # xs) ! length xs) = Skip" by (simp add: last_length) have P0cptn:"(\<Gamma>, (P0, s) # xs) \<in> cptn_mod" by fact from CptnModSeq2.hyps(4) have P1cptn:"(\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod" by (simp add: last_length) then have "zs = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys" by (simp add:CptnModSeq2.hyps) show ?case proof -{ fix sa P Q zsa assume eq:"(Seq P0 P1, s) # zs = (Seq P Q, sa) # zsa" then have "P0 =P \<and> P1 = Q \<and> s=sa \<and> zs=zsa" by auto have "last ((P0, s) # xs) = ((P, sa) # xs) ! length xs" by (simp add: `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa` last_length) then have "zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys" using `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa` `zs = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys` by force then have "(\<exists>xs s' s''. (\<Gamma>, (P, sa) # xs) \<in> cptn_mod \<and> (zsa = map (lift Q) xs \<or> fst (((P, sa) # xs) ! length xs) = Skip \<and> (\<exists>ys. (\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<in> cptn_mod \<and> zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<or> ((fst(((P, sa)#xs)!length xs)=Throw \<and> snd(last ((P, sa)#xs)) = Normal s' \<and> s=Normal s''\<and> (\<exists>ys. (\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod \<and> zsa=(map (lift Q) xs)@((Throw,Normal s')#ys)))))) " using P0cptn P1cptn `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa` last by blast } thus ?case by auto qed next case (CptnModSeq3 \<Gamma> P0 s xs s' ys zs P1) from CptnModSeq3.hyps(3) have last:"fst (((P0, Normal s) # xs) ! length xs) = Throw" by (simp add: last_length) have P0cptn:"(\<Gamma>, (P0, Normal s) # xs) \<in> cptn_mod" by fact from CptnModSeq3.hyps(4) have lastnormal:"snd (last ((P0, Normal s) # xs)) = Normal s'" by (simp add: last_length) then have "zs = map (lift P1) xs @ ((Throw, Normal s')#ys)" by (simp add:CptnModSeq3.hyps) show ?case proof -{ fix sa P Q zsa assume eq:"(Seq P0 P1, Normal s) # zs = (Seq P Q, Normal sa) # zsa" then have "P0 =P \<and> P1 = Q \<and> Normal s=Normal sa \<and> zs=zsa" by auto then have "(P0, Normal s) = (P, Normal sa)" by auto have "last ((P0, Normal s) # xs) = ((P, Normal sa) # xs) ! length xs" by (simp add: `P0 = P \<and> P1 = Q \<and> Normal s = Normal sa \<and> zs = zsa` last_length) then have zsa:"zsa = (map (lift Q) xs)@((Throw,Normal s')#ys)" using `P0 = P \<and> P1 = Q \<and> Normal s = Normal sa \<and> zs = zsa` `zs = map (lift P1) xs @ ((Throw, Normal s')#ys)` by force then have a1:"(\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod" using CptnModSeq3.hyps(5) by blast then have "(\<exists>xs s'. (\<Gamma>, (P, Normal sa) # xs) \<in> cptn_mod \<and> (zsa = map (lift Q) xs \<or> fst (((P,Normal sa) # xs) ! length xs) = Skip \<and> (\<exists>ys. (\<Gamma>, (Q, snd (((P, Normal sa) # xs) ! length xs)) # ys) \<in> cptn_mod \<and> zsa = map (lift Q) xs @ (Q, snd (((P, Normal sa) # xs) ! length xs)) # ys) \<or> ((fst(((P, Normal sa)#xs)!length xs)=Throw \<and> snd(last ((P, Normal sa)#xs)) = Normal s' \<and> (\<exists>ys. (\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod \<and> zsa=(map (lift Q) xs)@((Throw,Normal s')#ys))))))" using P0cptn zsa a1 last lastnormal by (metis \<open>(P0, Normal s) = (P, Normal sa)\<close>) } thus ?thesis by fast qed next case (CptnModEnv \<Gamma> P s t zs) then have step:"(\<Gamma>, (P, t) # zs) \<in> cptn_mod" by auto have step_e: "\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (P, t)" using CptnModEnv by auto show ?case proof (cases P) case (Seq P1 P2) then have eq_P:"(P, t) # zs = (LanguageCon.com.Seq P1 P2, t) # zs" by auto then obtain xs t' t'' where p1:"(\<Gamma>, (P1, t) # xs) \<in> cptn_mod" and p2:" (zs = map (lift P2) xs \<or> fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \<and> (\<exists>ys. (\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<in> cptn_mod \<and> zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<or> fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Throw \<and> snd (last ((P1, t) # xs)) = Normal t' \<and> t = Normal t'' \<and> (\<exists>ys. (\<Gamma>,(Throw,Normal t')#ys) \<in> cptn_mod \<and> zs = map (lift P2) xs @ ((LanguageCon.com.Throw, Normal t')#ys))) " using CptnModEnv(3) by auto have all_step:"(\<Gamma>, (P1, s)#((P1, t) # xs)) \<in> cptn_mod" using cptn_mod.CptnModEnv env_intro p1 step_e by blast show ?thesis using p2 proof assume "zs = map (lift P2) xs" have "(P, t) # zs = map (lift P2) ((P1, t) # xs)" by (simp add: `zs = map (lift P2) xs` lift_def local.Seq) thus ?thesis using all_step eq_P by fastforce next assume "fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \<and> (\<exists>ys. (\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<in> cptn_mod \<and> zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<or> fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Throw \<and> snd (last ((P1, t) # xs)) = Normal t' \<and> t = Normal t'' \<and> (\<exists>ys. (\<Gamma>,(Throw,Normal t')#ys) \<in> cptn_mod \<and> zs = map (lift P2) xs @ ((LanguageCon.com.Throw, Normal t')#ys))" then show ?thesis proof assume a1:"fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \<and> (\<exists>ys. (\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<in> cptn_mod \<and> zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys)" from a1 obtain ys where p2_exec:"(\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<in> cptn_mod \<and> zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys" by auto have f1:"fst (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs)) = LanguageCon.com.Skip" using a1 by fastforce then have p2_long_exec: "(\<Gamma>, (P2, snd (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs))) # ys) \<in> cptn_mod \<and> (P, t)#zs = map (lift P2) ((P1, t) # xs) @ (P2, snd (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs))) # ys" using p2_exec by (simp add: lift_def local.Seq) thus ?thesis using a1 f1 all_step eq_P by blast next assume a1:"fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Throw \<and> snd (last ((P1, t) # xs)) = Normal t' \<and> t = Normal t'' \<and> (\<exists>ys. (\<Gamma>,(Throw,Normal t')#ys) \<in> cptn_mod \<and> zs = map (lift P2) xs @ ((LanguageCon.com.Throw, Normal t')#ys))" then have last_throw: "fst (((P1, s)#(P1, t) # xs) ! length ((P1, t) #xs)) = LanguageCon.com.Throw" by fastforce from a1 have last_normal: "snd (last ((P1, s)#(P1, t) # xs)) = Normal t'" by fastforce have seq_lift: "(LanguageCon.com.Seq P1 P2, t) # map (lift P2) xs = map (lift P2) ((P1, t) # xs)" by (simp add: a1 lift_def) thus ?thesis using a1 last_throw last_normal all_step eq_P by (clarify, metis (no_types, lifting) append_Cons env_normal_s'_normal_s step_e) qed qed qed (auto) qed (force)+ lemma cptn_onlyif_cptn_mod_aux: assumes vars:"v = toSeq s" and vars1:"w = toSeq t" and stepseq:"\<Gamma>\<turnstile>\<^sub>c (P,v) \<rightarrow> (Q,w)" and normal_eq_l:"\<forall>ns ns'. (s = Normal ns \<or> s = Abrupt ns) \<and> (t = Normal ns' \<or> t = Abrupt ns') \<longrightarrow> snd ns = snd ns'" and stepmod:"(\<Gamma>,(Q,t)#xs) \<in> cptn_mod" shows "(\<Gamma>,(P,s)#(Q,t)#xs) \<in> cptn_mod" using stepseq normal_eq_l stepmod vars vars1 proof (induct arbitrary: xs) case (Basicc f e s1) thus ?case using stepc.Basicc[of \<Gamma> f e s1] by (simp add: cptn_mod.CptnModSkip) next case (Specc s1 t1 r) thus ?case using stepc.Specc[of s1 t1 r \<Gamma>] by (simp add: cptn_mod.CptnModSkip) next case (SpecStuckc s1 r) thus ?case using stepc.SpecStuckc[of s1 _ \<Gamma>] by (simp add: cptn_mod.CptnModSkip) next case (Guardc s1 g f c) thus ?case by (metis (mono_tags, lifting) cptn_mod.CptnModGuard prod_eq_iff toSeq.simps(1) toSeq_not_Normal xstate.inject(1)) next case (GuardFaultc) thus ?case by (metis SmallStepCon.redex.simps(9) cptn_mod.CptnModSkip stepc.GuardFaultc) next case (Seqc c1 s1 c1' t1 c2) have step: "\<Gamma>\<turnstile>\<^sub>c (c1, s1) \<rightarrow> (c1', t1)" by (simp add: Seqc.hyps(1)) then have nsc1: "c1\<noteq>Skip" using stepc_elim_cases(1) by blast have assum: "(\<Gamma>, (Seq c1' c2, t) # xs) \<in> cptn_mod" using Seqc.prems by blast have divseq:"(\<forall>s P Q zs. (Seq c1' c2, t) # xs=(Seq P Q, s)#zs \<longrightarrow> (\<exists>xs sv' sv''. ((\<Gamma>,(P, s)#xs) \<in> cptn_mod \<and> (zs=(map (lift Q) xs) \<or> ((fst(((P, s)#xs)!length xs)=Skip \<and> (\<exists>ys. (\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod \<and> zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or> ((fst(((P, s)#xs)!length xs)=Throw \<and> snd(last ((P, s)#xs)) = Normal sv' \<and> t=Normal sv''\<and> (\<exists>ys. (\<Gamma>,(Throw,Normal sv')#ys) \<in> cptn_mod \<and> zs=(map (lift Q) xs)@((Throw,Normal sv')#ys)) )))) ))" using div_seq [OF assum] unfolding seq_cond_def by auto {fix sa P Q zsa assume ass:"(Seq c1' c2, t) # xs = (Seq P Q, sa) # zsa" then have eqs:"c1' = P \<and> c2 = Q \<and> t = sa \<and> xs = zsa" by auto then have "(\<exists>xs sv' sv''. (\<Gamma>, (P, sa) # xs) \<in> cptn_mod \<and> (zsa = map (lift Q) xs \<or> fst (((P, sa) # xs) ! length xs) = Skip \<and> (\<exists>ys. (\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<in> cptn_mod \<and> zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<or> ((fst(((P, sa)#xs)!length xs)=Throw \<and> snd(last ((P, sa)#xs)) = Normal sv' \<and> t=Normal sv''\<and> (\<exists>ys. (\<Gamma>,(Throw,Normal sv')#ys) \<in> cptn_mod \<and> zsa=(map (lift Q) xs)@((Throw,Normal sv')#ys))))))" using ass divseq by blast } note conc=this [of c1' c2 t xs] then obtain xs' sa' sa'' where split:"(\<Gamma>, (c1', t) # xs') \<in> cptn_mod \<and> (xs = map (lift c2) xs' \<or> fst (((c1', t) # xs') ! length xs') = Skip \<and> (\<exists>ys. (\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and> xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or> ((fst(((c1', t)#xs')!length xs')=Throw \<and> snd(last ((c1', t)#xs')) = Normal sa' \<and> t=Normal sa''\<and> (\<exists>ys. (\<Gamma>,(Throw,Normal sa')#ys) \<in> cptn_mod \<and> xs=(map (lift c2) xs')@((Throw,Normal sa')#ys)) )))" by blast then have "(xs = map (lift c2) xs' \<or> fst (((c1', t) # xs') ! length xs') = Skip \<and> (\<exists>ys. (\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and> xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or> ((fst(((c1', t)#xs')!length xs')=Throw \<and> snd(last ((c1',t)#xs')) = Normal sa' \<and> t=Normal sa''\<and> (\<exists>ys. (\<Gamma>,(Throw,Normal sa')#ys) \<in> cptn_mod \<and> xs=(map (lift c2) xs')@((Throw,Normal sa')#ys)))))" by auto thus ?case proof{ assume c1'nonf:"xs = map (lift c2) xs'" then have c1'cptn:"(\<Gamma>, (c1', t) # xs') \<in> cptn_mod" using split by blast then have induct_step: "(\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod" using Seqc.hyps(2) using Seqc.prems(3) Seqc.prems(4) normal_eq_l by blast then have "(Seq c1' c2, t)#xs = map (lift c2) ((c1', t)#xs')" using c1'nonf by (simp add: CptnModSeq1 lift_def) thus ?thesis using c1'nonf c1'cptn induct_step by (auto simp add: CptnModSeq1) next assume "fst (((c1', t) # xs') ! length xs') = Skip \<and> (\<exists>ys. (\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and> xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or> ((fst(((c1', t)#xs')!length xs')=Throw \<and> snd(last ((c1', t)#xs')) = Normal sa' \<and> t=Normal sa''\<and> (\<exists>ys. (\<Gamma>,(Throw,Normal sa')#ys) \<in> cptn_mod \<and> xs=(map (lift c2) xs')@((Throw,Normal sa')#ys))))" thus ?thesis proof assume assth:"fst (((c1', t) # xs') ! length xs') = Skip \<and> (\<exists>ys. (\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and> xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys)" then obtain ys where split':"(\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and> xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys" by auto then have c1'cptn:"(\<Gamma>, (c1', t) # xs') \<in> cptn_mod" using split by blast then have induct_step: "(\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod" using Seqc.hyps(2) using Seqc.prems(3) Seqc.prems(4) normal_eq_l by blast then have seqmap:"(Seq c1 c2, s)#(Seq c1' c2, t)#xs = map (lift c2) ((c1,s)#(c1', t)#xs') @ (c2, snd (((c1', t) # xs') ! length xs')) # ys" using split' by (simp add: CptnModSeq2 lift_def) then have lastc1:"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'" by (simp add: last_length) then have lastc1skip:"fst (last ((c1, s) # (c1', t) # xs')) = Skip" using assth by fastforce thus ?thesis using seqmap split' last_length cptn_mod.CptnModSeq2 induct_step lastc1 lastc1skip by fastforce next assume assm:"((fst(((c1', t)#xs')!length xs')=Throw \<and> snd(last ((c1', t)#xs')) = Normal sa' \<and> t=Normal sa''\<and> (\<exists>ys. (\<Gamma>,(Throw,Normal sa')#ys) \<in> cptn_mod \<and> xs=(map (lift c2) xs')@((Throw,Normal sa')#ys))))" then have s'eqsa'': "t=Normal sa''" by auto then have snormal: "\<exists>ns. s=Normal ns" using Seqc.hyps(1) Seqc.prems(3) Seqc.prems(4) c_step normal_eq_l step_ce_notNormal by blast then have c1'cptn:"(\<Gamma>, (c1', t) # xs') \<in> cptn_mod" using split by blast then have induct_step: "(\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod" using Seqc.hyps(2) using Seqc.prems(3) Seqc.prems(4) normal_eq_l by blast then obtain ys where seqmap:"(Seq c1' c2, t)#xs = (map (lift c2) ((c1', t)#xs'))@((Throw,Normal sa')#ys)" using assm proof - assume a1: "\<And>ys. (LanguageCon.com.Seq c1' c2, t) # xs = map (lift c2) ((c1', t) # xs') @ (LanguageCon.com.Throw, Normal sa') # ys \<Longrightarrow> thesis" have "(LanguageCon.com.Seq c1' c2, Normal sa'') # map (lift c2) xs' = map (lift c2) ((c1', t) # xs')" by (simp add: assm lift_def) thus ?thesis using a1 assm by moura qed then have lastc1:"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'" by (simp add: last_length) then have lastc1skip:"fst (last ((c1, s) # (c1', t) # xs')) = Throw" using assm by fastforce then have "snd (last ((c1, s) # (c1', t) # xs')) = Normal sa'" using assm by force thus ?thesis using assm c1'cptn induct_step lastc1skip snormal seqmap s'eqsa'' by (auto simp add:cptn_mod.CptnModSeq3) qed }qed next case (SeqSkipc c2 s1 xs) then have c2incptn:"(\<Gamma>, (c2, s) # xs) \<in> cptn_mod" using eq_toSeq by blast moreover have 1:"(\<Gamma>, [(Skip, s)]) \<in> cptn_mod" by (simp add: cptn_mod.CptnModOne) moreover have 2:"fst(last ([(Skip, s)])) = Skip" by fastforce moreover have 3:"(\<Gamma>,(c2, snd(last [(Skip, s)]))#xs) \<in> cptn_mod" using c2incptn by auto moreover have "(c2,s)#xs=(map (lift c2) [])@(c2, snd(last [(Skip, s)]))#xs" by (auto simp add:lift_def) moreover have "s=t" using eq_toSeq SeqSkipc by blast ultimately show ?case by (simp add: CptnModSeq2) next case (SeqThrowc c2 s1 xs) have eq_st:"s=t" using eq_toSeq[OF SeqThrowc(1)] SeqThrowc by auto obtain ns where normals:"s=Normal ns" using SeqThrowc by (metis toSeq_not_Normal) have "(\<Gamma>, [(Throw, Normal ns)]) \<in> cptn_mod" by (simp add: cptn_mod.CptnModOne) then obtain ys where ys_nil:"ys=[]" and last:"(\<Gamma>, (Throw, s)#ys)\<in> cptn_mod" using normals by auto moreover have "fst (last ((Throw, Normal ns)#ys)) = Throw" using ys_nil last by auto moreover have "snd (last ((Throw, Normal ns)#ys)) = Normal ns" using ys_nil last by auto moreover from ys_nil have "(map (lift c2) ys) = []" by auto ultimately show ?case using SeqThrowc.prems cptn_mod.CptnModSeq3 eq_st normals by blast next case (CondTruec s1 b c1 c2) moreover obtain ns where normals:"s=Normal ns" by (metis (no_types) calculation(4) toSeq_not_Normal) moreover have "s=t" using calculation(4,5) eq_toSeq[OF calculation(2)] by auto ultimately show ?case by (simp add: cptn_mod.CptnModCondT) next case (CondFalsec s1 b c1 c2) moreover obtain ns where normals:"s=Normal ns" by (metis (no_types) calculation(4) toSeq_not_Normal) moreover have "s=t" using calculation(4,5) eq_toSeq[OF calculation(2)] by auto ultimately show ?case by (simp add: cptn_mod.CptnModCondF) next case (WhileTruec s1 b c) have sinb: "s1\<in>b" by fact obtain ns where normals:"s=Normal ns" by (metis (no_types) WhileTruec(4) toSeq_not_Normal) have eq_st:"s=t" using eq_toSeq[OF WhileTruec(2)] WhileTruec by auto have SeqcWhile: "(\<Gamma>, (Seq c (While b c), Normal ns) # xs) \<in> cptn_mod" using sinb normals eq_st WhileTruec by blast have divseq:"(\<forall>s P Q zs. (Seq c (While b c), Normal ns) # xs=(Seq P Q, s)#zs \<longrightarrow> (\<exists>xs s'. ((\<Gamma>,(P, s)#xs) \<in> cptn_mod \<and> (zs=(map (lift Q) xs) \<or> ((fst(((P, s)#xs)!length xs)=Skip \<and> (\<exists>ys. (\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod \<and> zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or> ((fst(((P, s)#xs)!length xs)=Throw \<and> snd(last ((P, s)#xs)) = Normal s' \<and> (\<exists>ys. (\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod \<and> zs=(map (lift Q) xs)@((Throw,Normal s')#ys)))))) ))" using div_seq [OF SeqcWhile] eq_st normals unfolding seq_cond_def by fast {fix sa P Q zsa assume ass:"(Seq c (While b c), Normal ns) # xs = (Seq P Q, sa) # zsa" then have eqs:"c = P \<and> (While b c) = Q \<and> Normal ns = sa \<and> xs = zsa" by auto then have "(\<exists>xs s'. (\<Gamma>, (P, sa) # xs) \<in> cptn_mod \<and> (zsa = map (lift Q) xs \<or> fst (((P, sa) # xs) ! length xs) = Skip \<and> (\<exists>ys. (\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<in> cptn_mod \<and> zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<or> ((fst(((P, sa)#xs)!length xs)=Throw \<and> snd(last ((P, sa)#xs)) = Normal s' \<and> (\<exists>ys. (\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod \<and> zsa=(map (lift Q) xs)@((Throw,Normal s')#ys)) ))))" using ass divseq by auto } note conc=this [of c "While b c" "Normal ns" xs] then obtain xs' s' where split:"(\<Gamma>, (c, Normal ns) # xs') \<in> cptn_mod \<and> (xs = map (lift (While b c)) xs' \<or> fst (((c, Normal ns) # xs') ! length xs') = Skip \<and> (\<exists>ys. (\<Gamma>, (While b c, snd (((c, Normal ns) # xs') ! length xs')) # ys) \<in> cptn_mod \<and> xs = map (lift (While b c)) xs' @ (While b c, snd (((c, Normal ns) # xs') ! length xs')) # ys) \<or> fst (((c, Normal ns) # xs') ! length xs') = Throw \<and> snd (last ((c, Normal ns) # xs')) = Normal s' \<and> (\<exists>ys. (\<Gamma>, ((Throw, Normal s')#ys)) \<in> cptn_mod \<and> xs = map (lift (While b c)) xs' @ ((Throw, Normal s')#ys)))" by blast then have "(xs = map (lift (While b c)) xs' \<or> fst (((c, Normal ns) # xs') ! length xs') = Skip \<and> (\<exists>ys. (\<Gamma>, (While b c, snd (((c, Normal ns) # xs') ! length xs')) # ys) \<in> cptn_mod \<and> xs = map (lift (While b c)) xs' @ (While b c, snd (((c, Normal ns) # xs') ! length xs')) # ys) \<or> fst (((c, Normal ns) # xs') ! length xs') = Throw \<and> snd (last ((c, Normal ns) # xs')) = Normal s' \<and> (\<exists>ys. (\<Gamma>, ((Throw, Normal s')#ys)) \<in> cptn_mod \<and> xs = map (lift (While b c)) xs' @ ((Throw, Normal s')#ys)))" .. thus ?case proof{ assume 1:"xs = map (lift (While b c)) xs'" have 3:"(\<Gamma>, (c, Normal ns) # xs') \<in> cptn_mod" using split by auto then show ?thesis using "1" cptn_mod.CptnModWhile1 sinb normals eq_st by (metis WhileTruec.prems(3) toSeq.simps(1) xstate.inject(1)) next assume "fst (((c, Normal ns) # xs') ! length xs') = Skip \<and> (\<exists>ys. (\<Gamma>, (While b c, snd (((c, Normal ns) # xs') ! length xs')) # ys) \<in> cptn_mod \<and> xs = map (lift (While b c)) xs' @ (While b c, snd (((c, Normal ns) # xs') ! length xs')) # ys) \<or> fst (((c, Normal ns) # xs') ! length xs') = Throw \<and> snd (last ((c, Normal ns) # xs')) = Normal s' \<and> (\<exists>ys. (\<Gamma>, ((Throw, Normal s')#ys)) \<in> cptn_mod \<and> xs = map (lift (While b c)) xs' @ ((Throw, Normal s')#ys))" thus ?case proof assume asm:"fst (((c, Normal ns) # xs') ! length xs') = Skip \<and> (\<exists>ys. (\<Gamma>, (While b c, snd (((c, Normal ns) # xs') ! length xs')) # ys) \<in> cptn_mod \<and> xs = map (lift (While b c)) xs' @ (While b c, snd (((c, Normal ns) # xs') ! length xs')) # ys)" then obtain ys where asm':"(\<Gamma>, (While b c, snd (last ((c, Normal ns) # xs'))) # ys) \<in> cptn_mod \<and> xs = map (lift (While b c)) xs' @ (While b c, snd (last ((c, Normal ns) # xs'))) # ys" by (auto simp add: last_length) moreover have 3:"(\<Gamma>, (c, Normal ns) # xs') \<in> cptn_mod" using split by auto moreover from asm have "fst (last ((c, Normal ns) # xs')) = Skip" by (simp add: last_length) ultimately show ?case using sinb normals eq_st WhileTruec.prems(3) by (auto simp add: CptnModWhile2) next assume asm:" fst (((c, Normal ns) # xs') ! length xs') = Throw \<and> snd (last ((c, Normal ns) # xs')) = Normal s' \<and> (\<exists>ys. (\<Gamma>, ((Throw, Normal s')#ys)) \<in> cptn_mod \<and> xs = map (lift (While b c)) xs' @ ((Throw, Normal s')#ys))" moreover have 3:"(\<Gamma>, (c, Normal ns) # xs') \<in> cptn_mod" using split by auto moreover from asm have "fst (last ((c, Normal ns) # xs')) = Throw" by (simp add: last_length) ultimately show ?case using sinb normals eq_st WhileTruec.prems(3) by (auto simp add:CptnModWhile3) qed }qed next case (WhileFalsec s1 b c) thus ?case using stepc.WhileFalsec[of s1 b \<Gamma> c] by (simp add: cptn_mod.CptnModSkip) next case (Awaitc s1 b \<Gamma>a c t1) thus ?case using stepc.Awaitc[of s1 b \<Gamma>a \<Gamma>] by (simp add: cptn_mod.CptnModSkip) next case (AwaitAbruptc s1 b \<Gamma>a c t1 ta) thus ?case using stepc.AwaitAbruptc[of s1 b \<Gamma>a \<Gamma> c t1 ta] by (simp add: cptn_mod.CptnModThrow) next case (Callc p bdy s1) moreover have eq_st:"s=t" using eq_toSeq[OF Callc(3)] Callc by auto moreover obtain ns where normals:"s=Normal ns" by (metis (no_types) Callc(5) toSeq_not_Normal) ultimately show ?case using cptn_mod.CptnModCall by fast next case (CallUndefinedc p s1) thus ?case using stepc.CallUndefinedc[of \<Gamma> p s1,OF CallUndefinedc(1)] by (simp add: cptn_mod.CptnModSkip) next case (DynComc c s1) moreover obtain ns where "s=Normal ns" by (metis (full_types) DynComc.prems(3) toSeq_not_Normal) moreover have "fst ns = s1" using calculation(3) calculation(5) by auto moreover have "s=t" using calculation(3,4) eq_toSeq[OF DynComc(1)] by force ultimately show ?case using cptn_mod.CptnModDynCom by blast next case (Catchc c1 s1 c1' t1 c2) have step: "\<Gamma>\<turnstile>\<^sub>c (c1, s1) \<rightarrow> (c1', t1)" by (simp add: Catchc.hyps(1)) then have nsc1: "c1\<noteq>Skip" using stepc_elim_cases(1) by blast have assum: "(\<Gamma>, (Catch c1' c2, t) # xs) \<in> cptn_mod" using Catchc.prems by blast have divcatch:"(\<forall>s P Q zs. (Catch c1' c2, t) # xs=(Catch P Q, s)#zs \<longrightarrow> (\<exists>xs s' s''. ((\<Gamma>,(P, s)#xs) \<in> cptn_mod \<and> (zs=(map (lift_catch Q) xs) \<or> ((fst(((P, s)#xs)!length xs)=Throw \<and> snd(last ((P, s)#xs)) = Normal s' \<and> s=Normal s''\<and> (\<exists>ys. (\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod \<and> zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or> ((fst(((P, s)#xs)!length xs)=Skip \<and> (\<exists>ys. (\<Gamma>,(Skip,snd(last ((P, s)#xs)))#ys) \<in> cptn_mod \<and> zs=(map (lift_catch Q) xs)@((Skip,snd(last ((P, s)#xs)))#ys)) )))) ))" using div_catch [OF assum] by (auto simp add: catch_cond_def) {fix sa P Q zsa assume ass:"(Catch c1' c2, t) # xs = (Catch P Q, sa) # zsa" then have eqs:"c1' = P \<and> c2 = Q \<and> t = sa \<and> xs = zsa" by auto then have "(\<exists>xs sv' sv''. ((\<Gamma>,(P, sa)#xs) \<in> cptn_mod \<and> (zsa=(map (lift_catch Q) xs) \<or> ((fst(((P, sa)#xs)!length xs)=Throw \<and> snd(last ((P, sa)#xs)) = Normal sv' \<and> t=Normal sv''\<and> (\<exists>ys. (\<Gamma>,(Q, snd(((P, sa)#xs)!length xs))#ys) \<in> cptn_mod \<and> zsa=(map (lift_catch Q) xs)@((Q, snd(((P, sa)#xs)!length xs))#ys)))) \<or> ((fst(((P, sa)#xs)!length xs)=Skip \<and> (\<exists>ys. (\<Gamma>,(Skip,snd(last ((P, sa)#xs)))#ys) \<in> cptn_mod \<and> zsa=(map (lift_catch Q) xs)@((Skip,snd(last ((P, sa)#xs)))#ys)))))) )" using ass divcatch by blast } note conc=this [of c1' c2 t xs] then obtain xs' sa' sa'' where split: "(\<Gamma>, (c1', t) # xs') \<in> cptn_mod \<and> (xs = map (lift_catch c2) xs' \<or> fst (((c1', t) # xs') ! length xs') = Throw \<and> snd (last ((c1', t) # xs')) = Normal sa' \<and> t = Normal sa'' \<and> (\<exists>ys. (\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and> xs = map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or> fst (((c1', t) # xs') ! length xs') = Skip \<and> (\<exists>ys. (\<Gamma>,(Skip,snd(last ((c1', t)#xs')))#ys) \<in> cptn_mod \<and> xs=(map (lift_catch c2) xs')@((Skip,snd(last ((c1', t)#xs')))#ys)))" by blast then have "(xs = map (lift_catch c2) xs' \<or> fst (((c1', t) # xs') ! length xs') = Throw \<and> snd (last ((c1', t) # xs')) = Normal sa' \<and> t = Normal sa'' \<and> (\<exists>ys. (\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and> xs = map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or> fst (((c1', t) # xs') ! length xs') = Skip \<and> (\<exists>ys. (\<Gamma>,(Skip,snd(last ((c1', t)#xs')))#ys) \<in> cptn_mod \<and> xs=(map (lift_catch c2) xs')@((Skip,snd(last ((c1', t)#xs')))#ys)))" by auto thus ?case proof{ assume c1'nonf:"xs = map (lift_catch c2) xs'" then have c1'cptn:"(\<Gamma>, (c1', t) # xs') \<in> cptn_mod" using split by blast then have induct_step: "(\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod" using Catchc.hyps(2) Catchc.prems(3) Catchc.prems(4) normal_eq_l by blast then have "(Catch c1' c2, t)#xs = map (lift_catch c2) ((c1', t)#xs')" using c1'nonf by (simp add: CptnModCatch1 lift_catch_def) thus ?thesis using c1'nonf c1'cptn induct_step by (auto simp add: CptnModCatch1) next assume "fst (((c1', t) # xs') ! length xs') = Throw \<and> snd (last ((c1', t) # xs')) = Normal sa' \<and> t = Normal sa'' \<and> (\<exists>ys. (\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and> xs =map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or> fst (((c1', t) # xs') ! length xs') = Skip \<and> (\<exists>ys. (\<Gamma>,(Skip,snd(last ((c1', t)#xs')))#ys) \<in> cptn_mod \<and> xs=(map (lift_catch c2) xs')@((Skip,snd(last ((c1', t)#xs')))#ys))" thus ?thesis proof assume assth: "fst (((c1', t) # xs') ! length xs') = Throw \<and> snd (last ((c1', t) # xs')) = Normal sa' \<and> t = Normal sa'' \<and> (\<exists>ys. (\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and> xs =map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys)" then have s'eqsa'': "t=Normal sa''" by auto then have snormal: "\<exists>ns. s=Normal ns" by (metis step_not_normal_s_eq_t stepseq toSeq_not_Normal vars vars1) then obtain ys where split':"(\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and> xs =map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys" using assth by auto then have c1'cptn:"(\<Gamma>, (c1',t) # xs') \<in> cptn_mod" using split by blast then have induct_step: "(\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod" using Catchc.hyps(2) Catchc.prems(3) Catchc.prems(4) normal_eq_l by blast then have seqmap:"(Catch c1 c2, s)#(Catch c1' c2, t)#xs = map (lift_catch c2) ((c1,s)#(c1', t)#xs') @ (c2, snd (((c1', t) # xs') ! length xs')) # ys" using split' by (simp add: CptnModCatch3 lift_catch_def) then have lastc1:"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'" by (simp add: last_length) then have lastc1skip:"fst (last ((c1, s) # (c1', t) # xs')) = Throw" using assth by fastforce then have "snd (last ((c1, s) # (c1', t) # xs')) = Normal sa'" using assth by force thus ?thesis using snormal seqmap s'eqsa'' split' last_length cptn_mod.CptnModCatch3 induct_step lastc1 lastc1skip by (smt append_Cons list.inject list.simps(9)) next assume assm:" fst (((c1', t) # xs') ! length xs') = Skip \<and> (\<exists>ys. (\<Gamma>,(Skip,snd(last ((c1', t)#xs')))#ys) \<in> cptn_mod \<and> xs=(map (lift_catch c2) xs')@((Skip,snd(last ((c1', t)#xs')))#ys))" then have c1'cptn:"(\<Gamma>, (c1', t) # xs') \<in> cptn_mod" using split by blast then have induct_step: "(\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod" using Catchc.hyps(2) Catchc.prems(3) Catchc.prems(4) normal_eq_l by blast then have "map (lift_catch c2) ((c1', t) # xs') = (Catch c1' c2, t) # map (lift_catch c2) xs'" by (auto simp add: lift_catch_def) then obtain ys where seqmap:"(Catch c1' c2, t)#xs = (map (lift_catch c2) ((c1', t)#xs'))@((Skip,snd(last ((c1', t)#xs')))#ys)" using assm by fastforce then have lastc1:"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'" by (simp add: last_length) then have lastc1skip:"fst (last ((c1, s) # (c1', t) # xs')) = Skip" using assm by fastforce then have "snd (last ((c1, s) # (c1', t) # xs')) = snd (last ((c1',t) # xs'))" using assm by force thus ?thesis using assm c1'cptn induct_step lastc1skip seqmap by (auto simp add:cptn_mod.CptnModCatch2) qed }qed next case (CatchThrowc c2 s1) then obtain ns where ns:"s = Normal ns" by (metis toSeq_not_Normal) then have eq_st: "s=t" using eq_toSeq[OF CatchThrowc(1)] CatchThrowc(3,4) by auto then have c2incptn:"(\<Gamma>, (c2, Normal ns) # xs) \<in> cptn_mod" using ns CatchThrowc by auto then have 1:"(\<Gamma>, [(Throw, Normal ns)]) \<in> cptn_mod" by (simp add: cptn_mod.CptnModOne) then have 2:"fst(last ([(Throw, Normal ns)])) = Throw" by fastforce then have 3:"(\<Gamma>,(c2, snd(last [(Throw, Normal ns)]))#xs) \<in> cptn_mod" using c2incptn by auto then have "(c2,Normal ns)#xs=(map (lift c2) [])@(c2, snd(last [(Throw, Normal ns)]))#xs" by (auto simp add:lift_def) thus ?case using eq_st ns CptnModCatch3 1 2 3 by fastforce next case (CatchSkipc c2 s1) have "(\<Gamma>, [(Skip, s)]) \<in> cptn_mod" by (simp add: cptn_mod.CptnModOne) then obtain ys where ys_nil:"ys=[]" and last:"(\<Gamma>, (Skip, s)#ys)\<in> cptn_mod" by auto moreover have "fst (last ((Skip, s)#ys)) = Skip" using ys_nil last by auto moreover have "snd (last ((Skip, s)#ys)) = s" using ys_nil last by auto moreover from ys_nil have "(map (lift_catch c2) ys) = []" by auto moreover have "s=t" using CatchSkipc.prems(3) CatchSkipc.prems(4) eq_toSeq normal_eq_l by blast ultimately show ?case using CatchSkipc.prems by (simp add: cptn_mod.CptnModCatch2 ys_nil) next case (FaultPropc c f) thus ?case by (metis cptn_mod.CptnModSkip stepc.FaultPropc) next case (AbruptPropc c f) thus ?case by (metis cptn_mod.CptnModSkip stepc.AbruptPropc) next case (StuckPropc c) thus ?case by (simp add: cptn_mod.CptnModSkip stepc.StuckPropc) qed lemma cptn_onlyif_cptn_mod: assumes cptn_asm:"(\<Gamma>,c) \<in> cptn" shows "(\<Gamma>,c) \<in> cptn_mod" using cptn_asm proof (induct) case CptnOne thus ?case by (rule CptnModOne) next case (Cptn \<Gamma> P s Q t xs) then have "\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (Q, t) \<or> \<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Q, toSeq t)" using step_ce_not_step_e_step_c by blast moreover{ assume "\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (Q, t)" then have ?case using Cptn.hyps(3) cptn_mod.CptnModEnv env_c_c' by blast } moreover{ assume a00:"\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Q, toSeq t)" moreover have "\<not> \<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (Q, t)" using env_c_c' mod_env_not_component calculation by blast then have ?case using cptn_onlyif_cptn_mod_aux[OF _ _ a00 _ Cptn(3)] Cptn by fastforce } ultimately show ?case by auto qed lemma lift_is_cptn: assumes cptn_asm:"(\<Gamma>,c)\<in>cptn" shows "(\<Gamma>,map (lift P) c) \<in> cptn" using cptn_asm proof (induct) case CptnOne thus ?case using cptn.simps by fastforce next case (Cptn \<Gamma> Pa s Q t xs) have "\<Gamma>\<turnstile>\<^sub>c (Pa, s) \<rightarrow>\<^sub>e (Q, t) \<or> \<Gamma>\<turnstile>\<^sub>c (Pa, toSeq s) \<rightarrow> (Q, toSeq t)" using Cptn.hyps(1) step_ce_not_step_e_step_c by blast moreover{ assume "\<Gamma>\<turnstile>\<^sub>c (Pa, s) \<rightarrow>\<^sub>e (Q, t)" then have ?case using Cptn unfolding lift_def by (cases rule: step_e.cases, (simp add: Env cptn.Cptn e_step), (simp add: Env_n cptn.Cptn e_step)) } moreover { assume "\<Gamma>\<turnstile>\<^sub>c (Pa, toSeq s) \<rightarrow> (Q, toSeq t)" moreover have "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Seq Pa P, toSeq s) \<rightarrow> (LanguageCon.com.Seq Q P, toSeq t)" using Seqc calculation by blast ultimately have "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Seq Pa P, s) \<rightarrow>\<^sub>c\<^sub>e (LanguageCon.com.Seq Q P, t)" using Cptn.hyps(1) c_step[of \<Gamma> "LanguageCon.com.Seq Pa P" s "LanguageCon.com.Seq Q P" t] env_c_c' step_ce_notNormal step_ce_step_c_eq_c step_dest by (metis xstate.inject(2) xstate.simps(5)) then have ?case using Cptn by (simp add: cptn.Cptn lift_def) } ultimately show ?case by auto qed lemma lift_catch_is_cptn: assumes cptn_asm:"(\<Gamma>,c)\<in>cptn" shows "(\<Gamma>,map (lift_catch P) c) \<in> cptn" using cptn_asm proof (induct) case CptnOne thus ?case using cptn.simps by fastforce next case (Cptn \<Gamma> Pa s Q t xs) have "\<Gamma>\<turnstile>\<^sub>c (Pa, s) \<rightarrow>\<^sub>e (Q, t) \<or> \<Gamma>\<turnstile>\<^sub>c (Pa, toSeq s) \<rightarrow> (Q, toSeq t)" using Cptn.hyps(1) step_ce_not_step_e_step_c by blast moreover{ assume "\<Gamma>\<turnstile>\<^sub>c (Pa, s) \<rightarrow>\<^sub>e (Q, t)" then have ?case using Cptn unfolding lift_catch_def by (cases rule: step_e.cases, (simp add: Env cptn.Cptn e_step), (simp add: Env_n cptn.Cptn e_step)) } moreover { assume "\<Gamma>\<turnstile>\<^sub>c (Pa, toSeq s) \<rightarrow> (Q, toSeq t)" moreover have "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Catch Pa P, toSeq s) \<rightarrow> (LanguageCon.com.Catch Q P, toSeq t)" using Catchc calculation by blast ultimately have "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Catch Pa P, s) \<rightarrow>\<^sub>c\<^sub>e (LanguageCon.com.Catch Q P, t)" using Cptn.hyps(1) c_step[of \<Gamma> "LanguageCon.com.Catch Pa P" s "LanguageCon.com.Catch Q P" t] env_c_c' step_ce_notNormal step_ce_step_c_eq_c step_dest by (metis xstate.inject(2) xstate.simps(5)) then have ?case using Cptn by (simp add: cptn.Cptn lift_catch_def) } ultimately show ?case by auto qed lemma last_lift: "\<lbrakk>xs\<noteq>[]; fst(xs!(length xs - (Suc 0)))=Q\<rbrakk> \<Longrightarrow> fst((map (lift P) xs)!(length (map (lift P) xs)- (Suc 0)))=Seq Q P" by (cases "(xs ! (length xs - (Suc 0)))") (simp add:lift_def) lemma last_lift_catch: "\<lbrakk>xs\<noteq>[]; fst(xs!(length xs - (Suc 0)))=Q\<rbrakk> \<Longrightarrow> fst((map (lift_catch P) xs)!(length (map (lift_catch P) xs)- (Suc 0)))=Catch Q P" by (cases "(xs ! (length xs - (Suc 0)))") (simp add:lift_catch_def) lemma last_fst [rule_format]: "P((a#x)!length x) \<longrightarrow> \<not>P a \<longrightarrow> P (x!(length x - (Suc 0)))" by (induct x) simp_all lemma last_fst_esp: "fst(((P,s)#xs)!(length xs))=Skip \<Longrightarrow> P\<noteq>Skip \<Longrightarrow> fst(xs!(length xs - (Suc 0)))=Skip" apply(erule last_fst) apply simp done lemma last_snd: "xs\<noteq>[] \<Longrightarrow> snd(((map (lift P) xs))!(length (map (lift P) xs) - (Suc 0)))=snd(xs!(length xs - (Suc 0)))" by (cases "(xs ! (length xs - (Suc 0)))") (simp_all add:lift_def) lemma last_snd_catch: "xs\<noteq>[] \<Longrightarrow> snd(((map (lift_catch P) xs))!(length (map (lift_catch P) xs) - (Suc 0)))=snd(xs!(length xs - (Suc 0)))" by (cases "(xs ! (length xs - (Suc 0)))") (simp_all add:lift_catch_def) lemma Cons_lift: "((Seq P Q), s) # (map (lift Q) xs) = map (lift Q) ((P, s) # xs)" by (simp add:lift_def) thm last_map eq_snd_iff list.inject list.simps(9) last_length lemma Cons_lift_catch: "((Catch P Q), s) # (map (lift_catch Q) xs) = map (lift_catch Q) ((P, s) # xs)" by (simp add:lift_catch_def) lemma Cons_lift_append: "((Seq P Q), s) # (map (lift Q) xs) @ ys = map (lift Q) ((P, s) # xs)@ ys " by (simp add:lift_def) lemma Cons_lift_catch_append: "((Catch P Q), s) # (map (lift_catch Q) xs) @ ys = map (lift_catch Q) ((P, s) # xs)@ ys " by (simp add:lift_catch_def) lemma lift_nth: "i<length xs \<Longrightarrow> map (lift Q) xs ! i = lift Q (xs! i)" by (simp add:lift_def) lemma lift_catch_nth: "i<length xs \<Longrightarrow> map (lift_catch Q) xs ! i = lift_catch Q (xs! i)" by (simp add:lift_catch_def) thm list.simps(9) last_length lift_catch_def Cons_lift_catch lemma snd_lift: "i< length xs \<Longrightarrow> snd(lift Q (xs ! i))= snd (xs ! i)" by (cases "xs!i") (simp add:lift_def) lemma snd_lift_catch: "i< length xs \<Longrightarrow> snd(lift_catch Q (xs ! i))= snd (xs ! i)" by (cases "xs!i") (simp add:lift_catch_def) lemma lift_P1: assumes map_cptn:"(\<Gamma>, map (lift Q) ((P, s) # xs)) \<in> cptn" and P_ends:"fst (last ((P, s) # xs)) = Skip" shows "(\<Gamma>, map (lift Q) ((P, s) # xs) @ [(Q, snd (last ((P, s) # xs)))]) \<in> cptn" using map_cptn P_ends proof (induct xs arbitrary: P s) case Nil have P0_skips: "P=Skip" using Nil.prems(2) by auto then have "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Seq LanguageCon.com.Skip Q, s) \<rightarrow>\<^sub>c\<^sub>e (Q, s)" by (metis SeqSkipc c_step xstate.inject(1) xstate.inject(2) xstate.simps(5)) then have "(\<Gamma>,[(Seq Skip Q, s), (Q, s)]) \<in> cptn" by (simp add: cptn.Cptn cptn.CptnOne) then show ?case using P0_skips by (simp add: lift_def) next case (Cons a xs) have "(\<Gamma>, map (lift Q) ((P, s) # a # xs)) \<in> cptn" using Cons.prems(1) by blast have "fst (last ( a # xs)) = Skip" using Cons.prems(2) by auto also have seq_PQ:"(\<Gamma>,(Seq P Q,s) # (map (lift Q) (a#xs))) \<in> cptn" by (metis Cons.prems(1) Cons_lift) then have "(\<Gamma>,(map (lift Q) (a#xs))) \<in> cptn" proof - assume a1:"(\<Gamma>, (Seq P Q, s) # map (lift Q) (a # xs)) \<in> cptn" then obtain a1 a2 xs1 where a2: "map (lift Q) (a#xs) = ((a1,a2)#xs1)" by fastforce thus ?thesis using cptn_dest using seq_PQ by auto qed then have "(\<Gamma>, map (lift Q) (a#xs) @ [(Q, snd (last ((a#xs))))]) \<in> cptn" by (metis Cons.hyps(1) calculation prod.collapse) then have t1:"(\<Gamma>, (Seq (fst a) Q, (snd a))#map (lift Q) xs @ [(Q, snd (last ((P, s)#(a#xs))))]) \<in> cptn" by (simp add: Cons_lift_append) then have "(\<Gamma>,(Seq P Q,s) # (Seq (fst a) Q, (snd a))#map (lift Q) xs)\<in> cptn" using seq_PQ by (simp add: Cons_lift) then have t2: "(\<Gamma>,(Seq P Q,s) # [(Seq (fst a) Q, (snd a))]) \<in> cptn" using cptn_dest1 by blast then have"((Seq P Q,s) # [(Seq (fst a) Q, (snd a))])!length [(Seq (fst a) Q, (snd a))] = (Seq (fst a) Q, (snd a))" by auto then have "(\<Gamma>,(Seq P Q,s) # [(Seq (fst a) Q, (snd a))]@map (lift Q) xs @ [(Q, snd (last ((P, s)#(a#xs))))])\<in> cptn" using cptn_append_is_cptn t1 t2 by blast then have "(\<Gamma>, map (lift Q) ((P,s)#(fst a, snd a)#xs) @[(Q, snd (last ((P, s)#(a#xs))))])\<in>cptn" using Cons_lift_append append_Cons append_Nil by metis thus ?case by auto qed lemma lift_catch_P1: assumes map_cptn:"(\<Gamma>, map (lift_catch Q) ((P, Normal s) # xs)) \<in> cptn" and P_ends:"fst (last ((P, Normal s) # xs)) = Throw" and P_ends_normal:"\<exists>p. snd(last ((P, Normal s) # xs)) = Normal p" shows "(\<Gamma>, map (lift_catch Q) ((P, Normal s) # xs) @ [(Q, snd (last ((P, Normal s) # xs)))]) \<in> cptn" using map_cptn P_ends P_ends_normal proof (induct xs arbitrary: P s) case Nil have P0_skips: "P=Throw" using Nil.prems(2) by auto then have "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Catch LanguageCon.com.Throw Q, Normal s) \<rightarrow>\<^sub>c\<^sub>e (Q, Normal s)" by (metis CatchThrowc surj_pair transfer_normal) then have "(\<Gamma>,[(Catch Throw Q, Normal s), (Q, Normal s)]) \<in> cptn" by (simp add: cptn.Cptn CatchThrowc cptn.CptnOne) then show ?case using P0_skips by (simp add: lift_catch_def) next case (Cons a xs) have s1:"(\<Gamma>, map (lift_catch Q) ((P, Normal s) # a # xs)) \<in> cptn" using Cons.prems(1) by blast have s2:"fst (last ( a # xs)) = Throw" using Cons.prems(2) by auto then obtain p where s3:"snd(last (a #xs)) = Normal p" using Cons.prems(3) by auto also have seq_PQ:"(\<Gamma>,(Catch P Q,Normal s) # (map (lift_catch Q) (a#xs))) \<in> cptn" by (metis Cons.prems(1) Cons_lift_catch) thm Cons.hyps then have axs_in_cptn:"(\<Gamma>,(map (lift_catch Q) (a#xs))) \<in> cptn" proof - assume a1:"(\<Gamma>, (Catch P Q, Normal s) # map (lift_catch Q) (a # xs)) \<in> cptn" then obtain a1 a2 xs1 where a2: "map (lift_catch Q) (a#xs) = ((a1,a2)#xs1)" by fastforce thus ?thesis using cptn_dest using seq_PQ by auto qed then have "(\<Gamma>, map (lift_catch Q) (a#xs) @ [(Q, snd (last ((a#xs))))]) \<in> cptn" proof (cases "xs=[]") case True thus ?thesis using s2 s3 axs_in_cptn by (metis Cons.hyps eq_snd_iff last_ConsL) next case False from seq_PQ have seq:"(\<Gamma>,(Catch P Q,Normal s) # (Catch (fst a) Q,snd a)#map (lift_catch Q) xs)\<in> cptn" by (simp add: Cons_lift_catch) obtain cf sf where last_map_axs:"(cf,sf)=last (map (lift_catch Q) (a#xs))" using prod.collapse by blast have "\<forall>p ps. (ps=[] \<and> last [p] = p) \<or> (ps\<noteq>[] \<and> last (p#ps) = last ps)" by simp then have tranclos:"\<Gamma>\<turnstile>\<^sub>c (Catch P Q,Normal s) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (Catch (fst a) Q,snd a)" using Cons_lift_catch by (metis (no_types) cptn_dest1 cptn_stepc_rtrancl not_Cons_self2 seq) have tranclos_a:"\<Gamma>\<turnstile>\<^sub>c (Catch (fst a) Q,snd a) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (cf,sf)" by (metis Cons_lift_catch axs_in_cptn cptn_stepc_rtrancl last_map_axs prod.collapse) have snd_last:"snd (last (map (lift_catch Q) (a#xs))) = snd (last (a #xs))" proof - have eqslist:"snd(((map (lift_catch Q) (a#xs)))!(length (map (lift_catch Q) xs)))= snd((a#xs)!(length xs))" using last_snd_catch by fastforce have "(lift_catch Q a)#(map (lift_catch Q) xs) = (map (lift_catch Q) (a#xs))" by auto then have "(map (lift_catch Q) (a#xs))!(length (map (lift_catch Q) xs)) = last (map (lift_catch Q) (a#xs))" using last_length [of "(lift_catch Q a)" "(map (lift_catch Q) xs)"] by auto thus ?thesis using eqslist by (simp add:last_length) qed then obtain p1 where "(snd a) = Normal p1" by (metis tranclos_a last_map_axs s3 snd_conv step_ce_normal_to_normal tranclos) moreover obtain a1 a2 where aeq:"a = (a1,a2)" by fastforce moreover have "fst (last ((a1,a2) # xs)) = Throw" using s2 False by auto moreover have "(\<Gamma>, map (lift_catch Q) ((a1,a2) # xs)) \<in> cptn" using aeq axs_in_cptn False by auto moreover have "\<exists>p. snd (last ((a1,a2) # xs)) = Normal p" using s3 aeq by auto moreover have "a2 = Normal p1" using aeq calculation(1) by auto ultimately have "(\<Gamma>, map (lift_catch Q) ((a1,a2) # xs) @ [(Q, snd (last ((a1,a2) # xs)))])\<in> cptn" using Cons.hyps aeq by blast thus ?thesis using aeq by force qed then have t1:"(\<Gamma>, (Catch (fst a) Q, (snd a))#map (lift_catch Q) xs @ [(Q, snd (last ((P, Normal s)#(a#xs))))]) \<in> cptn" by (simp add: Cons_lift_catch_append) then have "(\<Gamma>,(Catch P Q,Normal s) # (Catch (fst a) Q, (snd a))#map (lift_catch Q) xs)\<in> cptn" using seq_PQ by (simp add: Cons_lift_catch) then have t2: "(\<Gamma>,(Catch P Q,Normal s) # [(Catch (fst a) Q, (snd a))]) \<in> cptn" using cptn_dest1 by blast then have"((Catch P Q,Normal s) # [(Catch (fst a) Q, (snd a))])!length [(Catch (fst a) Q, (snd a))] = (Catch (fst a) Q, (snd a))" by auto then have "(\<Gamma>,(Catch P Q,Normal s) # [(Catch (fst a) Q, (snd a))]@map (lift_catch Q) xs @ [(Q, snd (last ((P, Normal s)#(a#xs))))])\<in> cptn" using cptn_append_is_cptn t1 t2 by blast then have "(\<Gamma>, map (lift_catch Q) ((P,Normal s)#(fst a, snd a)#xs) @[(Q, snd (last ((P,Normal s)#(a#xs))))])\<in>cptn" using Cons_lift_catch_append append_Cons append_Nil by metis thus ?case by auto qed lemma seq2: assumes p1:"(\<Gamma>, (P0, s) # xs) \<in> cptn_mod" and p2:"(\<Gamma>, (P0, s) # xs) \<in> cptn" and p3:"fst (last ((P0, s) # xs)) = Skip" and p4:"(\<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod" and p5:"(\<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \<in> cptn" and p6:"zs = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys" shows "(\<Gamma>, (Seq P0 P1, s) # zs) \<in> cptn" using p1 p2 p3 p4 p5 p6 proof - have last_skip:"fst (last ((P0, s) # xs)) = Skip" using p3 by blast have "(\<Gamma>, (map (lift P1) ((P0, s) # xs))@(P1, snd (last ((P0, s) # xs))) # ys) \<in> cptn" proof - have "(\<Gamma>,map (lift P1) ((P0, s) #xs)) \<in> cptn" using p2 lift_is_cptn by blast then have "(\<Gamma>,map (lift P1) ((P0, s) #xs)@[(P1, snd (last ((P0, s) # xs)))]) \<in> cptn" using last_skip lift_P1 by blast then have "(\<Gamma>,(Seq P0 P1, s) # map (lift P1) xs@[(P1, snd (last ((P0, s) # xs)))]) \<in> cptn" by (simp add: Cons_lift_append) moreover have "last ((Seq P0 P1, s) # map (lift P1) xs @[(P1, snd (last ((P0, s) # xs)))]) = (P1, snd (last ((P0, s) # xs)))" by auto moreover have "last ((Seq P0 P1, s) # map (lift P1) xs @[(P1, snd (last ((P0, s) # xs)))]) = ((Seq P0 P1, s) # map (lift P1) xs @[(P1, snd (last ((P0, s) # xs)))])!length (map (lift P1) xs @[(P1, snd (last ((P0, s) # xs)))])" by (metis last_length) ultimately have "(\<Gamma>, (Seq P0 P1, s) # map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys)\<in> cptn" using cptn_append_is_cptn p5 by fastforce thus ?thesis by (simp add: Cons_lift_append) qed thus ?thesis by (simp add: Cons_lift_append p6) qed lemma seq3: assumes p1:"(\<Gamma>, (P0, Normal s) # xs) \<in> cptn_mod" and p2:"(\<Gamma>, (P0, Normal s) # xs) \<in> cptn" and p3:"fst (last ((P0, Normal s) # xs)) = Throw" and p4:"snd (last ((P0, Normal s) # xs)) = Normal s'" and p5:"(\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod" and p6:"(\<Gamma>,(Throw,Normal s')#ys) \<in> cptn" and p7:"zs = map (lift P1) xs @((Throw,Normal s')#ys)" shows "(\<Gamma>, (Seq P0 P1, Normal s) # zs) \<in> cptn" using p1 p2 p3 p4 p5 p6 p7 proof (induct xs arbitrary: zs P0 s) case Nil have h:"\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Seq LanguageCon.com.Throw P1, Normal s') \<rightarrow>\<^sub>c\<^sub>e (LanguageCon.com.Throw, Normal s')" using SeqThrowc by (metis old.prod.exhaust transfer_normal) show ?case using cptn.Cptn[OF h,of ys] Nil by simp next case (Cons a as) then obtain sa where "snd a = Normal sa" by (meson Normal_Normal) obtain a1 a2 where a_prod:"a=(a1,a2)" by fastforce obtain la1 la2 where last_prod:"last (a#as) = (la1,la2)" by fastforce then have lasst_aas_last: "last (a#as) = (last ((P0, Normal s) # a # as))" by auto then have "la1 = Throw" using Cons.prems(3) last_prod by force have "la2 = Normal s'" using Cons.prems(4) last_prod lasst_aas_last by force have f1: "(\<Gamma>, (a1, a2) # as) \<in> cptn" using Cons.prems(2) a_prod cptn_dest by blast have f2: "Normal sa = a2" using `snd a = Normal sa` a_prod by force have "(\<Gamma>, a # as) \<in> cptn_mod" using f1 a_prod cptn_onlyif_cptn_mod by blast then have hyp:"(\<Gamma>, (Seq a1 P1, Normal sa) # map (lift P1) as @ ((Throw,Normal s')#ys)) \<in> cptn" using Cons.hyps Cons.prems(3) Cons.prems(4) Cons.prems(5) Cons.prems(6) a_prod f1 f2 by fastforce thus ?case proof - have "(Seq a1 P1, a2) # map (lift P1) as @((Throw,Normal s')#ys) = zs" by (simp add: Cons.prems(7) Cons_lift_append a_prod) moreover have "\<Gamma>\<turnstile>\<^sub>c (Seq P0 P1, Normal s) \<rightarrow>\<^sub>c\<^sub>e (Seq a1 P1, a2)" using Cons.prems(2) a_prod cptn_elim_cases(2) by (smt Seqc e_step env_intro eq_fst_iff eq_snd_iff f2 not_eq_not_env step_ce_dest step_dest1 toSeq.simps(1) transfer_normal) ultimately show ?thesis using Cons.prems(2) Seqc a_prod cptn.Cptn cptn_elim_cases f2 hyp by blast qed qed lemma cptn_if_cptn_mod: assumes cptn_mod_asm:"(\<Gamma>,c) \<in> cptn_mod" shows "(\<Gamma>,c) \<in> cptn" using cptn_mod_asm proof (induct) case (CptnModOne) thus ?case using cptn.CptnOne by blast next case CptnModSkip thus ?case by (simp add: c_step cptn.Cptn) next case CptnModThrow thus ?case by (simp add: c_step cptn.Cptn) next case CptnModCondT thus ?case by (metis CondTruec cptn.Cptn prod.exhaust_sel transfer_normal) next case CptnModCondF thus ?case by (metis CondFalsec cptn.Cptn prod.exhaust_sel transfer_normal) next case (CptnModSeq1 \<Gamma> P0 s xs zs P1) have "(\<Gamma>, map (lift P1) ((P0, s) # xs)) \<in> cptn" using CptnModSeq1.hyps(2) lift_is_cptn by blast thus ?case by (simp add: Cons_lift CptnModSeq1.hyps(3)) next case (CptnModSeq2 \<Gamma> P0 s xs P1 ys zs) thus ?case by (simp add:seq2) next case (CptnModSeq3 \<Gamma> P0 s xs s' zs P1) thus ?case by (simp add: seq3) next case (CptnModWhile1 \<Gamma> P s xs b zs) thus ?case by (metis Cons_lift WhileTruec cptn.Cptn lift_is_cptn prod.collapse transfer_normal) next case (CptnModWhile2 \<Gamma> P s xs b zs ys) then have "(\<Gamma>, (Seq P (While b P), Normal s) # zs) \<in> cptn" by (simp add:seq2) moreover have "\<Gamma>\<turnstile>\<^sub>c(While b P,toSeq (Normal s)) \<rightarrow> (Seq P (While b P),toSeq(Normal s))" by (simp add: CptnModWhile2.hyps(4) WhileTruec) ultimately show ?case by (metis cptn.Cptn prod.collapse toSeq.simps(1) transfer_normal) next case (CptnModWhile3 \<Gamma> P s xs b s' ys zs) then have "(\<Gamma>,(Seq P (While b P), Normal s) # zs) \<in> cptn" by (simp add: seq3) moreover have "\<Gamma>\<turnstile>\<^sub>c(While b P,toSeq (Normal s)) \<rightarrow> (Seq P (While b P),toSeq (Normal s))" by (simp add: CptnModWhile3.hyps(4) WhileTruec) ultimately show ?case by (metis cptn.Cptn prod.collapse toSeq.simps(1) transfer_normal) next case (CptnModCall \<Gamma> bdy s ys p) thus ?case by (metis Callc cptn.Cptn prod.exhaust_sel transfer_normal) next case (CptnModDynCom \<Gamma> c s ys) thus ?case by (metis DynComc cptn.Cptn prod.exhaust_sel transfer_normal) next case (CptnModGuard \<Gamma> c s ys g f) thus ?case by (metis Guardc cptn.Cptn prod.exhaust_sel transfer_normal) next case (CptnModCatch1 \<Gamma> P0 s xs zs P1) have "(\<Gamma>, map (lift_catch P1) ((P0, s) # xs)) \<in> cptn" using CptnModCatch1.hyps(2) lift_catch_is_cptn by blast thus ?case by (simp add: Cons_lift_catch CptnModCatch1.hyps(3)) next case (CptnModCatch2 \<Gamma> P0 s xs ys zs P1) thus ?case proof (induct xs arbitrary: zs P0 s) case Nil then have "\<Gamma>\<turnstile>\<^sub>c (Catch Skip P1, s) \<rightarrow>\<^sub>c\<^sub>e (LanguageCon.com.Skip, s)" by (metis CatchSkipc c_step xstate.inject(2) xstate.simps(1) xstate.simps(5)) thus ?case using cptn.simps using Nil.prems(3) Nil.prems(5) Nil.prems(6) by fastforce next case (Cons a as) then obtain sa where "snd a = sa" by auto then obtain a1 a2 where a_prod:"a=(a1,a2)" and sa_a2: "a2 =sa" by fastforce obtain la1 la2 where last_prod:"last (a#as) = (la1,la2)" by fastforce then have lasst_aas_last: "last (a#as) = (last ((P0, s) # a # as))" by auto then have "la1 = Skip" using Cons.prems(3) last_prod by force have f1: "(\<Gamma>, (a1, a2) # as) \<in> cptn" using Cons.prems(2) a_prod cptn_dest by blast have "(\<Gamma>, a # as) \<in> cptn_mod" using f1 a_prod cptn_onlyif_cptn_mod by blast then have hyp:"(\<Gamma>, (Catch a1 P1, a2) # map (lift_catch P1) as @ ((Skip, la2)#ys)) \<in> cptn" using Cons.hyps Cons.prems a_prod f1 last_prod by fastforce thus ?case proof - have f1:"(Catch a1 P1, a2) # map (lift_catch P1) as @ ((Skip, la2)#ys) = zs" using Cons.prems(4) Cons_lift_catch_append a_prod last_prod by (simp add: Cons.prems(6)) have "(\<Gamma>, map (lift_catch P1) ((P0, s) # a # as)) \<in> cptn" using Cons.prems(2) lift_catch_is_cptn by blast hence "(\<Gamma>, (LanguageCon.com.Catch P0 P1, s) # (LanguageCon.com.Catch a1 P1, a2) # map (lift_catch P1) as) \<in> cptn" by (metis (no_types) Cons_lift_catch a_prod) hence "(\<Gamma>, (LanguageCon.com.Catch P0 P1, s) # zs) \<in> cptn \<or> (\<Gamma>, (LanguageCon.com.Catch P0 P1, s) # (LanguageCon.com.Catch a1 P1, a2) # map (lift_catch P1) as) \<in> cptn \<and> (\<not> \<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Catch P0 P1, s) \<rightarrow>\<^sub>e (LanguageCon.com.Catch P0 P1, a2) \<or> (\<Gamma>, (LanguageCon.com.Catch P0 P1, a2) # map (lift_catch P1) as) \<notin> cptn \<or> LanguageCon.com.Catch a1 P1 \<noteq> LanguageCon.com.Catch P0 P1)" using f1 cptn.Cptn hyp using e_step by blast thus ?thesis by (metis (no_types) f1 cptn.Cptn cptn_elim_cases(2) hyp) qed qed next case (CptnModCatch3 \<Gamma> P0 s xs s' P1 ys zs) thus ?case proof (induct xs arbitrary: zs P0 s) case Nil then have "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Catch LanguageCon.com.Throw P1, Normal s) \<rightarrow>\<^sub>c\<^sub>e (P1, Normal s)" by (metis CatchThrowc prod.exhaust_sel transfer_normal) thus ?case using cptn.simps using Nil.prems(3) Nil.prems(6) Nil.prems(7) by fastforce next case (Cons a as) then obtain sa where "snd a = Normal sa" by (meson Normal_Normal) obtain a1 a2 where a_prod:"a=(a1,a2)" by fastforce obtain la1 la2 where last_prod:"last (a#as) = (la1,la2)" by fastforce then have lasst_aas_last: "last (a#as) = (last ((P0, Normal s) # a # as))" by auto then have "la1 = Throw" using Cons.prems(3) last_prod by force have "la2 = Normal s'" using Cons.prems(4) last_prod lasst_aas_last by force have f1: "(\<Gamma>, (a1, a2) # as) \<in> cptn" using Cons.prems(2) a_prod cptn_dest by blast have f2: "Normal sa = a2" using `snd a = Normal sa` a_prod by force have "(\<Gamma>, a # as) \<in> cptn_mod" using f1 a_prod cptn_onlyif_cptn_mod by blast then have hyp:"(\<Gamma>, (Catch a1 P1, Normal sa) # map (lift_catch P1) as @ (P1, snd (last ((a1, Normal sa) # as))) # ys) \<in> cptn" using Cons.hyps Cons.prems a_prod f1 f2 by (metis lasst_aas_last) thus ?case proof - (* have "\<Gamma>\<turnstile>\<^sub>c (P0, Normal s) \<rightarrow>\<^sub>e (P0, a2)" by (fastforce intro: step_e.intros) then *) have transit:"\<Gamma>\<turnstile>\<^sub>c(P0,Normal s) \<rightarrow>\<^sub>c\<^sub>e (a1,Normal sa)" by (metis (no_types) Cons.prems(2) a_prod cptn_elim_cases(2) f2) then have transit_catch:"\<Gamma>\<turnstile>\<^sub>c(Catch P0 P1,Normal s) \<rightarrow>\<^sub>c\<^sub>e (Catch a1 P1,Normal sa)" proof - have f1: "P0 = a1 \<or> \<not> \<Gamma>\<turnstile>\<^sub>c (P0, Normal s) \<rightarrow>\<^sub>e (a1, Normal sa)" using not_eq_not_env transit by blast have "\<Gamma>\<turnstile>\<^sub>c (a1, Normal s) \<rightarrow>\<^sub>e (a1, Normal sa) \<longrightarrow> \<Gamma>\<turnstile>\<^sub>c (Catch a1 P1, Normal s) \<rightarrow>\<^sub>e (Catch a1 P1, Normal sa)" using env_intro by blast then show ?thesis using f1 by (metis (no_types) Catchc e_step prod.collapse step_dest toSeq.simps(1) transfer_normal transit) qed have "a=(a1, Normal sa)" using a_prod f2 by auto then have "snd (last ((a1, Normal sa) # as)) = Normal s'" using Cons lasst_aas_last by fastforce hence f1: "snd (last ((a1, Normal sa) # as)) = la2" using `la2 = Normal s'` by blast have "(Catch a1 P1, a2) # map (lift_catch P1) as @ (P1, la2) # ys = zs" using Cons.prems Cons_lift_catch_append a_prod last_prod by auto moreover have "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Catch P0 P1, Normal s) \<rightarrow>\<^sub>c\<^sub>e (LanguageCon.com.Catch a1 P1, a2)" using f2 transit_catch by blast ultimately show ?thesis using f1 cptn.Cptn f2 hyp by metis qed qed next case (CptnModEnv) thus ?case by (simp add: cptn.Cptn e_step) qed lemma cptn_eq_cptn_mod: shows "(x \<in>cptn_mod) = (x\<in>cptn)" by (cases x, auto simp add: cptn_if_cptn_mod cptn_onlyif_cptn_mod) lemma cptn_eq_cptn_mod_set: shows "cptn_mod = cptn" by (auto simp add: cptn_if_cptn_mod cptn_onlyif_cptn_mod) subsection \<open>Computational modular semantic for nested calls\<close> inductive_set cptn_mod_nest_call :: "(nat\<times>('g,'l,'p,'f,'e) confs) set" where CptnModNestOne: "(n,\<Gamma>,[(P, s)]) \<in> cptn_mod_nest_call" | CptnModNestEnv: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,s) \<rightarrow>\<^sub>e (P,t);(n,\<Gamma>,(P, t)#xs) \<in> cptn_mod_nest_call\<rbrakk> \<Longrightarrow> (n,\<Gamma>,(P, s)#(P, t)#xs) \<in> cptn_mod_nest_call" | CptnModNestSkip: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,toSeq s) \<rightarrow> (Skip,toSeq t); redex P = P; \<forall>ns ns'. (s = Normal ns \<or> s = Abrupt ns) \<and> (t = Normal ns' \<or> t = Abrupt ns') \<longrightarrow> snd ns = snd ns'; \<forall>f. ((\<exists>sn. s = Normal sn) \<and> (\<Gamma> f) = Some Skip \<longrightarrow> P \<noteq> Call f ); (n,\<Gamma>,(Skip, t)#xs) \<in> cptn_mod_nest_call \<rbrakk> \<Longrightarrow> (n,\<Gamma>,(P,s)#(Skip, t)#xs) \<in>cptn_mod_nest_call" | CptnModNestThrow: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,toSeq s) \<rightarrow> (Throw,toSeq t); redex P = P; \<forall>f. ((\<exists>sn. s = Normal sn) \<and> (\<Gamma> f) = Some Throw \<longrightarrow> P \<noteq> Call f ); \<forall>ns ns'. (s = Normal ns \<or> s = Abrupt ns) \<and> (t = Normal ns' \<or> t = Abrupt ns') \<longrightarrow> snd ns = snd ns'; (n,\<Gamma>,(Throw, t)#xs) \<in> cptn_mod_nest_call \<rbrakk> \<Longrightarrow> (n,\<Gamma>,(P,s)#(Throw, t)#xs) \<in>cptn_mod_nest_call" | CptnModNestCondT: "\<lbrakk>(n,\<Gamma>,(P0, Normal s)#ys) \<in> cptn_mod_nest_call; fst s \<in> b \<rbrakk> \<Longrightarrow> (n,\<Gamma>,((Cond b P0 P1), Normal s)#(P0, Normal s)#ys) \<in> cptn_mod_nest_call" | CptnModNestCondF: "\<lbrakk>(n,\<Gamma>,(P1, Normal s)#ys) \<in> cptn_mod_nest_call; fst s \<notin> b \<rbrakk> \<Longrightarrow> (n,\<Gamma>,((Cond b P0 P1), Normal s)#(P1, Normal s)#ys) \<in> cptn_mod_nest_call" | CptnModNestSeq1: "\<lbrakk>(n,\<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call; zs=map (lift P1) xs \<rbrakk> \<Longrightarrow> (n,\<Gamma>,((Seq P0 P1), s)#zs) \<in> cptn_mod_nest_call" | CptnModNestSeq2: "\<lbrakk>(n,\<Gamma>, (P0, s)#xs) \<in> cptn_mod_nest_call; fst(last ((P0, s)#xs)) = Skip; (n,\<Gamma>,(P1, snd(last ((P0, s)#xs)))#ys) \<in> cptn_mod_nest_call; zs=(map (lift P1) xs)@((P1, snd(last ((P0, s)#xs)))#ys) \<rbrakk> \<Longrightarrow> (n,\<Gamma>,((Seq P0 P1), s)#zs) \<in> cptn_mod_nest_call" | CptnModNestSeq3: "\<lbrakk>(n,\<Gamma>, (P0, Normal s)#xs) \<in> cptn_mod_nest_call; fst(last ((P0, Normal s)#xs)) = Throw; snd(last ((P0, Normal s)#xs)) = Normal s'; (n,\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod_nest_call; zs=(map (lift P1) xs)@((Throw,Normal s')#ys) \<rbrakk> \<Longrightarrow> (n,\<Gamma>,((Seq P0 P1), Normal s)#zs) \<in> cptn_mod_nest_call" | CptnModNestWhile1: "\<lbrakk>(n,\<Gamma>, (P, Normal s)#xs) \<in> cptn_mod_nest_call; fst s \<in> b; zs=map (lift (While b P)) xs \<rbrakk> \<Longrightarrow> (n,\<Gamma>, ((While b P), Normal s)# ((Seq P (While b P)),Normal s)#zs) \<in> cptn_mod_nest_call" | CptnModNestWhile2: "\<lbrakk> (n,\<Gamma>, (P, Normal s)#xs) \<in> cptn_mod_nest_call; fst(last ((P, Normal s)#xs))=Skip; fst s \<in> b; zs=(map (lift (While b P)) xs)@ (While b P, snd(last ((P, Normal s)#xs)))#ys; (n,\<Gamma>,(While b P, snd(last ((P, Normal s)#xs)))#ys) \<in> cptn_mod_nest_call\<rbrakk> \<Longrightarrow> (n,\<Gamma>,(While b P, Normal s)# (Seq P (While b P), Normal s)#zs) \<in> cptn_mod_nest_call" | CptnModNestWhile3: "\<lbrakk> (n,\<Gamma>, (P, Normal s)#xs) \<in> cptn_mod_nest_call; fst(last ((P, Normal s)#xs))=Throw; fst s \<in> b; snd(last ((P, Normal s)#xs)) = Normal s'; (n,\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod_nest_call; zs=(map (lift (While b P)) xs)@((Throw,Normal s')#ys)\<rbrakk> \<Longrightarrow> (n,\<Gamma>,(While b P, Normal s)# (Seq P (While b P), Normal s)#zs) \<in> cptn_mod_nest_call" | CptnModNestCall: "\<lbrakk>(n,\<Gamma>,(bdy, Normal s)#ys) \<in> cptn_mod_nest_call;\<Gamma> p = Some bdy; bdy\<noteq>Call p \<rbrakk> \<Longrightarrow> (Suc n, \<Gamma>,((Call p), Normal s)#(bdy, Normal s)#ys) \<in> cptn_mod_nest_call" | CptnModNestDynCom: "\<lbrakk>(n,\<Gamma>,(c (fst s), Normal s)#ys) \<in> cptn_mod_nest_call \<rbrakk> \<Longrightarrow> (n,\<Gamma>,(DynCom c, Normal s)#(c (fst s), Normal s)#ys) \<in> cptn_mod_nest_call" | CptnModNestGuard: "\<lbrakk>(n,\<Gamma>,(c, Normal s)#ys) \<in> cptn_mod_nest_call; fst s \<in> g \<rbrakk> \<Longrightarrow> (n,\<Gamma>,(Guard f g c, Normal s)#(c, Normal s)#ys) \<in> cptn_mod_nest_call" | CptnModNestCatch1: "\<lbrakk>(n,\<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call; zs=map (lift_catch P1) xs \<rbrakk> \<Longrightarrow> (n,\<Gamma>,((Catch P0 P1), s)#zs) \<in> cptn_mod_nest_call" | CptnModNestCatch2: "\<lbrakk>(n,\<Gamma>, (P0, s)#xs) \<in> cptn_mod_nest_call; fst(last ((P0, s)#xs)) = Skip; (n,\<Gamma>,(Skip,snd(last ((P0, s)#xs)))#ys) \<in> cptn_mod_nest_call; zs=(map (lift_catch P1) xs)@((Skip,snd(last ((P0, s)#xs)))#ys) \<rbrakk> \<Longrightarrow> (n,\<Gamma>,((Catch P0 P1), s)#zs) \<in> cptn_mod_nest_call" | CptnModNestCatch3: "\<lbrakk>(n,\<Gamma>, (P0, Normal s)#xs) \<in> cptn_mod_nest_call; fst(last ((P0, Normal s)#xs)) = Throw; snd(last ((P0, Normal s)#xs)) = Normal s'; (n,\<Gamma>,(P1, snd(last ((P0, Normal s)#xs)))#ys) \<in> cptn_mod_nest_call; zs=(map (lift_catch P1) xs)@((P1, snd(last ((P0, Normal s)#xs)))#ys) \<rbrakk> \<Longrightarrow> (n,\<Gamma>,((Catch P0 P1), Normal s)#zs) \<in> cptn_mod_nest_call" lemmas CptnMod_nest_call_induct = cptn_mod_nest_call.induct [of _ _ "[(c,s)]", split_format (complete), case_names CptnModOne CptnModEnv CptnModSkip CptnModThrow CptnModCondT CptnModCondF CptnModSeq1 CptnModSeq2 CptnModSeq3 CptnModSeq4 CptnModWhile1 CptnModWhile2 CptnModWhile3 CptnModCall CptnModDynCom CptnModGuard CptnModCatch1 CptnModCatch2 CptnModCatch3, induct set] inductive_cases CptnModNest_elim_cases [cases set]: "(n,\<Gamma>,(Skip, s)#u#xs) \<in> cptn_mod_nest_call" "(n,\<Gamma>,(Guard f g c, s)#u#xs) \<in> cptn_mod_nest_call" "(n,\<Gamma>,(Basic f e, s)#u#xs) \<in> cptn_mod_nest_call" "(n,\<Gamma>,(Spec r e, s)#u#xs) \<in> cptn_mod_nest_call" "(n,\<Gamma>,(Seq c1 c2, s)#u#xs) \<in> cptn_mod_nest_call" "(n,\<Gamma>,(Cond b c1 c2, s)#u#xs) \<in> cptn_mod_nest_call" "(n,\<Gamma>,(Await b c2 e, s)#u#xs) \<in> cptn_mod_nest_call" "(n,\<Gamma>,(Call p, s)#u#xs) \<in> cptn_mod_nest_call" "(n,\<Gamma>,(DynCom c,s)#u#xs) \<in> cptn_mod_nest_call" "(n,\<Gamma>,(Throw,s)#u#xs) \<in> cptn_mod_nest_call" "(n,\<Gamma>,(Catch c1 c2,s)#u#xs) \<in> cptn_mod_nest_call" inductive_cases stepc_elim_cases_Seq_Seq': "\<Gamma>\<turnstile>\<^sub>c(Seq c1 c2,s) \<rightarrow> (Seq c1' c2',s')" inductive_cases stepc_elim_cases_Catch_Catch': "\<Gamma>\<turnstile>\<^sub>c(Catch c1 c2,s) \<rightarrow> (Catch c1' c2',s')" inductive_cases CptnModNest_same_elim_cases [cases set]: "(n,\<Gamma>,(u, s)#(u,t)#xs) \<in> cptn_mod_nest_call" inductive_cases CptnModNest_elim_cases_Stuck [cases set]: "(n,\<Gamma>,(P, Stuck)#(Skip, s)#xs) \<in> cptn_mod_nest_call" inductive_cases CptnModNest_elim_cases_Fault [cases set]: "(n,\<Gamma>,(P, Fault f)#(Skip, s)#xs) \<in> cptn_mod_nest_call" inductive_cases CptnModNest_elim_cases_Abrupt [cases set]: "(n,\<Gamma>,(P, Abrupt as)#(Skip, s)#xs) \<in> cptn_mod_nest_call" inductive_cases CptnModNest_elim_cases_Call_Stuck [cases set]: "(n,\<Gamma>,(Call p, s)#(Skip, Stuck)#xs) \<in> cptn_mod_nest_call" inductive_cases CptnModNest_elim_cases_Call [cases set]: "(0, \<Gamma>,((Call p), Normal s)#(bdy, Normal s)#ys) \<in> cptn_mod_nest_call" inductive_cases CptnEmpty [cases set]: "(n, \<Gamma>,[]) \<in> cptn_mod_nest_call" inductive_cases CptnModNest_elim_cases_Call_normal [cases set]: "(Suc n, \<Gamma>,((Call p), Normal s)#(bdy, Normal s)#ys) \<in> cptn_mod_nest_call" lemma cptn_mod_nest_mono1: "(n,\<Gamma>,cfs) \<in> cptn_mod_nest_call \<Longrightarrow> (Suc n,\<Gamma>,cfs)\<in> cptn_mod_nest_call" proof (induct rule:cptn_mod_nest_call.induct) case (CptnModNestOne) thus ?case using cptn_mod_nest_call.CptnModNestOne by blast next case (CptnModNestEnv) thus ?case using cptn_mod_nest_call.CptnModNestEnv by blast next case (CptnModNestSkip) thus ?case using cptn_mod_nest_call.CptnModNestSkip by blast next case (CptnModNestThrow) thus ?case using cptn_mod_nest_call.intros(4) by blast next case (CptnModNestCondT n) thus ?case using cptn_mod_nest_call.CptnModNestCondT[of "Suc n"] by blast next case (CptnModNestCondF n) thus ?case using cptn_mod_nest_call.CptnModNestCondF[of "Suc n"] by blast next case (CptnModNestSeq1 n) thus ?case using cptn_mod_nest_call.CptnModNestSeq1[of "Suc n"] by blast next case (CptnModNestSeq2 n) thus ?case using cptn_mod_nest_call.CptnModNestSeq2[of "Suc n"] by blast next case (CptnModNestSeq3 n) thus ?case using cptn_mod_nest_call.CptnModNestSeq3[of "Suc n"] by blast next case (CptnModNestWhile1 n) thus ?case using cptn_mod_nest_call.CptnModNestWhile1[of "Suc n"] by blast next case (CptnModNestWhile2 n) thus ?case using cptn_mod_nest_call.CptnModNestWhile2[of "Suc n"] by blast next case (CptnModNestWhile3 n) thus ?case using cptn_mod_nest_call.CptnModNestWhile3[of "Suc n"] by blast next case (CptnModNestCall) thus ?case using cptn_mod_nest_call.CptnModNestCall by fastforce next case (CptnModNestDynCom) thus ?case using cptn_mod_nest_call.CptnModNestDynCom by blast next case (CptnModNestGuard n) thus ?case using cptn_mod_nest_call.CptnModNestGuard[of "Suc n"] by fastforce next case (CptnModNestCatch1 n) thus ?case using cptn_mod_nest_call.CptnModNestCatch1[of "Suc n"] by fastforce next case (CptnModNestCatch2 n) thus ?case using cptn_mod_nest_call.CptnModNestCatch2[of "Suc n"] by fastforce next case (CptnModNestCatch3 n) thus ?case using cptn_mod_nest_call.CptnModNestCatch3[of "Suc n"] by fastforce qed lemma cptn_mod_nest_mono2: "(n,\<Gamma>,cfs) \<in> cptn_mod_nest_call \<Longrightarrow> m>n \<Longrightarrow> (m,\<Gamma>,cfs)\<in> cptn_mod_nest_call" proof (induct "m-n" arbitrary: m n) case 0 thus ?case by auto next case (Suc k) have "m - Suc n = k" using Suc.hyps(2) Suc.prems(2) Suc_diff_Suc Suc_inject by presburger then show ?case using Suc.hyps(1) Suc.prems(1) Suc.prems(2) cptn_mod_nest_mono1 less_Suc_eq by blast qed lemma cptn_mod_nest_mono: "(n,\<Gamma>,cfs) \<in> cptn_mod_nest_call \<Longrightarrow> m\<ge>n \<Longrightarrow> (m,\<Gamma>,cfs)\<in> cptn_mod_nest_call" proof (cases "n=m") assume "(n, \<Gamma>, cfs) \<in> cptn_mod_nest_call" and "n = m" thus ?thesis by auto next assume "(n, \<Gamma>, cfs) \<in> cptn_mod_nest_call" and "n\<le>m" and "n \<noteq> m" thus ?thesis by (auto simp add: cptn_mod_nest_mono2) qed subsection \<open>Equivalence of comp mod semantics and comp mod nested\<close> definition catch_cond_nest where "catch_cond_nest zs Q xs P s s'' s' \<Gamma> n \<equiv> (zs=(map (lift_catch Q) xs) \<or> ((fst(((P, s)#xs)!length xs)=Throw \<and> snd(last ((P, s)#xs)) = Normal s' \<and> s=Normal s''\<and> (\<exists>ys. (n,\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod_nest_call \<and> zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or> ((fst(((P, s)#xs)!length xs)=Skip \<and> (\<exists>ys. (n,\<Gamma>,(Skip,snd(last ((P, s)#xs)))#ys) \<in> cptn_mod_nest_call \<and> zs=(map (lift_catch Q) xs)@((Skip,snd(last ((P, s)#xs)))#ys))))) " lemma div_catch_nest: assumes cptn_m:"(n,\<Gamma>,list) \<in> cptn_mod_nest_call" shows "(\<forall>s P Q zs. list=(Catch P Q, s)#zs \<longrightarrow> (\<exists>xs s' s''. (n, \<Gamma>,(P, s)#xs) \<in> cptn_mod_nest_call \<and> catch_cond_nest zs Q xs P s s'' s' \<Gamma> n)) " unfolding catch_cond_nest_def using cptn_m proof (induct rule: cptn_mod_nest_call.induct) case (CptnModNestOne \<Gamma> P s) thus ?case using cptn_mod_nest_call.CptnModNestOne by blast next case (CptnModNestSkip \<Gamma> P s t n xs) from CptnModNestSkip.hyps have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Skip, toSeq t)" by auto from CptnModNestSkip.hyps have noskip: "~(P=Skip)" using stepc_elim_cases(1) by blast have no_catch: "\<forall>p1 p2. \<not>(P=Catch p1 p2)" using CptnModNestSkip.hyps(2) redex_not_Catch by auto from CptnModNestSkip.hyps have in_cptn_mod: "(n,\<Gamma>, (Skip, t) # xs) \<in> cptn_mod_nest_call" by auto then show ?case using no_catch by simp next case (CptnModNestThrow \<Gamma> P s t n xs) from CptnModNestThrow.hyps have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Throw, toSeq t)" by auto from CptnModNestThrow.hyps have in_cptn_mod: "(n,\<Gamma>, (Throw, t) # xs) \<in> cptn_mod_nest_call" by auto have no_catch: "\<forall>p1 p2. \<not>(P=Catch p1 p2)" using CptnModNestThrow.hyps(2) redex_not_Catch by auto then show ?case by auto next case (CptnModNestCondT \<Gamma> P0 s ys b P1) thus ?case using CptnModOne by blast next case (CptnModNestCondF \<Gamma> P0 s ys b P1) thus ?case using CptnModOne by blast next case (CptnModNestCatch1 sa P Q zs) thus ?case by blast next case (CptnModNestCatch2 n \<Gamma> P0 s xs ys zs P1) from CptnModNestCatch2.hyps(3) have last:"fst (((P0, s) # xs) ! length xs) = Skip" by (simp add: last_length) have P0cptn:"(n,\<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call" by fact then have "zs = map (lift_catch P1) xs @((Skip,snd(last ((P0, s)#xs)))#ys)" by (simp add:CptnModNestCatch2.hyps) show ?case proof -{ fix sa P Q zsa assume eq:"(Catch P0 P1, s) # zs = (Catch P Q, sa) # zsa" then have "P0 =P \<and> P1 = Q \<and> s=sa \<and> zs=zsa" by auto then have "(P0, s) = (P, sa)" by auto have "last ((P0, s) # xs) = ((P, sa) # xs) ! length xs" by (simp add: `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa` last_length) then have "zs = (map (lift_catch Q) xs)@((Skip,snd(last ((P0, s)#xs)))#ys)" using `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa` `zs = map (lift_catch P1) xs @ ((Skip,snd(last ((P0, s)#xs)))#ys)` by force then have "(\<exists>xs s' s''. ((n,\<Gamma>,(P, s)#xs) \<in> cptn_mod_nest_call \<and> ((zs=(map (lift_catch Q) xs) \<or> ((fst(((P, s)#xs)!length xs)=Throw \<and> snd(last ((P, s)#xs)) = Normal s' \<and> s=Normal s''\<and> (\<exists>ys. (n,\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod_nest_call \<and> zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or> (\<exists>ys. ((fst(((P, s)#xs)!length xs)=Skip \<and> (n,\<Gamma>,(Skip,snd(last ((P, s)#xs)))#ys) \<in> cptn_mod_nest_call \<and> zs=(map (lift_catch Q) xs)@((Skip,snd(last ((P0, s)#xs)))#ys))))))))" using P0cptn `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa` last CptnModNestCatch2.hyps(4) by blast } thus ?thesis by auto qed next case (CptnModNestCatch3 n \<Gamma> P0 s xs s' P1 ys zs) from CptnModNestCatch3.hyps(3) have last:"fst (((P0, Normal s) # xs) ! length xs) = Throw" by (simp add: last_length) from CptnModNestCatch3.hyps(4) have lastnormal:"snd (last ((P0, Normal s) # xs)) = Normal s'" by (simp add: last_length) have P0cptn:"(n,\<Gamma>, (P0, Normal s) # xs) \<in> cptn_mod_nest_call" by fact from CptnModNestCatch3.hyps(5) have P1cptn:"(n,\<Gamma>, (P1, snd (((P0, Normal s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call" by (simp add: last_length) then have "zs = map (lift_catch P1) xs @ (P1, snd (last ((P0, Normal s) # xs))) # ys" by (simp add:CptnModNestCatch3.hyps) show ?case proof -{ fix sa P Q zsa assume eq:"(Catch P0 P1, Normal s) # zs = (Catch P Q, Normal sa) # zsa" then have "P0 =P \<and> P1 = Q \<and> Normal s= Normal sa \<and> zs=zsa" by auto have "last ((P0, Normal s) # xs) = ((P, Normal sa) # xs) ! length xs" by (simp add: `P0 = P \<and> P1 = Q \<and> Normal s = Normal sa \<and> zs = zsa` last_length) then have "zsa = map (lift_catch Q) xs @ (Q, snd (((P, Normal sa) # xs) ! length xs)) # ys" using `P0 = P \<and> P1 = Q \<and> Normal s = Normal sa \<and> zs = zsa` `zs = map (lift_catch P1) xs @ (P1, snd (last ((P0, Normal s) # xs))) # ys` by force then have "(n,\<Gamma>, (P, Normal s) # xs) \<in> cptn_mod_nest_call \<and> (fst(((P, Normal s)#xs)!length xs)=Throw \<and> snd(last ((P, Normal s)#xs)) = Normal s' \<and> (\<exists>ys. (n,\<Gamma>,(Q, snd(((P, Normal s)#xs)!length xs))#ys) \<in> cptn_mod_nest_call \<and> zs=(map (lift_catch Q) xs)@((Q, snd(((P, Normal s)#xs)!length xs))#ys)))" using lastnormal P1cptn P0cptn `P0 = P \<and> P1 = Q \<and> Normal s = Normal sa \<and> zs = zsa` last by auto }note this [of P0 P1 s zs] thus ?thesis by blast qed next case (CptnModNestEnv \<Gamma> P s t n xs) then have step:"(n, \<Gamma>, (P, t) # xs) \<in> cptn_mod_nest_call" by auto have step_e: "\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (P, t)" using CptnModNestEnv by auto show ?case proof (cases P) case (Catch P1 P2) then have eq_P_Catch:"(P, t) # xs = (LanguageCon.com.Catch P1 P2, t) # xs" by auto then obtain xsa t' t'' where p1:"(n,\<Gamma>, (P1, t) # xsa) \<in> cptn_mod_nest_call" and p2:" (xs = map (lift_catch P2) xsa \<or> fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \<and> snd (last ((P1, t) # xsa)) = Normal t' \<and> t = Normal t'' \<and> (\<exists>ys. (n,\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<in> cptn_mod_nest_call \<and> xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<or> fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Skip \<and> (\<exists>ys.(n,\<Gamma>,(Skip,snd(last ((P1, t)#xsa)))#ys) \<in> cptn_mod_nest_call \<and> xs = map (lift_catch P2) xsa @ ((LanguageCon.com.Skip, snd (last ((P1, t) # xsa)))#ys)))" using CptnModNestEnv(3) by auto have all_step:"(n,\<Gamma>, (P1, s)#((P1, t) # xsa)) \<in> cptn_mod_nest_call" using p1 Env Env_n cptn_mod.CptnModEnv env_normal_s step_e proof - have "\<Gamma>\<turnstile>\<^sub>c (P1, s) \<rightarrow>\<^sub>e (P1, t)" using env_intro step_e by blast then show ?thesis by (simp add: cptn_mod_nest_call.CptnModNestEnv p1) qed show ?thesis using p2 proof assume "xs = map (lift_catch P2) xsa" have "(P, t) # xs = map (lift_catch P2) ((P1, t) # xsa)" by (simp add: `xs = map (lift_catch P2) xsa` lift_catch_def local.Catch) thus ?thesis using all_step eq_P_Catch by fastforce next assume "fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \<and> snd (last ((P1, t) # xsa)) = Normal t' \<and> t = Normal t'' \<and> (\<exists>ys. (n,\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<in> cptn_mod_nest_call \<and> xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<or> fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Skip \<and> (\<exists>ys. (n,\<Gamma>,(Skip,snd(last ((P1, t)#xsa)))#ys) \<in> cptn_mod_nest_call \<and> xs = map (lift_catch P2) xsa @ ((LanguageCon.com.Skip, snd (last ((P1, t) # xsa)))#ys))" then show ?thesis proof assume a1:"fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \<and> snd (last ((P1, t) # xsa)) = Normal t' \<and> t = Normal t'' \<and> (\<exists>ys. (n,\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<in> cptn_mod_nest_call \<and> xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys)" then obtain ys where p2_exec:"(n,\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<in> cptn_mod_nest_call \<and> xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys" by fastforce from a1 obtain t1 where t_normal: "t=Normal t1" using env_normal_s'_normal_s by blast have f1:"fst (((P1, s)#(P1, t) # xsa) ! length ((P1, t)#xsa)) = LanguageCon.com.Throw" using a1 by fastforce from a1 have last_normal: "snd (last ((P1, s)#(P1, t) # xsa)) = Normal t'" by fastforce then have p2_long_exec: "(n,\<Gamma>, (P2, snd (((P1, s)#(P1, t) # xsa) ! length ((P1, s)#xsa))) # ys) \<in> cptn_mod_nest_call \<and> (P, t)#xs = map (lift_catch P2) ((P1, t) # xsa) @ (P2, snd (((P1, s)#(P1, t) # xsa) ! length ((P1, s)#xsa))) # ys" using p2_exec by (simp add: lift_catch_def local.Catch) thus ?thesis using a1 f1 last_normal all_step eq_P_Catch by (clarify, metis (no_types) list.size(4) not_step_c_env step_e) next assume as1:"fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Skip \<and> (\<exists>ys. (n,\<Gamma>,(Skip,snd(last ((P1, t)#xsa)))#ys) \<in> cptn_mod_nest_call \<and> xs = map (lift_catch P2) xsa @ ((LanguageCon.com.Skip, snd (last ((P1, t) # xsa)))#ys))" then obtain ys where p1:"(n,\<Gamma>,(Skip,snd(last ((P1, t)#xsa)))#ys) \<in> cptn_mod_nest_call \<and> (P, t)#xs = map (lift_catch P2) ((P1, t) # xsa) @ ((LanguageCon.com.Skip, snd (last ((P1, t) # xsa)))#ys)" proof - assume a1: "\<And>ys. (n,\<Gamma>, (LanguageCon.com.Skip, snd (last ((P1, t) # xsa))) # ys) \<in> cptn_mod_nest_call \<and> (P, t) # xs = map (lift_catch P2) ((P1, t) # xsa) @ (LanguageCon.com.Skip, snd (last ((P1, t) # xsa))) # ys \<Longrightarrow> thesis" have "(LanguageCon.com.Catch P1 P2, t) # map (lift_catch P2) xsa = map (lift_catch P2) ((P1, t) # xsa)" by (simp add: lift_catch_def) thus ?thesis using a1 as1 eq_P_Catch by moura qed from as1 have p2: "fst (((P1, s)#(P1, t) # xsa) ! length ((P1, t) #xsa)) = LanguageCon.com.Skip" by fastforce thus ?thesis using p1 all_step eq_P_Catch by fastforce qed qed qed (auto) qed(force+) definition seq_cond_nest where "seq_cond_nest zs Q xs P s s'' s' \<Gamma> n \<equiv> (zs=(map (lift Q) xs) \<or> ((fst(((P, s)#xs)!length xs)=Skip \<and> (\<exists>ys. (n,\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod_nest_call \<and> zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or> ((fst(((P, s)#xs)!length xs)=Throw \<and> snd(last ((P, s)#xs)) = Normal s' \<and> s=Normal s''\<and> (\<exists>ys. (n,\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod_nest_call \<and> zs=(map (lift Q) xs)@((Throw,Normal s')#ys))))) " lemma Seq_P_Not_finish: assumes a0:"zs = map (lift Q) xs" and a1:"(m, \<Gamma>,(LanguageCon.com.Seq P Q, s) # zs) \<in> cptn_mod_nest_call" and a2:"seq_cond_nest zs Q xs' P s s'' s' \<Gamma> m" shows "xs=xs'" using a2 unfolding seq_cond_nest_def proof assume "zs= map (lift Q) xs'" then have "map (lift Q) xs' = map (lift Q) xs" using a0 by auto thus ?thesis using map_lift_eq_xs_xs' by fastforce next assume ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \<and> (\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \<or> fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \<and> snd (last ((P, s) # xs')) = Normal s' \<and> s = Normal s'' \<and> (\<exists>ys. (m, \<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (LanguageCon.com.Throw, Normal s') # ys)" {assume ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \<and> (\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)" then obtain ys where zs:"zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys" by auto then have zs_while:"fst (zs!(length (map (lift Q) xs'))) = Q" by (metis fstI nth_append_length) have "length zs = length (map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)" using zs by auto then have "(length (map (lift Q) xs')) < length zs" by auto then have ?thesis using a0 zs_while map_lift_all_seq using seq_and_if_not_eq(4) by fastforce }note l = this {assume ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \<and> snd (last ((P, s) # xs')) = Normal s' \<and> s = Normal s'' \<and> (\<exists>ys. (m, \<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (LanguageCon.com.Throw, Normal s') # ys)" then obtain ys where zs:"zs = map (lift Q) xs' @ (LanguageCon.com.Throw, Normal s') # ys" by auto then have zs_while: "fst (zs!(length (map (lift Q) xs'))) = Throw" by (metis fstI nth_append_length) have "length zs = length (map (lift Q) xs' @(LanguageCon.com.Throw, Normal s') # ys)" using zs by auto then have "(length (map (lift Q) xs')) < length zs" by auto then have ?thesis using a0 zs_while map_lift_all_seq using seq_and_if_not_eq(4) by fastforce } thus ?thesis using l ass by auto qed lemma Seq_P_Ends_Normal: assumes a0:"zs = map (lift Q) xs @ (Q, snd (last ((P, s) # xs))) # ys" and a0':"fst (last ((P, s) # xs)) = Skip" and a1:"(m, \<Gamma>,(LanguageCon.com.Seq P Q, s) # zs) \<in> cptn_mod_nest_call" and a2:"seq_cond_nest zs Q xs' P s s'' s' \<Gamma> m" shows "xs=xs' \<and> (m,\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod_nest_call" using a2 unfolding seq_cond_nest_def proof assume ass:"zs= map (lift Q) xs'" then have "map (lift Q) xs' = map (lift Q) xs @ (Q, snd (last ((P, s) # xs))) # ys" using a0 by auto then have zs_while:"fst (zs!(length (map (lift Q) xs))) = Q" by (metis a0 fstI nth_append_length) also have "length zs = length (map (lift Q) xs @ (Q, snd (last ((P, s) # xs))) # ys)" using a0 by auto then have "(length (map (lift Q) xs)) < length zs" by auto then show ?thesis using ass zs_while map_lift_all_seq using seq_and_if_not_eq(4) by metis next assume ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \<and> (\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \<or> fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \<and> snd (last ((P, s) # xs')) = Normal s' \<and> s = Normal s'' \<and> (\<exists>ys. (m, \<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (LanguageCon.com.Throw, Normal s') # ys)" {assume ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \<and> (\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)" then obtain ys' where zs:"zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys' \<and> (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys') \<in> cptn_mod_nest_call" by auto then have ?thesis using map_lift_some_eq[of Q xs Q _ ys xs' Q _ ys'] zs a0 seq_and_if_not_eq(4)[of Q] by auto }note l = this {assume ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \<and> snd (last ((P, s) # xs')) = Normal s' \<and> s = Normal s'' \<and> (\<exists>ys. (m, \<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (LanguageCon.com.Throw, Normal s') # ys)" then obtain ys' where zs:"zs = map (lift Q) xs' @ (LanguageCon.com.Throw, Normal s') # ys' \<and> (m, \<Gamma>, (LanguageCon.com.Throw, Normal s') # ys') \<in> cptn_mod_nest_call" by auto then have zs_while: "fst (zs!(length (map (lift Q) xs'))) = Throw" by (metis fstI nth_append_length) have False by (metis (no_types) LanguageCon.com.distinct(17) LanguageCon.com.distinct(71) a0 a0' ass last_length map_lift_some_eq seq_and_if_not_eq(4) zs) then have ?thesis by metis } thus ?thesis using l ass by auto qed lemma Seq_P_Ends_Abort: assumes a0:"zs = map (lift Q) xs @ (Throw, Normal s') # ys" and a0':"fst (last ((P, Normal s) # xs)) = Throw" and a0'':"snd(last ((P, Normal s) # xs)) = Normal s'" and a1:"(m, \<Gamma>,(LanguageCon.com.Seq P Q, Normal s) # zs) \<in> cptn_mod_nest_call" and a2:"seq_cond_nest zs Q xs' P (Normal s) ns'' ns' \<Gamma> m" shows "xs=xs' \<and> (m,\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod_nest_call" using a2 unfolding seq_cond_nest_def proof assume ass:"zs= map (lift Q) xs'" then have "map (lift Q) xs' = map (lift Q) xs @ (Throw, Normal s') # ys" using a0 by auto then have zs_while:"fst (zs!(length (map (lift Q) xs))) = Throw" by (metis a0 fstI nth_append_length) also have "length zs = length (map (lift Q) xs @ (Throw, Normal s') # ys)" using a0 by auto then have "(length (map (lift Q) xs)) < length zs" by auto then show ?thesis using ass zs_while map_lift_all_seq by (metis (no_types) LanguageCon.com.simps(82)) next assume ass:"fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Skip \<and> (\<exists>ys. (m, \<Gamma>, (Q, snd (((P, Normal s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (Q, snd (((P, Normal s) # xs') ! length xs')) # ys) \<or> fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Throw \<and> snd (last ((P, Normal s) # xs')) = Normal ns' \<and> Normal s = Normal ns'' \<and> (\<exists>ys. (m, \<Gamma>, (LanguageCon.com.Throw, Normal ns') # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (LanguageCon.com.Throw, Normal ns') # ys)" {assume ass:"fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Skip \<and> (\<exists>ys. (m, \<Gamma>, (Q, snd (((P, Normal s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (Q, snd (((P, Normal s) # xs') ! length xs')) # ys)" then obtain ys' where zs:"(m, \<Gamma>, (Q, snd (((P, Normal s) # xs') ! length xs')) # ys') \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (Q, snd (((P, Normal s) # xs') ! length xs')) # ys'" by auto then have ?thesis using a0 seq_and_if_not_eq(4)[of Q] by (metis LanguageCon.com.distinct(17) LanguageCon.com.distinct(71) a0' ass last_length map_lift_some_eq) }note l = this {assume ass:"fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Throw \<and> snd (last ((P, Normal s) # xs')) = Normal ns' \<and> Normal s = Normal ns'' \<and> (\<exists>ys. (m, \<Gamma>, (LanguageCon.com.Throw, Normal ns') # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (LanguageCon.com.Throw, Normal ns') # ys)" then obtain ys' where zs:"(m, \<Gamma>, (LanguageCon.com.Throw, Normal ns') # ys') \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (LanguageCon.com.Throw, Normal ns') # ys'" by auto then have zs_while: "fst (zs!(length (map (lift Q) xs'))) = Throw" by (metis fstI nth_append_length) then have ?thesis using a0 ass map_lift_some_eq by blast } thus ?thesis using l ass by auto qed lemma Catch_P_Not_finish: assumes a0:"zs = map (lift_catch Q) xs" and a1:"catch_cond_nest zs Q xs' P s s'' s' \<Gamma> m" shows "xs=xs'" using a1 unfolding catch_cond_nest_def proof assume "zs= map (lift_catch Q) xs'" then have "map (lift_catch Q) xs' = map (lift_catch Q) xs" using a0 by auto thus ?thesis using map_lift_catch_eq_xs_xs' by fastforce next assume ass:" fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \<and> snd (last ((P, s) # xs')) = Normal s' \<and> s = Normal s'' \<and> (\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \<or> fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \<and> (\<exists>ys. (m, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys)" {assume ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \<and> (\<exists>ys. (m, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys)" then obtain ys where zs:"(m, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys" by auto then have zs_while:"fst (zs!(length (map (lift_catch Q) xs'))) = Skip " by (metis fstI nth_append_length) have "length zs = length (map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)" using zs by auto then have "(length (map (lift Q) xs')) < length zs" by auto then have ?thesis using a0 zs_while map_lift_catch_all_catch using seq_and_if_not_eq(12) by fastforce }note l = this {assume ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \<and> snd (last ((P, s) # xs')) = Normal s' \<and> s = Normal s'' \<and> (\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)" then obtain ys where zs:"zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys" by auto then have zs_while: "fst (zs!(length (map (lift Q) xs'))) = Q" by (metis (no_types) eq_fst_iff length_map nth_append_length zs) have "length zs = length (map (lift Q) xs' @(LanguageCon.com.Throw, Normal s') # ys)" using zs by auto then have "(length (map (lift Q) xs')) < length zs" by auto then have ?thesis using a0 zs_while map_lift_catch_all_catch by fastforce } thus ?thesis using l ass by auto qed lemma Catch_P_Ends_Normal: assumes a0:"zs = map (lift_catch Q) xs @ (Q, snd (last ((P, Normal s) # xs))) # ys" and a0':"fst (last ((P, Normal s) # xs)) = Throw" and a0'':"snd (last ((P, Normal s) # xs)) = Normal s'" and a1:"catch_cond_nest zs Q xs' P (Normal s) ns'' ns' \<Gamma> m" shows "xs=xs' \<and> (m,\<Gamma>,(Q, snd(((P, Normal s)#xs)!length xs))#ys) \<in> cptn_mod_nest_call" using a1 unfolding catch_cond_nest_def proof assume ass:"zs= map (lift_catch Q) xs'" then have "map (lift_catch Q) xs' = map (lift_catch Q) xs @ (Q, snd (last ((P, Normal s) # xs))) # ys" using a0 by auto then have zs_while:"fst (zs!(length (map (lift_catch Q) xs))) = Q" by (metis a0 fstI nth_append_length) also have "length zs = length (map (lift_catch Q) xs @ (Q, snd (last ((P, Normal s) # xs))) # ys)" using a0 by auto then have "(length (map (lift_catch Q) xs)) < length zs" by auto then show ?thesis using ass zs_while map_lift_catch_all_catch using seq_and_if_not_eq(12) by metis next assume ass:"fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Throw \<and> snd (last ((P, Normal s) # xs')) = Normal ns' \<and> Normal s = Normal ns'' \<and> (\<exists>ys. (m, \<Gamma>, (Q, snd (((P, Normal s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift_catch Q) xs' @ (Q, snd (((P, Normal s) # xs') ! length xs')) # ys) \<or> fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Skip \<and> (\<exists>ys. (m, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P, Normal s) # xs'))) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, Normal s) # xs'))) # ys)" {assume ass:"fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Skip \<and> (\<exists>ys. (m, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P, Normal s) # xs'))) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, Normal s) # xs'))) # ys)" then obtain ys' where zs:"(m, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P, Normal s) # xs'))) # ys') \<in> cptn_mod_nest_call \<and> zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, Normal s) # xs'))) # ys'" by auto then have ?thesis using map_lift_catch_some_eq[of Q xs Q _ ys xs' Skip _ ys'] zs a0 seq_and_if_not_eq(12)[of Q] by (metis LanguageCon.com.distinct(17) LanguageCon.com.distinct(19) a0' ass last_length) }note l = this {assume ass:"fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Throw \<and> snd (last ((P, Normal s) # xs')) = Normal ns' \<and> Normal s = Normal ns'' \<and> (\<exists>ys. (m, \<Gamma>, (Q, snd (((P, Normal s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift_catch Q) xs' @ (Q, snd (((P, Normal s) # xs') ! length xs')) # ys)" then obtain ys' where zs:"(m, \<Gamma>, (Q, snd (((P, Normal s) # xs') ! length xs')) # ys') \<in> cptn_mod_nest_call \<and> zs = map (lift_catch Q) xs' @ (Q, snd (((P, Normal s) # xs') ! length xs')) # ys'" by auto then have zs_while: "fst (zs!(length (map (lift_catch Q) xs'))) = Q" by (metis fstI nth_append_length) then have ?thesis using LanguageCon.com.distinct(17) LanguageCon.com.distinct(71) a0 a0' ass last_length map_lift_catch_some_eq[of Q xs Q _ ys xs' Q _ ys'] seq_and_if_not_eq(12) zs by blast } thus ?thesis using l ass by auto qed lemma Catch_P_Ends_Skip: assumes a0:"zs = map (lift_catch Q) xs @ (Skip, snd (last ((P, s) # xs))) # ys" and a0':"fst (last ((P,s) # xs)) = Skip" and a1:"catch_cond_nest zs Q xs' P s ns'' ns' \<Gamma> m" shows "xs=xs' \<and> (m,\<Gamma>,(Skip,snd(last ((P,s) # xs)))#ys) \<in> cptn_mod_nest_call" using a1 unfolding catch_cond_nest_def proof assume ass:"zs= map (lift_catch Q) xs'" then have "map (lift_catch Q) xs' = map (lift_catch Q) xs @ (Skip, snd (last ((P, s) # xs))) # ys" using a0 by auto then have zs_while:"fst (zs!(length (map (lift_catch Q) xs))) = Skip" by (metis a0 fstI nth_append_length) also have "length zs = length (map (lift_catch Q) xs @ (Skip, snd (last ((P, s) # xs))) # ys)" using a0 by auto then have "(length (map (lift_catch Q) xs)) < length zs" by auto then show ?thesis using ass zs_while map_lift_catch_all_catch by (metis LanguageCon.com.distinct(19)) next assume ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \<and> snd (last ((P, s) # xs')) = Normal ns' \<and> s = Normal ns'' \<and> (\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \<or> fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \<and> (\<exists>ys. (m, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys)" {assume ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \<and> (\<exists>ys. (m, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys)" then obtain ys' where zs:"(m, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys') \<in> cptn_mod_nest_call \<and> zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys'" by auto then have ?thesis using a0 seq_and_if_not_eq(12)[of Q] a0' ass last_length map_lift_catch_some_eq using LanguageCon.com.distinct(19) by blast }note l = this {assume ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \<and> snd (last ((P, s) # xs')) = Normal ns' \<and> s = Normal ns'' \<and> (\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)" then obtain ys' where zs:"(m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys') \<in> cptn_mod_nest_call \<and> zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys'" by auto then have zs_while: "fst (zs!(length (map (lift_catch Q) xs'))) = Q" by (metis fstI nth_append_length) then have ?thesis using a0 seq_and_if_not_eq(12)[of Q] a0' ass last_length map_lift_catch_some_eq by (metis LanguageCon.com.distinct(17) LanguageCon.com.distinct(19)) } thus ?thesis using l ass by auto qed lemma div_seq_nest: assumes cptn_m:"(n,\<Gamma>,list) \<in> cptn_mod_nest_call" shows "(\<forall>s P Q zs. list=(Seq P Q, s)#zs \<longrightarrow> (\<exists>xs s' s''. (n,\<Gamma>,(P, s)#xs) \<in> cptn_mod_nest_call \<and> seq_cond_nest zs Q xs P s s'' s' \<Gamma> n)) " unfolding seq_cond_nest_def using cptn_m proof (induct rule: cptn_mod_nest_call.induct) case (CptnModNestOne \<Gamma> P s) thus ?case using cptn_mod_nest_call.CptnModNestOne by blast next case (CptnModNestSkip \<Gamma> P s t n xs) from CptnModNestSkip.hyps have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Skip, toSeq t)" by auto from CptnModNestSkip.hyps have noskip: "~(P=Skip)" using stepc_elim_cases(1) by blast have x: "\<forall>c c1 c2. redex c = Seq c1 c2 \<Longrightarrow> False" using redex_not_Seq by blast from CptnModNestSkip.hyps have in_cptn_mod: "(n,\<Gamma>, (Skip, t) # xs) \<in> cptn_mod_nest_call" by auto then show ?case using CptnModNestSkip.hyps(2) SmallStepCon.redex_not_Seq by blast next case (CptnModNestThrow \<Gamma> P s t xs) from CptnModNestThrow.hyps have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Throw, toSeq t)" by auto moreover from CptnModNestThrow.hyps have no_seq: "\<forall>p1 p2. \<not>(P=Seq p1 p2)" using CptnModNestThrow.hyps(2) redex_not_Seq by auto ultimately show ?case by auto next case (CptnModNestCondT \<Gamma> P0 s ys b P1) thus ?case by auto next case (CptnModNestCondF \<Gamma> P0 s ys b P1) thus ?case by auto next case (CptnModNestSeq1 n \<Gamma> P0 s xs zs P1) thus ?case by blast next case (CptnModNestSeq2 n \<Gamma> P0 s xs P1 ys zs) from CptnModNestSeq2.hyps(3) last_length have last:"fst (((P0, s) # xs) ! length xs) = Skip" by (simp add: last_length) have P0cptn:"(n,\<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call" by fact from CptnModNestSeq2.hyps(4) have P1cptn:"(n,\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call" by (simp add: last_length) then have "zs = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys" by (simp add:CptnModNestSeq2.hyps) show ?case by (metis CptnModNestSeq2.hyps(3) CptnModNestSeq2.hyps(4) CptnModNestSeq2.hyps(6) LanguageCon.com.inject(3) P0cptn fst_conv last_length list.sel(3) nth_Cons_0 snd_conv) next case (CptnModNestSeq3 n \<Gamma> P0 s xs s' ys zs P1) from CptnModNestSeq3.hyps(3) have last:"fst (((P0, Normal s) # xs) ! length xs) = Throw" by (simp add: last_length) have P0cptn:"(n,\<Gamma>, (P0, Normal s) # xs) \<in> cptn_mod_nest_call" by fact from CptnModNestSeq3.hyps(4) have lastnormal:"snd (last ((P0, Normal s) # xs)) = Normal s'" by (simp add: last_length) then have "zs = map (lift P1) xs @ ((Throw, Normal s')#ys)" by (simp add:CptnModNestSeq3.hyps) show ?case by (metis CptnModNestSeq3.hyps(3) CptnModNestSeq3.hyps(5) CptnModNestSeq3.hyps(7) LanguageCon.com.inject(3) P0cptn fst_conv last_length lastnormal list.inject snd_conv) next case (CptnModNestEnv \<Gamma> P s t n zs) then have step:"(n,\<Gamma>, (P, t) # zs) \<in> cptn_mod_nest_call" by auto have step_e: "\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (P, t)" using CptnModNestEnv by auto show ?case proof (cases P) case (Seq P1 P2) then have eq_P:"(P, t) # zs = (LanguageCon.com.Seq P1 P2, t) # zs" by auto then obtain xs t' t'' where p1:"(n,\<Gamma>, (P1, t) # xs) \<in> cptn_mod_nest_call" and p2:" (zs = map (lift P2) xs \<or> fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \<and> (\<exists>ys. (n,\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<or> fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Throw \<and> snd (last ((P1, t) # xs)) = Normal t' \<and> t = Normal t'' \<and> (\<exists>ys. (n,\<Gamma>,(Throw,Normal t')#ys) \<in> cptn_mod_nest_call \<and> zs = map (lift P2) xs @ ((LanguageCon.com.Throw, Normal t')#ys))) " using CptnModNestEnv(3) by auto have all_step:"(n,\<Gamma>, (P1, s)#((P1, t) # xs)) \<in> cptn_mod_nest_call" using p1 cptn_mod_nest_call.CptnModNestEnv step_e by (metis (no_types, lifting) env_intro) show ?thesis using p2 proof assume "zs = map (lift P2) xs" have "(P, t) # zs = map (lift P2) ((P1, t) # xs)" by (simp add: `zs = map (lift P2) xs` lift_def local.Seq) thus ?thesis using all_step eq_P by fastforce next assume "fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \<and> (\<exists>ys. (n,\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<or> fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Throw \<and> snd (last ((P1, t) # xs)) = Normal t' \<and> t = Normal t'' \<and> (\<exists>ys. (n,\<Gamma>,(Throw,Normal t')#ys) \<in> cptn_mod_nest_call \<and> zs = map (lift P2) xs @ ((LanguageCon.com.Throw, Normal t')#ys))" then show ?thesis proof assume a1:"fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \<and> (\<exists>ys. (n,\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys)" from a1 obtain ys where p2_exec:"(n,\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys" by auto have f1:"fst (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs)) = LanguageCon.com.Skip" using a1 by fastforce then have p2_long_exec: "(n,\<Gamma>, (P2, snd (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs))) # ys) \<in> cptn_mod_nest_call \<and> (P, t)#zs = map (lift P2) ((P1, t) # xs) @ (P2, snd (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs))) # ys" using p2_exec by (simp add: lift_def local.Seq) thus ?thesis using a1 f1 all_step eq_P by blast next assume a1:"fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Throw \<and> snd (last ((P1, t) # xs)) = Normal t' \<and> t = Normal t'' \<and> (\<exists>ys. (n,\<Gamma>,(Throw,Normal t')#ys) \<in> cptn_mod_nest_call \<and> zs = map (lift P2) xs @ ((LanguageCon.com.Throw, Normal t')#ys))" then have last_throw: "fst (((P1, s)#(P1, t) # xs) ! length ((P1, t) #xs)) = LanguageCon.com.Throw" by fastforce from a1 have last_normal: "snd (last ((P1, s)#(P1, t) # xs)) = Normal t'" by fastforce have seq_lift: "(LanguageCon.com.Seq P1 P2, t) # map (lift P2) xs = map (lift P2) ((P1, t) # xs)" by (simp add: a1 lift_def) thus ?thesis using a1 last_throw last_normal all_step eq_P by (clarify, metis (no_types, lifting) append_Cons env_normal_s'_normal_s step_e) qed qed qed (auto) qed (force)+ lemma not_func_redex_cptn_mod_nest_n': assumes vars:"v = toSeq s" and vars1:"w = toSeq t" and a0:"\<Gamma>\<turnstile>\<^sub>c (P, v) \<rightarrow> (Q, w)" and a0':"\<forall>ns ns'. (s = Normal ns \<or> s = Abrupt ns) \<and> (t = Normal ns' \<or> t = Abrupt ns') \<longrightarrow> snd ns = snd ns'" and a1:"(n,\<Gamma>,(Q,t)#xs) \<in> cptn_mod_nest_call" and a2:"(\<forall>fn. redex P \<noteq> Call fn) \<or> (redex P = Call fn \<and> \<Gamma> fn = None) \<or> (redex P = Call fn \<and> (\<forall>sa. s\<noteq>Normal sa))" shows "(n,\<Gamma>,(P,s)#(Q,t)#xs) \<in> cptn_mod_nest_call" using a0 a1 a2 a0' vars vars1 proof (induct arbitrary: xs) case (Basicc f e s1) thus ?case using stepc.Basicc[of \<Gamma> f e s1] by (simp add: Basicc cptn_mod_nest_call.CptnModNestSkip) next case (Specc s1 t1 r) thus ?case using stepc.Specc[of s1 t1 r \<Gamma>] by (simp add: Specc cptn_mod_nest_call.CptnModNestSkip) next case (SpecStuckc s1 r) thus ?case using stepc.SpecStuckc[of s1 _ \<Gamma>] by (simp add: cptn_mod_nest_call.CptnModNestSkip stepc.SpecStuckc) next case (Guardc s1 g f c) thus ?case by (metis (mono_tags, lifting) cptn_mod_nest_call.CptnModNestGuard prod_eqI toSeq.simps(1) toSeq_not_Normal xstate.inject(1)) next case (GuardFaultc s1 g f c) thus ?case using stepc.GuardFaultc[of s1 g \<Gamma> f] by (simp add: GuardFaultc cptn_mod_nest_call.CptnModNestSkip) next case (Seqc c1 s1 c1' t1 c2) have step: "\<Gamma>\<turnstile>\<^sub>c (c1, s1) \<rightarrow> (c1', t1)" by (simp add: Seqc.hyps(1)) then have nsc1: "c1\<noteq>Skip" using stepc_elim_cases(1) by blast have assum: "(n, \<Gamma>, (Seq c1' c2, t) # xs) \<in> cptn_mod_nest_call" using Seqc.prems by blast have divseq:"(\<forall>s P Q zs. (Seq c1' c2, t) # xs=(Seq P Q, s)#zs \<longrightarrow> (\<exists>xs sv' sv''. ((n,\<Gamma>,(P, s)#xs) \<in> cptn_mod_nest_call \<and> (zs=(map (lift Q) xs) \<or> ((fst(((P, s)#xs)!length xs)=Skip \<and> (\<exists>ys. (n,\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod_nest_call \<and> zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or> ((fst(((P, s)#xs)!length xs)=Throw \<and> snd(last ((P, s)#xs)) = Normal sv' \<and> t=Normal sv''\<and> (\<exists>ys. (n,\<Gamma>,(Throw,Normal sv')#ys) \<in> cptn_mod_nest_call \<and> zs=(map (lift Q) xs)@((Throw,Normal sv')#ys)) )))) ))" using div_seq_nest [OF assum] unfolding seq_cond_nest_def by auto {fix sa P Q zsa assume ass:"(Seq c1' c2, t) # xs = (Seq P Q, sa) # zsa" then have eqs:"c1' = P \<and> c2 = Q \<and> t = sa \<and> xs = zsa" by auto then have "(\<exists>xs sv' sv''. (n,\<Gamma>, (P, sa) # xs) \<in> cptn_mod_nest_call \<and> (zsa = map (lift Q) xs \<or> fst (((P, sa) # xs) ! length xs) = Skip \<and> (\<exists>ys. (n,\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and> zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<or> ((fst(((P, sa)#xs)!length xs)=Throw \<and> snd(last ((P, sa)#xs)) = Normal sv' \<and> t=Normal sv''\<and> (\<exists>ys. (n,\<Gamma>,(Throw,Normal sv')#ys) \<in> cptn_mod_nest_call \<and> zsa=(map (lift Q) xs)@((Throw,Normal sv')#ys))))))" using ass divseq by blast } note conc=this [of c1' c2 t xs] then obtain xs' sa' sa'' where split:"(n,\<Gamma>, (c1',t) # xs') \<in> cptn_mod_nest_call \<and> (xs = map (lift c2) xs' \<or> fst (((c1', t) # xs') ! length xs') = Skip \<and> (\<exists>ys. (n,\<Gamma>, (c2, snd (((c1',t) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or> ((fst(((c1', t)#xs')!length xs')=Throw \<and> snd(last ((c1', t)#xs')) = Normal sa' \<and> t=Normal sa''\<and> (\<exists>ys. (n,\<Gamma>,(Throw,Normal sa')#ys) \<in> cptn_mod_nest_call \<and> xs=(map (lift c2) xs')@((Throw,Normal sa')#ys)) )))" by blast then have "(xs = map (lift c2) xs' \<or> fst (((c1', t) # xs') ! length xs') = Skip \<and> (\<exists>ys. (n,\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or> ((fst(((c1', t)#xs')!length xs')=Throw \<and> snd(last ((c1',t)#xs')) = Normal sa' \<and> t=Normal sa''\<and> (\<exists>ys. (n,\<Gamma>,(Throw,Normal sa')#ys) \<in> cptn_mod_nest_call \<and> xs=(map (lift c2) xs')@((Throw,Normal sa')#ys)))))" by auto thus ?case proof{ assume c1'nonf:"xs = map (lift c2) xs'" then have c1'cptn:"(n,\<Gamma>, (c1', t) # xs') \<in> cptn_mod_nest_call" using split by blast then have induct_step: "(n,\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod_nest_call" using Seqc.hyps(2) Seqc.prems(2) Seqc.prems(4) a0' by (simp add: Seqc.prems(5)) then have "(Seq c1' c2, t)#xs = map (lift c2) ((c1', t)#xs')" using c1'nonf by (simp add: lift_def) thus ?thesis using c1'nonf c1'cptn induct_step by (auto simp add: CptnModNestSeq1) next assume "fst (((c1', t) # xs') ! length xs') = Skip \<and> (\<exists>ys. (n,\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or> ((fst(((c1', t)#xs')!length xs')=Throw \<and> snd(last ((c1', t)#xs')) = Normal sa' \<and> t=Normal sa''\<and> (\<exists>ys. (n,\<Gamma>,(Throw,Normal sa')#ys) \<in> cptn_mod_nest_call \<and> xs=(map (lift c2) xs')@((Throw,Normal sa')#ys))))" thus ?thesis proof assume assth:"fst (((c1', t) # xs') ! length xs') = Skip \<and> (\<exists>ys. (n,\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys)" then obtain ys where split':"(n,\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys" by auto then have c1'cptn:"(n,\<Gamma>, (c1', t) # xs') \<in> cptn_mod_nest_call" using split by blast then have induct_step: "(n,\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod_nest_call" using Seqc.hyps(2) Seqc.prems(2) by (simp add: Seqc.prems(4) Seqc.prems(5) a0') then have seqmap:"(Seq c1 c2, s)#(Seq c1' c2, t)#xs = map (lift c2) ((c1,s)#(c1', t)#xs') @ (c2, snd (((c1', t) # xs') ! length xs')) # ys" using split' by (simp add: lift_def) then have lastc1:"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'" by (simp add: last_length) then have lastc1skip:"fst (last ((c1, s) # (c1', t) # xs')) = Skip" using assth by fastforce thus ?thesis using seqmap split' cptn_mod_nest_call.CptnModNestSeq2 induct_step lastc1 lastc1skip by (metis (no_types) Cons_lift_append ) next assume assm:"((fst(((c1', t)#xs')!length xs')=Throw \<and> snd(last ((c1', t)#xs')) = Normal sa' \<and> t=Normal sa''\<and> (\<exists>ys.(n,\<Gamma>,(Throw,Normal sa')#ys) \<in> cptn_mod_nest_call \<and> xs=(map (lift c2) xs')@((Throw,Normal sa')#ys))))" then have s'eqsa'': "t=Normal sa''" by auto then have snormal: "\<exists>ns. s=Normal ns" by (metis Seqc.prems(4) Seqc.prems(5) local.step step_not_normal_s_eq_t toSeq_not_Normal) then have c1'cptn:"(n,\<Gamma>, (c1', t) # xs') \<in> cptn_mod_nest_call" using split by blast then have induct_step: "(n,\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod_nest_call" using Seqc.hyps(2) Seqc.prems(2) by (simp add: Seqc.prems(4) Seqc.prems(5) a0') then obtain ys where seqmap:"(Seq c1' c2, t)#xs = (map (lift c2) ((c1', t)#xs'))@((Throw,Normal sa')#ys)" using assm using Cons_lift_append by blast then have lastc1:"last ((c1, s) # (c1',t) # xs') = ((c1', t) # xs') ! length xs'" by (simp add: last_length) then have lastc1skip:"fst (last ((c1, s) # (c1', t) # xs')) = Throw" using assm by fastforce then have "snd (last ((c1, s) # (c1', t) # xs')) = Normal sa'" using assm by force thus ?thesis using assm c1'cptn induct_step lastc1skip snormal seqmap s'eqsa'' by (auto simp add:cptn_mod_nest_call.CptnModNestSeq3) qed }qed next case (SeqSkipc c2 s1 xs) have c2incptn:"(n,\<Gamma>, (c2, s) # xs) \<in> cptn_mod_nest_call" using SeqSkipc.prems(1) SeqSkipc.prems(4) SeqSkipc.prems(5) a0' eq_toSeq by blast moreover have 1:"(n,\<Gamma>, [(Skip, s)]) \<in> cptn_mod_nest_call" by (simp add: cptn_mod_nest_call.CptnModNestOne) moreover have 2:"fst(last ([(Skip, s)])) = Skip" by fastforce moreover have 3:"(n,\<Gamma>,(c2, snd(last [(Skip, s)]))#xs) \<in> cptn_mod_nest_call" using c2incptn by auto moreover have "(c2,s)#xs=(map (lift c2) [])@(c2, snd(last [(Skip, s)]))#xs" by (auto simp add:lift_def) moreover have "s=t" using eq_toSeq SeqSkipc by blast ultimately show ?case by (simp add: CptnModNestSeq2) next case (SeqThrowc c2 s1 xs) have eq_st:"s=t" using eq_toSeq[OF SeqThrowc(3)] SeqThrowc by auto obtain ns where normals:"s=Normal ns" using SeqThrowc by (metis toSeq_not_Normal) have "(n,\<Gamma>, [(Throw, Normal ns)]) \<in> cptn_mod_nest_call" by (simp add: cptn_mod_nest_call.CptnModNestOne) then obtain ys where ys_nil:"ys=[]" and last:"(n, \<Gamma>, (Throw, s)#ys)\<in> cptn_mod_nest_call" using normals by auto moreover have "fst (last ((Throw, Normal ns)#ys)) = Throw" using ys_nil last by auto moreover have "snd (last ((Throw, Normal ns)#ys)) = Normal ns" using ys_nil last by auto moreover from ys_nil have "(map (lift c2) ys) = []" by auto ultimately show ?case using SeqThrowc.prems cptn_mod_nest_call.CptnModNestSeq3 eq_st normals by blast next case (CondTruec s1 b c1 c2) moreover obtain ns where normals:"s=Normal ns" by (metis (no_types) calculation(5) toSeq_not_Normal) moreover have "s=t" using calculation(5,6) eq_toSeq[OF calculation(4)] by auto ultimately show ?case by (simp add: cptn_mod_nest_call.CptnModNestCondT) next case (CondFalsec s1 b c1 c2) moreover obtain ns where normals:"s=Normal ns" by (metis (no_types) calculation(5) toSeq_not_Normal) moreover have "s=t" using calculation(5,6) eq_toSeq[OF calculation(4)] by auto ultimately show ?case by (simp add: cptn_mod_nest_call.CptnModNestCondF) next case (WhileTruec s1 b c) have sinb: "s1\<in>b" by fact obtain ns where normals:"s=Normal ns" by (metis (no_types) WhileTruec(5) toSeq_not_Normal) have eq_st:"s=t" using eq_toSeq[OF WhileTruec(4)] WhileTruec by auto have SeqcWhile: "(n,\<Gamma>, (Seq c (While b c), Normal ns) # xs) \<in> cptn_mod_nest_call" using WhileTruec.prems(1) eq_st normals by force have divseq:"(\<forall>s P Q zs. (Seq c (While b c), Normal ns) # xs=(Seq P Q, s)#zs \<longrightarrow> (\<exists>xs s'. ((n,\<Gamma>,(P, s)#xs) \<in> cptn_mod_nest_call \<and> (zs=(map (lift Q) xs) \<or> ((fst(((P, s)#xs)!length xs)=Skip \<and> (\<exists>ys. (n,\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod_nest_call \<and> zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or> ((fst(((P, s)#xs)!length xs)=Throw \<and> snd(last ((P, s)#xs)) = Normal s' \<and> (\<exists>ys. (n,\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod_nest_call \<and> zs=(map (lift Q) xs)@((Throw,Normal s')#ys)))))) ))" using div_seq_nest [OF SeqcWhile] eq_st normals unfolding seq_cond_nest_def by fast {fix sa P Q zsa assume ass:"(Seq c (While b c), Normal ns) # xs = (Seq P Q, sa) # zsa" then have eqs:"c = P \<and> (While b c) = Q \<and> Normal ns = sa \<and> xs = zsa" by auto then have "(\<exists>xs s'. (n,\<Gamma>, (P, sa) # xs) \<in> cptn_mod_nest_call \<and> (zsa = map (lift Q) xs \<or> fst (((P, sa) # xs) ! length xs) = Skip \<and> (\<exists>ys. (n,\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and> zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<or> ((fst(((P, sa)#xs)!length xs)=Throw \<and> snd(last ((P, sa)#xs)) = Normal s' \<and> (\<exists>ys. (n,\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod_nest_call \<and> zsa=(map (lift Q) xs)@((Throw,Normal s')#ys)) ))))" using ass divseq by auto } note conc=this [of c "While b c" "Normal ns" xs] then obtain xs' s' where split:"(n,\<Gamma>, (c, Normal ns) # xs') \<in> cptn_mod_nest_call \<and> (xs = map (lift (While b c)) xs' \<or> fst (((c, Normal ns) # xs') ! length xs') = Skip \<and> (\<exists>ys. (n,\<Gamma>, (While b c, snd (((c, Normal ns) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> xs = map (lift (While b c)) xs' @ (While b c, snd (((c, Normal ns) # xs') ! length xs')) # ys) \<or> fst (((c, Normal ns) # xs') ! length xs') = Throw \<and> snd (last ((c, Normal ns) # xs')) = Normal s' \<and> (\<exists>ys. (n,\<Gamma>, ((Throw, Normal s')#ys)) \<in> cptn_mod_nest_call \<and> xs = map (lift (While b c)) xs' @ ((Throw, Normal s')#ys)))" by blast then have "(xs = map (lift (While b c)) xs' \<or> fst (((c, Normal ns) # xs') ! length xs') = Skip \<and> (\<exists>ys. (n,\<Gamma>, (While b c, snd (((c, Normal ns) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> xs = map (lift (While b c)) xs' @ (While b c, snd (((c, Normal ns) # xs') ! length xs')) # ys) \<or> fst (((c, Normal ns) # xs') ! length xs') = Throw \<and> snd (last ((c, Normal ns) # xs')) = Normal s' \<and> (\<exists>ys. (n,\<Gamma>, ((Throw, Normal s')#ys)) \<in> cptn_mod_nest_call \<and> xs = map (lift (While b c)) xs' @ ((Throw, Normal s')#ys)))" .. thus ?case proof{ assume 1:"xs = map (lift (While b c)) xs'" have 3:"(n, \<Gamma>, (c, Normal ns) # xs') \<in> cptn_mod_nest_call" using split by auto then show ?thesis using "1" cptn_mod_nest_call.CptnModNestWhile1 sinb normals eq_st by (metis WhileTruec.prems(4) toSeq.simps(1) xstate.inject(1)) next assume "fst (((c, Normal ns) # xs') ! length xs') = Skip \<and> (\<exists>ys. (n,\<Gamma>, (While b c, snd (((c, Normal ns) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> xs = map (lift (While b c)) xs' @ (While b c, snd (((c, Normal ns) # xs') ! length xs')) # ys) \<or> fst (((c, Normal ns) # xs') ! length xs') = Throw \<and> snd (last ((c, Normal ns) # xs')) = Normal s' \<and> (\<exists>ys. (n,\<Gamma>, ((Throw, Normal s')#ys)) \<in> cptn_mod_nest_call \<and> xs = map (lift (While b c)) xs' @ ((Throw, Normal s')#ys))" thus ?case proof assume asm:"fst (((c, Normal ns) # xs') ! length xs') = Skip \<and> (\<exists>ys. (n,\<Gamma>, (While b c, snd (((c, Normal ns) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> xs = map (lift (While b c)) xs' @ (While b c, snd (((c, Normal ns) # xs') ! length xs')) # ys)" then obtain ys where asm':"(n,\<Gamma>, (While b c, snd (last ((c, Normal ns) # xs'))) # ys) \<in> cptn_mod_nest_call \<and> xs = map (lift (While b c)) xs' @ (While b c, snd (last ((c, Normal ns) # xs'))) # ys" by (auto simp add: last_length) moreover have 3:"(n,\<Gamma>, (c, Normal ns) # xs') \<in> cptn_mod_nest_call" using split by auto moreover from asm have "fst (last ((c, Normal ns) # xs')) = Skip" by (simp add: last_length) ultimately show ?case using sinb normals eq_st WhileTruec.prems(4) by (auto simp add:CptnModNestWhile2) next assume asm:" fst (((c, Normal ns) # xs') ! length xs') = Throw \<and> snd (last ((c, Normal ns) # xs')) = Normal s' \<and> (\<exists>ys. (n,\<Gamma>, ((Throw, Normal s')#ys)) \<in> cptn_mod_nest_call \<and> xs = map (lift (While b c)) xs' @ ((Throw, Normal s')#ys))" moreover have 3:"(n,\<Gamma>, (c, Normal ns) # xs') \<in> cptn_mod_nest_call" using split by auto moreover from asm have "fst (last ((c, Normal ns) # xs')) = Throw" by (simp add: last_length) ultimately show ?case using sinb normals eq_st WhileTruec.prems(4) by (auto simp add:CptnModNestWhile3) qed }qed next case (WhileFalsec s1 b c) thus ?case using stepc.WhileFalsec[of s1 b \<Gamma> c] by (simp add: cptn_mod_nest_call.CptnModNestSkip) next case (Awaitc s1 b \<Gamma>a c t1) thus ?case using stepc.Awaitc[of s1 b \<Gamma>a \<Gamma>] by (simp add: cptn_mod_nest_call.CptnModNestSkip) next case (AwaitAbruptc s1 b \<Gamma>a c t1 ta) thus ?case using stepc.AwaitAbruptc[of s1 b \<Gamma>a \<Gamma> c t1 ta] by (simp add: cptn_mod_nest_call.CptnModNestThrow) next case (Callc p bdy s1) moreover have eq_st:"s=t" using eq_toSeq[OF Callc(5)] Callc by auto moreover obtain ns where normals:"s=Normal ns" by (metis (no_types) Callc(6) toSeq_not_Normal) ultimately show ?case by (metis LanguageCon.com.inject(6) SmallStepCon.redex.simps(7) option.distinct(1)) next case (CallUndefinedc p s1) then have seq:"\<Gamma>\<turnstile>\<^sub>c( (LanguageCon.com.Call p),toSeq s) \<rightarrow> (Skip,toSeq t)" using stepc.CallUndefinedc[of \<Gamma> p s1] by auto thus ?case using CallUndefinedc CptnModNestSkip[OF seq _ _ _ CallUndefinedc(2)] by force next case (DynComc c s1) moreover have eq_st:"s=t" using calculation(4) calculation(5) eq_toSeq[OF calculation(3)] by force moreover obtain ns where normals:"s=Normal ns" by (metis calculation(4) toSeq_not_Normal) moreover have "(n, \<Gamma>, (LanguageCon.com.DynCom c, Normal ns) # (c (fst ns), Normal ns) # xs) \<in> cptn_mod_nest_call" using DynComc.prems(1) DynComc.prems(4) cptn_mod_nest_call.CptnModNestDynCom eq_st normals by fastforce then show ?case using DynComc.prems(4) eq_st normals by fastforce next case (Catchc c1 s1 c1' t1 c2) have step: "\<Gamma>\<turnstile>\<^sub>c (c1, s1) \<rightarrow> (c1', t1)" by (simp add: Catchc.hyps(1)) then have nsc1: "c1\<noteq>Skip" using stepc_elim_cases(1) by blast have assum: "(n,\<Gamma>, (Catch c1' c2, t) # xs) \<in> cptn_mod_nest_call" using Catchc.prems by blast have divcatch:"(\<forall>s P Q zs. (Catch c1' c2, t) # xs=(Catch P Q, s)#zs \<longrightarrow> (\<exists>xs s' s''. ((n,\<Gamma>,(P, s)#xs) \<in> cptn_mod_nest_call \<and> (zs=(map (lift_catch Q) xs) \<or> ((fst(((P, s)#xs)!length xs)=Throw \<and> snd(last ((P, s)#xs)) = Normal s' \<and> s=Normal s''\<and> (\<exists>ys. (n,\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod_nest_call \<and> zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or> ((fst(((P, s)#xs)!length xs)=Skip \<and> (\<exists>ys. (n,\<Gamma>,(Skip,snd(last ((P, s)#xs)))#ys) \<in> cptn_mod_nest_call \<and> zs=(map (lift_catch Q) xs)@((Skip,snd(last ((P, s)#xs)))#ys)) )))) ))" using div_catch_nest [OF assum] by (auto simp add: catch_cond_nest_def) {fix sa P Q zsa assume ass:"(Catch c1' c2,t) # xs = (Catch P Q, sa) # zsa" then have eqs:"c1' = P \<and> c2 = Q \<and> t = sa \<and> xs = zsa" by auto then have "(\<exists>xs sv' sv''. ((n, \<Gamma>,(P, sa)#xs) \<in> cptn_mod_nest_call \<and> (zsa=(map (lift_catch Q) xs) \<or> ((fst(((P, sa)#xs)!length xs)=Throw \<and> snd(last ((P, sa)#xs)) = Normal sv' \<and> t=Normal sv''\<and> (\<exists>ys. (n,\<Gamma>,(Q, snd(((P, sa)#xs)!length xs))#ys) \<in> cptn_mod_nest_call \<and> zsa=(map (lift_catch Q) xs)@((Q, snd(((P, sa)#xs)!length xs))#ys)))) \<or> ((fst(((P, sa)#xs)!length xs)=Skip \<and> (\<exists>ys. (n,\<Gamma>,(Skip,snd(last ((P, sa)#xs)))#ys) \<in> cptn_mod_nest_call \<and> zsa=(map (lift_catch Q) xs)@((Skip,snd(last ((P, sa)#xs)))#ys)))))) )" using ass divcatch by blast } note conc=this [of c1' c2 t xs] then obtain xs' sa' sa'' where split: "(n,\<Gamma>, (c1', t) # xs') \<in> cptn_mod_nest_call \<and> (xs = map (lift_catch c2) xs' \<or> fst (((c1', t) # xs') ! length xs') = Throw \<and> snd (last ((c1', t) # xs')) = Normal sa' \<and> t = Normal sa'' \<and> (\<exists>ys. (n,\<Gamma>, (c2, snd (((c1',t) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> xs = map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or> fst (((c1', t) # xs') ! length xs') = Skip \<and> (\<exists>ys. (n,\<Gamma>,(Skip,snd(last ((c1', t)#xs')))#ys) \<in> cptn_mod_nest_call \<and> xs=(map (lift_catch c2) xs')@((Skip,snd(last ((c1', t)#xs')))#ys)))" by blast then have "(xs = map (lift_catch c2) xs' \<or> fst (((c1', t) # xs') ! length xs') = Throw \<and> snd (last ((c1', t) # xs')) = Normal sa' \<and> t = Normal sa'' \<and> (\<exists>ys. (n,\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> xs = map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or> fst (((c1', t) # xs') ! length xs') = Skip \<and> (\<exists>ys. (n,\<Gamma>,(Skip,snd(last ((c1', t)#xs')))#ys) \<in> cptn_mod_nest_call \<and> xs=(map (lift_catch c2) xs')@((Skip,snd(last ((c1', t)#xs')))#ys)))" by auto thus ?case proof{ assume c1'nonf:"xs = map (lift_catch c2) xs'" then have c1'cptn:"(n,\<Gamma>, (c1', t) # xs') \<in> cptn_mod_nest_call" using split by blast then have induct_step: "(n, \<Gamma>, (c1, s) # (c1',t)#xs') \<in> cptn_mod_nest_call" using Catchc.hyps(2) Catchc.prems(2) by (simp add: Catchc.prems(4) Catchc.prems(5) a0') then have "(Catch c1' c2, t)#xs = map (lift_catch c2) ((c1', t)#xs')" using c1'nonf by (simp add: CptnModCatch1 lift_catch_def) thus ?thesis using c1'nonf c1'cptn induct_step by (auto simp add: CptnModNestCatch1) next assume "fst (((c1', t) # xs') ! length xs') = Throw \<and> snd (last ((c1', t) # xs')) = Normal sa' \<and>t = Normal sa'' \<and> (\<exists>ys. (n,\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> xs =map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or> fst (((c1', t) # xs') ! length xs') = Skip \<and> (\<exists>ys. (n,\<Gamma>,(Skip,snd(last ((c1', t)#xs')))#ys) \<in> cptn_mod_nest_call \<and> xs=(map (lift_catch c2) xs')@((Skip,snd(last ((c1', t)#xs')))#ys))" thus ?thesis proof assume assth: "fst (((c1', t) # xs') ! length xs') = Throw \<and> snd (last ((c1', t) # xs')) = Normal sa' \<and> t = Normal sa'' \<and> (\<exists>ys. (n,\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> xs =map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys)" then have s'eqsa'': "t=Normal sa''" by auto then have snormal: "\<exists>ns. s=Normal ns" using Catchc.prems(4) Catchc.prems(5) a0' c_step local.step step_ce_notNormal by blast then obtain ys where split':"(n,\<Gamma>, (c2, snd (((c1',t) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and> xs =map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys" using assth by auto then have c1'cptn:"(n,\<Gamma>, (c1', t) # xs') \<in> cptn_mod_nest_call" using split by blast then have induct_step: "(n,\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod_nest_call" using Catchc.hyps(2) Catchc.prems(2) SmallStepCon.redex.simps(11) by (simp add: Catchc.prems(4) Catchc.prems(5) a0') then have seqmap:"(Catch c1 c2, s)#(Catch c1' c2, t)#xs = map (lift_catch c2) ((c1,s)#(c1', t)#xs') @ (c2, snd (((c1', t) # xs') ! length xs')) # ys" using split' by (simp add: CptnModCatch3 lift_catch_def) then have lastc1:"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'" by (simp add: last_length) then have lastc1skip:"fst (last ((c1, s) # (c1', t) # xs')) = Throw" using assth by fastforce then have "snd (last ((c1, s) # (c1', t) # xs')) = Normal sa'" using assth by force thus ?thesis using snormal seqmap s'eqsa'' split' cptn_mod_nest_call.CptnModNestCatch3 induct_step lastc1 lastc1skip using Cons_lift_catch_append by (metis) next assume assm:" fst (((c1', t) # xs') ! length xs') = Skip \<and> (\<exists>ys. (n,\<Gamma>,(Skip,snd(last ((c1', t)#xs')))#ys) \<in> cptn_mod_nest_call \<and> xs=(map (lift_catch c2) xs')@((Skip,snd(last ((c1', t)#xs')))#ys))" then have c1'cptn:"(n,\<Gamma>, (c1', t) # xs') \<in> cptn_mod_nest_call" using split by blast then have induct_step: "(n,\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod_nest_call" using Catchc.hyps(2) Catchc.prems(2) SmallStepCon.redex.simps(11) by (simp add: Catchc.prems(4) Catchc.prems(5) a0') then have "map (lift_catch c2) ((c1', t) # xs') = (Catch c1' c2, t) # map (lift_catch c2) xs'" by (auto simp add: lift_catch_def) then obtain ys where seqmap:"(Catch c1' c2, t)#xs = (map (lift_catch c2) ((c1', t)#xs'))@((Skip,snd(last ((c1', t)#xs')))#ys)" using assm by fastforce then have lastc1:"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'" by (simp add: last_length) then have lastc1skip:"fst (last ((c1, s) # (c1', t) # xs')) = Skip" using assm by fastforce then have "snd (last ((c1, s) # (c1', t) # xs')) = snd (last ((c1', t) # xs'))" using assm by force thus ?thesis using assm c1'cptn induct_step lastc1skip seqmap by (auto simp add:cptn_mod_nest_call.CptnModNestCatch2) qed }qed next case (CatchThrowc c2 s1) then obtain ns where ns:"s = Normal ns" by (metis toSeq_not_Normal) then have eq_st: "s=t" using eq_toSeq[OF CatchThrowc(3)] CatchThrowc(4,5) by auto have c2incptn:"(n,\<Gamma>, (c2, Normal ns) # xs) \<in> cptn_mod_nest_call" using CatchThrowc.prems(1) eq_st ns by fastforce have 1:"(n,\<Gamma>, [(Throw, Normal ns)]) \<in> cptn_mod_nest_call" by (simp add: cptn_mod_nest_call.CptnModNestOne) have 2:"fst(last ([(Throw, Normal ns)])) = Throw" by fastforce have 3:"(n,\<Gamma>,(c2, snd(last [(Throw, Normal ns)]))#xs) \<in> cptn_mod_nest_call" using c2incptn by auto moreover have "(c2,Normal ns)#xs= (map (lift c2) [])@(c2, snd(last [(Throw, Normal ns)]))#xs" by (auto simp add:lift_def) ultimately show ?case using eq_st ns CptnModNestCatch3[OF 1 2] by fastforce next case (CatchSkipc c2 s1) have "(n,\<Gamma>, [(Skip, s)]) \<in> cptn_mod_nest_call" by (simp add: cptn_mod_nest_call.CptnModNestOne) then obtain ys where ys_nil:"ys=[]" and last:"(n,\<Gamma>, (Skip, s)#ys)\<in> cptn_mod_nest_call" by auto moreover have "fst (last ((Skip, s)#ys)) = Skip" using ys_nil last by auto moreover have "snd (last ((Skip, s)#ys)) = s" using ys_nil last by auto moreover from ys_nil have "(map (lift_catch c2) ys) = []" by auto moreover have "s=t" using CatchSkipc.prems(4) CatchSkipc.prems(5) a0' eq_toSeq by blast ultimately show ?case using CatchSkipc.prems by simp (simp add: cptn_mod_nest_call.CptnModNestCatch2 ys_nil) next case (FaultPropc c f) moreover have "s=t" using calculation(6) calculation(7) eq_toSeq[OF a0'] by force moreover have "s=Fault f" using calculation(7) calculation(8) eq_toSeq by force ultimately show ?case using stepc.FaultPropc[of c \<Gamma> f, OF FaultPropc(1,2)] by (metis cptn_mod_nest_call.CptnModNestSkip xstate.distinct(3)) next case (AbruptPropc c f) thus ?case by (metis cptn_mod_nest_call.CptnModNestSkip stepc.AbruptPropc toSeq.simps(1) xstate.distinct(1)) next case (StuckPropc c) thus ?case by (metis (no_types, lifting) cptn_mod_nest_call.CptnModNestSkip stepc.StuckPropc toSeq_not_stuck xstate.distinct(5)) qed lemma not_func_redex_cptn_mod_nest_n_env: assumes a0:"\<Gamma>\<turnstile>\<^sub>c (P,s) \<rightarrow>\<^sub>e (P, t)" and a1:"(n,\<Gamma>,(P,t)#xs) \<in> cptn_mod_nest_call" shows "(n,\<Gamma>,(P,s)#(P,t)#xs) \<in> cptn_mod_nest_call" by (simp add: a0 a1 cptn_mod_nest_call.CptnModNestEnv) lemma cptn_mod_nest_cptn_mod:"(n,\<Gamma>,cfs) \<in> cptn_mod_nest_call \<Longrightarrow> (\<Gamma>,cfs)\<in> cptn_mod" by (induct rule:cptn_mod_nest_call.induct, (auto simp:cptn_mod.intros )+) lemma cptn_mod_cptn_mod_nest: "(\<Gamma>,cfs)\<in> cptn_mod \<Longrightarrow> \<exists>n. (n,\<Gamma>,cfs) \<in> cptn_mod_nest_call" proof (induct rule:cptn_mod.induct) case (CptnModSkip \<Gamma> P s t xs) then obtain n where cptn_nest:"(n, \<Gamma>, (Skip, t) # xs) \<in> cptn_mod_nest_call" by auto {assume asm:"\<forall>f. ((\<exists>sn. s = Normal sn) \<and> (\<Gamma> f) = Some Skip \<longrightarrow> P \<noteq> Call f )" then have ?case using CptnModNestSkip[OF CptnModSkip(1) CptnModSkip(2) CptnModSkip(3) asm cptn_nest] by auto }note t1=this {assume asm:"\<not> (\<forall>f. ((\<exists>sn. s = Normal sn) \<and> (\<Gamma> f) = Some Skip \<longrightarrow> P \<noteq> Call f))" then obtain f where asm:"((\<exists>sn. s = Normal sn) \<and> (\<Gamma> f) = Some Skip \<and> P = Call f)" by auto then obtain sn where normal_s:"s=Normal sn" by auto then have t_eq_s:"t=s" using asm cptn_nest normal_s call_f_step_not_s_eq_t_false[OF CptnModSkip(1)] eq_toSeq[OF CptnModSkip.hyps(3)] CptnModSkip.hyps(2) toSeq.simps(1) by blast then have "(Suc n, \<Gamma>,((Call f), Normal sn)#(Skip, Normal sn)#xs) \<in> cptn_mod_nest_call" using asm cptn_nest normal_s CptnModNestCall by fastforce then have ?case using asm normal_s t_eq_s by fastforce }note t2 = this then show ?case using t1 t2 by fastforce next case (CptnModThrow \<Gamma> P s t xs) then obtain n where cptn_nest:"(n, \<Gamma>, (Throw, t) # xs) \<in> cptn_mod_nest_call" by auto {assume asm:"\<forall>f. ((\<exists>sn. s = Normal sn) \<and> (\<Gamma> f) = Some Throw \<longrightarrow> P \<noteq> Call f )" then have ?case using CptnModNestThrow[OF CptnModThrow(1) CptnModThrow(2) asm CptnModThrow(3)] using cptn_nest by blast }note t1=this { assume asm:"\<not> (\<forall>f. ((\<exists>sn. s = Normal sn) \<and> (\<Gamma> f) = Some Throw \<longrightarrow> P \<noteq> Call f))" then obtain f where asm:"((\<exists>sn. s = Normal sn) \<and> (\<Gamma> f) = Some Throw \<and> P = Call f)" by auto then obtain sn where normal_s:"s=Normal sn" by auto then have t_eq_s:"t=s" using asm cptn_nest normal_s eq_toSeq[OF CptnModThrow.hyps(3)] CptnModThrow.hyps(1) call_f_step_not_s_eq_t_false[OF CptnModThrow.hyps(1)] by fastforce then have "(Suc n, \<Gamma>,((Call f), Normal sn)#(Throw, Normal sn)#xs) \<in> cptn_mod_nest_call" using asm cptn_nest normal_s CptnModNestCall by fastforce then have ?case using asm normal_s t_eq_s by fastforce }note t2 = this then show ?case using t1 t2 by fastforce next case (CptnModSeq2 \<Gamma> P0 s xs P1 ys zs) obtain n where n:"(n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call" using CptnModSeq2(2) by auto also obtain m where m:"(m, \<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call" using CptnModSeq2(5) by auto ultimately show ?case proof (cases "n\<ge>m") case True thus ?thesis using cptn_mod_nest_mono[of m \<Gamma> _ n] m n CptnModSeq2 cptn_mod_nest_call.CptnModNestSeq2 by blast next case False thus ?thesis using cptn_mod_nest_mono[of n \<Gamma> _ m] m n CptnModSeq2 cptn_mod_nest_call.CptnModNestSeq2 le_cases3 by blast qed next case (CptnModSeq3 \<Gamma> P0 s xs s' ys zs P1) obtain n where n:"(n, \<Gamma>, (P0, Normal s) # xs) \<in> cptn_mod_nest_call" using CptnModSeq3(2) by auto also obtain m where m:"(m, \<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \<in> cptn_mod_nest_call" using CptnModSeq3(6) by auto ultimately show ?case proof (cases "n\<ge>m") case True thus ?thesis using cptn_mod_nest_mono[of m \<Gamma> _ n] m n CptnModSeq3 cptn_mod_nest_call.CptnModNestSeq3 by blast next case False thus ?thesis using cptn_mod_nest_mono[of n \<Gamma> _ m] m n CptnModSeq3 cptn_mod_nest_call.CptnModNestSeq3 le_cases3 proof - have f1: "\<not> n \<le> m \<or> (m, \<Gamma>, (P0, Normal s) # xs) \<in> cptn_mod_nest_call" by (metis cptn_mod_nest_mono[of n \<Gamma> _ m] n) have "n \<le> m" using False by linarith then have "(m, \<Gamma>, (P0, Normal s) # xs) \<in> cptn_mod_nest_call" using f1 by metis then show ?thesis by (metis (no_types) CptnModSeq3(3) CptnModSeq3(4) CptnModSeq3(7) cptn_mod_nest_call.CptnModNestSeq3 m) qed qed next case (CptnModWhile2 \<Gamma> P s xs b zs ys) obtain n where n:"(n, \<Gamma>, (P, Normal s) # xs) \<in> cptn_mod_nest_call" using CptnModWhile2(2) by auto also obtain m where m:" (m, \<Gamma>, (LanguageCon.com.While b P, snd (last ((P, Normal s) # xs))) # ys) \<in> cptn_mod_nest_call" using CptnModWhile2(7) by auto ultimately show ?case proof (cases "n\<ge>m") case True thus ?thesis using cptn_mod_nest_mono[of m \<Gamma> _ n] m n CptnModWhile2 cptn_mod_nest_call.CptnModNestWhile2 by metis next case False thus ?thesis proof - have f1: "\<not> n \<le> m \<or> (m, \<Gamma>, (P, Normal s) # xs) \<in> cptn_mod_nest_call" using cptn_mod_nest_mono[of n \<Gamma> _ m] n by presburger have "n \<le> m" using False by linarith then have "(m, \<Gamma>, (P, Normal s) # xs) \<in> cptn_mod_nest_call" using f1 by metis then show ?thesis by (metis (no_types) CptnModWhile2(3) CptnModWhile2(4) CptnModWhile2(5) cptn_mod_nest_call.CptnModNestWhile2 m) qed qed next case (CptnModWhile3 \<Gamma> P s xs b s' ys zs) obtain n where n:"(n, \<Gamma>, (P, Normal s) # xs) \<in> cptn_mod_nest_call" using CptnModWhile3(2) by auto also obtain m where m:" (m, \<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \<in> cptn_mod_nest_call" using CptnModWhile3(7) by auto ultimately show ?case proof (cases "n\<ge>m") case True thus ?thesis proof - have "(n, \<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \<in> cptn_mod_nest_call" using True cptn_mod_nest_mono[of m \<Gamma> _ n] m by presburger then show ?thesis by (metis (no_types) CptnModWhile3.hyps(3) CptnModWhile3.hyps(4) CptnModWhile3.hyps(5) CptnModWhile3.hyps(8) cptn_mod_nest_call.CptnModNestWhile3 n) qed next case False thus ?thesis using m n cptn_mod_nest_call.CptnModNestWhile3 cptn_mod_nest_mono[of n \<Gamma> _ m] by (metis CptnModWhile3.hyps(3) CptnModWhile3.hyps(4) CptnModWhile3.hyps(5) CptnModWhile3.hyps(8) le_cases) qed next case (CptnModCatch2 \<Gamma> P0 s xs ys zs P1) obtain n where n:"(n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call" using CptnModCatch2(2) by auto also obtain m where m:"(m, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call" using CptnModCatch2(5) by auto ultimately show ?case proof (cases "n\<ge>m") case True thus ?thesis using cptn_mod_nest_mono[of m \<Gamma> _ n] m n CptnModCatch2 cptn_mod_nest_call.CptnModNestCatch2 by blast next case False thus ?thesis using cptn_mod_nest_mono[of n \<Gamma> _ m] m n CptnModCatch2 cptn_mod_nest_call.CptnModNestCatch2 le_cases3 by blast qed next case (CptnModCatch3 \<Gamma> P0 s xs s' ys zs P1) obtain n where n:"(n, \<Gamma>, (P0, Normal s) # xs) \<in> cptn_mod_nest_call" using CptnModCatch3(2) by auto also obtain m where m:"(m, \<Gamma>, (ys, snd (last ((P0, Normal s) # xs))) # zs) \<in> cptn_mod_nest_call" using CptnModCatch3(6) by auto ultimately show ?case proof (cases "n\<ge>m") case True thus ?thesis using cptn_mod_nest_mono[of m \<Gamma> _ n] m n CptnModCatch3 cptn_mod_nest_call.CptnModNestCatch3 by blast next case False thus ?thesis using cptn_mod_nest_mono[of n \<Gamma> _ m] m n CptnModCatch3 cptn_mod_nest_call.CptnModNestCatch3 le_cases3 proof - have f1: "\<not> n \<le> m \<or> (m, \<Gamma>, (P0, Normal s) # xs) \<in> cptn_mod_nest_call" using \<open>\<And>cfs. \<lbrakk>(n, \<Gamma>, cfs) \<in> cptn_mod_nest_call; n \<le> m\<rbrakk> \<Longrightarrow> (m, \<Gamma>, cfs) \<in> cptn_mod_nest_call\<close> n by presburger have "n \<le> m" using False by auto then have "(m, \<Gamma>, (P0, Normal s) # xs) \<in> cptn_mod_nest_call" using f1 by meson then show ?thesis by (metis (no_types) \<open>P1 = map (lift_catch ys) xs @ (ys, snd (last ((P0, Normal s) # xs))) # zs\<close> \<open>fst (last ((P0, Normal s) # xs)) = LanguageCon.com.Throw\<close> \<open>snd (last ((P0, Normal s) # xs)) = Normal s'\<close> cptn_mod_nest_call.CptnModNestCatch3 m) qed qed qed(fastforce intro: cptn_mod_nest_call.intros)+ lemma cptn_mod_same_n: assumes a0:"(\<Gamma>,cfs)\<in> cptn_mod" shows "\<exists>n. (n,\<Gamma>,cfs) \<in> cptn_mod_nest_call" proof - show ?thesis using cptn_mod_cptn_mod_nest by (metis a0 ) qed lemma cptn_mod_same_n1: assumes a0:"(\<Gamma>,cfs)\<in> cptn_mod" and a1:"(\<Gamma>,cfs1)\<in> cptn_mod" shows "\<exists>n. (n,\<Gamma>,cfs) \<in> cptn_mod_nest_call \<and> (n,\<Gamma>,cfs1) \<in> cptn_mod_nest_call" proof - show ?thesis using cptn_mod_nest_mono cptn_mod_cptn_mod_nest by (metis a0 a1 cptn_mod_nest_mono2 leI) qed lemma cptn_mod_eq_cptn_mod_nest: "(\<Gamma>,cfs)\<in> cptn_mod \<longleftrightarrow> (\<exists>n. (n,\<Gamma>,cfs) \<in> cptn_mod_nest_call)" using cptn_mod_cptn_mod_nest cptn_mod_nest_cptn_mod by auto lemma cptn_mod_eq_cptn_mod_nest': "\<exists>n. ((\<Gamma>,cfs)\<in> cptn_mod \<longleftrightarrow> (n,\<Gamma>,cfs) \<in> cptn_mod_nest_call)" using cptn_mod_eq_cptn_mod_nest by auto lemma cptn_mod_eq_cptn_mod_nest1: "(\<Gamma>,cfs)\<in> cptn_mod = (\<exists>n. (n,\<Gamma>,cfs) \<in> cptn_mod_nest_call)" using cptn_mod_cptn_mod_nest cptn_mod_nest_cptn_mod by auto lemma cptn_eq_cptn_mod_nest: "(\<Gamma>,cfs)\<in> cptn = (\<exists>n. (n,\<Gamma>,cfs) \<in> cptn_mod_nest_call)" using cptn_eq_cptn_mod_set cptn_mod_cptn_mod_nest cptn_mod_nest_cptn_mod by blast subsection \<open>computation on nested calls limit\<close> subsection \<open>Elimination theorems\<close> lemma elim_cptn_mod_nest_step_c: assumes a0:"(n,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and a1:"cfg = (P,s)#(Q,t)#cfg1" shows "\<Gamma>\<turnstile>\<^sub>c (P,toSeq s) \<rightarrow> (Q,toSeq t) \<or> \<Gamma>\<turnstile>\<^sub>c (P,s) \<rightarrow>\<^sub>e (Q,t)" proof- have "(\<Gamma>,cfg) \<in> cptn" using a0 cptn_mod_nest_cptn_mod using cptn_eq_cptn_mod_set by auto then have "\<Gamma>\<turnstile>\<^sub>c (P,s) \<rightarrow>\<^sub>c\<^sub>e (Q,t)" using a1 by (metis cptn_elim_cases(2)) thus ?thesis using step_ce_not_step_e_step_c by blast qed lemma elim_cptn_mod_nest_call_env: assumes a0:"(n,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and a1:"cfg = (P,s)#(P,t)#cfg1" and a2:"\<forall>f. \<Gamma> f = Some (LanguageCon.com.Call f) \<and> (\<exists>sn. s = Normal sn) \<and> s = t \<longrightarrow> SmallStepCon.redex P \<noteq> LanguageCon.com.Call f" shows "(n,\<Gamma>,(P,t)#cfg1) \<in> cptn_mod_nest_call" using a0 a1 a2 proof (induct arbitrary: P cfg1 s t rule:cptn_mod_nest_call.induct ) case (CptnModNestSeq1 n \<Gamma> P0 sa xs zs P1) then obtain xs' where "xs = (P0, t)#xs'" unfolding lift_def by fastforce then have step:"(n, \<Gamma>, (P0, t) # xs') \<in> cptn_mod_nest_call" using CptnModNestSeq1 by fastforce have "(P, t) = lift P1 (P0, t) \<and> cfg1 = map (lift P1) xs'" using CptnModNestSeq1.hyps(3) CptnModNestSeq1.prems(1) \<open>xs = (P0, t) # xs'\<close> by auto then have "(n, \<Gamma>, (LanguageCon.com.Seq P0 P1, t) # cfg1) \<in> cptn_mod_nest_call" by (meson cptn_mod_nest_call.CptnModNestSeq1 local.step) then show ?case using CptnModNestSeq1.prems(1) by fastforce next case (CptnModNestSeq2 n \<Gamma> P0 sa xs P1 ys zs) thus ?case proof (induct xs) case Nil thus ?case using Nil.prems(6) Nil.prems(7) by fastforce next case (Cons x xs') then have x:"x=(P0,t)" proof- have "zs=(Seq P0 P1,t)#cfg1" using Cons by fastforce thus ?thesis using Cons(7) unfolding lift_def proof - assume "zs = map (\<lambda>a. case a of (P, s) \<Rightarrow> (LanguageCon.com.Seq P P1, s)) (x # xs') @ (P1, snd (last ((P0, sa) # x # xs'))) # ys" then have "LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0 P1 \<and> snd x = t" by (simp add: \<open>zs = (LanguageCon.com.Seq P0 P1, t) # cfg1\<close> case_prod_beta) then show ?thesis by fastforce qed qed then have step:"(n, \<Gamma>, (P0, t) # xs') \<in> cptn_mod_nest_call" using Cons by force have "fst (last ((P0, t) # xs')) = LanguageCon.com.Skip" using Cons.prems(3) \<open>x = (P0, t)\<close> by force then show ?case using Cons.prems(4) Cons.prems(6) CptnModNestSeq2.prems(1) x cptn_mod_nest_call.CptnModNestSeq2 local.step by fastforce qed next case (CptnModNestSeq3 n \<Gamma> P0 sa xs s' ys zs P1) thus ?case proof (induct xs) case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force next case (Cons x xs') then have x:"x=(P0,t)" proof- have zs:"zs=(Seq P0 P1,t)#cfg1" using Cons by fastforce have "(LanguageCon.com.Seq (fst x) P1, snd x) = lift P1 x" by (simp add: lift_def prod.case_eq_if) then have "LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0 P1 \<and> snd x = t" using Cons.prems(7) zs by force then show ?thesis by fastforce qed then have step:"(n, \<Gamma>, (P0, t) # xs') \<in> cptn_mod_nest_call" using Cons by force then obtain t' where t:"t=Normal t'" using Normal_Normal Cons(2) Cons(5) cptn_mod_nest_cptn_mod cptn_eq_cptn_mod_set x by (metis snd_eqD) then show ?case using x Cons(5) Cons(6) cptn_mod_nest_call.CptnModNestSeq3 step proof - have "last ((P0, Normal t') # xs') = last ((P0, Normal sa) # x # xs')" using t x by force then have h:"fst (last ((P0, Normal t') # xs')) = LanguageCon.com.Throw" using Cons.prems(3) by presburger then show ?thesis using Cons.prems(4) Cons.prems(5) Cons.prems(7) CptnModNestSeq3.prems(1) cptn_mod_nest_call.CptnModNestSeq3[OF local.step[simplified t]] t x by fastforce qed qed next case (CptnModNestCatch1 n \<Gamma> P0 s xs zs P1) then obtain xs' where "xs = (P0, t)#xs'" unfolding lift_catch_def by fastforce then have step:"(n, \<Gamma>, (P0, t) # xs') \<in> cptn_mod_nest_call" using CptnModNestCatch1 by fastforce have "(P, t) = lift_catch P1 (P0, t) \<and> cfg1 = map (lift_catch P1) xs'" using CptnModNestCatch1.hyps(3) CptnModNestCatch1.prems(1) \<open>xs = (P0, t) # xs'\<close> by auto then have "(n, \<Gamma>, (Catch P0 P1, t) # cfg1) \<in> cptn_mod_nest_call" by (meson cptn_mod_nest_call.CptnModNestCatch1 local.step) then show ?case using CptnModNestCatch1.prems(1) by fastforce next case (CptnModNestCatch2 n \<Gamma> P0 sa xs ys zs P1) thus ?case proof (induct xs) case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force next case (Cons x xs') then have x:"x=(P0,t)" proof- have zs:"zs=(Catch P0 P1,t)#cfg1" using Cons by fastforce have "(LanguageCon.com.Catch (fst x) P1, snd x) = lift_catch P1 x" by (simp add: lift_catch_def prod.case_eq_if) then have "LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0 P1 \<and> snd x = t" using Cons.prems(6) zs by fastforce then show ?thesis by fastforce qed then have step:"(n, \<Gamma>, (P0, t) # xs') \<in> cptn_mod_nest_call" using Cons by force have "fst (last ((P0, t) # xs')) = LanguageCon.com.Skip" using Cons.prems(3) x by auto then show ?case using Cons.prems(4) Cons.prems(6) CptnModNestCatch2.prems(1) cptn_mod_nest_call.CptnModNestCatch2 local.step x by fastforce qed next case (CptnModNestCatch3 n \<Gamma> P0 sa xs s' P1 ys zs) thus ?case proof (induct xs) case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force next case (Cons x xs') then have x:"x=(P0,t)" proof- have zs:"zs=(Catch P0 P1,t)#cfg1" using Cons by fastforce thus ?thesis using Cons(8) lift_catch_def unfolding lift_def proof - assume "zs = map (lift_catch P1) (x # xs') @ (P1, snd (last ((P0, Normal sa) # x # xs'))) # ys" then have "LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0 P1 \<and> snd x = t" by (simp add: case_prod_unfold lift_catch_def zs) then show ?thesis by fastforce qed qed then have step:"(n, \<Gamma>, (P0, t) # xs') \<in> cptn_mod_nest_call" using Cons by force then obtain t' where t:"t=Normal t'" using Normal_Normal Cons(2) Cons(5) cptn_mod_nest_cptn_mod cptn_eq_cptn_mod_set x by (metis snd_eqD) then show ?case using cptn_mod_nest_call.CptnModNestCatch3[OF local.step[simplified t]] Cons.prems(3) Cons.prems(4) Cons.prems(7) CptnModNestCatch3.hyps(4) CptnModNestCatch3.hyps(5) CptnModNestCatch3.prems(1) x by fastforce qed qed(fastforce+) lemma elim_cptn_mod_nest_not_env_call: assumes a0:"(n,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and a1:"cfg = (P,s)#(Q,t)#cfg1" and a2:"(\<forall>f. redex P \<noteq> Call f) \<or> SmallStepCon.redex P = LanguageCon.com.Call fn \<and> \<Gamma> fn = None \<or> (redex P = Call fn \<and> (\<forall>sa. s\<noteq>Normal sa))" shows "(n,\<Gamma>,(Q,t)#cfg1) \<in> cptn_mod_nest_call" using a0 a1 a2 proof (induct arbitrary: P Q cfg1 s t rule:cptn_mod_nest_call.induct ) case (CptnModNestSeq1 n \<Gamma> P0 s xs zs P1) then obtain P0' xs' where "xs = (P0', t)#xs'" unfolding lift_def by fastforce then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using CptnModNestSeq1 by fastforce have Q:"(Q, t) = lift P1 (P0', t) \<and> cfg1 = map (lift P1) xs'" using CptnModNestSeq1.hyps(3) CptnModNestSeq1.prems(1) \<open>xs = (P0', t) # xs'\<close> by auto also then have "(n, \<Gamma>, (LanguageCon.com.Seq P0' P1, t) # cfg1) \<in> cptn_mod_nest_call" by (meson cptn_mod_nest_call.CptnModNestSeq1 local.step) ultimately show ?case using CptnModNestSeq1.prems(1) by (simp add: Cons_lift Q) next case (CptnModNestSeq2 n \<Gamma> P0 sa xs P1 ys zs) thus ?case proof (induct xs) case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force next case (Cons x xs') then have x:"\<exists>P0'. x=(P0',t)" proof- obtain P0'' where zs: "zs=(Seq P0'' P1,t)#cfg1" using Cons(7) Cons(8) unfolding lift_def by (simp add: Cons_eq_append_conv case_prod_beta') thus ?thesis using Cons(7) unfolding lift_def proof - assume "zs = map (\<lambda>a. case a of (P, s) \<Rightarrow> (LanguageCon.com.Seq P P1, s)) (x # xs') @ (P1, snd (last ((P0, sa) # x # xs'))) # ys" then have "LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0'' P1 \<and> snd x = t" by (simp add: zs case_prod_beta) also have "sa=s" using Cons by fastforce ultimately show ?thesis by (meson eq_snd_iff) qed qed then obtain P0' where x:"x=(P0',t)" by auto then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using Cons by force have "fst (last ((P0', t) # xs')) = LanguageCon.com.Skip" using Cons.prems(3) x by force then show ?case using Cons.prems(4) Cons.prems(6) CptnModNestSeq2.prems(1) x local.step cptn_mod_nest_call.CptnModNestSeq2[of n \<Gamma> P0' t xs' P1 ys] Cons_lift_append by (metis (no_types, lifting) last_ConsR list.inject list.simps(3)) qed next case (CptnModNestSeq3 n \<Gamma> P0 sa xs s' ys zs P1) thus ?case proof (induct xs) case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force next case (Cons x xs') then have x:"\<exists>P0'. x=(P0',t)" proof- obtain P0' where zs:"zs=(Seq P0' P1,t)#cfg1" using Cons(8) Cons(9) unfolding lift_def unfolding lift_def by (simp add: Cons_eq_append_conv case_prod_beta') have "(LanguageCon.com.Seq (fst x) P1, snd x) = lift P1 x" by (simp add: lift_def prod.case_eq_if) then have "LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0' P1 \<and> snd x = t" using zs by (simp add: Cons.prems(7)) then show ?thesis by (meson eq_snd_iff) qed then obtain P0' where x:"x=(P0',t)" by auto then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" proof - have f1: "LanguageCon.com.Seq P0 P1 = P \<and> Normal sa = s" using CptnModNestSeq3.prems(1) by blast then have "SmallStepCon.redex P = SmallStepCon.redex P0" by (metis SmallStepCon.redex.simps(4)) then show ?thesis using f1 Cons.prems(2) CptnModNestSeq3.prems(2) x by presburger qed then obtain t' where t:"t=Normal t'" using Normal_Normal Cons(2) Cons(5) cptn_mod_nest_cptn_mod cptn_eq_cptn_mod_set x by (metis snd_eqD) then show ?case using x Cons(5) Cons(6) cptn_mod_nest_call.CptnModNestSeq3 step proof - have "last ((P0', Normal t') # xs') = last ((P0, Normal sa) # x # xs')" using t x by force also then have "fst (last ((P0', Normal t') # xs')) = LanguageCon.com.Throw" using Cons.prems(3) by presburger ultimately show ?thesis using Cons.prems(4) Cons.prems(5) Cons.prems(7) CptnModNestSeq3.prems(1) cptn_mod_nest_call.CptnModNestSeq3[of n \<Gamma> P0' t' xs' s' ys] local.step t x Cons_lift_append by (metis (no_types, lifting) list.sel(3)) qed qed next case (CptnModNestCatch1 n \<Gamma> P0 s xs zs P1) then obtain P0' xs' where xs:"xs = (P0', t)#xs'" unfolding lift_catch_def by fastforce then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using CptnModNestCatch1 by fastforce have Q:"(Q, t) = lift_catch P1 (P0', t) \<and> cfg1 = map (lift_catch P1) xs'" using CptnModNestCatch1.hyps(3) CptnModNestCatch1.prems(1) xs by auto then have "(n, \<Gamma>, (Catch P0' P1, t) # cfg1) \<in> cptn_mod_nest_call" by (meson cptn_mod_nest_call.CptnModNestCatch1 local.step) then show ?case using CptnModNestCatch1.prems(1) by (simp add:Cons_lift_catch Q) next case (CptnModNestCatch2 n \<Gamma> P0 sa xs ys zs P1) thus ?case proof (induct xs) case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force next case (Cons x xs') then have x:"\<exists>P0'. x=(P0',t)" proof- obtain P0' where zs:"zs=(Catch P0' P1,t)#cfg1" using Cons unfolding lift_catch_def by (simp add: case_prod_unfold) have "(LanguageCon.com.Catch (fst x) P1, snd x) = lift_catch P1 x" by (simp add: lift_catch_def prod.case_eq_if) then have "LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0' P1 \<and> snd x = t" using Cons.prems(6) zs by fastforce then show ?thesis by (meson eq_snd_iff) qed then obtain P0' where x:"x=(P0',t)" by auto then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using Cons.prems(2) CptnModNestCatch2.prems(1) CptnModNestCatch2.prems(2) x by force have skip:"fst (last ((P0', t) # xs')) = LanguageCon.com.Skip" using Cons.prems(3) x by auto show ?case proof - have "(P, s) # (Q, t) # cfg1 = (LanguageCon.com.Catch P0 P1, sa) # map (lift_catch P1) (x # xs') @ (LanguageCon.com.Skip, snd (last ((P0, sa) # x # xs'))) # ys" using CptnModNestCatch2.prems Cons.prems(6) by auto then show ?thesis using Cons_lift_catch_append Cons.prems(4) cptn_mod_nest_call.CptnModNestCatch2[OF local.step skip] last.simps list.distinct(1) x by (metis (no_types) list.sel(3) x) qed qed next case (CptnModNestCatch3 n \<Gamma> P0 sa xs s' P1 ys zs) thus ?case proof (induct xs) case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force next case (Cons x xs') then have x:"\<exists>P0'. x=(P0',t)" proof- obtain P0' where zs:"zs=(Catch P0' P1,t)#cfg1" using Cons unfolding lift_catch_def by (simp add: case_prod_unfold) thus ?thesis using Cons(8) lift_catch_def unfolding lift_def proof - assume "zs = map (lift_catch P1) (x # xs') @ (P1, snd (last ((P0, Normal sa) # x # xs'))) # ys" then have "LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0' P1 \<and> snd x = t" by (simp add: case_prod_unfold lift_catch_def zs) then show ?thesis by (meson eq_snd_iff) qed qed then obtain P0' where x:"x=(P0',t)" by auto then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using Cons using Cons.prems(2) CptnModNestCatch3.prems(1) CptnModNestCatch3.prems(2) x by force then obtain t' where t:"t=Normal t'" using Normal_Normal Cons(2) Cons(5) cptn_mod_nest_cptn_mod cptn_eq_cptn_mod_set x by (metis snd_eqD) then show ?case proof - have "last ((P0', Normal t') # xs') = last ((P0, Normal sa) # x # xs')" using t x by force also then have "fst (last ((P0', Normal t') # xs')) = LanguageCon.com.Throw" using Cons.prems(3) by presburger ultimately show ?thesis using Cons.prems(4) Cons.prems(5) Cons.prems(7) CptnModNestCatch3.prems(1) cptn_mod_nest_call.CptnModNestCatch3[of n \<Gamma> P0' t' xs' s' P1] local.step t x by (metis Cons_lift_catch_append list.sel(3)) qed qed next case (CptnModNestWhile1 n \<Gamma> P0 s' xs b zs) thus ?case using cptn_mod_nest_call.CptnModNestSeq1 list.inject by blast next case (CptnModNestWhile2 n \<Gamma> P0 s' xs b zs ys) have "(LanguageCon.com.While b P0, Normal s') = (P, s) \<and> (LanguageCon.com.Seq P0 (LanguageCon.com.While b P0), Normal s') # zs = (Q, t) # cfg1" using CptnModNestWhile2.prems by fastforce then show ?case using CptnModNestWhile2.hyps(1) CptnModNestWhile2.hyps(3) CptnModNestWhile2.hyps(5) CptnModNestWhile2.hyps(6) cptn_mod_nest_call.CptnModNestSeq2 by blast next case (CptnModNestWhile3 n \<Gamma> P0 s' xs b zs) thus ?case by (metis (no_types) CptnModNestWhile3.hyps(1) CptnModNestWhile3.hyps(3) CptnModNestWhile3.hyps(5) CptnModNestWhile3.hyps(6) CptnModNestWhile3.hyps(8) CptnModNestWhile3.prems cptn_mod_nest_call.CptnModNestSeq3 list.inject) qed(fastforce+) lemma elim_cptn_mod_nest_call_n_greater_zero: assumes a0:"(n,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and a1:"cfg = (P,Normal s)#(Q,t)#cfg1 \<and> P = Call f \<and> \<Gamma> f = Some Q \<and> P\<noteq>Q" shows "n>0" using a0 a1 by (induct rule:cptn_mod_nest_call.induct, fastforce+) lemma elim_cptn_mod_nest_call_0_False: assumes a0:"(0,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and a1:"cfg = (P,Normal s)#(Q,t)#cfg1 \<and> P = Call f \<and> \<Gamma> f = Some Q \<and> P\<noteq>Q" shows "PP" using a0 a1 elim_cptn_mod_nest_call_n_greater_zero by fastforce lemma elim_cptn_mod_nest_call_n_dec1: assumes a0:"(n,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and a1:"cfg = (P,Normal s)#(Q,t)#cfg1 \<and> P = Call f \<and> \<Gamma> f = Some Q \<and> t= Normal s \<and> P\<noteq>Q" shows "(n-1,\<Gamma>,(Q,t)#cfg1) \<in> cptn_mod_nest_call" using a0 a1 by (induct rule:cptn_mod_nest_call.induct,fastforce+) lemma elim_cptn_mod_nest_call_n_dec: assumes a0:"(n,\<Gamma>,(Call f,Normal s)#(the (\<Gamma> f),Normal s)#cfg1) \<in> cptn_mod_nest_call" and a1:"\<Gamma> f = Some Q " and a2:"Call f\<noteq>the (\<Gamma> f)" shows "(n-1,\<Gamma>,(the (\<Gamma> f),Normal s)#cfg1) \<in> cptn_mod_nest_call" using elim_cptn_mod_nest_call_n_dec1[OF a0] a1 a2 by fastforce lemma elim_cptn_mod_nest_call_n: assumes a0:"(n,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and a1:"cfg = (P, s)#(Q,t)#cfg1" shows "(n,\<Gamma>,(Q,t)#cfg1) \<in> cptn_mod_nest_call" using a0 a1 proof (induct arbitrary: P Q cfg1 s t rule:cptn_mod_nest_call.induct ) case (CptnModNestCall n \<Gamma> bdy sa ys p) thus ?case using cptn_mod_nest_mono1 list.inject by blast next case (CptnModNestSeq1 n \<Gamma> P0 s xs zs P1) then obtain P0' xs' where "xs = (P0', t)#xs'" unfolding lift_def by fastforce then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using CptnModNestSeq1 by fastforce have Q:"(Q, t) = lift P1 (P0', t) \<and> cfg1 = map (lift P1) xs'" using CptnModNestSeq1.hyps(3) CptnModNestSeq1.prems(1) \<open>xs = (P0', t) # xs'\<close> by auto also then have "(n, \<Gamma>, (LanguageCon.com.Seq P0' P1, t) # cfg1) \<in> cptn_mod_nest_call" by (meson cptn_mod_nest_call.CptnModNestSeq1 local.step) ultimately show ?case using CptnModNestSeq1.prems(1) by (simp add: Cons_lift Q) next case (CptnModNestSeq2 n \<Gamma> P0 sa xs P1 ys zs) thus ?case proof (induct xs) case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force next case (Cons x xs') then have x:"\<exists>P0'. x=(P0',t)" proof- obtain P0'' where zs: "zs=(Seq P0'' P1,t)#cfg1" using Cons(7) Cons(8) unfolding lift_def by (simp add: Cons_eq_append_conv case_prod_beta') thus ?thesis using Cons(7) unfolding lift_def proof - assume "zs = map (\<lambda>a. case a of (P, s) \<Rightarrow> (LanguageCon.com.Seq P P1, s)) (x # xs') @ (P1, snd (last ((P0, sa) # x # xs'))) # ys" then have "LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0'' P1 \<and> snd x = t" by (simp add: zs case_prod_beta) also have "sa=s" using Cons by fastforce ultimately show ?thesis by (meson eq_snd_iff) qed qed then obtain P0' where x:"x=(P0',t)" by auto then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using Cons by force have "fst (last ((P0', t) # xs')) = LanguageCon.com.Skip" using Cons.prems(3) x by force then show ?case using Cons.prems(4) Cons.prems(6) CptnModNestSeq2.prems(1) x local.step cptn_mod_nest_call.CptnModNestSeq2[of n \<Gamma> P0' t xs' P1 ys] Cons_lift_append by (metis (no_types, lifting) last_ConsR list.inject list.simps(3)) qed next case (CptnModNestSeq3 n \<Gamma> P0 sa xs s' ys zs P1) thus ?case proof (induct xs) case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force next case (Cons x xs') then have x:"\<exists>P0'. x=(P0',t)" proof- obtain P0' where zs:"zs=(Seq P0' P1,t)#cfg1" using Cons(8) Cons(9) unfolding lift_def unfolding lift_def by (simp add: Cons_eq_append_conv case_prod_beta') have "(LanguageCon.com.Seq (fst x) P1, snd x) = lift P1 x" by (simp add: lift_def prod.case_eq_if) then have "LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0' P1 \<and> snd x = t" using zs by (simp add: Cons.prems(7)) then show ?thesis by (meson eq_snd_iff) qed then obtain P0' where x:"x=(P0',t)" by auto then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using Cons by fastforce then obtain t' where t:"t=Normal t'" using Normal_Normal Cons(2) Cons(5) cptn_mod_nest_cptn_mod cptn_eq_cptn_mod_set x by (metis snd_eqD) then show ?case using x Cons(5) Cons(6) cptn_mod_nest_call.CptnModNestSeq3 step proof - have "last ((P0', Normal t') # xs') = last ((P0, Normal sa) # x # xs')" using t x by force also then have "fst (last ((P0', Normal t') # xs')) = LanguageCon.com.Throw" using Cons.prems(3) by presburger ultimately show ?thesis using Cons.prems(4) Cons.prems(5) Cons.prems(7) CptnModNestSeq3.prems(1) cptn_mod_nest_call.CptnModNestSeq3[of n \<Gamma> P0' t' xs' s' ys] local.step t x Cons_lift_append by (metis (no_types, lifting) list.sel(3)) qed qed next case (CptnModNestCatch1 n \<Gamma> P0 s xs zs P1) then obtain P0' xs' where xs:"xs = (P0', t)#xs'" unfolding lift_catch_def by fastforce then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using CptnModNestCatch1 by fastforce have Q:"(Q, t) = lift_catch P1 (P0', t) \<and> cfg1 = map (lift_catch P1) xs'" using CptnModNestCatch1.hyps(3) CptnModNestCatch1.prems(1) xs by auto then have "(n, \<Gamma>, (Catch P0' P1, t) # cfg1) \<in> cptn_mod_nest_call" by (meson cptn_mod_nest_call.CptnModNestCatch1 local.step) then show ?case using CptnModNestCatch1.prems(1) by (simp add:Cons_lift_catch Q) next case (CptnModNestCatch2 n \<Gamma> P0 sa xs ys zs P1) thus ?case proof (induct xs) case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force next case (Cons x xs') then have x:"\<exists>P0'. x=(P0',t)" proof- obtain P0' where zs:"zs=(Catch P0' P1,t)#cfg1" using Cons unfolding lift_catch_def by (simp add: case_prod_unfold) have "(LanguageCon.com.Catch (fst x) P1, snd x) = lift_catch P1 x" by (simp add: lift_catch_def prod.case_eq_if) then have "LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0' P1 \<and> snd x = t" using Cons.prems(6) zs by fastforce then show ?thesis by (meson eq_snd_iff) qed then obtain P0' where x:"x=(P0',t)" by auto then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using Cons by fastforce have skip:"fst (last ((P0', t) # xs')) = LanguageCon.com.Skip" using Cons.prems(3) x by auto show ?case proof - have "(P, s) # (Q, t) # cfg1 = (LanguageCon.com.Catch P0 P1, sa) # map (lift_catch P1) (x # xs') @ (LanguageCon.com.Skip, snd (last ((P0, sa) # x # xs'))) # ys" using CptnModNestCatch2.prems Cons.prems(6) by auto then show ?thesis using Cons_lift_catch_append Cons.prems(4) cptn_mod_nest_call.CptnModNestCatch2[OF local.step skip] last.simps list.distinct(1) x by (metis (no_types) list.sel(3) x) qed qed next case (CptnModNestCatch3 n \<Gamma> P0 sa xs s' P1 ys zs) thus ?case proof (induct xs) case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force next case (Cons x xs') then have x:"\<exists>P0'. x=(P0',t)" proof- obtain P0' where zs:"zs=(Catch P0' P1,t)#cfg1" using Cons unfolding lift_catch_def by (simp add: case_prod_unfold) thus ?thesis using Cons(8) lift_catch_def unfolding lift_def proof - assume "zs = map (lift_catch P1) (x # xs') @ (P1, snd (last ((P0, Normal sa) # x # xs'))) # ys" then have "LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0' P1 \<and> snd x = t" by (simp add: case_prod_unfold lift_catch_def zs) then show ?thesis by (meson eq_snd_iff) qed qed then obtain P0' where x:"x=(P0',t)" by auto then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using Cons by fastforce then obtain t' where t:"t=Normal t'" using Normal_Normal Cons(2) Cons(5) cptn_mod_nest_cptn_mod cptn_eq_cptn_mod_set x by (metis snd_eqD) then show ?case proof - have "last ((P0', Normal t') # xs') = last ((P0, Normal sa) # x # xs')" using t x by force also then have "fst (last ((P0', Normal t') # xs')) = LanguageCon.com.Throw" using Cons.prems(3) by presburger ultimately show ?thesis using Cons.prems(4) Cons.prems(5) Cons.prems(7) CptnModNestCatch3.prems(1) cptn_mod_nest_call.CptnModNestCatch3[of n \<Gamma> P0' t' xs' s' P1] local.step t x by (metis Cons_lift_catch_append list.sel(3)) qed qed next case (CptnModNestWhile1 n \<Gamma> P0 s' xs b zs) thus ?case using cptn_mod_nest_call.CptnModNestSeq1 list.inject by blast next case (CptnModNestWhile2 n \<Gamma> P0 s' xs b zs ys) have "(LanguageCon.com.While b P0, Normal s') = (P, s) \<and> (LanguageCon.com.Seq P0 (LanguageCon.com.While b P0), Normal s') # zs = (Q, t) # cfg1" using CptnModNestWhile2.prems by fastforce then show ?case using CptnModNestWhile2.hyps(1) CptnModNestWhile2.hyps(3) CptnModNestWhile2.hyps(5) CptnModNestWhile2.hyps(6) cptn_mod_nest_call.CptnModNestSeq2 by blast next case (CptnModNestWhile3 n \<Gamma> P0 s' xs b zs) thus ?case by (metis (no_types) CptnModNestWhile3.hyps(1) CptnModNestWhile3.hyps(3) CptnModNestWhile3.hyps(5) CptnModNestWhile3.hyps(6) CptnModNestWhile3.hyps(8) CptnModNestWhile3.prems cptn_mod_nest_call.CptnModNestSeq3 list.inject) qed (fastforce+) lemma dropcptn_is_cptn1 [rule_format,elim!]: "\<forall>j<length c. (n,\<Gamma>,c) \<in> cptn_mod_nest_call \<longrightarrow> (n,\<Gamma>, drop j c) \<in> cptn_mod_nest_call" proof - {fix j assume "j<length c \<and> (n,\<Gamma>,c) \<in> cptn_mod_nest_call" then have "(n,\<Gamma>, drop j c) \<in> cptn_mod_nest_call" proof(induction j arbitrary: c) case 0 then show ?case by auto next case (Suc j) then obtain a b c' where "c=a#b#c'" by (metis (no_types, hide_lams) Suc_less_eq length_Cons list.exhaust list.size(3) not_less0) then also have "j<length (b#c')" using Suc by auto ultimately moreover have "(n, \<Gamma>, drop j (b # c')) \<in> cptn_mod_nest_call" using elim_cptn_mod_nest_call_n[of n \<Gamma> c] Suc by (metis surj_pair) ultimately show ?case by auto qed } thus ?thesis by auto qed definition min_call where "min_call n \<Gamma> cfs \<equiv> (n,\<Gamma>,cfs) \<in> cptn_mod_nest_call \<and> (\<forall>m<n. \<not>((m,\<Gamma>,cfs) \<in> cptn_mod_nest_call))" lemma minimum_nest_call: "(m,\<Gamma>,cfs) \<in> cptn_mod_nest_call \<Longrightarrow> \<exists>n. min_call n \<Gamma> cfs" unfolding min_call_def proof (induct arbitrary: m rule:cptn_mod_nest_call.induct) case (CptnModNestOne) thus ?case using cptn_mod_nest_call.CptnModNestOne by blast next case (CptnModNestEnv \<Gamma> P s t n xs) then have "\<not> \<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (P, toSeq t)" using mod_env_not_component step_change_p_or_eq_s by blast then obtain min_n where min:"(min_n, \<Gamma>, (P, t) # xs) \<in> cptn_mod_nest_call \<and> (\<forall>m<min_n. (m, \<Gamma>, (P, t) # xs) \<notin> cptn_mod_nest_call)" using CptnModNestEnv by blast then have "(min_n, \<Gamma>, (P,s)#(P, t) # xs) \<in> cptn_mod_nest_call" using cptn_mod_nest_call.CptnModNestEnv CptnModNestEnv by blast also have "(\<forall>m<min_n. (m, \<Gamma>, (P, s)#(P, t) # xs) \<notin> cptn_mod_nest_call)" using elim_cptn_mod_nest_call_n min by fastforce ultimately show ?case by auto next case (CptnModNestSkip \<Gamma> P s t n xs) then obtain min_n where min:"(min_n, \<Gamma>, (LanguageCon.com.Skip, t) # xs) \<in> cptn_mod_nest_call \<and> (\<forall>m<min_n. (m, \<Gamma>, (LanguageCon.com.Skip, t) # xs) \<notin> cptn_mod_nest_call)" by auto then have "(min_n, \<Gamma>, (P,s)#(LanguageCon.com.Skip, t) # xs) \<in> cptn_mod_nest_call" using cptn_mod_nest_call.CptnModNestSkip CptnModNestSkip by blast also have "(\<forall>m<min_n. (m, \<Gamma>, (P, s)#(LanguageCon.com.Skip, t) # xs) \<notin> cptn_mod_nest_call)" using elim_cptn_mod_nest_call_n min by blast ultimately show ?case by fastforce next case (CptnModNestThrow \<Gamma> P s t n xs) thus ?case using elim_cptn_mod_nest_call_n[OF CptnModNestThrow(5)] by (metis (no_types, lifting) cptn_mod_nest_call.CptnModNestThrow elim_cptn_mod_nest_call_n) next case (CptnModNestCondT n \<Gamma> P0 s xs b P1) thus ?case by (meson cptn_mod_nest_call.CptnModNestCondT elim_cptn_mod_nest_call_n) next case (CptnModNestCondF n \<Gamma> P1 s xs b P0) thus ?case by (meson cptn_mod_nest_call.CptnModNestCondF elim_cptn_mod_nest_call_n) next case (CptnModNestSeq1 n \<Gamma> P s xs zs Q) thus ?case by (metis (no_types, lifting) Seq_P_Not_finish cptn_mod_nest_call.CptnModNestSeq1 div_seq_nest) next case (CptnModNestSeq2 n \<Gamma> P s xs Q ys zs) then obtain min_p where min_p:"(min_p, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call \<and> (\<forall>m<min_p. (m, \<Gamma>, (P, s) # xs) \<notin> cptn_mod_nest_call)" by auto from CptnModNestSeq2(5) obtain min_q where min_q:"(min_q, \<Gamma>, (Q, snd (last ((P, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and> (\<forall>m<min_q. (m, \<Gamma>, (Q, snd (last ((P, s) # xs))) # ys) \<notin> cptn_mod_nest_call)" by auto thus ?case proof(cases "min_p\<ge>min_q") case True then have "(min_p, \<Gamma>, (Q, snd (last ((P,s) # xs))) # ys) \<in> cptn_mod_nest_call" using min_q using cptn_mod_nest_mono by blast then have "(min_p, \<Gamma>, (Seq P Q, s) # zs) \<in> cptn_mod_nest_call" using conjunct1[OF min_p] cptn_mod_nest_call.CptnModNestSeq2[of min_p \<Gamma> P s xs Q ys zs] CptnModNestSeq2(6) CptnModNestSeq2(3) by blast also have "\<forall>m<min_p. (m, \<Gamma>,(Seq P Q,s) # zs) \<notin> cptn_mod_nest_call" by (metis CptnModNestSeq2.hyps(3) CptnModNestSeq2.hyps(6) Seq_P_Ends_Normal div_seq_nest min_p) ultimately show ?thesis by auto next case False then have "(min_q, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call" using min_p cptn_mod_nest_mono by force then have "(min_q, \<Gamma>, (Seq P Q, s) # zs) \<in> cptn_mod_nest_call" using conjunct1[OF min_q] cptn_mod_nest_call.CptnModNestSeq2[of min_q \<Gamma> P s xs Q ys zs] CptnModNestSeq2(6) CptnModNestSeq2(3) by blast also have "\<forall>m<min_q. (m, \<Gamma>,(Seq P Q,s) # zs) \<notin> cptn_mod_nest_call" proof - {fix m assume min_m:"m<min_q" then have "(m, \<Gamma>,(Seq P Q, s) # zs) \<notin> cptn_mod_nest_call" proof - {assume ass:"(m, \<Gamma>, (Seq P Q, s) # zs) \<in> cptn_mod_nest_call" then obtain xs' s' s'' where m_cptn:"(m, \<Gamma>, (P, s) # xs') \<in> cptn_mod_nest_call \<and> seq_cond_nest zs Q xs' P s s'' s' \<Gamma> m" using div_seq_nest[of m \<Gamma> "(LanguageCon.com.Seq P Q, s) # zs"] by fastforce then have "seq_cond_nest zs Q xs' P s s'' s' \<Gamma> m" by auto then have ?thesis using Seq_P_Ends_Normal[OF CptnModNestSeq2(6) CptnModNestSeq2(3) ass] min_m min_q by (metis last_length) } thus ?thesis by auto qed }thus ?thesis by auto qed ultimately show ?thesis by auto qed next case (CptnModNestSeq3 n \<Gamma> P s xs s' ys zs Q) then obtain min_p where min_p:"(min_p, \<Gamma>, (P, Normal s) # xs) \<in> cptn_mod_nest_call \<and> (\<forall>m<min_p. (m, \<Gamma>, (P, Normal s) # xs) \<notin> cptn_mod_nest_call)" by auto from CptnModNestSeq3(6) obtain min_q where min_q:"(min_q, \<Gamma>, (Throw, Normal s') # ys) \<in> cptn_mod_nest_call \<and> (\<forall>m<min_q. (m, \<Gamma>, (Throw, Normal s') # ys) \<notin> cptn_mod_nest_call)" by auto thus ?case proof(cases "min_p\<ge>min_q") case True then have "(min_p, \<Gamma>, (Throw, Normal s') # ys) \<in> cptn_mod_nest_call" using min_q using cptn_mod_nest_mono by blast then have "(min_p, \<Gamma>, (Seq P Q, Normal s) # zs) \<in> cptn_mod_nest_call" using conjunct1[OF min_p] cptn_mod_nest_call.CptnModNestSeq3[of min_p \<Gamma> P s xs s' ys zs Q] CptnModNestSeq3(4) CptnModNestSeq3(3) CptnModNestSeq3(7) by blast also have "\<forall>m<min_p. (m, \<Gamma>,(Seq P Q,Normal s) # zs) \<notin> cptn_mod_nest_call" by (metis CptnModNestSeq3.hyps(3) CptnModNestSeq3.hyps(4) CptnModNestSeq3.hyps(7) Seq_P_Ends_Abort div_seq_nest min_p) ultimately show ?thesis by auto next case False then have "(min_q, \<Gamma>, (P, Normal s) # xs) \<in> cptn_mod_nest_call" using min_p cptn_mod_nest_mono by force then have "(min_q, \<Gamma>, (Seq P Q, Normal s) # zs) \<in> cptn_mod_nest_call" using conjunct1[OF min_q] cptn_mod_nest_call.CptnModNestSeq3[of min_q \<Gamma> P s xs s' ys zs Q] CptnModNestSeq3(4) CptnModNestSeq3(3) CptnModNestSeq3(7) by blast also have "\<forall>m<min_q. (m, \<Gamma>,(Seq P Q,Normal s) # zs) \<notin> cptn_mod_nest_call" by (metis CptnModNestSeq3.hyps(3) CptnModNestSeq3.hyps(4) CptnModNestSeq3.hyps(7) Seq_P_Ends_Abort div_seq_nest min_q) ultimately show ?thesis by auto qed next case (CptnModNestWhile1 n \<Gamma> P s xs b zs) then obtain min_n where min:"(min_n, \<Gamma>, (P, Normal s) # xs) \<in> cptn_mod_nest_call \<and> (\<forall>m<min_n. (m, \<Gamma>, (P, Normal s) # xs) \<notin> cptn_mod_nest_call)" by auto then have "(min_n, \<Gamma>, (While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \<in> cptn_mod_nest_call" using cptn_mod_nest_call.CptnModNestWhile1[of min_n \<Gamma> P s xs b zs] CptnModNestWhile1 by meson also have "\<forall>m<min_n. (m, \<Gamma>,(While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \<notin> cptn_mod_nest_call" by (metis CptnModNestWhile1.hyps(4) Seq_P_Not_finish div_seq_nest elim_cptn_mod_nest_call_n min) ultimately show ?case by auto next case (CptnModNestWhile2 n \<Gamma> P s xs b zs ys) then obtain min_n_p where min_p:"(min_n_p, \<Gamma>, (P, Normal s) # xs) \<in> cptn_mod_nest_call \<and> (\<forall>m<min_n_p. (m, \<Gamma>, (P, Normal s) # xs) \<notin> cptn_mod_nest_call)" by auto from CptnModNestWhile2 obtain min_n_w where min_w:"(min_n_w, \<Gamma>, (LanguageCon.com.While b P, snd (last ((P, Normal s) # xs))) # ys) \<in> cptn_mod_nest_call \<and> (\<forall>m<min_n_w. (m, \<Gamma>, (LanguageCon.com.While b P, snd (last ((P, Normal s) # xs))) # ys) \<notin> cptn_mod_nest_call)" by auto thus ?case proof (cases "min_n_p\<ge>min_n_w") case True then have "(min_n_p, \<Gamma>, (LanguageCon.com.While b P, snd (last ((P, Normal s) # xs))) # ys) \<in> cptn_mod_nest_call" using min_w using cptn_mod_nest_mono by blast then have "(min_n_p, \<Gamma>, (While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \<in> cptn_mod_nest_call" using min_p cptn_mod_nest_call.CptnModNestWhile2[of min_n_p \<Gamma> P s xs b zs] CptnModNestWhile2 by blast also have "\<forall>m<min_n_p. (m, \<Gamma>,(While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \<notin> cptn_mod_nest_call" by (metis CptnModNestWhile2.hyps(3) CptnModNestWhile2.hyps(5) Seq_P_Ends_Normal div_seq_nest elim_cptn_mod_nest_call_n min_p) ultimately show ?thesis by auto next case False then have False:"min_n_p<min_n_w" by auto then have "(min_n_w, \<Gamma>, (P, Normal s) # xs) \<in> cptn_mod_nest_call" using min_p cptn_mod_nest_mono by force then have "(min_n_w, \<Gamma>, (While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \<in> cptn_mod_nest_call" using min_w min_p cptn_mod_nest_call.CptnModNestWhile2[of min_n_w \<Gamma> P s xs b zs] CptnModNestWhile2 by blast also have "\<forall>m<min_n_w. (m, \<Gamma>,(While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \<notin> cptn_mod_nest_call" proof - {fix m assume min_m:"m<min_n_w" then have "(m, \<Gamma>,(While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \<notin> cptn_mod_nest_call" proof - {assume "(m, \<Gamma>,(While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \<in> cptn_mod_nest_call" then have a1:"(m, \<Gamma>,(Seq P (While b P), Normal s) # zs) \<in> cptn_mod_nest_call" using elim_cptn_mod_nest_not_env_call by fastforce then obtain xs' s' s'' where m_cptn:"(m, \<Gamma>, (P, Normal s) # xs') \<in> cptn_mod_nest_call \<and> seq_cond_nest zs (While b P) xs' P (Normal s) s'' s' \<Gamma> m" using div_seq_nest[of m \<Gamma> "(LanguageCon.com.Seq P (LanguageCon.com.While b P), Normal s) # zs"] by fastforce then have "seq_cond_nest zs (While b P) xs' P (Normal s) s'' s' \<Gamma> m" by auto then have ?thesis unfolding seq_cond_nest_def by (metis CptnModNestWhile2.hyps(3) CptnModNestWhile2.hyps(5) Seq_P_Ends_Normal a1 last_length m_cptn min_m min_w) } thus ?thesis by auto qed }thus ?thesis by auto qed ultimately show ?thesis by auto qed next case (CptnModNestWhile3 n \<Gamma> P s xs b s' ys zs) then obtain min_n_p where min_p:"(min_n_p, \<Gamma>, (P, Normal s) # xs) \<in> cptn_mod_nest_call \<and> (\<forall>m<min_n_p. (m, \<Gamma>, (P, Normal s) # xs) \<notin> cptn_mod_nest_call)" by auto from CptnModNestWhile3 obtain min_n_w where min_w:"(min_n_w, \<Gamma>, (Throw, snd (last ((P, Normal s) # xs))) # ys) \<in> cptn_mod_nest_call \<and> (\<forall>m<min_n_w. (m, \<Gamma>, (Throw, snd (last ((P, Normal s) # xs))) # ys) \<notin> cptn_mod_nest_call)" by auto thus ?case proof (cases "min_n_p\<ge>min_n_w") case True then have "(min_n_p, \<Gamma>, (Throw, snd (last ((P, Normal s) # xs))) # ys) \<in> cptn_mod_nest_call" using min_w using cptn_mod_nest_mono by blast then have "(min_n_p, \<Gamma>, (While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \<in> cptn_mod_nest_call" using min_p cptn_mod_nest_call.CptnModNestWhile3[of min_n_p \<Gamma> P s xs b s' ys zs] CptnModNestWhile3 by fastforce also have "\<forall>m<min_n_p. (m, \<Gamma>,(While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \<notin> cptn_mod_nest_call" by (metis CptnModNestWhile3.hyps(3) CptnModNestWhile3.hyps(5) CptnModNestWhile3.hyps(8) Seq_P_Ends_Abort div_seq_nest elim_cptn_mod_nest_call_n min_p) ultimately show ?thesis by auto next case False then have False:"min_n_p<min_n_w" by auto then have "(min_n_w, \<Gamma>, (P, Normal s) # xs) \<in> cptn_mod_nest_call" using min_p cptn_mod_nest_mono by force then have "(min_n_w, \<Gamma>, (While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \<in> cptn_mod_nest_call" using min_w min_p cptn_mod_nest_call.CptnModNestWhile3[of min_n_w \<Gamma> P s xs b s' ys zs] CptnModNestWhile3 by fastforce also have "\<forall>m<min_n_w. (m, \<Gamma>,(While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \<notin> cptn_mod_nest_call" proof - {fix m assume min_m:"m<min_n_w" then have "(m, \<Gamma>,(While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \<notin> cptn_mod_nest_call" proof - {assume "(m, \<Gamma>,(While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \<in> cptn_mod_nest_call" then have s1:"(m, \<Gamma>,(Seq P (While b P), Normal s) # zs) \<in> cptn_mod_nest_call" using elim_cptn_mod_nest_not_env_call by fastforce then obtain xs' s' s'' where m_cptn:"(m, \<Gamma>, (P, Normal s) # xs') \<in> cptn_mod_nest_call \<and> seq_cond_nest zs (While b P) xs' P (Normal s) s'' s' \<Gamma> m" using div_seq_nest[of m \<Gamma> "(LanguageCon.com.Seq P (LanguageCon.com.While b P), Normal s) # zs"] by fastforce then have "seq_cond_nest zs (While b P) xs' P (Normal s) s'' s' \<Gamma> m" by auto then have ?thesis unfolding seq_cond_nest_def by (metis CptnModNestWhile3.hyps(3) CptnModNestWhile3.hyps(5) CptnModNestWhile3.hyps(8) Seq_P_Ends_Abort s1 m_cptn min_m min_w) } thus ?thesis by auto qed }thus ?thesis by auto qed ultimately show ?thesis by auto qed next case (CptnModNestCall n \<Gamma> bdy s xs f) thus ?case proof - { fix nn :: "nat \<Rightarrow> nat" obtain nna :: nat where ff1: "(nna, \<Gamma>, (bdy, Normal s) # xs) \<in> cptn_mod_nest_call \<and> (\<forall>n. \<not> n < nna \<or> (n, \<Gamma>, (bdy, Normal s) # xs) \<notin> cptn_mod_nest_call)" by (meson CptnModNestCall.hyps(2)) moreover { assume "(nn (nn (Suc nna)), \<Gamma>, (bdy, Normal s) # xs) \<in> cptn_mod_nest_call" then have "\<not> Suc (nn (nn (Suc nna))) < Suc nna" using ff1 by blast then have "(nn (Suc nna), \<Gamma>, (LanguageCon.com.Call f, Normal s) # (bdy, Normal s) # xs) \<in> cptn_mod_nest_call \<longrightarrow> (\<exists>n. (n, \<Gamma>, (LanguageCon.com.Call f, Normal s) # (bdy, Normal s) # xs) \<in> cptn_mod_nest_call \<and> (\<not> nn n < n \<or> (nn n, \<Gamma>, (LanguageCon.com.Call f, Normal s) # (bdy, Normal s) # xs) \<notin> cptn_mod_nest_call))" using ff1 by (meson CptnModNestCall.hyps(3) CptnModNestCall.hyps(4) cptn_mod_nest_call.CptnModNestCall less_trans_Suc) } ultimately have "\<exists>n. (n, \<Gamma>, (LanguageCon.com.Call f, Normal s) # (bdy, Normal s) # xs) \<in> cptn_mod_nest_call \<and> (\<not> nn n < n \<or> (nn n, \<Gamma>, (LanguageCon.com.Call f, Normal s) # (bdy, Normal s) # xs) \<notin> cptn_mod_nest_call)" by (metis (no_types) CptnModNestCall.hyps(3) CptnModNestCall.hyps(4) cptn_mod_nest_call.CptnModNestCall elim_cptn_mod_nest_call_n) } then show ?thesis by meson qed next case (CptnModNestDynCom n \<Gamma> c s xs) thus ?case by (meson cptn_mod_nest_call.CptnModNestDynCom elim_cptn_mod_nest_call_n) next case (CptnModNestGuard n \<Gamma> c s xs g f) thus ?case by (meson cptn_mod_nest_call.CptnModNestGuard elim_cptn_mod_nest_call_n) next case (CptnModNestCatch1 n \<Gamma> P s xs zs Q) thus ?case by (metis (no_types, lifting) Catch_P_Not_finish cptn_mod_nest_call.CptnModNestCatch1 div_catch_nest) next case (CptnModNestCatch2 n \<Gamma> P s xs ys zs Q) then obtain min_p where min_p:"(min_p, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call \<and> (\<forall>m<min_p. (m, \<Gamma>, (P, s) # xs) \<notin> cptn_mod_nest_call)" by auto from CptnModNestCatch2(5) obtain min_q where min_q:"(min_q, \<Gamma>, (Skip, snd (last ((P, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and> (\<forall>m<min_q. (m, \<Gamma>, (Skip, snd (last ((P, s) # xs))) # ys) \<notin> cptn_mod_nest_call)" by auto thus ?case proof(cases "min_p\<ge>min_q") case True then have "(min_p, \<Gamma>, (Skip, snd (last ((P,s) # xs))) # ys) \<in> cptn_mod_nest_call" using min_q using cptn_mod_nest_mono by blast then have "(min_p, \<Gamma>, (Catch P Q, s) # zs) \<in> cptn_mod_nest_call" using conjunct1[OF min_p] cptn_mod_nest_call.CptnModNestCatch2[of min_p \<Gamma> P s xs] CptnModNestCatch2(6) CptnModNestCatch2(3) by blast also have "\<forall>m<min_p. (m, \<Gamma>,(Catch P Q,s) # zs) \<notin> cptn_mod_nest_call" proof - {fix m assume min_m:"m<min_p" then have "(m, \<Gamma>,(Catch P Q, s) # zs) \<notin> cptn_mod_nest_call" proof - {assume ass:"(m, \<Gamma>, (Catch P Q, s) # zs) \<in> cptn_mod_nest_call" then obtain xs' s' s'' where m_cptn:"(m, \<Gamma>, (P, s) # xs') \<in> cptn_mod_nest_call \<and> catch_cond_nest zs Q xs' P s s'' s' \<Gamma> m" using div_catch_nest[of m \<Gamma> "(Catch P Q, s) # zs"] by fastforce then have "catch_cond_nest zs Q xs' P s s'' s' \<Gamma> m" by auto then have "xs=xs'" using Catch_P_Ends_Skip[OF CptnModNestCatch2(6) CptnModNestCatch2(3)] by fastforce then have "(m, \<Gamma>, (P,s) # xs) \<in> cptn_mod_nest_call" using m_cptn by auto then have False using min_p min_m by fastforce } thus ?thesis by auto qed }thus ?thesis by auto qed ultimately show ?thesis by auto next case False then have "(min_q, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call" using min_p cptn_mod_nest_mono by force then have "(min_q, \<Gamma>, (Catch P Q, s) # zs) \<in> cptn_mod_nest_call" using conjunct1[OF min_q] cptn_mod_nest_call.CptnModNestCatch2[of min_q \<Gamma> P s xs ] CptnModNestCatch2(6) CptnModNestCatch2(3) by blast also have "\<forall>m<min_q. (m, \<Gamma>,(Catch P Q,s) # zs) \<notin> cptn_mod_nest_call" proof - {fix m assume min_m:"m<min_q" then have "(m, \<Gamma>,(Catch P Q, s) # zs) \<notin> cptn_mod_nest_call" proof - {assume ass:"(m, \<Gamma>, (Catch P Q, s) # zs) \<in> cptn_mod_nest_call" then obtain xs' s' s'' where m_cptn:"(m, \<Gamma>, (P, s) # xs') \<in> cptn_mod_nest_call \<and> catch_cond_nest zs Q xs' P s s'' s' \<Gamma> m" using div_catch_nest[of m \<Gamma> "(Catch P Q, s) # zs"] by fastforce then have "catch_cond_nest zs Q xs' P s s'' s' \<Gamma> m" by auto then have ?thesis using Catch_P_Ends_Skip[OF CptnModNestCatch2(6) CptnModNestCatch2(3)] min_m min_q by blast } thus ?thesis by auto qed }thus ?thesis by auto qed ultimately show ?thesis by auto qed next case (CptnModNestCatch3 n \<Gamma> P s xs s' Q ys zs ) then obtain min_p where min_p:"(min_p, \<Gamma>, (P, Normal s) # xs) \<in> cptn_mod_nest_call \<and> (\<forall>m<min_p. (m, \<Gamma>, (P, Normal s) # xs) \<notin> cptn_mod_nest_call)" by auto from CptnModNestCatch3(6) CptnModNestCatch3(4) obtain min_q where min_q:"(min_q, \<Gamma>, (Q, snd (last ((P, Normal s) # xs))) # ys) \<in> cptn_mod_nest_call \<and> (\<forall>m<min_q. (m, \<Gamma>, (Q, snd (last ((P, Normal s) # xs))) # ys) \<notin> cptn_mod_nest_call)" by auto thus ?case proof(cases "min_p\<ge>min_q") case True then have "(min_p, \<Gamma>, (Q, snd (last ((P, Normal s) # xs))) # ys) \<in> cptn_mod_nest_call" using min_q using cptn_mod_nest_mono by blast then have "(min_p, \<Gamma>, (Catch P Q, Normal s) # zs) \<in> cptn_mod_nest_call" using conjunct1[OF min_p] cptn_mod_nest_call.CptnModNestCatch3[of min_p \<Gamma> P s xs s' Q ys zs] CptnModNestCatch3(4) CptnModNestCatch3(3) CptnModNestCatch3(7) by fastforce also have "\<forall>m<min_p. (m, \<Gamma>,(Catch P Q,Normal s) # zs) \<notin> cptn_mod_nest_call" proof - {fix m assume min_m:"m<min_p" then have "(m, \<Gamma>,(Catch P Q, Normal s) # zs) \<notin> cptn_mod_nest_call" proof - {assume ass:"(m, \<Gamma>, (Catch P Q,Normal s) # zs) \<in> cptn_mod_nest_call" then obtain xs' ns' ns'' where m_cptn:"(m, \<Gamma>, (P, Normal s) # xs') \<in> cptn_mod_nest_call \<and> catch_cond_nest zs Q xs' P (Normal s) ns'' ns' \<Gamma> m" using div_catch_nest[of m \<Gamma> "(Catch P Q, Normal s) # zs"] by fastforce then have "catch_cond_nest zs Q xs' P (Normal s) ns'' ns' \<Gamma> m" by auto then have "xs=xs'" using Catch_P_Ends_Normal[OF CptnModNestCatch3(7) CptnModNestCatch3(3) CptnModNestCatch3(4)] by fastforce then have "(m, \<Gamma>, (P,Normal s) # xs) \<in> cptn_mod_nest_call" using m_cptn by auto then have False using min_p min_m by fastforce } thus ?thesis by auto qed }thus ?thesis by auto qed ultimately show ?thesis by auto next case False then have "(min_q, \<Gamma>, (P, Normal s) # xs) \<in> cptn_mod_nest_call" using min_p cptn_mod_nest_mono by force then have "(min_q, \<Gamma>, (Catch P Q, Normal s) # zs) \<in> cptn_mod_nest_call" using conjunct1[OF min_q] cptn_mod_nest_call.CptnModNestCatch3[of min_q \<Gamma> P s xs s' ] CptnModNestCatch3(4) CptnModNestCatch3(3) CptnModNestCatch3(7) by blast also have "\<forall>m<min_q. (m, \<Gamma>,(Catch P Q,Normal s) # zs) \<notin> cptn_mod_nest_call" proof - {fix m assume min_m:"m<min_q" then have "(m, \<Gamma>,(Catch P Q, Normal s) # zs) \<notin> cptn_mod_nest_call" proof - {assume ass:"(m, \<Gamma>, (Catch P Q, Normal s) # zs) \<in> cptn_mod_nest_call" then obtain xs' ns' ns'' where m_cptn:"(m, \<Gamma>, (P, Normal s) # xs') \<in> cptn_mod_nest_call \<and> catch_cond_nest zs Q xs' P (Normal s) ns'' ns' \<Gamma> m" using div_catch_nest[of m \<Gamma> "(Catch P Q, Normal s) # zs"] by fastforce then have "catch_cond_nest zs Q xs' P (Normal s) ns'' ns' \<Gamma> m" by auto then have ?thesis using Catch_P_Ends_Normal[OF CptnModNestCatch3(7) CptnModNestCatch3(3) CptnModNestCatch3(4)] min_m min_q by (metis last_length) } thus ?thesis by auto qed }thus ?thesis by auto qed ultimately show ?thesis by auto qed qed lemma elim_cptn_mod_min_nest_call: assumes a0:"min_call n \<Gamma> cfg" and a1:"cfg = (P,s)#(Q,t)#cfg1" and a2:"(\<forall>f. redex P \<noteq> Call f) \<or> SmallStepCon.redex P = LanguageCon.com.Call fn \<and> \<Gamma> fn = None \<or> (redex P = Call fn \<and> (\<forall>sa. s\<noteq>Normal sa)) \<or> (redex P = Call fn \<and> P=Q)" shows "min_call n \<Gamma> ((Q,t)#cfg1)" proof - have a0: "(n,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and a0': "(\<forall>m<n. (m, \<Gamma>, cfg) \<notin> cptn_mod_nest_call)" using a0 unfolding min_call_def by auto then have "(n,\<Gamma>,(Q,t)#cfg1) \<in> cptn_mod_nest_call" using a0 a1 elim_cptn_mod_nest_call_n by blast also have "(\<forall>m<n. (m, \<Gamma>, (Q,t)#cfg1) \<notin> cptn_mod_nest_call)" proof- { assume "\<not>(\<forall>m<n. (m, \<Gamma>, (Q,t)#cfg1) \<notin> cptn_mod_nest_call)" then obtain m where asm0:"m<n" and asm1:"(m, \<Gamma>, (Q,t)#cfg1) \<in> cptn_mod_nest_call" by auto have ce:"\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>c\<^sub>e (Q, t)" using a0 a1 cptn_elim_cases(2) cptn_eq_cptn_mod_nest by blast then have "\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (Q, t) \<or> \<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Q, toSeq t)" using step_ce_dest by blast then have "(m, \<Gamma>, cfg) \<in> cptn_mod_nest_call" proof assume "\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (Q, t)" then show ?thesis using a0 a1 a2 cptn_mod_nest_call.CptnModNestEnv by (metis asm1 env_c_c') next assume a00:"\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Q, toSeq t)" moreover have "P\<noteq>Q" using mod_env_not_component calculation by auto moreover have norm:"\<forall>ns ns'. (s = Normal ns \<or> s = Abrupt ns) \<and> (t = Normal ns' \<or> t = Abrupt ns') \<longrightarrow> snd ns = snd ns'" using calculation ce step_ce_notNormal step_dest1 by blast then show ?thesis using mod_env_not_component a2 not_func_redex_cptn_mod_nest_n'[OF _ _ a00 norm] by (simp add: a1 asm1 calculation(2)) qed then have False using a0' asm0 by auto } thus ?thesis by auto qed ultimately show ?thesis unfolding min_call_def by auto qed lemma elim_call_cptn_mod_min_nest_call: assumes a0:"min_call n \<Gamma> cfg" and a1:"cfg = (P,s)#(Q,t)#cfg1" and a2:"P = Call f \<and> \<Gamma> f = Some Q \<and> (\<exists>sa. s=Normal sa) \<and> P\<noteq>Q" shows "min_call (n-1) \<Gamma> ((Q,t)#cfg1)" proof - obtain s' where a0: "(n,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and a0': "(\<forall>m<n. (m, \<Gamma>, cfg) \<notin> cptn_mod_nest_call)" and a2': "s= Normal s'" using a0 a2 unfolding min_call_def by auto then have "(n-1,\<Gamma>,(Q,t)#cfg1) \<in> cptn_mod_nest_call" using a1 a2 a2' elim_cptn_mod_nest_call_n_dec[of n \<Gamma> f s' cfg1 Q] by (metis (no_types, lifting) SmallStepCon.redex.simps(7) call_f_step_ce_not_s_eq_t_env_step cptn_elim_cases(2) cptn_if_cptn_mod cptn_mod_nest_cptn_mod elim_cptn_mod_nest_call_n_dec1 not_eq_not_env) moreover have "(\<forall>m<n - 1. (m, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call)" proof - { fix m assume "m<n-1" then have "(m, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call" proof - obtain pp :: "('b \<times> 'c) \<times> 'c list" where f1: "s = Normal pp" using a2 by blast then have "(LanguageCon.com.Call f, Normal pp) = (P, s)" by (simp add: a2) then have f2: "Normal pp = t" by (metis (no_types) SmallStepCon.redex.simps(7) a0 a1 a2 call_f_step_ce_not_s_eq_t_env_step cptn_elim_cases(2) cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod not_eq_not_env) have "m < n - Suc 0" using \<open>m < n - 1\<close> by presburger then have f3: "m + Suc 0 < n" by (meson less_diff_conv) have "(LanguageCon.com.Call f, Normal pp) = (P, s)" using f1 by (simp add: a2) then show ?thesis using f3 f2 a0' a1 a2 cptn_mod_nest_call.CptnModNestCall by fastforce qed } thus ?thesis by auto qed ultimately show ?thesis unfolding min_call_def by auto qed lemma skip_min_nested_call_0: assumes a0:"min_call n \<Gamma> cfg" and a1:"cfg = (Skip,s)#cfg1" shows "n=0" proof - have asm0:"(n, \<Gamma>, cfg) \<in> cptn_mod_nest_call" and asm1:"(\<forall>m<n. (m, \<Gamma>, cfg) \<notin> cptn_mod_nest_call)" using a0 unfolding min_call_def by auto show ?thesis using a1 asm0 asm1 proof (induct cfg1 arbitrary: cfg s n) case Nil thus ?case using cptn_mod_nest_call.CptnModNestOne neq0_conv by blast next case (Cons x xs) then obtain Q s' where cfg:"cfg = (LanguageCon.com.Skip, s) # (Q,s') # xs" by force then have min_call:"min_call n \<Gamma> cfg" using Cons unfolding min_call_def by auto then have "(\<forall>f. SmallStepCon.redex Skip \<noteq> LanguageCon.com.Call f)" by auto then have "min_call n \<Gamma> ((Q, s')#xs)" using elim_cptn_mod_min_nest_call[OF min_call cfg] cfg by simp thus ?case using Cons cfg unfolding min_call_def proof - assume a1: "(n, \<Gamma>, (Q, s') # xs) \<in> cptn_mod_nest_call \<and> (\<forall>m<n. (m, \<Gamma>, (Q, s') # xs) \<notin> cptn_mod_nest_call)" have "LanguageCon.com.Skip = Q" by (metis (no_types) \<open>(n, \<Gamma>, cfg) \<in> cptn_mod_nest_call\<close> cfg cptn_dest1_pair cptn_if_cptn_mod cptn_mod_nest_cptn_mod fst_conv last.simps last_length length_Cons lessI not_Cons_self2 skip_all_skip) then show ?thesis using a1 by (meson Cons.hyps) qed qed qed lemma throw_min_nested_call_0: assumes a0:"min_call n \<Gamma> cfg" and a1:"cfg = (Throw,s)#cfg1" shows "n=0" proof - have asm0:"(n, \<Gamma>, cfg) \<in> cptn_mod_nest_call" and asm1:"(\<forall>m<n. (m, \<Gamma>, cfg) \<notin> cptn_mod_nest_call)" using a0 unfolding min_call_def by auto show ?thesis using a1 asm0 asm1 proof (induct cfg1 arbitrary: cfg s n) case Nil thus ?case using cptn_mod_nest_call.CptnModNestOne neq0_conv by blast next case (Cons x xs) obtain s' where x:"x = (Skip,s') \<or> x = (Throw, s')" using CptnMod_elim_cases(10)[OF cptn_mod_nest_cptn_mod[OF Cons(3)[simplified Cons(2)]]] ce_Throw_toSkip cptn_elim_cases_pair(2) by auto then obtain Q where cfg:"cfg = (LanguageCon.com.Throw, s) # (Q,s') # xs" using Cons by force then have min_call:"min_call n \<Gamma> cfg" using Cons unfolding min_call_def by auto then have "(\<forall>f. SmallStepCon.redex Skip \<noteq> LanguageCon.com.Call f)" by auto then have min_call':"min_call n \<Gamma> ((Q, s')#xs)" using elim_cptn_mod_min_nest_call[OF min_call cfg] cfg by simp from x show ?case proof assume "x=(Skip,s')" thus ?thesis using skip_min_nested_call_0 min_call' Cons(2) cfg by fastforce next assume "x=(Throw,s')" thus ?thesis using Cons(1,2) min_call' cfg unfolding min_call_def by blast qed qed qed text \<open> function to calculate that there is not any subsequent where the nested call is n \<close> definition cond_seq_1 where "cond_seq_1 n \<Gamma> c1 s xs c2 zs ys \<equiv> ((n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<and> fst(last((c1,s)#xs)) = Skip \<and> (n,\<Gamma>,((c2, snd(last ((c1, s)#xs)))#ys)) \<in> cptn_mod_nest_call \<and> zs=(map (lift c2) xs)@((c2, snd(last ((c1, s)#xs)))#ys))" definition cond_seq_2 where "cond_seq_2 n \<Gamma> c1 s xs c2 zs ys s' s'' \<equiv> s= Normal s'' \<and> (n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<and> fst(last ((c1, s)#xs)) = Throw \<and> snd(last ((c1, s)#xs)) = Normal s' \<and> (n,\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod_nest_call \<and> zs=(map (lift c2) xs)@((Throw,Normal s')#ys)" definition cond_catch_1 where "cond_catch_1 n \<Gamma> c1 s xs c2 zs ys \<equiv> ((n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<and> fst(last((c1,s)#xs)) = Skip \<and> (n,\<Gamma>,((Skip, snd(last ((c1, s)#xs)))#ys)) \<in> cptn_mod_nest_call \<and> zs=(map (lift_catch c2) xs)@((Skip, snd(last ((c1, s)#xs)))#ys))" definition cond_catch_2 where "cond_catch_2 n \<Gamma> c1 s xs c2 zs ys s' s'' \<equiv> s= Normal s'' \<and> (n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<and> fst(last ((c1, s)#xs)) = Throw \<and> snd(last ((c1, s)#xs)) = Normal s' \<and> (n,\<Gamma>,(c2,Normal s')#ys) \<in> cptn_mod_nest_call \<and> zs=(map (lift_catch c2) xs)@((c2,Normal s')#ys)" (* fun biggest_nest_call :: "('s,'p,'f,'e)com \<Rightarrow> ('s,'f) xstate \<Rightarrow> (('s,'p,'f,'e) config) list \<Rightarrow> ('s,'p,'f,'e) body \<Rightarrow> nat \<Rightarrow> bool" where "biggest_nest_call (Seq c1 c2) s zs \<Gamma> n = (if (\<exists>xs. ((min_call n \<Gamma> ((c1,s)#xs)) \<and> (zs=map (lift c2) xs))) then let xsa = (SOME xs. (min_call n \<Gamma> ((c1,s)#xs)) \<and> (zs=map (lift c2) xs)) in (biggest_nest_call c1 s xsa \<Gamma> n) else if (\<exists>xs ys. cond_seq_1 n \<Gamma> c1 s xs c2 zs ys) then let xsa = (SOME xs. \<exists>ys. cond_seq_1 n \<Gamma> c1 s xs c2 zs ys); ysa = (SOME ys. cond_seq_1 n \<Gamma> c1 s xsa c2 zs ys) in if (min_call n \<Gamma> ((c2, snd(last ((c1, s)#xsa)))#ysa)) then True else (biggest_nest_call c1 s xsa \<Gamma> n) else let xsa = (SOME xs. \<exists>ys s' s''. cond_seq_2 n \<Gamma> c1 s xs c2 zs ys s' s'') in (biggest_nest_call c1 s xsa \<Gamma> n))" |"biggest_nest_call (Catch c1 c2) s zs \<Gamma> n = (if (\<exists>xs. ((min_call n \<Gamma> ((c1,s)#xs)) \<and> (zs=map (lift_catch c2) xs))) then let xsa = (SOME xs. (min_call n \<Gamma> ((c1,s)#xs)) \<and> (zs=map (lift_catch c2) xs)) in (biggest_nest_call c1 s xsa \<Gamma> n) else if (\<exists>xs ys. cond_catch_1 n \<Gamma> c1 s xs c2 zs ys) then let xsa = (SOME xs. \<exists>ys. cond_catch_1 n \<Gamma> c1 s xs c2 zs ys) in (biggest_nest_call c1 s xsa \<Gamma> n) else let xsa = (SOME xs. \<exists>ys s' s''. cond_catch_2 n \<Gamma> c1 s xs c2 zs ys s' s''); ysa = (SOME ys. \<exists>s' s''. cond_catch_2 n \<Gamma> c1 s xsa c2 zs ys s' s'') in if (min_call n \<Gamma> ((c2, snd(last ((c1, s)#xsa)))#ysa)) then True else (biggest_nest_call c1 s xsa \<Gamma> n))" |"biggest_nest_call _ _ _ _ _ = False" *) lemma min_call_less_eq_n: "(n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<Longrightarrow> (n,\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call \<Longrightarrow> min_call p \<Gamma> ((c1, s)#xs) \<and> min_call q \<Gamma> ((c2, snd(last ((c1, s)#xs)))#ys) \<Longrightarrow> p\<le>n \<and> q\<le>n" unfolding min_call_def using le_less_linear by blast lemma min_call_seq_less_eq_n': "(n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<Longrightarrow> min_call p \<Gamma> ((c1, s)#xs) \<Longrightarrow> p\<le>n" unfolding min_call_def using le_less_linear by blast lemma min_call_seq2: "min_call n \<Gamma> ((Seq c1 c2,s)#zs) \<Longrightarrow> (n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<Longrightarrow> fst(last ((c1, s)#xs)) = Skip \<Longrightarrow> (n,\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call \<Longrightarrow> zs=(map (lift c2) xs)@((c2, snd(last ((c1, s)#xs)))#ys) \<Longrightarrow> min_call n \<Gamma> ((c1, s)#xs) \<or> min_call n \<Gamma> ((c2, snd(last ((c1, s)#xs)))#ys) " proof - assume a0:"min_call n \<Gamma> ((Seq c1 c2,s)#zs)" and a1:"(n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call" and a2:"fst(last ((c1, s)#xs)) = Skip" and a3:"(n,\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call" and a4:"zs=(map (lift c2) xs)@((c2, snd(last ((c1, s)#xs)))#ys)" then obtain p q where min_calls: "min_call p \<Gamma> ((c1, s)#xs) \<and> min_call q \<Gamma> ((c2, snd(last ((c1, s)#xs)))#ys)" using a1 a3 minimum_nest_call by blast then have p_q:"p\<le>n \<and> q\<le>n" using a0 a1 a3 a4 min_call_less_eq_n by blast { assume ass0:"p<n \<and> q <n" then have "(p,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call" and "(q,\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call" using min_calls unfolding min_call_def by auto then have ?thesis proof (cases "p\<le>q") case True then have q_cptn_c1:"(q, \<Gamma>, (c1, s) # xs) \<in> cptn_mod_nest_call" using cptn_mod_nest_mono min_calls unfolding min_call_def by blast have q_cptn_c2:"(q, \<Gamma>, (c2, snd (last ((c1, s) # xs))) # ys) \<in> cptn_mod_nest_call" using min_calls unfolding min_call_def by auto then have "(q,\<Gamma>,((Seq c1 c2,s)#zs)) \<in>cptn_mod_nest_call" using True min_calls a2 a4 CptnModNestSeq2[OF q_cptn_c1 a2 q_cptn_c2 a4] by auto thus ?thesis using ass0 a0 unfolding min_call_def by auto next case False then have q_cptn_c1:"(p, \<Gamma>, (c1, s) # xs) \<in> cptn_mod_nest_call" using min_calls unfolding min_call_def by blast have q_cptn_c2:"(p, \<Gamma>, (c2, snd (last ((c1, s) # xs))) # ys) \<in> cptn_mod_nest_call" using min_calls False unfolding min_call_def by (metis (no_types, lifting) cptn_mod_nest_mono2 not_less) then have "(p,\<Gamma>,((Seq c1 c2,s)#zs)) \<in>cptn_mod_nest_call" using False min_calls a2 a4 CptnModNestSeq2[OF q_cptn_c1 a2 q_cptn_c2 a4] by auto thus ?thesis using ass0 a0 unfolding min_call_def by auto qed }note l=this { assume ass0:"p\<ge>n \<or> q \<ge>n" then have ?thesis using p_q min_calls by fastforce } thus ?thesis using l by fastforce qed lemma min_call_seq3: "min_call n \<Gamma> ((Seq c1 c2,s)#zs) \<Longrightarrow> s= Normal s'' \<Longrightarrow> (n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<Longrightarrow> fst(last ((c1, s)#xs)) = Throw \<Longrightarrow> snd(last ((c1, s)#xs)) = Normal s' \<Longrightarrow> (n,\<Gamma>,(Throw, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call \<Longrightarrow> zs=(map (lift c2) xs)@((Throw, snd(last ((c1, s)#xs)))#ys) \<Longrightarrow> min_call n \<Gamma> ((c1, s)#xs) " proof - assume a0:"min_call n \<Gamma> ((Seq c1 c2,s)#zs)" and a0':"s= Normal s''" and a1:"(n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call" and a2:"fst(last ((c1, s)#xs)) = Throw" and a2':"snd(last ((c1, s)#xs)) = Normal s'" and a3:"(n,\<Gamma>,(Throw, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call" and a4:"zs=(map (lift c2) xs)@((Throw, snd(last ((c1, s)#xs)))#ys)" then obtain p where min_calls: "min_call p \<Gamma> ((c1, s)#xs) \<and> min_call 0 \<Gamma> ((Throw, snd(last ((c1, s)#xs)))#ys)" using a1 a3 minimum_nest_call throw_min_nested_call_0 by metis then have p_q:"p\<le>n \<and> 0\<le>n" using a0 a1 a3 a4 min_call_less_eq_n by blast { assume ass0:"p<n \<and> 0 <n" then have "(p,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call" and "(0,\<Gamma>,(Throw, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call" using min_calls unfolding min_call_def by auto then have ?thesis proof (cases "p\<le>0") case True then have q_cptn_c1:"(0, \<Gamma>, (c1, Normal s'') # xs) \<in> cptn_mod_nest_call" using cptn_mod_nest_mono min_calls a0' unfolding min_call_def by blast have q_cptn_c2:"(0, \<Gamma>, (Throw, snd (last ((c1, s) # xs))) # ys) \<in> cptn_mod_nest_call" using min_calls unfolding min_call_def by auto then have "(0,\<Gamma>,((Seq c1 c2,s)#zs)) \<in>cptn_mod_nest_call" using True min_calls a2 a4 a2' a0' CptnModNestSeq3[OF q_cptn_c1 ] by auto thus ?thesis using ass0 a0 unfolding min_call_def by auto next case False then have q_cptn_c1:"(p, \<Gamma>, (c1, Normal s'') # xs) \<in> cptn_mod_nest_call" using min_calls a0' unfolding min_call_def by blast have q_cptn_c2:"(p, \<Gamma>, (Throw, snd (last ((c1, s) # xs))) # ys) \<in> cptn_mod_nest_call" using min_calls False unfolding min_call_def by (metis (no_types, lifting) cptn_mod_nest_mono2 not_less) then have "(p,\<Gamma>,((Seq c1 c2,s)#zs)) \<in>cptn_mod_nest_call" using False min_calls a2 a4 a0' a2' CptnModNestSeq3[OF q_cptn_c1] by auto thus ?thesis using ass0 a0 unfolding min_call_def by auto qed }note l=this { assume ass0:"p\<ge>n \<or> 0 \<ge>n" then have ?thesis using p_q min_calls by fastforce } thus ?thesis using l by fastforce qed lemma min_call_catch2: "min_call n \<Gamma> ((Catch c1 c2,s)#zs) \<Longrightarrow> (n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<Longrightarrow> fst(last ((c1, s)#xs)) = Skip \<Longrightarrow> (n,\<Gamma>,(Skip, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call \<Longrightarrow> zs=(map (lift_catch c2) xs)@((Skip, snd(last ((c1, s)#xs)))#ys) \<Longrightarrow> min_call n \<Gamma> ((c1, s)#xs) " proof - assume a0:"min_call n \<Gamma> ((Catch c1 c2,s)#zs)" and a1:"(n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call" and a2:"fst(last ((c1, s)#xs)) = Skip" and a3:"(n,\<Gamma>,(Skip, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call" and a4:"zs=(map (lift_catch c2) xs)@((Skip, snd(last ((c1, s)#xs)))#ys)" then obtain p where min_calls: "min_call p \<Gamma> ((c1, s)#xs) \<and> min_call 0 \<Gamma> ((Skip, snd(last ((c1, s)#xs)))#ys)" using a1 a3 minimum_nest_call skip_min_nested_call_0 by metis then have p_q:"p\<le>n \<and> 0\<le>n" using a0 a1 a3 a4 min_call_less_eq_n by blast { assume ass0:"p<n \<and> 0 <n" then have "(p,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call" and "(0,\<Gamma>,(Skip, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call" using min_calls unfolding min_call_def by auto then have ?thesis proof (cases "p\<le>0") case True then have q_cptn_c1:"(0, \<Gamma>, (c1, s) # xs) \<in> cptn_mod_nest_call" using cptn_mod_nest_mono min_calls unfolding min_call_def by blast have q_cptn_c2:"(0, \<Gamma>, (Skip, snd (last ((c1, s) # xs))) # ys) \<in> cptn_mod_nest_call" using min_calls unfolding min_call_def by auto then have "(0,\<Gamma>,((Catch c1 c2,s)#zs)) \<in>cptn_mod_nest_call" using True min_calls a2 a4 CptnModNestCatch2[OF q_cptn_c1 ] by auto thus ?thesis using ass0 a0 unfolding min_call_def by auto next case False then have q_cptn_c1:"(p, \<Gamma>, (c1, s) # xs) \<in> cptn_mod_nest_call" using min_calls unfolding min_call_def by blast have q_cptn_c2:"(p, \<Gamma>, (Skip, snd (last ((c1, s) # xs))) # ys) \<in> cptn_mod_nest_call" using min_calls False unfolding min_call_def by (metis (no_types, lifting) cptn_mod_nest_mono2 not_less) then have "(p,\<Gamma>,((Catch c1 c2,s)#zs)) \<in>cptn_mod_nest_call" using False min_calls a2 a4 CptnModNestCatch2[OF q_cptn_c1] by auto thus ?thesis using ass0 a0 unfolding min_call_def by auto qed }note l=this { assume ass0:"p\<ge>n \<or> 0 \<ge>n" then have ?thesis using p_q min_calls by fastforce } thus ?thesis using l by fastforce qed lemma min_call_catch_less_eq_n: "(n,\<Gamma>, (c1, Normal s)#xs) \<in> cptn_mod_nest_call \<Longrightarrow> (n,\<Gamma>,(c2, snd(last ((c1, Normal s)#xs)))#ys) \<in> cptn_mod_nest_call \<Longrightarrow> min_call p \<Gamma> ((c1, Normal s)#xs) \<and> min_call q \<Gamma> ((c2, snd(last ((c1, Normal s)#xs)))#ys) \<Longrightarrow> p\<le>n \<and> q\<le>n" unfolding min_call_def using le_less_linear by blast lemma min_call_catch3: "min_call n \<Gamma> ((Catch c1 c2,Normal s)#zs) \<Longrightarrow> (n,\<Gamma>, (c1, Normal s)#xs) \<in> cptn_mod_nest_call \<Longrightarrow> fst(last ((c1, Normal s)#xs)) = Throw \<Longrightarrow> snd(last ((c1, Normal s)#xs)) = Normal s' \<Longrightarrow> (n,\<Gamma>,(c2, snd(last ((c1, Normal s)#xs)))#ys) \<in> cptn_mod_nest_call \<Longrightarrow> zs=(map (lift_catch c2) xs)@((c2, snd(last ((c1, Normal s)#xs)))#ys) \<Longrightarrow> min_call n \<Gamma> ((c1, Normal s)#xs) \<or> min_call n \<Gamma> ((c2, snd(last ((c1, Normal s)#xs)))#ys) " proof - assume a0:"min_call n \<Gamma> ((Catch c1 c2,Normal s)#zs)" and a1:"(n,\<Gamma>, (c1, Normal s)#xs) \<in> cptn_mod_nest_call" and a2:"fst(last ((c1, Normal s)#xs)) = Throw" and a2':"snd(last ((c1, Normal s)#xs)) = Normal s'" and a3:"(n,\<Gamma>,(c2, snd(last ((c1, Normal s)#xs)))#ys) \<in> cptn_mod_nest_call" and a4:"zs=(map (lift_catch c2) xs)@((c2, snd(last ((c1, Normal s)#xs)))#ys)" then obtain p q where min_calls: "min_call p \<Gamma> ((c1, Normal s)#xs) \<and> min_call q \<Gamma> ((c2, snd(last ((c1, Normal s)#xs)))#ys)" using a1 a3 minimum_nest_call by blast then have p_q:"p\<le>n \<and> q\<le>n" using a1 a2 a2' a3 a4 min_call_less_eq_n by blast { assume ass0:"p<n \<and> q <n" then have "(p,\<Gamma>, (c1, Normal s)#xs) \<in> cptn_mod_nest_call" and "(q,\<Gamma>,(c2, snd(last ((c1, Normal s)#xs)))#ys) \<in> cptn_mod_nest_call" using min_calls unfolding min_call_def by auto then have ?thesis proof (cases "p\<le>q") case True then have q_cptn_c1:"(q, \<Gamma>, (c1,Normal s) # xs) \<in> cptn_mod_nest_call" using cptn_mod_nest_mono min_calls unfolding min_call_def by blast have q_cptn_c2:"(q, \<Gamma>, (c2, snd (last ((c1, Normal s) # xs))) # ys) \<in> cptn_mod_nest_call" using min_calls unfolding min_call_def by auto then have "(q,\<Gamma>,((Catch c1 c2, Normal s)#zs)) \<in>cptn_mod_nest_call" using True min_calls a2 a2' a4 CptnModNestCatch3[OF q_cptn_c1 a2 a2' q_cptn_c2 a4] by auto thus ?thesis using ass0 a0 unfolding min_call_def by auto next case False then have q_cptn_c1:"(p, \<Gamma>, (c1, Normal s) # xs) \<in> cptn_mod_nest_call" using min_calls unfolding min_call_def by blast have q_cptn_c2:"(p, \<Gamma>, (c2, snd (last ((c1, Normal s) # xs))) # ys) \<in> cptn_mod_nest_call" using min_calls False unfolding min_call_def by (metis (no_types, lifting) cptn_mod_nest_mono2 not_less) then have "(p,\<Gamma>,((Catch c1 c2,Normal s)#zs)) \<in>cptn_mod_nest_call" using False min_calls a2 a4 CptnModNestCatch3[OF q_cptn_c1 a2 a2' q_cptn_c2 a4] by auto thus ?thesis using ass0 a0 unfolding min_call_def by auto qed }note l=this { assume ass0:"p\<ge>n \<or> q \<ge>n" then have ?thesis using p_q min_calls by fastforce } thus ?thesis using l by fastforce qed lemma min_call_seq_c1_not_finish: "min_call n \<Gamma> cfg \<Longrightarrow> cfg = (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1 \<Longrightarrow> (n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call \<Longrightarrow> (Q, t) # cfg1 = map (lift P1) xs \<Longrightarrow> min_call n \<Gamma> ((P0, s)#xs) " proof - assume a0:"min_call n \<Gamma> cfg" and a1:" cfg = (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1" and a2:"(n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call" and a3:"(Q, t) # cfg1 = map (lift P1) xs" then have "(n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call" using a2 by auto moreover have "\<forall>m<n. (m, \<Gamma>,(P0, s)#xs) \<notin> cptn_mod_nest_call" proof- {fix m assume ass:"m<n" { assume ass1:"(m, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call" then have "(m,\<Gamma>,cfg) \<in> cptn_mod_nest_call" using a1 a3 CptnModNestSeq1[OF ass1] by auto then have False using ass a0 unfolding min_call_def by auto } then have "(m, \<Gamma>, (P0, s) # xs) \<notin> cptn_mod_nest_call" by auto } then show ?thesis by auto qed ultimately show ?thesis unfolding min_call_def by auto qed lemma min_call_seq_not_finish: " min_call n \<Gamma> ((P0, s)#xs) \<Longrightarrow> cfg = (LanguageCon.com.Seq P0 P1, s) # cfg1 \<Longrightarrow> cfg1 = map (lift P1) xs \<Longrightarrow> min_call n \<Gamma> cfg " proof - assume a0:"min_call n \<Gamma> ((P0, s)#xs)" and a1:" cfg = (LanguageCon.com.Seq P0 P1, s) # cfg1" and a2:" cfg1 = map (lift P1) xs" then have "(n, \<Gamma>,cfg) \<in> cptn_mod_nest_call" using a0 a1 a2 CptnModNestSeq1[of n \<Gamma> P0 s xs "cfg1" P1] unfolding min_call_def by auto moreover have "\<forall>m<n. (m, \<Gamma>,cfg) \<notin> cptn_mod_nest_call" proof- {fix m assume ass:"m<n" { assume ass1:"(m, \<Gamma>, cfg) \<in> cptn_mod_nest_call" then have "(m,\<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call" using a1 a2 by (metis (no_types) Seq_P_Not_finish div_seq_nest) then have False using ass a0 unfolding min_call_def by auto } then have "(m, \<Gamma>, cfg) \<notin> cptn_mod_nest_call" by auto } then show ?thesis by auto qed ultimately show ?thesis unfolding min_call_def by auto qed lemma min_call_catch_c1_not_finish: "min_call n \<Gamma> cfg \<Longrightarrow> cfg = (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1 \<Longrightarrow> (n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call \<Longrightarrow> (Q, t) # cfg1 = map (lift_catch P1) xs \<Longrightarrow> min_call n \<Gamma> ((P0, s)#xs) " proof - assume a0:"min_call n \<Gamma> cfg" and a1:" cfg = (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1" and a2:"(n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call" and a3:"(Q, t) # cfg1 = map (lift_catch P1) xs" then have "(n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call" using a2 by auto moreover have "\<forall>m<n. (m, \<Gamma>,(P0, s)#xs) \<notin> cptn_mod_nest_call" proof- {fix m assume ass:"m<n" { assume ass1:"(m, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call" then have "(m,\<Gamma>,cfg) \<in> cptn_mod_nest_call" using a1 a3 CptnModNestCatch1[OF ass1] by auto then have False using ass a0 unfolding min_call_def by auto } then have "(m, \<Gamma>, (P0, s) # xs) \<notin> cptn_mod_nest_call" by auto } then show ?thesis by auto qed ultimately show ?thesis unfolding min_call_def by auto qed lemma min_call_catch_not_finish: " min_call n \<Gamma> ((P0, s)#xs) \<Longrightarrow> cfg = (LanguageCon.com.Catch P0 P1, s) # cfg1 \<Longrightarrow> cfg1 = map (lift_catch P1) xs \<Longrightarrow> min_call n \<Gamma> cfg " proof - assume a0:"min_call n \<Gamma> ((P0, s)#xs)" and a1:" cfg = (Catch P0 P1, s) # cfg1" and a2:" cfg1 = map (lift_catch P1) xs" then have "(n, \<Gamma>,cfg) \<in> cptn_mod_nest_call" using a0 a1 a2 CptnModNestCatch1[of n \<Gamma> P0 s xs "cfg1" P1] unfolding min_call_def by auto moreover have "\<forall>m<n. (m, \<Gamma>,cfg) \<notin> cptn_mod_nest_call" proof- {fix m assume ass:"m<n" { assume ass1:"(m, \<Gamma>, cfg) \<in> cptn_mod_nest_call" then have "(m,\<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call" using a1 a2 by (metis (no_types) Catch_P_Not_finish div_catch_nest) then have False using ass a0 unfolding min_call_def by auto } then have "(m, \<Gamma>, cfg) \<notin> cptn_mod_nest_call" by auto } then show ?thesis by auto qed ultimately show ?thesis unfolding min_call_def by auto qed lemma seq_xs_no_empty: assumes seq:"seq_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \<Gamma> n" and cfg:"cfg = (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1" and a0:"SmallStepCon.redex (LanguageCon.com.Seq P0 P1) = LanguageCon.com.Call f" shows"\<exists>Q' xs'. Q=Seq Q' P1 \<and> xs=(Q',t)#xs'" using seq unfolding lift_def seq_cond_nest_def proof assume "(Q, t) # cfg1 = map (\<lambda>(P, s). (LanguageCon.com.Seq P P1, s)) xs" thus ?thesis by auto next assume "fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \<and> (\<exists>ys. (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (\<lambda>(P, s). (LanguageCon.com.Seq P P1, s)) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<or> fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and> snd (last ((P0, s) # xs)) = Normal s' \<and> s = Normal s'' \<and> (\<exists>ys. (n, \<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (\<lambda>(P, s). (LanguageCon.com.Seq P P1, s)) xs @ (LanguageCon.com.Throw, Normal s') # ys)" thus ?thesis proof assume ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \<and> (\<exists>ys. (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (\<lambda>(P, s). (LanguageCon.com.Seq P P1, s)) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys)" show ?thesis proof (cases xs) case Nil thus ?thesis using cfg a0 ass by auto next case (Cons xa xsa) then obtain a b where xa:"xa = (a,b)" by fastforce obtain pps :: "(('a \<times> 'b, 'c, 'd, 'e) LanguageCon.com \<times> (('a \<times> 'b) \<times> 'b list, 'd) xstate) list" where "(Q, t) = (Seq a P1, b) \<and> cfg1 = map (\<lambda>(c, y). (Seq c P1, y)) xsa @ (P1, snd (((P0, s) # xs) ! length xs)) # pps" using ass local.Cons xa by moura then show ?thesis using local.Cons xa by auto qed next assume ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and> snd (last ((P0, s) # xs)) = Normal s' \<and> s = Normal s'' \<and> (\<exists>ys. (n, \<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (\<lambda>(P, s). (LanguageCon.com.Seq P P1, s)) xs @ (LanguageCon.com.Throw, Normal s') # ys)" thus ?thesis proof (cases xs) case Nil thus ?thesis using cfg a0 ass by auto next case (Cons xa xsa) then obtain a b where xa:"xa = (a,b)" by fastforce obtain pps :: "(('a \<times> 'b, 'c, 'd, 'e) LanguageCon.com \<times> (('a \<times> 'b) \<times> 'b list, 'd) xstate) list" where "(Q, t) = (Seq a P1, b) \<and> cfg1 = map (\<lambda>(c, y). (Seq c P1, y)) xsa @ (LanguageCon.com.Throw, Normal s') # pps" using ass local.Cons xa by moura then show ?thesis using local.Cons xa by auto qed qed qed lemma catch_xs_no_empty: assumes seq:"catch_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \<Gamma> n" and cfg:"cfg = (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1" and a0:"SmallStepCon.redex (LanguageCon.com.Catch P0 P1) = LanguageCon.com.Call f" shows"\<exists>Q' xs'. Q=Catch Q' P1 \<and> xs=(Q',t)#xs'" using seq unfolding lift_catch_def catch_cond_nest_def proof assume "(Q, t) # cfg1 = map (\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs" thus ?thesis by auto next assume "fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and> snd (last ((P0, s) # xs)) = Normal s' \<and> s = Normal s'' \<and> (\<exists>ys. (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<or> fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \<and> (\<exists>ys. (n, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @ (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys)" thus ?thesis proof assume ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and> snd (last ((P0, s) # xs)) = Normal s' \<and> s = Normal s'' \<and> (\<exists>ys. (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys)" show ?thesis proof (cases xs) case Nil thus ?thesis using cfg a0 ass by auto next case (Cons xa xsa) then obtain a b where xa:"xa = (a,b)" by fastforce obtain pps :: "(('a \<times> 'b, 'c, 'd, 'e) com \<times> (('a \<times> 'b) \<times> 'b list, 'd) xstate) list" where "(Q, t) = (Catch a P1, b) \<and> cfg1 = map (\<lambda>(c, y). (Catch c P1, y)) xsa @ (P1, snd (((P0, s) # xs) ! length xs)) # pps" using ass local.Cons xa by moura then show ?thesis using local.Cons xa by auto qed next assume ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \<and> (\<exists>ys. (n, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @ (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys)" thus ?thesis proof (cases xs) case Nil thus ?thesis using cfg a0 ass by auto next case (Cons xa xsa) then obtain a b where xa:"xa = (a,b)" by fastforce obtain pps :: "(('a \<times> 'b, 'c, 'd, 'e) com \<times> (('a \<times> 'b) \<times> 'b list, 'd) xstate) list" where "(Q, t) = (Catch a P1, b) \<and> cfg1 = map (\<lambda>(c, y). (Catch c P1, y)) xsa @ (Skip, snd (last ((P0, s) # xs))) # pps" using ass local.Cons xa by moura then show ?thesis using local.Cons xa by auto qed qed qed lemma redex_call_cptn_mod_min_nest_call_gr_zero: assumes a0:"min_call n \<Gamma> cfg" and a1:"cfg = (P,s)#(Q,t)#cfg1" and a2:"redex P = Call f \<and> \<Gamma> f = Some bdy \<and> (\<exists>sa. s=Normal sa) \<and> t=s" and a3:"\<Gamma>\<turnstile>\<^sub>c(P,toSeq s)\<rightarrow>(Q,toSeq t)" shows "n>0" using a0 a1 a2 a3 proof (induct P arbitrary: Q cfg1 cfg s t n) case (Call f1) then obtain ns where "toSeq s = Normal ns" by (metis toSeq.simps(1)) then show ?case using Call stepc_Normal_elim_cases(9)[of \<Gamma> f1 ns "(Q,Normal ns)"] elim_cptn_mod_nest_call_n_greater_zero unfolding min_call_def by (metis (no_types, lifting) Pair_inject xstate.simps(9)) next case (Seq P0 P1) then obtain xs s' s'' where p0_cptn:"(n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call" and seq:"seq_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \<Gamma> n" using div_seq_nest[of n \<Gamma> cfg] unfolding min_call_def by blast then obtain m where min:"min_call m \<Gamma> ((P0, s)#xs)" using minimum_nest_call by blast have xs':"\<exists>Q' xs'. Q=Seq Q' P1 \<and> xs=(Q',t)#xs'" using seq Seq seq_xs_no_empty by meson then have "0<m" using Seq(1,5,6) min using SmallStepCon.redex.simps(4) stepc_elim_cases_Seq_Seq by fastforce thus ?case by (metis min min_call_def not_gr0 p0_cptn) next case (Catch P0 P1) then obtain xs s' s'' where p0_cptn:"(n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call" and seq:"catch_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \<Gamma> n" using div_catch_nest[of n \<Gamma> cfg] unfolding min_call_def by blast then obtain m where min:"min_call m \<Gamma> ((P0, s)#xs)" using minimum_nest_call by blast obtain Q' xs' where xs':"Q=Catch Q' P1 \<and> xs=(Q',t)#xs'" using catch_xs_no_empty[OF seq Catch(4)] Catch by blast then have "0<m" using Catch(1,5,6) min using SmallStepCon.redex.simps(4) stepc_elim_cases_Catch_Catch by fastforce thus ?case by (metis min min_call_def not_gr0 p0_cptn) qed(auto) (* lemma elim_redex_call_cptn_mod_min_nest_call: assumes a0:"min_call n \<Gamma> cfg" and a1:"cfg = (P,s)#(Q,t)#cfg1" and a2:"redex P = Call f \<and> \<Gamma> f = Some bdy \<and> (\<exists>sa. s=Normal sa) \<and> t=s " and a3:"biggest_nest_call P s ((Q,t)#cfg1) \<Gamma> n" shows "min_call n \<Gamma> ((Q,t)#cfg1)" using a0 a1 a2 a3 proof (induct P arbitrary: Q cfg1 cfg s t n) case Cond thus ?case by fastforce next case (Seq P0 P1) then obtain xs s' s'' where p0_cptn:"(n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call" and seq:"seq_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \<Gamma> n" using div_seq_nest[of n \<Gamma> cfg] unfolding min_call_def by blast show ?case using seq unfolding seq_cond_nest_def proof assume ass:"(Q, t) # cfg1 = map (lift P1) xs" then obtain Q' xs' where xs':"Q=Seq Q' P1 \<and> xs=(Q',t)#xs'" unfolding lift_def by fastforce then have ctpn_P0:"(P0, s) # xs = (P0, s) # (Q', t) # xs'" by auto then have min_p0:"min_call n \<Gamma> ((P0, s)#xs)" using min_call_seq_c1_not_finish[OF Seq(3) Seq(4) p0_cptn] ass by auto then have ex_xs:"\<exists>xs. min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift P1) xs" using ass by auto then have min_xs:"min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift P1) xs" using min_p0 ass by auto have "xs= (SOME xs. (min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift P1) xs))" proof - have "\<forall>xsa. min_call n \<Gamma> ((P0, s)#xsa) \<and> (Q, t) # cfg1 = map (lift P1) xsa \<longrightarrow> xsa = xs" using xs' ass by (metis map_lift_eq_xs_xs') thus ?thesis using min_xs some_equality by (metis (mono_tags, lifting)) qed then have big:"biggest_nest_call P0 s ((Q', t) # xs') \<Gamma> n" using biggest_nest_call.simps(1)[of P0 P1 s "((Q, t) # cfg1)" \<Gamma> n] Seq(6) xs' ex_xs by auto have reP0:"redex P0 = (Call f) \<and> \<Gamma> f = Some bdy \<and> (\<exists>saa. s = Normal saa) \<and> t = s " using Seq(5) xs' by auto have min_call:"min_call n \<Gamma> ((Q', t) # xs')" using Seq(1)[OF min_p0 ctpn_P0 reP0] big xs' ass by auto thus ?thesis using min_call_seq_not_finish[OF min_call] ass xs' by blast next assume ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \<and> (\<exists>ys. (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<or> fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and> snd (last ((P0, s) # xs)) = Normal s' \<and> s = Normal s'' \<and> (\<exists>ys. (n, \<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift P1) xs @ (LanguageCon.com.Throw, Normal s') # ys)" {assume ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \<and> (\<exists>ys. (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys)" have ?thesis proof (cases xs) case Nil thus ?thesis using Seq ass by fastforce next case (Cons xa xsa) then obtain ys where seq2_ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \<and> (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift P1) (xa#xsa) @ (P1, snd (((P0, s) # xs) ! length xs)) # ys" using ass by auto then obtain mq mp1 where min_call_q:"min_call mq \<Gamma> ((P0, s) # xs)" and min_call_p1:"min_call mp1 \<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)" using seq2_ass minimum_nest_call p0_cptn by fastforce then have mp: "mq\<le>n \<and> mp1 \<le>n" using seq2_ass min_call_less_eq_n[of n \<Gamma> P0 s xs P1 ys mq mp1] Seq(3,4) p0_cptn by (simp add: last_length) have min_call:"min_call n \<Gamma> ((P0, s) # xs) \<or> min_call n \<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)" using seq2_ass min_call_seq2[of n \<Gamma> P0 P1 s "(Q, t) # cfg1" xs ys] Seq(3,4) p0_cptn by (simp add: last_length local.Cons) from seq2_ass obtain Q' where Q':"Q=Seq Q' P1 \<and> xa=(Q',t)" unfolding lift_def by (metis (mono_tags, lifting) fst_conv length_greater_0_conv list.simps(3) list.simps(9) nth_Cons_0 nth_append prod.case_eq_if prod.collapse snd_conv) then have q'_n_cptn:"(n,\<Gamma>,(Q',t)#xsa)\<in>cptn_mod_nest_call" using p0_cptn Q' Cons using elim_cptn_mod_nest_call_n by blast show ?thesis proof(cases "mp1=n") case True then have "min_call n \<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)" using min_call_p1 by auto then have min_P1:"min_call n \<Gamma> ((P1, snd ((xa # xsa) ! length xsa)) # ys)" using Cons seq2_ass by fastforce then have p1_n_cptn:"(n, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call" using Seq.prems(1) Seq.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast also then have "(\<forall>m<n. (m, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call)" proof- { fix m assume ass:"m<n" { assume Q_m:"(m, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call" then have False using min_P1 ass Q' Cons unfolding min_call_def proof - assume a1: "(n, \<Gamma>, (P1, snd ((xa # xsa) ! length xsa)) # ys) \<in> cptn_mod_nest_call \<and> (\<forall>m<n. (m, \<Gamma>, (P1, snd ((xa # xsa) ! length xsa)) # ys) \<notin> cptn_mod_nest_call)" have f2: "\<forall>n f ps. (n, f, ps) \<notin> cptn_mod_nest_call \<or> (\<forall>x c ca psa. ps \<noteq> (LanguageCon.com.Seq (c::('b, 'a, 'c,'d) LanguageCon.com) ca, x) # psa \<or> (\<exists>ps b ba. (n, f, (c, x) # ps) \<in> cptn_mod_nest_call \<and> seq_cond_nest psa ca ps c x ba b f n))" using div_seq_nest by blast have f3: "(P1, snd (last ((Q', t) # xsa))) # ys = (P1, snd (((P0, s) # xs) ! length xs)) # ys" by (simp add: Q' last_length local.Cons) have "fst (last ((Q', t) # xsa)) = LanguageCon.com.Skip" by (metis (no_types) Q' last_ConsR last_length list.distinct(1) local.Cons seq2_ass) then show ?thesis using f3 f2 a1 by (metis (no_types) Cons_lift_append Q' Seq_P_Ends_Normal Q_m ass seq2_ass) qed } } then show ?thesis by auto qed ultimately show ?thesis unfolding min_call_def by auto next case False then have "mp1<n" using mp by auto then have not_min_call_p1_n:"\<not> min_call n \<Gamma> ((P1, snd (last ((P0, s) # xs))) # ys)" using min_call_p1 last_length unfolding min_call_def by metis then have min_call:"min_call n \<Gamma> ((P0, s) # xs)" using min_call last_length unfolding min_call_def by metis then have "(P0, s) # xs = (P0, s) # xa#xsa" using Cons by auto then have big:"biggest_nest_call P0 s (((Q',t))#xsa) \<Gamma> n" proof- have "\<not>(\<exists>xs. min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift P1) xs)" using min_call seq2_ass Cons proof - have "min_call n \<Gamma> ((LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1)" using Seq.prems(1) Seq.prems(2) by blast then show ?thesis by (metis (no_types) Seq_P_Not_finish append_Nil2 list.simps(3) local.Cons min_call_def same_append_eq seq seq2_ass) qed moreover have "\<exists>xs ys. cond_seq_1 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys" using seq2_ass p0_cptn unfolding cond_seq_1_def by (metis last_length local.Cons) moreover have "(SOME xs. \<exists>ys. cond_seq_1 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys) = xs" proof - let ?P = "\<lambda>xsa. \<exists>ys. (n, \<Gamma>, (P0, s) # xsa) \<in> cptn_mod_nest_call \<and> fst (last ((P0, s) # xsa)) = LanguageCon.com.Skip \<and> (n, \<Gamma>, (P1, snd (last ((P0, s) # xsa))) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift P1) xsa @ (P1, snd (last ((P0, s) # xsa))) # ys" have "(\<And>x. \<exists>ys. (n, \<Gamma>, (P0, s) # x) \<in> cptn_mod_nest_call \<and> fst (last ((P0, s) # x)) = LanguageCon.com.Skip \<and> (n, \<Gamma>, (P1, snd (last ((P0, s) # x))) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift P1) x @ (P1, snd (last ((P0, s) # x))) # ys \<Longrightarrow> x = xs)" by (metis Seq_P_Ends_Normal cptn_mod_nest_call.CptnModNestSeq2 seq) moreover have "\<exists>ys. (n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call \<and> fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \<and> (n, \<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys" using ass p0_cptn by (simp add: last_length) ultimately show ?thesis using some_equality[of ?P xs] unfolding cond_seq_1_def by blast qed moreover have "(SOME ys. cond_seq_1 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys) = ys" proof - let ?P = "\<lambda>ys. (n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call \<and> fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \<and> (n, \<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys" have "(n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call \<and> fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \<and> (n, \<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys" using p0_cptn seq2_ass Cons by (simp add: last_length) then show ?thesis using some_equality[of ?P ys] unfolding cond_seq_1_def by fastforce qed ultimately have "biggest_nest_call P0 s xs \<Gamma> n" using not_min_call_p1_n Seq(6) biggest_nest_call.simps(1)[of P0 P1 s "(Q, t) # cfg1" \<Gamma> n] by presburger then show ?thesis using Cons Q' by auto qed have C:"(P0, s) # xs = (P0, s) # (Q', t) # xsa" using Cons Q' by auto have reP0:"redex P0 = (Call f) \<and> \<Gamma> f = Some bdy \<and> (\<exists>saa. s = Normal saa) \<and> t = s" using Seq(5) Q' by auto then have min_call:"min_call n \<Gamma> ((Q', t) # xsa)" using Seq(1)[OF min_call C reP0 big] by auto have p1_n_cptn:"(n, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call" using Seq.prems(1) Seq.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast also then have "(\<forall>m<n. (m, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call)" proof- { fix m assume ass:"m<n" { assume Q_m:"(m, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call" then obtain xsa' s1 s1' where p0_cptn:"(m, \<Gamma>,(Q', t)#xsa') \<in> cptn_mod_nest_call" and seq:"seq_cond_nest cfg1 P1 xsa' Q' t s1 s1' \<Gamma> m" using div_seq_nest[of m \<Gamma> "(Q, t) # cfg1"] Q' by blast then have "xsa=xsa'" using seq2_ass Seq_P_Ends_Normal[of cfg1 P1 xsa Q' t ys m \<Gamma> xsa' s1 s1'] Cons by (metis Cons_lift_append Q' Q_m last.simps last_length list.inject list.simps(3)) then have False using min_call p0_cptn ass unfolding min_call_def by auto } } then show ?thesis by auto qed ultimately show ?thesis unfolding min_call_def by auto qed qed }note l=this {assume ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and> snd (last ((P0, s) # xs)) = Normal s' \<and> s = Normal s'' \<and> (\<exists>ys. (n, \<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift P1) xs @ (LanguageCon.com.Throw, Normal s') # ys)" have ?thesis proof (cases "\<Gamma>\<turnstile>\<^sub>c(LanguageCon.com.Seq P0 P1, s) \<rightarrow> (Q,t)") case True thus ?thesis proof (cases xs) case Nil thus ?thesis using Seq ass by fastforce next case (Cons xa xsa) then obtain ys where seq2_ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and> snd (last ((P0, s) # xs)) = Normal s' \<and> s = Normal s'' \<and> (n, \<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift P1) xs @ (LanguageCon.com.Throw, Normal s') # ys" using ass by auto then have t_eq:"t=Normal s''" using Seq by fastforce obtain mq mp1 where min_call_q:"min_call mq \<Gamma> ((P0, s) # xs)" and min_call_p1:"min_call mp1 \<Gamma> ((Throw, snd (((P0, s) # xs) ! length xs)) # ys)" using seq2_ass minimum_nest_call p0_cptn by (metis last_length) then have mp1_zero:"mp1=0" by (simp add: throw_min_nested_call_0) then have min_call: "min_call n \<Gamma> ((P0, s) # xs)" using seq2_ass min_call_seq3[of n \<Gamma> P0 P1 s "(Q, t) # cfg1" s'' xs s' ys] Seq(3,4) p0_cptn by (metis last_length) have n_z:"n>0" using redex_call_cptn_mod_min_nest_call_gr_zero[OF Seq(3) Seq(4) Seq(5) True] by auto from seq2_ass obtain Q' where Q':"Q=Seq Q' P1 \<and> xa=(Q',t)" unfolding lift_def using Cons proof - assume a1: "\<And>Q'. Q = LanguageCon.com.Seq Q' P1 \<and> xa = (Q', t) \<Longrightarrow> thesis" have "(LanguageCon.com.Seq (fst xa) P1, snd xa) = ((Q, t) # cfg1) ! 0" using seq2_ass unfolding lift_def by (simp add: Cons case_prod_unfold) then show ?thesis using a1 by fastforce qed have big_call:"biggest_nest_call P0 s ((Q',t)#xsa) \<Gamma> n" proof- have "\<not>(\<exists>xs. min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift P1) xs)" using min_call seq2_ass Cons Seq.prems(1) Seq.prems(2) by (metis Seq_P_Not_finish append_Nil2 list.simps(3) min_call_def same_append_eq seq) moreover have "\<not>(\<exists>xs ys. cond_seq_1 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys)" using min_call seq2_ass p0_cptn Cons Seq.prems(1) Seq.prems(2) unfolding cond_seq_1_def by (metis com.distinct(17) com.distinct(71) last_length map_lift_some_eq seq_and_if_not_eq(4)) moreover have "(SOME xs. \<exists>ys s' s''. cond_seq_2 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys s' s'') = xs" proof- let ?P="\<lambda>xsa. \<exists>ys s' s''. s= Normal s'' \<and> (n,\<Gamma>, (P0, s)#xs) \<in> cptn_mod_nest_call \<and> fst(last ((P0, s)#xs)) = Throw \<and> snd(last ((P0, s)#xs)) = Normal s' \<and> (n,\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod_nest_call \<and> ((Q, t) # cfg1)=(map (lift P1) xs)@((Throw,Normal s')#ys)" have "(\<And>x. \<exists>ys s' s''. s= Normal s'' \<and> (n,\<Gamma>, (P0, s)#x) \<in> cptn_mod_nest_call \<and> fst(last ((P0, s)#x)) = Throw \<and> snd(last ((P0, s)#x)) = Normal s' \<and> (n,\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod_nest_call \<and> ((Q, t) # cfg1)=(map (lift P1) x)@((Throw,Normal s')#ys) \<Longrightarrow> x=xs)" using map_lift_some_eq seq2_ass by fastforce moreover have "\<exists>ys s' s''. s= Normal s'' \<and> (n,\<Gamma>, (P0, s)#xs) \<in> cptn_mod_nest_call \<and> fst(last ((P0, s)#xs)) = Throw \<and> snd(last ((P0, s)#xs)) = Normal s' \<and> (n,\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod_nest_call \<and> ((Q, t) # cfg1)=(map (lift P1) xs)@((Throw,Normal s')#ys)" using ass p0_cptn by (simp add: last_length Cons) ultimately show ?thesis using some_equality[of ?P xs] unfolding cond_seq_2_def by blast qed ultimately have "biggest_nest_call P0 s xs \<Gamma> n" using Seq(6) biggest_nest_call.simps(1)[of P0 P1 s "(Q, t) # cfg1" \<Gamma> n] by presburger then show ?thesis using Cons Q' by auto qed have min_call:"min_call n \<Gamma> ((Q',t)#xsa)" using Seq(1)[OF min_call _ _ big_call] Seq(5) Cons Q' by fastforce then have p1_n_cptn:"(n, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call" using Seq.prems(1) Seq.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast also then have "(\<forall>m<n. (m, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call)" proof- { fix m assume ass:"m<n" { assume Q_m:"(m, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call" then obtain xsa' s1 s1' where p0_cptn:"(m, \<Gamma>,(Q', t)#xsa') \<in> cptn_mod_nest_call" and seq:"seq_cond_nest cfg1 P1 xsa' Q' (Normal s'') s1 s1' \<Gamma> m" using div_seq_nest[of m \<Gamma> "(Q, t) # cfg1"] Q' t_eq by blast then have "xsa=xsa'" using seq2_ass Seq_P_Ends_Abort[of cfg1 P1 xsa s' ys Q' s'' m \<Gamma> xsa' s1 s1' ] Cons Q' Q_m by (simp add: Cons_lift_append last_length t_eq) then have False using min_call p0_cptn ass unfolding min_call_def by auto } } then show ?thesis by auto qed ultimately show ?thesis unfolding min_call_def by auto qed next case False then have env:"\<Gamma>\<turnstile>\<^sub>c(LanguageCon.com.Seq P0 P1, s) \<rightarrow>\<^sub>e (Q,t)" using Seq by (meson elim_cptn_mod_nest_step_c min_call_def) moreover then have Q:"Q=Seq P0 P1" using env_c_c' by blast ultimately show ?thesis using Seq proof - obtain nn :: "(('b, 'a, 'c,'d) LanguageCon.com \<times> ('b, 'c) xstate) list \<Rightarrow> ('a \<Rightarrow> ('b, 'a, 'c,'d) LanguageCon.com option) \<Rightarrow> nat \<Rightarrow> nat" where f1: "\<forall>x0 x1 x2. (\<exists>v3<x2. (v3, x1, x0) \<in> cptn_mod_nest_call) = (nn x0 x1 x2 < x2 \<and> (nn x0 x1 x2, x1, x0) \<in> cptn_mod_nest_call)" by moura have f2: "(n, \<Gamma>, (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1) \<in> cptn_mod_nest_call \<and> (\<forall>n. \<not> n < n \<or> (n, \<Gamma>, (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1) \<notin> cptn_mod_nest_call)" using local.Seq(3) local.Seq(4) min_call_def by blast then have "\<not> nn ((Q, t) # cfg1) \<Gamma> n < n \<or> (nn ((Q, t) # cfg1) \<Gamma> n, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call" using False env env_c_c' not_func_redex_cptn_mod_nest_n_env by (metis Seq.prems(1) Seq.prems(2) min_call_def) then show ?thesis using f2 f1 by (meson elim_cptn_mod_nest_call_n min_call_def) qed qed } thus ?thesis using l ass by fastforce qed next case (Catch P0 P1) then obtain xs s' s'' where p0_cptn:"(n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call" and catch:"catch_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \<Gamma> n" using div_catch_nest[of n \<Gamma> cfg] unfolding min_call_def by blast show ?case using catch unfolding catch_cond_nest_def proof assume ass:"(Q, t) # cfg1 = map (lift_catch P1) xs" then obtain Q' xs' where xs':"Q=Catch Q' P1 \<and> xs=(Q',t)#xs'" unfolding lift_catch_def by fastforce then have ctpn_P0:"(P0, s) # xs = (P0, s) # (Q', t) # xs'" by auto then have min_p0:"min_call n \<Gamma> ((P0, s)#xs)" using min_call_catch_c1_not_finish[OF Catch(3) Catch(4) p0_cptn] ass by auto then have ex_xs:"\<exists>xs. min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift_catch P1) xs" using ass by auto then have min_xs:"min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift_catch P1) xs" using min_p0 ass by auto have "xs= (SOME xs. (min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift_catch P1) xs))" proof - have "\<forall>xsa. min_call n \<Gamma> ((P0, s)#xsa) \<and> (Q, t) # cfg1 = map (lift_catch P1) xsa \<longrightarrow> xsa = xs" using xs' ass by (metis map_lift_catch_eq_xs_xs') thus ?thesis using min_xs some_equality by (metis (mono_tags, lifting)) qed then have big:"biggest_nest_call P0 s ((Q', t) # xs') \<Gamma> n" using biggest_nest_call.simps(2)[of P0 P1 s "((Q, t) # cfg1)" \<Gamma> n] Catch(6) xs' ex_xs by auto have reP0:"redex P0 = (Call f) \<and> \<Gamma> f = Some bdy \<and> (\<exists>saa. s = Normal saa) \<and> t = s " using Catch(5) xs' by auto have min_call:"min_call n \<Gamma> ((Q', t) # xs')" using Catch(1)[OF min_p0 ctpn_P0 reP0] big xs' ass by auto thus ?thesis using min_call_catch_not_finish[OF min_call] ass xs' by blast next assume ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and> snd (last ((P0, s) # xs)) = Normal s' \<and> s = Normal s'' \<and> (\<exists>ys. (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<or> fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \<and> (\<exists>ys. (n, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift_catch P1) xs @ (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys)" {assume ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and> snd (last ((P0, s) # xs)) = Normal s' \<and> s = Normal s'' \<and> (\<exists>ys. (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys)" have ?thesis proof (cases xs) case Nil thus ?thesis using Catch ass by fastforce next case (Cons xa xsa) then obtain ys where catch2_ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and> snd (last ((P0, s) # xs)) = Normal s' \<and> s = Normal s'' \<and> (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys" using ass by auto then obtain mq mp1 where min_call_q:"min_call mq \<Gamma> ((P0, s) # xs)" and min_call_p1:"min_call mp1 \<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)" using catch2_ass minimum_nest_call p0_cptn by fastforce then have mp: "mq\<le>n \<and> mp1 \<le>n" using catch2_ass min_call_less_eq_n Catch(3,4) p0_cptn by (metis last_length) have min_call:"min_call n \<Gamma> ((P0, s) # xs) \<or> min_call n \<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)" using catch2_ass min_call_catch3[of n \<Gamma> P0 P1 s'' "(Q, t) # cfg1" xs s' ys] Catch(3,4) p0_cptn by (metis last_length) from catch2_ass obtain Q' where Q':"Q=Catch Q' P1 \<and> xa=(Q',t)" unfolding lift_catch_def proof - assume a1: "\<And>Q'. Q = LanguageCon.com.Catch Q' P1 \<and> xa = (Q', t) \<Longrightarrow> thesis" assume "fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and> snd (last ((P0, s) # xs)) = Normal s' \<and> s = Normal s'' \<and> (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys" then have "(LanguageCon.com.Catch (fst xa) P1, snd xa) = ((Q, t) # cfg1) ! 0" by (simp add: local.Cons prod.case_eq_if) then show ?thesis using a1 by force qed then have q'_n_cptn:"(n,\<Gamma>,(Q',t)#xsa)\<in>cptn_mod_nest_call" using p0_cptn Q' Cons using elim_cptn_mod_nest_call_n by blast show ?thesis proof(cases "mp1=n") case True then have "min_call n \<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)" using min_call_p1 by auto then have min_P1:"min_call n \<Gamma> ((P1, snd ((xa # xsa) ! length xsa)) # ys)" using Cons catch2_ass by fastforce then have p1_n_cptn:"(n, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call" using Catch.prems(1) Catch.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast also then have "(\<forall>m<n. (m, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call)" proof- { fix m assume ass:"m<n" { assume Q_m:"(m, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call" then have t_eq_s:"t=Normal s''" using Catch catch2_ass by fastforce then obtain xsa' s1 s1' where p0_cptn:"(m, \<Gamma>,(Q', t)#xsa') \<in> cptn_mod_nest_call" and catch_cond:"catch_cond_nest cfg1 P1 xsa' Q' (Normal s'') s1 s1' \<Gamma> m" using Q_m div_catch_nest[of m \<Gamma> "(Q, t) # cfg1"] Q' by blast have fst:"fst (last ((Q', Normal s'') # xsa)) = LanguageCon.com.Throw" using catch2_ass Cons Q' by (simp add: last_length t_eq_s) have cfg:"cfg1 = map (lift_catch P1) xsa @ (P1, snd (last ((Q', Normal s'') # xsa))) # ys" using catch2_ass Cons Q' by (simp add: last_length t_eq_s) have snd:"snd (last ((Q', Normal s'') # xsa)) = Normal s'" using catch2_ass Cons Q' by (simp add: last_length t_eq_s) then have "xsa=xsa' \<and> (m, \<Gamma>, (P1, snd (((Q', Normal s'') # xsa) ! length xsa)) # ys) \<in> cptn_mod_nest_call" using catch2_ass Catch_P_Ends_Normal[OF cfg fst snd catch_cond] Cons by auto then have False using min_P1 ass Q' t_eq_s unfolding min_call_def by auto } } then show ?thesis by auto qed ultimately show ?thesis unfolding min_call_def by auto next case False then have "mp1<n" using mp by auto then have not_min_call_p1_n:"\<not> min_call n \<Gamma> ((P1, snd (last ((P0, s) # xs))) # ys)" using min_call_p1 last_length unfolding min_call_def by metis then have min_call:"min_call n \<Gamma> ((P0, s) # xs)" using min_call last_length unfolding min_call_def by metis then have "(P0, s) # xs = (P0, s) # xa#xsa" using Cons by auto then have big:"biggest_nest_call P0 s (((Q',t))#xsa) \<Gamma> n" proof- have "\<not>(\<exists>xs. min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift_catch P1) xs)" using min_call catch2_ass Cons proof - have "min_call n \<Gamma> ((Catch P0 P1, s) # (Q, t) # cfg1)" using Catch.prems(1) Catch.prems(2) by blast then show ?thesis by (metis (no_types) Catch_P_Not_finish append_Nil2 list.simps(3) same_append_eq catch catch2_ass) qed moreover have "\<not>(\<exists>xs ys. cond_catch_1 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys)" unfolding cond_catch_1_def using catch2_ass by (metis Catch_P_Ends_Skip LanguageCon.com.distinct(17) catch last_length) moreover have "\<exists>xs ys. cond_catch_2 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys s' s''" using catch2_ass p0_cptn unfolding cond_catch_2_def last_length by metis moreover have "(SOME xs. \<exists>ys s' s''. cond_catch_2 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys s' s'') = xs" proof - let ?P = "\<lambda>xsa. s = Normal s'' \<and> (n, \<Gamma>, (P0, s) # xsa) \<in> cptn_mod_nest_call \<and> fst (last ((P0, s) # xsa)) = LanguageCon.com.Throw \<and> snd (last ((P0, s) # xsa)) = Normal s' \<and> (n, \<Gamma>, (P1, Normal s') # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift_catch P1) xsa @ (P1, Normal s') # ys" have "(\<And>x. \<exists>ys s' s''. s = Normal s'' \<and> (n, \<Gamma>, (P0, s) # x) \<in> cptn_mod_nest_call \<and> fst (last ((P0, s) # x)) = LanguageCon.com.Throw \<and> snd (last ((P0, s) # x)) = Normal s' \<and> (n, \<Gamma>, (P1, Normal s') # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift_catch P1) x @ (P1, Normal s') # ys \<Longrightarrow> x = xs)" by (metis Catch_P_Ends_Normal catch) moreover have "\<exists>ys. s = Normal s'' \<and> (n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call \<and> fst (last ((P0, s) # xs)) = LanguageCon.com.Throw \<and> snd (last ((P0, s) # xs)) = Normal s' \<and> (n, \<Gamma>, (P1, Normal s') # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, Normal s') # ys" using ass p0_cptn by (metis (full_types) last_length ) ultimately show ?thesis using some_equality[of ?P xs] unfolding cond_catch_2_def by blast qed moreover have "(SOME ys. \<exists>s' s''. cond_catch_2 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys s' s'') = ys" proof - let ?P = "\<lambda>ysa. s = Normal s'' \<and> (n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call \<and> fst (last ((P0, s) # xs)) = LanguageCon.com.Throw \<and> snd (last ((P0, s) # xs)) = Normal s' \<and> (n, \<Gamma>, (P1, Normal s') # ysa) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, Normal s') # ysa" have "(\<And>x. \<exists>s' s''. s = Normal s'' \<and> (n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call \<and> fst (last ((P0, s) # xs)) = LanguageCon.com.Throw \<and> snd (last ((P0, s) # xs)) = Normal s' \<and> (n, \<Gamma>, (P1, Normal s') # x) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, Normal s') # x \<Longrightarrow> x = ys)" using catch2_ass by auto moreover have "s = Normal s'' \<and> (n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call \<and> fst (last ((P0, s) # xs)) = LanguageCon.com.Throw \<and> snd (last ((P0, s) # xs)) = Normal s' \<and> (n, \<Gamma>, (P1, Normal s') # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, Normal s') # ys" using ass p0_cptn by (metis (full_types) catch2_ass last_length p0_cptn) ultimately show ?thesis using some_equality[of ?P ys] unfolding cond_catch_2_def by blast qed ultimately have "biggest_nest_call P0 s xs \<Gamma> n" using not_min_call_p1_n Catch(6) biggest_nest_call.simps(2)[of P0 P1 s "(Q, t) # cfg1" \<Gamma> n] by presburger then show ?thesis using Cons Q' by auto qed have C:"(P0, s) # xs = (P0, s) # (Q', t) # xsa" using Cons Q' by auto have reP0:"redex P0 = (Call f) \<and> \<Gamma> f = Some bdy \<and> (\<exists>saa. s = Normal saa) \<and> t = s " using Catch(5) Q' by auto then have min_call:"min_call n \<Gamma> ((Q', t) # xsa)" using Catch(1)[OF min_call C reP0 big] by auto have p1_n_cptn:"(n, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call" using Catch.prems(1) Catch.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast also then have "(\<forall>m<n. (m, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call)" proof- { fix m assume ass:"m<n" { assume Q_m:"(m, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call" then have t_eq_s:"t=Normal s''" using Catch catch2_ass by fastforce then obtain xsa' s1 s1' where p0_cptn:"(m, \<Gamma>,(Q', t)#xsa') \<in> cptn_mod_nest_call" and catch_cond:"catch_cond_nest cfg1 P1 xsa' Q' (Normal s'') s1 s1' \<Gamma> m" using Q_m div_catch_nest[of m \<Gamma> "(Q, t) # cfg1"] Q' by blast have fst:"fst (last ((Q', Normal s'') # xsa)) = LanguageCon.com.Throw" using catch2_ass Cons Q' by (simp add: last_length t_eq_s) have cfg:"cfg1 = map (lift_catch P1) xsa @ (P1, snd (last ((Q', Normal s'') # xsa))) # ys" using catch2_ass Cons Q' by (simp add: last_length t_eq_s) have snd:"snd (last ((Q', Normal s'') # xsa)) = Normal s'" using catch2_ass Cons Q' by (simp add: last_length t_eq_s) then have "xsa=xsa'" using catch2_ass Catch_P_Ends_Normal[OF cfg fst snd catch_cond] Cons by auto then have False using min_call p0_cptn ass unfolding min_call_def by auto } } then show ?thesis by auto qed ultimately show ?thesis unfolding min_call_def by auto qed qed }note l=this {assume ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \<and> (\<exists>ys. (n, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift_catch P1) xs @ (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys)" have ?thesis proof (cases "\<Gamma>\<turnstile>\<^sub>c(Catch P0 P1, s) \<rightarrow> (Q,t)") case True thus ?thesis proof (cases xs) case Nil thus ?thesis using Catch ass by fastforce next case (Cons xa xsa) then obtain ys where catch2_ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \<and> (n, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift_catch P1) xs @ (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys" using ass by auto then have t_eq:"t=s" using Catch by fastforce obtain mq mp1 where min_call_q:"min_call mq \<Gamma> ((P0, s) # xs)" and min_call_p1:"min_call mp1 \<Gamma> ((Skip, snd (((P0, s) # xs) ! length xs)) # ys)" using catch2_ass minimum_nest_call p0_cptn by (metis last_length) then have mp1_zero:"mp1=0" by (simp add: skip_min_nested_call_0) then have min_call: "min_call n \<Gamma> ((P0, s) # xs)" using catch2_ass min_call_catch2[of n \<Gamma> P0 P1 s "(Q, t) # cfg1" xs ys] Catch(3,4) p0_cptn by (metis last_length) have n_z:"n>0" using redex_call_cptn_mod_min_nest_call_gr_zero[OF Catch(3) Catch(4) Catch(5) True] by auto from catch2_ass obtain Q' where Q':"Q=Catch Q' P1 \<and> xa=(Q',t)" unfolding lift_catch_def using Cons proof - assume a1: "\<And>Q'. Q = Catch Q' P1 \<and> xa = (Q', t) \<Longrightarrow> thesis" have "(Catch (fst xa) P1, snd xa) = ((Q, t) # cfg1) ! 0" using catch2_ass unfolding lift_catch_def by (simp add: Cons case_prod_unfold) then show ?thesis using a1 by fastforce qed have big_call:"biggest_nest_call P0 s ((Q',t)#xsa) \<Gamma> n" proof- have "\<not>(\<exists>xs. min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift_catch P1) xs)" using min_call catch2_ass Cons proof - have "min_call n \<Gamma> ((Catch P0 P1, s) # (Q, t) # cfg1)" using Catch.prems(1) Catch.prems(2) by blast then show ?thesis by (metis (no_types) Catch_P_Not_finish append_Nil2 list.simps(3) same_append_eq catch catch2_ass) qed moreover have "(\<exists>xs ys. cond_catch_1 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys)" using catch2_ass p0_cptn unfolding cond_catch_1_def last_length by metis moreover have "(SOME xs. \<exists>ys. cond_catch_1 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys) = xs" proof - let ?P = "\<lambda>xsa. \<exists>ys. (n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call \<and> fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \<and> (n, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xsa))) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift_catch P1) xsa @ (LanguageCon.com.Skip, snd (last ((P0, s) # xsa))) # ys" have "\<And>xsa. \<exists>ys. (n, \<Gamma>,(P0, s)#xsa) \<in> cptn_mod_nest_call \<and> fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \<and> (n, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xsa))) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift_catch P1) xsa @ (LanguageCon.com.Skip, snd (last ((P0, s) # xsa))) # ys \<Longrightarrow> xsa = xs" using Catch_P_Ends_Skip catch catch2_ass map_lift_catch_some_eq by fastforce moreover have "\<exists>ys. (n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call \<and> fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \<and> (n, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift_catch P1) xs @ (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys" using ass p0_cptn by (simp add: last_length) ultimately show ?thesis using some_equality[of ?P xs] unfolding cond_catch_1_def by blast qed ultimately have "biggest_nest_call P0 s xs \<Gamma> n" using Catch(6) biggest_nest_call.simps(2)[of P0 P1 s "(Q, t) # cfg1" \<Gamma> n] by presburger then show ?thesis using Cons Q' by auto qed have min_call:"min_call n \<Gamma> ((Q',t)#xsa)" using Catch(1)[OF min_call _ _ big_call] Catch(5) Cons Q' by fastforce then have p1_n_cptn:"(n, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call" using Catch.prems(1) Catch.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast also then have "(\<forall>m<n. (m, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call)" proof- { fix m assume ass:"m<n" { assume Q_m:"(m, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call" then obtain xsa' s1 s1' where p0_cptn:"(m, \<Gamma>,(Q', t)#xsa') \<in> cptn_mod_nest_call" and seq:"catch_cond_nest cfg1 P1 xsa' Q' t s1 s1' \<Gamma> m" using div_catch_nest[of m \<Gamma> "(Q, t) # cfg1"] Q' t_eq by blast then have "xsa=xsa'" using catch2_ass Catch_P_Ends_Skip[of cfg1 P1 xsa Q' t ys xsa' s1 s1'] Cons Q' Q_m by (simp add: last_length) then have False using min_call p0_cptn ass unfolding min_call_def by auto } } then show ?thesis by auto qed ultimately show ?thesis unfolding min_call_def by auto qed next case False then have env:"\<Gamma>\<turnstile>\<^sub>c(Catch P0 P1, s) \<rightarrow>\<^sub>e (Q,t)" using Catch by (meson elim_cptn_mod_nest_step_c min_call_def) moreover then have Q:"Q=Catch P0 P1" using env_c_c' by blast ultimately show ?thesis using Catch proof - obtain nn :: "(('b, 'a, 'c,'d) LanguageCon.com \<times> ('b, 'c) xstate) list \<Rightarrow> ('a \<Rightarrow> ('b, 'a, 'c,'d) LanguageCon.com option) \<Rightarrow> nat \<Rightarrow> nat" where f1: "\<forall>x0 x1 x2. (\<exists>v3<x2. (v3, x1, x0) \<in> cptn_mod_nest_call) = (nn x0 x1 x2 < x2 \<and> (nn x0 x1 x2, x1, x0) \<in> cptn_mod_nest_call)" by moura have f2: "(n, \<Gamma>, (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1) \<in> cptn_mod_nest_call \<and> (\<forall>n. \<not> n < n \<or> (n, \<Gamma>, (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1) \<notin> cptn_mod_nest_call)" using local.Catch(3) local.Catch(4) min_call_def by blast then have "\<not> nn ((Q, t) # cfg1) \<Gamma> n < n \<or> (nn ((Q, t) # cfg1) \<Gamma> n, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call" using False env env_c_c' not_func_redex_cptn_mod_nest_n_env by (metis Catch.prems(1) Catch.prems(2) min_call_def) then show ?thesis using f2 f1 by (meson elim_cptn_mod_nest_call_n min_call_def) qed qed } thus ?thesis using l ass by fastforce qed qed (fastforce)+ *) lemma cptn_mod_nest_n_1: assumes a0:"(n,\<Gamma>,cfs) \<in> cptn_mod_nest_call" and a1:"cfs=(p,s)#cfs'" and a2:"\<not> (min_call n \<Gamma> cfs)" shows "(n-1,\<Gamma>,cfs) \<in> cptn_mod_nest_call" using a0 a1 a2 by (metis (no_types, lifting) Suc_diff_1 Suc_leI cptn_mod_nest_mono less_nat_zero_code min_call_def not_less) lemma cptn_mod_nest_tl_n_1: assumes a0:"(n,\<Gamma>,cfs) \<in> cptn_mod_nest_call" and a1:"cfs=(p,s)#(q,t)#cfs'" and a2:"\<not> (min_call n \<Gamma> cfs)" shows "(n-1,\<Gamma>,(q,t)#cfs') \<in> cptn_mod_nest_call" using a0 a1 a2 by (meson elim_cptn_mod_nest_call_n cptn_mod_nest_n_1) lemma cptn_mod_nest_tl_not_min: assumes a0:"(n,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and a1:"cfg=(p,s)#cfg'" and a2:"\<not> (min_call n \<Gamma> cfg)" shows "\<not> (min_call n \<Gamma> cfg')" proof (cases cfg') case Nil have "(\<Gamma>, []) \<notin> cptn" using cptn.simps by auto then show ?thesis unfolding min_call_def using cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod local.Nil by blast next case (Cons xa cfga) then obtain q t where "xa = (q,t)" by fastforce then have "(n-1,\<Gamma>,cfg') \<in> cptn_mod_nest_call" using a0 a1 a2 cptn_mod_nest_tl_n_1 Cons by fastforce also then have "(n,\<Gamma>,cfg') \<in> cptn_mod_nest_call" using cptn_mod_nest_mono Nat.diff_le_self by blast ultimately show ?thesis unfolding min_call_def using a0 a2 min_call_def by force qed definition cp :: "('g\<times>'l,'p,'f,'e) body \<Rightarrow> ('g\<times>'l,'p,'f,'e)com \<Rightarrow> (('g\<times>'l)\<times>('l list),'f) xstate \<Rightarrow> (('g,'l,'p,'f,'e) confs) set" where "cp \<Gamma> P s \<equiv> {(\<Gamma>1,l). l!0=(P,s) \<and> (\<Gamma>,l) \<in> cptn \<and> \<Gamma>1=\<Gamma>}" lemma cp_sub: assumes a0: "(\<Gamma>,(x#l0)@l1) \<in> cp \<Gamma> P s" shows "(\<Gamma>,(x#l0)) \<in> cp \<Gamma> P s" proof - have "(x#l0)!0 = (P,s)" using a0 unfolding cp_def by auto also have "(\<Gamma>,(x#l0))\<in>cptn" using a0 unfolding cp_def using cptn_dest_2 by fastforce ultimately show ?thesis using a0 unfolding cp_def by blast qed definition cpn :: "nat \<Rightarrow> ('g\<times>'l,'p,'f,'e) body \<Rightarrow> ('g\<times>'l,'p,'f,'e)com \<Rightarrow> (('g\<times>'l)\<times>('l list),'f) xstate \<Rightarrow> (('g,'l,'p,'f,'e) confs) set" where "cpn n \<Gamma> P s \<equiv> {(\<Gamma>1,l). l!0=(P,s) \<and> (n,\<Gamma>,l) \<in> cptn_mod_nest_call \<and> \<Gamma>1=\<Gamma>}" end
(* Title: HOL/Auth/n_germanSymIndex_lemma_inv__12_on_rules.thy Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences *) header{*The n_germanSymIndex Protocol Case Study*} theory n_germanSymIndex_lemma_inv__12_on_rules imports n_germanSymIndex_lemma_on_inv__12 begin section{*All lemmas on causal relation between inv__12*} lemma lemma_inv__12_on_rules: assumes b1: "r \<in> rules N" and b2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__12 p__Inv0 p__Inv2)" shows "invHoldForRule s f r (invariants N)" proof - have c1: "(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)\<or> (\<exists> i. i\<le>N\<and>r=n_SendReqS i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvReqE N i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInvAck i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendGntS i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendGntE N i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvGntS i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" apply (cut_tac b1, auto) done moreover { assume d1: "(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_StoreVsinv__12) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendReqSVsinv__12) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendReqE__part__0Vsinv__12) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendReqE__part__1Vsinv__12) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvReqSVsinv__12) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqE N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvReqEVsinv__12) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInv__part__0Vsinv__12) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInv__part__1Vsinv__12) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInvAckVsinv__12) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvInvAckVsinv__12) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendGntS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendGntSVsinv__12) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendGntE N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendGntEVsinv__12) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvGntSVsinv__12) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvGntEVsinv__12) done } ultimately show "invHoldForRule s f r (invariants N)" by satx qed end
lemma closed_scaling: fixes S :: "'a::real_normed_vector set" assumes "closed S" shows "closed ((\<lambda>x. c *\<^sub>R x) ` S)"
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import algebra.group.pi import algebra.category.Group.preadditive import category_theory.limits.shapes.biproducts import algebra.category.Group.limits /-! # The category of abelian groups has finite biproducts -/ open category_theory open category_theory.limits open_locale big_operators universe u namespace AddCommGroup -- As `AddCommGroup` is preadditive, and has all limits, it automatically has biproducts. instance : has_binary_biproducts AddCommGroup := has_binary_biproducts.of_has_binary_products instance : has_finite_biproducts AddCommGroup := has_finite_biproducts.of_has_finite_products -- We now construct explicit limit data, -- so we can compare the biproducts to the usual unbundled constructions. /-- Construct limit data for a binary product in `AddCommGroup`, using `AddCommGroup.of (G × H)`. -/ @[simps cone_X is_limit_lift] def binary_product_limit_cone (G H : AddCommGroup.{u}) : limits.limit_cone (pair G H) := { cone := { X := AddCommGroup.of (G × H), π := { app := λ j, discrete.cases_on j (λ j, walking_pair.cases_on j (add_monoid_hom.fst G H) (add_monoid_hom.snd G H)), naturality' := by rintros ⟨⟨⟩⟩ ⟨⟨⟩⟩ ⟨⟨⟨⟩⟩⟩; refl, }}, is_limit := { lift := λ s, add_monoid_hom.prod (s.π.app ⟨walking_pair.left⟩) (s.π.app ⟨walking_pair.right⟩), fac' := by { rintros s (⟨⟩|⟨⟩); { ext x, simp, } }, uniq' := λ s m w, begin ext; [rw ← w ⟨walking_pair.left⟩, rw ← w ⟨walking_pair.right⟩]; refl, end, } } @[simp] lemma binary_product_limit_cone_cone_π_app_left (G H : AddCommGroup.{u}) : (binary_product_limit_cone G H).cone.π.app ⟨walking_pair.left⟩ = add_monoid_hom.fst G H := rfl @[simp] lemma binary_product_limit_cone_cone_π_app_right (G H : AddCommGroup.{u}) : (binary_product_limit_cone G H).cone.π.app ⟨walking_pair.right⟩ = add_monoid_hom.snd G H := rfl /-- We verify that the biproduct in AddCommGroup is isomorphic to the cartesian product of the underlying types: -/ @[simps hom_apply] noncomputable def biprod_iso_prod (G H : AddCommGroup.{u}) : (G ⊞ H : AddCommGroup) ≅ AddCommGroup.of (G × H) := is_limit.cone_point_unique_up_to_iso (binary_biproduct.is_limit G H) (binary_product_limit_cone G H).is_limit @[simp, elementwise] lemma biprod_iso_prod_inv_comp_fst (G H : AddCommGroup.{u}) : (biprod_iso_prod G H).inv ≫ biprod.fst = add_monoid_hom.fst G H := is_limit.cone_point_unique_up_to_iso_inv_comp _ _ (discrete.mk walking_pair.left) @[simp, elementwise] lemma biprod_iso_prod_inv_comp_snd (G H : AddCommGroup.{u}) : (biprod_iso_prod G H).inv ≫ biprod.snd = add_monoid_hom.snd G H := is_limit.cone_point_unique_up_to_iso_inv_comp _ _ (discrete.mk walking_pair.right) variables {J : Type u} (f : J → AddCommGroup.{u}) namespace has_limit /-- The map from an arbitrary cone over a indexed family of abelian groups to the cartesian product of those groups. -/ @[simps] def lift (s : fan f) : s.X ⟶ AddCommGroup.of (Π j,f j) := { to_fun := λ x j, s.π.app ⟨j⟩ x, map_zero' := by { ext, simp }, map_add' := λ x y, by { ext, simp }, } /-- Construct limit data for a product in `AddCommGroup`, using `AddCommGroup.of (Π j, F.obj j)`. -/ @[simps] def product_limit_cone : limits.limit_cone (discrete.functor f) := { cone := { X := AddCommGroup.of (Π j, f j), π := discrete.nat_trans (λ j, pi.eval_add_monoid_hom (λ j, f j) j.as), }, is_limit := { lift := lift f, fac' := λ s j, by { cases j, ext, simp, }, uniq' := λ s m w, begin ext x j, dsimp only [has_limit.lift], simp only [add_monoid_hom.coe_mk], exact congr_arg (λ g : s.X ⟶ f j, (g : s.X → f j) x) (w ⟨j⟩), end, }, } end has_limit open has_limit /-- We verify that the biproduct we've just defined is isomorphic to the AddCommGroup structure on the dependent function type -/ @[simps hom_apply] noncomputable def biproduct_iso_pi [fintype J] (f : J → AddCommGroup.{u}) : (⨁ f : AddCommGroup) ≅ AddCommGroup.of (Π j, f j) := is_limit.cone_point_unique_up_to_iso (biproduct.is_limit f) (product_limit_cone f).is_limit @[simp, elementwise] lemma biproduct_iso_pi_inv_comp_π [fintype J] (f : J → AddCommGroup.{u}) (j : J) : (biproduct_iso_pi f).inv ≫ biproduct.π f j = pi.eval_add_monoid_hom (λ j, f j) j := is_limit.cone_point_unique_up_to_iso_inv_comp _ _ (discrete.mk j) end AddCommGroup
@system Root(Organ) begin end
The monomial $a^0$ is equal to the polynomial $a$.
If $x$ is an algebraic integer, then so is $-x$.
import Data.Complex rootsOfUnity n = [cis (2*pi*k/n) | k <- [0..n-1]]
lemma residue_diff: assumes "open s" "z \<in> s" and f_holo: "f holomorphic_on s - {z}" and g_holo:"g holomorphic_on s - {z}" shows "residue (\<lambda>z. f z - g z) z= residue f z - residue g z"
If $s$ is a compact set in $\mathbb{R}^n$ and $c$ is a bounded component of the complement of $s$, then there is no continuous map from $s \cup c$ to the unit sphere that maps $s$ to the antipodal map of $s$ and $c$ to the unit sphere.
{-# OPTIONS --cubical --safe --postfix-projections #-} open import Prelude open import Relation.Binary module Data.RBTree {e} {E : Type e} {r₁ r₂} (totalOrder : TotalOrder E r₁ r₂) where open import Relation.Binary.Construct.Bounded totalOrder open TotalOrder totalOrder using (_≤?_) data Colour : Type where red black : Colour add-black : Colour → ℕ → ℕ add-black red = λ n → n add-black black = suc private variable n : ℕ data Tree (lb ub : [∙]) : ℕ → Type (e ℓ⊔ r₂) where leaf : lb [≤] ub → Tree lb ub n node : (x : E) → (c : Colour) → Tree lb [ x ] n → Tree [ x ] ub n → Tree lb ub (add-black c n) private variable lb ub : [∙] IsBlack : Tree lb ub n → Type IsBlack (leaf x) = ⊤ IsBlack (node x red tr tr₁) = ⊥ IsBlack (node x black tr tr₁) = ⊤ Valid-rec : Tree lb ub n → Type Valid-rec (leaf x) = ⊤ Valid-rec (node x red xs ys) = IsBlack xs × IsBlack ys × Valid-rec xs × Valid-rec ys Valid-rec (node x black xs ys) = Valid-rec xs × Valid-rec ys Valid : Tree lb ub n → Type Valid tr = IsBlack tr × Valid-rec tr -- insertWithin : (x : E) → -- (lb [≤] [ x ]) → -- ([ x ] [≤] ub) → -- (tr : Tree lb ub n) → -- Valid-rec tr → -- ∃ c Σ (Tree lb ub (add-black c n)) Valid-rec -- insertWithin x lb≤x x≤ub (leaf _) val = red , node x red (leaf lb≤x) (leaf x≤ub) , tt , tt , tt , tt -- insertWithin x lb≤x x≤ub (node y c ls rs) val with x ≤? y -- insertWithin x lb≤x x≤ub (node y red ls rs) val | inl x≤y with insertWithin x lb≤x x≤y ls (fst (snd (snd val))) -- insertWithin x lb≤x x≤ub (node y red ls rs) val | inl x≤y | red , ls′ , val′ = black , node y black ls′ rs , val′ , snd (snd (snd val)) -- insertWithin x lb≤x x≤ub (node y red ls rs) val | inl x≤y | black , ls′ , val′ = {!{!!} , node y {!!} ls′ rs , {!!}!} -- insertWithin x lb≤x x≤ub (node y black ls rs) val | inl x≤y with insertWithin x lb≤x x≤y ls (fst val) -- insertWithin x lb≤x x≤ub (node y black ls rs) val | inl x≤y | res = {!!} -- insertWithin x lb≤x x≤ub (node y c ls rs) val | inr y≤x = {!!} -- -- insertWithin x lb≤x x≤ub (node y ls rs) with x ≤? y -- -- insertWithin x lb≤x x≤ub (node y ls rs) | inl x≤y = node y (insertWithin x lb≤x x≤y ls) rs -- -- insertWithin x lb≤x x≤ub (node y ls rs) | inr y≤x = node y ls (insertWithin x y≤x x≤ub rs)
State Before: α : Type u_1 inst✝ : HeytingAlgebra α a b : α ha : IsRegular a hb : IsRegular b ⊢ IsRegular (a ⇨ b) State After: no goals Tactic: rw [IsRegular, compl_compl_himp_distrib, ha.eq, hb.eq]
""" RiemannMatrix Type containing information about the Riemann Matrix, for use in computing the Riemann theta function. """ struct RiemannMatrix τ::Array{<:Number} # matrix in Siegel upper-half space g::Integer # genus X::Array{<:Real} # real part of τ Y::Array{<:Real} # imaginary part of τ T::Array{<:Real} # upper triangular matrix in Cholesky factorization of Y ellipsoid::Array{} # points to sum over for computing theta functions """ RiemannMatrix(τ, siegel=false, ϵ=1.0e-12, nderivs=4) Construct a RiemannMatrix type using a matrix τ in the Siegel upper-half space, for use in computing the Riemann theta function. # Arguments - `τ::Array{<:Number}`: 2-dimensional array of complex numbers - `siegel::Bool=false`: do a siegel transformation on τ if true, and use the input matrix otherwise - `ϵ::Real=1.0e-12`: absolute error in value of theta function or its derivatives - `nderivs::Integer=4`: highest order of the derivatives of the theta function # Examples ```julia julia> RiemannMatrix([1+im -1; -1 1+im], siegel=true, nderivs=2) ``` """ function RiemannMatrix(τ::Array{<:Number}; siegel::Bool=false, ϵ::Real=1.0e-12, nderivs::Integer=4) τ = (siegel ? siegel_transform(τ)[2] : τ); X = real(τ); Y = imag(τ); g = size(Y)[1]; T = (g > 1 ? convert(Array{Float64}, cholesky(Symmetric(Y)).U) : sqrt.(Y)); ρ = svp(T)[2]*sqrt(π); # length of shortest vector in lattice generated by √π*T radius = [radius_ellipsoid(ϵ, T, Y, ρ, i) for i=0:nderivs]; # radius of ellipsoids for computing theta function, and up to nderivs derivatives. ellipsoid = [ellipsoid_uniform(T, r) for r in radius]; new(τ, g, X, Y, T, ellipsoid) end end """ random_siegel(g) Sample a random matrix in the Siegel upper half space with genus g. # Arguments - `g::Integer`: genus. # Examples ```julia julia> random_siegel(5) ``` """ function random_siegel(g::Integer) Mx = 2*rand(g, g) - ones(g,g); # entries are random between [-1,1) My = 2*rand(g, g) - ones(g,g); # entries are random between [-1,1) τ = Symmetric((1/2)*(transpose(Mx) + Mx)) + Symmetric(transpose(My)*My)*im; # symmetric real part and psd imaginary part return convert(Array, τ); end
""" Ledgers This package provides support for general financial ledgers See README.md for the full documentation Copyright 2019-2020, Eric Forgy, Scott P. Jones and other contributors Licensed under MIT License, see LICENSE.md """ module Ledgers using UUIDs, StructArrays, AbstractTrees import Instruments using Instruments: Position # Although importing Instruments is enough to extend the methods below, we still import # them explicitly so we can use them like `Ledgers.position` instead of `Instruments.position`. # Unfortunately, `Base` also exports `position`. import Instruments: instrument, currency, symbol, position, amount export Identifier, AccountId, AbstractAccount, AccountWrapper, AccountNumber export LedgerAccount, Ledger, Entry, Account, AccountGroup, ledgeraccount, add_account, ledger export id, balance, credit!, debit!, post!, add_entry! # Although the methods below are exported by Instruments, we export them explicitly # because we do not expect users to use `Instruments` directly. export instrument, currency, symbol, position, amount include("accounts.jl") abstract type AbstractLedgerAccount{P} <: AbstractAccount{P} end struct Entry{P,A<:AbstractLedgerAccount{P}} debit::A credit::A amount::P end struct LedgerId <: Identifier value::UUID end LedgerId() = LedgerId(uuid4()) struct Ledger{P <: Position,A<:AbstractLedgerAccount{P}} id::LedgerId accounts::Dict{AccountId,A} entries::Vector{Entry{P}} end function Ledger(accounts::AbstractVector{<:AbstractLedgerAccount{P}}, entries::AbstractVector{Entry{P}}; id=LedgerId()) where {P <: Position} ledger = Ledger(P) add_account!.(Ref(ledger), accounts) add_entry!.(Ref(ledger), entries) return ledger end Base.iterate(ledger::Ledger, state=1) = iterate(ledger.entries, state) Ledger(::Type{P}) where {P <: Position} = Ledger{P,LedgerAccount{P}}(LedgerId(),Dict{AccountId,LedgerAccount{P}}(), Vector{Entry{P}}()) mutable struct LedgerAccount{P} <: AbstractLedgerAccount{P} id::AccountId balance::P ledger::Ledger{P} end function LedgerAccount(balance::P, ledger) where {P <: Position} acc = LedgerAccount{P}(AccountId(), balance, ledger) add_account!(ledger, acc) acc end LedgerAccount(::Type{P}, ledger) where {P <: Position} = LedgerAccount(P(0), ledger) ledgeraccount(acc::LedgerAccount) = acc ledgeraccount(acc::AbstractAccount) = ledgeraccount(acc.account) ledger(acc::LedgerAccount) = acc.ledger ledger(acc::AbstractAccount) = ledger(ledgeraccount(acc)) balance(acc::LedgerAccount) = acc.balance balance(acc::AbstractAccount) = balance(ledgeraccount(acc)) id(acc::LedgerAccount) = acc.id function add_account!(ledger::Ledger{P}, acc::AbstractAccount{P}) where {P <: Position} acc = ledgeraccount(acc) if id(acc) ∈ keys(ledger.accounts) warn("Account already in ledger.") return end ledger.accounts[acc.id] = acc end function add_accounts!(ledger::Ledger{P}, ag::AccountGroup) where P for acc in ag add_account!(ledger, acc) end ledger end function add_entry!(ledger::Ledger, entry::Entry) (id(entry.credit) ∈ keys(ledger.accounts) && id(entry.debit) ∈ keys(ledger.accounts)) || error("Unknown account in entry.") push!(ledger.entries, entry) post!(entry) end Instruments.symbol(::Type{A}) where {P, A<:AbstractAccount{P}} = symbol(P) Instruments.currency(::Type{A}) where {P, A<:AbstractAccount{P}} = currency(P) Instruments.instrument(::Type{A}) where {P, A<:AbstractAccount{P}} = instrument(P) Instruments.position(::Type{A}) where {P, A<:AbstractAccount{P}} = P Instruments.amount(acc::AbstractAccount) = amount(balance(acc)) debit!(acc::LedgerAccount, amt::Position) = (acc.balance -= amt) credit!(acc::LedgerAccount, amt::Position) = (acc.balance += amt) function post!(entry::Entry) debit!(ledgeraccount(entry.debit), entry.amount) credit!(ledgeraccount(entry.credit), entry.amount) end Base.getindex(ledger::Ledger, ix) = ledger.entries[ix] Base.getindex(ledger::Ledger, id::AccountId) = ledger.accounts[id] Base.getindex(grp::AccountGroup, id::AccountId) = grp.accounts[id] # struct EntityId <: Identifier # value::UUID # end # EntityId() = EntityId(uuid4()) # struct Entity # id::EntityId # name::String # ledgers::Dict{Type{<:Position},Ledger{<:AbstractAccount}} # end # const chartofaccounts = Dict{String,AccountGroup{<:Cash}}() # iscontra(a::AccountGroup) = !isequal(a,a.parent) && !isequal(a.parent,getledger(a)) && !isequal(a.parent.isdebit,a.isdebit) # function loadchart(ledgername,ledgercode,csvfile) # data, headers = readdlm(csvfile,',',String,header=true) # nrow,ncol = size(data) # ledger = add(AccountGroup(ledgername,ledgercode)) # for i = 1:nrow # row = data[i,:] # number = row[1] # name = row[2] # parent = chartofaccounts[row[3]] # isdebit = isequal(row[4],"Debit") # add(AccountGroup(parent,name,number,isdebit)) # end # return ledger # end # function trim(a::AccountGroup,newparent::AccountGroup=AccountGroup(a.parent.name,a.parent.number)) # newaccount = isequal(a,a.parent) ? newparent : AccountGroup(newparent,a.name,a.number,a.isdebit,a.balance) # for subaccount in a.accounts # balance(subaccount).a_print_account function _print_account(io::IO, acc) iobuff = IOBuffer() isempty(acc.number.value) || print(iobuff,"[$(acc.number)] ") print(iobuff,acc.name,": ") acc.isdebit ? print(iobuff,balance(acc)) : print(iobuff,-balance(acc)) print(io,String(take!(iobuff))) end Base.show(io::IO, id::Identifier) = print(io, id.value) Base.show(io::IO, number::AccountNumber) = print(io, number.value) Base.show(io::IO, acc::LedgerAccount) = print(io, "$(string(id(acc))): $(balance(acc))") Base.show(io::IO, acc::AbstractAccount) = _print_account(io, acc) Base.show(io::IO, acc::AccountGroup) = print_tree(io, acc) Base.show(io::IO, entry::Entry) = print_tree(io, entry) Base.show(io::IO, ledger::Ledger) = print_tree(io, ledger) Base.show(io::IO, a::Vector{<:AbstractAccount}) = print_tree(io, a) AbstractTrees.printnode(io::IO, acc::Ledger{P}) where {P <: Position} = print(io, "$(symbol(P)) Ledger: [$(acc.id)]") AbstractTrees.children(acc::Ledger) = collect(values(acc.accounts)) AbstractTrees.printnode(io::IO, acc::AccountGroup) = _print_account(io, acc) AbstractTrees.children(acc::AccountGroup) = vcat(collect(values(acc.subgroups)), collect(values(acc.accounts))) AbstractTrees.printnode(io::IO, b::AbstractVector{<:AbstractAccount}) = isempty(b) ? print(io, "Accounts: None") : print(io, "Accounts:") AbstractTrees.children(b::AbstractVector{<:AbstractAccount}) = b AbstractTrees.children(entry::Entry) = [entry.debit, entry.credit] AbstractTrees.printnode(io::IO, ::Entry) = print(io, "Entry:") end # module Ledgers
The battalion embarked for England in May 1940 as part of 5th Infantry Brigade , 2nd New Zealand Division . Arriving in June , it spent the remainder of the year on garrison duties in the south of England . In March 1941 it travelled for Egypt and then onto Greece . Andrew led the battalion through the subsequent Battle of Greece , during which it saw little action , and the Battle of Crete .
module ExactLength %default total data Vect : Nat -> Type -> Type where Nil : Vect Z a (::) : a -> Vect k a -> Vect (S k) a {- exactLength : { m : _ } -> (len : Nat) -> Vect m a -> Maybe (Vect len a) exactLength len input = case m == len of False => Nothing True => Just input -} -- build-up: equality of Nats (EqNat.idr) data EqNat : Nat -> Nat -> Type where Same : (num : Nat) -> EqNat num num sameS : (eq : EqNat k j) -> EqNat (S k) (S j) sameS (Same l) = Same (S l) checkEqNat : (num1 : Nat) -> (num2 : Nat) -> Maybe (EqNat num1 num2) checkEqNat Z Z = Just (Same Z) checkEqNat Z _ = Nothing checkEqNat _ Z = Nothing checkEqNat (S k) (S l) = case checkEqNat k l of Nothing => Nothing Just eq => Just (sameS eq) exactLength : { m : Nat } -> (len : Nat) -> Vect m a -> Maybe (Vect len a) exactLength len input = case checkEqNat m len of Nothing => Nothing Just (Same len) => Just input -- implementation of checkEqNat using the generic equality type {- data (=) : a -> b -> Type where Refl : x = x Synonym: Equal -} checkEqNat' : (num1 : Nat) -> (num2 : Nat) -> Maybe (num1 = num2) checkEqNat' Z Z = Just Refl checkEqNat' Z _ = Nothing checkEqNat' _ Z = Nothing checkEqNat' (S k) (S l) = case checkEqNat' k l of Nothing => Nothing Just eq => Just (cong S eq) exactLength' : { m : Nat } -> (len : Nat) -> Vect m a -> Maybe (Vect len a) exactLength' len input = case checkEqNat' m len of Nothing => Nothing Just Refl => Just input
[STATEMENT] lemma fo_nmlzd_mono_sub: "X \<subseteq> X' \<Longrightarrow> fo_nmlzd X xs \<Longrightarrow> fo_nmlzd X' xs" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>X \<subseteq> X'; fo_nmlzd X xs\<rbrakk> \<Longrightarrow> fo_nmlzd X' xs [PROOF STEP] by (meson fo_nmlzd_def order_trans)
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import topology.sheaves.presheaf import category_theory.limits.punit import category_theory.limits.shapes.products import category_theory.limits.shapes.equalizers import category_theory.full_subcategory /-! # The sheaf condition in terms of an equalizer of products Here we set up the machinery for the "usual" definition of the sheaf condition, e.g. as in https://stacks.math.columbia.edu/tag/0072 in terms of an equalizer diagram where the two objects are `∏ F.obj (U i)` and `∏ F.obj (U i) ⊓ (U j)`. -/ universes v u noncomputable theory open category_theory open category_theory.limits open topological_space open opposite open topological_space.opens namespace Top variables {C : Type u} [category.{v} C] [has_products C] variables {X : Top.{v}} (F : presheaf C X) {ι : Type v} (U : ι → opens X) namespace presheaf namespace sheaf_condition_equalizer_products /-- The product of the sections of a presheaf over a family of open sets. -/ def pi_opens : C := ∏ (λ i : ι, F.obj (op (U i))) /-- The product of the sections of a presheaf over the pairwise intersections of a family of open sets. -/ def pi_inters : C := ∏ (λ p : ι × ι, F.obj (op (U p.1 ⊓ U p.2))) /-- The morphism `Π F.obj (U i) ⟶ Π F.obj (U i) ⊓ (U j)` whose components are given by the restriction maps from `U i` to `U i ⊓ U j`. -/ def left_res : pi_opens F U ⟶ pi_inters F U := pi.lift (λ p : ι × ι, pi.π _ p.1 ≫ F.map (inf_le_left (U p.1) (U p.2)).op) /-- The morphism `Π F.obj (U i) ⟶ Π F.obj (U i) ⊓ (U j)` whose components are given by the restriction maps from `U j` to `U i ⊓ U j`. -/ def right_res : pi_opens F U ⟶ pi_inters F U := pi.lift (λ p : ι × ι, pi.π _ p.2 ≫ F.map (inf_le_right (U p.1) (U p.2)).op) /-- The morphism `F.obj U ⟶ Π F.obj (U i)` whose components are given by the restriction maps from `U j` to `U i ⊓ U j`. -/ def res : F.obj (op (supr U)) ⟶ pi_opens F U := pi.lift (λ i : ι, F.map (topological_space.opens.le_supr U i).op) @[simp] lemma res_π (i : ι) : res F U ≫ limit.π _ i = F.map (opens.le_supr U i).op := by rw [res, limit.lift_π, fan.mk_π_app] lemma w : res F U ≫ left_res F U = res F U ≫ right_res F U := begin dsimp [res, left_res, right_res], ext, simp only [limit.lift_π, limit.lift_π_assoc, fan.mk_π_app, category.assoc], rw [←F.map_comp], rw [←F.map_comp], congr, end /-- The equalizer diagram for the sheaf condition. -/ @[reducible] def diagram : walking_parallel_pair.{v} ⥤ C := parallel_pair (left_res F U) (right_res F U) /-- The restriction map `F.obj U ⟶ Π F.obj (U i)` gives a cone over the equalizer diagram for the sheaf condition. The sheaf condition asserts this cone is a limit cone. -/ def fork : fork.{v} (left_res F U) (right_res F U) := fork.of_ι _ (w F U) @[simp] lemma fork_X : (fork F U).X = F.obj (op (supr U)) := rfl @[simp] lemma fork_ι : (fork F U).ι = res F U := rfl @[simp] lemma fork_π_app_walking_parallel_pair_zero : (fork F U).π.app walking_parallel_pair.zero = res F U := rfl @[simp] lemma fork_π_app_walking_parallel_pair_one : (fork F U).π.app walking_parallel_pair.one = res F U ≫ left_res F U := rfl variables {F} {G : presheaf C X} /-- Isomorphic presheaves have isomorphic `pi_opens` for any cover `U`. -/ @[simp] def pi_opens.iso_of_iso (α : F ≅ G) : pi_opens F U ≅ pi_opens G U := pi.map_iso (λ X, α.app _) /-- Isomorphic presheaves have isomorphic `pi_inters` for any cover `U`. -/ @[simp] def pi_inters.iso_of_iso (α : F ≅ G) : pi_inters F U ≅ pi_inters G U := pi.map_iso (λ X, α.app _) /-- Isomorphic presheaves have isomorphic sheaf condition diagrams. -/ def diagram.iso_of_iso (α : F ≅ G) : diagram F U ≅ diagram G U := nat_iso.of_components begin rintro ⟨⟩, exact pi_opens.iso_of_iso U α, exact pi_inters.iso_of_iso U α end begin rintro ⟨⟩ ⟨⟩ ⟨⟩, { simp, }, { ext, simp [left_res], }, { ext, simp [right_res], }, { simp, }, end. /-- If `F G : presheaf C X` are isomorphic presheaves, then the `fork F U`, the canonical cone of the sheaf condition diagram for `F`, is isomorphic to `fork F G` postcomposed with the corresponding isomorphism between sheaf condition diagrams. -/ def fork.iso_of_iso (α : F ≅ G) : fork F U ≅ (cones.postcompose (diagram.iso_of_iso U α).inv).obj (fork G U) := begin fapply fork.ext, { apply α.app, }, { ext, dunfold fork.ι, -- Ugh, `simp` can't unfold abbreviations. simp [res, diagram.iso_of_iso], } end section open_embedding variables {V : Top.{v}} {j : V ⟶ X} (oe : open_embedding j) variables (𝒰 : ι → opens V) /-- Push forward a cover along an open embedding. -/ @[simp] def cover.of_open_embedding : ι → opens X := (λ i, oe.is_open_map.functor.obj (𝒰 i)) /-- The isomorphism between `pi_opens` corresponding to an open embedding. -/ @[simp] def pi_opens.iso_of_open_embedding : pi_opens (oe.is_open_map.functor.op ⋙ F) 𝒰 ≅ pi_opens F (cover.of_open_embedding oe 𝒰) := pi.map_iso (λ X, F.map_iso (iso.refl _)) /-- The isomorphism between `pi_inters` corresponding to an open embedding. -/ @[simp] def pi_inters.iso_of_open_embedding : pi_inters (oe.is_open_map.functor.op ⋙ F) 𝒰 ≅ pi_inters F (cover.of_open_embedding oe 𝒰) := pi.map_iso (λ X, F.map_iso begin dsimp [is_open_map.functor], exact iso.op { hom := hom_of_le (by { simp only [oe.to_embedding.inj, set.image_inter], apply le_refl _, }), inv := hom_of_le (by { simp only [oe.to_embedding.inj, set.image_inter], apply le_refl _, }), }, end) /-- The isomorphism of sheaf condition diagrams corresponding to an open embedding. -/ def diagram.iso_of_open_embedding : diagram (oe.is_open_map.functor.op ⋙ F) 𝒰 ≅ diagram F (cover.of_open_embedding oe 𝒰) := nat_iso.of_components begin rintro ⟨⟩, exact pi_opens.iso_of_open_embedding oe 𝒰, exact pi_inters.iso_of_open_embedding oe 𝒰 end begin rintro ⟨⟩ ⟨⟩ ⟨⟩, { simp, }, { ext, dsimp [left_res, is_open_map.functor], simp only [limit.lift_π, cones.postcompose_obj_π, iso.op_hom, discrete.nat_iso_hom_app, functor.map_iso_refl, functor.map_iso_hom, lim_map_π_assoc, limit.lift_map, fan.mk_π_app, nat_trans.comp_app, category.assoc], dsimp, rw [category.id_comp, ←F.map_comp], refl, }, { ext, dsimp [right_res, is_open_map.functor], simp only [limit.lift_π, cones.postcompose_obj_π, iso.op_hom, discrete.nat_iso_hom_app, functor.map_iso_refl, functor.map_iso_hom, lim_map_π_assoc, limit.lift_map, fan.mk_π_app, nat_trans.comp_app, category.assoc], dsimp, rw [category.id_comp, ←F.map_comp], refl, }, { simp, }, end. /-- If `F : presheaf C X` is a presheaf, and `oe : U ⟶ X` is an open embedding, then the sheaf condition fork for a cover `𝒰` in `U` for the composition of `oe` and `F` is isomorphic to sheaf condition fork for `oe '' 𝒰`, precomposed with the isomorphism of indexing diagrams `diagram.iso_of_open_embedding`. We use this to show that the restriction of sheaf along an open embedding is still a sheaf. -/ def fork.iso_of_open_embedding : fork (oe.is_open_map.functor.op ⋙ F) 𝒰 ≅ (cones.postcompose (diagram.iso_of_open_embedding oe 𝒰).inv).obj (fork F (cover.of_open_embedding oe 𝒰)) := begin fapply fork.ext, { dsimp [is_open_map.functor], exact F.map_iso (iso.op { hom := hom_of_le (by simp only [supr_s, supr_mk, le_def, subtype.coe_mk, set.le_eq_subset, set.image_Union]), inv := hom_of_le (by simp only [supr_s, supr_mk, le_def, subtype.coe_mk, set.le_eq_subset, set.image_Union]), }), }, { ext, dunfold fork.ι, -- Ugh, it is unpleasant that we need this. simp only [res, diagram.iso_of_open_embedding, discrete.nat_iso_inv_app, functor.map_iso_inv, limit.lift_π, cones.postcompose_obj_π, functor.comp_map, fork_π_app_walking_parallel_pair_zero, pi_opens.iso_of_open_embedding, nat_iso.of_components.inv_app, functor.map_iso_refl, functor.op_map, limit.lift_map, fan.mk_π_app, nat_trans.comp_app, quiver.hom.unop_op, category.assoc, lim_map_eq_lim_map], dsimp, rw [category.comp_id, ←F.map_comp], refl, }, end end open_embedding end sheaf_condition_equalizer_products end presheaf end Top
(* Title: CoreC++ Author: Daniel Wasserrab Maintainer: Daniel Wasserrab <wasserra at fmi.uni-passau.de> Based on the Jinja theory Common/TypeRel.thy by Tobias Nipkow *) header {* \isaheader{The subclass relation} *} theory ClassRel imports Decl begin -- "direct repeated subclass" inductive_set subclsR :: "prog \<Rightarrow> (cname \<times> cname) set" and subclsR' :: "prog \<Rightarrow> [cname, cname] \<Rightarrow> bool" ("_ \<turnstile> _ \<prec>\<^sub>R _" [71,71,71] 70) for P :: prog where "P \<turnstile> C \<prec>\<^sub>R D \<equiv> (C,D) \<in> subclsR P" | subclsRI: "\<lbrakk>class P C = Some (Bs,rest); Repeats(D) \<in> set Bs\<rbrakk> \<Longrightarrow> P \<turnstile> C \<prec>\<^sub>R D" -- "direct shared subclass" inductive_set subclsS :: "prog \<Rightarrow> (cname \<times> cname) set" and subclsS' :: "prog \<Rightarrow> [cname, cname] \<Rightarrow> bool" ("_ \<turnstile> _ \<prec>\<^sub>S _" [71,71,71] 70) for P :: prog where "P \<turnstile> C \<prec>\<^sub>S D \<equiv> (C,D) \<in> subclsS P" | subclsSI: "\<lbrakk>class P C = Some (Bs,rest); Shares(D) \<in> set Bs\<rbrakk> \<Longrightarrow> P \<turnstile> C \<prec>\<^sub>S D" -- "direct subclass" inductive_set subcls1 :: "prog \<Rightarrow> (cname \<times> cname) set" and subcls1' :: "prog \<Rightarrow> [cname, cname] \<Rightarrow> bool" ("_ \<turnstile> _ \<prec>\<^sup>1 _" [71,71,71] 70) for P :: prog where "P \<turnstile> C \<prec>\<^sup>1 D \<equiv> (C,D) \<in> subcls1 P" | subcls1I: "\<lbrakk>class P C = Some (Bs,rest); D \<in> baseClasses Bs\<rbrakk> \<Longrightarrow> P \<turnstile> C \<prec>\<^sup>1 D" abbreviation subcls :: "prog \<Rightarrow> [cname, cname] \<Rightarrow> bool" ("_ \<turnstile> _ \<preceq>\<^sup>* _" [71,71,71] 70) where "P \<turnstile> C \<preceq>\<^sup>* D \<equiv> (C,D) \<in> (subcls1 P)\<^sup>*" lemma subclsRD: "P \<turnstile> C \<prec>\<^sub>R D \<Longrightarrow> \<exists>fs ms Bs. (class P C = Some (Bs,fs,ms)) \<and> (Repeats(D) \<in> set Bs)" by(auto elim: subclsR.cases) lemma subclsSD: "P \<turnstile> C \<prec>\<^sub>S D \<Longrightarrow> \<exists>fs ms Bs. (class P C = Some (Bs,fs,ms)) \<and> (Shares(D) \<in> set Bs)" by(auto elim: subclsS.cases) lemma subcls1D: "P \<turnstile> C \<prec>\<^sup>1 D \<Longrightarrow> \<exists>fs ms Bs. (class P C = Some (Bs,fs,ms)) \<and> (D \<in> baseClasses Bs)" by(auto elim: subcls1.cases) lemma subclsR_subcls1: "P \<turnstile> C \<prec>\<^sub>R D \<Longrightarrow> P \<turnstile> C \<prec>\<^sup>1 D" by (auto elim!:subclsR.cases intro:subcls1I simp:RepBaseclass_isBaseclass) lemma subclsS_subcls1: "P \<turnstile> C \<prec>\<^sub>S D \<Longrightarrow> P \<turnstile> C \<prec>\<^sup>1 D" by (auto elim!:subclsS.cases intro:subcls1I simp:ShBaseclass_isBaseclass) lemma subcls1_subclsR_or_subclsS: "P \<turnstile> C \<prec>\<^sup>1 D \<Longrightarrow> P \<turnstile> C \<prec>\<^sub>R D \<or> P \<turnstile> C \<prec>\<^sub>S D" by (auto dest!:subcls1D intro:subclsRI dest:baseClasses_repeats_or_shares subclsSI) lemma finite_subcls1: "finite (subcls1 P)" apply(subgoal_tac "subcls1 P = (SIGMA C: {C. is_class P C} . {D. D \<in> baseClasses (fst(the(class P C)))})") prefer 2 apply(fastforce simp:is_class_def dest: subcls1D elim: subcls1I) apply simp apply(rule finite_SigmaI [OF finite_is_class]) apply(rule_tac B = "baseClasses (fst (the (class P C)))" in finite_subset) apply (auto intro:finite_baseClasses simp:is_class_def) done lemma finite_subclsR: "finite (subclsR P)" by(rule_tac B = "subcls1 P" in finite_subset, auto simp:subclsR_subcls1 finite_subcls1) lemma finite_subclsS: "finite (subclsS P)" by(rule_tac B = "subcls1 P" in finite_subset, auto simp:subclsS_subcls1 finite_subcls1) lemma subcls1_class: "P \<turnstile> C \<prec>\<^sup>1 D \<Longrightarrow> is_class P C" by (auto dest:subcls1D simp:is_class_def) lemma subcls_is_class: "\<lbrakk>P \<turnstile> D \<preceq>\<^sup>* C; is_class P C\<rbrakk> \<Longrightarrow> is_class P D" by (induct rule:rtrancl_induct,auto dest:subcls1_class) end
State Before: α : Type u β : Type v γ : Type w δ : Type ?u.257261 ι : Sort x f✝ f₁ f₂ : Filter α g g₁ g₂ : Filter β m✝ : α → β m' : β → γ s : Set α t : Set β f : Filter β m : α → β hf : range m ∈ f ⊢ map m (comap m f) = f State After: no goals Tactic: rw [map_comap, inf_eq_left.2 (le_principal_iff.2 hf)]
-- --------------------------------------------------------------- [ Model.idr ] -- Module : Model.idr -- Copyright : (c) Jan de Muijnck-Hughes -- License : see LICENSE -- --------------------------------------------------------------------- [ EOH ] ||| The GRL Model as Goal Graph module GRL.Model import public Data.AVL.Graph import public Data.List import GRL.Common import Debug.Trace %access export -- ------------------------------------------------------------------- [ Nodes ] ||| Nodes in the Goal Graph public export record GoalNode where constructor GNode getNodeTy : GElemTy getNodeTitle : String getSValue : Maybe SValue getStructTy : Maybe GStructTy Show GoalNode where show (GNode ty n s d) = with List unwords ["[GNode", show ty, n, show s, show d, "]"] Eq GoalNode where (==) (GNode xty x xs xd) (GNode yty y ys yd) = xty == yty && x == y && xs == ys && xd == yd -- ------------------------------------------------------------------- [ Edges ] public export data GoalEdge : Type where Contribution : CValue -> GoalEdge Correlation : CValue -> GoalEdge Decomp : GoalEdge Show GoalEdge where show (Contribution ty) = with List unwords ["[Contrib", show ty, "]"] show (Correlation ty) = with List unwords ["[Correl", show ty, "]"] show Decomp = with List unwords ["[Decomp]"] Eq GoalEdge where (==) (Contribution x) (Contribution y) = x == y (==) (Correlation x) (Correlation y) = x == y (==) Decomp Decomp = True (==) _ _ = False -- ---------------------------------------------------------------- [ Synonyms ] public export GModel : Type GModel = Graph (GoalNode) (GoalEdge) -- ---------------------------------------------------------- [ Util Functions ] isDeCompEdge : Maybe GoalEdge -> Bool isDeCompEdge (Just Decomp) = True isDeCompEdge _ = False isContribEdge : Maybe GoalEdge -> Bool isContribEdge (Just (Contribution y)) = True isContribEdge _ = False isCorrelEdge : Maybe GoalEdge -> Bool isCorrelEdge (Just (Correlation y)) = True isCorrelEdge _ = False getGoalByTitle : String -> GModel -> Maybe GoalNode getGoalByTitle t g = getValueUsing (\x => getNodeTitle x == t) g getGoalIDByTitle : String -> GModel -> Maybe NodeID getGoalIDByTitle t g = getNodeIDUsing (\x => getNodeTitle x == t) g getGoalByTitle' : GoalNode -> GModel -> Maybe GoalNode getGoalByTitle' t g = getGoalByTitle (getNodeTitle t) g hasGoal : String -> GModel -> Bool hasGoal t m = isJust $ getValueUsing (\x => getNodeTitle x == t) m updateGoalNode : (sfunc : GoalNode -> Bool) -> (ufunc : GoalNode -> GoalNode) -> (model : GModel) -> GModel updateGoalNode f u m = case getValueUsing f m of Nothing => m Just val => updateNodeValueUsing val u m getDeCompEdges : NodeID -> GModel -> List (DemiEdge GoalEdge) getDeCompEdges n m = filter (\(y,l) => isDeCompEdge l) cs where cs : List (DemiEdge GoalEdge) cs = getEdgesByID n m getIntentEdges : NodeID -> GModel -> List (DemiEdge GoalEdge) getIntentEdges n m = filter (\(y,l) => not (isDeCompEdge l)) cs where cs : List (DemiEdge GoalEdge) cs = getEdgesByID n m -- --------------------------------------------------------------------- [ EOF ]
[STATEMENT] lemma sign_changes_Cons_ge: "sign_changes (x # xs) \<ge> sign_changes xs" [PROOF STATE] proof (prove) goal (1 subgoal): 1. sign_changes xs \<le> sign_changes (x # xs) [PROOF STEP] unfolding sign_changes_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. length (remdups_adj (filter (\<lambda>x. x \<noteq> (0::'a)) (map sgn xs))) - 1 \<le> length (remdups_adj (filter (\<lambda>x. x \<noteq> (0::'a)) (map sgn (x # xs)))) - 1 [PROOF STEP] by (simp add: remdups_adj_Cons split: list.split)
------------------------------------------------------------------------ -- A definitional interpreter ------------------------------------------------------------------------ {-# OPTIONS --cubical --sized-types #-} module Lambda.Partiality-monad.Inductive.Interpreter where open import Equality.Propositional.Cubical open import Prelude hiding (⊥) open import Bijection equality-with-J using (_↔_) open import Function-universe equality-with-J hiding (id; _∘_) open import Maybe equality-with-J open import Monad equality-with-J open import Vec.Function equality-with-J open import Partiality-monad.Inductive open import Partiality-monad.Inductive.Fixpoints open import Partiality-monad.Inductive.Monad open import Lambda.Syntax hiding ([_]) open Closure Tm ------------------------------------------------------------------------ -- An interpreter monad -- The interpreter monad. M : ∀ {ℓ} → Type ℓ → Type ℓ M = MaybeT _⊥ -- Information ordering. infix 4 _⊑M_ _⊑M_ : ∀ {a} {A : Type a} → M A → M A → Type a x ⊑M y = run x ⊑ run y -- Bind is monotone. _>>=ᵐ-mono_ : ∀ {ℓ} {A B : Type ℓ} {x y : M A} {f g : A → M B} → x ⊑M y → (∀ z → f z ⊑M g z) → x >>= f ⊑M y >>= g _>>=ᵐ-mono_ {x = x} {y} {f} {g} x⊑y f⊑g = run x >>= maybe (MaybeT.run ∘ f) (return nothing) ⊑⟨ x⊑y >>=-mono maybe f⊑g (run fail ■) ⟩■ run y >>= maybe (MaybeT.run ∘ g) (return nothing) ■ -- A variant of bind for sequences. infix 5 _>>=ˢ_ _>>=ˢ_ : {A B : Type} → Increasing-sequence (Maybe A) → (A → Increasing-sequence (Maybe B)) → Increasing-sequence (Maybe B) s >>=ˢ f = (λ n → MaybeT.run (wrap (s [ n ]) >>= λ x → wrap (f x [ n ]))) , (λ n → increasing s n >>=ᵐ-mono λ x → increasing (f x) n) ------------------------------------------------------------------------ -- One interpreter module Interpreter₁ where -- This interpreter is defined as the least upper bound of a -- sequence of increasingly defined interpreters. infix 10 _∙_ mutual ⟦_⟧′ : ∀ {n} → Tm n → Env n → ℕ → M Value ⟦ con i ⟧′ ρ n = return (con i) ⟦ var x ⟧′ ρ n = return (ρ x) ⟦ ƛ t ⟧′ ρ n = return (ƛ t ρ) ⟦ t₁ · t₂ ⟧′ ρ n = ⟦ t₁ ⟧′ ρ n >>= λ v₁ → ⟦ t₂ ⟧′ ρ n >>= λ v₂ → (v₁ ∙ v₂) n _∙_ : Value → Value → ℕ → M Value (con i ∙ v₂) n = fail (ƛ t₁ ρ ∙ v₂) zero = liftʳ never (ƛ t₁ ρ ∙ v₂) (suc n) = ⟦ t₁ ⟧′ (cons v₂ ρ) n mutual ⟦⟧′-increasing : ∀ {n} (t : Tm n) ρ n → ⟦ t ⟧′ ρ n ⊑M ⟦ t ⟧′ ρ (suc n) ⟦⟧′-increasing (con i) ρ n = MaybeT.run (return (con i)) ■ ⟦⟧′-increasing (var x) ρ n = MaybeT.run (return (ρ x)) ■ ⟦⟧′-increasing (ƛ t) ρ n = MaybeT.run (return (ƛ t ρ)) ■ ⟦⟧′-increasing (t₁ · t₂) ρ n = ⟦⟧′-increasing t₁ ρ n >>=ᵐ-mono λ v₁ → ⟦⟧′-increasing t₂ ρ n >>=ᵐ-mono λ v₂ → ∙-increasing v₁ v₂ n ∙-increasing : ∀ v₁ v₂ n → (v₁ ∙ v₂) n ⊑M (v₁ ∙ v₂) (suc n) ∙-increasing (con i) v₂ n = run fail ■ ∙-increasing (ƛ t₁ ρ) v₂ (suc n) = ⟦⟧′-increasing t₁ (cons v₂ ρ) n ∙-increasing (ƛ t₁ ρ) v₂ zero = never >>= return ∘ just ≡⟨ never->>= ⟩⊑ never ⊑⟨ never⊑ _ ⟩■ run (⟦ t₁ ⟧′ (cons v₂ ρ) 0) ■ ⟦_⟧ˢ : ∀ {n} → Tm n → Env n → Increasing-sequence (Maybe Value) ⟦ t ⟧ˢ ρ = MaybeT.run ∘ ⟦ t ⟧′ ρ , ⟦⟧′-increasing t ρ ⟦_⟧ : ∀ {n} → Tm n → Env n → M Value run (⟦ t ⟧ ρ) = ⨆ (⟦ t ⟧ˢ ρ) ------------------------------------------------------------------------ -- Another interpreter module Interpreter₂ where -- This interpreter is defined using a fixpoint combinator. M′ : Type → Type₁ M′ = MaybeT (Partial (∃ λ n → Tm n × Env n) (λ _ → Maybe Value)) infix 10 _∙_ _∙_ : Value → Value → M′ Value con i ∙ v₂ = fail ƛ t₁ ρ ∙ v₂ = wrap (rec (_ , t₁ , cons v₂ ρ)) ⟦_⟧′ : ∀ {n} → Tm n → Env n → M′ Value ⟦ con i ⟧′ ρ = return (con i) ⟦ var x ⟧′ ρ = return (ρ x) ⟦ ƛ t ⟧′ ρ = return (ƛ t ρ) ⟦ t₁ · t₂ ⟧′ ρ = ⟦ t₁ ⟧′ ρ >>= λ v₁ → ⟦ t₂ ⟧′ ρ >>= λ v₂ → v₁ ∙ v₂ ⟦_⟧ : ∀ {n} → Tm n → Env n → M Value run (⟦ t ⟧ ρ) = fixP {A = ∃ λ n → Tm n × Env n} (λ { (_ , t , ρ) → run (⟦ t ⟧′ ρ) }) (_ , t , ρ) ------------------------------------------------------------------------ -- The two interpreters are pointwise equal interpreters-equal : ∀ {n} (t : Tm n) ρ → Interpreter₁.⟦ t ⟧ ρ ≡ Interpreter₂.⟦ t ⟧ ρ interpreters-equal = λ t ρ → $⟨ ⟦⟧-lemma t ρ ⟩ (∀ n → run (Interpreter₁.⟦ t ⟧′ ρ n) ≡ app→ step₂ (suc n) (_ , t , ρ)) ↝⟨ cong ⨆ ∘ _↔_.to equality-characterisation-increasing ⟩ ⨆ (Interpreter₁.⟦ t ⟧ˢ ρ) ≡ ⨆ (tailˢ (at (fix→-sequence step₂) (_ , t , ρ))) ↝⟨ flip trans (⨆tail≡⨆ _) ⟩ ⨆ (Interpreter₁.⟦ t ⟧ˢ ρ) ≡ ⨆ (at (fix→-sequence step₂) (_ , t , ρ)) ↝⟨ id ⟩ run (Interpreter₁.⟦ t ⟧ ρ) ≡ run (Interpreter₂.⟦ t ⟧ ρ) ↝⟨ cong wrap ⟩□ Interpreter₁.⟦ t ⟧ ρ ≡ Interpreter₂.⟦ t ⟧ ρ □ where open Partial open Trans-⊑ step₂ : Trans-⊑ (∃ λ n → Tm n × Env n) (λ _ → Maybe Value) step₂ = transformer λ { (_ , t , ρ) → run (Interpreter₂.⟦ t ⟧′ ρ) } mutual ⟦⟧-lemma : ∀ {n} (t : Tm n) ρ n → run (Interpreter₁.⟦ t ⟧′ ρ n) ≡ function (run (Interpreter₂.⟦ t ⟧′ ρ)) (app→ step₂ n) ⟦⟧-lemma (con i) ρ n = refl ⟦⟧-lemma (var x) ρ n = refl ⟦⟧-lemma (ƛ t) ρ n = refl ⟦⟧-lemma (t₁ · t₂) ρ n = cong₂ _>>=_ (⟦⟧-lemma t₁ ρ n) $ ⟨ext⟩ $ flip maybe refl λ v₁ → cong₂ _>>=_ (⟦⟧-lemma t₂ ρ n) $ ⟨ext⟩ $ flip maybe refl λ v₂ → ∙-lemma v₁ v₂ n ∙-lemma : ∀ v₁ v₂ n → run ((v₁ Interpreter₁.∙ v₂) n) ≡ function (run (v₁ Interpreter₂.∙ v₂)) (app→ step₂ n) ∙-lemma (con i) v₂ n = refl ∙-lemma (ƛ t₁ ρ) v₂ zero = never >>= return ∘ just ≡⟨ never->>= ⟩∎ never ∎ ∙-lemma (ƛ t₁ ρ) v₂ (suc n) = ⟦⟧-lemma t₁ (cons v₂ ρ) n -- Let us use Interpreter₁ as the default interpreter. open Interpreter₁ public ------------------------------------------------------------------------ -- An example -- The semantics of Ω is the non-terminating computation never. Ω-loops : run (⟦ Ω ⟧ nil) ≡ never Ω-loops = antisymmetry (least-upper-bound _ _ lemma) (never⊑ _) where ω-nil = ƛ (var fzero · var fzero) nil reduce-twice : ∀ n → run (⟦ Ω ⟧′ nil n) ≡ run ((ω-nil ∙ ω-nil) n) reduce-twice n = run (⟦ Ω ⟧′ nil n) ≡⟨ now->>= ⟩ run (⟦ ω ⟧′ nil n >>= λ v₂ → (ω-nil ∙ v₂) n) ≡⟨ now->>= ⟩∎ run ((ω-nil ∙ ω-nil) n) ∎ lemma : ∀ n → run (⟦ Ω ⟧′ nil n) ⊑ never lemma zero = run (⟦ Ω ⟧′ nil zero) ≡⟨ reduce-twice zero ⟩⊑ run ((ω-nil ∙ ω-nil) zero) ≡⟨ never->>= ⟩⊑ never ■ lemma (suc n) = run (⟦ Ω ⟧′ nil (suc n)) ≡⟨ reduce-twice (suc n) ⟩⊑ run (⟦ Ω ⟧′ nil n) ⊑⟨ lemma n ⟩■ never ■
\documentclass[././main.tex]{subfiles} \begin{document} \section{Episode One} \subsection{Soren and Benoweth Arrive at Ha'ard} \subsection{The Living are Hungry} \subsection{The Dogs of War} \end{document}
# CHEM 1000 - Spring 2022 Prof. Geoffrey Hutchison, University of Pittsburgh ## 8 Integrals Chapter 8 in [*Mathematical Methods for Chemists*](http://sites.bu.edu/straub/mathematical-methods-for-molecular-science/) By the end of this session, you should be able to: - Understand some basic rules for integrals in one variable - Simple anti-derivatives - U substitution - Integration by parts - Trig substitution - Understand challenges in doing integrals (i.e., we can't solve some of them) ### Motivation An integral computes the area under a curve. Consequently, there are **many** applications in physics and chemistry: - integrating peaks in NMR spectra inform the number and ratios of atoms (e.g., 3 $^1H$) - integrating electrical current over time yields the amount of charges - integrating force and displacement give the *work* performed - integrating an orbital (technically $\psi^* \psi$) tells us the probability of finding an electron in that region - integrating to find surface area and volume are important predictors of solubility - integrating to get the average value of a curve (e.g., average of a charge distribution from a molecule) - integrating to calculate the moments of inertia of a molecule Of course most people have this reaction to derivatives and integrals: From [XKCD](https://xkcd.com/2117/) ### Integrals and Antiderivatives The integral of a function is literally written as the area under the curve. That is, if we want the area under $f(x)$ from $a$ to $b$, we can divide it up into a bunch of little rectangles: $x_{0}=a<x_{1}<\cdots<x_{N}=b$ $$ \int_{a}^{b} f(x) d x=\lim _{N \rightarrow \infty} \sum_{i=1}^{N} f\left(x_{i}^{*}\right)\left(x_{i}-x_{i-1}\right) $$ Notice that the product $f(x_i^ * ) (x_i - x_{i-1})$ for each $i$ is the area of a rectangle of height $f(x_i^ * )$ and width $x_i - x_{i-1}$. We can think of these "Riemann sums" as the area of $N$ rectangles with heights determined by the graph of $y=f(x)$. (We can use this definition to calculate numerical integrals if we cannot determine the exact expression of an integral.) One question is often how this area under a curve connects with derivatives. After all, the derivative is the tangent to the curve at a particular point. What's the connection? This connection is actually so important, it's called the [Fundamental Theorem of Calculus](https://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus). Consider the 'extra' little bit of area in yellow: If this is small enough, we can approximate the area as a rectangle. - The area from 0 to x is: $A(x)$ - The area from zero to the "new area" is then $A(x+dx)$. - Obviously, the height of the rectangle is given by $f(x)$ - The width of the rectangle is $dx$ $$ \frac{A(x + dx) - A(x)}{dx} = f(x) $$ The first part of that is the definition of the derivative $A'(x)$. Or, put another way, $A(x)$ is the antiderivative of $f(x)$. ### Evaluating Integrals We'll discuss ***numeric*** integration later. Suffice to say that some times we don't have good ways to get an analytical formula for an integral. Let's start with derivatives, which we know: $$ \frac{d}{d x} f(x)=f^{\prime}(x) $$ We saw the total differential as well - the change in the function vs. the change in the $x$ value: $$ d f(x)=f^{\prime}(x) d x $$ So for any case where we know the derivative, we can set up known integrals: $$ f(x)=\int d f(x)=\int f^{\prime}(x) d x $$ #### Some Review of Common Integrals - Integration of a constant: $$ \int a d x=a \int d x=a x+C $$ Note this also means that the integral of a constant times a function can be evaluated by taking the constant 'out front'. - Polynomials / powers: $$ \int x^{n} d x=\frac{1}{n+1} x^{n+1}+C \quad n \neq-1 $$ - 1/x (i.e., what to do for $x^{-1}$ above $$ \int \frac{1}{x} d x=\ln x+C $$ - Integral of sums: Much like derivatives, when we have multiple terms in an integral, we can integrate each part separately: $$ \int[f(x)+g(x)] d x=\int f(x) d x+\int g(x) d x $$ - Exponential: Borrowing from derivatives, the integral of $e^x$ will be $e^x$ $$ \int e^{a x} d x=\frac{1}{a} e^{a x}+C $$ - Sines and Cosines: $$ \begin{array}{l} \int \sin (a x) d x=-\frac{1}{a} \cos (a x)+C \\ \int \cos (a x) d x=\frac{1}{a} \sin (a x)+C \end{array} $$ <div class="alert alert-block alert-success"> These are the main integrals you should know. There are a few tools to integrate more complicated integrals, and there are some known *definite* integrals. Beyond that, there are a few other ways to evaluate more complicated integrals: - substitution of variables - some functions (even complicated ones) have known integrals that can be found on integral tables - some integrals have no known formula, but are important enough to create "special functions" (e.g., the [error function erf(x)](https://en.wikipedia.org/wiki/Error_function) - use computer algebra / calculus tools like Mathematica or Sympy which will use combinations of these techniques - give up and perform numeric integration </div> Let's review three general substitution patterns for integrals. #### 1. "U Substitution" Sometimes, we're lucky and have something like this: $$ \int \cos ^{2} x \sin x d x $$ Unlike derivatives, there's no specific product rule for integrals. But we could define $u = \cos x$ and then $du =-\sin x dx$: $$ \int \cos ^{2} x \sin x d x=-\int u^{2} d u=-\frac{1}{3} u^{3}+C=-\frac{1}{3} \cos ^{3} x+C $$ **This only works if you see an integral that looks like a product, with one part that's a derivative of the other.** #### 2. Integration by Parts What if you have an integral with a product, but it's not like that. You can often use integration by parts: $$ \int u d v=u v-\int v d u $$ That is, if you have two functions multiplied together, you pick a $u$ and a $dv$ and apply. For example: $$ \int_{0}^{\infty} x e^{-a x} d x=\int u d v $$ $$ \begin{array}{cc} u=x & d v=e^{-a x} d x \\ d u=d x & v=-\frac{1}{a} e^{-a x} \end{array} $$ You might think "but how did we get $v$": $$ v=\int d v=\int e^{-a x} d x=-\frac{1}{a} e^{-a x} $$ You might also ask "how do you decide which one is $u$ and which one is $v$" - the point is that you want this term to be really easy: $$ \int v d u $$ Anyway, for this thing, you get: $$ \begin{aligned} \int_{0}^{\infty} x e^{-a x} d x &=\int u d v=u v-\int v d u=-\left.\frac{1}{a} x e^{-a x}\right|_{0} ^{\infty}-\int_{0}^{\infty}\left(-\frac{1}{a} e^{-a x}\right) d x \\ &=-\left.\frac{1}{a^{2}} e^{-a x}\right|_{0} ^{\infty}=\frac{1}{a^{2}} \end{aligned} $$ #### 3. Trigonometric Substitution Sometimes you can evaluate unknown trigonometric integrals using some flavor of trig identities. For example, $\sin ^{2} x=\frac{1}{2}(1-\cos (2 x))$ So we can then evaluate: $$ \begin{aligned} \int \sin ^{2} x d x &=\int \frac{1}{2}(1-\cos (2 x)) d x=\frac{1}{2} \int d x-\frac{1}{2} \int \cos (2 x) d x \\ &=\frac{1}{2} x-\frac{1}{4} \sin (2 x)+C \end{aligned} $$ <div class="alert alert-block alert-success"> I'll be honest. A lot of derivatives I can do in my head or with a bit of pen and paper. I do most integrals with Sympy or Wolfram Alpha. I'm going to concentrate more on concepts than on "can you do integral substitutions" </div> ```python from sympy import init_session init_session() ``` The main command for `sympy` is `integrate(function, variable)` ```python integrate(2*x**2 + 3*x, x) ``` ```python # integration by parts a = symbols('a') integrate(x*exp(-a*x), x) ``` One catch, is that Sympy will omit the constant of integration C... What about trigonometric substitution? ```python integrate(sin(x)**2, x) ``` Weird integrals? ```python integrate(sqrt(1/x), x) ``` Do some practice: $\int m v d v$ $\int \frac{1}{x^{3}} d x$ $\int \sin 3 x d x$ $\int(3 x+5)^{2} 4 x d x$ $\int e^{-\varepsilon / k_{B} T} d \varepsilon$ $\int \cos (2 \pi v t) d t$ $\int \frac{R T}{p} d p$ $\int \frac{1}{2} \kappa x^{2} d x$ $\int \frac{q^{2}}{4 \pi \varepsilon_{0} r^{2}} d r$ ```python # space for practice q, epsilon, r = symbols('q epsilon r') integrate(q**2/(4*pi*epsilon*r**2), r) ``` Does it seem like integration is harder than derivatives? You're not wrong. We can even time the difference! https://www.marksmath.org/visualization/integration_vs_differentiation/ ```python # pick a random function … f = exp(sin(x**2)) + 3*sqrt(x) %time i = diff(f, x) %time i = integrate(f, x) ``` ------- This notebook is from Prof. Geoffrey Hutchison, University of Pittsburgh https://github.com/ghutchis/chem1000 <a rel="license" href="http://creativecommons.org/licenses/by/4.0/"></a>
theory T86 imports Main begin lemma "( (\<forall> x::nat. \<forall> y::nat. meet(x, y) = meet(y, x)) & (\<forall> x::nat. \<forall> y::nat. join(x, y) = join(y, x)) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, meet(y, z)) = meet(meet(x, y), z)) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(x, join(y, z)) = join(join(x, y), z)) & (\<forall> x::nat. \<forall> y::nat. meet(x, join(x, y)) = x) & (\<forall> x::nat. \<forall> y::nat. join(x, meet(x, y)) = x) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, join(y, z)) = join(mult(x, y), mult(x, z))) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(join(x, y), z) = join(mult(x, z), mult(y, z))) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, over(join(mult(x, y), z), y)) = x) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(y, undr(x, join(mult(x, y), z))) = y) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(over(x, y), y), x) = x) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(y, undr(y, x)), x) = x) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. over(join(x, y), z) = join(over(x, z), over(y, z))) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. over(x, meet(y, z)) = join(over(x, y), over(x, z))) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(meet(x, y), z) = join(undr(x, z), undr(y, z))) & (\<forall> x::nat. \<forall> y::nat. invo(join(x, y)) = meet(invo(x), invo(y))) & (\<forall> x::nat. \<forall> y::nat. invo(meet(x, y)) = join(invo(x), invo(y))) & (\<forall> x::nat. invo(invo(x)) = x) ) \<longrightarrow> (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(x, join(y, z)) = join(undr(x, y), undr(x, z))) " nitpick[card nat=8,timeout=86400] oops end
function [vX] = spm_vec(X,varargin) % Vectorise a numeric, cell or structure array - a compiled routine % FORMAT [vX] = spm_vec(X) % X - numeric, cell or stucture array[s] % vX - vec(X) % % See spm_unvec %__________________________________________________________________________ % % e.g.: % spm_vec({eye(2) 3}) = [1 0 0 1 3]' %__________________________________________________________________________ % Copyright (C) 2005-2013 Wellcome Trust Centre for Neuroimaging % Karl Friston % $Id: spm_vec.m 6110 2014-07-21 09:36:13Z karl $ %error('spm_vec.c not compiled - see Makefile') % initialise X and vX %-------------------------------------------------------------------------- if nargin > 1 X = [{X},varargin]; end % vectorise numerical arrays %-------------------------------------------------------------------------- if isnumeric(X) vX = X(:); % vectorise logical arrays %-------------------------------------------------------------------------- elseif islogical(X) vX = X(:); % vectorise structure into cell arrays %-------------------------------------------------------------------------- elseif isstruct(X) vX = []; f = fieldnames(X); X = X(:); for i = 1:numel(f) vX = cat(1,vX,spm_vec({X.(f{i})})); end % vectorise cells into numerical arrays %-------------------------------------------------------------------------- elseif iscell(X) vX = []; for i = 1:numel(X) vX = cat(1,vX,spm_vec(X{i})); end else vX = []; end
{-# OPTIONS --cubical --safe #-} module Cubical.Data.Strict2Group.Categorical where open import Cubical.Foundations.Prelude open import Cubical.Categories.InternalCategory open import Cubical.Categories.Groups {-- Formalization of strict 2-groups as internal categories of the 1-category Grp of Groups. --} Strict2GroupInternalCat : (ℓ : Level) → Type (ℓ-suc ℓ) Strict2GroupInternalCat ℓ = InternalCategory (1BGROUP ℓ)
Don't miss your chance to see this brick ranch located in Potter's Hollow. This property features a open kitchen with all new appliances, a living spaces, new paint, high efficiency furnace, plus a huge backyard with a multi tiered deck. Don't wait this will be gone fast! Call NOW! Listing provided courtesy of White Door Realty.
# Homework 03 ### Brown University ### DATA 1010 ### Fall 2020 ## Problem 1 In this problem we'll explore the Lagrange multipliers method used to discover the extrema of a smooth function $f$ whose domain is a strict subset of $\mathbb{R}^n$. (a) Write down conditions on the first derivative (the gradient) of $f$ and conditions on the second derivative (the Hessian) of $f$ that must be satisfied at any local extremum of $f$, and explain briefly why they are necessarily satisfied. (Your written solution may follow the presentation in DG, but it should be in your own words.) You may assume that the boundary of the domain of $f$ is the 0-level set of a differentiable function $g$ with nonvanishing gradient. *Hint: The second-order condition at the boundary will require some new thoughts. You'll need to think about how the Hessian specifies which directions you can go from a critical point to increase/decrease the function.* In the standard derivation, the multiplier $\lambda$ arises as an equation-solving convenience. However, it can be given an interpretation in the context of the constrained optimization problem. ### Answer: We can have local extrema arise if one of many conditions are met. First, if we have a local max, min or saddle point at a point that is not on the boundary of our domain. If this is the case, local max will have zero gradient because at this exact point the function is not increasing or decreasing in any direction and the second derivative is negative in all directions because as we move away from the critical point the derivative is negative and it is becoming increasingly greater in absolute value. Local min will have zero gradient for the same reason and positive second derivative in all directions because as we move away from the critical point the derivatives are changing at an increasing rate. Saddle points will have zero gradient also for the same reason but the second derivatives will be a mix of positive and negative. Negative in the directions of decrease and positive in the directions of increase. Another case to consider is when the min or max is on the boundary, g of the domain. In this case the gradient of our function f and the gradient of g must be proportional(pointing in the same direction) because if this wasn't the case there would be some direction that we could move to increase or decrease the function(depending on whether it was a min or max). From this idea we derive the equation ∇f = λ∇g. At this kind of point(max or min) the second derivative can can be positive negative or zero because all that matters is that the slope is increasing or decreasing. We also need to consider the possibility that there is a boundary at a saddle point. In this case we will have to look at the second order behavior. If the boundary is a straight line then there will always be a direction of increase and decrease and we can check the second derivative to determine these directions as layed out above when discussing saddle points. However if the boundary is arched sufficiently then its possible to cut of all directions of increase or decrease. In this case we have a max or min respectively. (b) Using the example $f(\mathbf{x}) = 3x_1 + 4x_2$ and $g(\mathbf{x}) = x_1^2 + x_2^2 - 1$, find the extrema and the values of $\lambda$ at those points. ```julia using SymPy @vars x y λ f = 3x + 4y g = x^2 + y^2 -1 (min, max) = sympy.solve((diff(f, x) - λ*diff(g, x), diff(f, y) - λ*diff(g, y), g), (x, y, λ)) ``` 2-element Array{Tuple{Sym,Sym,Sym},1}: (-3/5, -4/5, -5/2) (3/5, 4/5, 5/2) ### Answer We use Lagrange multipliers to set up a system of 3 equations with three unknowns. We have ∇f = λ∇g(which is two equations) and we also have g = 0. We use diff from SymPy to perform the differentiation and sympy.solve to solve the system of equations. The result is we have (3/5, 4/5) as a max and (-3/5, -4/5) as a min. (c) At this point, find the gradient of both $f(x)$ and $g(x)$, are these two gradients linearly dependent? If so, what is the multiplier relating these two gradients? Describe what $\lambda$ represents. (Hint: think about replacing the constraint equation $g(x) = 0$ with $g(x) = c$ for some small value of $c$.) Here's an interactive graph to help you visualize what's going on: ```julia df = [diff(f, x) diff(f, y)] #gradient of f dg(a, b) = [diff(g, x)(x => a, y => b) diff(g, y)(x => a, y => b)] #gradient of g ("∇f at max:", dg(max[1], max[2]), "∇g at max:", df), ("∇f at min:", dg(min[1], min[2]), "∇g at min:", df) ``` (("∇f at max:", Sym[6/5 8/5], "∇g at max:", Sym[3 4]), ("∇f at min:", Sym[-6/5 -8/5], "∇g at min:", Sym[3 4])) ### Answer Here we have computed the gradient of f and g and evaluated at our max and min from above. We can see that in the case of the the max the multiplier is 5/2 and in the case of the min the multiplier is -5/2. λ is the ratio ∇f / ∇g. However we could also interpret it in another way. λ tells us how a slight change in our constraint level set will effect f(x). ```julia using Plots plotlyjs() f(x) = 3x[1] + 4x[2] g(x) = x[1]^2 + x[2]^2 - 1 surface(-2:0.1:2, -2:0.1:2, (x₁,x₂) -> f([x₁,x₂])) surface!(-2:0.1:2, -2:0.1:2, (x₁,x₂) -> g([x₁,x₂])) θs = LinRange(0, 2π, 100) path3d!(cos.(θs), sin.(θs), fill(0.1,length(θs)), linewidth = 8) ``` ```julia using Pkg Pkg.instantiate() ```  Installed LaTeXStrings ─ v1.2.0 ## Problem 2 We would like to examine the details of matrix differentiation in this problem. Let's say that $\mathbf{x} = [x_1, x_2, x_3]$ and $$A = \left[\begin{matrix} 1 & 2 & 0 \\ 2 & 1 & 0 \\ 0 & 1 & 1 \end{matrix}\right]$$ (a) Given an $\mathbb{R}^3$-valued function $\mathbf{a}$ of a vector $\mathbf{x}$ in $\mathbb{R}^3$, recall that the derivative of $\mathbf{a}$ with respect to $\mathbf{x}$ is $$ \frac{\partial \mathbf{a}}{\partial \mathbf{x}} = \left(\begin{matrix} \frac{\partial a_1}{\partial x_1} & \frac{\partial a_1}{\partial x_2} & \frac{\partial a_1}{\partial x_3} \\ \frac{\partial a_2}{\partial x_1} & \frac{\partial a_2}{\partial x_2} & \frac{\partial a_2}{\partial x_3} \\ \frac{\partial a_3}{\partial x_1} & \frac{\partial a_3}{\partial x_2} & \frac{\partial a_3}{\partial x_3} \end{matrix}\right) $$ where $\mathbf{a} = [a_1, a_2, a_3]$, $\mathbf{x} = [x_1, x_2, x_3]$. Using this definition, find $\frac{\partial (A\mathbf{x})}{\partial \mathbf{x}}$ and show that it is equal to the matrix $A$. ### Answer: We can see that : $A x=\left[\begin{array}{l}1 x_{1}+2 x_{2}+0 x_{3} \\ 2 x_{1}+1 x_{2}+0 x_{3} \\ 0 x_{1}+1 x_{2}+1 x_{3}\end{array}\right]$ so by the above definition we can see that: $$ \frac{\partial(A x)}{\partial x}=\left[\begin{array}{lll} 1 & 2 & 0 \\ 2 & 1 & 0 \\ 0 & 1 & 1 \end{array}\right] = A $$ (b) Similarly, the derivative of a real-valued function with respect to a vector in $\mathbb{R}^3$ is $$\frac{\partial a}{\partial \mathbf{x}} = \left[\begin{array}{ccc} \frac{\partial a}{\partial x_1} & \frac{\partial a}{\partial x_2} & \frac{\partial a}{\partial x_3}\end{array}\right],$$ where $\mathbf{x} = (x_1, x_2, x_3)$ Using this definition, find $\mathbf{x}'A\mathbf{x}$, then find $\frac{\partial \mathbf{x}'A\mathbf{x}}{\partial \mathbf{x}}$, and show that it is equal to $\mathbf{x}'(A + A')$. ### Answer: Using $Ax$ from above we have $x'Ax=x'\left[\begin{array}{l}1 x_{1}+2 x_{2}+0 x_{3} \\ 2 x_{1}+1 x_{2}+0 x_{3} \\ 0 x_{1}+1 x_{2}+1 x_{3}\end{array}\right] = \left[x_{1}^{2}+4 x_{1} x_{2}+x_{2}^{2}+x_{2} x_{3}+x_{3}^{2}\right]$ From the fact given above we now have $$ \frac{\partial x^{\prime} A x}{\partial x}=[\ 2 x_{1}+4 x_{2} \quad 4 x_{1}+2 x_{2}+x_{3} \quad x_{2}+2 x_{3}] = \left[\begin{array}{lll} x_{1} & x_{2} & x_{3} \end{array}\right]\left(\left[\begin{array}{lll} 1 & 2 & 0 \\ 2 & 1 & 0 \\ 0 & 1 & 1 \end{array}\right]+\left[\begin{array}{lll} 1 & 2 & 0 \\ 2 & 1 & 1 \\ 0 & 0 & 1 \end{array}\right]\right)=x^{\prime}\left(A+A^{\prime}\right) $$ ## Problem 3 In class, we differentiated the function $x \mapsto \exp(\cos^2(x))$ at the point $x = \pi/4$ "autodiff-style", meaning that we substituted as soon as possible in our function evaluations and derivative calculations, so that we could have nothing but functions and numbers the whole way through. In other words, we avoided having to represent any symbolic expressions in the computation. This is what it looks like drawn out in a diagram, with derivative values in purple and function values in green: In this problem, we're going to do the same thing but with matrix derivatives in place of the single-variable derivatives. Consider the function $f(\mathbf{x}) = [\sigma(x_1), \sigma(x_2), \sigma(x_3)]$, where $\sigma(x) = \frac{1}{1 + \exp(-x)}$. Let $A = \left[\begin{matrix} 1 & 2 & 0 \\ 3 & -2 & 1 \\ 0 & 3 & 2 \end{matrix}\right]$ and $B = \left[\begin{matrix} 4 & -1 & 2 \\ 0 & 0 & 2 \\ 3 & 0 & 0 \end{matrix}\right]$. Differentiate the function $\mathbf{x} \mapsto Bf(A\mathbf{x})$ with respect to $\mathbf{x}$ at the point $\mathbf{x} = [-1, 0, 2]$, using a diagram as similar as possible to the one above. Actually, it should be exactly the same, [mutatis mutandis](https://en.wikipedia.org/wiki/Mutatis_mutandis). Notes: 1. The function we're differentiating here is a composition of the functions "multiply by $B$", f, and "multiply by $A$". 2. To make life easier, feel free to take the equation $\frac{d\sigma}{dx} = \frac{e^{- x}}{\left(1 + e^{- x}\right)^{2}}$ as given. 3. This function is not only related to neural networks, it **is** a neural network. Differentiating (specifically using this autodifferentiation technique) is how we train neural networks. 4. Also, feel free to evaluate each expression numerically or exactly, as you prefer. 5. Here's some code to help get you started: ### Please note that the 3x3 matrices next to the 3x1 columns vectors on top of the image are not meant to be multiplied. In each case the one on the left is the derivative and the one on the right is each function evaluated at Ax, f(Ax) and Bf(Ax) respectively. ```julia using LinearAlgebra A = [1 2 0; 3 -2 1; 0 3 2] B = [4 -1 2; 0 0 2; 3 0 0] x = [-1, 0, 2] #σ(x) = 1/(1 + sympy.exp(-x)) # exact approach σ(x) = 1/(1 + exp(-x)) # numerical approach dσ(x) = exp(-x) / (1 + exp(-x))^2 Ax = A*x B*diagm([dσ(Ax[1]), dσ(Ax[2]), dσ(Ax[3])])*A ``` 3×3 Array{Float64,2}: 0.196612 2.0721 -0.125961 0.0 0.105976 0.0706508 0.589836 1.17967 0.0 ### Answer In this problem we compute the derivative "auto-diff" style by, at each step computing the the value of the function and the derivative at the output from the previous step. At the end we multiply each of the three derivatives to get the final answer as shown above. ## Problem 4 Given a square matrix $A$, its matrix exponential $\exp(A)$ is defined to be $I + A + \frac12A^2 + \frac16A^3 + \cdots$. In other languages, the function `exp` exponentiates a matrix entry-by-entry, while the matrix exponential is a different function, like `expm`. In Julia, `exp` computes the matrix exponential, while `exp.` is the component-wise version: ```julia A = [1 2; 3 4] ``` 2×2 Array{Int64,2}: 1 2 3 4 (a) Numerically investigate the claim that the derivative of $\exp(tA)$ with respect to $t \in \mathbb{R}$ is $A\exp(tA)$. Or should it be $\exp(tA)A$? Note 1: the derivative of a matix-valued function of a real variable is defined entry-by-entry. Note 2: "Numerically investigate" just means "make up a few small examples and see if the results you get for those examples make sense". You can use difference quotients to approximate derivatives. Even though that method loses a lot of precision, it's fine because you're just doing an approximate check anyway. ```julia function is_this_correct(matrix, t, ϵ) println("diff quotient:", (exp((t + ϵ)*matrix) - exp(t*matrix)) / ϵ), println("A*exp(tA): ", matrix*exp(t*matrix)) println("exp(tA)*A: ", exp(t*matrix) * matrix) end println(is_this_correct(A, 1, 10^-6)) println(is_this_correct(A, 0, 10^-6)) println(is_this_correct(A, -1, 10^-6)) ``` diff quotient:[276.17939234403354 402.88525265452773; 604.3278789604753 880.5072713187197] A*exp(tA): [276.17864989971486 402.8841706654232; 604.3262559981348 880.5049058978498] exp(tA)*A: [276.1786498997149 402.8841706654232; 604.3262559981348 880.5049058978498] nothing diff quotient:[1.000003500228885 2.000005000009; 3.0000075000135 4.000010999982704] A*exp(tA): [1.0 2.0; 3.0 4.0] exp(tA)*A: [1.0 2.0; 3.0 4.0] nothing diff quotient:[-0.40519235122715697 0.19675712203959242; 0.2951356834479667 -0.11005666772367913] A*exp(tA): [-0.4051924439546264 0.1967571339831402; 0.29513570097471 -0.11005674297991597] exp(tA)*A: [-0.4051924439546264 0.19675713398314; 0.2951357009747102 -0.11005674297991597] nothing ### Answer For this question we approximate the derivative of exp(tA) by using difference quotients for various values of t and epsilon of 10^-6. We compare this value to A*exp(tA) and exp(tA)*A. A*exp(tA) and exp(tA)*A are the same up to a very high degree of precision and our difference quotient is also very close. It seems that both A*exp(tA) and exp(tA)*A are the correct derivative. (b) Numerically investigate the claim that if $A$ is diagonalizable as $V D V^{-1}$, then the matrix exponential can be calcluated as $V \exp.(D) V^{-1}$. In other words, the idea is that you can matrix exponentiate by diagonalizing and applying the exponential function entry-wise to the diagonal matrix. ```julia B = [1 2; 2 1] function is_this_correct2(matrix) D, V = eigen(matrix) println(V*exp.(diagm(D))*inv(V)) println(exp(matrix)) end is_this_correct2(A) is_this_correct2(B) ``` [52.82644912441753 75.25106032243072; 112.61934260593233 163.21631012349727] [51.968956198705044 74.73656456700328; 112.10484685050491 164.07380304920997] [9.226708182179554 9.85882874100811; 9.858828741008113 11.226708182179555] [10.226708182179554 9.85882874100811; 9.85882874100811 10.226708182179554] ### Answer For this question we have a function that prints two matrices. One evaluated as V*exp.(D)*V inverse and the other as exp() of our matrix. We run this function on two diagnolizable matrices, one that is symmetric and one that is not. For both we see that our resulting matrices are close but off by enough to raise concern. It is possible that this is do to machine error being amplified during computation. However we observe that if we replace exp.(D) with exp(D) our results are within an extremely small margin of error. ```julia B = [1 2; 2 1] function is_this_correct2(matrix) D, V = eigen(matrix) println(V*exp(diagm(D))*inv(V)) println(exp(matrix)) end is_this_correct2(A) is_this_correct2(B) ``` [51.96895619870499 74.73656456700319; 112.10484685050479 164.0738030492098] [51.968956198705044 74.73656456700328; 112.10484685050491 164.07380304920997] [10.226708182179555 9.858828741008113; 9.858828741008113 10.226708182179555] [10.226708182179554 9.85882874100811; 9.85882874100811 10.226708182179554] *Solution.* ## Problem 5 In this problem, we're going to look at a couple virtues of having the `Int8` and `Int64` data types "wrap around" from $2^n-1$ to $-2^n$ (for $n = 8$ and $n = 64$, respectively). (a) Use ordinary, by-hand arithmetic to add the binary numbers `00011011` and `00000101`. *Hint: this is exactly like decimal addition, with place-value and carrying and all that, but with 2 in place of 10.* 00011011 + 00000101 = 00100000 (b) Now apply the same, by-hand algorithm to add the Int8 numbers `00000011` and `11111001`. Does the algorithm yield the correct result, despite the second number being negative? 00000011 + 11111001 = 11111100 which is 3 - 7 = -4 so it works (c) Julia, like many languages, includes *bitshift* operators. As the name suggests, these operators shift a value's underlying bits over a specified number of positions: ```julia twentyone = parse(Int8, "21") bitstring(twentyone) ``` "00010101" ```julia bitstring(twentyone >>> 1) ``` "00001010" ```julia bitstring(twentyone >>> -1) ``` "00101010" We can use the bitshift operator to calculate the midpoint between two integers `lo` and `hi`: ```julia lo = 2 hi = 14 (lo + hi) >>> 1 ``` 8 (d) Explain why the formula `(lo + hi) >>> 1` gives the midpoint between `lo` and `hi`. This works because the formula for mid point is (hi + lo) / 2 and moving the bits over 1 to the right is the same as division by 2. This is because for any given bit n, n-1 is half its value (e) Show that if `n` is equal to `2^62`, this formula gives the correct midpoint between `n` and `2n`, even though the intermediate value `2n` is actually *negative* in the Int64 system. Show also that the more straightforward formula `(n + 2n) ÷ 2` gives a mathematically incorrect result in this overflow context. ## Problem 6 Consider the following PRNG (which was actually widely used in the early 1970s): we begin with an odd positive integer $a_1$ less than $2^{31}$ and for all $n \geq 2$, we define $a_n$ to be the remainder when dividing $65539a_{n-1}$ by $2^{31}$. Use Julia to calculate $9a_{3n+1} - 6 a_{3n+2} + a_{3n+3}$ for the first $10^6$ values of $n$, and show that there are only $\textit{15}$ unique values in the resulting list (!). Based on this observation, describe what you would see if you plotted many points of the form $(a_{3n+1},a_{3n+2},a_{3n+3})$ in three-dimensional space. ```julia function PRNG1970(oddint, n) a = [oddint] for i in 1:n push!(a, mod(65539*a[end], 2^31)) end a end function f(oddint, n) seq = PRNG1970(oddint, n) length(Set([9*seq[3*n+1] - 6*seq[3*n+2] + seq[3*n+3] for n in 1:10^3])) end plot([( ``` 15 #### This problem is purely optional: --- ## Bonus Problem We have learned the representation of numbers with the `Int64` and `Float64` format. We will look a bit more into how one can implement calculations at the machine level. (a) Calculate the sum of the Int8 value with bitstring $00110101$ and the Int8 value with bitstring $b = 00011011$. (b) Descibe an algorithm for multiplying two `Int8` numbers. *Hint: You will want to multiply digit by digit, similar to hand-multiplication in base 10.* (c) Now we want to add the two `Int8` numbers $a=01110010$ and $b=00101011$, first, please convert these numbers to decimal numbers and calculate the correct sum. (d) Using `Julia` and the builtin `Int8()` function, calculate the sum described in (c). What do you find? Can you provide an explaination for this behavior? Now we will consider two `Float64` numbers. We would like to look at one way of implementing addition of `Float64` numbers, described below. For the sake of simplicity, we shall assume that we are only adding positive numbers and they do not exceed $2^{1024}$. Remember that for every `Float64` number, we have an exponent value $e$ that ranges from $0$ to $2^{11} - 1$, and a mantissa value $f$ that ranges from $0$ to $2^{52} - 1$. Say we have now a new data type `intinf`, the rules are: - Every digit is either 0 or 1, there is a "decimal point" and an unlimited number of digits on both sides of the "decimal point". - If the $n^{th}$ digit above the "decimal point" is a $1$, it represents $2^{n-1}$ - If the $n^{th}$ digit below the "decimal point" is a $1$, it represents $2^{-n}$ If you are familiar with radix points in binary numbers, this is exactly that. For example, $110.01_{[intinf]}$ = $1 * 2^2 + 1 * 2^1 + 1 * 2^{-2} = 6.25$. (e) What is $100.101_{[intinf]}$? What about $10.001_{[intinf]}$? What is $100.101_{[intinf]} + 10.001_{[intinf]}$? (f) Given the $e$ and $f$ of a `Float64` number, please represent that number in `intinf` format. You will need to use the symbols `>>` and `<<`. `a >> x` means to move the digits of `a` right by `x` spaces while holding the "decimal point" still. E.g. `1.0 >> 2 = 0.01`, `0.101 << 2 = 10.1` (g) To add two `Float64` numbers together, we will first convert them into `intinf` numbers, then add them together, and finally convert the sum back into `Float64`. With this process in mind, please write down the specific steps of adding two `Float64` numbers represented by $a = (e_a, f_a)$ and $b = (e_b, f_b)$. Your final answer should be another `Float64` number. Please give explaination to all your procedures. You are not required to use mathematical representations from start to finish, feel free to explain in words where necessary. Bonus: How would you implement multiplication of two `Float64` numbers? Again, please give sufficient reasoning and/or steps of calculation where necessary. (This is not required and will not affect your grade.) ```julia 2+2 ``` 4 ```julia ```
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Displayed.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Transport open import Cubical.Functions.FunExtEquiv open import Cubical.Data.Sigma open import Cubical.Relation.Binary private variable ℓ ℓA ℓA' ℓ≅A ℓB ℓB' ℓ≅B ℓC ℓ≅C : Level record UARel (A : Type ℓA) (ℓ≅A : Level) : Type (ℓ-max ℓA (ℓ-suc ℓ≅A)) where no-eta-equality constructor uarel field _≅_ : A → A → Type ℓ≅A ua : (a a' : A) → (a ≅ a') ≃ (a ≡ a') uaIso : (a a' : A) → Iso (a ≅ a') (a ≡ a') uaIso a a' = equivToIso (ua a a') ≅→≡ : {a a' : A} (p : a ≅ a') → a ≡ a' ≅→≡ {a} {a'} = Iso.fun (uaIso a a') ≡→≅ : {a a' : A} (p : a ≡ a') → a ≅ a' ≡→≅ {a} {a'} = Iso.inv (uaIso a a') ρ : (a : A) → a ≅ a ρ a = ≡→≅ refl open BinaryRelation -- another constructor for UARel using contractibility of relational singletons make-𝒮 : {A : Type ℓA} {ℓ≅A : Level} {_≅_ : A → A → Type ℓ≅A} (ρ : isRefl _≅_) (contrTotal : contrRelSingl _≅_) → UARel A ℓ≅A UARel._≅_ (make-𝒮 {_≅_ = _≅_} _ _) = _≅_ UARel.ua (make-𝒮 {_≅_ = _≅_} ρ c) = contrRelSingl→isUnivalent _≅_ ρ c record DUARel {A : Type ℓA} {ℓ≅A : Level} (𝒮-A : UARel A ℓ≅A) (B : A → Type ℓB) (ℓ≅B : Level) : Type (ℓ-max (ℓ-max ℓA ℓB) (ℓ-max ℓ≅A (ℓ-suc ℓ≅B))) where no-eta-equality constructor duarel open UARel 𝒮-A field _≅ᴰ⟨_⟩_ : {a a' : A} → B a → a ≅ a' → B a' → Type ℓ≅B uaᴰ : {a a' : A} (b : B a) (p : a ≅ a') (b' : B a') → (b ≅ᴰ⟨ p ⟩ b') ≃ PathP (λ i → B (≅→≡ p i)) b b' fiberRel : (a : A) → Rel (B a) (B a) ℓ≅B fiberRel a = _≅ᴰ⟨ ρ a ⟩_ uaᴰρ : {a : A} (b b' : B a) → b ≅ᴰ⟨ ρ a ⟩ b' ≃ (b ≡ b') uaᴰρ {a} b b' = compEquiv (uaᴰ b (ρ _) b') (substEquiv (λ q → PathP (λ i → B (q i)) b b') (retEq (ua a a) refl)) ρᴰ : {a : A} → (b : B a) → b ≅ᴰ⟨ ρ a ⟩ b ρᴰ {a} b = invEq (uaᴰρ b b) refl
-- | Exercises on Lists module Koans.Lists -- | What is the type of this list. nats : ?someType nats = [0,1,2,3,4,5,6,7,9] -- | Reproduce the list [0,1,3,5,7,9,2,4,6,8] using the following functions. odds : List Int odds = [1,3,5,7,9] evens : List Int evens = [2,4,6,8] zero : Int zero = 0 zeroOddsEvens : Bool zeroOddsEvens = ?fillme2 ++ odds ++ ?fillme3 == [0,1,3,5,7,9,2,4,6,8] -- | Complete the result of following functions. headOList : Bool headOList = ?fillme4 == head [5,4,3,2,1] tailOList : Bool tailOList = ?fillme5 == tail [0,1,2,3,4,5] lastOList : Bool lastOList = ?fillme6 == last [5,4,3,2,1] initOList : Bool initOList = ?fillme7 == init [1,2,3,4,5,6] lengthOList : Bool lengthOList = ?fillme8 == length [1,2,3,4,5] reverseTheList : Bool reverseTheList = ?fillme9 reverse [1,2,3,4,5] first3 : Bool first3 = ?fillme10 == take 3 [1..10] drop3 : Bool drop3 = ?fillme11 drop 3 [1..10] countAllTheNumbers : Bool countAllTheNumbers = ?fillme12 == sum [1..10] timesAllTheNnumbers : Bool timesAllTheNnumbers = ?fillme13 == product [1..10] elementOrNot : Bool elementOrNot = elem 4 ?fillme14 == True -- | Make this function true stopPete : List Nat stopPete = ?fillme15 (repeat 3) == [3,3,3,3] -- --------------------------------------------------------------------- [ EOF ]
(* Title: JinjaThreads/Framework/FWState.thy Author: Andreas Lochbihler *) header {* \chapter{The generic multithreaded semantics} \isaheader{State of the multithreaded semantics} *} theory FWState imports "../Basic/Auxiliary" begin datatype lock_action = Lock | Unlock | UnlockFail | ReleaseAcquire datatype ('t,'x,'m) new_thread_action = NewThread 't 'x 'm | ThreadExists 't bool datatype 't conditional_action = Join 't | Yield datatype ('t, 'w) wait_set_action = Suspend 'w | Notify 'w | NotifyAll 'w | WakeUp 't | Notified | WokenUp datatype 't interrupt_action = IsInterrupted 't bool | Interrupt 't | ClearInterrupt 't type_synonym 'l lock_actions = "'l \<Rightarrow>f lock_action list" translations (type) "'l lock_actions" <= (type) "'l \<Rightarrow>f lock_action list" type_synonym ('l,'t,'x,'m,'w,'o) thread_action = "'l lock_actions \<times> ('t,'x,'m) new_thread_action list \<times> 't conditional_action list \<times> ('t, 'w) wait_set_action list \<times> 't interrupt_action list \<times> 'o list" (* pretty printing for thread_action type *) print_translation {* let fun tr' [Const (@{type_syntax finfun}, _) $ l $ (Const (@{type_syntax list}, _) $ Const (@{type_syntax lock_action}, _)), Const (@{type_syntax "prod"}, _) $ (Const (@{type_syntax list}, _) $ (Const (@{type_syntax new_thread_action}, _) $ t1 $ x $ m)) $ (Const (@{type_syntax "prod"}, _) $ (Const (@{type_syntax list}, _) $ (Const (@{type_syntax conditional_action}, _) $ t2)) $ (Const (@{type_syntax "prod"}, _) $ (Const (@{type_syntax list}, _) $ (Const (@{type_syntax wait_set_action}, _) $ t3 $ w)) $ (Const (@{type_syntax "prod"}, _) $ (Const (@{type_syntax "list"}, _) $ (Const (@{type_syntax "interrupt_action"}, _) $ t4)) $ (Const (@{type_syntax "list"}, _) $ o1))))] = if t1 = t2 andalso t2 = t3 andalso t3 = t4 then Syntax.const @{type_syntax thread_action} $ l $ t1 $ x $ m $ w $ o1 else raise Match; in [(@{type_syntax "prod"}, K tr')] end *} typ "('l,'t,'x,'m,'w,'o) thread_action" definition locks_a :: "('l,'t,'x,'m,'w,'o) thread_action \<Rightarrow> 'l lock_actions" ("\<lbrace>_\<rbrace>\<^bsub>l\<^esub>" [0] 1000) where "locks_a \<equiv> fst" definition thr_a :: "('l,'t,'x,'m,'w,'o) thread_action \<Rightarrow> ('t,'x,'m) new_thread_action list" ("\<lbrace>_\<rbrace>\<^bsub>t\<^esub>" [0] 1000) where "thr_a \<equiv> fst o snd" definition cond_a :: "('l,'t,'x,'m,'w,'o) thread_action \<Rightarrow> 't conditional_action list" ("\<lbrace>_\<rbrace>\<^bsub>c\<^esub>" [0] 1000) where "cond_a = fst o snd o snd" definition wset_a :: "('l,'t,'x,'m,'w,'o) thread_action \<Rightarrow> ('t, 'w) wait_set_action list" ("\<lbrace>_\<rbrace>\<^bsub>w\<^esub>" [0] 1000) where "wset_a = fst o snd o snd o snd" definition interrupt_a :: "('l,'t,'x,'m,'w,'o) thread_action \<Rightarrow> 't interrupt_action list" ("\<lbrace>_\<rbrace>\<^bsub>i\<^esub>" [0] 1000) where "interrupt_a = fst o snd o snd o snd o snd" definition obs_a :: "('l,'t,'x,'m,'w,'o) thread_action \<Rightarrow> 'o list" ("\<lbrace>_\<rbrace>\<^bsub>o\<^esub>" [0] 1000) where "obs_a \<equiv> snd o snd o snd o snd o snd" lemma locks_a_conv [simp]: "locks_a (ls, ntsjswss) = ls" by(simp add:locks_a_def) lemma thr_a_conv [simp]: "thr_a (ls, nts, jswss) = nts" by(simp add: thr_a_def) lemma cond_a_conv [simp]: "cond_a (ls, nts, js, wws) = js" by(simp add: cond_a_def) lemma wset_a_conv [simp]: "wset_a (ls, nts, js, wss, isobs) = wss" by(simp add: wset_a_def) lemma interrupt_a_conv [simp]: "interrupt_a (ls, nts, js, ws, is, obs) = is" by(simp add: interrupt_a_def) lemma obs_a_conv [simp]: "obs_a (ls, nts, js, wss, is, obs) = obs" by(simp add: obs_a_def) fun ta_update_locks :: "('l,'t,'x,'m,'w,'o) thread_action \<Rightarrow> lock_action \<Rightarrow> 'l \<Rightarrow> ('l,'t,'x,'m,'w,'o) thread_action" where "ta_update_locks (ls, nts, js, wss, obs) lta l = (ls(l $:= ls $ l @ [lta]), nts, js, wss, obs)" fun ta_update_NewThread :: "('l,'t,'x,'m,'w,'o) thread_action \<Rightarrow> ('t,'x,'m) new_thread_action \<Rightarrow> ('l,'t,'x,'m,'w,'o) thread_action" where "ta_update_NewThread (ls, nts, js, wss, is, obs) nt = (ls, nts @ [nt], js, wss, is, obs)" fun ta_update_Conditional :: "('l,'t,'x,'m,'w,'o) thread_action \<Rightarrow> 't conditional_action \<Rightarrow> ('l,'t,'x,'m,'w,'o) thread_action" where "ta_update_Conditional (ls, nts, js, wss, is, obs) j = (ls, nts, js @ [j], wss, is, obs)" fun ta_update_wait_set :: "('l,'t,'x,'m,'w,'o) thread_action \<Rightarrow> ('t, 'w) wait_set_action \<Rightarrow> ('l,'t,'x,'m,'w,'o) thread_action" where "ta_update_wait_set (ls, nts, js, wss, is, obs) ws = (ls, nts, js, wss @ [ws], is, obs)" fun ta_update_interrupt :: "('l,'t,'x,'m,'w,'o) thread_action \<Rightarrow> 't interrupt_action \<Rightarrow> ('l,'t,'x,'m,'w,'o) thread_action" where "ta_update_interrupt (ls, nts, js, wss, is, obs) i = (ls, nts, js, wss, is @ [i], obs)" fun ta_update_obs :: "('l,'t,'x,'m,'w,'o) thread_action \<Rightarrow> 'o \<Rightarrow> ('l,'t,'x,'m,'w,'o) thread_action" where "ta_update_obs (ls, nts, js, wss, is, obs) ob = (ls, nts, js, wss, is, obs @ [ob])" abbreviation empty_ta :: "('l,'t,'x,'m,'w,'o) thread_action" where "empty_ta \<equiv> (K$ [], [], [], [], [], [])" notation (input) empty_ta ("\<epsilon>") text {* Pretty syntax for specifying thread actions: Write @{text "\<lbrace> Lock\<rightarrow>l, Unlock\<rightarrow>l, Suspend w, Interrupt t\<rbrace>"} instead of @{term "((K$ [])(l $:= [Lock, Unlock]), [], [Suspend w], [Interrupt t], [])"}. @{text "thread_action'"} is a type that contains of all basic thread actions. Automatically coerce basic thread actions into that type and then dispatch to the right update function by pattern matching. For coercion, adhoc overloading replaces the generic injection @{text "inject_thread_action"} by the specific ones, i.e. constructors. To avoid ambiguities with observable actions, the observable actions must be of sort @{text "obs_action"}, which the basic thread action types are not. *} class obs_action datatype ('l,'t,'x,'m,'w,'o) thread_action' = LockAction "lock_action \<times> 'l" | NewThreadAction "('t,'x,'m) new_thread_action" | ConditionalAction "'t conditional_action" | WaitSetAction "('t, 'w) wait_set_action" | InterruptAction "'t interrupt_action" | ObsAction 'o setup {* Sign.add_const_constraint (@{const_name ObsAction}, SOME @{typ "'o :: obs_action \<Rightarrow> ('l,'t,'x,'m,'w,'o) thread_action'"}) *} fun thread_action'_to_thread_action :: "('l,'t,'x,'m,'w,'o :: obs_action) thread_action' \<Rightarrow> ('l,'t,'x,'m,'w,'o) thread_action \<Rightarrow> ('l,'t,'x,'m,'w,'o) thread_action" where "thread_action'_to_thread_action (LockAction (la, l)) ta = ta_update_locks ta la l" | "thread_action'_to_thread_action (NewThreadAction nt) ta = ta_update_NewThread ta nt" | "thread_action'_to_thread_action (ConditionalAction ca) ta = ta_update_Conditional ta ca" | "thread_action'_to_thread_action (WaitSetAction wa) ta = ta_update_wait_set ta wa" | "thread_action'_to_thread_action (InterruptAction ia) ta = ta_update_interrupt ta ia" | "thread_action'_to_thread_action (ObsAction ob) ta = ta_update_obs ta ob" consts inject_thread_action :: "'a \<Rightarrow> ('l,'t,'x,'m,'w,'o) thread_action'" nonterminal ta_let and ta_lets syntax "_ta_snoc" :: "ta_lets \<Rightarrow> ta_let \<Rightarrow> ta_lets" ("_,/ _") "_ta_block" :: "ta_lets \<Rightarrow> 'a" ("\<lbrace>_\<rbrace>" [0] 1000) "_ta_empty" :: "ta_lets" ("") "_ta_single" :: "ta_let \<Rightarrow> ta_lets" ("_") "_ta_inject" :: "logic \<Rightarrow> ta_let" ("(_)") "_ta_lock" :: "logic \<Rightarrow> logic \<Rightarrow> ta_let" ("_\<rightarrow>_") translations "_ta_block _ta_empty" == "CONST empty_ta" "_ta_block (_ta_single bta)" == "_ta_block (_ta_snoc _ta_empty bta)" "_ta_inject bta" == "CONST inject_thread_action bta" "_ta_lock la l" == "CONST inject_thread_action (CONST Pair la l)" "_ta_block (_ta_snoc btas bta)" == "CONST thread_action'_to_thread_action bta (_ta_block btas)" adhoc_overloading inject_thread_action NewThreadAction ConditionalAction WaitSetAction InterruptAction ObsAction LockAction lemma ta_upd_proj_simps [simp]: shows ta_obs_proj_simps: "\<lbrace>ta_update_obs ta obs\<rbrace>\<^bsub>l\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>l\<^esub>" "\<lbrace>ta_update_obs ta obs\<rbrace>\<^bsub>t\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>t\<^esub>" "\<lbrace>ta_update_obs ta obs\<rbrace>\<^bsub>w\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>w\<^esub>" "\<lbrace>ta_update_obs ta obs\<rbrace>\<^bsub>c\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>c\<^esub>" "\<lbrace>ta_update_obs ta obs\<rbrace>\<^bsub>i\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>i\<^esub>" "\<lbrace>ta_update_obs ta obs\<rbrace>\<^bsub>o\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>o\<^esub> @ [obs]" and ta_lock_proj_simps: "\<lbrace>ta_update_locks ta x l\<rbrace>\<^bsub>l\<^esub> = (let ls = \<lbrace>ta\<rbrace>\<^bsub>l\<^esub> in ls(l $:= ls $ l @ [x]))" "\<lbrace>ta_update_locks ta x l\<rbrace>\<^bsub>t\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>t\<^esub>" "\<lbrace>ta_update_locks ta x l\<rbrace>\<^bsub>w\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>w\<^esub>" "\<lbrace>ta_update_locks ta x l\<rbrace>\<^bsub>c\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>c\<^esub>" "\<lbrace>ta_update_locks ta x l\<rbrace>\<^bsub>i\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>i\<^esub>" "\<lbrace>ta_update_locks ta x l\<rbrace>\<^bsub>o\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>o\<^esub>" and ta_thread_proj_simps: "\<lbrace>ta_update_NewThread ta t\<rbrace>\<^bsub>l\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>l\<^esub>" "\<lbrace>ta_update_NewThread ta t\<rbrace>\<^bsub>t\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>t\<^esub> @ [t]" "\<lbrace>ta_update_NewThread ta t\<rbrace>\<^bsub>w\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>w\<^esub>" "\<lbrace>ta_update_NewThread ta t\<rbrace>\<^bsub>c\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>c\<^esub>" "\<lbrace>ta_update_NewThread ta t\<rbrace>\<^bsub>i\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>i\<^esub>" "\<lbrace>ta_update_NewThread ta t\<rbrace>\<^bsub>o\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>o\<^esub>" and ta_wset_proj_simps: "\<lbrace>ta_update_wait_set ta w\<rbrace>\<^bsub>l\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>l\<^esub>" "\<lbrace>ta_update_wait_set ta w\<rbrace>\<^bsub>t\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>t\<^esub>" "\<lbrace>ta_update_wait_set ta w\<rbrace>\<^bsub>w\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>w\<^esub> @ [w]" "\<lbrace>ta_update_wait_set ta w\<rbrace>\<^bsub>c\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>c\<^esub>" "\<lbrace>ta_update_wait_set ta w\<rbrace>\<^bsub>i\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>i\<^esub>" "\<lbrace>ta_update_wait_set ta w\<rbrace>\<^bsub>o\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>o\<^esub>" and ta_cond_proj_simps: "\<lbrace>ta_update_Conditional ta c\<rbrace>\<^bsub>l\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>l\<^esub>" "\<lbrace>ta_update_Conditional ta c\<rbrace>\<^bsub>t\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>t\<^esub>" "\<lbrace>ta_update_Conditional ta c\<rbrace>\<^bsub>w\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>w\<^esub>" "\<lbrace>ta_update_Conditional ta c\<rbrace>\<^bsub>c\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>c\<^esub> @ [c]" "\<lbrace>ta_update_Conditional ta c\<rbrace>\<^bsub>i\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>i\<^esub>" "\<lbrace>ta_update_Conditional ta c\<rbrace>\<^bsub>o\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>o\<^esub>" and ta_interrupt_proj_simps: "\<lbrace>ta_update_interrupt ta i\<rbrace>\<^bsub>l\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>l\<^esub>" "\<lbrace>ta_update_interrupt ta i\<rbrace>\<^bsub>t\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>t\<^esub>" "\<lbrace>ta_update_interrupt ta i\<rbrace>\<^bsub>c\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>c\<^esub>" "\<lbrace>ta_update_interrupt ta i\<rbrace>\<^bsub>w\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>w\<^esub>" "\<lbrace>ta_update_interrupt ta i\<rbrace>\<^bsub>i\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>i\<^esub> @ [i]" "\<lbrace>ta_update_interrupt ta i\<rbrace>\<^bsub>o\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>o\<^esub>" by(cases ta, simp)+ lemma thread_action'_to_thread_action_proj_simps [simp]: shows thread_action'_to_thread_action_proj_locks_simps: "\<lbrace>thread_action'_to_thread_action (LockAction (la, l)) ta\<rbrace>\<^bsub>l\<^esub> = \<lbrace>ta_update_locks ta la l\<rbrace>\<^bsub>l\<^esub>" "\<lbrace>thread_action'_to_thread_action (NewThreadAction nt) ta\<rbrace>\<^bsub>l\<^esub> = \<lbrace>ta_update_NewThread ta nt\<rbrace>\<^bsub>l\<^esub>" "\<lbrace>thread_action'_to_thread_action (ConditionalAction ca) ta\<rbrace>\<^bsub>l\<^esub> = \<lbrace>ta_update_Conditional ta ca\<rbrace>\<^bsub>l\<^esub>" "\<lbrace>thread_action'_to_thread_action (WaitSetAction wa) ta\<rbrace>\<^bsub>l\<^esub> = \<lbrace>ta_update_wait_set ta wa\<rbrace>\<^bsub>l\<^esub>" "\<lbrace>thread_action'_to_thread_action (InterruptAction ia) ta\<rbrace>\<^bsub>l\<^esub> = \<lbrace>ta_update_interrupt ta ia\<rbrace>\<^bsub>l\<^esub>" "\<lbrace>thread_action'_to_thread_action (ObsAction ob) ta\<rbrace>\<^bsub>l\<^esub> = \<lbrace>ta_update_obs ta ob\<rbrace>\<^bsub>l\<^esub>" and thread_action'_to_thread_action_proj_nt_simps: "\<lbrace>thread_action'_to_thread_action (LockAction (la, l)) ta\<rbrace>\<^bsub>t\<^esub> = \<lbrace>ta_update_locks ta la l\<rbrace>\<^bsub>t\<^esub>" "\<lbrace>thread_action'_to_thread_action (NewThreadAction nt) ta\<rbrace>\<^bsub>t\<^esub> = \<lbrace>ta_update_NewThread ta nt\<rbrace>\<^bsub>t\<^esub>" "\<lbrace>thread_action'_to_thread_action (ConditionalAction ca) ta\<rbrace>\<^bsub>t\<^esub> = \<lbrace>ta_update_Conditional ta ca\<rbrace>\<^bsub>t\<^esub>" "\<lbrace>thread_action'_to_thread_action (WaitSetAction wa) ta\<rbrace>\<^bsub>t\<^esub> = \<lbrace>ta_update_wait_set ta wa\<rbrace>\<^bsub>t\<^esub>" "\<lbrace>thread_action'_to_thread_action (InterruptAction ia) ta\<rbrace>\<^bsub>t\<^esub> = \<lbrace>ta_update_interrupt ta ia\<rbrace>\<^bsub>t\<^esub>" "\<lbrace>thread_action'_to_thread_action (ObsAction ob) ta\<rbrace>\<^bsub>t\<^esub> = \<lbrace>ta_update_obs ta ob\<rbrace>\<^bsub>t\<^esub>" and thread_action'_to_thread_action_proj_cond_simps: "\<lbrace>thread_action'_to_thread_action (LockAction (la, l)) ta\<rbrace>\<^bsub>c\<^esub> = \<lbrace>ta_update_locks ta la l\<rbrace>\<^bsub>c\<^esub>" "\<lbrace>thread_action'_to_thread_action (NewThreadAction nt) ta\<rbrace>\<^bsub>c\<^esub> = \<lbrace>ta_update_NewThread ta nt\<rbrace>\<^bsub>c\<^esub>" "\<lbrace>thread_action'_to_thread_action (ConditionalAction ca) ta\<rbrace>\<^bsub>c\<^esub> = \<lbrace>ta_update_Conditional ta ca\<rbrace>\<^bsub>c\<^esub>" "\<lbrace>thread_action'_to_thread_action (WaitSetAction wa) ta\<rbrace>\<^bsub>c\<^esub> = \<lbrace>ta_update_wait_set ta wa\<rbrace>\<^bsub>c\<^esub>" "\<lbrace>thread_action'_to_thread_action (InterruptAction ia) ta\<rbrace>\<^bsub>c\<^esub> = \<lbrace>ta_update_interrupt ta ia\<rbrace>\<^bsub>c\<^esub>" "\<lbrace>thread_action'_to_thread_action (ObsAction ob) ta\<rbrace>\<^bsub>c\<^esub> = \<lbrace>ta_update_obs ta ob\<rbrace>\<^bsub>c\<^esub>" and thread_action'_to_thread_action_proj_wset_simps: "\<lbrace>thread_action'_to_thread_action (LockAction (la, l)) ta\<rbrace>\<^bsub>w\<^esub> = \<lbrace>ta_update_locks ta la l\<rbrace>\<^bsub>w\<^esub>" "\<lbrace>thread_action'_to_thread_action (NewThreadAction nt) ta\<rbrace>\<^bsub>w\<^esub> = \<lbrace>ta_update_NewThread ta nt\<rbrace>\<^bsub>w\<^esub>" "\<lbrace>thread_action'_to_thread_action (ConditionalAction ca) ta\<rbrace>\<^bsub>w\<^esub> = \<lbrace>ta_update_Conditional ta ca\<rbrace>\<^bsub>w\<^esub>" "\<lbrace>thread_action'_to_thread_action (WaitSetAction wa) ta\<rbrace>\<^bsub>w\<^esub> = \<lbrace>ta_update_wait_set ta wa\<rbrace>\<^bsub>w\<^esub>" "\<lbrace>thread_action'_to_thread_action (InterruptAction ia) ta\<rbrace>\<^bsub>w\<^esub> = \<lbrace>ta_update_interrupt ta ia\<rbrace>\<^bsub>w\<^esub>" "\<lbrace>thread_action'_to_thread_action (ObsAction ob) ta\<rbrace>\<^bsub>w\<^esub> = \<lbrace>ta_update_obs ta ob\<rbrace>\<^bsub>w\<^esub>" and thread_action'_to_thread_action_proj_interrupt_simps: "\<lbrace>thread_action'_to_thread_action (LockAction (la, l)) ta\<rbrace>\<^bsub>i\<^esub> = \<lbrace>ta_update_locks ta la l\<rbrace>\<^bsub>i\<^esub>" "\<lbrace>thread_action'_to_thread_action (NewThreadAction nt) ta\<rbrace>\<^bsub>i\<^esub> = \<lbrace>ta_update_NewThread ta nt\<rbrace>\<^bsub>i\<^esub>" "\<lbrace>thread_action'_to_thread_action (ConditionalAction ca) ta\<rbrace>\<^bsub>i\<^esub> = \<lbrace>ta_update_Conditional ta ca\<rbrace>\<^bsub>i\<^esub>" "\<lbrace>thread_action'_to_thread_action (WaitSetAction wa) ta\<rbrace>\<^bsub>i\<^esub> = \<lbrace>ta_update_wait_set ta wa\<rbrace>\<^bsub>i\<^esub>" "\<lbrace>thread_action'_to_thread_action (InterruptAction ia) ta\<rbrace>\<^bsub>i\<^esub> = \<lbrace>ta_update_interrupt ta ia\<rbrace>\<^bsub>i\<^esub>" "\<lbrace>thread_action'_to_thread_action (ObsAction ob) ta\<rbrace>\<^bsub>i\<^esub> = \<lbrace>ta_update_obs ta ob\<rbrace>\<^bsub>i\<^esub>" and thread_action'_to_thread_action_proj_obs_simps: "\<lbrace>thread_action'_to_thread_action (LockAction (la, l)) ta\<rbrace>\<^bsub>o\<^esub> = \<lbrace>ta_update_locks ta la l\<rbrace>\<^bsub>o\<^esub>" "\<lbrace>thread_action'_to_thread_action (NewThreadAction nt) ta\<rbrace>\<^bsub>o\<^esub> = \<lbrace>ta_update_NewThread ta nt\<rbrace>\<^bsub>o\<^esub>" "\<lbrace>thread_action'_to_thread_action (ConditionalAction ca) ta\<rbrace>\<^bsub>o\<^esub> = \<lbrace>ta_update_Conditional ta ca\<rbrace>\<^bsub>o\<^esub>" "\<lbrace>thread_action'_to_thread_action (WaitSetAction wa) ta\<rbrace>\<^bsub>o\<^esub> = \<lbrace>ta_update_wait_set ta wa\<rbrace>\<^bsub>o\<^esub>" "\<lbrace>thread_action'_to_thread_action (InterruptAction ia) ta\<rbrace>\<^bsub>o\<^esub> = \<lbrace>ta_update_interrupt ta ia\<rbrace>\<^bsub>o\<^esub>" "\<lbrace>thread_action'_to_thread_action (ObsAction ob) ta\<rbrace>\<^bsub>o\<^esub> = \<lbrace>ta_update_obs ta ob\<rbrace>\<^bsub>o\<^esub>" by(simp_all) lemmas ta_upd_simps = ta_update_locks.simps ta_update_NewThread.simps ta_update_Conditional.simps ta_update_wait_set.simps ta_update_interrupt.simps ta_update_obs.simps thread_action'_to_thread_action.simps declare ta_upd_simps [simp del] hide_const (open) LockAction NewThreadAction ConditionalAction WaitSetAction InterruptAction ObsAction thread_action'_to_thread_action hide_type (open) thread_action' datatype wake_up_status = WSNotified | WSWokenUp datatype 'w wait_set_status = InWS 'w | PostWS wake_up_status type_synonym 't lock = "('t \<times> nat) option" type_synonym ('l,'t) locks = "'l \<Rightarrow>f 't lock" type_synonym 'l released_locks = "'l \<Rightarrow>f nat" type_synonym ('l,'t,'x) thread_info = "'t \<rightharpoonup> ('x \<times> 'l released_locks)" type_synonym ('w,'t) wait_sets = "'t \<rightharpoonup> 'w wait_set_status" type_synonym 't interrupts = "'t set" type_synonym ('l,'t,'x,'m,'w) state = "('l,'t) locks \<times> (('l,'t,'x) thread_info \<times> 'm) \<times> ('w,'t) wait_sets \<times> 't interrupts" translations (type) "('l, 't) locks" <= (type) "'l \<Rightarrow>f ('t \<times> nat) option" (type) "('l, 't, 'x) thread_info" <= (type) "'t \<rightharpoonup> ('x \<times> ('l \<Rightarrow>f nat))" (* pretty printing for state type *) print_translation {* let fun tr' [Const (@{type_syntax finfun}, _) $ l1 $ (Const (@{type_syntax option}, _) $ (Const (@{type_syntax "prod"}, _) $ t1 $ Const (@{type_syntax nat}, _))), Const (@{type_syntax "prod"}, _) $ (Const (@{type_syntax "prod"}, _) $ (Const (@{type_syntax fun}, _) $ t2 $ (Const (@{type_syntax option}, _) $ (Const (@{type_syntax "prod"}, _) $ x $ (Const (@{type_syntax finfun}, _) $ l2 $ Const (@{type_syntax nat}, _))))) $ m) $ (Const (@{type_syntax prod}, _) $ (Const (@{type_syntax fun}, _) $ t3 $ (Const (@{type_syntax option}, _) $ (Const (@{type_syntax wait_set_status}, _) $ w))) $ (Const (@{type_syntax fun}, _) $ t4 $ (Const (@{type_syntax bool}, _))))] = if t1 = t2 andalso t1 = t3 andalso t1 = t4 andalso l1 = l2 then Syntax.const @{type_syntax state} $ l1 $ t1 $ x $ m $ w else raise Match; in [(@{type_syntax "prod"}, K tr')] end *} typ "('l,'t,'x,'m,'w) state" abbreviation no_wait_locks :: "'l \<Rightarrow>f nat" where "no_wait_locks \<equiv> (K$ 0)" lemma neq_no_wait_locks_conv: "ln \<noteq> no_wait_locks \<longleftrightarrow> (\<exists>l. ln $ l > 0)" by(auto simp add: expand_finfun_eq fun_eq_iff) lemma neq_no_wait_locksE: assumes "ln \<noteq> no_wait_locks" obtains l where "ln $ l > 0" using assms by(auto simp add: neq_no_wait_locks_conv) text {* Use type variables for components instead of @{typ "('l,'t,'x,'m,'w) state"} in types for state projections to allow to reuse them for refined state implementations for code generation. *} definition locks :: "('locks \<times> ('thread_info \<times> 'm) \<times> 'wsets \<times> 'interrupts) \<Rightarrow> 'locks" where "locks lstsmws \<equiv> fst lstsmws" definition thr :: "('locks \<times> ('thread_info \<times> 'm) \<times> 'wsets \<times> 'interrupts) \<Rightarrow> 'thread_info" where "thr lstsmws \<equiv> fst (fst (snd lstsmws))" definition shr :: "('locks \<times> ('thread_info \<times> 'm) \<times> 'wsets \<times> 'interrupts) \<Rightarrow> 'm" where "shr lstsmws \<equiv> snd (fst (snd lstsmws))" definition wset :: "('locks \<times> ('thread_info \<times> 'm) \<times> 'wsets \<times> 'interrupts) \<Rightarrow> 'wsets" where "wset lstsmws \<equiv> fst (snd (snd lstsmws))" definition interrupts :: "('locks \<times> ('thread_info \<times> 'm) \<times> 'wsets \<times> 'interrupts) \<Rightarrow> 'interrupts" where "interrupts lstsmws \<equiv> snd (snd (snd lstsmws))" lemma locks_conv [simp]: "locks (ls, tsmws) = ls" by(simp add: locks_def) lemma thr_conv [simp]: "thr (ls, (ts, m), ws) = ts" by(simp add: thr_def) lemma shr_conv [simp]: "shr (ls, (ts, m), ws, is) = m" by(simp add: shr_def) lemma wset_conv [simp]: "wset (ls, (ts, m), ws, is) = ws" by(simp add: wset_def) lemma interrupts_conv [simp]: "interrupts (ls, (ts, m), ws, is) = is" by(simp add: interrupts_def) primrec convert_new_thread_action :: "('x \<Rightarrow> 'x') \<Rightarrow> ('t,'x,'m) new_thread_action \<Rightarrow> ('t,'x','m) new_thread_action" where "convert_new_thread_action f (NewThread t x m) = NewThread t (f x) m" | "convert_new_thread_action f (ThreadExists t b) = ThreadExists t b" lemma convert_new_thread_action_inv [simp]: "NewThread t x h = convert_new_thread_action f nta \<longleftrightarrow> (\<exists>x'. nta = NewThread t x' h \<and> x = f x')" "ThreadExists t b = convert_new_thread_action f nta \<longleftrightarrow> nta = ThreadExists t b" "convert_new_thread_action f nta = NewThread t x h \<longleftrightarrow> (\<exists>x'. nta = NewThread t x' h \<and> x = f x')" "convert_new_thread_action f nta = ThreadExists t b \<longleftrightarrow> nta = ThreadExists t b" by(cases nta, auto)+ lemma convert_new_thread_action_eqI: "\<lbrakk> \<And>t x m. nta = NewThread t x m \<Longrightarrow> nta' = NewThread t (f x) m; \<And>t b. nta = ThreadExists t b \<Longrightarrow> nta' = ThreadExists t b \<rbrakk> \<Longrightarrow> convert_new_thread_action f nta = nta'" apply(cases nta) apply fastforce+ done lemma convert_new_thread_action_compose [simp]: "convert_new_thread_action f (convert_new_thread_action g ta) = convert_new_thread_action (f o g) ta" apply(cases ta) apply(simp_all add: convert_new_thread_action_def) done lemma inj_convert_new_thread_action [simp]: "inj (convert_new_thread_action f) = inj f" apply(rule iffI) apply(rule injI) apply(drule_tac x="NewThread undefined x undefined" in injD) apply auto[2] apply(rule injI) apply(case_tac x) apply(auto dest: injD) done lemma convert_new_thread_action_id: "convert_new_thread_action id = (id :: ('t, 'x, 'm) new_thread_action \<Rightarrow> ('t, 'x, 'm) new_thread_action)" (is ?thesis1) "convert_new_thread_action (\<lambda>x. x) = (id :: ('t, 'x, 'm) new_thread_action \<Rightarrow> ('t, 'x, 'm) new_thread_action)" (is ?thesis2) proof - show ?thesis1 by(rule ext)(case_tac x, simp_all) thus ?thesis2 by(simp add: id_def) qed definition convert_extTA :: "('x \<Rightarrow> 'x') \<Rightarrow> ('l,'t,'x,'m,'w,'o) thread_action \<Rightarrow> ('l,'t,'x','m,'w,'o) thread_action" where "convert_extTA f ta = (\<lbrace>ta\<rbrace>\<^bsub>l\<^esub>, map (convert_new_thread_action f) \<lbrace>ta\<rbrace>\<^bsub>t\<^esub>, snd (snd ta))" lemma convert_extTA_simps [simp]: "convert_extTA f \<epsilon> = \<epsilon>" "\<lbrace>convert_extTA f ta\<rbrace>\<^bsub>l\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>l\<^esub>" "\<lbrace>convert_extTA f ta\<rbrace>\<^bsub>t\<^esub> = map (convert_new_thread_action f) \<lbrace>ta\<rbrace>\<^bsub>t\<^esub>" "\<lbrace>convert_extTA f ta\<rbrace>\<^bsub>c\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>c\<^esub>" "\<lbrace>convert_extTA f ta\<rbrace>\<^bsub>w\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>w\<^esub>" "\<lbrace>convert_extTA f ta\<rbrace>\<^bsub>i\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>i\<^esub>" "convert_extTA f (las, tas, was, cas, is, obs) = (las, map (convert_new_thread_action f) tas, was, cas, is, obs)" apply(simp_all add: convert_extTA_def) apply(cases ta, simp)+ done lemma convert_extTA_eq_conv: "convert_extTA f ta = ta' \<longleftrightarrow> \<lbrace>ta\<rbrace>\<^bsub>l\<^esub> = \<lbrace>ta'\<rbrace>\<^bsub>l\<^esub> \<and> \<lbrace>ta\<rbrace>\<^bsub>c\<^esub> = \<lbrace>ta'\<rbrace>\<^bsub>c\<^esub> \<and> \<lbrace>ta\<rbrace>\<^bsub>w\<^esub> = \<lbrace>ta'\<rbrace>\<^bsub>w\<^esub> \<and> \<lbrace>ta\<rbrace>\<^bsub>o\<^esub> = \<lbrace>ta'\<rbrace>\<^bsub>o\<^esub> \<and> \<lbrace>ta\<rbrace>\<^bsub>i\<^esub> = \<lbrace>ta'\<rbrace>\<^bsub>i\<^esub> \<and> length \<lbrace>ta\<rbrace>\<^bsub>t\<^esub> = length \<lbrace>ta'\<rbrace>\<^bsub>t\<^esub> \<and> (\<forall>n < length \<lbrace>ta\<rbrace>\<^bsub>t\<^esub>. convert_new_thread_action f (\<lbrace>ta\<rbrace>\<^bsub>t\<^esub> ! n) = \<lbrace>ta'\<rbrace>\<^bsub>t\<^esub> ! n)" apply(cases ta, cases ta') apply(auto simp add: convert_extTA_def map_eq_all_nth_conv) done lemma convert_extTA_compose [simp]: "convert_extTA f (convert_extTA g ta) = convert_extTA (f o g) ta" by(simp add: convert_extTA_def) lemma obs_a_convert_extTA [simp]: "obs_a (convert_extTA f ta) = obs_a ta" by(cases ta) simp text {* Actions for thread start/finish *} datatype 'o action = NormalAction 'o | InitialThreadAction | ThreadFinishAction instance action :: (type) obs_action proof qed definition convert_obs_initial :: "('l,'t,'x,'m,'w,'o) thread_action \<Rightarrow> ('l,'t,'x,'m,'w,'o action) thread_action" where "convert_obs_initial ta = (\<lbrace>ta\<rbrace>\<^bsub>l\<^esub>, \<lbrace>ta\<rbrace>\<^bsub>t\<^esub>, \<lbrace>ta\<rbrace>\<^bsub>c\<^esub>, \<lbrace>ta\<rbrace>\<^bsub>w\<^esub>, \<lbrace>ta\<rbrace>\<^bsub>i\<^esub>, map NormalAction \<lbrace>ta\<rbrace>\<^bsub>o\<^esub>)" lemma inj_NormalAction [simp]: "inj NormalAction" by(rule injI) auto lemma convert_obs_initial_inject [simp]: "convert_obs_initial ta = convert_obs_initial ta' \<longleftrightarrow> ta = ta'" by(cases ta)(cases ta', auto simp add: convert_obs_initial_def) lemma convert_obs_initial_empty_TA [simp]: "convert_obs_initial \<epsilon> = \<epsilon>" by(simp add: convert_obs_initial_def) lemma convert_obs_initial_eq_empty_TA [simp]: "convert_obs_initial ta = \<epsilon> \<longleftrightarrow> ta = \<epsilon>" "\<epsilon> = convert_obs_initial ta \<longleftrightarrow> ta = \<epsilon>" by(case_tac [!] ta)(auto simp add: convert_obs_initial_def) lemma convert_obs_initial_simps [simp]: "\<lbrace>convert_obs_initial ta\<rbrace>\<^bsub>o\<^esub> = map NormalAction \<lbrace>ta\<rbrace>\<^bsub>o\<^esub>" "\<lbrace>convert_obs_initial ta\<rbrace>\<^bsub>l\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>l\<^esub>" "\<lbrace>convert_obs_initial ta\<rbrace>\<^bsub>t\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>t\<^esub>" "\<lbrace>convert_obs_initial ta\<rbrace>\<^bsub>c\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>c\<^esub>" "\<lbrace>convert_obs_initial ta\<rbrace>\<^bsub>w\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>w\<^esub>" "\<lbrace>convert_obs_initial ta\<rbrace>\<^bsub>i\<^esub> = \<lbrace>ta\<rbrace>\<^bsub>i\<^esub>" by(simp_all add: convert_obs_initial_def) type_synonym ('l,'t,'x,'m,'w,'o) semantics = "'t \<Rightarrow> 'x \<times> 'm \<Rightarrow> ('l,'t,'x,'m,'w,'o) thread_action \<Rightarrow> 'x \<times> 'm \<Rightarrow> bool" (* pretty printing for semantics *) print_translation {* let fun tr' [t4, Const (@{type_syntax fun}, _) $ (Const (@{type_syntax "prod"}, _) $ x1 $ m1) $ (Const (@{type_syntax fun}, _) $ (Const (@{type_syntax "prod"}, _) $ (Const (@{type_syntax finfun}, _) $ l $ (Const (@{type_syntax list}, _) $ Const (@{type_syntax lock_action}, _))) $ (Const (@{type_syntax "prod"}, _) $ (Const (@{type_syntax list}, _) $ (Const (@{type_syntax new_thread_action}, _) $ t1 $ x2 $ m2)) $ (Const (@{type_syntax "prod"}, _) $ (Const (@{type_syntax list}, _) $ (Const (@{type_syntax conditional_action}, _) $ t2)) $ (Const (@{type_syntax "prod"}, _) $ (Const (@{type_syntax list}, _) $ (Const (@{type_syntax wait_set_action}, _) $ t3 $ w)) $ (Const (@{type_syntax prod}, _) $ (Const (@{type_syntax list}, _) $ (Const (@{type_syntax interrupt_action}, _) $ t5)) $ (Const (@{type_syntax list}, _) $ o1)))))) $ (Const (@{type_syntax fun}, _) $ (Const (@{type_syntax "prod"}, _) $ x3 $ m3) $ Const (@{type_syntax bool}, _)))] = if x1 = x2 andalso x1 = x3 andalso m1 = m2 andalso m1 = m3 andalso t1 = t2 andalso t2 = t3 andalso t3 = t4 andalso t4 = t5 then Syntax.const @{type_syntax semantics} $ l $ t1 $ x1 $ m1 $ w $ o1 else raise Match; in [(@{type_syntax fun}, K tr')] end *} typ "('l,'t,'x,'m,'w,'o) semantics" end
module Data.Scientific import Data.Fin import Data.List import Data.Vect ||| Arbitrary precision coefficient for scientific notation in base b. ||| Representants are unique regarding (==) and there are no trailing zeros. ||| For a coefficient x this holds: ||| 1 <= x < b public export data Coefficient : (b : Nat) -> Type where CoeffInt : Fin (S b) -> Coefficient (S (S b)) CoeffFloat : Fin (S b) -> List (Fin (S (S b))) -> Fin (S b) -> Coefficient (S (S b)) public export Uninhabited (Coefficient 0) where uninhabited _ impossible public export Uninhabited (Coefficient 1) where uninhabited _ impossible public export Eq (Coefficient b) where (CoeffInt x) == (CoeffInt y) = x == y (CoeffFloat x xs x') == (CoeffFloat y ys y') = x == y && xs == ys && x' == y' _ == _ = False public export Ord (Coefficient b) where compare (CoeffInt x) (CoeffInt y) = compare x y compare (CoeffInt x) (CoeffFloat y ys y') = case compare x y of EQ => LT comp => comp compare (CoeffFloat x xs x') (CoeffInt y) = case compare x y of EQ => GT comp => comp compare (CoeffFloat x xs x') (CoeffFloat y ys y') = compare (FS x :: xs `snoc` FS x') (FS y :: ys `snoc` FS y') private prettyShowDigit : Fin 10 -> Char prettyShowDigit x = case x of 0 => '0' 1 => '1' 2 => '2' 3 => '3' 4 => '4' 5 => '5' 6 => '6' 7 => '7' 8 => '8' 9 => '9' private prettyShowCoefficient : Coefficient 10 -> String prettyShowCoefficient (CoeffInt x) = pack [ prettyShowDigit (FS x) ] prettyShowCoefficient (CoeffFloat x xs x') = pack $ [ prettyShowDigit (FS x), '.' ] ++ map prettyShowDigit xs ++ [ prettyShowDigit (FS x') ] public export data Sign = Positive | Negative public export Eq Sign where Positive == Positive = True Negative == Negative = True _ == _ = False public export Ord Sign where compare Positive Positive = EQ compare Positive Negative = GT compare Negative Positive = LT compare Negative Negative = EQ private prettyShowSign : Sign -> String prettyShowSign s = case s of Positive => "" Negative => "-" ||| A scientific notation numeral in base b. ||| Representants are unique, as this type is built on top of Coefficient. ||| The numbers x represented are those which can be written as a finite sum of powers of b: ||| x = \Sigma_{i=n}^m a_i * b^i , {n,m : Integer; a_i : Fin b} public export data Scientific : (b : Nat) -> Type where SciZ : Scientific (S (S b)) Sci : Sign -> Coefficient b -> Integer -> Scientific b public export Uninhabited (Scientific 0) where uninhabited (Sci _ _ _) impossible public export Uninhabited (Scientific 1) where uninhabited (Sci _ _ _) impossible public export Eq (Scientific b) where SciZ == SciZ = True (Sci s c e) == (Sci s' c' e') = s == s' && c == c' && e == e' _ == _ = False public export Ord (Scientific b) where compare SciZ SciZ = EQ compare SciZ (Sci s _ _) = case s of Positive => LT Negative => GT compare (Sci s _ _) SciZ = case s of Positive => GT Negative => LT compare (Sci s c e) (Sci s' c' e') = case (s, s') of (Positive, Positive) => case compare e e' of EQ => compare c c' comp => comp (Positive, Negative) => GT (Negative, Positive) => LT (Negative, Negative) => case compare e' e of EQ => compare c' c comp => comp infixl 9 ^ private (^) : Nat -> Nat -> Nat x ^ Z = 1 x ^ (S k) = x * (x ^ k) private digitsToNat : {b : _} -> List (Fin (S (S b))) -> Nat digitsToNat [] = 0 digitsToNat (x::xs) = finToNat x + (S (S b)) * digitsToNat xs export toInteger : {b : _} -> Scientific b -> Maybe Integer toInteger SciZ = Just 0 toInteger (Sci s c e) = if e >= 0 then case c of CoeffInt x => Just $ withSign $ finToNat (FS x) * (b ^ integerToNat e) CoeffFloat x xs x' => let digits = reverse $ (FS x) :: xs ++ [FS x'] e' = e - natToInteger (length (xs ++ [FS x'])) in if e' >= 0 then Just $ withSign $ digitsToNat digits * (b ^ integerToNat e') else Nothing else Nothing where withSign : Nat -> Integer withSign = case s of Negative => negate . natToInteger Positive => natToInteger export negate : Scientific b -> Scientific b negate SciZ = SciZ negate (Sci s c e) = let s' = case s of Positive => Negative Negative => Positive in Sci s' c e export abs : Scientific b -> Scientific b abs SciZ = SciZ abs (Sci _ c e) = Sci Positive c e -- TODO: What happens, when Integer is negative? Low priority, since this is private. ||| The digits of an Integer, least significant first. private integerDigits : {b : _} -> Integer -> List (Fin (S (S b))) integerDigits 0 = [] integerDigits x = d :: integerDigits r where d : Fin (S (S b)) d = restrict (S b) x r : Integer r = x `div` natToInteger (S (S b)) ||| Remove the zeros near the head of a list. private removeLeadingZeros : List (Fin (S (S b))) -> Maybe (Fin (S b), List (Fin (S (S b)))) removeLeadingZeros [] = Nothing removeLeadingZeros (FZ :: xs) = removeLeadingZeros xs removeLeadingZeros (FS x :: xs) = Just (x, xs) private fromDigits : List (Fin (S (S b))) -> Scientific (S (S b)) fromDigits ys = case removeLeadingZeros $ reverse ys of Nothing => SciZ Just (x, ys') => case removeLeadingZeros $ reverse ys' of Nothing => Sci Positive (CoeffInt x) (cast $ length ys') Just (x', xs) => Sci Positive (CoeffFloat x (reverse xs) x') (cast $ length ys') export fromFin : Fin (S (S b)) -> Scientific (S (S b)) fromFin FZ = SciZ fromFin (FS x) = Sci Positive (CoeffInt x) 0 export fromInteger : {b : _} -> Integer -> Scientific (S (S b)) fromInteger x = if x < 0 then negate $ fromIntegerPositive x else fromIntegerPositive x where fromIntegerPositive : Integer -> Scientific (S (S b)) fromIntegerPositive = fromDigits . integerDigits . abs export fromNat : {b : _} -> Nat -> Scientific (S (S b)) fromNat = fromInteger . natToInteger ||| Single bit full adder in base (S (S b)). private plusBit : (op : Sign) -> {b : _} -> (carry : Bool) -> Fin (S (S b)) -> Fin (S (S b)) -> ((Fin (S (S b))), Bool) plusBit op False x FZ = (x, False) plusBit Positive True x FZ = case strengthen $ FS FZ of Nothing => (FZ, True) Just z => (z, False) plusBit Negative True x FZ = case x of FZ => (last, True) FS z => (weaken z, False) plusBit Positive carry x (FS y) = case strengthen $ FS x of Nothing => (fst $ plusBit Positive carry FZ (weaken y), True) Just z => plusBit Positive carry z (weaken y) plusBit Negative carry x (FS y) = case x of FZ => (fst $ plusBit Negative carry last (weaken y), True) FS z => plusBit Negative carry (weaken z) (weaken y) ||| N bit full adder in base (S (S b)). export plusBits : (op : Sign) -> {b : _} -> (carry : Bool) -> Vect n (Fin (S (S b))) -> Vect n (Fin (S (S b))) -> (Vect n (Fin (S (S b))), Bool) plusBits op carry [] [] = ([], carry) plusBits op carry (x :: xs) (y :: ys) = let (z, carry') = plusBit op carry x y (zs, sign) = plusBits op carry' xs ys in (z :: zs, sign) -- TODO: Add NonEmpty to result type. ||| All bits of a Coefficient, least significant first. export coefficientBits : Coefficient (S (S b)) -> List (Fin (S (S b))) coefficientBits (CoeffInt x) = [FS x] coefficientBits (CoeffFloat x xs x') = reverse $ FS x :: xs ++ [FS x'] -- TODO: get a definiton like this working: --equalizeLength : a -> -- (xs : List a) -> -- (ys : List a) -> -- (Vect (max (length xs) (length ys)) a, Vect (max (length xs) (length ys)) a) private equalizeLength : a -> (n : _) -> (xs : List a) -> (ys : List a) -> (Vect n a, Vect n a) equalizeLength a Z _ _ = ([],[]) equalizeLength a (S k) [] [] = let (ps, qs) = equalizeLength a k [] [] in (a :: ps, a :: qs) equalizeLength a (S k) [] (y::ys) = let (ps, qs) = equalizeLength a k [] ys in (a :: ps, y :: qs) equalizeLength a (S k) (x::xs) [] = let (ps, qs) = equalizeLength a k xs [] in (x :: ps, a :: qs) equalizeLength a (S k) (x::xs) (y::ys) = let (ps, qs) = equalizeLength a k xs ys in (x :: ps, y :: qs) ||| Wrapper for plusBits, adding padding regarding the exponent and trailing zeros. private plusBits' : (op : Sign) -> {b : _} -> (List (Fin (S (S b))), Integer) -> (List (Fin (S (S b))), Integer) -> (List (Fin (S (S b))), Bool) plusBits' op (xs,xe) (ys,ye) = let n = max (length xs) (length ys) (xs'', ys'') = equalizeLength FZ n xs' ys' (zs, overflow) = plusBits op False (reverse xs'') (reverse ys'') in (toList zs, overflow) where xs' : List (Fin (S (S b))) xs' = reverse $ xs ++ replicate (integerToNat ye `minus` integerToNat xe) FZ ys' : List (Fin (S (S b))) ys' = reverse $ ys ++ replicate (integerToNat xe `minus` integerToNat ye) FZ -- TODO: remove this or removeLeadingZeros private removeLeadingZeros' : List (Fin (S (S b))) -> (Nat, Maybe (Fin (S b), List (Fin (S (S b))))) removeLeadingZeros' [] = (Z, Nothing) removeLeadingZeros' (FZ :: xs) = let (n, res) = removeLeadingZeros' xs in (S n, res) removeLeadingZeros' (FS x :: xs) = (Z, Just (x, xs)) ||| Requires the digits to be ordered, least significant first. ||| Returns Coefficient and number of significant zeros. private fromDigits' : List (Fin (S (S b))) -> (Maybe (Coefficient (S (S b))), Nat) fromDigits' ys = let (n, removedLeading) = removeLeadingZeros' $ reverse ys in case removedLeading of Nothing => (Nothing, n) Just (x, ys') => case removeLeadingZeros $ reverse ys' of Nothing => (Just (CoeffInt x), n) Just (x', xs) => (Just (CoeffFloat x (reverse xs) x'), n) export (+) : {b : _} -> Scientific (S (S b)) -> Scientific (S (S b)) -> Scientific (S (S b)) SciZ + y = y x + SciZ = x x@(Sci s c e) + y@(Sci s' c' e') = let (zs, bit) = plusBits' op (xs, e) (ys, e') in case op of Positive => let s'' = s bits = if bit then [FS FZ] else [FZ] in case fromDigits' $ zs ++ bits of (Nothing, _) => SciZ (Just c'', bitShift) => let e'' = max e e' + 1 - natToInteger bitShift in Sci s'' c'' e'' Negative => let s'' = if bit then s' else s in case fromDigits' zs of (Nothing, _) => SciZ (Just c'', bitShift) => let e'' = max e e' - natToInteger bitShift in Sci s'' c'' e'' where op : Sign op = if s == s' then Positive else Negative xs : List (Fin (S (S b))) xs = coefficientBits c ys : List (Fin (S (S b))) ys = coefficientBits c' (-) : {b : _} -> Scientific (S (S b)) -> Scientific (S (S b)) -> Scientific (S (S b)) x - y = x + negate y -- TODO ||| Multiply two Coefficients and return True in the Bool, when the product is greater than the base. private multCoefficents : {b : _} -> Coefficient (S (S b)) -> Coefficient (S (S b)) -> (Coefficient (S (S b)), Bool) multCoefficents (CoeffInt x) (CoeffInt y) = case integerToFin res (S b) of Nothing => (CoeffInt $ restrict b res, True) Just fin => (CoeffInt fin, False) where res : Integer res = (finToInteger x + 1) * (finToInteger y + 1) - 1 multCoefficents a@(CoeffInt x) b@(CoeffFloat y ys y') = multCoefficents b a -- TODO: finish multCoefficents multCoefficents (CoeffFloat x xs x') (CoeffInt y) = ?multCoefficents_rhs_2 multCoefficents (CoeffFloat x xs x') (CoeffFloat y ys y') = ?multCoefficents_rhs_3 export (*) : {b : _} -> Scientific (S (S b)) -> Scientific (S (S b)) -> Scientific (S (S b)) SciZ * y = SciZ x * SciZ = SciZ (Sci s c e) * (Sci s' c' e') = Sci s'' c'' e'' where coefficientPair : (Coefficient (S (S b)), Bool) coefficientPair = multCoefficents c c' s'' : Sign s'' = if s == s' then Positive else Negative c'' : Coefficient (S (S b)) c'' = fst coefficientPair e'' : Integer e'' = if snd coefficientPair then e + e' + 1 else e + e' -- -- TODO: implementations don't work because the base (S (S b)) isn't accessible in the method's context. -- -- TODO: consider other implementations: -- -- - Fractional might not terminate, because of infinite representation -- -- - Integral doesn't sound like it would fit, but mod and div make still make sense -- public export -- Num (Scientific b) where -- -- (+) = (+) -- -- (*) = (*) -- -- fromInteger = fromInteger -- public export -- Neg (Scientific b) where -- -- negate = negate -- -- (-) = (-) -- public export -- Abs (Scientific b) where -- -- abs = abs ||| Create string representing using scientific notation. export prettyShowScientific : Scientific 10 -> String prettyShowScientific SciZ = "0" prettyShowScientific (Sci s c e) = prettyShowSign s ++ prettyShowCoefficient c ++ prettyExponent where prettyExponent : String prettyExponent = case e of 0 => "" x => "e" ++ show x
(* Title: HOL/Auth/n_moesi_lemma_on_inv__1.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_moesi Protocol Case Study*} theory n_moesi_lemma_on_inv__1 imports n_moesi_base begin section{*All lemmas on causal relation between inv__1 and some rule r*} lemma n_rule_t1Vsinv__1: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_rule_t1 i)" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__1 p__Inv0 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_rule_t1 i" apply fastforce done from a2 obtain p__Inv0 p__Inv2 where a2:"p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__1 p__Inv0 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i=p__Inv0)\<or>(i~=p__Inv0\<and>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 ''a'') p__Inv0)) (Const M)) (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv0)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const M)) (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv0\<and>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_rule_t2Vsinv__1: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_rule_t2 N i)" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__1 p__Inv0 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_rule_t2 N i" apply fastforce done from a2 obtain p__Inv0 p__Inv2 where a2:"p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__1 p__Inv0 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i=p__Inv0)\<or>(i~=p__Inv0\<and>i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "((formEval (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E)) s))\<or>((formEval (andForm (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const M)) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const M))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E)))) s))" by auto moreover { assume c1: "((formEval (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E)) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const M)) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const M))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } moreover { assume b1: "(i=p__Inv0)" have "((formEval (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)) s))\<or>((formEval (andForm (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const M)) (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const M))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)))) s))" by auto moreover { assume c1: "((formEval (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const M)) (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const M))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } moreover { assume b1: "(i~=p__Inv0\<and>i~=p__Inv2)" have "((formEval (andForm (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)) (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E))) s))\<or>((formEval (andForm (andForm (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const M)) (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)))) (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E))) s))\<or>((formEval (andForm (andForm (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const M))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)))) (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E))) s))\<or>((formEval (andForm (andForm (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)) (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const M))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E)))) s))\<or>((formEval (andForm (andForm (andForm (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const M)) (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)))) (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const M))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E)))) s))\<or>((formEval (andForm (andForm (andForm (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const M))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)))) (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const M))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E)))) s))\<or>((formEval (andForm (andForm (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const M)))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E)))) s))\<or>((formEval (andForm (andForm (andForm (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const M)) (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const M)))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E)))) s))\<or>((formEval (andForm (andForm (andForm (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const M))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const M)))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)) (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const M)) (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)))) (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const M))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)))) (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)) (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const M))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (andForm (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const M)) (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)))) (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const M))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (andForm (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const M))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)))) (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const M))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const M)))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (andForm (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const M)) (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const M)))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (andForm (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const M))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv2)) (Const E)))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const M)))) (neg (eqn (IVar (Para (Ident ''a'') p__Inv0)) (Const E)))) s))" have "?P2 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_rul_t3Vsinv__1: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_rul_t3 N i)" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__1 p__Inv0 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_rul_t3 N i" apply fastforce done from a2 obtain p__Inv0 p__Inv2 where a2:"p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__1 p__Inv0 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i=p__Inv0)\<or>(i~=p__Inv0\<and>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__Inv0)" 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__Inv0\<and>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_rul_t4Vsinv__1: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_rul_t4 N i)" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__1 p__Inv0 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_rul_t4 N i" apply fastforce done from a2 obtain p__Inv0 p__Inv2 where a2:"p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__1 p__Inv0 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i=p__Inv0)\<or>(i~=p__Inv0\<and>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__Inv0)" 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__Inv0\<and>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_rul_t5Vsinv__1: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_rul_t5 N i)" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__1 p__Inv0 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_rul_t5 N i" apply fastforce done from a2 obtain p__Inv0 p__Inv2 where a2:"p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__1 p__Inv0 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i=p__Inv0)\<or>(i~=p__Inv0\<and>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__Inv0)" 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__Inv0\<and>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 end