{"size":389,"ext":"thy","lang":"Isabelle","max_stars_count":30.0,"content":"theory lscmnbignum_Lsc__bignum__mont_exp_window__subprogram_def_WP_parameter_def_53\nimports \"..\/LibSPARKcrypto\"\nbegin\n\nwhy3_open \"lscmnbignum_Lsc__bignum__mont_exp_window__subprogram_def_WP_parameter_def_53.xml\"\n\nwhy3_vc WP_parameter_def\n using `\\aux4__first\\\\<^sub>\\ \\ aux4_first` `a_first < a_last`\n by (simp add: mk_bounds_fst add_increasing2)\n\nwhy3_end\n\nend\n","avg_line_length":27.7857142857,"max_line_length":92,"alphanum_fraction":0.8380462725} {"size":22034,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/n_flash_lemma_inv__6_on_rules.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_flash Protocol Case Study*} \n\ntheory n_flash_lemma_inv__6_on_rules imports n_flash_lemma_on_inv__6\nbegin\nsection{*All lemmas on causal relation between inv__6*}\nlemma lemma_inv__6_on_rules:\n assumes b1: \"r \\ rules N\" and b2: \"(\\ p__Inv4. p__Inv4\\N\\f=inv__6 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n proof -\n have c1: \"(\\ src data. src\\N\\data\\N\\r=n_Store src data)\\\n (\\ data. data\\N\\r=n_Store_Home data)\\\n (\\ src. src\\N\\r=n_PI_Remote_Get src)\\\n (\\ src. src\\N\\r=n_PI_Remote_GetX src)\\\n (\\ dst. dst\\N\\r=n_PI_Remote_PutX dst)\\\n (\\ src. src\\N\\r=n_PI_Remote_Replace src)\\\n (\\ dst. dst\\N\\r=n_NI_Nak dst)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__0 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__1 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__2 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Get__part__0 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Get__part__1 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Put_Head N src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Put src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Put_Dirty src)\\\n (\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Nak src dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_Get_Nak_Home dst)\\\n (\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Put src dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_Get_Put_Home dst)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__0 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__1 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__2 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__0 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__1 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_1 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_2 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_3 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_4 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_5 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_6 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__0 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__1 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src)\\\n (\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8 N src pp)\\\n (\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__0 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__1 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_10_Home N src)\\\n (\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_10 N src pp)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_11 N src)\\\n (\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_Nak src dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_GetX_Nak_Home dst)\\\n (\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_PutX src dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_GetX_PutX_Home dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_Put dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_PutX dst)\\\n (\\ dst. dst\\N\\r=n_NI_Inv dst)\\\n (\\ src. src\\N\\r=n_NI_InvAck_exists_Home src)\\\n (\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_InvAck_exists src pp)\\\n (\\ src. src\\N\\r=n_NI_InvAck_1 N src)\\\n (\\ src. src\\N\\r=n_NI_InvAck_2 N src)\\\n (\\ src. src\\N\\r=n_NI_InvAck_3 N src)\\\n (\\ src. src\\N\\r=n_NI_Replace src)\\\n (r=n_PI_Local_Get_Get )\\\n (r=n_PI_Local_Get_Put )\\\n (r=n_PI_Local_GetX_GetX__part__0 )\\\n (r=n_PI_Local_GetX_GetX__part__1 )\\\n (r=n_PI_Local_GetX_PutX_HeadVld__part__0 N )\\\n (r=n_PI_Local_GetX_PutX_HeadVld__part__1 N )\\\n (r=n_PI_Local_GetX_PutX__part__0 )\\\n (r=n_PI_Local_GetX_PutX__part__1 )\\\n (r=n_PI_Local_PutX )\\\n (r=n_PI_Local_Replace )\\\n (r=n_NI_Nak_Home )\\\n (r=n_NI_Nak_Clear )\\\n (r=n_NI_Local_Put )\\\n (r=n_NI_Local_PutXAcksDone )\\\n (r=n_NI_Wb )\\\n (r=n_NI_FAck )\\\n (r=n_NI_ShWb N )\\\n (r=n_NI_Replace_Home )\"\n apply (cut_tac b1, auto) done\n moreover {\n assume d1: \"(\\ src data. src\\N\\data\\N\\r=n_Store src data)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_StoreVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ data. data\\N\\r=n_Store_Home data)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_Store_HomeVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_PI_Remote_Get src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Remote_GetVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_PI_Remote_GetX src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Remote_GetXVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_PI_Remote_PutX dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Remote_PutXVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_PI_Remote_Replace src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Remote_ReplaceVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Nak dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_NakVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__0 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Nak__part__0Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__1 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Nak__part__1Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__2 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Nak__part__2Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Get__part__0 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Get__part__0Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Get__part__1 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Get__part__1Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Put_Head N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Put_HeadVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Put src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_PutVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Put_Dirty src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Put_DirtyVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Nak src dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_Get_NakVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_Get_Nak_Home dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_Get_Nak_HomeVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Put src dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_Get_PutVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_Get_Put_Home dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_Get_Put_HomeVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__0 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_Nak__part__0Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__1 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_Nak__part__1Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__2 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_Nak__part__2Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__0 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_GetX__part__0Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__1 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_GetX__part__1Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_1Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_2 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_2Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_3 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_3Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_4 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_4Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_5 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_5Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_6 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_6Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__0 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_7__part__0Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_7__part__1Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_7_NODE_Get__part__0Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_7_NODE_Get__part__1Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_8_HomeVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_8_Home_NODE_GetVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8 N src pp)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_8Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_8_NODE_GetVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__0 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_9__part__0Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_9__part__1Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_10_Home N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_10_HomeVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_10 N src pp)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_10Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_11 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_11Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_Nak src dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_GetX_NakVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_GetX_Nak_Home dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_GetX_Nak_HomeVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_PutX src dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_GetX_PutXVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_GetX_PutX_Home dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_GetX_PutX_HomeVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_Put dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_PutVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_PutX dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_PutXVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Inv dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_InvAck_exists_Home src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_exists_HomeVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_InvAck_exists src pp)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_existsVsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_InvAck_1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_1Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_InvAck_2 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_2Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_InvAck_3 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_3Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Replace src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_ReplaceVsinv__6) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_Get_Get )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_Get_GetVsinv__6) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_Get_Put )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_Get_PutVsinv__6) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_GetX__part__0 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_GetX__part__0Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_GetX__part__1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_GetX__part__1Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_PutX_HeadVld__part__0 N )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_PutX_HeadVld__part__0Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_PutX_HeadVld__part__1 N )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_PutX_HeadVld__part__1Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_PutX__part__0 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_PutX__part__0Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_PutX__part__1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_PutX__part__1Vsinv__6) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_PutX )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_PutXVsinv__6) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_Replace )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_ReplaceVsinv__6) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Nak_Home )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Nak_HomeVsinv__6) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Nak_Clear )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Nak_ClearVsinv__6) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Local_Put )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_PutVsinv__6) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Local_PutXAcksDone )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_PutXAcksDoneVsinv__6) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Wb )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_WbVsinv__6) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_FAck )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_FAckVsinv__6) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_ShWb N )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_ShWbVsinv__6) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Replace_Home )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Replace_HomeVsinv__6) done\n }\n\n ultimately show \"invHoldForRule s f r (invariants N)\"\n by satx\nqed\n\nend\n","avg_line_length":40.879406308,"max_line_length":132,"alphanum_fraction":0.6616138695} {"size":1904,"ext":"thy","lang":"Isabelle","max_stars_count":1.0,"content":"theory T28\nimports Main\nbegin\nlemma \"(\n(\\ x::nat. \\ y::nat. meet(x, y) = meet(y, x)) &\n(\\ x::nat. \\ y::nat. join(x, y) = join(y, x)) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(x, meet(y, z)) = meet(meet(x, y), z)) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(x, join(y, z)) = join(join(x, y), z)) &\n(\\ x::nat. \\ y::nat. meet(x, join(x, y)) = x) &\n(\\ x::nat. \\ y::nat. join(x, meet(x, y)) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(x, join(y, z)) = join(mult(x, y), mult(x, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(join(x, y), z) = join(mult(x, z), mult(y, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(x, over(join(mult(x, y), z), y)) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(y, undr(x, join(mult(x, y), z))) = y) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(mult(over(x, y), y), x) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(mult(y, undr(y, x)), x) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(meet(x, y), z) = meet(mult(x, z), mult(y, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. over(join(x, y), z) = join(over(x, z), over(y, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. over(x, meet(y, z)) = join(over(x, y), over(x, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. undr(meet(x, y), z) = join(undr(x, z), undr(y, z))) &\n(\\ x::nat. \\ y::nat. invo(join(x, y)) = meet(invo(x), invo(y))) &\n(\\ x::nat. \\ y::nat. invo(meet(x, y)) = join(invo(x), invo(y))) &\n(\\ x::nat. invo(invo(x)) = x)\n) \\\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(x, meet(y, z)) = meet(mult(x, y), mult(x, z)))\n\"\nnitpick[card nat=7,timeout=86400]\noops\nend","avg_line_length":65.6551724138,"max_line_length":108,"alphanum_fraction":0.5330882353} {"size":1905,"ext":"thy","lang":"Isabelle","max_stars_count":1.0,"content":"theory T151\nimports Main\nbegin\nlemma \"(\n(\\ x::nat. \\ y::nat. meet(x, y) = meet(y, x)) &\n(\\ x::nat. \\ y::nat. join(x, y) = join(y, x)) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(x, meet(y, z)) = meet(meet(x, y), z)) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(x, join(y, z)) = join(join(x, y), z)) &\n(\\ x::nat. \\ y::nat. meet(x, join(x, y)) = x) &\n(\\ x::nat. \\ y::nat. join(x, meet(x, y)) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(x, join(y, z)) = join(mult(x, y), mult(x, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(join(x, y), z) = join(mult(x, z), mult(y, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(x, over(join(mult(x, y), z), y)) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(y, undr(x, join(mult(x, y), z))) = y) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(mult(over(x, y), y), x) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(mult(y, undr(y, x)), x) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(x, meet(y, z)) = meet(mult(x, y), mult(x, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(meet(x, y), z) = meet(mult(x, z), mult(y, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. over(join(x, y), z) = join(over(x, z), over(y, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. undr(meet(x, y), z) = join(undr(x, z), undr(y, z))) &\n(\\ x::nat. \\ y::nat. invo(join(x, y)) = meet(invo(x), invo(y))) &\n(\\ x::nat. \\ y::nat. invo(meet(x, y)) = join(invo(x), invo(y))) &\n(\\ x::nat. invo(invo(x)) = x)\n) \\\n(\\ x::nat. \\ y::nat. \\ z::nat. over(x, meet(y, z)) = join(over(x, y), over(x, z)))\n\"\nnitpick[card nat=7,timeout=86400]\noops\nend","avg_line_length":65.6896551724,"max_line_length":108,"alphanum_fraction":0.5333333333} {"size":81488,"ext":"thy","lang":"Isabelle","max_stars_count":10.0,"content":"theory Expressions\n imports Prog_Variables Misc_Missing Extended_Sorry Multi_Transfer\nbegin\n\n(* TODO: are expressions actually necessary?\n\n Why can't we just use terms of the form (\\m. ... (eval_variable x m))?\n\n (We won't have the guarantee that the set of variables used by an expression\n is finite, or even well-defined, but do we ever use those facts?)\n*)\n\ntypedef 'a expression = \"{(vs,f::_\\'a). finite vs \\ (\\m1 m2. (\\v\\vs. Rep_mem2 m1 v = Rep_mem2 m2 v) \\ f m1 = f m2)}\"\n apply (rule exI[of _ \"({},(\\x. undefined))\"]) by auto\nsetup_lifting type_definition_expression\n\nlift_definition rel_expression :: \"(variable_raw \\ variable_raw \\ bool) \\ ('a \\ 'b \\ bool) \\ 'a expression \\ 'b expression \\ bool\"\n is \"\\(rel_v::variable_raw \\ variable_raw \\ bool) (rel_result::'a \\ 'b \\ bool). \n (rel_prod (rel_set rel_v) (rel_fun (rel_mem2 rel_v) rel_result)\n :: variable_raw set * (mem2 => 'a) => variable_raw set * (_ => 'b) => bool)\".\n\nlemma rel_expression_eq: \"rel_expression (=) (=) = (=)\"\n unfolding rel_expression.rep_eq rel_set_eq rel_mem2_eq rel_fun_eq prod.rel_eq Rep_expression_inject by rule\n\nlemma left_unique_rel_expression[transfer_rule]:\n assumes \"left_unique R\" and \"left_unique S\" and \"right_total R\" and \"type_preserving_var_rel R\"\n shows \"left_unique (rel_expression R S)\"\nproof -\n have \"e = f\" if \"rel_expression R S e g\" and \"rel_expression R S f g\" for e f g\n proof -\n obtain vse E where e: \"Rep_expression e = (vse,E)\" by (atomize_elim, auto)\n obtain vsf F where f: \"Rep_expression f = (vsf,F)\" by (atomize_elim, auto)\n obtain vsg G where g: \"Rep_expression g = (vsg,G)\" by (atomize_elim, auto)\n from that have \"rel_prod (rel_set R) (rel_fun (rel_mem2 R) S) (vse,E) (vsg,G)\"\n unfolding rel_expression.rep_eq e g by simp\n then have vseg: \"rel_set R vse vsg\" and EG: \"(rel_fun (rel_mem2 R) S) E G\" by auto\n\n from that have \"rel_prod (rel_set R) (rel_fun (rel_mem2 R) S) (vsf,F) (vsg,G)\"\n unfolding rel_expression.rep_eq f g by simp\n then have vsfg: \"rel_set R vsf vsg\" and FG: \"(rel_fun (rel_mem2 R) S) F G\" by auto\n\n from vseg vsfg have \"vse = vsf\"\n using \\left_unique R\\\n by (meson left_uniqueD left_unique_rel_set) \n\n have left_unique_fun: \"left_unique (rel_fun (rel_mem2 R) S)\"\n apply (rule left_unique_fun)\n apply (rule left_total_rel_mem2)\n using assms by auto\n from EG FG have \"E = F\"\n using left_unique_fun\n by (meson left_uniqueD)\n\n from \\vse = vsf\\ \\E = F\\\n show \"e = f\"\n using Rep_expression_inject e f by fastforce\n qed\n then show ?thesis\n unfolding left_unique_def by simp\nqed\n\nlemma rel_expression_flip[simp]: \"(rel_expression R S)^--1 = rel_expression R^--1 S^--1\"\n apply (rule ext)+ unfolding conversep_iff apply transfer\n using rel_mem2_flip[unfolded conversep_iff]\n apply (auto simp: rel_fun_def rel_set_def)\n by (metis (full_types))+\n\nlemma right_unique_rel_expression[transfer_rule]:\n assumes \"right_unique R\" and \"right_unique S\" and \"left_total R\" and \"type_preserving_var_rel R\"\n shows \"right_unique (rel_expression R S)\"\n apply (subst conversep_conversep[of R, symmetric])\n apply (subst conversep_conversep[of S, symmetric])\n apply (subst rel_expression_flip[symmetric])\n apply (simp del: rel_expression_flip)\n apply (rule left_unique_rel_expression)\n using assms by auto\n\nlemma bi_unique_rel_expression[transfer_rule]:\n assumes \"bi_unique R\" and \"bi_unique S\" and \"bi_total R\" and \"type_preserving_var_rel R\"\n shows \"bi_unique (rel_expression R S)\"\n using assms by (meson bi_total_alt_def bi_unique_alt_def left_unique_rel_expression right_unique_rel_expression)\n\n\nlift_definition expression :: \"'a::universe variables \\ ('a\\'b) \\ 'b expression\" is\n \"\\(vs::'a variables) (f::'a\\'b). (set (raw_variables vs), (f o eval_variables vs) :: mem2\\'b)\"\n using eval_variables_footprint by fastforce\n\n(* lifting_forget mem2.lifting *)\nlift_definition expression_eval :: \"'b expression \\ mem2 \\ 'b\" is \"\\(vs::variable_raw set,f::mem2\\'b) m. f m\" .\n(* setup_lifting type_definition_mem2 *)\n\nlemma expression_eval: \"expression_eval (expression X e) m = e (eval_variables X m)\"\n unfolding expression_eval.rep_eq expression.rep_eq by auto\n\nlift_definition expression_vars :: \"'a expression \\ variable_raw set\" is \"\\(vs::variable_raw set,f). vs\" .\nlemma expression_vars[simp]: \"expression_vars (expression X e) = set (raw_variables X)\"\n by (simp add: expression.rep_eq expression_vars.rep_eq)\n\nlemma Rep_expression_components: \"Rep_expression e = (expression_vars e, expression_eval e)\"\n apply transfer by auto\n\nlemma expression_eqI: \"expression_vars e = expression_vars e' \\ expression_eval e = expression_eval e' \\ e = e'\"\n apply transfer by auto\n\ntext \\\nSome notation, used mainly in the documentation of the ML code:\n\\<^item> A term of type \\<^typ>\\'a variables\\ is an \\<^emph>\\explicit variable list\\ if it is of the form\n \\<^term>\\\\x\\<^sub>1,x\\<^sub>2,dots,x\\<^sub>n\\\\ where the \\<^term>\\x\\<^sub>i\\ are free variables.\n\n\\<^item> A term of type \\<^typ>\\'a variables\\ is an \\<^emph>\\explicit variable term\\ if it is built from\n \\<^const>\\variable_concat\\, \\<^const>\\variable_unit\\, \\<^const>\\variable_singleton\\ and free variables.\n\n\\<^item> An expression is \\<^emph>\\well-formed explicit\\ iff it is of the form \\<^term>\\expression \\x\\<^sub>1,x\\<^sub>2,dots,x\\<^sub>n\\ (\\(z\\<^sub>1,z\\<^sub>2,dots,z\\<^sub>n). e (z\\<^sub>1,z\\<^sub>2,dots,z\\<^sub>n))\\\n where the \\<^term>\\x\\<^sub>i\\ are free variables.\n\n\\<^item> An expression is \\<^emph>\\varlist explicit\\ iff it is of the form \\<^term>\\expression \\x\\<^sub>1,x\\<^sub>2,dots,x\\<^sub>n\\ e\\\n where the \\<^term>\\x\\<^sub>i\\ are free variables.\n\n\\<^item> An expression is \\<^emph>\\explicit\\ iff it is of the form \\<^term>\\expression Q e\\ where \\<^term>\\Q\\ is an explicit variable term.\n\\\n\nlift_definition fv_expression :: \"'a expression \\ string set\" is \"\\(vs,f). variable_raw_name ` vs\" .\nlemma fv_expression: \"fv_expression (expression v e) = set (variable_names v)\"\n apply transfer unfolding variable_names_def by auto\n\nsection \\Constructing expressions\\\n\nabbreviation \"const_expression z \\ expression \\\\ (\\_. z)\"\n\nlift_definition map_expression' :: \"(('z \\ 'e) \\ 'f) \\ ('z \\ 'e expression) \\ 'f expression\" is\n \"\\F ez. if (\\z. fst (ez z) = fst (ez undefined)) \n then (fst (ez undefined), (\\m. F (\\z. snd (ez z) m)))\n else Rep_expression (const_expression undefined)\" \n apply (rename_tac F ez)\nproof -\n fix F :: \"('z \\ 'e) \\ 'f\" and ez :: \"'z \\ variable_raw set \\ (mem2 \\ 'e)\"\n assume assm: \"(\\x. ez x \\ {(vs, f). finite vs \\ (\\m1 m2. (\\v\\vs. Rep_mem2 m1 v = Rep_mem2 m2 v) \\ f m1 = f m2)})\"\n show \"(if \\z. fst (ez z) = fst (ez undefined) then (fst (ez undefined), \\m. F (\\z. snd (ez z) m)) else Rep_expression (const_expression undefined))\n \\ {(vs, f). finite vs \\ (\\m1 m2. (\\v\\vs. Rep_mem2 m1 v = Rep_mem2 m2 v) \\ f m1 = f m2)}\"\n proof (cases \"\\z. fst (ez z) = fst (ez undefined)\")\n case True\n then show ?thesis using assm apply (auto simp: split_beta) by metis\n next\n case False\n then show ?thesis using Rep_expression by metis\n qed\nqed\n\nlemma map_expression'[simp]: \"map_expression' f (\\z. expression Q (e z)) = expression Q (\\a. f (\\z. e z a))\"\n apply transfer by auto\n\n\n\nlift_definition pair_expression :: \"'a expression \\ 'b expression \\ ('a \\ 'b) expression\" is\n \"\\(vs1,e1) (vs2,e2). (vs1 \\ vs2, \\m. (e1 m, e2 m))\"\n by auto\n\n\nlemma pair_expression[simp]: \"pair_expression (expression Q1 e1) (expression Q2 e2)\n = expression (variable_concat Q1 Q2) (\\(z1,z2). (e1 z1, e2 z2))\"\n apply (subst Rep_expression_inject[symmetric])\n unfolding pair_expression.rep_eq expression.rep_eq\n by auto \n\ndefinition map_expression :: \"('e \\ 'f) \\ ('e expression) \\ 'f expression\" where\n \"map_expression f e = map_expression' (\\e. f (e ())) (\\_. e)\"\n\nlemma map_expression[simp]:\n \"map_expression f (expression Q e) = expression Q (\\x. f (e x))\" \n unfolding map_expression_def map_expression'\n apply (tactic \\cong_tac \\<^context> 1\\) by auto\n\ndefinition map_expression2' :: \"('e1 \\ ('z \\ 'e2) \\ 'f) \\ ('e1 expression) \\ ('z \\ 'e2 expression) \\ 'f expression\" where\n \"map_expression2' f e1 e2 = map_expression' (\\x12. let x1 = fst (x12 undefined) in\n let x2 = \\z. snd (x12 z) in\n f x1 x2) (\\z. pair_expression e1 (e2 z))\"\n\nlemma map_expression2'[simp]:\n \"map_expression2' f (expression Q1 e1) (\\z. expression Q2 (e2 z))\n = expression (variable_concat Q1 Q2) (\\(x1,x2). f (e1 x1) (\\z. e2 z x2))\"\n unfolding map_expression2'_def pair_expression map_expression'\n apply (tactic \\cong_tac \\<^context> 1\\) by auto\n\ndefinition map_expression2 :: \"('e1 \\ 'e2 \\ 'f) \\ 'e1 expression \\ 'e2 expression \\ 'f expression\" where\n \"map_expression2 f e1 e2 = map_expression (\\(x1,x2). f x1 x2) (pair_expression e1 e2)\"\n\nlemma map_expression2[simp]:\n \"map_expression2 f (expression Q1 e1) (expression Q2 e2)\n = expression (variable_concat Q1 Q2) (\\(x1,x2). f (e1 x1) (e2 x2))\"\n unfolding map_expression2_def pair_expression apply simp\n apply (tactic \\cong_tac \\<^context> 1\\) by auto\n\ndefinition map_expression3 :: \"('e1 \\ 'e2 \\ 'e3 \\ 'f) \\ 'e1 expression \\ 'e2 expression \\ 'e3 expression \\ 'f expression\" where\n \"map_expression3 f e1 e2 e3 = map_expression (\\(x1,x2,x3). f x1 x2 x3)\n (pair_expression e1 (pair_expression e2 e3))\"\n\nlemma map_expression3[simp]:\n \"map_expression3 f (expression Q1 e1) (expression Q2 e2) (expression Q3 e3)\n = expression (variable_concat Q1 (variable_concat Q2 Q3)) (\\(x1,x2,x3). f (e1 x1) (e2 x2) (e3 x3))\"\n unfolding map_expression3_def pair_expression apply simp\n apply (tactic \\cong_tac \\<^context> 1\\) by auto\n\ndefinition map_expression3' ::\n \"('e1 \\ 'e2 \\ ('z \\ 'e3) \\ 'f) \\ ('e1 expression) \\ ('e2 expression) \\ ('z \\ 'e3 expression) \\ 'f expression\" where\n \"map_expression3' f e1 e2 e3 = map_expression'\n (\\x123. let x1 = fst (x123 undefined) in\n let x2 = fst (snd (x123 undefined)) in\n let x3 = \\z. snd (snd (x123 z)) in\n f x1 x2 x3)\n (\\z. (pair_expression e1 (pair_expression e2 (e3 z))))\"\n\nlemma map_expression3'[simp]:\n \"map_expression3' f (expression Q1 e1) (expression Q2 e2) (\\z. expression Q3 (e3 z))\n = expression (variable_concat Q1 (variable_concat Q2 Q3)) (\\(x1,x2,x3). f (e1 x1) (e2 x2) (\\z. e3 z x3))\"\n unfolding map_expression3'_def pair_expression map_expression'\n apply (tactic \\cong_tac \\<^context> 1\\) by auto\n\ndefinition map_expression4' ::\n \"('e1 \\ 'e2 \\ 'e3 \\ ('z \\ 'e4) \\ 'f) \\ ('e1 expression) \\ ('e2 expression) \\ ('e3 expression) \\ ('z \\ 'e4 expression) \\ 'f expression\" where\n \"map_expression4' f e1 e2 e3 e4 = map_expression'\n (\\x1234. let x1 = fst (x1234 undefined) in\n let x2 = fst (snd (x1234 undefined)) in\n let x3 = fst (snd (snd (x1234 undefined))) in\n let x4 = \\z. snd (snd (snd (x1234 z))) in\n f x1 x2 x3 x4)\n (\\z. (pair_expression e1 (pair_expression e2 (pair_expression e3 (e4 z)))))\"\n\nlemma map_expression4'[simp]:\n \"map_expression4' f (expression Q1 e1) (expression Q2 e2) (expression Q3 e3) (\\z. expression Q4 (e4 z))\n = expression (variable_concat Q1 (variable_concat Q2 (variable_concat Q3 Q4))) (\\(x1,x2,x3,x4). f (e1 x1) (e2 x2) (e3 x3) (\\z. e4 z x4))\"\n unfolding map_expression4'_def pair_expression map_expression'\n apply (tactic \\cong_tac \\<^context> 1\\) by auto\n\nlemma expression_eval_map_expression':\n assumes \"\\z. expression_vars (e z) = expression_vars (e undefined)\"\n shows \"expression_eval (map_expression' f e) x = f (\\z. expression_eval (e z) x)\"\n using assms\n apply (transfer fixing: f x)\n by (simp add: case_prod_beta)\n\nlemma expression_eval_map_expression[simp]:\n shows \"expression_eval (map_expression f e) x = f (expression_eval e x)\"\n unfolding map_expression_def\n by (rule expression_eval_map_expression', simp)\n\nlemma expression_eval_pair_expression[simp]:\n shows \"expression_eval (pair_expression e g) x = (expression_eval e x, expression_eval g x)\"\n apply (transfer fixing: x)\n by (simp add: case_prod_beta)\n\n\nlemma expression_eval_map_expression2[simp]:\n shows \"expression_eval (map_expression2 f e g) x = f (expression_eval e x) (expression_eval g x)\"\n unfolding map_expression2_def\n apply (subst expression_eval_map_expression)\n apply (subst expression_eval_pair_expression)\n by simp\n\nlemma range_cases[case_names 1]: \"x : range f \\ (\\y. P (f y)) \\ P x\"\n unfolding image_def by auto \n\nlift_definition index_expression :: \"bool \\ 'a expression \\ 'a expression\" is\n \"\\left (vs,e). (index_var_raw left ` vs, \\m. e (unindex_mem2 left m))\"\n by auto\n\nlemma index_expression[simp]: \"index_expression left (expression Q e) = expression (index_vars left Q) e\"\n for Q :: \"'b::universe variables\" and e :: \"'b \\ 'a\"\n using [[transfer_del_const index_vars]]\n apply transfer by auto\n\nlift_definition index_flip_expression :: \"'a expression \\ 'a expression\" is\n \"\\(vs,e). (index_flip_var_raw ` vs, \\m. e (index_flip_mem2 m))\"\n by auto\n\nlemma index_flip_expression[simp]: \"index_flip_expression (expression Q e) = expression (index_flip_vars Q) e\"\n for Q :: \"'b::universe variables\" and e :: \"'b \\ 'a\"\n using [[transfer_del_const index_flip_vars]]\n apply transfer by auto\n\nlemma index_flip_expression_vars[simp]: \"expression_vars (index_flip_expression e) = index_flip_var_raw ` expression_vars e\"\n by (simp add: expression_vars.rep_eq index_flip_expression.rep_eq split_beta)\n\nlemma index_flip_expression_twice[simp]: \"index_flip_expression (index_flip_expression e) = e\"\n apply transfer by (auto simp: image_iff)\n\n\nlemma index_flip_expression_index_expression:\n \"index_flip_expression (index_expression left x) = index_expression (\\left) x\"\n apply transfer apply auto\n using image_iff by fastforce\n\n(* lemma expression_vars_index_flip_expression: \"expression_vars (index_flip_expression e) = index_flip_var_raw ` expression_vars e\"\n by (simp add: expression_vars.rep_eq index_flip_expression.rep_eq split_beta) *)\n\nlemma expression_eval_index_flip_expression: \"expression_eval (index_flip_expression e) = \n expression_eval e o index_flip_mem2\"\n unfolding o_def\n by (simp add: expression_eval.rep_eq index_flip_expression.rep_eq split_beta)\n\nlemma index_flip_expression_pair_expression: \"index_flip_expression (pair_expression e1 e2)\n = pair_expression (index_flip_expression e1) (index_flip_expression e2)\"\n apply transfer by auto\n\nlemma index_flip_expression_map_expression': \"index_flip_expression (map_expression' f ez)\n = map_expression' f (index_flip_expression o ez)\"\nproof (cases \"\\z. expression_vars (ez z) = expression_vars (ez undefined)\")\n case True\n then have True': \"expression_vars (index_flip_expression (ez z)) = expression_vars (index_flip_expression (ez undefined))\" for z\n apply transfer\n apply simp\n by (metis (mono_tags, lifting) fst_conv split_beta)\n\n from True have \"expression_vars (map_expression' f ez) = expression_vars (ez undefined)\"\n apply transfer by (simp add: fst_def)\n hence \"expression_vars (index_flip_expression (map_expression' f ez)) \n = index_flip_var_raw ` expression_vars (ez undefined)\"\n unfolding index_flip_expression_vars by simp\n moreover from True' have \"expression_vars (map_expression' f (index_flip_expression o ez)) \n = expression_vars (index_flip_expression (ez undefined))\"\n unfolding o_def apply transfer by (auto simp: fst_def)\n moreover have \"expression_vars (index_flip_expression (ez undefined))\n = index_flip_var_raw ` expression_vars (ez undefined)\"\n unfolding index_flip_expression_vars by simp\n ultimately have vars: \"expression_vars (index_flip_expression (map_expression' f ez))\n = expression_vars (map_expression' f (index_flip_expression o ez))\"\n by simp\n\n from True have \"expression_eval (map_expression' f ez) = (\\m. f (\\z. expression_eval (ez z) m))\"\n apply transfer by (auto simp: fst_def snd_def)\n hence \"expression_eval (index_flip_expression (map_expression' f ez)) \n = (\\m. f (\\z. expression_eval (ez z) (index_flip_mem2 m)))\"\n unfolding expression_eval_index_flip_expression by (simp add: o_def)\n moreover from True' have \"expression_eval (map_expression' f (index_flip_expression o ez)) \n = (\\m. f (\\z. expression_eval (index_flip_expression (ez z)) m))\"\n unfolding o_def apply transfer by (auto simp: fst_def snd_def)\n moreover have \"expression_eval (ez z) (index_flip_mem2 m) = expression_eval (index_flip_expression (ez z)) m\" for m z\n apply transfer by (simp add: split_beta)\n ultimately have eval: \"expression_eval (index_flip_expression (map_expression' f ez))\n = expression_eval (map_expression' f (index_flip_expression o ez))\"\n by simp\n \n from vars eval show ?thesis\n by (rule expression_eqI)\nnext\n case False\n then have False': \"\\ (\\z. expression_vars (index_flip_expression (ez z)) = expression_vars (index_flip_expression (ez undefined)))\"\n apply transfer\n apply (simp add: case_prod_beta)\n using index_flip_var_raw_inject by blast\n\n have \"map_expression' f ez = const_expression undefined\"\n apply (subst Rep_expression_inject[symmetric])\n using False by (auto simp: map_expression'.rep_eq expression_vars.rep_eq case_prod_beta)\n then have \"index_flip_expression (map_expression' f ez) = const_expression undefined\"\n by simp\n also from False' have \"map_expression' f (index_flip_expression o ez) = const_expression undefined\"\n apply (subst Rep_expression_inject[symmetric])\n using False by (auto simp: map_expression'.rep_eq expression_vars.rep_eq case_prod_beta)\n finally show ?thesis by metis\nqed\n\nlemma index_flip_expression_map_expression: \"index_flip_expression (map_expression f e)\n = map_expression f (index_flip_expression e)\"\n unfolding map_expression_def\n apply (subst index_flip_expression_map_expression') \n by (simp add: o_def)\n\nlemma index_flip_map_expression2': \"index_flip_expression (map_expression2' f e1 e2) = \n map_expression2' f (index_flip_expression e1) (index_flip_expression o e2)\"\n unfolding map_expression2'_def by (simp add: index_flip_expression_pair_expression index_flip_expression_map_expression' o_def)\n\nsection \\Substitutions\\\n\n(* TODO move *)\nlemma variable_raw_domain_Rep_variable[simp]: \"variable_raw_domain (Rep_variable (v::'a::universe variable)) = range (embedding::'a\\_)\"\n apply transfer by simp\n\ntypedef substitution1 = \"{(v::variable_raw, vs, e::mem2\\universe). \n finite vs \\\n (\\m. e m \\ variable_raw_domain v) \\\n (\\m1 m2. (\\w\\vs. Rep_mem2 m1 w = Rep_mem2 m2 w) \\ e m1 = e m2)}\"\n by (rule exI[of _ \"(Rep_variable (undefined::unit variable), {}, \\_. embedding ())\"], auto)\nsetup_lifting type_definition_substitution1\n\nlift_definition substitute1 :: \"'a::universe variable \\ 'a expression \\ substitution1\" is\n \"\\(v::variable_raw) (vs,e). (v, vs, \\m. embedding (e m))\" \n by auto \n\nlift_definition substitution1_footprint :: \"substitution1 \\ variable_raw set\" is \"\\(_,vs::variable_raw set,_). vs\" .\nlift_definition substitution1_variable :: \"substitution1 \\ variable_raw\" is \"\\(v::variable_raw,_,_). v\" .\nlift_definition substitution1_function :: \"substitution1 \\ mem2 \\ universe\" is \"\\(_,_,f::mem2\\universe). f\" .\n\nlemma Rep_substitution1_components: \"Rep_substitution1 s = (substitution1_variable s, substitution1_footprint s, substitution1_function s)\"\n apply transfer by auto\n\nlemma substitution1_function_domain: \"substitution1_function s m \\ variable_raw_domain (substitution1_variable s)\"\n apply transfer by auto\n\nlemma substitute1_variable[simp]: \"substitution1_variable (substitute1 x e) = Rep_variable x\"\n apply transfer by auto\nlemma substitute1_function: \"substitution1_function (substitute1 x e) m = embedding (expression_eval e m)\"\n apply transfer by auto\n\n\n\nlift_definition index_flip_substitute1 :: \"substitution1 \\ substitution1\" \n is \"\\(v,vs,f). (index_flip_var_raw v, index_flip_var_raw ` vs, f o index_flip_mem2)\"\n by auto\n\nlemma index_flip_substitute1: \"index_flip_substitute1 (substitute1 x e) = \n substitute1 (index_flip_var x) (index_flip_expression e)\"\n apply transfer by auto\n\nlemma substitution1_variable_index_flip: \"substitution1_variable (index_flip_substitute1 s) = \n index_flip_var_raw (substitution1_variable s)\"\n apply transfer by auto\n\nlemma substitution1_function_index_flip: \"substitution1_function (index_flip_substitute1 s) = \n substitution1_function s \\ index_flip_mem2\"\n apply (cases \"Rep_substitution1 s\")\n by (simp add: substitution1_function.rep_eq index_flip_substitute1.rep_eq)\n\nlemma index_flip_var_raw_substitution1_footprint: \"index_flip_var_raw ` substitution1_footprint s =\n substitution1_footprint (index_flip_substitute1 s)\"\n apply (cases \"Rep_substitution1 s\")\n by (simp add: substitution1_footprint.rep_eq index_flip_substitute1.rep_eq)\n\nlemma index_flip_substitute1_twice[simp]: \"index_flip_substitute1 (index_flip_substitute1 s) = s\"\n apply transfer by (auto simp: image_iff)\n\n\ndefinition rel_substitute1x :: \"(variable_raw\\variable_raw\\bool) \\ (variable_raw\\variable_raw\\bool) \\ (substitution1\\substitution1\\bool)\"\n where \"rel_substitute1x R S s1 s2 \\ R (substitution1_variable s1) (substitution1_variable s2) \\\n (rel_set R (substitution1_footprint s1) (substitution1_footprint s2)) \\\n (rel_fun (rel_mem2 S) (=)) (substitution1_function s1) (substitution1_function s2)\"\n\n\n(* Remove? *)\nlift_definition rel_substitute1 :: \n \"(variable_raw\\variable_raw\\bool) \\ ('a::universe expression\\'b::universe expression\\bool) \n \\ (substitution1\\substitution1\\bool)\" is\n \"\\(rel_v::variable_raw\\variable_raw\\bool) \n (rel_exp :: (variable_raw set * (mem2 \\ 'a)) \\ (variable_raw set * (mem2 \\ 'b)) \\ bool). \n rel_prod rel_v (%(vs1,f1) (vs2,f2). range f1 \\ range (embedding::'a\\_) \\ range f2 \\ range (embedding::'b\\_) \\\n rel_exp (vs1, inv embedding o f1 :: mem2 \\ 'a) \n (vs2, inv embedding o f2 :: mem2 \\ 'b))\"\nproof (rename_tac rel_v rel_exp1 rel_exp2 prod1 prod2)\n fix rel_v and rel_exp1 rel_exp2 :: \"variable_raw set \\ (mem2 \\ 'a)\n \\ variable_raw set \\ (mem2 \\ 'b) \\ bool\" and prod1 prod2 :: \"variable_raw \\ variable_raw set \\ (mem2 \\ universe)\"\n obtain v1 vs1 f1 where prod1: \"prod1 = (v1,vs1,f1)\" apply atomize_elim by (meson prod_cases3)\n obtain v2 vs2 f2 where prod2: \"prod2 = (v2,vs2,f2)\" apply atomize_elim by (meson prod_cases3)\n assume eq: \"vsf1 \\ {(vs, f). finite vs \\ (\\m1 m2. (\\v\\vs. Rep_mem2 m1 v = Rep_mem2 m2 v) \\ f m1 = f m2)} \\\n vsf2 \\ {(vs, f). finite vs \\ (\\m1 m2. (\\v\\vs. Rep_mem2 m1 v = Rep_mem2 m2 v) \\ f m1 = f m2)} \\\n rel_exp1 vsf1 vsf2 = rel_exp2 vsf1 vsf2\" for vsf1 vsf2\n assume p1: \"prod1 \\ {(v, vs, e).\n finite vs \\ (\\m. e m \\ variable_raw_domain v) \\ (\\m1 m2. (\\w\\vs. Rep_mem2 m1 w = Rep_mem2 m2 w) \\ e m1 = e m2)} \"\n assume p2: \"prod2 \\ {(v, vs, e).\n finite vs \\ (\\m. e m \\ variable_raw_domain v) \\ (\\m1 m2. (\\w\\vs. Rep_mem2 m1 w = Rep_mem2 m2 w) \\ e m1 = e m2)}\"\n have \"rel_exp1 (vs1, inv embedding \\ f1) (vs2, inv embedding \\ f2) \\\n rel_exp2 (vs1, inv embedding \\ f1) (vs2, inv embedding \\ f2)\"\n apply (rule eq)\n using p1 p2 unfolding prod1 prod2 apply auto by presburger+\n then\n show \"rel_prod rel_v (\\(vs1, f1) (vs2, f2). range f1 \\ range (embedding::'a\\_) \\ range f2 \\ range (embedding::'b\\_) \\ rel_exp1 (vs1, inv embedding \\ f1) (vs2, inv embedding \\ f2)) prod1 prod2 =\n rel_prod rel_v (\\(vs1, f1) (vs2, f2). range f1 \\ range (embedding::'a\\_) \\ range f2 \\ range (embedding::'b\\_) \\ rel_exp2 (vs1, inv embedding \\ f1) (vs2, inv embedding \\ f2)) prod1 prod2\"\n by (simp add: case_prod_beta prod1 prod2)\nqed\n\n(* TODO remove *)\nlift_definition rel_substitute1' :: \"(variable_raw\\variable_raw\\bool) \\ ('a::universe expression\\'b::universe expression\\bool) \\ (substitution1\\substitution1\\bool)\" is\n \"\\(rel_v::variable_raw\\variable_raw\\bool) \n (rel_exp :: (variable_raw set * (mem2 \\ 'a)) \\ (variable_raw set * (mem2 \\ 'b)) \\ bool). \n rel_prod rel_v (%(vs1,f1) (vs2,f2). rel_exp (vs1, inv embedding o f1 :: mem2 \\ 'a) \n (vs2, inv embedding o f2 :: mem2 \\ 'b))\"\nproof (rename_tac rel_v rel_exp1 rel_exp2 prod1 prod2)\n fix rel_v and rel_exp1 rel_exp2 :: \"variable_raw set \\ (mem2 \\ 'a)\n \\ variable_raw set \\ (mem2 \\ 'b) \\ bool\" and prod1 prod2 :: \"variable_raw \\ variable_raw set \\ (mem2 \\ universe)\"\n obtain v1 vs1 f1 where prod1: \"prod1 = (v1,vs1,f1)\" apply atomize_elim by (meson prod_cases3)\n obtain v2 vs2 f2 where prod2: \"prod2 = (v2,vs2,f2)\" apply atomize_elim by (meson prod_cases3)\n assume eq: \"vsf1 \\ {(vs, f). finite vs \\ (\\m1 m2. (\\v\\vs. Rep_mem2 m1 v = Rep_mem2 m2 v) \\ f m1 = f m2)} \\\n vsf2 \\ {(vs, f). finite vs \\ (\\m1 m2. (\\v\\vs. Rep_mem2 m1 v = Rep_mem2 m2 v) \\ f m1 = f m2)} \\\n rel_exp1 vsf1 vsf2 = rel_exp2 vsf1 vsf2\" for vsf1 vsf2\n assume p1: \"prod1 \\ {(v, vs, e).\n finite vs \\ (\\m. e m \\ variable_raw_domain v) \\ (\\m1 m2. (\\w\\vs. Rep_mem2 m1 w = Rep_mem2 m2 w) \\ e m1 = e m2)} \"\n assume p2: \"prod2 \\ {(v, vs, e).\n finite vs \\ (\\m. e m \\ variable_raw_domain v) \\ (\\m1 m2. (\\w\\vs. Rep_mem2 m1 w = Rep_mem2 m2 w) \\ e m1 = e m2)}\"\n have \"rel_exp1 (vs1, inv embedding \\ f1) (vs2, inv embedding \\ f2) \\\n rel_exp2 (vs1, inv embedding \\ f1) (vs2, inv embedding \\ f2)\"\n apply (rule eq)\n using p1 p2 unfolding prod1 prod2 apply auto by presburger+\n then\n show \"rel_prod rel_v (\\(vs1, f1) (vs2, f2). rel_exp1 (vs1, inv embedding \\ f1) (vs2, inv embedding \\ f2)) prod1 prod2 =\n rel_prod rel_v (\\(vs1, f1) (vs2, f2). rel_exp2 (vs1, inv embedding \\ f1) (vs2, inv embedding \\ f2)) prod1 prod2\"\n by (simp add: case_prod_beta prod1 prod2)\nqed\n\nlemma rel_substitute1_flip[simp]: \"(rel_substitute1 R S)^--1 = rel_substitute1 R^--1 S^--1\"\n apply (rule ext)+ unfolding conversep_iff apply transfer by auto\n\nlemma rel_substitute1x_flip[simp]: \"(rel_substitute1x R S)^--1 = rel_substitute1x R^--1 S^--1\"\n apply (rule ext)+ unfolding rel_substitute1x_def by (auto simp: rel_fun_def simp flip: rel_mem2_flip)\n\nlemma left_unique_rel_substitute1x[transfer_rule]: \n assumes \"left_unique R\"\n assumes \"left_unique S\"\n and \"right_total S\"\n and \"type_preserving_var_rel S\"\n shows \"left_unique (rel_substitute1x R S)\"\nproof (unfold rel_substitute1x_def, rule left_uniqueI, auto)\n fix x y z\n assume \"R (substitution1_variable x) (substitution1_variable z)\"\n and \"R (substitution1_variable y) (substitution1_variable z)\"\n with \\left_unique R\\ have \"substitution1_variable x = substitution1_variable y\"\n by (rule left_uniqueD)\n moreover\n assume \"rel_set R (substitution1_footprint x) (substitution1_footprint z)\"\n and \"rel_set R (substitution1_footprint y) (substitution1_footprint z)\"\n with \\left_unique R\\ have \"substitution1_footprint x = substitution1_footprint y\"\n by (meson left_uniqueD left_unique_rel_set)\n moreover\n assume \"rel_fun (rel_mem2 S) (=) (substitution1_function x) (substitution1_function z)\"\n and \"rel_fun (rel_mem2 S) (=) (substitution1_function y) (substitution1_function z)\"\n with assms have \"substitution1_function x = substitution1_function y\"\n by (meson left_total_rel_mem2 left_uniqueD left_unique_eq left_unique_fun)\n ultimately\n show \"x = y\"\n using Rep_substitution1_components Rep_substitution1_inject by auto\nqed\n\nlemma left_unique_rel_substitute1[transfer_rule]: \n assumes \"left_unique R\"\n assumes \"left_unique S\"\n shows \"left_unique (rel_substitute1 R S)\"\nproof -\n have \"s1 = s2\" if \"rel_substitute1 R S s1 t\" and \"rel_substitute1 R S s2 t\" for s1 s2 t\n proof -\n obtain xs1 vss1 es1 where s1: \"Rep_substitution1 s1 = (xs1,vss1,es1)\" by (meson prod_cases3)\n then have \"finite vss1\" and foot1: \"(\\w\\vss1. Rep_mem2 m1 w = Rep_mem2 m2 w) \\ es1 m1 = es1 m2\" for m1 m2\n using Rep_substitution1[of s1] by auto\n obtain xs2 vss2 es2 where s2: \"Rep_substitution1 s2 = (xs2,vss2,es2)\" by (meson prod_cases3)\n then have \"finite vss2\" and foot2: \"(\\w\\vss2. Rep_mem2 m1 w = Rep_mem2 m2 w) \\ es2 m1 = es2 m2\" for m1 m2\n using Rep_substitution1[of s2] by auto\n obtain xt vst et where t: \"Rep_substitution1 t = (xt,vst,et)\" by (meson prod_cases3)\n\n from that have \"rel_prod R\n (\\(vss1, es1) (vst, et).\n range es1 \\ range EMBEDDING('a) \\\n range et \\ range EMBEDDING('b) \\\n S (Abs_expression (vss1, inv EMBEDDING('a) \\ es1)) (Abs_expression (vst, inv EMBEDDING('b) \\ et)))\n (xs1, vss1, es1) (xt, vst, et)\"\n unfolding rel_substitute1.rep_eq s1 t by simp\n then have R1: \"R xs1 xt\" and range_es1: \"range es1 \\ range EMBEDDING('a)\" and \"range et \\ range EMBEDDING('b)\" \n and S1: \"S (Abs_expression (vss1, inv EMBEDDING('a) \\ es1)) (Abs_expression (vst, inv EMBEDDING('b) \\ et))\"\n by auto\n\n from that have \"rel_prod R\n (\\(vss2, es2) (vst, et).\n range es2 \\ range EMBEDDING('a) \\\n range et \\ range EMBEDDING('b) \\\n S (Abs_expression (vss2, inv EMBEDDING('a) \\ es2)) (Abs_expression (vst, inv EMBEDDING('b) \\ et)))\n (xs2, vss2, es2) (xt, vst, et)\"\n unfolding rel_substitute1.rep_eq s2 t by simp\n then have R2: \"R xs2 xt\" and range_es2: \"range es2 \\ range EMBEDDING('a)\" and \"range et \\ range EMBEDDING('b)\" \n and S2: \"S (Abs_expression (vss2, inv EMBEDDING('a) \\ es2)) (Abs_expression (vst, inv EMBEDDING('b) \\ et))\"\n by auto\n\n from R1 R2 have \"xs1 = xs2\"\n using \\left_unique R\\\n by (meson left_uniqueD)\n\n from S1 S2 have AbsS: \"Abs_expression (vss1, inv EMBEDDING('a) \\ es1) = Abs_expression (vss2, inv EMBEDDING('a) \\ es2)\"\n using \\left_unique S\\\n by (meson left_uniqueD)\n have \"(vss1, inv EMBEDDING('a) \\ es1) = (vss2, inv EMBEDDING('a) \\ es2)\"\n apply (rule Abs_expression_inject[THEN iffD1, OF _ _ AbsS])\n using foot1 foot2 \\finite vss1\\ \\finite vss2\\ by force+\n then have \"vss1 = vss2\" and inv: \"inv EMBEDDING('a) o es1 = inv EMBEDDING('a) o es2\" by auto\n with range_es1 range_es2 have \"es1 = es2\"\n by (smt fun.inj_map_strong inv_into_injective subsetCE) \n\n from \\xs1 = xs2\\ and \\vss1 = vss2\\ and \\es1 = es2\\\n show \"s1 = s2\"\n using Rep_substitution1_inject s1 s2 by fastforce\n qed\n then show ?thesis\n unfolding left_unique_def by simp\nqed\n\nlemma right_unique_rel_substitute1[transfer_rule]:\n assumes \"right_unique R\" and \"right_unique S\"\n shows \"right_unique (rel_substitute1 R S)\"\n apply (subst conversep_conversep[of R, symmetric])\n apply (subst conversep_conversep[of S, symmetric])\n apply (subst rel_substitute1_flip[symmetric])\n apply (simp del: rel_substitute1_flip)\n apply (rule left_unique_rel_substitute1)\n using assms by auto\n\nlemma right_unique_rel_substitute1x[transfer_rule]:\n assumes \"right_unique R\" and \"right_unique S\" and \"left_total S\" and \"type_preserving_var_rel S\"\n shows \"right_unique (rel_substitute1x R S)\"\n apply (subst conversep_conversep[of R, symmetric])\n apply (subst conversep_conversep[of S, symmetric])\n apply (subst rel_substitute1x_flip[symmetric])\n apply (simp del: rel_substitute1x_flip)\n apply (rule left_unique_rel_substitute1x)\n using assms by auto\n\nlemma bi_unique_rel_substitute1[transfer_rule]:\n assumes \"bi_unique R\" and \"bi_unique S\"\n shows \"bi_unique (rel_substitute1 R S)\"\n using assms by (meson bi_total_alt_def bi_unique_alt_def left_unique_rel_substitute1 right_unique_rel_substitute1)\n\nlemma bi_unique_rel_substitute1x[transfer_rule]:\n assumes \"bi_unique R\" and \"bi_unique S\" and \"bi_total S\" and \"type_preserving_var_rel S\"\n shows \"bi_unique (rel_substitute1x R S)\"\n using assms by (meson bi_total_alt_def bi_unique_alt_def left_unique_rel_substitute1x right_unique_rel_substitute1x)\n\n\nlemma rel_substitute1_expression_eq: \"rel_substitute1 R (rel_expression S T) s1 s2 = \n (R (substitution1_variable s1) (substitution1_variable s2) \\\n rel_set S (substitution1_footprint s1) (substitution1_footprint s2) \\\n range (substitution1_function s1) \\ range EMBEDDING('a) \\ \n range (substitution1_function s2) \\ range EMBEDDING('b) \\ \n rel_fun (rel_mem2 S) T (inv EMBEDDING('a) \\ substitution1_function s1)\n (inv EMBEDDING('b) \\ substitution1_function s2))\"\n using [[transfer_del_const pcr_mem2]]\n apply transfer by force\n\n\nlemma rel_substitution1x_function:\n includes lifting_syntax\n fixes R S\n defines \"subR == rel_substitute1x R S\"\n shows \"(subR ===> rel_mem2 S ===> (=)) substitution1_function substitution1_function\"\n unfolding subR_def rel_substitute1x_def apply (rule rel_funI)+ unfolding rel_fun_def\n apply transfer by auto\n\nlemma rel_substitution1_function:\n includes lifting_syntax\n fixes R\n defines \"subR == rel_substitute1 R (rel_expression R (=))\"\n shows \"(subR ===> rel_mem2 R ===> (=)) substitution1_function substitution1_function\"\nproof (rule rel_funI, rule rel_funI, rename_tac s1 s2 m1 m2)\n fix s1 s2 m1 m2\n assume s12: \"subR s1 s2\"\n assume m12: \"rel_mem2 R m1 m2\"\n show \"substitution1_function s1 m1 = substitution1_function s2 m2\"\n using s12 m12 unfolding subR_def \n apply transfer unfolding rel_fun_def rel_set_def apply auto\n by (metis UNIV_I image_subset_iff inv_into_injective)\nqed\n\n(* TODO define *)\n\n(* Note: substitute_vars adds variables from varterm right-to-left to the substition1 list.\n This means, right variables have priority in case of name clashes *)\naxiomatization substitute_vars :: \"'a variables \\ 'a expression \\ substitution1 list\"\naxiomatization where substitute_vars_unit: \"substitute_vars variable_unit e = []\"\naxiomatization where substitute_vars_concat: \"substitute_vars (variable_concat v1 v2) e\n = (substitute_vars v2 (map_expression snd e)) @ (substitute_vars v1 (map_expression fst e))\" for e :: \"('a::universe*'b::universe) expression\"\naxiomatization where substitute_vars_singleton: \"substitute_vars (variable_singleton v) e = [substitute1 v e]\" for e :: \"('a::universe) expression\"\n\n\nlift_definition subst_mem2 :: \"substitution1 list \\ mem2 \\ mem2\" is\n \"\\(\\::substitution1 list) (m::mem2) (v::variable_raw). \n case find (\\s. substitution1_variable s=v) \\ of None \\ Rep_mem2 m v | Some s \\ substitution1_function s m\"\nproof (rename_tac \\ m v)\n fix \\ m v\n show \"(case find (\\s. substitution1_variable s = v) \\ of None \\ Rep_mem2 m v | Some s \\ substitution1_function s m) \\ variable_raw_domain v\" \n proof (cases \"find (\\s. substitution1_variable s = v) \\ = None\")\n case True\n then show ?thesis using Rep_mem2 by auto\n next\n case False\n then obtain s where find: \"find (\\s. substitution1_variable s = v) \\ = Some s\" by auto\n have \"s \\ set \\\" and \"substitution1_variable s = v\"\n using find apply (subst (asm) find_Some_iff) using nth_mem apply force\n using find apply (subst (asm) find_Some_iff) using nth_mem by force\n then have \"substitution1_function s m \\ variable_raw_domain v\"\n using substitution1_function_domain by metis\n with find show ?thesis by auto\n qed\nqed\n\n\nlemma rel_substitute1_Rep_substitution1:\n includes lifting_syntax\n fixes R S S'\n defines \"subR == rel_substitute1 R (rel_expression R S)\"\n assumes \"\\x y. S x y \\ S' (embedding x) (embedding y)\"\n shows \"(subR ===> rel_prod R (rel_prod (rel_set R) (rel_mem2 R ===> S'))) Rep_substitution1 Rep_substitution1\"\n apply (rule rel_funI)\n apply (simp add: subR_def rel_substitute1_expression_eq[abs_def] rel_fun_def Rep_substitution1_components rel_prod_conv BNF_Greatest_Fixpoint.image2p_def)\n using assms by (auto simp: f_inv_into_f image_subset_iff) \n\nlemma rel_substitute1x_Rep_substitution1:\n includes lifting_syntax\n fixes R S S'\n defines \"subR == rel_substitute1x R S\"\n shows \"(subR ===> rel_prod R (rel_prod (rel_set R) (rel_mem2 S ===> (=)))) Rep_substitution1 Rep_substitution1\"\n apply (rule rel_funI)\n by (simp add: subR_def rel_substitute1x_def Rep_substitution1_components)\n\nlemma rel_substitute1_substitution1_variable: \n includes lifting_syntax\n fixes R S\n defines \"subR == rel_substitute1 R (rel_expression R S)\"\n shows \"(subR ===> R) substitution1_variable substitution1_variable\"\nproof -\n define S' where S': \"S' == BNF_Greatest_Fixpoint.image2p embedding embedding S\"\n have [unfolded subR_def, transfer_rule]: \"(subR ===> rel_prod R (rel_prod (rel_set R) (rel_mem2 R ===> S'))) Rep_substitution1 Rep_substitution1\"\n unfolding subR_def apply (rule rel_substitute1_Rep_substitution1) by (simp add: S' image2p_def)\n show ?thesis\n unfolding subR_def substitution1_variable_def map_fun_def\n by transfer_prover\nqed\n\nlemma rel_substitute1x_substitution1_variable: \n includes lifting_syntax\n fixes R S\n defines \"subR == rel_substitute1x R S\"\n shows \"(subR ===> R) substitution1_variable substitution1_variable\"\n unfolding subR_def rel_substitute1x_def rel_fun_def by auto\n\nlemma rel_substitute1x_substitution1_footprint:\n includes lifting_syntax\n fixes R S\n defines \"subR == rel_substitute1x R S\"\n shows \"(subR ===> rel_set R) substitution1_footprint substitution1_footprint\"\n unfolding subR_def rel_substitute1x_def rel_fun_def by auto\n\nlemma rel_substitute1_substitution1_footprint:\n includes lifting_syntax\n fixes R\n defines \"subR == rel_substitute1 R (rel_expression R (=))\"\n shows \"(subR ===> rel_set R) substitution1_footprint substitution1_footprint\"\nproof -\n have [unfolded subR_def, transfer_rule]: \"(subR ===> rel_prod R (rel_prod (rel_set R) (rel_mem2 R ===> (=)))) Rep_substitution1 Rep_substitution1\"\n unfolding subR_def apply (rule rel_substitute1_Rep_substitution1) by simp\n show ?thesis\n unfolding subR_def substitution1_footprint_def map_fun_def\n by transfer_prover\nqed\n\nlemma subst_mem2_empty[simp]: \"subst_mem2 [] = id\"\n apply (rule ext) apply (subst Rep_mem2_inject[symmetric]) \n by (simp add: subst_mem2.rep_eq)\n\n(* \ndefinition subst_expression :: \"substitution list \\ 'b expression \\ 'b expression\" where\n \"subst_expression \\ e = *)\n\n\nlemma rel_subst_mem2_x:\n includes lifting_syntax\n fixes R\n assumes [transfer_rule]: \"bi_unique R\"\n defines \"subR == rel_substitute1x R R\"\n shows \"(list_all2 subR ===> rel_mem2 R ===> rel_mem2 R) subst_mem2 subst_mem2\"\nproof (rule rel_funI, rule rel_funI)\n fix s1 s2 m1 m2\n assume s12[unfolded subR_def, transfer_rule]: \"list_all2 subR s1 s2\"\n assume m12[transfer_rule]: \"rel_mem2 R m1 m2\"\n show \"rel_mem2 R (subst_mem2 s1 m1) (subst_mem2 s2 m2)\"\n unfolding rel_mem2.rep_eq subst_mem2.rep_eq \n proof (rule rel_funI, rename_tac v1 v2) \n fix v1 v2\n assume v12[transfer_rule]: \"R v1 v2\"\n note rel_substitute1x_substitution1_variable[transfer_rule]\n define find1 find2 \n where \"find1 = find (\\s. substitution1_variable s = v1) s1\" \n and \"find2 = find (\\s. substitution1_variable s = v2) s2\"\n have find12: \"(rel_option subR) find1 find2\" \n unfolding find1_def find2_def subR_def\n by transfer_prover\n show \"(case find1 of None \\ Rep_mem2 m1 v1 | Some s \\ substitution1_function s m1) =\n (case find2 of None \\ Rep_mem2 m2 v2 | Some s \\ substitution1_function s m2)\"\n proof (cases \"find1\")\n case None\n with find12 have None2: \"find2 = None\" by auto\n show ?thesis\n unfolding None None2 apply simp\n by (metis (full_types) v12 m12 rel_fun_def rel_mem2.rep_eq)\n next\n case (Some s1')\n with find12 obtain s2' where Some2: \"find2 = Some s2'\" and [transfer_rule]: \"subR s1' s2'\"\n by (meson option_rel_Some1)\n have [transfer_rule]: \"(subR ===> rel_mem2 R ===> (=)) substitution1_function substitution1_function\"\n unfolding subR_def by (rule rel_substitution1x_function)\n show ?thesis\n unfolding Some Some2 apply simp by transfer_prover\n qed\n qed\nqed\n\nlemma rel_subst_mem2:\n includes lifting_syntax\n fixes R\n assumes [transfer_rule]: \"bi_unique R\"\n defines \"subR == rel_substitute1 R (rel_expression R (=))\"\n shows \"(list_all2 subR ===> rel_mem2 R ===> rel_mem2 R) subst_mem2 subst_mem2\"\nproof (rule rel_funI, rule rel_funI)\n fix s1 s2 m1 m2\n assume s12[unfolded subR_def, transfer_rule]: \"list_all2 subR s1 s2\"\n assume m12[transfer_rule]: \"rel_mem2 R m1 m2\"\n show \"rel_mem2 R (subst_mem2 s1 m1) (subst_mem2 s2 m2)\"\n unfolding rel_mem2.rep_eq subst_mem2.rep_eq \n proof (rule rel_funI, rename_tac v1 v2) \n fix v1 v2\n assume v12[transfer_rule]: \"R v1 v2\"\n note rel_substitute1_substitution1_variable[transfer_rule]\n define find1 find2 where \"find1 = find (\\s. substitution1_variable s = v1) s1\" and \"find2 = find (\\s. substitution1_variable s = v2) s2\"\n have find12: \"(rel_option subR) find1 find2\" \n unfolding find1_def find2_def subR_def\n by transfer_prover\n show \"(case find1 of None \\ Rep_mem2 m1 v1 | Some s \\ substitution1_function s m1) =\n (case find2 of None \\ Rep_mem2 m2 v2 | Some s \\ substitution1_function s m2)\"\n proof (cases \"find1\")\n case None\n with find12 have None2: \"find2 = None\" by auto\n show ?thesis\n unfolding None None2 apply simp\n by (metis (full_types) v12 m12 rel_fun_def rel_mem2.rep_eq)\n next\n case (Some s1')\n with find12 obtain s2' where Some2: \"find2 = Some s2'\" and [transfer_rule]: \"subR s1' s2'\"\n by (meson option_rel_Some1)\n have [transfer_rule]: \"(subR ===> rel_mem2 R ===> (=)) substitution1_function substitution1_function\"\n unfolding subR_def by (rule rel_substitution1_function)\n show ?thesis\n unfolding Some Some2 apply simp by transfer_prover\n qed\n qed\nqed\n\n\nlemma finite_substitution1_footprint[simp]: \"finite (substitution1_footprint \\)\"\n apply transfer by auto\n\n(* TODO move *)\nlemma find_map: \"find p (map f l) = map_option f (find (\\x. p (f x)) l)\"\n by (induction l, auto)\n\ndefinition \"subst_expression_footprint (\\::substitution1 list) (vs::variable_raw set) =\n (Union {substitution1_footprint s | s v. \n Some s = find (\\s. substitution1_variable s = v) \\ \\ substitution1_variable s \\ vs})\n \\ (vs - substitution1_variable ` set \\)\"\n\nlemma finite_subst_expression_footprint: \"finite vs \\ finite (subst_expression_footprint \\ vs)\"\nproof -\n assume \"finite vs\"\n have \"subst_expression_footprint \\ vs \n \\ (Union {substitution1_footprint s | s. s\\set \\ \\ substitution1_variable s \\ vs})\n \\ (vs - substitution1_variable ` set \\)\"\n unfolding subst_expression_footprint_def apply auto\n by (metis (full_types) find_Some_iff nth_mem)+\n moreover \n from \\finite vs\\ have \"finite \\\" by auto\n ultimately show ?thesis\n by (meson finite_subset)\nqed\n\nlemma subst_expression_footprint_union:\n \"subst_expression_footprint \\ (X \\ Y) = subst_expression_footprint \\ X \\ subst_expression_footprint \\ Y\"\n unfolding subst_expression_footprint_def by blast\n\nlemma rel_set_subst_expression_footprint_x:\n includes lifting_syntax\n assumes \"bi_unique R\" and \"bi_total R\" and \"type_preserving_var_rel R\"\n defines \"subR == rel_substitute1x R R\"\n assumes \"list_all2 subR s1 s2\"\n assumes \"rel_set R vs1 vs2\" \n shows \"rel_set R (subst_expression_footprint s1 vs1) (subst_expression_footprint s2 vs2)\"\nproof (rule rel_setI)\n\n have goal: \"\\y\\subst_expression_footprint s2 vs2. R x y\" if \"x \\ subst_expression_footprint s1 vs1\" \n and [transfer_rule]: \"list_all2 subR s1 s2\"\n and [transfer_rule]: \"rel_set R vs1 vs2\"\n and [transfer_rule]: \"bi_unique R\"\n and [transfer_rule]: \"bi_total R\"\n and [transfer_rule]: \"type_preserving_var_rel R\"\n and subR_def: \"subR = rel_substitute1x R R\"\n for x s1 s2 vs1 vs2 R subR\n proof -\n have [transfer_rule]: \"(subR ===> R) substitution1_variable substitution1_variable\"\n unfolding subR_def by (rule rel_substitute1x_substitution1_variable)\n have [transfer_rule]: \"(subR ===> rel_set R) substitution1_footprint substitution1_footprint\"\n unfolding subR_def by (rule rel_substitute1x_substitution1_footprint)\n have [transfer_rule]: \"bi_unique subR\" \n unfolding subR_def\n using \\bi_unique R\\ apply (rule bi_unique_rel_substitute1x)\n using that bi_unique_eq by auto\n show ?thesis\n proof (cases \"x \\ vs1 - substitution1_variable ` set s1\")\n case False\n with that obtain sx vx where x_sx: \"x \\ substitution1_footprint sx\" \n and Some1: \"Some sx = find (\\s. substitution1_variable s = vx) s1\" \n and sx_vs1: \"substitution1_variable sx \\ vs1\"\n unfolding subst_expression_footprint_def by auto\n from Some1 obtain i where s1i: \"s1!i = sx\" and lens1: \"i < length s1\"\n by (metis find_Some_iff) \n define sy where \"sy = s2!i\"\n then have [transfer_rule]: \"subR sx sy\"\n using s1i lens1 \\list_all2 subR s1 s2\\ list_all2_conv_all_nth by blast\n from Some1 have vx_def: \"vx = substitution1_variable sx\"\n by (metis (mono_tags) find_Some_iff)\n define vy where \"vy = substitution1_variable sy\"\n have [transfer_rule]: \"R vx vy\" unfolding vy_def vx_def\n by (meson \\(subR ===> R) substitution1_variable substitution1_variable\\ \\subR sx sy\\ rel_funD)\n from sx_vs1 have \"vx : vs1\"\n by (simp add: vx_def)\n have Some2: \"Some sy = find (\\s. substitution1_variable s = vy) s2\"\n apply (transfer fixing: sy vy s1) \n by (fact Some1)\n have sy_vs2: \"substitution1_variable sy \\ vs2\"\n apply (transfer fixing: sy vs2)\n by (fact sx_vs1)\n have \"rel_set R (substitution1_footprint sx) (substitution1_footprint sy)\"\n by (meson \\(subR ===> rel_set R) substitution1_footprint substitution1_footprint\\ \\subR sx sy\\ rel_funD)\n with x_sx obtain y where Rxy: \"R x y\" and y_sy: \"y \\ substitution1_footprint sy\"\n by (meson rel_set_def)\n from Some2 sy_vs2 y_sy have \"y\\subst_expression_footprint s2 vs2\"\n unfolding subst_expression_footprint_def by auto\n with Rxy show ?thesis by auto\n next\n case True\n have \"rel_set R (vs1 - substitution1_variable ` set s1) (vs2 - substitution1_variable ` set s2)\"\n by transfer_prover\n with True obtain y where \"y \\ vs2 - substitution1_variable ` set s2\" and Rxy: \"R x y\"\n by (meson rel_set_def)\n then have \"y\\subst_expression_footprint s2 vs2\"\n unfolding subst_expression_footprint_def by auto\n with Rxy show ?thesis by auto \n qed\n qed\n show \"\\y\\subst_expression_footprint s2 vs2. R x y\" if \"x \\ subst_expression_footprint s1 vs1\" for x\n apply (rule goal) using assms that by simp_all\n show \"\\x\\subst_expression_footprint s1 vs1. R x y\" if \"y \\ subst_expression_footprint s2 vs2\" for y\n apply (subst conversep_iff[of R, symmetric])\n apply (rule goal[where R=\"conversep R\" and subR=\"conversep subR\"]) \n apply (simp_all add: list.rel_flip)\n using that assms by (simp_all add: subR_def)\nqed\n\nlemma rel_set_subst_expression_footprint:\n includes lifting_syntax\n assumes \"bi_unique R\" and \"bi_total R\" and \"type_preserving_var_rel R\"\n defines \"subR == rel_substitute1 R (rel_expression R (=))\"\n assumes \"list_all2 subR s1 s2\"\n assumes \"rel_set R vs1 vs2\" \n shows \"rel_set R (subst_expression_footprint s1 vs1) (subst_expression_footprint s2 vs2)\"\nproof (rule rel_setI)\n\n have goal: \"\\y\\subst_expression_footprint s2 vs2. R x y\" if \"x \\ subst_expression_footprint s1 vs1\" \n and [transfer_rule]: \"list_all2 subR s1 s2\"\n and [transfer_rule]: \"rel_set R vs1 vs2\"\n and [transfer_rule]: \"bi_unique R\"\n and [transfer_rule]: \"bi_total R\"\n and [transfer_rule]: \"type_preserving_var_rel R\"\n and subR_def: \"subR = rel_substitute1 R (rel_expression R (=))\"\n for x s1 s2 vs1 vs2 R subR\n proof -\n have [transfer_rule]: \"(subR ===> R) substitution1_variable substitution1_variable\"\n unfolding subR_def by (rule rel_substitute1_substitution1_variable)\n have [transfer_rule]: \"(subR ===> rel_set R) substitution1_footprint substitution1_footprint\"\n unfolding subR_def by (rule rel_substitute1_substitution1_footprint)\n have [transfer_rule]: \"bi_unique subR\" \n unfolding subR_def\n using \\bi_unique R\\ apply (rule bi_unique_rel_substitute1)\n apply (rule bi_unique_rel_expression)\n using that bi_unique_eq by auto\n show ?thesis\n proof (cases \"x \\ vs1 - substitution1_variable ` set s1\")\n case False\n with that obtain sx vx where x_sx: \"x \\ substitution1_footprint sx\" \n and Some1: \"Some sx = find (\\s. substitution1_variable s = vx) s1\" \n and sx_vs1: \"substitution1_variable sx \\ vs1\"\n unfolding subst_expression_footprint_def by auto\n from Some1 obtain i where s1i: \"s1!i = sx\" and lens1: \"i < length s1\"\n by (metis find_Some_iff) \n define sy where \"sy = s2!i\"\n then have [transfer_rule]: \"subR sx sy\"\n using s1i lens1 \\list_all2 subR s1 s2\\ list_all2_conv_all_nth by blast\n from Some1 have vx_def: \"vx = substitution1_variable sx\"\n by (metis (mono_tags) find_Some_iff)\n define vy where \"vy = substitution1_variable sy\"\n have [transfer_rule]: \"R vx vy\" unfolding vy_def vx_def\n by (meson \\(subR ===> R) substitution1_variable substitution1_variable\\ \\subR sx sy\\ rel_funD)\n from sx_vs1 have \"vx : vs1\"\n by (simp add: vx_def)\n have Some2: \"Some sy = find (\\s. substitution1_variable s = vy) s2\"\n apply (transfer fixing: sy vy s1) \n by (fact Some1)\n have sy_vs2: \"substitution1_variable sy \\ vs2\"\n apply (transfer fixing: sy vs2)\n by (fact sx_vs1)\n have \"rel_set R (substitution1_footprint sx) (substitution1_footprint sy)\"\n by (meson \\(subR ===> rel_set R) substitution1_footprint substitution1_footprint\\ \\subR sx sy\\ rel_funD)\n with x_sx obtain y where Rxy: \"R x y\" and y_sy: \"y \\ substitution1_footprint sy\"\n by (meson rel_set_def)\n from Some2 sy_vs2 y_sy have \"y\\subst_expression_footprint s2 vs2\"\n unfolding subst_expression_footprint_def by auto\n with Rxy show ?thesis by auto\n next\n case True\n have \"rel_set R (vs1 - substitution1_variable ` set s1) (vs2 - substitution1_variable ` set s2)\"\n by transfer_prover\n with True obtain y where \"y \\ vs2 - substitution1_variable ` set s2\" and Rxy: \"R x y\"\n by (meson rel_set_def)\n then have \"y\\subst_expression_footprint s2 vs2\"\n unfolding subst_expression_footprint_def by auto\n with Rxy show ?thesis by auto \n qed\n qed\n show \"\\y\\subst_expression_footprint s2 vs2. R x y\" if \"x \\ subst_expression_footprint s1 vs1\" for x\n apply (rule goal) using assms that by simp_all\n show \"\\x\\subst_expression_footprint s1 vs1. R x y\" if \"y \\ subst_expression_footprint s2 vs2\" for y\n apply (subst conversep_iff[of R, symmetric])\n apply (rule goal[where R=\"conversep R\" and subR=\"conversep subR\"]) \n apply (simp_all add: list.rel_flip)\n using that assms by (simp_all add: subR_def)\nqed\n\nlemma subst_mem2_footprint:\n fixes \\ vs\n assumes meq: \"\\v. v\\subst_expression_footprint \\ vs \\ Rep_mem2 m1 v = Rep_mem2 m2 v\"\n assumes \"v \\ vs\"\n shows \"Rep_mem2 (subst_mem2 \\ m1) v = Rep_mem2 (subst_mem2 \\ m2) v\"\nproof (cases \"find (\\s. substitution1_variable s=v) \\\")\n case None\n then have unmod: \"Rep_mem2 (subst_mem2 \\ m) v = Rep_mem2 m v\" for m\n unfolding subst_mem2.rep_eq by simp\n from None have \"v \\ substitution1_variable ` set \\\"\n apply transfer by (auto simp: find_None_iff)\n with \\v \\ vs\\ have \"v \\ subst_expression_footprint \\ vs\"\n unfolding subst_expression_footprint_def by simp \n with unmod and meq show ?thesis by metis\nnext\n case (Some s)\n then have s_v: \"substitution1_variable s = v\"\n by (metis (mono_tags, lifting) find_Some_iff)\n from Some have Rep_sf: \"Rep_mem2 (subst_mem2 \\ m) v = substitution1_function s m\" for m\n unfolding subst_mem2.rep_eq by auto \n have sf_eq: \"(\\w\\substitution1_footprint s. Rep_mem2 m1 w = Rep_mem2 m2 w) \\ substitution1_function s m1 = substitution1_function s m2\"\n apply transfer by auto\n from Some \\v\\vs\\ s_v have \"Some s = find (\\s. substitution1_variable s = v) \\ \\ substitution1_variable s \\ vs\"\n by auto\n then have \"substitution1_footprint s \\ subst_expression_footprint \\ vs\"\n unfolding subst_expression_footprint_def by auto\n with sf_eq meq have \"substitution1_function s m1 = substitution1_function s m2\" by auto\n with sf_eq show ?thesis\n by (simp add: Rep_sf)\nqed\n\n\nlift_definition subst_expression :: \"substitution1 list \\ 'b expression \\ 'b expression\" is\n \"\\(\\::substitution1 list) (vs,e).\n (subst_expression_footprint \\ vs,\n e o subst_mem2 \\)\"\nproof (auto simp: finite_subst_expression_footprint)\n fix \\ and vs :: \"variable_raw set\" and e :: \"mem2\\'b\" and m1 m2\n assume \"finite vs\"\n assume \"\\m1 m2. (\\v\\vs. Rep_mem2 m1 v = Rep_mem2 m2 v) \\ e m1 = e m2\"\n then have e_footprint: \"e m1 = e m2\" if \"\\v\\vs. Rep_mem2 m1 v = Rep_mem2 m2 v\" for m1 m2 using that by simp\n assume meq: \"\\v\\subst_expression_footprint \\ vs.\n Rep_mem2 m1 v = Rep_mem2 m2 v\"\n then have \"Rep_mem2 (subst_mem2 \\ m1) v = Rep_mem2 (subst_mem2 \\ m2) v\" if \"v \\ vs\" for v\n using meq subst_mem2_footprint that by metis \n then show \"e (subst_mem2 \\ m1) = e (subst_mem2 \\ m2)\" \n by (rule_tac e_footprint, simp)\nqed\n\nlemma subst_expression_footprint: \"expression_vars (subst_expression \\ e) = subst_expression_footprint \\ (expression_vars e)\"\n apply transfer by auto\nlemma subst_expression_eval: \"expression_eval (subst_expression \\ e) = expression_eval e o subst_mem2 \\\"\n apply (rule ext) unfolding o_def expression_eval.rep_eq subst_expression.rep_eq case_prod_beta by simp\n\n\nlemma rel_expression_subst_expression [transfer_rule]: \n includes lifting_syntax\n assumes [transfer_rule]: \"bi_unique R\" and [transfer_rule]: \"bi_total R\" and [transfer_rule]: \"type_preserving_var_rel R\"\n defines \"subR == rel_substitute1 R (rel_expression R (=))\"\n shows \"(list_all2 subR ===> rel_expression R (=) ===> rel_expression R (=)) \n subst_expression subst_expression\"\nproof -\n have \"rel_expression R (=) (subst_expression s1 e1) (subst_expression s2 e2)\" \n if subR_s1_s2[transfer_rule]: \"list_all2 subR s1 s2\" and R_e1_e2: \"rel_expression R (=) e1 e2\" \n for s1 s2 and e1 e2 :: \"'b expression\"\n proof -\n define vs1 E1 vs2 E2 where \"vs1 = expression_vars e1\" and \"E1 = expression_eval e1\"\n and \"vs2 = expression_vars e2\" and \"E2 = expression_eval e2\"\n have [unfolded subR_def, transfer_rule]: \"(subR ===> rel_prod R (rel_prod (rel_set R) (rel_mem2 R ===> (=)))) Rep_substitution1 Rep_substitution1\"\n unfolding subR_def apply (rule rel_substitute1_Rep_substitution1) by simp\n have [transfer_rule]: \"(subR ===> R) substitution1_variable substitution1_variable\"\n unfolding subR_def by (rule rel_substitute1_substitution1_variable)\n have [transfer_rule]: \"bi_unique subR\" \n unfolding subR_def\n using \\bi_unique R\\ apply (rule bi_unique_rel_substitute1)\n apply (rule bi_unique_rel_expression)\n using assms bi_unique_eq by auto\n have [transfer_rule]: \"(subR ===> rel_set R) substitution1_footprint substitution1_footprint\"\n unfolding subR_def by (rule rel_substitute1_substitution1_footprint)\n have R_vs1_vs2[transfer_rule]: \"rel_set R vs1 vs2\"\n unfolding vs1_def vs2_def using R_e1_e2 apply transfer by auto\n have foot: \"rel_set R (subst_expression_footprint s1 vs1) (subst_expression_footprint s2 vs2)\"\n apply (rule rel_set_subst_expression_footprint)\n using assms R_vs1_vs2 subR_s1_s2 unfolding subR_def by auto\n have E1E2: \"(rel_mem2 R ===> (=)) E1 E2\" \n unfolding E1_def E2_def apply (rule rel_funI)\n using R_e1_e2 apply transfer \n unfolding rel_mem2.rep_eq rel_fun_def by auto\n have subst_mem2_s1_s2: \"(rel_mem2 R ===> rel_mem2 R) (subst_mem2 s1) (subst_mem2 s2)\"\n using rel_subst_mem2 subR_s1_s2 \\bi_unique R\\\n by (metis rel_fun_def subR_def)\n from E1E2 subst_mem2_s1_s2 have subst: \"(rel_mem2 R ===> (=)) (E1 \\ subst_mem2 s1) (E2 \\ subst_mem2 s2)\"\n by (smt comp_def rel_funD rel_funI)\n show ?thesis\n unfolding rel_expression.rep_eq subst_expression.rep_eq using foot subst\n by (simp add: Rep_expression_components E1_def E2_def vs1_def vs2_def)\n qed\n\n then show ?thesis\n unfolding subR_def\n apply (rule_tac rel_funI)+ by assumption\nqed\n\nlemma rel_expression_subst_expression_x [transfer_rule]: \n includes lifting_syntax\n fixes R\n assumes [transfer_rule]: \"bi_unique R\" and [transfer_rule]: \"bi_total R\" and [transfer_rule]: \"type_preserving_var_rel R\"\n defines \"subR == rel_substitute1x R R\"\n shows \"(list_all2 subR ===> rel_expression R (=) ===> rel_expression R (=)) \n subst_expression subst_expression\"\nproof -\n have \"rel_expression R (=) (subst_expression s1 e1) (subst_expression s2 e2)\" \n if subR_s1_s2[transfer_rule]: \"list_all2 subR s1 s2\" and R_e1_e2: \"rel_expression R (=) e1 e2\" \n for s1 s2 and e1 e2 :: \"'b expression\"\n proof -\n define vs1 E1 vs2 E2 where \"vs1 = expression_vars e1\" and \"E1 = expression_eval e1\"\n and \"vs2 = expression_vars e2\" and \"E2 = expression_eval e2\"\n have [unfolded subR_def, transfer_rule]: \n \"(subR ===> rel_prod R (rel_prod (rel_set R) (rel_mem2 R ===> (=)))) Rep_substitution1 Rep_substitution1\"\n unfolding subR_def by (rule rel_substitute1x_Rep_substitution1)\n have [transfer_rule]: \"(subR ===> R) substitution1_variable substitution1_variable\"\n unfolding subR_def by (rule rel_substitute1x_substitution1_variable)\n have [transfer_rule]: \"bi_unique subR\" \n unfolding subR_def\n using \\bi_unique R\\ apply (rule bi_unique_rel_substitute1x)\n by (auto simp: assms)\n have [transfer_rule]: \"(subR ===> rel_set R) substitution1_footprint substitution1_footprint\"\n unfolding subR_def by (rule rel_substitute1x_substitution1_footprint)\n have R_vs1_vs2[transfer_rule]: \"rel_set R vs1 vs2\"\n unfolding vs1_def vs2_def using R_e1_e2 apply transfer by auto\n have foot: \"rel_set R (subst_expression_footprint s1 vs1) (subst_expression_footprint s2 vs2)\"\n apply (rule rel_set_subst_expression_footprint_x)\n using assms R_vs1_vs2 subR_s1_s2 unfolding subR_def by auto\n have E1E2: \"(rel_mem2 R ===> (=)) E1 E2\" \n unfolding E1_def E2_def apply (rule rel_funI)\n using R_e1_e2 apply transfer \n unfolding rel_mem2.rep_eq rel_fun_def by auto\n have subst_mem2_s1_s2: \"(rel_mem2 R ===> rel_mem2 R) (subst_mem2 s1) (subst_mem2 s2)\"\n using rel_subst_mem2_x subR_s1_s2 \\bi_unique R\\\n by (metis rel_fun_def subR_def)\n from E1E2 subst_mem2_s1_s2 have subst: \"(rel_mem2 R ===> (=)) (E1 \\ subst_mem2 s1) (E2 \\ subst_mem2 s2)\"\n by (smt comp_def rel_funD rel_funI)\n show ?thesis\n unfolding rel_expression.rep_eq subst_expression.rep_eq using foot subst\n by (simp add: Rep_expression_components E1_def E2_def vs1_def vs2_def)\n qed\n\n then show ?thesis\n unfolding subR_def\n apply (rule_tac rel_funI)+ by assumption\nqed\n\n\nlemma subst_expression_unit_tac:\n shows \"expression variable_unit E = subst_expression s (expression variable_unit E)\"\n apply (subst Rep_expression_inject[symmetric])\n unfolding expression.rep_eq subst_expression.rep_eq subst_expression_footprint_def\n by auto\n\nlemma subst_expression_singleton_same_tac:\n fixes x :: \"'x::universe variable\"\n shows \"expression R (\\r. E (F r)) = subst_expression (substitute1 x (expression R F) # s) (expression \\x\\ E)\"\nproof (subst Rep_expression_inject[symmetric], simp add: expression.rep_eq subst_expression.rep_eq, rule conjI)\n define x' where \"x' = Rep_variable x\"\n have aux: \"((\\v. (x' = v \\ sa = substitute1 x (expression R F)) \\\n (x' \\ v \\ Some sa = find (\\s. substitution1_variable s = v) s)) \\\n substitution1_variable sa = x')\n =\n (sa = substitute1 x (expression R F) \\ substitution1_variable sa = x')\" for sa\n apply auto by (metis (mono_tags) find_Some_iff)\n have \"subst_expression_footprint (substitute1 x (expression R F) # s) {x'} = substitution1_footprint (substitute1 x (expression R F))\"\n unfolding subst_expression_footprint_def by (simp add: x'_def[symmetric] aux)\n also have \"\\ = set (raw_variables R)\"\n by (simp add: substitution1_footprint.rep_eq substitute1.rep_eq case_prod_beta expression.rep_eq)\n finally\n show \"set (raw_variables R) = subst_expression_footprint (substitute1 x (expression R F) # s) {x'}\" by simp\nnext\n have eval_x: \"(embedding::'x\\_) (eval_variables \\x\\ m) = (Rep_mem2 m (Rep_variable x))\" for m\n apply (simp add: variable_singleton.rep_eq eval_variables.rep_eq)\n apply (rule f_inv_into_f)\n by (metis (no_types, lifting) Rep_mem2 mem_Collect_eq variable_raw_domain_Rep_variable)\n have \"F (eval_variables R m) = eval_variables \\x\\ (subst_mem2 (substitute1 x (expression R F) # s) m)\" for m\n apply (subst embedding_inv[symmetric])\n apply (simp add: eval_x subst_mem2.rep_eq substitute1_function)\n apply transfer by auto\n then\n show \"(\\r. E (F r)) \\ eval_variables R = E \\ eval_variables \\x\\ \\ subst_mem2 (substitute1 x (expression R F) # s)\"\n by auto\nqed\n\nlemma subst_expression_singleton_empty_tac:\n shows \"expression \\x\\ E = subst_expression [] (expression \\x\\ E)\"\n apply (subst Rep_expression_inject[symmetric])\n unfolding expression.rep_eq subst_expression.rep_eq subst_expression_footprint_def\n by simp\n\nlemma subst_expression_singleton_notsame_tac:\n fixes x :: \"'x::universe variable\" and y :: \"'y::universe variable\"\n assumes neq: \"variable_name x \\ variable_name y\"\n assumes e_def: \"e = subst_expression \\ (expression \\y\\ E)\"\n shows \"e = subst_expression (substitute1 x f # \\) (expression \\y\\ E)\"\nproof (unfold e_def, subst Rep_expression_inject[symmetric], simp add: expression.rep_eq subst_expression.rep_eq, rule conjI)\n define x' y' where \"x' = Rep_variable x\" and \"y' = Rep_variable y\"\n from neq have [simp]: \"x' \\ y'\"\n by (metis variable_name.rep_eq x'_def y'_def)\n then have aux1: \"Some s = find (\\s. substitution1_variable s = v) (substitute1 x f # \\) \\ substitution1_variable s \\ {y'}\n \\ Some s = find (\\s. substitution1_variable s = v) \\ \\ substitution1_variable s \\ {y'}\"\n for v s\n by (metis (mono_tags) find.simps(2) find_Some_iff singletonD substitute1_variable x'_def)\n from \\x' \\ y'\\ \n have aux2: \"{y'} - substitution1_variable ` set (substitute1 x f # \\)\n = {y'} - substitution1_variable ` set (\\)\"\n using x'_def by auto\n show \"subst_expression_footprint \\ {y'} = subst_expression_footprint (substitute1 x f # \\) {y'}\"\n unfolding subst_expression_footprint_def aux1 aux2 by simp\n\n have eval_y: \"(embedding::'y\\_) (eval_variables \\y\\ m) = (Rep_mem2 m (Rep_variable y))\" for m\n apply (simp add: variable_singleton.rep_eq eval_variables.rep_eq)\n apply (rule f_inv_into_f)\n by (metis (no_types, lifting) Rep_mem2 mem_Collect_eq variable_raw_domain_Rep_variable)\n have \"eval_variables \\y\\ (subst_mem2 \\ m) = eval_variables \\y\\ (subst_mem2 (substitute1 x f # \\) m)\" for m\n apply (subst embedding_inv[symmetric])\n by (simp add: eval_y subst_mem2.rep_eq substitute1_function del: embedding_inv flip: x'_def y'_def)\n then show \"E \\ eval_variables \\y\\ \\ subst_mem2 \\ = E \\ eval_variables \\y\\ \\ subst_mem2 (substitute1 x f # \\)\"\n by auto\nqed\n\nlemma subst_expression_concat_id_tac:\n assumes \"expression Q1' e1 = subst_expression s (expression Q1 (\\x. x))\"\n assumes \"expression Q2' e2 = subst_expression s (expression Q2 (\\x. x))\"\n shows \"expression (variable_concat Q1' Q2') (\\(x1,x2). (e1 x1, e2 x2)) = subst_expression s (expression (variable_concat Q1 Q2) (\\x. x))\"\nproof (subst Rep_expression_inject[symmetric], simp add: expression.rep_eq subst_expression.rep_eq, rule conjI)\n show \"set (raw_variables Q1') \\ set (raw_variables Q2') =\n subst_expression_footprint s (set (raw_variables Q1) \\ set (raw_variables Q2))\"\n apply (subst subst_expression_footprint_union)\n using assms by (metis expression_vars subst_expression_footprint)\nnext\n have 1: \"e1 (eval_variables Q1' m) = eval_variables Q1 (subst_mem2 s m)\" for m\n using assms(1)[THEN arg_cong[where f=expression_eval]]\n unfolding subst_expression_eval o_def expression_eval\n by metis\n have 2: \"e2 (eval_variables Q2' m) = eval_variables Q2 (subst_mem2 s m)\" for m\n using assms(2)[THEN arg_cong[where f=expression_eval]]\n unfolding subst_expression_eval o_def expression_eval\n by metis\n from 1 2\n show \"(\\(x1, x2). (e1 x1, e2 x2)) \\ eval_variables (variable_concat Q1' Q2') =\n (\\x. x) \\ eval_variables (variable_concat Q1 Q2) \\ subst_mem2 s\"\n by auto\nqed\n\nlemma subst_expression_id_comp_tac:\n assumes \"expression Q' g = subst_expression s (expression Q (\\x. x))\"\n shows \"expression Q' (\\x. E (g x)) = subst_expression s (expression Q E)\"\nproof (subst Rep_expression_inject[symmetric], simp add: expression.rep_eq subst_expression.rep_eq, rule conjI)\n have \"set (raw_variables Q') = expression_vars (expression Q' g)\"\n by simp\n also have \"\\ = expression_vars (subst_expression s (expression Q (\\x. x)))\"\n using assms by simp\n also have \"\\ = subst_expression_footprint s (expression_vars (expression Q (\\x. x)))\"\n unfolding subst_expression_footprint by rule\n also have \"\\ = subst_expression_footprint s (set (raw_variables Q))\"\n by simp\n finally\n show \"set (raw_variables Q') = subst_expression_footprint s (set (raw_variables Q))\"\n by assumption\n\n\n from assms have \"expression_eval (expression Q' g) m = expression_eval (subst_expression s (expression Q (\\x. x))) m\" for m\n by simp\n then have \"g (eval_variables Q' m) = expression_eval (subst_expression s (expression Q (\\x. x))) m\" for m\n by (simp add: expression_eval)\n also have \"\\ m = eval_variables Q (subst_mem2 s m)\" for m\n unfolding expression_eval.rep_eq subst_expression.rep_eq case_prod_beta expression.rep_eq\n by simp\n finally have \"g (eval_variables Q' m) = eval_variables Q (subst_mem2 s m)\" for m\n by assumption\n then show \"(\\x. E (g x)) \\ eval_variables Q' = E \\ eval_variables Q \\ subst_mem2 s\"\n by auto\nqed\n\n\nlemma index_flip_subst_expression: \n fixes \\ :: \"substitution1 list\" and e :: \"'a expression\"\n shows \"index_flip_expression (subst_expression \\ e) \n = subst_expression (map index_flip_substitute1 \\) (index_flip_expression e)\"\nproof -\n define subR where \"subR = (rel_substitute1x rel_flip_index rel_flip_index)\" \n \n have rel_set_rel_flip_index: \"rel_set rel_flip_index x y \\ index_flip_var_raw ` x = y\" for x y\n unfolding rel_set_def rel_flip_index_def by auto\n\n include lifting_syntax\n note bi_unique_rel_flip_index[transfer_rule]\n note bi_total_rel_flip_index[transfer_rule]\n note type_preserving_rel_flip_index[transfer_rule]\n\n have rel_fun_flip[simp]: \"(x ===> y)^--1 = (x^--1 ===> y^--1)\" for x :: \"'c\\'d\\bool\" and y :: \"'e\\'f\\bool\" \n unfolding rel_fun_def by auto\n\n have \"rel_expression rel_flip_index (=) e (index_flip_expression e)\" for e :: \"'c expression\"\n proof (unfold rel_expression.rep_eq index_flip_expression.rep_eq, cases \"Rep_expression e\", auto)\n fix vs f assume \"Rep_expression e = (vs,f)\"\n show \"rel_set rel_flip_index vs (index_flip_var_raw ` vs)\"\n by (rule rel_setI, unfold rel_flip_index_def, auto)\n show \"(rel_mem2 rel_flip_index ===> (=)) f (\\m. f (index_flip_mem2 m))\"\n apply (rule conversepD[of \"(rel_mem2 rel_flip_index ===> (=))\"])\n unfolding rel_fun_flip apply simp\n unfolding rel_fun_def rel_mem2.rep_eq rel_flip_index_def'\n unfolding rel_flip_index_def' apply transfer by auto\n qed\n then have [transfer_rule]: \"((=) ===> rel_expression rel_flip_index (=)) (%x. x) index_flip_expression\"\n unfolding rel_fun_def by auto\n\n have rel_flip_index_index_flip_var_raw: \"rel_flip_index v (index_flip_var_raw v)\" for v\n by (simp add: rel_flip_index_def)\n have rel_set_rel_flip_index_index_flip_var_raw: \"rel_set rel_flip_index vs (index_flip_var_raw ` vs)\" for vs\n by (subst rel_set_rel_flip_index, rule)\n have Fx: \"F x = (F \\ index_flip_mem2) y\" if \"rel_mem2 rel_flip_index x y\" for F::\"mem2\\'c\" and x y\n using that apply transfer apply (auto simp: rel_flip_index_def[abs_def])\n by (metis (full_types) rel_fun_def)\n then have inv_embedding_index_flip_mem2: \"(rel_mem2 rel_flip_index ===> (=)) (inv embedding \\ f) (inv embedding \\ (f \\ index_flip_mem2))\" for f\n apply (rule_tac rel_funI) by simp\n\n have \"rel_substitute1x rel_flip_index rel_flip_index s (index_flip_substitute1 s)\" for s\n unfolding rel_substitute1x_def \n using Fx\n by (metis (mono_tags, lifting) index_flip_var_raw_substitution1_footprint rel_flip_index_def rel_funI rel_set_rel_flip_index substitution1_function_index_flip substitution1_variable_index_flip)\n \n then have index_flip_substitute1_transfer [transfer_rule]:\n \"((=) ===> subR) (%x. x) index_flip_substitute1\"\n unfolding subR_def rel_fun_def by auto\n have \"index_flip_expression e = f\" if that[transfer_rule]: \"rel_expression rel_flip_index (=) e f\" for e f :: \"'c expression\"\n apply transfer by rule\n then have [transfer_rule]: \"(rel_expression rel_flip_index (=) ===> rel_expression (=) (=)) index_flip_expression id\"\n apply (rule_tac rel_funI) by (simp add: rel_expression_eq)\n\n have [transfer_rule]: \"(list_all2 subR ===> rel_expression rel_flip_index (=) ===> rel_expression rel_flip_index (=))\n subst_expression subst_expression\"\n unfolding subR_def\n by transfer_prover\n\n have \"(rel_expression (=) (=))\n (index_flip_expression (subst_expression \\ e))\n (id (subst_expression (map index_flip_substitute1 \\) (index_flip_expression e)))\"\n apply transfer_prover_start\n apply transfer_step+\n by simp\n then\n show \"index_flip_expression (subst_expression \\ e) = subst_expression (map index_flip_substitute1 \\) (index_flip_expression e)\"\n unfolding rel_expression_eq id_def by assumption\nqed\n\n\nsection \\ML code\\\n\nlemma expression_clean_assoc_aux: \\ \\Helper for ML function clean_expression_conv_varlist\\\n assumes \"expression (variable_concat Q (variable_concat R S)) (\\(q,(r,s)). e ((q,r),s)) \\ e'\"\n shows \"expression (variable_concat (variable_concat Q R) S) e \\ e'\"\n unfolding assms[symmetric]\n apply (rule eq_reflection)\n apply (subst Rep_expression_inject[symmetric])\n apply (simp add: expression.rep_eq)\n apply (rule ext)\n by simp\n\nlemma expression_clean_singleton_aux: \\ \\Helper for ML function clean_expression_conv_varlist\\\n shows \"expression \\x\\ e \\ expression \\x\\ e\"\n by simp\n\n\nlemma expression_clean_cons_unit_aux: \\ \\Helper for ML function clean_expression_conv_varlist\\\n assumes \"expression Q (\\q. e (q,())) \\ expression Q' e'\"\n shows \"expression (variable_concat Q variable_unit) e \\ expression Q' e'\"\n unfolding assms[symmetric]\n apply (rule eq_reflection)\n apply (subst Rep_expression_inject[symmetric])\n apply (simp add: expression.rep_eq)\n apply (rule ext)\n by simp\n\nlemma expression_clean_unit_cons_aux: \\ \\Helper for ML function clean_expression_conv_varlist\\\n assumes \"expression Q (\\q. e ((),q)) \\ expression Q' e'\"\n shows \"expression (variable_concat variable_unit Q) e \\ expression Q' e'\"\n unfolding assms[symmetric]\n apply (rule eq_reflection)\n apply (subst Rep_expression_inject[symmetric])\n apply (simp add: expression.rep_eq)\n apply (rule ext)\n by simp\n\nlemma expression_vars_inject: \"expression Q e = expression Q' e' \\ set (raw_variables Q) = set (raw_variables Q')\"\n by (metis expression.rep_eq prod.sel(1))\n\nlemma expression_clean_var_cons_aux: \\ \\Helper for ML function clean_expression_conv_varlist\\\n assumes \"expression Q (\\x. x) \\ expression Q' e'\"\n shows \"expression (variable_concat \\x\\ Q) (\\x. x) \\ expression (variable_concat \\x\\ Q') (\\(x,q). (x, e' q))\"\n apply (rule eq_reflection)\n apply (subst Rep_expression_inject[symmetric])\n apply (simp add: expression.rep_eq)\n using expression_vars_inject[OF assms[THEN meta_eq_to_obj_eq]] apply auto\n apply (rule ext)\n apply auto\n by (metis assms comp_apply expression.rep_eq prod.inject)\n\nlemma expression_clean_unit_aux: \\ \\Helper for ML function clean_expression_conv_varlist\\\n shows \"expression \\\\ e \\ expression \\\\ (\\_. e ())\"\n by simp\n\nlemma expression_id_comp_aux: \\ \\Helper for ML function clean_expression_conv_varlist\\\n assumes \"expression Q (\\x. x) \\ expression Q' g\"\n shows \"expression Q e \\ expression Q' (\\x. e (g x))\"\n apply (rule eq_reflection)\n using assms[THEN meta_eq_to_obj_eq] apply transfer\n by (auto simp add: o_def)\n\nlemma subst_expression_convert_substitute_vars_tac: \\ \\Helper for ML function subst_expression_tac\\\n assumes \"\\ = substitute_vars xs e\"\n assumes \"g = subst_expression \\ f\"\n shows \"g = subst_expression (substitute_vars xs e) f\"\n using assms by simp\n\nlemma substitute_vars_unit_tac: \\ \\Helper for ML function substitute_vars_tac\\\n shows \"[] = substitute_vars \\\\ e\"\n by (simp add: substitute_vars_unit)\n\nlemma substitute_vars_singleton_tac: \\ \\Helper for ML function substitute_vars_tac\\\n shows \"[substitute1 x e] = substitute_vars \\x\\ e\"\n by (simp add: substitute_vars_singleton)\n\nlemma substitute_vars_concat_tac: \\ \\Helper for ML function substitute_vars_tac\\\n assumes \"e1 = map_expression fst e\"\n assumes \"e2 = map_expression snd e\"\n assumes \"lQ = substitute_vars Q e1\"\n assumes \"lR = substitute_vars R e2\"\n assumes \"lQR = lR @ lQ\"\n shows \"lQR = substitute_vars (variable_concat Q R) e\"\n apply (subst substitute_vars_concat) unfolding assms by simp\n\nsection \"Orderings on expressions\"\n\ninstantiation expression :: (ord) ord begin\ndefinition \"less_eq_expression e f \\ expression_eval e \\ expression_eval f\"\ndefinition \"less_expression e f \\ expression_eval e \\ expression_eval f \\ \\ (expression_eval f \\ expression_eval e)\"\ninstance by intro_classes \nend\n\ninstantiation expression :: (preorder) preorder begin\ninstance apply intro_classes\n unfolding less_expression_def less_eq_expression_def \n using order_trans by auto\nend\n\n\nML_file \"expressions.ML\"\n\nsimproc_setup clean_expression (\"expression Q e\") = Expressions.clean_expression_simproc\n\nconsts \"expression_syntax\" :: \"'a \\ 'a expression\" (\"Expr[_]\")\nparse_translation \\[(\\<^const_syntax>\\expression_syntax\\, fn ctx => fn [e] => Expressions.term_to_expression_untyped ctx e)]\\\nhide_const expression_syntax\n\n(* TODO remove *)\nschematic_goal \"?x = substitute_vars \\var_z,var_x\\ Expr[x]\" and \"?x = xxx\"\napply (tactic \\Expressions.substitute_vars_tac \\<^context> 1\\)\nprint_theorems\n oops\n\nend\n","avg_line_length":54.5435073628,"max_line_length":273,"alphanum_fraction":0.7186211467} {"size":8836,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/n_g2kAbsAfter_lemma_on_inv__89.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_g2kAbsAfter Protocol Case Study*} \n\ntheory n_g2kAbsAfter_lemma_on_inv__89 imports n_g2kAbsAfter_base\nbegin\nsection{*All lemmas on causal relation between inv__89 and some rule r*}\nlemma n_n_RecvReq_i1Vsinv__89:\nassumes a1: \"(r=n_n_RecvReq_i1 )\" and\na2: \"(f=inv__89 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P3 s\"\n apply (cut_tac a1 a2 , simp, rule_tac x=\"(neg (andForm (eqn (IVar (Field (Ident ''AChan3_1'') ''Cmd'')) (Const InvAck)) (eqn (IVar (Ident ''CurCmd'')) (Const Empty))))\" in exI, auto) done\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_RecvInvAck_i1Vsinv__89:\nassumes a1: \"(r=n_n_RecvInvAck_i1 )\" and\na2: \"(f=inv__89 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nhave \"((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\\((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))\" by auto\n moreover {\n assume c1: \"((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 c1, simp, rule_tac x=\"(neg (andForm (andForm (eqn (IVar (Field (Ident ''Chan3_1'') ''Cmd'')) (Const InvAck)) (eqn (IVar (Ident ''CurCmd'')) (Const ReqS))) (eqn (IVar (Field (Ident ''AChan3_1'') ''Cmd'')) (Const InvAck))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n }\n moreover {\n assume c1: \"((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 c1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n }\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_n_SendGntS_i1Vsinv__89:\nassumes a1: \"(r=n_n_SendGntS_i1 )\" and\na2: \"(f=inv__89 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_SendGntE_i1Vsinv__89:\nassumes a1: \"(r=n_n_SendGntE_i1 )\" and\na2: \"(f=inv__89 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_ARecvReq_i1Vsinv__89:\nassumes a1: \"(r=n_n_ARecvReq_i1 )\" and\na2: \"(f=inv__89 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P3 s\"\n apply (cut_tac a1 a2 , simp, rule_tac x=\"(neg (andForm (eqn (IVar (Field (Ident ''AChan3_1'') ''Cmd'')) (Const InvAck)) (eqn (IVar (Ident ''CurCmd'')) (Const Empty))))\" in exI, auto) done\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_ASendInvAck_i1Vsinv__89:\nassumes a1: \"(r=n_n_ASendInvAck_i1 )\" and\na2: \"(f=inv__89 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P3 s\"\n apply (cut_tac a1 a2 , simp, rule_tac x=\"(neg (andForm (andForm (eqn (IVar (Field (Ident ''AChan2_1'') ''Cmd'')) (Const Inv)) (eqn (IVar (Ident ''CurCmd'')) (Const ReqS))) (eqn (IVar (Ident ''ExGntd'')) (Const false))))\" in exI, auto) done\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_ARecvInvAck_i1Vsinv__89:\nassumes a1: \"(r=n_n_ARecvInvAck_i1 )\" and\na2: \"(f=inv__89 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nhave \"((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\\((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))\" by auto\n moreover {\n assume c1: \"((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 c1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n }\n moreover {\n assume c1: \"((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 c1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n }\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_n_ASendGntS_i1Vsinv__89:\nassumes a1: \"(r=n_n_ASendGntS_i1 )\" and\na2: \"(f=inv__89 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_ASendGntE_i1Vsinv__89:\nassumes a1: \"(r=n_n_ASendGntE_i1 )\" and\na2: \"(f=inv__89 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_SendInvS_i1Vsinv__89:\n assumes a1: \"r=n_n_SendInvS_i1 \" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_SendReqEI_i1Vsinv__89:\n assumes a1: \"r=n_n_SendReqEI_i1 \" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendReqEI_i1Vsinv__89:\n assumes a1: \"r=n_n_ASendReqEI_i1 \" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendReqIS_j1Vsinv__89:\n assumes a1: \"r=n_n_ASendReqIS_j1 \" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendReqES_i1Vsinv__89:\n assumes a1: \"r=n_n_ASendReqES_i1 \" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ARecvGntE_i1Vsinv__89:\n assumes a1: \"r=n_n_ARecvGntE_i1 \" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ARecvGntS_i1Vsinv__89:\n assumes a1: \"r=n_n_ARecvGntS_i1 \" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendInvE_i1Vsinv__89:\n assumes a1: \"r=n_n_ASendInvE_i1 \" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendInvS_i1Vsinv__89:\n assumes a1: \"r=n_n_ASendInvS_i1 \" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_SendReqES_i1Vsinv__89:\n assumes a1: \"r=n_n_SendReqES_i1 \" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_SendInvE_i1Vsinv__89:\n assumes a1: \"r=n_n_SendInvE_i1 \" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendReqSE_j1Vsinv__89:\n assumes a1: \"r=n_n_ASendReqSE_j1 \" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_RecvGntS_i1Vsinv__89:\n assumes a1: \"r=n_n_RecvGntS_i1 \" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_SendReqEE_i1Vsinv__89:\n assumes a1: \"r=n_n_SendReqEE_i1 \" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_RecvGntE_i1Vsinv__89:\n assumes a1: \"r=n_n_RecvGntE_i1 \" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_Store_i1Vsinv__89:\n assumes a1: \"\\ d. d\\N\\r=n_n_Store_i1 d\" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_AStore_i1Vsinv__89:\n assumes a1: \"\\ d. d\\N\\r=n_n_AStore_i1 d\" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_SendReqS_j1Vsinv__89:\n assumes a1: \"r=n_n_SendReqS_j1 \" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_SendInvAck_i1Vsinv__89:\n assumes a1: \"r=n_n_SendInvAck_i1 \" and\n a2: \"(f=inv__89 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \nend\n","avg_line_length":34.515625,"max_line_length":267,"alphanum_fraction":0.6809642372} {"size":29397,"ext":"thy","lang":"Isabelle","max_stars_count":21.0,"content":"theory Definition_Utils\nimports \n Main\n \"Automatic_Refinement.Refine_Lib\" \n \"HOL-Library.Rewrite\"\nkeywords \n \"concrete_definition\" :: thy_decl\n and \"prepare_code_thms\" :: thy_decl\n and \"synth_definition\" :: thy_goal\n\nbegin\n\n declare [[ML_exception_debugger, ML_debugger, ML_exception_trace]]\n\ntext {*\n This theory provides a tool for extracting definitions from terms, and\n for generating code equations for recursion combinators.\n*}\n\n(*\n TODO: Copied and merged from $AFP\/Refine_Monadic\/Refine_Automation\n and isafol\/GRAT\/gratchk\/Synth_Definition\n\n TODO: Not properly localized \n \n \n TODO: Finally merge Definition_Utils and Synth_Definition structure. \n Use \\ instead of schematics for user interface!\n \n*)\n\nML_val \\Symtab.update_list\\\nML {*\nsignature DEFINITION_UTILS = sig\n type extraction = {\n pattern: term, (* Pattern to be defined as own constant *)\n gen_thm: thm, (* Code eq generator: [| c==rhs; ... |] ==> c == ... *)\n gen_tac: local_theory -> tactic' (* Solves remaining premises of gen_thm *)\n }\n\n val extract_as_def: (string * typ) list -> string -> term \n -> local_theory -> ((term * thm) * local_theory)\n\n (* Returns new_def_thm, code_thms, raw_def_thms *) \n val extract_recursion_eqs: extraction list -> string -> thm \n -> local_theory -> ((thm * thm list * thm list) * local_theory)\n \n (* Generate and register with names, code-theorems by specified attrib *) \n val extract_recursion_eqs': extraction list -> string -> Token.src list -> thm \n -> local_theory -> ((thm list) * local_theory)\n\n val declare_extraction_group: binding -> Context.generic -> string * Context.generic\n val add_extraction: xstring * Position.T -> extraction -> Context.generic -> Context.generic\n val check_extraction_group: Proof.context -> xstring * Position.T -> string\n val get_extraction_group: Proof.context -> string -> extraction list\n \n val prepare_code_thms_cmd: (xstring * Position.T) list -> Token.src list -> thm -> local_theory -> local_theory\n\n val sd_cmd: ((binding * Token.src list) * Token.src list) * string -> Proof.context -> Proof.state\n val sd_parser: Token.T list -> (((binding * Token.src list) * Token.src list) * string) * Token.T list\n \n \n val define_concrete_fun: extraction list option -> binding -> \n Token.src list -> indexname list -> thm ->\n cterm list -> local_theory -> (thm * thm) * local_theory\n \n val mk_qualified: string -> bstring -> binding\n\n (* Convert \\ to schematic variable *)\n val prepare_pattern: term -> term \n \n val prepare_cd_pattern: Proof.context -> cterm -> cterm\n val add_cd_pattern: cterm -> Context.generic -> Context.generic\n val del_cd_pattern: cterm -> Context.generic -> Context.generic\n val get_cd_patterns: Proof.context -> cterm list\n\n val add_vc_rec_thm: thm -> Context.generic -> Context.generic\n val del_vc_rec_thm: thm -> Context.generic -> Context.generic\n val get_vc_rec_thms: Proof.context -> thm list\n\n val add_vc_solve_thm: thm -> Context.generic -> Context.generic\n val del_vc_solve_thm: thm -> Context.generic -> Context.generic\n val get_vc_solve_thms: Proof.context -> thm list\n\n val vc_solve_tac: Proof.context -> bool -> tactic'\n val vc_solve_modifiers: Method.modifier parser list\n\n val setup: theory -> theory\nend\n\nstructure Definition_Utils :DEFINITION_UTILS = struct\n\n type extraction = {\n pattern: term, (* Pattern to be defined as own constant *)\n gen_thm: thm, (* Code eq generator: [| c==rhs; ... |] ==> c == ... *)\n gen_tac: local_theory -> tactic' (* Solves remaining premises of gen_thm *)\n }\n\n val eq_extraction = (op = o apply2 #pattern)\n \n structure extractions = Generic_Data (\n type T = extraction list Name_Space.table\n val empty = Name_Space.empty_table \"Fixed-Point Extractions\"\n val extend = I\n val merge = Name_Space.join_tables (fn _ => Library.merge eq_extraction)\n )\n\n fun declare_extraction_group binding context = let\n val table = extractions.get context\n val (name,table) = Name_Space.define context false (binding,[]) table\n val context = extractions.put table context\n in\n (name,context)\n end\n \n fun add_extraction namepos ex context = let\n fun f table = let\n val (key,_) = Name_Space.check context table namepos\n val table = Name_Space.map_table_entry key (Library.update eq_extraction ex) table\n in\n table\n end\n in\n extractions.map f context\n end\n \n fun check_extraction_group ctxt namepos = let\n val context = Context.Proof ctxt\n val table = extractions.get context\n val (key,_) = Name_Space.check context table namepos\n in\n key\n end\n \n fun get_extraction_group ctxt full_name = let\n val context = Context.Proof ctxt\n val table = extractions.get context\n val (_,exs) = Name_Space.check context table (full_name,Position.none)\n in \n exs\n end\n \n \n(* \n Context.theory_map (extractions.map (\n Symtab.update_list (op = o apply2 #pattern) (name,ex)))\n*) \n\n (*\n Define new constant name for subterm t in context bnd.\n Returns replacement for t using the new constant and definition \n theorem.\n *)\n fun extract_as_def bnd name t lthy = let\n val loose = rev (loose_bnos t);\n\n val nctx = Variable.names_of lthy\n val (name,nctx) = Name.variant name nctx (* TODO: Disambiguate name by appending serial_string() *)\n val name = name ^ serial_string()\n val (rnames,_) = fold_map (Name.variant o #1) bnd nctx\n \n (*val rnames = #1 (Variable.names_of lthy |> fold_map (Name.variant o #1) bnd);*)\n val rfrees = map (fn (name,(_,typ)) => Free (name,typ)) (rnames ~~ bnd);\n val t' = subst_bounds (rfrees,t);\n val params = map Bound (rev loose);\n \n val param_vars \n = (Library.foldl (fn (l,i) => nth rfrees i :: l) ([],loose));\n val param_types = map fastype_of param_vars;\n\n val def_t = Logic.mk_equals \n (list_comb (Free (name,param_types ---> fastype_of t'),param_vars),t')\n |> fold (Logic.all) param_vars \n\n (* TODO: Makarius says: Use Local_Theory.define here! *) \n val ((lhs_t,(_,def_thm)),lthy) \n = Specification.definition NONE [] [] (Binding.empty_atts,def_t) lthy;\n\n (*val _ = tracing \"xxxx\";*)\n val app_t = list_comb (lhs_t, params);\n in \n ((app_t,def_thm),lthy)\n end;\n\n\nfun mk_qualified basename q = Binding.qualify true basename (Binding.name q);\n\n\nlocal\n\n fun transform exs t lthy = let \n val pat_net : extraction Item_Net.T =\n Item_Net.init (op= o apply2 #pattern) (fn {pattern, ...} => [pattern])\n |> fold Item_Net.update exs\n\n val thy = Proof_Context.theory_of lthy\n \n fun tr env t ctx = let\n (* Recurse for subterms *)\n val (t,ctx) = case t of\n t1$t2 => let\n val (t1,ctx) = tr env t1 ctx\n val (t2,ctx) = tr env t2 ctx\n in \n (t1$t2,ctx)\n end\n | Abs (x,T,t) => let \n val (t',ctx) = tr ((x,T)::env) t ctx\n in (Abs (x,T,t'),ctx) end\n | _ => (t,ctx) \n\n (* Check if we match a pattern *)\n val ex = \n Item_Net.retrieve_matching pat_net t\n |> get_first (fn ex => \n case\n try (Pattern.first_order_match thy (#pattern ex,t)) \n (Vartab.empty,Vartab.empty)\n of NONE => NONE | SOME _ => SOME ex\n )\n in\n case ex of \n NONE => (t,ctx)\n | SOME ex => let\n (* Extract as new constant *)\n val (idx,defs,lthy) = ctx\n val name = (\"f_\" ^ string_of_int idx)\n val ((t,def_thm),lthy) = extract_as_def env name t lthy\n val ctx = (idx+1,(def_thm,ex)::defs,lthy)\n in\n (t,ctx)\n end\n end\n \n val (t,(_,defs,lthy)) = tr [] t (0,[],lthy)\n in \n ((t,defs),lthy)\n \n end\n\n fun simp_only_tac thms ctxt = simp_tac (put_simpset HOL_basic_ss ctxt addsimps thms)\n \nin\n\n\nfun extract_recursion_eqs [] _ def_thm lthy = ((def_thm,[],[]),lthy)\n | extract_recursion_eqs exs basename def_thm lthy = let\n \n val def_thm = Local_Defs.meta_rewrite_rule lthy def_thm\n\n (* Open local target *)\n val (_,lthy) = Local_Theory.open_target lthy \n val lthy = Local_Theory.map_background_naming (Name_Space.mandatory_path basename) lthy\n \n val (def_thm, lthy) = yield_singleton (apfst snd oo Variable.import true) def_thm lthy\n \n val rhs = Thm.rhs_of def_thm |> Thm.term_of\n \n (* Transform RHS, generating new constants *)\n val ((rhs',aux_defs),lthy) = transform exs rhs lthy;\n val aux_def_thms = map #1 aux_defs\n \n (* Prove equality *)\n val rhs_eq_thm = Goal.prove_internal \n lthy [] (Logic.mk_equals (rhs,rhs') |> Thm.cterm_of lthy)\n (K (ALLGOALS (simp_only_tac aux_def_thms lthy)))\n\n (* Generate new definition theorem *) \n val code_thm = Thm.transitive def_thm rhs_eq_thm \n \n (* Generate code equations *)\n fun mk_code_thm lthy (def_thm,{gen_thm, gen_tac, ...}) = let\n val ((_,def_thm),lthy') = yield_singleton2 \n (Variable.import true) def_thm lthy;\n val thm = def_thm RS gen_thm;\n val tac = SOLVED' (gen_tac lthy')\n ORELSE' (simp_only_tac aux_def_thms lthy' THEN' gen_tac lthy')\n (* TODO: The unfold auf_def_thms fallback is a dirty hack, to enable e.g., monotonicity proofs\n without proper mono-prover setup for the generated constants.\n \n A cleaner way would only generate constants along with mono-prover-setup!\n *)\n\n val thm = the (SINGLE (ALLGOALS tac) thm);\n val thm = singleton (Variable.export lthy' lthy) thm;\n in\n thm\n end;\n \n val aux_code_thms = map (mk_code_thm lthy) aux_defs;\n\n val _ = if forall Thm.no_prems aux_code_thms then () else \n warning \"Unresolved premises in code theorems\"\n \n (* Close Target *)\n val lthy1 = lthy\n val lthy = Local_Theory.close_target lthy\n\n (* Transfer Results *)\n val xfer = Local_Theory.standard_form lthy1 lthy Morphism.thm\n \n val code_thm = xfer code_thm\n val aux_code_thms = map xfer aux_code_thms\n val aux_def_thms = map xfer aux_def_thms\n \nin\n ((code_thm,aux_code_thms,aux_def_thms),lthy)\nend;\n\nend\n\n(*\nfun extract_recursion_eqs exs basename orig_def_thm lthy = let\n val thy = Proof_Context.theory_of lthy\n \n val pat_net : extraction Item_Net.T =\n Item_Net.init (op= o apply2 #pattern) (fn {pattern, ...} => [pattern])\n |> fold Item_Net.update exs\n\n local\n fun tr env t ctx = let\n (* Recurse for subterms *)\n val (t,ctx) = case t of\n t1$t2 => let\n val (t1,ctx) = tr env t1 ctx\n val (t2,ctx) = tr env t2 ctx\n in \n (t1$t2,ctx)\n end\n | Abs (x,T,t) => let \n val (t',ctx) = tr ((x,T)::env) t ctx\n in (Abs (x,T,t'),ctx) end\n | _ => (t,ctx) \n\n (* Check if we match a pattern *)\n val ex = \n Item_Net.retrieve_matching pat_net t\n |> get_first (fn ex => \n case\n try (Pattern.first_order_match thy (#pattern ex,t)) \n (Vartab.empty,Vartab.empty)\n of NONE => NONE | SOME _ => SOME ex\n )\n in\n case ex of \n NONE => (t,ctx)\n | SOME ex => let\n (* Extract as new constant *)\n val (idx,defs,lthy) = ctx\n val name = (basename ^ \"_\" ^ string_of_int idx)\n val ((t,def_thm),lthy) = extract_as_def env name t lthy\n val ctx = (idx+1,(def_thm,ex)::defs,lthy)\n in\n (t,ctx)\n end\n end\n in\n fun transform t lthy = let \n val (t,(_,defs,lthy)) = tr [] t (0,[],lthy)\n in \n ((t,defs),lthy)\n end\n end\n\n (* Import theorem and extract RHS *)\n \n (* val lthy0 = lthy *)\n val orig_def_thm = Local_Defs.meta_rewrite_rule lthy orig_def_thm\n val args = Thm.lhs_of orig_def_thm |> Thm.term_of |> Term.strip_comb |> snd |> take_suffix is_Var\n |> map (fst o fst o dest_Var)\n \n val orig_def_thm = Local_Defs.abs_def_rule lthy orig_def_thm\n \n val ((_,orig_def_thm'),lthy) = yield_singleton2 \n (Variable.importT) orig_def_thm lthy;\n val (lhs,rhs) = orig_def_thm' (*|> Local_Defs.meta_rewrite_rule lthy *) |> Thm.prop_of |> Logic.dest_equals;\n \n (* Transform RHS, generating new constants *)\n val ((rhs',defs),lthy) = transform rhs lthy;\n val def_thms = map #1 defs\n\n (* Obtain new def_thm *)\n val def_unfold_ss = \n put_simpset HOL_basic_ss lthy addsimps (orig_def_thm::def_thms)\n\n val _ = @{print} (orig_def_thm::def_thms)\n \n local \n val lthy0 = lthy\n val (argns,lthy) = Variable.variant_fixes args lthy\n \n val tys = fastype_of lhs |> binder_types |> take (length args)\n \n val args = map Free (argns ~~ tys)\n\n val lhs = list_comb (lhs,args)\n val rhs = list_comb (rhs',args)\n\n val new_def_ct = Logic.mk_equals (lhs,rhs) |> Thm.cterm_of lthy\n\n val _ = tracing \"Prove\"\n val new_def_thm = Goal.prove_internal lthy [] new_def_ct (K (simp_tac def_unfold_ss 1))\n val _ = tracing \"Done\"\n in \n val new_def_thm = singleton (Variable.export lthy lthy0) new_def_thm\n end\n \n \n (* \n val def_unfold_ss = \n put_simpset HOL_basic_ss lthy addsimps (orig_def_thm::def_thms)\n val new_def_thm = Goal.prove_internal lthy\n [] (Logic.mk_equals (lhs,rhs') |> Thm.cterm_of lthy) (K (simp_tac def_unfold_ss 1))\n *)\n\n (* Obtain new theorem by folding with defs of generated constants *)\n (* TODO: Maybe cleaner to generate eq-thm and prove by \"unfold, refl\" *)\n (*val new_def_thm \n = Library.foldr (fn (dt,t) => Local_Defs.fold lthy [dt] t) \n (def_thms,orig_def_thm');*)\n\n (* Prepare code equations *)\n fun mk_code_thm lthy (def_thm,{gen_thm, gen_tac, ...}) = let\n val ((_,def_thm),lthy') = yield_singleton2 \n (Variable.import true) def_thm lthy;\n val thm = def_thm RS gen_thm;\n val tac = SOLVED' (gen_tac lthy')\n ORELSE' (simp_tac def_unfold_ss THEN' gen_tac lthy')\n\n val thm = the (SINGLE (ALLGOALS tac) thm);\n val thm = singleton (Variable.export lthy' lthy) thm;\n in\n thm\n end;\n \n val code_thms = map (mk_code_thm lthy) defs;\n\n val _ = if forall Thm.no_prems code_thms then () else \n warning \"Unresolved premises in code theorems\"\n \nin\n ((new_def_thm,code_thms,def_thms),lthy)\nend;\n*)\n\nfun extract_recursion_eqs' exs basename attribs orig_def_thm lthy = let\n \n val ((new_def_thm,code_thms,def_thms),lthy) = extract_recursion_eqs exs basename orig_def_thm lthy\n\n (* Register definitions of generated constants *)\n val (_,lthy) \n = Local_Theory.note ((mk_qualified basename \"defs\",[]),def_thms) lthy;\n \n val code_thms = new_def_thm::code_thms\n \n val (_,lthy) = Local_Theory.note \n ((mk_qualified basename \"code\",attribs),code_thms)\n lthy;\nin\n (code_thms,lthy)\nend \n\nfun prepare_code_thms_cmd names attribs thm lthy = let\n fun name_of (Const (n,_)) = n \n | name_of (Free (n,_)) = n\n | name_of _ = raise (THM (\"No definitional theorem\",0,[thm]));\n\n val (lhs,_) = thm |> Local_Defs.meta_rewrite_rule lthy |> Thm.prop_of |> Logic.dest_equals;\n val basename = lhs |> strip_comb |> #1 \n |> name_of \n |> Long_Name.base_name;\n\n val exs_tab = extractions.get (Context.Proof lthy)\n \n val exs = map (Name_Space.check (Context.Proof lthy) exs_tab #> snd) names |> flat\n val exs = case exs of [] => Name_Space.dest_table exs_tab |> map snd |> flat | _ => exs\n\n val _ = case exs of [] => error \"No extraction patterns selected\" | _ => ()\n \n val (_,lthy) = extract_recursion_eqs' exs basename attribs thm lthy\n\nin\n lthy\nend;\n\n\nfun extract_concrete_fun _ [] concl = \n raise TERM (\"Conclusion does not match any extraction pattern\",[concl])\n | extract_concrete_fun thy (pat::pats) concl = (\n case Refine_Util.fo_matchp thy pat concl of\n NONE => extract_concrete_fun thy pats concl\n | SOME [t] => t\n | SOME (t::_) => (\n warning (\"concrete_definition: Pattern has multiple holes, taking \"\n ^ \"first one: \" ^ @{make_string} pat\n ); t)\n | _ => (warning (\"concrete_definition: Ignoring invalid pattern \" \n ^ @{make_string} pat);\n extract_concrete_fun thy pats concl)\n )\n\n\n(* Define concrete function from refinement lemma *)\nfun define_concrete_fun gen_code fun_name attribs_raw param_names thm pats\n (orig_lthy:local_theory) = \nlet\n val lthy = orig_lthy;\n val ((inst,thm'),lthy) = yield_singleton2 (Variable.import true) thm lthy;\n\n val concl = thm' |> Thm.concl_of\n\n (*val ((typ_subst,term_subst),lthy) \n = Variable.import_inst true [concl] lthy;\n val concl = Term_Subst.instantiate (typ_subst,term_subst) concl;\n *)\n\n val term_subst = #2 inst |> map (apsnd Thm.term_of) \n\n val param_terms = map (fn name =>\n case AList.lookup (fn (n,v) => n = #1 v) term_subst name of\n NONE => raise TERM (\"No such variable: \"\n ^Term.string_of_vname name,[concl])\n | SOME t => t\n ) param_names;\n\n (* \n val _ = Syntax.pretty_term lthy concl |> Pretty.writeln\n val _ = Pretty.big_list \"Patterns\" (map (Syntax.pretty_term lthy o Thm.term_of) pats) |> Pretty.writeln\n *)\n \n val f_term = extract_concrete_fun (Proof_Context.theory_of lthy) pats concl;\n\n val lhs_type = map Term.fastype_of param_terms ---> Term.fastype_of f_term;\n val lhs_term \n = list_comb ((Free (Binding.name_of fun_name,lhs_type)),param_terms);\n val def_term = Logic.mk_equals (lhs_term,f_term) \n |> fold Logic.all param_terms;\n\n val attribs = map (Attrib.check_src lthy) attribs_raw;\n\n val ((_,(_,def_thm)),lthy) = Specification.definition \n (SOME (fun_name,NONE,Mixfix.NoSyn)) [] [] ((Binding.empty,attribs),def_term) lthy;\n\n val folded_thm = Local_Defs.fold lthy [def_thm] thm';\n\n val basename = Binding.name_of fun_name\n \n val (_,lthy) \n = Local_Theory.note \n ((mk_qualified (basename) \"refine\",[]),[folded_thm]) \n lthy;\n\n val lthy = case gen_code of\n NONE => lthy\n | SOME modes => let\n val (_,lthy) = extract_recursion_eqs' modes (Binding.name_of fun_name) @{attributes [code]} def_thm lthy\n in\n lthy\n end\n \n \nin\n ((def_thm,folded_thm),lthy)\nend;\n\n fun prepare_pattern t = let\n val nidx = maxidx_of_term t + 1\n \n val t_orig = t\n \n val t = map_aterms (fn \n @{mpat (typs) \"\\::?'v_T\"} => Var ((\"HOLE\",nidx),T)\n | v as Var ((name,_),T) => if String.isPrefix \"_\" name then v else Var ((\"_\"^name,nidx),T)\n | t => t\n ) t\n |> Term_Subst.zero_var_indexes\n \n fun is_hole (Var ((n,_),_)) = not (String.isPrefix \"_\" n)\n | is_hole _ = false\n \n val num_holes = fold_aterms (fn t => is_hole t ? (curry op + 1)) t 0 \n \n val _ = num_holes = 1 orelse raise TERM(\"cd-pattern has multiple or no holes\",[t_orig,t])\n in\n t\n end\n\n\n (*val cfg_prep_code = Attrib.setup_config_bool @{binding synth_definition_prep_code} (K false)*)\n local \n open Refine_Util\n (*val flags = parse_bool_config' \"prep_code\" cfg_prep_code\n val parse_flags = parse_paren_list' flags *)\n\n in \n val sd_parser = (*parse_flags --*) Parse.binding -- Parse.opt_attribs --| @{keyword \"is\"} \n -- Scan.optional (Parse.attribs --| Parse.$$$ \":\") [] -- Parse.term \n end \n\n\n fun sd_cmd (((name,attribs_raw),attribs2_raw),t_raw) lthy = let\n local\n (*val ctxt = Refine_Util.apply_configs flags lthy*)\n in\n (*val flag_prep_code = Config.get ctxt cfg_prep_code*)\n end\n\n val read = Syntax.read_prop (Proof_Context.set_mode Proof_Context.mode_pattern lthy)\n \n val t = t_raw |> read |> prepare_pattern\n val ctxt = Variable.declare_term t lthy\n val pat= Thm.cterm_of ctxt t\n val goal=t\n\n val attribs2 = map (Attrib.check_src lthy) attribs2_raw;\n \n \n fun \n after_qed [[thm]] ctxt = let\n val thm = singleton (Variable.export ctxt lthy) thm\n\n val (_,lthy) \n = Local_Theory.note \n ((mk_qualified (Binding.name_of name) \"refine_raw\",[]),[thm]) \n lthy;\n\n val ((dthm,rthm),lthy) = define_concrete_fun NONE name attribs_raw [] thm [pat] lthy\n\n val (_,lthy) = Local_Theory.note ((Binding.empty,attribs2),[rthm]) lthy\n \n (* FIXME: Does not work, as we cannot see the default extraction patterns!\n val lthy = lthy \n |> flag_prep_code ? Refine_Automation.extract_recursion_eqs \n [Sepref_Extraction.heap_extraction] (Binding.name_of name) dthm\n *)\n\n val _ = Thm.pretty_thm lthy dthm |> Pretty.string_of |> writeln\n val _ = Thm.pretty_thm lthy rthm |> Pretty.string_of |> writeln\n in\n lthy\n end\n | after_qed thmss _ = raise THM (\"After-qed: Wrong thmss structure\",~1,flat thmss)\n\n in\n Proof.theorem NONE after_qed [[ (goal,[]) ]] ctxt\n end\n\n \n \n \n\n val cd_pat_eq = apply2 (Thm.term_of #> Refine_Util.anorm_term) #> op aconv\n\n structure cd_patterns = Generic_Data (\n type T = cterm list\n val empty = []\n val extend = I\n val merge = merge cd_pat_eq\n ) \n\n fun prepare_cd_pattern ctxt pat = \n case Thm.term_of pat |> fastype_of of\n @{typ bool} => \n Thm.term_of pat \n |> HOLogic.mk_Trueprop \n |> Thm.cterm_of ctxt\n | _ => pat\n\n fun add_cd_pattern pat context = \n cd_patterns.map (insert cd_pat_eq (prepare_cd_pattern (Context.proof_of context) pat)) context\n\n fun del_cd_pattern pat context = \n cd_patterns.map (remove cd_pat_eq (prepare_cd_pattern (Context.proof_of context) pat)) context\n\n val get_cd_patterns = cd_patterns.get o Context.Proof\n\n\n structure rec_thms = Named_Thms ( \n val name = @{binding vcs_rec}\n val description = \"VC-Solver: Recursive intro rules\"\n )\n\n structure solve_thms = Named_Thms ( \n val name = @{binding vcs_solve}\n val description = \"VC-Solver: Solve rules\"\n )\n\n val add_vc_rec_thm = rec_thms.add_thm\n val del_vc_rec_thm = rec_thms.del_thm\n val get_vc_rec_thms = rec_thms.get\n\n val add_vc_solve_thm = solve_thms.add_thm\n val del_vc_solve_thm = solve_thms.del_thm\n val get_vc_solve_thms = solve_thms.get\n\n val rec_modifiers = [\n Args.$$$ \"rec\" -- Scan.option Args.add -- Args.colon \n >> K (Method.modifier rec_thms.add \\<^here>),\n Args.$$$ \"rec\" -- Scan.option Args.del -- Args.colon \n >> K (Method.modifier rec_thms.del \\<^here>)\n ];\n\n val solve_modifiers = [\n Args.$$$ \"solve\" -- Scan.option Args.add -- Args.colon \n >> K (Method.modifier solve_thms.add \\<^here>),\n Args.$$$ \"solve\" -- Scan.option Args.del -- Args.colon \n >> K (Method.modifier solve_thms.del \\<^here>)\n ];\n\n val vc_solve_modifiers = \n clasimp_modifiers @ rec_modifiers @ solve_modifiers;\n\n fun vc_solve_tac ctxt no_pre = let\n val rthms = rec_thms.get ctxt\n val sthms = solve_thms.get ctxt\n val pre_tac = if no_pre then K all_tac else clarsimp_tac ctxt\n val tac = SELECT_GOAL (auto_tac ctxt)\n in\n TRY o pre_tac\n THEN_ALL_NEW_FWD (TRY o REPEAT_ALL_NEW_FWD (resolve_tac ctxt rthms))\n THEN_ALL_NEW_FWD (TRY o SOLVED' (resolve_tac ctxt sthms THEN_ALL_NEW_FWD tac))\n end\n\n val setup = I\n #> rec_thms.setup \n #> solve_thms.setup\n\n\nend;\n*}\n\nsetup Definition_Utils.setup\n\n\nsetup {*\n let\n fun parse_cpat cxt = let \n val (t, (context, tks)) = Scan.lift Args.embedded_inner_syntax cxt \n val ctxt = Context.proof_of context\n val t = Proof_Context.read_term_pattern ctxt t\n |> Definition_Utils.prepare_pattern\n in\n (Thm.cterm_of ctxt t, (context, tks))\n end\n\n fun do_p f = Scan.repeat1 parse_cpat >> (fn pats => \n Thm.declaration_attribute (K (fold f pats)))\n in\n Attrib.setup @{binding \"cd_patterns\"} (\n Scan.lift Args.add |-- do_p Definition_Utils.add_cd_pattern\n || Scan.lift Args.del |-- do_p Definition_Utils.del_cd_pattern\n || do_p Definition_Utils.add_cd_pattern\n )\n \"Add\/delete concrete_definition pattern\"\n end\n*}\n\n(* Command setup *)\n\n(* TODO: Folding of .refine-lemma seems not to work, if the function has\n parameters on which it does not depend *)\n\nML {* Outer_Syntax.local_theory \n @{command_keyword concrete_definition} \n \"Define constant from theorem\"\n (Parse.binding \n -- Parse.opt_attribs\n -- Scan.optional (@{keyword \"for\"} |-- Scan.repeat1 Args.var) []\n --| @{keyword \"is\"} -- Parse.thm\n -- Scan.optional (@{keyword \"uses\"} |-- Scan.repeat1 Args.embedded_inner_syntax) []\n >> (fn ((((name,attribs),params),raw_thm),pats) => fn lthy => let\n val thm = \n case Attrib.eval_thms lthy [raw_thm] of\n [thm] => thm\n | _ => error \"Expecting exactly one theorem\";\n val pats = case pats of \n [] => Definition_Utils.get_cd_patterns lthy\n | l => map (Proof_Context.read_term_pattern lthy #> Definition_Utils.prepare_pattern #> Thm.cterm_of lthy #>\n Definition_Utils.prepare_cd_pattern lthy) l\n\n in \n Definition_Utils.define_concrete_fun \n NONE name attribs params thm pats lthy \n |> snd\n end))\n*}\n\ntext {* \n Command: \n @{text \"concrete_definition name [attribs] for params uses thm is patterns\"}\n where @{text \"attribs\"}, @{text \"for\"}, and @{text \"is\"}-parts are optional.\n\n Declares a new constant @{text \"name\"} by matching the theorem @{text \"thm\"} \n against a pattern.\n \n If the @{text \"for\"} clause is given, it lists variables in the theorem, \n and thus determines the order of parameters of the defined constant. Otherwise,\n parameters will be in order of occurrence.\n\n If the @{text \"is\"} clause is given, it lists patterns. The conclusion of the\n theorem will be matched against each of these patterns. For the first matching\n pattern, the constant will be declared to be the term that matches the first\n non-dummy variable of the pattern. If no @{text \"is\"}-clause is specified,\n the default patterns will be tried.\n\n Attribute: @{text \"cd_patterns pats\"}. Declaration attribute. Declares\n default patterns for the @{text \"concrete_definition\"} command.\n \n*}\n\ndeclare [[ cd_patterns \"_ = \\\" \"_ == \\\" ]]\n\nML_val \\Parse.binding\\\n\nML_val \\val x:binding = Binding.empty\\\n\nML_val \\@{binding foo}\\\n\nML {* \n let\n val modes = (Scan.optional\n (@{keyword \"(\"} |-- Parse.list1 (Parse.position Args.name) --| @{keyword \")\"}) [])\n in\n Outer_Syntax.local_theory \n @{command_keyword prepare_code_thms} \n \"Extract recursive code equations from definition theorem with fixed points\"\n (modes -- Parse.opt_attribs -- Parse.thms1\n >> (fn ((modes,attribs),raw_thms) => fn lthy => let\n val attribs = map (Attrib.check_src lthy) attribs\n val thms = Attrib.eval_thms lthy raw_thms\n in\n fold (Definition_Utils.prepare_code_thms_cmd modes attribs) thms lthy\n end)\n )\n end\n*}\n\ntext {* \n Command: \n @{text \"prepare_code_thms (modes) thm\"}\n where the @{text \"(mode)\"}-part is optional.\n\n Set up code-equations for recursions in constant defined by @{text \"thm\"}.\n The optional @{text \"modes\"} is a comma-separated list of extraction modes.\n*}\n\ntext \\Example setup for option monad fixed points\\\n\nlemma gen_code_thm_option_fixp:\n fixes x\n assumes D: \"f \\ option.fixp_fun B\"\n assumes M: \"(\\x. option.mono_body (\\f. B f x))\"\n shows \"f x \\ B f x\"\n unfolding D\n apply (subst option.mono_body_fixp)\n by (rule M)\n\nML_val \\\n Definition_Utils.add_extraction (\"option\",\\<^here>) {\n pattern = Logic.varify_global @{term \"option.fixp_fun x\"},\n gen_thm = @{thm gen_code_thm_option_fixp},\n gen_tac = Partial_Function.mono_tac\n }\n\\\n \ndeclaration \\K (Definition_Utils.declare_extraction_group @{binding option} #> snd)\\\n \ndeclaration {* fn _ =>\n Definition_Utils.add_extraction (\"option\",\\<^here>) {\n pattern = Logic.varify_global @{term \"option.fixp_fun x\"},\n gen_thm = @{thm gen_code_thm_option_fixp},\n gen_tac = Partial_Function.mono_tac\n }\n*}\n\n definition \"option_fixp_extraction_test m n = option.fixp_fun (\\D x. \n if x\\(0::int) then \n Some 0 \n else \n Option.bind (D (x-int m)) (\\a.\n Option.bind (D (x-n)) (\\b.\n Some (a+b)\n )))\"\n\n prepare_code_thms (option) [code] option_fixp_extraction_test_def\n print_theorems\n export_code option_fixp_extraction_test in SML\n\nML \\\nval _ = Theory.setup\n (ML_Antiquotation.inline \\<^binding>\\extraction_group\\\n (Args.context -- Scan.lift (Parse.position Args.embedded) >>\n (fn (ctxt, name) => ML_Syntax.print_string (Definition_Utils.check_extraction_group ctxt name))));\n\\ \n\ntext {* \n Command: \n @{text \"synth_definition binding [def_attrs] is [ref_attrs]: term\"}\n where the @{text \"(def_attrs)\"} and @{text \"(ref_attrs)\"} parts are optional.\n\n Sets up a schematic goal with a hole, proves the schematic goal, and \n define what has been inserted into the hole as a new constant. \n Moreover, generate a refinement theorem for the proved goal with the hole replaced by \n the defined constant.\n \n The \\def_attrs\\ are applied to the definition theorem, the \\ref_attrs\\ to \n the refinement theorem.\n*}\n \n \nML \\\n local open Definition_Utils in\n val _ = Outer_Syntax.local_theory_to_proof @{command_keyword \"synth_definition\"}\n \"Synthesis of constant from schematic goal with hole\"\n (sd_parser >> sd_cmd)\n \n end\n\\\n \nend\n","avg_line_length":31.9185667752,"max_line_length":113,"alphanum_fraction":0.6495220601} {"size":18060,"ext":"thy","lang":"Isabelle","max_stars_count":11.0,"content":"(* \n This file is a part of IsarMathLib - \n a library of formalized mathematics written for Isabelle\/Isar.\n\n Copyright (C) 2013 Daniel de la Concepcion\n\n This program is free software; Redistribution and use in source and binary forms, \n with or without modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice, \n this list of conditions and the following disclaimer.\n 2. Redistributions in binary form must reproduce the above copyright notice, \n this list of conditions and the following disclaimer in the documentation and\/or \n other materials provided with the distribution.\n 3. The name of the author may not be used to endorse or promote products \n derived from this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED \nWARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF \nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \nIN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, \nPROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; \nOR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \nWHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR \nOTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, \nEVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *)\n\nsection \\Topological groups 2\\\n\ntheory TopologicalGroup_ZF_2 imports Topology_ZF_8 TopologicalGroup_ZF Group_ZF_2\nbegin\n\ntext\\This theory deals with quotient topological groups.\\\n\nsubsection\\Quotients of topological groups\\\n\ntext\\The quotient topology given by the quotient group equivalent relation, has\nan open quotient map.\\\n\ntheorem(in topgroup) quotient_map_topgroup_open:\n assumes \"IsAsubgroup(H,f)\" \"A\\T\"\n defines \"r \\ QuotientGroupRel(G,f,H)\"\n shows \"{\\b,r``{b}\\. b\\\\T}``A\\(T{quotient by}r)\"\nproof-\n have eqT:\"equiv(\\T,r)\" and eqG:\"equiv(G,r)\" using group0.Group_ZF_2_4_L3 assms(1) unfolding r_def IsAnormalSubgroup_def\n using group0_valid_in_tgroup by auto\n have subA:\"A\\G\" using assms(2) by auto\n have subH:\"H\\G\" using group0.group0_3_L2[OF group0_valid_in_tgroup assms(1)].\n have A1:\"{\\b,r``{b}\\. b\\\\T}-``({\\b,r``{b}\\. b\\\\T}``A)=H\\A\"\n proof\n {\n fix t assume \"t\\{\\b,r``{b}\\. b\\\\T}-``({\\b,r``{b}\\. b\\\\T}``A)\"\n then have \"\\m\\({\\b,r``{b}\\. b\\\\T}``A). \\t,m\\\\{\\b,r``{b}\\. b\\\\T}\" using vimage_iff by auto\n then obtain m where \"m\\({\\b,r``{b}\\. b\\\\T}``A)\"\"\\t,m\\\\{\\b,r``{b}\\. b\\\\T}\" by auto\n then obtain b where \"b\\A\"\"\\b,m\\\\{\\b,r``{b}\\. b\\\\T}\"\"t\\G\" and rel:\"r``{t}=m\" using image_iff by auto\n then have \"r``{b}=m\" by auto\n then have \"r``{t}=r``{b}\" using rel by auto\n with \\b\\A\\subA have \"\\t,b\\\\r\" using eq_equiv_class[OF _ eqT] by auto\n then have \"f`\\t,GroupInv(G,f)`b\\\\H\" unfolding r_def QuotientGroupRel_def by auto\n then obtain h where \"h\\H\" and prd:\"f`\\t,GroupInv(G,f)`b\\=h\" by auto\n then have \"h\\G\" using subH by auto\n have \"b\\G\" using \\b\\A\\\\A\\T\\ by auto\n then have \"(\\b)\\G\" using neg_in_tgroup by auto\n from prd have \"h=t\\(\\b)\" by simp\n with \\t\\G\\ \\b\\G\\ have \"t = h\\b\" using inv_cancel_two_add(1) by simp \n then have \"\\\\h,b\\,t\\\\f\" using apply_Pair[OF topgroup_f_binop] \\h\\G\\\\b\\G\\ by auto \n moreover from \\h\\H\\\\b\\A\\ have \"\\h,b\\\\H\\A\" by auto\n ultimately have \"t\\f``(H\\A)\" using image_iff by auto\n with subA subH have \"t\\H\\A\" using interval_add(2) by auto\n }\n then show \"({\\b,r``{b}\\. b\\\\T}-``({\\b,r``{b}\\. b\\\\T}``A))\\H\\A\" by force\n {\n fix t assume \"t\\H\\A\"\n with subA subH have \"t \\ f``(H\\A)\" using interval_add(2) by auto\n then obtain ha where \"ha\\H\\A\" \"\\ha,t\\\\f\" using image_iff by auto\n then obtain h aa where \"ha=\\h,aa\\\"\"h\\H\"\"aa\\A\" by auto\n then have \"h\\G\"\"aa\\G\" using subH subA by auto\n from \\\\ha,t\\\\f\\ have \"t\\G\" using topgroup_f_binop unfolding Pi_def by auto\n from \\ha=\\h,aa\\\\ \\\\ha,t\\\\f\\ have \"t=h\\aa\" using apply_equality topgroup_f_binop \n by auto \n with \\h\\G\\ \\aa\\G\\ have \"t\\(\\aa) = h\" using inv_cancel_two_add(2) by simp\n with \\h\\H\\\\t\\G\\\\aa\\G\\ have \"\\t,aa\\\\r\" unfolding r_def QuotientGroupRel_def by auto\n then have \"r``{t}=r``{aa}\" using eqT equiv_class_eq by auto\n with \\aa\\G\\ have \"\\aa,r``{t}\\\\{\\b,r``{b}\\. b\\\\T}\" by auto\n with \\aa\\A\\ have A1:\"r``{t}\\({\\b,r``{b}\\. b\\\\T}``A)\" using image_iff by auto\n from \\t\\G\\ have \"\\t,r``{t}\\\\{\\b,r``{b}\\. b\\\\T}\" by auto\n with A1 have \"t\\{\\b,r``{b}\\. b\\\\T}-``({\\b,r``{b}\\. b\\\\T}``A)\" using vimage_iff by auto\n }\n then show \"H\\A\\{\\b,r``{b}\\. b\\\\T}-``({\\b,r``{b}\\. b\\\\T}``A)\" by auto\n qed\n have \"H\\A=(\\x\\H. x \\ A)\" using interval_add(3) subH subA by auto moreover\n have \"\\x\\H. x \\ A\\T\" using open_tr_open(1) assms(2) subH by blast\n then have \"{x \\ A. x\\H}\\T\" by auto\n then have \"(\\x\\H. x \\ A)\\T\" using topSpaceAssum unfolding IsATopology_def by auto\n ultimately have \"H\\A\\T\" by auto\n with A1 have \"{\\b,r``{b}\\. b\\\\T}-``({\\b,r``{b}\\. b\\\\T}``A)\\T\" by auto\n then have \"({\\b,r``{b}\\. b\\\\T}``A)\\{quotient topology in}((\\T)\/\/r){by}{\\b,r``{b}\\. b\\\\T}{from}T\"\n using QuotientTop_def topSpaceAssum quotient_proj_surj using \n func1_1_L6(2)[OF quotient_proj_fun] by auto\n then show \"({\\b,r``{b}\\. b\\\\T}``A)\\(T{quotient by}r)\" using EquivQuo_def[OF eqT] by auto\nqed \n \n\ntext\\A quotient of a topological group is just a quotient group with an appropiate\n topology that makes product and inverse continuous.\\\n\ntheorem (in topgroup) quotient_top_group_F_cont:\n assumes \"IsAnormalSubgroup(G,f,H)\"\n defines \"r \\ QuotientGroupRel(G,f,H)\"\n defines \"F \\ QuotientGroupOp(G,f,H)\"\n shows \"IsContinuous(ProductTopology(T{quotient by}r,T{quotient by}r),T{quotient by}r,F)\"\nproof-\n have eqT:\"equiv(\\T,r)\" and eqG:\"equiv(G,r)\" using group0.Group_ZF_2_4_L3 assms(1) unfolding r_def IsAnormalSubgroup_def\n using group0_valid_in_tgroup by auto\n have fun:\"{\\\\b,c\\,\\r``{b},r``{c}\\\\. \\b,c\\\\\\T\\\\T}:G\\G\\(G\/\/r)\\(G\/\/r)\" using product_equiv_rel_fun unfolding G_def by auto \n have C:\"Congruent2(r,f)\" using Group_ZF_2_4_L5A[OF Ggroup assms(1)] unfolding r_def.\n with eqT have \"IsContinuous(ProductTopology(T,T),ProductTopology(T{quotient by}r,T{quotient by}r),{\\\\b,c\\,\\r``{b},r``{c}\\\\. \\b,c\\\\\\T\\\\T})\"\n using product_quo_fun by auto\n have tprod:\"topology0(ProductTopology(T,T))\" unfolding topology0_def using Top_1_4_T1(1)[OF topSpaceAssum topSpaceAssum].\n have Hfun:\"{\\\\b,c\\,\\r``{b},r``{c}\\\\. \\b,c\\\\\\T\\\\T}\\surj(\\ProductTopology(T,T),\\(({quotient topology in}(((\\T)\/\/r)\\((\\T)\/\/r)){by}{\\\\b,c\\,\\r``{b},r``{c}\\\\. \\b,c\\\\\\T\\\\T}{from}(ProductTopology(T,T)))))\" using prod_equiv_rel_surj\n total_quo_equi[OF eqT] topology0.total_quo_func[OF tprod prod_equiv_rel_surj] unfolding F_def QuotientGroupOp_def r_def\n by auto\n have Ffun:\"F:\\(({quotient topology in}(((\\T)\/\/r)\\((\\T)\/\/r)){by}{\\\\b,c\\,\\r``{b},r``{c}\\\\. \\b,c\\\\\\T\\\\T}{from}(ProductTopology(T,T))))\\\\(T{quotient by}r)\"\n using EquivClass_1_T1[OF eqG C] using total_quo_equi[OF eqT] topology0.total_quo_func[OF tprod prod_equiv_rel_surj] unfolding F_def QuotientGroupOp_def r_def\n by auto\n have cc:\"(F O {\\\\b,c\\,\\r``{b},r``{c}\\\\. \\b,c\\\\\\T\\\\T}):G\\G\\G\/\/r\" using comp_fun[OF fun EquivClass_1_T1[OF eqG C]]\n unfolding F_def QuotientGroupOp_def r_def by auto\n then have \"(F O {\\\\b,c\\,\\r``{b},r``{c}\\\\. \\b,c\\\\\\T\\\\T}):\\(ProductTopology(T,T))\\\\(T{quotient by}r)\" using Top_1_4_T1(3)[OF topSpaceAssum topSpaceAssum]\n total_quo_equi[OF eqT] by auto\n then have two:\"two_top_spaces0(ProductTopology(T,T),T{quotient by}r,(F O {\\\\b,c\\,\\r``{b},r``{c}\\\\. \\b,c\\\\\\T\\\\T}))\" unfolding two_top_spaces0_def\n using Top_1_4_T1(1)[OF topSpaceAssum topSpaceAssum] equiv_quo_is_top[OF eqT] by auto\n have \"IsContinuous(ProductTopology(T,T),T,f)\" using fcon prodtop_def by auto moreover\n have \"IsContinuous(T,T{quotient by}r,{\\b,r``{b}\\. b\\\\T})\" using quotient_func_cont[OF quotient_proj_surj]\n unfolding EquivQuo_def[OF eqT] by auto\n ultimately have cont:\"IsContinuous(ProductTopology(T,T),T{quotient by}r,{\\b,r``{b}\\. b\\\\T} O f)\"\n using comp_cont by auto\n {\n fix A assume A:\"A\\G\\G\"\n then obtain g1 g2 where A_def:\"A=\\g1,g2\\\" \"g1\\G\"\"g2\\G\" by auto\n then have \"f`A=g1\\g2\" and p:\"g1\\g2\\\\T\" unfolding grop_def using \n apply_type[OF topgroup_f_binop] by auto\n then have \"{\\b,r``{b}\\. b\\\\T}`(f`A)={\\b,r``{b}\\. b\\\\T}`(g1\\g2)\" by auto\n with p have \"{\\b,r``{b}\\. b\\\\T}`(f`A)=r``{g1\\g2}\" using apply_equality[OF _ quotient_proj_fun]\n by auto\n then have Pr1:\"({\\b,r``{b}\\. b\\\\T} O f)`A=r``{g1\\g2}\" using comp_fun_apply[OF topgroup_f_binop A] by auto\n from A_def(2,3) have \"\\g1,g2\\\\\\T\\\\T\" by auto\n then have \"\\\\g1,g2\\,\\r``{g1},r``{g2}\\\\\\{\\\\b,c\\,\\r``{b},r``{c}\\\\. \\b,c\\\\\\T\\\\T}\" by auto\n then have \"{\\\\b,c\\,\\r``{b},r``{c}\\\\. \\b,c\\\\\\T\\\\T}`A=\\r``{g1},r``{g2}\\\" using A_def(1) apply_equality[OF _ product_equiv_rel_fun]\n by auto\n then have \"F`({\\\\b,c\\,\\r``{b},r``{c}\\\\. \\b,c\\\\\\T\\\\T}`A)=F`\\r``{g1},r``{g2}\\\" by auto\n then have \"F`({\\\\b,c\\,\\r``{b},r``{c}\\\\. \\b,c\\\\\\T\\\\T}`A)=r``({g1\\g2})\" using group0.Group_ZF_2_2_L2[OF group0_valid_in_tgroup eqG C\n _ A_def(2,3)] unfolding F_def QuotientGroupOp_def r_def by auto moreover\n note fun ultimately have \"(F O {\\\\b,c\\,\\r``{b},r``{c}\\\\. \\b,c\\\\\\T\\\\T})`A=r``({g1\\g2})\" using comp_fun_apply[OF _ A] by auto\n then have \"(F O {\\\\b,c\\,\\r``{b},r``{c}\\\\. \\b,c\\\\\\T\\\\T})`A=({\\b,r``{b}\\. b\\\\T} O f)`A\" using Pr1 by auto\n }\n then have \"(F O {\\\\b,c\\,\\r``{b},r``{c}\\\\. \\b,c\\\\\\T\\\\T})=({\\b,r``{b}\\. b\\\\T} O f)\" using fun_extension[OF cc comp_fun[OF topgroup_f_binop quotient_proj_fun]]\n unfolding F_def QuotientGroupOp_def r_def by auto\n then have A:\"IsContinuous(ProductTopology(T,T),T{quotient by}r,F O {\\\\b,c\\,\\r``{b},r``{c}\\\\. \\b,c\\\\\\T\\\\T})\" using cont by auto\n have \"IsAsubgroup(H,f)\" using assms(1) unfolding IsAnormalSubgroup_def by auto\n then have \"\\A\\T. {\\b, r `` {b}\\ . b \\ \\T} `` A \\ ({quotient by}r)\" using quotient_map_topgroup_open unfolding r_def by auto\n with eqT have \"ProductTopology({quotient by}r,{quotient by}r)=({quotient topology in}(((\\T)\/\/r)\\((\\T)\/\/r)){by}{\\\\b,c\\,\\r``{b},r``{c}\\\\. \\b,c\\\\\\T\\\\T}{from}(ProductTopology(T,T)))\" using prod_quotient\n by auto\n with A show \"IsContinuous(ProductTopology(T{quotient by}r,T{quotient by}r),T{quotient by}r,F)\"\n using two_top_spaces0.cont_quotient_top[OF two Hfun Ffun] topology0.total_quo_func[OF tprod prod_equiv_rel_surj] unfolding F_def QuotientGroupOp_def r_def\n by auto\nqed\n\nlemma (in group0) Group_ZF_2_4_L8: \n assumes \"IsAnormalSubgroup(G,P,H)\" \n defines \"r \\ QuotientGroupRel(G,P,H)\" \n and \"F \\ QuotientGroupOp(G,P,H)\"\n shows \"GroupInv(G\/\/r,F):G\/\/r\\G\/\/r\"\n using group0_2_T2[OF Group_ZF_2_4_T1[OF _ assms(1)]] groupAssum using assms(2,3)\n by auto\n\ntheorem (in topgroup) quotient_top_group_INV_cont:\n assumes \"IsAnormalSubgroup(G,f,H)\"\n defines \"r \\ QuotientGroupRel(G,f,H)\"\n defines \"F \\ QuotientGroupOp(G,f,H)\"\n shows \"IsContinuous(T{quotient by}r,T{quotient by}r,GroupInv(G\/\/r,F))\"\nproof-\n have eqT:\"equiv(\\T,r)\" and eqG:\"equiv(G,r)\" using group0.Group_ZF_2_4_L3 assms(1) unfolding r_def IsAnormalSubgroup_def\n using group0_valid_in_tgroup by auto\n have two:\"two_top_spaces0(T,T{quotient by}r,{\\b,r``{b}\\. b\\G})\" unfolding two_top_spaces0_def\n using topSpaceAssum equiv_quo_is_top[OF eqT] quotient_proj_fun total_quo_equi[OF eqT] by auto\n have \"IsContinuous(T,T,GroupInv(G,f))\" using inv_cont. moreover\n {\n fix g assume G:\"g\\G\"\n then have \"GroupInv(G,f)`g=\\g\" using grinv_def by auto\n then have \"r``({GroupInv(G,f)`g})=GroupInv(G\/\/r,F)`(r``{g})\" using group0.Group_ZF_2_4_L7\n [OF group0_valid_in_tgroup assms(1) G] unfolding r_def F_def by auto\n then have \"{\\b,r``{b}\\. b\\G}`(GroupInv(G,f)`g)=GroupInv(G\/\/r,F)`({\\b,r``{b}\\. b\\G}`g)\"\n using apply_equality[OF _ quotient_proj_fun] G neg_in_tgroup unfolding grinv_def\n by auto\n then have \"({\\b,r``{b}\\. b\\G}O GroupInv(G,f))`g=(GroupInv(G\/\/r,F)O {\\b,r``{b}\\. b\\G})`g\"\n using comp_fun_apply[OF quotient_proj_fun G] comp_fun_apply[OF group0_2_T2[OF Ggroup] G] by auto\n }\n then have A1:\"{\\b,r``{b}\\. b\\G}O GroupInv(G,f)=GroupInv(G\/\/r,F)O {\\b,r``{b}\\. b\\G}\" using fun_extension[\n OF comp_fun[OF quotient_proj_fun group0.Group_ZF_2_4_L8[OF group0_valid_in_tgroup assms(1)]] \n comp_fun[OF group0_2_T2[OF Ggroup] quotient_proj_fun[of \"G\"\"r\"]]] unfolding r_def F_def by auto\n have \"IsContinuous(T,T{quotient by}r,{\\b,r``{b}\\. b\\\\T})\" using quotient_func_cont[OF quotient_proj_surj]\n unfolding EquivQuo_def[OF eqT] by auto\n ultimately have \"IsContinuous(T,T{quotient by}r,{\\b,r``{b}\\. b\\\\T}O GroupInv(G,f))\"\n using comp_cont by auto\n with A1 have \"IsContinuous(T,T{quotient by}r,GroupInv(G\/\/r,F)O {\\b,r``{b}\\. b\\G})\" by auto\n then have \"IsContinuous({quotient topology in}(\\T) \/\/ r{by}{\\b, r `` {b}\\ . b \\ \\T}{from}T,T{quotient by}r,GroupInv(G\/\/r,F))\"\n using two_top_spaces0.cont_quotient_top[OF two quotient_proj_surj, of \"GroupInv(G\/\/r,F)\"\"r\"] group0.Group_ZF_2_4_L8[OF group0_valid_in_tgroup assms(1)]\n using total_quo_equi[OF eqT] unfolding r_def F_def by auto\n then show ?thesis unfolding EquivQuo_def[OF eqT].\nqed\n\ntext\\Finally we can prove that quotient groups of topological groups\n are topological groups.\\\n\ntheorem(in topgroup) quotient_top_group:\n assumes \"IsAnormalSubgroup(G,f,H)\"\n defines \"r \\ QuotientGroupRel(G,f,H)\"\n defines \"F \\ QuotientGroupOp(G,f,H)\"\n shows \"IsAtopologicalGroup({quotient by}r,F)\"\n unfolding IsAtopologicalGroup_def using total_quo_equi equiv_quo_is_top\n Group_ZF_2_4_T1 Ggroup assms(1) quotient_top_group_INV_cont quotient_top_group_F_cont\n group0.Group_ZF_2_4_L3 group0_valid_in_tgroup assms(1) unfolding r_def F_def IsAnormalSubgroup_def\n by auto\n\n\nend\n","avg_line_length":79.2105263158,"max_line_length":442,"alphanum_fraction":0.6736434109} {"size":7051,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"(*\n File: Min_Int_Poly.thy\n Author: Manuel Eberl, TU M\u00fcnchen\n*)\nsection \\The minimal polynomial of an algebraic number\\\ntheory Min_Int_Poly\nimports\n \"Algebraic_Numbers.Algebraic_Numbers\"\n \"HOL-Computational_Algebra.Computational_Algebra\"\n More_Polynomial_HLW\nbegin\n\ntext \\\n Given an algebraic number \\x\\ in a field, the minimal polynomial is the unique irreducible\n integer polynomial with positive leading coefficient that has \\x\\ as a root.\n\n Note that we assume characteristic 0 since the material upon which all of this builds also\n assumes it.\n\\\n\n(* TODO Move *)\n\ndefinition min_int_poly :: \"'a :: field_char_0 \\ int poly\" where\n \"min_int_poly x =\n (if algebraic x then THE p. p represents x \\ irreducible p \\ Polynomial.lead_coeff p > 0\n else [:0, 1:])\"\n\nlemma\n fixes x :: \"'a :: {field_char_0, field_gcd}\"\n shows min_int_poly_represents [intro]: \"algebraic x \\ min_int_poly x represents x\"\n and min_int_poly_irreducible [intro]: \"irreducible (min_int_poly x)\"\n and lead_coeff_min_int_poly_pos: \"Polynomial.lead_coeff (min_int_poly x) > 0\"\nproof -\n note * = theI'[OF algebraic_imp_represents_unique, of x]\n show \"min_int_poly x represents x\" if \"algebraic x\"\n using *[OF that] by (simp add: that min_int_poly_def)\n have \"irreducible [:0, 1::int:]\"\n by (rule irreducible_linear_poly) auto\n thus \"irreducible (min_int_poly x)\"\n using * by (auto simp: min_int_poly_def)\n show \"Polynomial.lead_coeff (min_int_poly x) > 0\"\n using * by (auto simp: min_int_poly_def)\nqed\n\nlemma \n fixes x :: \"'a :: {field_char_0, field_gcd}\"\n shows degree_min_int_poly_pos [intro]: \"Polynomial.degree (min_int_poly x) > 0\"\n and degree_min_int_poly_nonzero [simp]: \"Polynomial.degree (min_int_poly x) \\ 0\"\nproof -\n show \"Polynomial.degree (min_int_poly x) > 0\"\n proof (cases \"algebraic x\")\n case True\n hence \"min_int_poly x represents x\"\n by auto\n thus ?thesis by blast\n qed (auto simp: min_int_poly_def)\n thus \"Polynomial.degree (min_int_poly x) \\ 0\"\n by blast\nqed\n\nlemma min_int_poly_squarefree [intro]:\n fixes x :: \"'a :: {field_char_0, field_gcd}\"\n shows \"squarefree (min_int_poly x)\"\n by (rule irreducible_imp_squarefree) auto\n\nlemma min_int_poly_primitive [intro]:\n fixes x :: \"'a :: {field_char_0, field_gcd}\"\n shows \"primitive (min_int_poly x)\"\n by (rule irreducible_imp_primitive) auto\n\nlemma min_int_poly_content [simp]:\n fixes x :: \"'a :: {field_char_0, field_gcd}\"\n shows \"content (min_int_poly x) = 1\"\n using min_int_poly_primitive[of x] by (simp add: primitive_def)\n\nlemma ipoly_min_int_poly [simp]: \n \"algebraic x \\ ipoly (min_int_poly x) (x :: 'a :: {field_gcd, field_char_0}) = 0\"\n using min_int_poly_represents[of x] by (auto simp: represents_def)\n\nlemma min_int_poly_nonzero [simp]:\n fixes x :: \"'a :: {field_char_0, field_gcd}\"\n shows \"min_int_poly x \\ 0\"\n using lead_coeff_min_int_poly_pos[of x] by auto\n\nlemma min_int_poly_normalize [simp]:\n fixes x :: \"'a :: {field_char_0, field_gcd}\"\n shows \"normalize (min_int_poly x) = min_int_poly x\"\n unfolding normalize_poly_def using lead_coeff_min_int_poly_pos[of x] by simp\n\nlemma min_int_poly_prime_elem [intro]:\n fixes x :: \"'a :: {field_char_0, field_gcd}\"\n shows \"prime_elem (min_int_poly x)\"\n using min_int_poly_irreducible[of x] by blast\n\nlemma min_int_poly_prime [intro]:\n fixes x :: \"'a :: {field_char_0, field_gcd}\"\n shows \"prime (min_int_poly x)\"\n using min_int_poly_prime_elem[of x]\n by (simp only: prime_normalize_iff [symmetric] min_int_poly_normalize)\n\nlemma min_int_poly_unique:\n fixes x :: \"'a :: {field_char_0, field_gcd}\"\n assumes \"p represents x\" \"irreducible p\" \"Polynomial.lead_coeff p > 0\"\n shows \"min_int_poly x = p\"\nproof -\n from assms(1) have x: \"algebraic x\"\n using algebraic_iff_represents by blast\n thus ?thesis\n using the1_equality[OF algebraic_imp_represents_unique[OF x], of p] assms\n unfolding min_int_poly_def by auto\nqed\n\nlemma min_int_poly_of_int [simp]:\n \"min_int_poly (of_int n :: 'a :: {field_char_0, field_gcd}) = [:-of_int n, 1:]\"\n by (intro min_int_poly_unique irreducible_linear_poly) auto\n\nlemma min_int_poly_of_nat [simp]:\n \"min_int_poly (of_nat n :: 'a :: {field_char_0, field_gcd}) = [:-of_nat n, 1:]\"\n using min_int_poly_of_int[of \"int n\"] by (simp del: min_int_poly_of_int)\n\nlemma min_int_poly_0 [simp]: \"min_int_poly (0 :: 'a :: {field_char_0, field_gcd}) = [:0, 1:]\"\n using min_int_poly_of_int[of 0] unfolding of_int_0 by simp\n\nlemma min_int_poly_1 [simp]: \"min_int_poly (1 :: 'a :: {field_char_0, field_gcd}) = [:-1, 1:]\"\n using min_int_poly_of_int[of 1] unfolding of_int_1 by simp\n\nlemma poly_min_int_poly_0_eq_0_iff [simp]:\n fixes x :: \"'a :: {field_char_0, field_gcd}\"\n assumes \"algebraic x\"\n shows \"poly (min_int_poly x) 0 = 0 \\ x = 0\"\nproof\n assume *: \"poly (min_int_poly x) 0 = 0\"\n show \"x = 0\"\n proof (rule ccontr)\n assume \"x \\ 0\"\n hence \"poly (min_int_poly x) 0 \\ 0\"\n using assms by (intro represents_irr_non_0) auto\n with * show False by contradiction\n qed\nqed auto\n\nlemma min_int_poly_conv_Gcd:\n fixes x :: \"'a :: {field_char_0, field_gcd}\"\n assumes \"algebraic x\"\n shows \"min_int_poly x = Gcd {p. p \\ 0 \\ p represents x}\"\nproof (rule sym, rule Gcd_eqI, (safe)?)\n fix p assume p: \"\\q. q \\ {p. p \\ 0 \\ p represents x} \\ p dvd q\"\n show \"p dvd min_int_poly x\"\n using assms by (intro p) auto\nnext\n fix p assume p: \"p \\ 0\" \"p represents x\"\n have \"min_int_poly x represents x\"\n using assms by auto\n hence \"poly (gcd (of_int_poly (min_int_poly x)) (of_int_poly p)) x = 0\"\n using p by (intro poly_gcd_eq_0I) auto\n hence \"ipoly (gcd (min_int_poly x) p) x = 0\"\n by (subst (asm) gcd_of_int_poly) auto\n hence \"gcd (min_int_poly x) p represents x\"\n using p unfolding represents_def by auto\n\n have \"min_int_poly x dvd gcd (min_int_poly x) p \\ is_unit (gcd (min_int_poly x) p)\"\n by (intro irreducibleD') auto\n moreover from \\gcd (min_int_poly x) p represents x\\ have \"\\is_unit (gcd (min_int_poly x) p)\"\n by (auto simp: represents_def)\n ultimately have \"min_int_poly x dvd gcd (min_int_poly x) p\"\n by blast\n also have \"\\ dvd p\"\n by blast\n finally show \"min_int_poly x dvd p\" .\nqed auto\n\nlemma min_int_poly_eqI:\n fixes x :: \"'a :: {field_char_0, field_gcd}\"\n assumes \"p represents x\" \"irreducible p\" \"Polynomial.lead_coeff p \\ 0\"\n shows \"min_int_poly x = p\"\nproof -\n from assms have [simp]: \"p \\ 0\"\n by auto\n have \"Polynomial.lead_coeff p \\ 0\"\n by auto\n with assms(3) have \"Polynomial.lead_coeff p > 0\"\n by linarith\n moreover have \"algebraic x\"\n using \\p represents x\\ by (meson algebraic_iff_represents)\n ultimately show ?thesis\n unfolding min_int_poly_def\n using the1_equality[OF algebraic_imp_represents_unique[OF \\algebraic x\\], of p] assms by auto\nqed\n\nend","avg_line_length":37.1105263158,"max_line_length":112,"alphanum_fraction":0.7128066941} {"size":476,"ext":"thy","lang":"Isabelle","max_stars_count":30.0,"content":"theory lscmnec_Lsc__ec__uncompress_point__subprogram_def_WP_parameter_def_3\nimports \"..\/LibSPARKcrypto\"\nbegin\n\nwhy3_open \"lscmnec_Lsc__ec__uncompress_point__subprogram_def_WP_parameter_def_3.xml\"\n\nwhy3_vc WP_parameter_def\n using\n `(num_of_big_int' (Array lsc__bignum__mont_mult__a1 _) _ _ = _) = _`\n `(math_int_from_word (of_int 1) < num_of_big_int' m _ _) = _`\n by (simp add: mk_bounds_eqs integer_in_range_def slide_eq less_imp_le [OF pos_mod_bound])\n\nwhy3_end\n\nend\n","avg_line_length":29.75,"max_line_length":91,"alphanum_fraction":0.8151260504} {"size":394,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* automatically generated -- do not edit manually *)\ntheory Simple imports Constant Zenon begin\nML_command {* writeln (\"*** TLAPS PARSED\\n\"); *}\nconsts\n \"isReal\" :: c\n \"isa_slas_a\" :: \"[c,c] => c\"\n \"isa_bksl_diva\" :: \"[c,c] => c\"\n \"isa_perc_a\" :: \"[c,c] => c\"\n \"isa_peri_peri_a\" :: \"[c,c] => c\"\n \"isInfinity\" :: c\n \"isa_lbrk_rbrk_a\" :: \"[c] => c\"\n \"isa_less_more_a\" :: \"[c] => c\"\n\nend\n","avg_line_length":26.2666666667,"max_line_length":53,"alphanum_fraction":0.5736040609} {"size":4445,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/n_german_lemma_inv__50_on_rules.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_german Protocol Case Study*} \n\ntheory n_german_lemma_inv__50_on_rules imports n_german_lemma_on_inv__50\nbegin\nsection{*All lemmas on causal relation between inv__50*}\nlemma lemma_inv__50_on_rules:\n assumes b1: \"r \\ rules N\" and b2: \"(\\ p__Inv1 p__Inv2. p__Inv1\\N\\p__Inv2\\N\\p__Inv1~=p__Inv2\\f=inv__50 p__Inv1 p__Inv2)\"\n shows \"invHoldForRule s f r (invariants N)\"\n proof -\n have c1: \"(\\ i d. i\\N\\d\\N\\r=n_Store i d)\\\n (\\ i. i\\N\\r=n_SendReqS i)\\\n (\\ i. i\\N\\r=n_SendReqE__part__0 i)\\\n (\\ i. i\\N\\r=n_SendReqE__part__1 i)\\\n (\\ i. i\\N\\r=n_RecvReqS N i)\\\n (\\ i. i\\N\\r=n_RecvReqE N i)\\\n (\\ i. i\\N\\r=n_SendInv__part__0 i)\\\n (\\ i. i\\N\\r=n_SendInv__part__1 i)\\\n (\\ i. i\\N\\r=n_SendInvAck i)\\\n (\\ i. i\\N\\r=n_RecvInvAck i)\\\n (\\ i. i\\N\\r=n_SendGntS i)\\\n (\\ i. i\\N\\r=n_SendGntE N i)\\\n (\\ i. i\\N\\r=n_RecvGntS i)\\\n (\\ i. i\\N\\r=n_RecvGntE i)\"\n apply (cut_tac b1, auto) done\n moreover {\n assume d1: \"(\\ i d. i\\N\\d\\N\\r=n_Store i d)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_StoreVsinv__50) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendReqS i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendReqSVsinv__50) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendReqE__part__0 i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendReqE__part__0Vsinv__50) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendReqE__part__1 i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendReqE__part__1Vsinv__50) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvReqS N i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvReqSVsinv__50) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvReqE N i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvReqEVsinv__50) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendInv__part__0 i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendInv__part__0Vsinv__50) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendInv__part__1 i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendInv__part__1Vsinv__50) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendInvAck i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendInvAckVsinv__50) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvInvAck i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvInvAckVsinv__50) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendGntS i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendGntSVsinv__50) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendGntE N i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendGntEVsinv__50) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvGntS i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvGntSVsinv__50) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvGntE i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvGntEVsinv__50) done\n }\n\n ultimately show \"invHoldForRule s f r (invariants N)\"\n by satx\nqed\n\nend\n","avg_line_length":37.3529411765,"max_line_length":157,"alphanum_fraction":0.6326209224} {"size":13869,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"(******************************************************************************\n * Isabelle\/C\n *\n * Copyright (c) 2018-2019 Universit\u00e9 Paris-Saclay, Univ. Paris-Sud, France\n *\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are\n * met:\n *\n * * Redistributions of source code must retain the above copyright\n * notice, this list of conditions and the following disclaimer.\n *\n * * Redistributions in binary form must reproduce the above\n * copyright notice, this list of conditions and the following\n * disclaimer in the documentation and\/or other materials provided\n * with the distribution.\n *\n * * Neither the name of the copyright holders nor the names of its\n * contributors may be used to endorse or promote products derived\n * from this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n ******************************************************************************)\n\nchapter \\Example: A Simple C Program with Directives and Annotations\\\n\ntheory C2\n imports \"..\/C_Main\"\nbegin\n\nsection \\A Simplistic Setup: Parse and Store\\\n\ntext\\The following setup just stores the result of the parsed values in the environment.\\\n\n\nML\\\nstructure Data_Out = Generic_Data\n (type T = (C_Grammar_Rule.start_happy * C_Antiquote.antiq C_Env.stream) list\n val empty = []\n val extend = I\n val merge = K empty)\n\nfun get_module thy =\n let val context = Context.Theory thy\n in (Data_Out.get context \n |> map (apfst (C_Grammar_Rule.start_happy1 #> the)), C_Module.Data_In_Env.get context)\n end\n\\\n\nsetup \\Context.theory_map (C_Module.Data_Accept.put\n (fn ast => fn env_lang =>\n Data_Out.map (cons (ast, #stream_ignored env_lang |> rev))))\\\n\n\nsection \\Example of a Possible Semantics for \\#include\\\\\n\nsubsection \\Implementation\\\n\ntext \\ The CPP directive \\<^C>\\#include _\\ is used to import signatures of\nmodules in C. This has the effect that imported identifiers are included in the C environment and,\nas a consequence, appear as constant symbols and not as free variables in the output. \\\n\ntext \\ The following structure is an extra mechanism to define the effect of \\<^C>\\#include _\\ wrt. to\nits definition in its environment. \\\n\nML \\\nstructure Directive_include = Generic_Data\n (type T = (Input.source * C_Env.markup_ident) list Symtab.table\n val empty = Symtab.empty\n val extend = I\n val merge = K empty)\n\\\n\nML \\ \\\\<^theory>\\Pure\\\\ \\\nlocal\nfun return f (env_cond, env) = ([], (env_cond, f env))\n\nval _ =\n Theory.setup\n (Context.theory_map\n (C_Context0.Directives.map\n (C_Context.directive_update (\"include\", \\<^here>)\n ( (return o K I)\n , fn C_Lex.Include (C_Lex.Group2 (toks_bl, _, tok :: _)) =>\n let\n fun exec file =\n if exists (fn C_Scan.Left _ => false | C_Scan.Right _ => true) file then\n K (error (\"Unsupported character\"\n ^ Position.here\n (Position.range_position\n (C_Lex.pos_of tok, C_Lex.end_pos_of (List.last toks_bl)))))\n else\n fn (env_lang, env_tree) =>\n fold\n (fn (src, data) => fn (env_lang, env_tree) => \n let val (name, pos) = Input.source_content src\n in C_Grammar_Rule_Lib.shadowTypedef0''''\n name\n [pos]\n data\n env_lang\n env_tree\n end)\n (these (Symtab.lookup (Directive_include.get (#context env_tree))\n (String.concat\n (maps (fn C_Scan.Left s => [s] | _ => []) file))))\n (env_lang, env_tree)\n in\n case tok of\n C_Lex.Token (_, (C_Lex.String (_, file), _)) => exec file\n | C_Lex.Token (_, (C_Lex.File (_, file), _)) => exec file\n | _ => tap (fn _ => (* not yet implemented *)\n warning (\"Ignored directive\"\n ^ Position.here \n (Position.range_position\n ( C_Lex.pos_of tok\n , C_Lex.end_pos_of (List.last toks_bl)))))\n end |> K |> K\n | _ => K (K I)))))\nin end\n\\\n\nML \\\nstructure Include =\nstruct\nfun init name vars =\n Context.theory_map\n (Directive_include.map\n (Symtab.update\n (name, map (rpair {global = true, params = [], ret = C_Env.Previous_in_stack}) vars)))\n\nfun append name vars =\n Context.theory_map\n (Directive_include.map\n (Symtab.map_default\n (name, [])\n (rev o fold (cons o rpair {global = true, params = [], ret = C_Env.Previous_in_stack}) vars\n o rev)))\n\nval show =\n Context.theory_map\n (Directive_include.map\n (tap\n (Symtab.dest\n #>\n app (fn (fic, vars) =>\n writeln (\"Content of \\\"\" ^ fic ^ \"\\\": \"\n ^ String.concat (map (fn (i, _) => let val (name, pos) = Input.source_content i\n in name ^ Position.here pos ^ \" \" end)\n vars))))))\nend\n\\\n\nsetup \\Include.append \"stdio.h\" [\\printf\\, \\scanf\\]\\\n\nsubsection \\Tests\\\n\nC \\\n\/\/@ setup \\Include.append \"tmp\" [\\b\\]\\\n#include \"tmp\"\nint a = b;\n\n\\\n\nC \\\nint b = 0;\n\/\/@ setup \\Include.init \"tmp\" [\\b\\]\\\n#include \"tmp\"\nint a = b;\n\\\n\nC \\\nint c = 0;\n\/\/@ setup \\Include.append \"tmp\" [\\c\\]\\\n\/\/@ setup \\Include.append \"tmp\" [\\c\\]\\\n#include \"tmp\"\nint a = b + c;\n\/\/@ setup \\Include.show\\\n\\\n\nsection \\Working with Pragmas\\\nC\\\n\n#include \n#include \/*sdfsdf *\/ \n#define a B\n#define b(C) \n#pragma \/* just exists syntaxically *\/\n\\\n\n\ntext\\In the following, we retrieve the C11 AST parsed above. \\\nML\\ val ((C_Ast.CTranslUnit0 (t,u), v)::R, env) = get_module @{theory};\n val u = C_Grammar_Rule_Lib.decode u; \n C_Ast.CTypeSpec0; \\\n\n\n\nsection \\Working with Annotation Commands\\\n\nML \\ \\\\<^theory>\\Isabelle_C.C_Command\\\\ \\\n\\ \\setup for a dummy ensures : the \"Hello World\" of Annotation Commands\\\nlocal\ndatatype antiq_hol = Term of string (* term *)\n\nval scan_opt_colon = Scan.option (C_Parse.$$$ \":\")\n\nfun msg cmd_name call_pos cmd_pos =\n tap (fn _ =>\n tracing (\"\\Hello World\\ reported by \\\"\" ^ cmd_name ^ \"\\\" here\" ^ call_pos cmd_pos))\n\nfun command (cmd as (cmd_name, _)) scan0 scan f =\n C_Annotation.command'\n cmd\n \"\"\n (fn (_, (cmd_pos, _)) =>\n (scan0 -- (scan >> f) >> (fn _ => C_Env.Never |> msg cmd_name Position.here cmd_pos)))\nin\nval _ = Theory.setup ( C_Inner_Syntax.command_no_range\n (C_Inner_Toplevel.generic_theory oo C_Inner_Isar_Cmd.setup \\K (K (K I))\\)\n (\"loop\", \\<^here>, \\<^here>)\n #> command (\"ensures\", \\<^here>) scan_opt_colon C_Parse.term Term\n #> command (\"invariant\", \\<^here>) scan_opt_colon C_Parse.term Term\n #> command (\"assigns\", \\<^here>) scan_opt_colon C_Parse.term Term\n #> command (\"requires\", \\<^here>) scan_opt_colon C_Parse.term Term\n #> command (\"variant\", \\<^here>) scan_opt_colon C_Parse.term Term)\nend\n\\\n\nC\\\n\/*@ ensures \"result >= x && result >= y\"\n *\/\n\nint max(int x, int y) {\n if (x > y) return x; else return y;\n}\n\\\n\nML\\ \nval ((C_Ast.CTranslUnit0 (t,u), v)::R, env) = get_module @{theory};\nval u = C_Grammar_Rule_Lib.decode u\n\\\n\n\nsection \\C Code: Various Examples\\\n\ntext\\This example suite is drawn from Frama-C and used in our GLA - TPs. \\\n\nC\\\nint sqrt(int a) {\n int i = 0;\n int tm = 1;\n int sum = 1;\n\n \/*@ loop invariant \"1 <= sum <= a+tm\"\n loop invariant \"(i+1)*(i+1) == sum\"\n loop invariant \"tm+(i*i) == sum\"\n loop invariant \"1<=tm<=sum\"\n loop assigns \"i, tm, sum\"\n loop variant \"a-sum\"\n *\/\n while (sum <= a) { \n i++;\n tm = tm + 2;\n sum = sum + tm;\n }\n \n return i;\n}\n\\\n\nC\\\n\/*@ requires \"n >= 0\"\n requires \"valid(t+(0..n-1))\"\n ensures \"exists integer i; (0<=i result == 0\"\n ensures \"(forall integer i; 0<=i t[i] == 0) <==> result == 1\"\n assigns nothing\n *\/\n\nint allzeros(int t[], int n) {\n int k = 0;\n\n \/*@ loop invariant \"0 <= k <= n\"\n loop invariant \"forall integer i; 0<=i t[i] == 0\"\n loop assigns k\n loop variant \"n-k\"\n *\/\n while(k < n) {\n if (t[k]) return 0;\n k = k + 1;\n }\n return 1;\n}\n\n\\\n\nC\\\n\n\/*@ requires \"n >= 0\"\n requires \"valid(t+(0..n-1))\"\n ensures \"(forall integer i; 0<=i t[i] != v) <==> result == -1\"\n ensures \"(exists integer i; 0<=i result == v\"\n assigns nothing\n *\/\n\nint binarysearch(int t[], int n, int v) {\n int l = 0;\n int u = n-1;\n\n \/*@ loop invariant false\n *\/\n while (l <= u) {\n int m = (l + u) \/ 2;\n if (t[m] < v) {\n l = m + 1;\n } else if (t[m] > v) {\n u = m - 1;\n }\n else return m; \n }\n return -1;\n}\n\\\n\n\nC\\\n\/*@ requires \"n >= 0\"\n requires \"valid(t+(0..n-1))\"\n requires \"(forall integer i,j; 0<=i<=j t[i] <= t[j])\"\n ensures \"exists integer i; (0<=i result == 1\"\n ensures \"(forall integer i; 0<=i t[i] != x) <==> result == 0\"\n assigns nothing\n *\/\n\nint linearsearch(int x, int t[], int n) {\n int i = 0;\n\n \/*@ loop invariant \"0<=i<=n\"\n loop invariant \"forall integer j; 0<=j (t[j] != x)\"\n loop assigns i\n loop variant \"n-i\"\n *\/\n while (i < n) {\n if (t[i] < x) {\n i++;\n } else {\n return (t[i] == x);\n }\n }\n\n return 0;\n}\n\\\n\n\nsection \\C Code: A Sorting Algorithm\\\n\nC\\\n#include \n \nint main()\n{\n int array[100], n, c, d, position, swap;\n \n printf(\"Enter number of elements\\n\");\n scanf(\"%d\", &n);\n \n printf(\"Enter %d integers\\n\", n);\n \n for (c = 0; c < n; c++) scanf(\"%d\", &array[c]);\n \n for (c = 0; c < (n - 1); c++)\n {\n position = c;\n \n for (d = c + 1; d < n; d++)\n {\n if (array[position] > array[d])\n position = d;\n }\n if (position != c)\n {\n swap = array[c];\n array[c] = array[position];\n array[position] = swap;\n }\n }\n\nprintf(\"Sorted list in ascending order:\\n\");\n \n for (c = 0; c < n; c++)\n printf(\"%d\\n\", array[c]);\n \n return 0;\n}\n\\\n\ntext\\A better example implementation:\\\n\nC\\\n#include \n#include \n \n#define SIZE 10\n \nvoid swap(int *x,int *y);\nvoid selection_sort(int* a, const int n);\nvoid display(int a[],int size);\n \nvoid main()\n{\n \n int a[SIZE] = {8,5,2,3,1,6,9,4,0,7};\n \n int i;\n printf(\"The array before sorting:\\n\");\n display(a,SIZE);\n \n selection_sort(a,SIZE);\n \n printf(\"The array after sorting:\\n\");\n display(a,SIZE);\n}\n \n\/*\n swap two integers\n*\/\nvoid swap(int *x,int *y)\n{\n int temp;\n \n temp = *x;\n *x = *y;\n *y = temp;\n}\n\/*\n perform selection sort\n*\/\nvoid selection_sort(int* a,const int size)\n{\n int i, j, min;\n \n for (i = 0; i < size - 1; i++)\n {\n min = i;\n for (j = i + 1; j < size; j++)\n {\n if (a[j] < a[min])\n {\n min = j;\n }\n }\n swap(&a[i], &a[min]);\n }\n}\n\/*\n display array content\n*\/\nvoid display(int a[],const int size)\n{\n int i;\n for(i=0; i\n\ntext\\Accessing the underlying C11-AST's via the ML Interface.\\\n\nML\\\nlocal open C_Ast in\nval _ = CTranslUnit0\nval ((CTranslUnit0 (t,u), v)::_, _) = get_module @{theory};\nval u = C_Grammar_Rule_Lib.decode u\nval _ = case u of Left (p1,p2) => writeln (Position.here p1 ^ \" \" ^ Position.here p2)\n | Right _ => error \"Not expecting that value\"\nval CDeclExt0(x1)::_ = t;\nval _ = CDecl0\nend\n\\\n\nsection \\C Code: Floats Exist\\\n\nC\\\nint a;\nfloat b;\nint m() {return 0;}\n\\\n\nend","avg_line_length":27.6274900398,"max_line_length":121,"alphanum_fraction":0.5502920182} {"size":4047,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"chapter \"Matching adaptation\"\n\ntheory Matching\nimports Semantic_Extras\nbegin\n\ncontext begin\n\nqualified fun fold2 where\n\"fold2 f err [] [] init = init\" |\n\"fold2 f err (x # xs) (y # ys) init = fold2 f err xs ys (f x y init)\" |\n\"fold2 _ err _ _ _ = err\"\n\nqualified lemma fold2_cong[fundef_cong]:\n assumes \"init1 = init2\" \"err1 = err2\" \"xs1 = xs2\" \"ys1 = ys2\"\n assumes \"\\init x y. x \\ set xs1 \\ y \\ set ys1 \\ f x y init = g x y init\"\n shows \"fold2 f err1 xs1 ys1 init1 = fold2 g err2 xs2 ys2 init2\"\nusing assms\nby (induction f err1 xs1 ys1 init1 arbitrary: init2 xs2 ys2 rule: fold2.induct) auto\n\nfun pmatch_single :: \"((string),(string),(nat*tid_or_exn))namespace \\((v)store_v)list \\ pat \\ v \\(string*v)list \\((string*v)list)match_result \" where\n\"pmatch_single envC s Pany v' env = ( Match env )\" |\n\"pmatch_single envC s (Pvar x) v' env = ( Match ((x,v')# env))\" |\n\"pmatch_single envC s (Plit l) (Litv l') env = (\n if l = l' then\n Match env\n else if lit_same_type l l' then\n No_match\n else\n Match_type_error )\" |\n\"pmatch_single envC s (Pcon (Some n) ps) (Conv (Some (n', t')) vs) env =\n (case nsLookup envC n of\n Some (l, t1) =>\n if same_tid t1 t' \\ (List.length ps = l) then\n if same_ctor (id_to_n n, t1) (n',t') then\n fold2 (\\p v m. case m of\n Match env \\ pmatch_single envC s p v env \n | m \\ m) Match_type_error ps vs (Match env)\n else\n No_match\n else\n Match_type_error\n | _ => Match_type_error\n )\" |\n\"pmatch_single envC s (Pcon None ps) (Conv None vs) env = (\n if List.length ps = List.length vs then\n fold2 (\\p v m. case m of\n Match env \\ pmatch_single envC s p v env \n | m \\ m)\n Match_type_error ps vs (Match env)\n else\n Match_type_error )\" |\n\"pmatch_single envC s (Pref p) (Loc lnum) env =\n (case store_lookup lnum s of\n Some (Refv v2) => pmatch_single envC s p v2 env\n | Some _ => Match_type_error\n | None => Match_type_error\n )\" |\n\"pmatch_single envC s (Ptannot p t1) v2 env = pmatch_single envC s p v2 env\" |\n\"pmatch_single envC _ _ _ env = Match_type_error\"\n\nprivate lemma pmatch_list_length_neq:\n \"length vs \\ length ps \\ fold2(\\p v m. case m of\n Match env \\ pmatch_single cenv s p v env \n | m \\ m) Match_type_error ps vs m = Match_type_error\"\n by (induction ps vs arbitrary:m rule:List.list_induct2') auto\n\nprivate lemma pmatch_list_nomatch:\n \"length vs = length ps \\ fold2(\\p v m. case m of\n Match env \\ pmatch_single cenv s p v env \n | m \\ m) Match_type_error ps vs No_match = No_match\"\n by (induction ps vs rule:List.list_induct2') auto\n\nprivate lemma pmatch_list_typerr:\n \"length vs = length ps \\ fold2(\\p v m. case m of\n Match env \\ pmatch_single cenv s p v env \n | m \\ m) Match_type_error ps vs Match_type_error = Match_type_error\"\n by (induction ps vs rule:List.list_induct2') auto\n\nprivate lemma pmatch_single_eq0:\n \"length ps = length vs \\ pmatch_list cenv s ps vs env = fold2(\\p v m. case m of\n Match env \\ pmatch_single cenv s p v env \n | m \\ m) Match_type_error ps vs (Match env)\"\n \"pmatch cenv s p v0 env = pmatch_single cenv s p v0 env\"\nproof (induction rule: pmatch_list_pmatch.induct)\n case (4 envC s n ps n' t' vs env)\n then show ?case\n by (auto split:option.splits match_result.splits dest!:pmatch_list_length_neq[where m = \"Match env\" and cenv = envC and s = s])\nqed (auto split:option.splits match_result.splits store_v.splits simp:pmatch_list_nomatch pmatch_list_typerr)\n\nlemma pmatch_single_equiv: \"pmatch = pmatch_single\"\nby (rule ext)+ (simp add: pmatch_single_eq0)\n\nend\n\nexport_code pmatch_single checking SML\n\nend","avg_line_length":41.2959183673,"max_line_length":209,"alphanum_fraction":0.6775389177} {"size":3969,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/n_germanSimp_lemma_inv__57_on_rules.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_germanSimp Protocol Case Study*} \n\ntheory n_germanSimp_lemma_inv__57_on_rules imports n_germanSimp_lemma_on_inv__57\nbegin\nsection{*All lemmas on causal relation between inv__57*}\nlemma lemma_inv__57_on_rules:\n assumes b1: \"r \\ rules N\" and b2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__57 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n proof -\n have c1: \"(\\ i d. i\\N\\d\\N\\r=n_Store i d)\\\n (\\ i. i\\N\\r=n_RecvReqS N i)\\\n (\\ i. i\\N\\r=n_RecvReqE__part__0 N i)\\\n (\\ i. i\\N\\r=n_RecvReqE__part__1 N i)\\\n (\\ i. i\\N\\r=n_SendInv__part__0 i)\\\n (\\ i. i\\N\\r=n_SendInv__part__1 i)\\\n (\\ i. i\\N\\r=n_SendInvAck i)\\\n (\\ i. i\\N\\r=n_RecvInvAck i)\\\n (\\ i. i\\N\\r=n_SendGntS i)\\\n (\\ i. i\\N\\r=n_SendGntE N i)\\\n (\\ i. i\\N\\r=n_RecvGntS i)\\\n (\\ i. i\\N\\r=n_RecvGntE i)\"\n apply (cut_tac b1, auto) done\n moreover {\n assume d1: \"(\\ i d. i\\N\\d\\N\\r=n_Store i d)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_StoreVsinv__57) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvReqS N i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvReqSVsinv__57) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvReqE__part__0 N i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvReqE__part__0Vsinv__57) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvReqE__part__1 N i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvReqE__part__1Vsinv__57) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendInv__part__0 i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendInv__part__0Vsinv__57) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendInv__part__1 i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendInv__part__1Vsinv__57) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendInvAck i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendInvAckVsinv__57) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvInvAck i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvInvAckVsinv__57) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendGntS i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendGntSVsinv__57) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendGntE N i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendGntEVsinv__57) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvGntS i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvGntSVsinv__57) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvGntE i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvGntEVsinv__57) done\n }\n\n ultimately show \"invHoldForRule s f r (invariants N)\"\n by satx\nqed\n\nend\n","avg_line_length":37.8,"max_line_length":157,"alphanum_fraction":0.6394557823} {"size":11169,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"(******************************************************************************\n * Isabelle\/C\n *\n * Copyright (c) 2018-2019 Universit\u00e9 Paris-Saclay, Univ. Paris-Sud, France\n *\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are\n * met:\n *\n * * Redistributions of source code must retain the above copyright\n * notice, this list of conditions and the following disclaimer.\n *\n * * Redistributions in binary form must reproduce the above\n * copyright notice, this list of conditions and the following\n * disclaimer in the documentation and\/or other materials provided\n * with the distribution.\n *\n * * Neither the name of the copyright holders nor the names of its\n * contributors may be used to endorse or promote products derived\n * from this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n ******************************************************************************)\n\nchapter \\Example: Lexer Stress Test\\\n\ntheory C0\n imports \"..\/C_Main\"\nbegin\n\ndeclare[[C_lexer_trace]]\n\nsection \\Regular C Code\\\n\nsubsection \\Comments, Keywords and Pragmas\\\n\nC \\ \\Nesting of comments following the example suite of\n \\<^url>\\https:\/\/gcc.gnu.org\/onlinedocs\/cpp\/Initial-processing.html\\\\ \\\n\/* inside \/* inside *\/ int a = \"outside\";\n\/\/ inside \/\/ inside until end of line\nint a = \"outside\";\n\/* inside\n \/\/ inside\ninside\n*\/ int a = \"outside\";\n\/\/ inside \/* inside until end of line\nint a = \"outside\";\n\\\n\nC \\ \\Backslash newline\\ \\\ni\\ \nn\\ \nt a = \"\/* \/\/ \/\\ \n*\\\nfff *\/\\\n\";\n\\\n\nC \\ \\Backslash newline, Directive \\<^url>\\https:\/\/gcc.gnu.org\/onlinedocs\/cpp\/Initial-processing.html\\\\ \\\n\/\\\n*\n*\/ # \/*\n*\/ defi\\\nne FO\\\nO 10\\\n20\\\n\nC \\ \\Directive: conditional\\ \\\n#ifdef a\n#elif\n#else\n#if\n#endif\n#endif\n\\\n(*\nC \\ \\Directive: pragma\\ \\# f # \"\/**\/\"\n\/**\/\n# \/**\/ \/\/ #\n\n_Pragma \/\\\n**\/(\"a\")\n\\\n*)\nC \\ \\Directive: macro\\ \\\n#define a zz\n#define a(x1,x2) z erz(( zz\n#define a (x1,x2) z erz(( zz\n#undef z\n#if\n#define a zz\n#define a(x1,x2) z erz(( zz\n#define a (x1,x2) z erz(( zz\n#endif\n\\\n\nsubsection \\Scala\/jEdit Latency on Multiple Bindings\\\n\nC \\ \\Example of obfuscated code \\<^url>\\https:\/\/en.wikipedia.org\/wiki\/International_Obfuscated_C_Code_Contest\\\\ \\\n#define _ -F<00||--F-OO--;\nint F=00,OO=00;main(){F_OO();printf(\"%1.3f\\n\",4.*-F\/OO\/OO);}F_OO()\n{\n _-_-_-_\n _-_-_-_-_-_-_-_-_\n _-_-_-_-_-_-_-_-_-_-_-_\n _-_-_-_-_-_-_-_-_-_-_-_-_-_\n _-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n _-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n _-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n _-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n _-_-_-_-_-_-_-_-_-_-_-_-_-_\n _-_-_-_-_-_-_-_-_-_-_-_\n _-_-_-_-_-_-_-_\n _-_-_-_\n}\n\\\n\ntext \\ Select inside the ball, experience the latency.\nA special keyboard combination ``Ctrl-like key\\<^footnote>\\on Apple: Cmd\\ + Shift +\nEnter'' lets Isabelle\/Scala\/jEdit enter in a mode where the selected bound occurrences can be all\nsimultaneously replaced by new input characters typed on the keyboard. (The ``select-entity'' action\nexists since Isabelle2016-1, see the respective section ``Prover IDE -- Isabelle\/Scala\/jEdit'' in\nthe NEWS.)\\\n\nsubsection \\Lexing and Parsing Obfuscated Sources\\\n\ntext \\Another lexer\/parser - stress test: parsing an obfuscated C source.\\\n\nC \\ \\Example of obfuscated code \\<^url>\\https:\/\/www.ioccc.org\/2018\/endoh1\/prog.c\\\\ \\\n #define\/*__Int3rn^ti[]n\/l_()I3fusc^t3|]_C_C<>I7E_C[]nt3st__*\/L\/*__MMXVIII__*\/for\n #include\/*!\"'()*+,-.\/12357:;<=>?CEFGHIJKLMNSTUVWXYZ[]^_`cfhijklmnrstuvwxyz{|}*\/\n char*r,F[1<<21]=\"~T\/}3(|+G{>\/zUhy;Jx+5wG>u55t.?sIZrC]n.;m+:l+Hk]WjNJi\/Sh+2f1>c2H`)(_2(^L\\\n -]=([1\/Z<2Y7\/X12W:.VFFU1,T77S+;N?;M\/>L..K1+JCCI<+(=3)Z-;*(:*.Y\/5(-=)2*-U,\\\n\/+-?5'(,+++***''EE>T,215IEUF:N`2`:?GK;+^`+?>)5?>U>_)5GxG).2K.2};}_235(]:5,S7E1(vTSS,-SSTvU(<-HG\\\n-2E2\/2L2\/EE->E:?EE,2XMMMM1Hy`)5rHK;+.T+?[n2\/_2{LKN2\/_|cK2+.2`;}:?{KL57?|cK:2{NrHKtMMMK2nrH;rH[n\"\n\"CkM_E21-E,-1->E(_:mSE\/LhLE\/mm:2Ul;2M>,2KW-+.-u).5Lm?fM`2`2nZXjj?[nT+?KH~-?f<;G_x2;;2XT7LXIuuVF2X(G(GVV-:-:KjJ]HKLyN7UjJ3.WXjNI2KNx#&#&&$#$;ZXIc###$&$$#>7[LMv{&&&&#&##L,l2TY.&$#$#&&$,(iiii,#&&&#$#$?TY2.$#$1(x###;2EE[t,\\\nSSEz.SW-k,T&&jC?E-.$## &#&57+$$# &&&W1-&$$7W -J$#$kEN&#& $##C^+$##W,h###n\/+L2YE\"\n\"2nJk\/H;YNs#$[,:TU(#$ ,: &&~H>&# Y; &&G_x ,mT&$YE-#& 5G $#VVF$#&zNs$$&Ej]HELy\\\nCN\/U^Jk71<(#&:G7E+^&# l|?1 $$Y.2$$ 7lzs WzZw>&$E -x; 2zsW\/$$#HKt&$$v>+t1(>\"\n\"7>S7S,;TT,&$;S7S>7&#>E_::U $$'\",op ,*G= F,*I=957+F ;int*t,k,O, i, j,T[+060<<+020];int M(\nint m,int nop){;;;return+ m%(0+nop );;} int*tOo,w, h,z,W;void(C) (int n){n=putchar(n);}int\nf,c,H=11,Y=64<<2,Z,pq,X ;void(E\/*d *\/)( int\/*RP*\/n ){L(Z=k+00; Z; Z\/=+2+000)G[000]=*G*!!f\n|M(n,2)<=13*3?*G-*r?*I++=*G:(*I++=r[1],*I++=r[2]):1;L(j=12,r\n=I;(*I=i=getchar())>-1;I++)i-7-3?I-=i<32||127<=i,j+=12:(H+=17+3,W=W-1;r++)*r-\n7-3?J(),w++:(w=z,h+=17+3);C(71);C(73);V('*'*'1'*7);C(57);C(32*3+1);V(W);V(H);C(122*2);L(V(i=z);i\n<32*3;)C(i++\/3*X\/31);C(33);C(X);C(11);L(G=\"SJYXHFUJ735\";*G;)C(*G++-5);C(3);V(1);L(V(j=z);j<21*3;\n j++){k=257;V(63777);V(k<<2);V(M(j,32)?11:511);V(z);C(22*2);V(i=f=z);V(z);V(W);V(H);V(1<<11);r=\n G=I+W*H;L(t=T;i<1<<21;i++)T[i]=iX?X:G-r\n ,C(k),k;)L(;k--;C(*r++\/*---#$%&04689@ABDOPQRabdegopq---*\/));}C(53+6);return(z);}\n\\\n\nsection \\Experiments with \\<^dir>\\..\/..\/src_ext\/parser_menhir\\\\\n\ndeclare[[C_lexer_trace = false]]\n\nsubsection \\Expecting to succeed\\\n\n\\<^cancel>\\C_file \\..\/..\/src_ext\/parser_menhir\/tests\/aligned_struct_c18.c\\\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/argument_scope.c\\\n\\<^cancel>\\C_file \\..\/..\/src_ext\/parser_menhir\/tests\/atomic.c\\\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/atomic_parenthesis.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/bitfield_declaration_ambiguity.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/bitfield_declaration_ambiguity.ok.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/block_scope.c\\\n\\<^cancel>\\C_file \\..\/..\/src_ext\/parser_menhir\/tests\/c11-noreturn.c\\\\\n\\<^cancel>\\C_file \\..\/..\/src_ext\/parser_menhir\/tests\/c1x-alignas.c\\\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/char-literal-printing.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/c-namespace.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/control-scope.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/dangling_else.c\\\n\\<^cancel>\\C_file \\..\/..\/src_ext\/parser_menhir\/tests\/dangling_else_lookahead.c\\\\\n\\<^cancel>\\C_file \\..\/..\/src_ext\/parser_menhir\/tests\/dangling_else_lookahead.if.c\\\\\n\\<^cancel>\\C_file \\..\/..\/src_ext\/parser_menhir\/tests\/declaration_ambiguity.c\\\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/declarators.c\\\n\\<^cancel>\\C_file \\..\/..\/src_ext\/parser_menhir\/tests\/declarator_visibility.c\\\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/designator.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/enum.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/enum_constant_visibility.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/enum_shadows_typedef.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/enum-trick.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/expressions.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/function-decls.c\\\n\\<^cancel>\\C_file \\..\/..\/src_ext\/parser_menhir\/tests\/function_parameter_scope.c\\\\\n\\<^cancel>\\C_file \\..\/..\/src_ext\/parser_menhir\/tests\/function_parameter_scope_extends.c\\\\\n\\<^cancel>\\C_file \\..\/..\/src_ext\/parser_menhir\/tests\/if_scopes.c\\\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/local_scope.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/local_typedef.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/long-long-struct.c\\\n\\<^cancel>\\C_file \\..\/..\/src_ext\/parser_menhir\/tests\/loop_scopes.c\\\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/namespaces.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/no_local_scope.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/parameter_declaration_ambiguity.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/parameter_declaration_ambiguity.test.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/statements.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/struct-recursion.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/typedef_star.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/types.c\\\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/variable_star.c\\\n\nsubsection \\Expecting to fail\\\n\nC_file \\..\/..\/src_ext\/parser_menhir\/tests\/bitfield_declaration_ambiguity.fail.c\\\n\\<^cancel>\\C_file \\..\/..\/src_ext\/parser_menhir\/tests\/dangling_else_misleading.fail.c\\\\\n\nend\n","avg_line_length":48.7729257642,"max_line_length":154,"alphanum_fraction":0.6407914764} {"size":339,"ext":"thy","lang":"Isabelle","max_stars_count":30.0,"content":"theory lscmnec_Lsc__ec__invert__subprogram_def_WP_parameter_def_1\nimports \"..\/LibSPARKcrypto\"\nbegin\n\nwhy3_open \"lscmnec_Lsc__ec__invert__subprogram_def_WP_parameter_def_1.xml\"\n\nwhy3_vc WP_parameter_def\n using\n `(num_of_big_int' r _ _ = _) = _`\n `(math_int_from_word (of_int 1) < num_of_big_int' m _ _) = _`\n by simp\n\nwhy3_end\n\nend\n","avg_line_length":21.1875,"max_line_length":74,"alphanum_fraction":0.7876106195} {"size":10142,"ext":"thy","lang":"Isabelle","max_stars_count":2.0,"content":"section \\\\Extra_Lattice\\ -- Additional results about lattices\\\n\ntheory Extra_Lattice\n imports Main\nbegin\n\n\nsubsection\\\\Lattice_Missing\\ -- Miscellaneous missing facts about lattices\\\n\ntext \\Two bundles to activate and deactivate lattice specific notation (e.g., \\\\\\ etc.).\n Activate the notation locally via \"@{theory_text \\includes lattice_notation\\}\" in a lemma statement.\n (Or sandwich a declaration using that notation between \"@{theory_text \\unbundle lattice_notation ... unbundle no_lattice_notation\\}.)\\\n\nbundle lattice_notation begin\nnotation inf (infixl \"\\\" 70)\nnotation sup (infixl \"\\\" 65)\nnotation Inf (\"\\\")\nnotation Sup (\"\\\")\nnotation bot (\"\\\")\nnotation top (\"\\\")\nend\n\nbundle no_lattice_notation begin\nnotation inf (infixl \"\\\" 70)\nnotation sup (infixl \"\\\" 65)\nnotation Inf (\"\\\")\nnotation Sup (\"\\\")\nnotation bot (\"\\\")\nnotation top (\"\\\")\nend\n\nunbundle lattice_notation\n\ntext \\The following class \\complemented_lattice\\ describes complemented lattices (with\n \\<^const>\\uminus\\ for the complement). The definition follows \n \\<^url>\\https:\/\/en.wikipedia.org\/wiki\/Complemented_lattice#Definition_and_basic_properties\\.\n Additionally, it adopts the convention from \\<^class>\\boolean_algebra\\ of defining \n \\<^const>\\minus\\ in terms of the complement.\\\n\nclass complemented_lattice = bounded_lattice + uminus + minus + \n assumes inf_compl_bot[simp]: \"inf x (-x) = bot\"\n and sup_compl_top[simp]: \"sup x (-x) = top\"\n and diff_eq: \"x - y = inf x (- y)\" begin\n\nlemma dual_complemented_lattice:\n \"class.complemented_lattice (\\x y. x \\ (- y)) uminus sup greater_eq greater inf \\ \\\"\nproof (rule class.complemented_lattice.intro)\n show \"class.bounded_lattice (\\) (\\x y. (y::'a) \\ x) (\\x y. y < x) (\\) \\ \\\"\n by (rule dual_bounded_lattice)\n show \"class.complemented_lattice_axioms (\\x y. (x::'a) \\ - y) uminus (\\) (\\) \\ \\\"\n by (unfold_locales, auto simp add: diff_eq)\nqed\n\n\nlemma compl_inf_bot [simp]: \"inf (- x) x = bot\"\n by (simp add: inf_commute)\n\nlemma compl_sup_top [simp]: \"sup (- x) x = top\"\n by (simp add: sup_commute)\n\nend\n\nclass complete_complemented_lattice = complemented_lattice + complete_lattice \n\ntext \\The following class \\complemented_lattice\\ describes orthocomplemented lattices,\n following \\<^url>\\https:\/\/en.wikipedia.org\/wiki\/Complemented_lattice#Orthocomplementation\\.\\\nclass orthocomplemented_lattice = complemented_lattice +\n assumes ortho_involution[simp]: \"- (- x) = x\"\n and ortho_antimono: \"x \\ y \\ -x \\ -y\" begin\n\nlemma dual_orthocomplemented_lattice:\n \"class.orthocomplemented_lattice (\\x y. x \\ - y) uminus sup greater_eq greater inf \\ \\\"\nproof (rule class.orthocomplemented_lattice.intro)\n show \"class.complemented_lattice (\\x y. (x::'a) \\ - y) uminus (\\) (\\x y. y \\ x) (\\x y. y < x) (\\) \\ \\\"\n by (rule dual_complemented_lattice)\n show \"class.orthocomplemented_lattice_axioms uminus (\\x y. (y::'a) \\ x)\"\n by (unfold_locales, auto simp add: diff_eq intro: ortho_antimono)\nqed\n\n\n\nlemma compl_eq_compl_iff [simp]: \"- x = - y \\ x = y\"\n by (metis ortho_involution)\n\nlemma compl_bot_eq [simp]: \"- bot = top\"\n by (metis inf_compl_bot inf_top_left ortho_involution)\n\nlemma compl_top_eq [simp]: \"- top = bot\"\n using compl_bot_eq ortho_involution by blast\n\ntext \\De Morgan's law\\\n (* Proof from: https:\/\/planetmath.org\/orthocomplementedlattice *)\nlemma compl_sup [simp]: \"- (x \\ y) = - x \\ - y\"\nproof -\n have \"- (x \\ y) \\ - x\"\n by (simp add: ortho_antimono)\n moreover have \"- (x \\ y) \\ - y\"\n by (simp add: ortho_antimono)\n ultimately have 1: \"- (x \\ y) \\ - x \\ - y\"\n by (simp add: sup.coboundedI1)\n have \\x \\ - (-x \\ -y)\\\n by (metis inf.cobounded1 ortho_antimono ortho_involution)\n moreover have \\y \\ - (-x \\ -y)\\\n by (metis inf.cobounded2 ortho_antimono ortho_involution)\n ultimately have \\x \\ y \\ - (-x \\ -y)\\\n by auto\n hence 2: \\-x \\ -y \\ - (x \\ y)\\\n using ortho_antimono by fastforce\n from 1 2 show ?thesis\n using dual_order.antisym by presburger\nqed\n\ntext \\De Morgan's law\\\nlemma compl_inf [simp]: \"- (x \\ y) = - x \\ - y\"\n using compl_sup\n by (metis ortho_involution)\n\nlemma compl_mono:\n assumes \"x \\ y\"\n shows \"- y \\ - x\"\n by (simp add: assms local.ortho_antimono)\n\nlemma compl_le_compl_iff [simp]: \"- x \\ - y \\ y \\ x\"\n by (auto dest: compl_mono)\n\nlemma compl_le_swap1:\n assumes \"y \\ - x\"\n shows \"x \\ -y\"\n using assms ortho_antimono by fastforce\n\nlemma compl_le_swap2:\n assumes \"- y \\ x\"\n shows \"- x \\ y\"\n using assms local.ortho_antimono by fastforce\n\nlemma compl_less_compl_iff[simp]: \"- x < - y \\ y < x\"\n by (auto simp add: less_le)\n\nlemma compl_less_swap1:\n assumes \"y < - x\"\n shows \"x < - y\"\n using assms compl_less_compl_iff by fastforce\n\nlemma compl_less_swap2:\n assumes \"- y < x\"\n shows \"- x < y\"\n using assms compl_le_swap1 compl_le_swap2 less_le_not_le by auto\n\nlemma sup_cancel_left1: \"sup (sup x a) (sup (- x) b) = top\"\n by (simp add: sup_commute sup_left_commute)\n\nlemma sup_cancel_left2: \"sup (sup (- x) a) (sup x b) = top\"\n by (simp add: sup.commute sup_left_commute)\n\nlemma inf_cancel_left1: \"inf (inf x a) (inf (- x) b) = bot\"\n by (simp add: inf.left_commute inf_commute)\n\nlemma inf_cancel_left2: \"inf (inf (- x) a) (inf x b) = bot\"\n using inf.left_commute inf_commute by auto\n\nlemma sup_compl_top_left1 [simp]: \"sup (- x) (sup x y) = top\"\n by (simp add: sup_assoc[symmetric])\n\nlemma sup_compl_top_left2 [simp]: \"sup x (sup (- x) y) = top\"\n using sup_compl_top_left1[of \"- x\" y] by simp\n\nlemma inf_compl_bot_left1 [simp]: \"inf (- x) (inf x y) = bot\"\n by (simp add: inf_assoc[symmetric])\n\nlemma inf_compl_bot_left2 [simp]: \"inf x (inf (- x) y) = bot\"\n using inf_compl_bot_left1[of \"- x\" y] by simp\n\nlemma inf_compl_bot_right [simp]: \"inf x (inf y (- x)) = bot\"\n by (subst inf_left_commute) simp\n\nend\n\nclass complete_orthocomplemented_lattice = orthocomplemented_lattice + complete_lattice\n\ninstance complete_orthocomplemented_lattice \\ complete_complemented_lattice\n by intro_classes\n\ntext \\The following class \\orthomodular_lattice\\ describes orthomodular lattices,\nfollowing \\<^url>\\https:\/\/en.wikipedia.org\/wiki\/Complemented_lattice#Orthomodular_lattices\\.\\\nclass orthomodular_lattice = orthocomplemented_lattice +\n assumes orthomodular: \"x \\ y \\ sup x (inf (-x) y) = y\" begin\n\nlemma dual_orthomodular_lattice:\n \"class.orthomodular_lattice (\\x y. x \\ - y) uminus sup greater_eq greater inf \\ \\\"\nproof (rule class.orthomodular_lattice.intro)\n show \"class.orthocomplemented_lattice (\\x y. (x::'a) \\ - y) uminus (\\) (\\x y. y \\ x) (\\x y. y < x) (\\) \\ \\\"\n by (rule dual_orthocomplemented_lattice)\n show \"class.orthomodular_lattice_axioms uminus (\\) (\\x y. (y::'a) \\ x) (\\)\"\n proof (unfold_locales)\n show \"(x::'a) \\ (- x \\ y) = y\"\n if \"(y::'a) \\ x\"\n for x :: 'a\n and y :: 'a\n using that local.compl_eq_compl_iff local.ortho_antimono local.orthomodular by fastforce\n qed\n\nqed\n\n\nend\n\nclass complete_orthomodular_lattice = orthomodular_lattice + complete_lattice begin\n\nend\n\ninstance complete_orthomodular_lattice \\ complete_orthocomplemented_lattice\n by intro_classes\n\n\ninstance boolean_algebra \\ orthomodular_lattice\nproof\n fix x y :: 'a \n show \"sup (x::'a) (inf (- x) y) = y\"\n if \"(x::'a) \\ y\"\n using that\n by (simp add: sup.absorb_iff2 sup_inf_distrib1) \n show \"x - y = inf x (- y)\"\n by (simp add: boolean_algebra_class.diff_eq)\nqed auto\n\ninstance complete_boolean_algebra \\ complete_orthomodular_lattice\n by intro_classes\n\nlemma image_of_maximum:\n fixes f::\"'a::order \\ 'b::conditionally_complete_lattice\"\n assumes \"mono f\"\n and \"\\x. x:M \\ x\\m\"\n and \"m:M\"\n shows \"(SUP x\\M. f x) = f m\"\n by (smt (verit, ccfv_threshold) assms(1) assms(2) assms(3) cSup_eq_maximum imageE imageI monoD)\n\nlemma cSup_eq_cSup:\n fixes A B :: \\'a::conditionally_complete_lattice set\\\n assumes bdd: \\bdd_above A\\\n assumes B: \\\\a. a\\A \\ \\b\\B. b \\ a\\\n assumes A: \\\\b. b\\B \\ \\a\\A. a \\ b\\\n shows \\Sup A = Sup B\\\nproof (cases \\B = {}\\)\n case True\n with A B have \\A = {}\\\n by auto\n with True show ?thesis by simp\nnext\n case False\n have \\bdd_above B\\\n by (meson A bdd bdd_above_def order_trans)\n have \\A \\ {}\\\n using A False by blast\n moreover have \\a \\ Sup B\\ if \\a \\ A\\ for a\n proof -\n obtain b where \\b \\ B\\ and \\b \\ a\\\n using B \\a \\ A\\ by auto\n then show ?thesis\n apply (rule cSup_upper2)\n using \\bdd_above B\\ by simp\n qed\n moreover have \\Sup B \\ c\\ if \\\\a. a \\ A \\ a \\ c\\ for c\n using False apply (rule cSup_least)\n using A that by fastforce\n ultimately show ?thesis\n by (rule cSup_eq_non_empty)\nqed\n\nunbundle no_lattice_notation\n\nend\n","avg_line_length":37.2867647059,"max_line_length":177,"alphanum_fraction":0.6911851706} {"size":7690,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/n_g2kAbsAfter_lemma_on_inv__14.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_g2kAbsAfter Protocol Case Study*} \n\ntheory n_g2kAbsAfter_lemma_on_inv__14 imports n_g2kAbsAfter_base\nbegin\nsection{*All lemmas on causal relation between inv__14 and some rule r*}\nlemma n_n_Store_i1Vsinv__14:\nassumes a1: \"(\\ d. d\\N\\r=n_n_Store_i1 d)\" and\na2: \"(f=inv__14 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain d where a1:\"d\\N\\r=n_n_Store_i1 d\" apply fastforce done\n have \"?P3 s\"\n apply (cut_tac a1 a2 , simp, rule_tac x=\"(neg (andForm (eqn (IVar (Field (Ident ''Chan2_1'') ''Cmd'')) (Const GntE)) (eqn (IVar (Field (Ident ''Cache_1'') ''State'')) (Const E))))\" in exI, auto) done\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_AStore_i1Vsinv__14:\nassumes a1: \"(\\ d. d\\N\\r=n_n_AStore_i1 d)\" and\na2: \"(f=inv__14 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain d where a1:\"d\\N\\r=n_n_AStore_i1 d\" apply fastforce done\n have \"?P3 s\"\n apply (cut_tac a1 a2 , simp, rule_tac x=\"(neg (andForm (eqn (IVar (Field (Ident ''ACache_1'') ''State'')) (Const E)) (eqn (IVar (Field (Ident ''Chan2_1'') ''Cmd'')) (Const GntE))))\" in exI, auto) done\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_SendInvE_i1Vsinv__14:\nassumes a1: \"(r=n_n_SendInvE_i1 )\" and\na2: \"(f=inv__14 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_SendInvS_i1Vsinv__14:\nassumes a1: \"(r=n_n_SendInvS_i1 )\" and\na2: \"(f=inv__14 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_SendInvAck_i1Vsinv__14:\nassumes a1: \"(r=n_n_SendInvAck_i1 )\" and\na2: \"(f=inv__14 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_SendGntS_i1Vsinv__14:\nassumes a1: \"(r=n_n_SendGntS_i1 )\" and\na2: \"(f=inv__14 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_SendGntE_i1Vsinv__14:\nassumes a1: \"(r=n_n_SendGntE_i1 )\" and\na2: \"(f=inv__14 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P3 s\"\n apply (cut_tac a1 a2 , simp, rule_tac x=\"(neg (andForm (eqn (IVar (Ident ''ExGntd'')) (Const false)) (neg (eqn (IVar (Ident ''MemData'')) (IVar (Ident ''AuxData''))))))\" in exI, auto) done\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_RecvGntS_i1Vsinv__14:\nassumes a1: \"(r=n_n_RecvGntS_i1 )\" and\na2: \"(f=inv__14 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_RecvGntE_i1Vsinv__14:\nassumes a1: \"(r=n_n_RecvGntE_i1 )\" and\na2: \"(f=inv__14 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_RecvReq_i1Vsinv__14:\n assumes a1: \"r=n_n_RecvReq_i1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_SendReqEI_i1Vsinv__14:\n assumes a1: \"r=n_n_SendReqEI_i1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendReqEI_i1Vsinv__14:\n assumes a1: \"r=n_n_ASendReqEI_i1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendReqIS_j1Vsinv__14:\n assumes a1: \"r=n_n_ASendReqIS_j1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendReqES_i1Vsinv__14:\n assumes a1: \"r=n_n_ASendReqES_i1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ARecvGntE_i1Vsinv__14:\n assumes a1: \"r=n_n_ARecvGntE_i1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendGntS_i1Vsinv__14:\n assumes a1: \"r=n_n_ASendGntS_i1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ARecvGntS_i1Vsinv__14:\n assumes a1: \"r=n_n_ARecvGntS_i1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendInvE_i1Vsinv__14:\n assumes a1: \"r=n_n_ASendInvE_i1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendInvS_i1Vsinv__14:\n assumes a1: \"r=n_n_ASendInvS_i1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_SendReqES_i1Vsinv__14:\n assumes a1: \"r=n_n_SendReqES_i1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendReqSE_j1Vsinv__14:\n assumes a1: \"r=n_n_ASendReqSE_j1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_SendReqEE_i1Vsinv__14:\n assumes a1: \"r=n_n_SendReqEE_i1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_RecvInvAck_i1Vsinv__14:\n assumes a1: \"r=n_n_RecvInvAck_i1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ARecvReq_i1Vsinv__14:\n assumes a1: \"r=n_n_ARecvReq_i1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_SendReqS_j1Vsinv__14:\n assumes a1: \"r=n_n_SendReqS_j1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ARecvInvAck_i1Vsinv__14:\n assumes a1: \"r=n_n_ARecvInvAck_i1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendInvAck_i1Vsinv__14:\n assumes a1: \"r=n_n_ASendInvAck_i1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendGntE_i1Vsinv__14:\n assumes a1: \"r=n_n_ASendGntE_i1 \" and\n a2: \"(f=inv__14 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \nend\n","avg_line_length":32.5847457627,"max_line_length":202,"alphanum_fraction":0.6940182055} {"size":22177,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/flash_data_cub_lemma_inv__103_on_rules.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The flash_data_cub Protocol Case Study*} \n\ntheory flash_data_cub_lemma_inv__103_on_rules imports flash_data_cub_lemma_on_inv__103\nbegin\nsection{*All lemmas on causal relation between inv__103*}\nlemma lemma_inv__103_on_rules:\n assumes b1: \"r \\ rules N\" and b2: \"(f=inv__103 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n proof -\n have c1: \"(\\ src data. src\\N\\data\\N\\r=n_Store src data)\\\n (\\ data. data\\N\\r=n_Store_Home data)\\\n (\\ src. src\\N\\r=n_PI_Remote_Get src)\\\n (r=n_PI_Local_Get_Get )\\\n (r=n_PI_Local_Get_Put )\\\n (\\ src. src\\N\\r=n_PI_Remote_GetX src)\\\n (r=n_PI_Local_GetX_GetX__part__0 )\\\n (r=n_PI_Local_GetX_GetX__part__1 )\\\n (r=n_PI_Local_GetX_PutX_HeadVld__part__0 N )\\\n (r=n_PI_Local_GetX_PutX_HeadVld__part__1 N )\\\n (r=n_PI_Local_GetX_PutX__part__0 )\\\n (r=n_PI_Local_GetX_PutX__part__1 )\\\n (\\ dst. dst\\N\\r=n_PI_Remote_PutX dst)\\\n (r=n_PI_Local_PutX )\\\n (\\ src. src\\N\\r=n_PI_Remote_Replace src)\\\n (r=n_PI_Local_Replace )\\\n (\\ dst. dst\\N\\r=n_NI_Nak dst)\\\n (r=n_NI_Nak_Home )\\\n (r=n_NI_Nak_Clear )\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__0 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__1 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__2 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Get__part__0 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Get__part__1 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Put_Head N src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Put src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Put_Dirty src)\\\n (\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Nak src dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_Get_Nak_Home dst)\\\n (\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Put src dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_Get_Put_Home dst)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__0 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__1 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__2 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__0 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__1 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_1 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_2 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_3 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_4 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_5 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_6 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__0 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__1 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src)\\\n (\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8 N src pp)\\\n (\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__0 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__1 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_10_Home N src)\\\n (\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_10 N src pp)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_11 N src)\\\n (\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_Nak src dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_GetX_Nak_Home dst)\\\n (\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_PutX src dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_GetX_PutX_Home dst)\\\n (r=n_NI_Local_Put )\\\n (\\ dst. dst\\N\\r=n_NI_Remote_Put dst)\\\n (r=n_NI_Local_PutXAcksDone )\\\n (\\ dst. dst\\N\\r=n_NI_Remote_PutX dst)\\\n (\\ dst. dst\\N\\r=n_NI_Inv dst)\\\n (\\ src. src\\N\\r=n_NI_InvAck_exists_Home src)\\\n (\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_InvAck_exists src pp)\\\n (\\ src. src\\N\\r=n_NI_InvAck_1 N src)\\\n (\\ src. src\\N\\r=n_NI_InvAck_2 N src)\\\n (\\ src. src\\N\\r=n_NI_InvAck_3 N src)\\\n (r=n_NI_Wb )\\\n (r=n_NI_FAck )\\\n (r=n_NI_ShWb N )\\\n (\\ src. src\\N\\r=n_NI_Replace src)\\\n (r=n_NI_Replace_Home )\"\n apply (cut_tac b1, auto) done\n moreover {\n assume d1: \"(\\ src data. src\\N\\data\\N\\r=n_Store src data)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_StoreVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ data. data\\N\\r=n_Store_Home data)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_Store_HomeVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_PI_Remote_Get src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Remote_GetVsinv__103) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_Get_Get )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_Get_GetVsinv__103) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_Get_Put )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_Get_PutVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_PI_Remote_GetX src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Remote_GetXVsinv__103) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_GetX__part__0 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_GetX__part__0Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_GetX__part__1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_GetX__part__1Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_PutX_HeadVld__part__0 N )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_PutX_HeadVld__part__0Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_PutX_HeadVld__part__1 N )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_PutX_HeadVld__part__1Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_PutX__part__0 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_PutX__part__0Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_PutX__part__1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_PutX__part__1Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_PI_Remote_PutX dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Remote_PutXVsinv__103) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_PutX )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_PutXVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_PI_Remote_Replace src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Remote_ReplaceVsinv__103) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_Replace )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_ReplaceVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Nak dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_NakVsinv__103) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Nak_Home )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Nak_HomeVsinv__103) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Nak_Clear )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Nak_ClearVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__0 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Nak__part__0Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__1 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Nak__part__1Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__2 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Nak__part__2Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Get__part__0 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Get__part__0Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Get__part__1 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Get__part__1Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Put_Head N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Put_HeadVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Put src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_PutVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Put_Dirty src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Put_DirtyVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Nak src dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_Get_NakVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_Get_Nak_Home dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_Get_Nak_HomeVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Put src dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_Get_PutVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_Get_Put_Home dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_Get_Put_HomeVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__0 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_Nak__part__0Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__1 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_Nak__part__1Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__2 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_Nak__part__2Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__0 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_GetX__part__0Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__1 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_GetX__part__1Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_1Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_2 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_2Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_3 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_3Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_4 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_4Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_5 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_5Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_6 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_6Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__0 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_7__part__0Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_7__part__1Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_7_NODE_Get__part__0Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_7_NODE_Get__part__1Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_8_HomeVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_8_Home_NODE_GetVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8 N src pp)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_8Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_8_NODE_GetVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__0 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_9__part__0Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_9__part__1Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_10_Home N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_10_HomeVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_10 N src pp)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_10Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_11 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_11Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_Nak src dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_GetX_NakVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_GetX_Nak_Home dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_GetX_Nak_HomeVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_PutX src dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_GetX_PutXVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_GetX_PutX_Home dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_GetX_PutX_HomeVsinv__103) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Local_Put )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_PutVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_Put dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_PutVsinv__103) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Local_PutXAcksDone )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_PutXAcksDoneVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_PutX dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_PutXVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Inv dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_InvAck_exists_Home src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_exists_HomeVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_InvAck_exists src pp)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_existsVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_InvAck_1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_1Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_InvAck_2 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_2Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_InvAck_3 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_3Vsinv__103) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Wb )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_WbVsinv__103) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_FAck )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_FAckVsinv__103) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_ShWb N )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_ShWbVsinv__103) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Replace src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_ReplaceVsinv__103) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Replace_Home )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Replace_HomeVsinv__103) done\n }\n\n ultimately show \"invHoldForRule s f r (invariants N)\"\n by satx\nqed\n\nend\n","avg_line_length":41.1447124304,"max_line_length":132,"alphanum_fraction":0.6643369256} {"size":1796,"ext":"thy","lang":"Isabelle","max_stars_count":1.0,"content":"theory T177\nimports Main\nbegin\nlemma \"(\n(\\ x::nat. \\ y::nat. meet(x, y) = meet(y, x)) &\n(\\ x::nat. \\ y::nat. join(x, y) = join(y, x)) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(x, meet(y, z)) = meet(meet(x, y), z)) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(x, join(y, z)) = join(join(x, y), z)) &\n(\\ x::nat. \\ y::nat. meet(x, join(x, y)) = x) &\n(\\ x::nat. \\ y::nat. join(x, meet(x, y)) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(x, join(y, z)) = join(mult(x, y), mult(x, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(join(x, y), z) = join(mult(x, z), mult(y, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(x, over(join(mult(x, y), z), y)) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(y, undr(x, join(mult(x, y), z))) = y) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(mult(over(x, y), y), x) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(mult(y, undr(y, x)), x) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(meet(x, y), z) = meet(mult(x, z), mult(y, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. undr(x, join(y, z)) = join(undr(x, y), undr(x, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. over(x, meet(y, z)) = join(over(x, y), over(x, z))) &\n(\\ x::nat. \\ y::nat. invo(join(x, y)) = meet(invo(x), invo(y))) &\n(\\ x::nat. \\ y::nat. invo(meet(x, y)) = join(invo(x), invo(y))) &\n(\\ x::nat. invo(invo(x)) = x)\n) \\\n(\\ x::nat. \\ y::nat. \\ z::nat. undr(meet(x, y), z) = join(undr(x, z), undr(y, z)))\n\"\nnitpick[card nat=4,timeout=86400]\noops\nend","avg_line_length":64.1428571429,"max_line_length":108,"alphanum_fraction":0.5339643653} {"size":91,"ext":"thy","lang":"Isabelle","max_stars_count":95.0,"content":"chapter {* Parametricity Solver *}\n(*<*)\ntheory Param_Chapter imports Main begin end\n(*>*)\n","avg_line_length":18.2,"max_line_length":43,"alphanum_fraction":0.7032967033} {"size":23691,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/n_flash_nodata_cub_lemma_on_inv__121.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_flash_nodata_cub Protocol Case Study*} \n\ntheory n_flash_nodata_cub_lemma_on_inv__121 imports n_flash_nodata_cub_base\nbegin\nsection{*All lemmas on causal relation between inv__121 and some rule r*}\nlemma n_NI_Local_Get_Put_HeadVsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Put_Head N src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_Get_Put_Head N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_Get_PutVsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Put src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_Get_Put src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_Get_Put_DirtyVsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Put_Dirty src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_Get_Put_Dirty src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_1Vsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_1 N src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_1 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_2Vsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_2 N src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_2 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_3Vsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_3 N src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_3 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_4Vsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_4 N src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_4 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_5Vsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_5 N src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_5 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_6Vsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_6 N src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_6 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_7__part__0Vsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__0 N src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_7__part__0 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_7__part__1Vsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__1 N src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_7__part__1 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_7_NODE_Get__part__0Vsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_7_NODE_Get__part__1Vsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_8_HomeVsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home N src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_8_Home N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_8_Home_NODE_GetVsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_8Vsinv__121:\nassumes a1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8 N src pp)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src pp where a1:\"src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8 N src pp\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_8_NODE_GetVsinv__121:\nassumes a1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src pp where a1:\"src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_9__part__0Vsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__0 N src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_9__part__0 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_9__part__1Vsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__1 N src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_9__part__1 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_10_HomeVsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_10_Home N src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_10_Home N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_10Vsinv__121:\nassumes a1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_10 N src pp)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src pp where a1:\"src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_10 N src pp\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_11Vsinv__121:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_11 N src)\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_11 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_PI_Local_GetX_PutX_HeadVld__part__0Vsinv__121:\nassumes a1: \"(r=n_PI_Local_GetX_PutX_HeadVld__part__0 N )\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_PI_Local_GetX_PutX_HeadVld__part__1Vsinv__121:\nassumes a1: \"(r=n_PI_Local_GetX_PutX_HeadVld__part__1 N )\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_PutXAcksDoneVsinv__121:\nassumes a1: \"(r=n_NI_Local_PutXAcksDone )\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P3 s\"\n apply (cut_tac a1 a2 , simp, rule_tac x=\"(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_PutX)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))))\" in exI, auto) done\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_WbVsinv__121:\nassumes a1: \"(r=n_NI_Wb )\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P3 s\"\n apply (cut_tac a1 a2 , simp, rule_tac x=\"(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''WbMsg'') ''Cmd'')) (Const WB_Wb))))\" in exI, auto) done\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_ShWbVsinv__121:\nassumes a1: \"(r=n_NI_ShWb N )\" and\na2: \"(f=inv__121 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P3 s\"\n apply (cut_tac a1 a2 , simp, rule_tac x=\"(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const false)) (eqn (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''Cmd'')) (Const SHWB_ShWb))))\" in exI, auto) done\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_Get_Get__part__1Vsinv__121:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Get__part__1 src\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_GetX_PutX_HomeVsinv__121:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Remote_GetX_PutX_Home dst\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Remote_GetVsinv__121:\n assumes a1: \"\\ src. src\\N\\r=n_PI_Remote_Get src\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_GetX_PutX__part__0Vsinv__121:\n assumes a1: \"r=n_PI_Local_GetX_PutX__part__0 \" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_GetX__part__1Vsinv__121:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__1 src\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_InvAck_3Vsinv__121:\n assumes a1: \"\\ src. src\\N\\r=n_NI_InvAck_3 N src\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_InvAck_1Vsinv__121:\n assumes a1: \"\\ src. src\\N\\r=n_NI_InvAck_1 N src\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_GetX_GetX__part__1Vsinv__121:\n assumes a1: \"r=n_PI_Local_GetX_GetX__part__1 \" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_GetX_GetX__part__0Vsinv__121:\n assumes a1: \"r=n_PI_Local_GetX_GetX__part__0 \" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Remote_ReplaceVsinv__121:\n assumes a1: \"\\ src. src\\N\\r=n_PI_Remote_Replace src\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_ReplaceVsinv__121:\n assumes a1: \"r=n_PI_Local_Replace \" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_Nak__part__1Vsinv__121:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__1 src\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_Get_Nak__part__1Vsinv__121:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__1 src\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_Get_Get__part__0Vsinv__121:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Get__part__0 src\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_InvAck_existsVsinv__121:\n assumes a1: \"\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_InvAck_exists src pp\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_Nak__part__2Vsinv__121:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__2 src\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Remote_PutXVsinv__121:\n assumes a1: \"\\ dst. dst\\N\\r=n_PI_Remote_PutX dst\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_Get_Put_HomeVsinv__121:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Remote_Get_Put_Home dst\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_InvVsinv__121:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Inv dst\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_PutXVsinv__121:\n assumes a1: \"r=n_PI_Local_PutX \" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_Get_Nak__part__2Vsinv__121:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__2 src\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_GetX__part__0Vsinv__121:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__0 src\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_Get_PutVsinv__121:\n assumes a1: \"r=n_PI_Local_Get_Put \" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_ReplaceVsinv__121:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Replace src\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_GetX_Nak_HomeVsinv__121:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Remote_GetX_Nak_Home dst\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_GetX_NakVsinv__121:\n assumes a1: \"\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_Nak src dst\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_NakVsinv__121:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Nak dst\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Remote_GetXVsinv__121:\n assumes a1: \"\\ src. src\\N\\r=n_PI_Remote_GetX src\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_GetX_PutX__part__1Vsinv__121:\n assumes a1: \"r=n_PI_Local_GetX_PutX__part__1 \" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_Get_Nak_HomeVsinv__121:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Remote_Get_Nak_Home dst\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_PutXVsinv__121:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Remote_PutX dst\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_PutVsinv__121:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Remote_Put dst\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_Nak__part__0Vsinv__121:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__0 src\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_InvAck_exists_HomeVsinv__121:\n assumes a1: \"\\ src. src\\N\\r=n_NI_InvAck_exists_Home src\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Replace_HomeVsinv__121:\n assumes a1: \"r=n_NI_Replace_Home \" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_GetX_PutXVsinv__121:\n assumes a1: \"\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_PutX src dst\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_PutVsinv__121:\n assumes a1: \"r=n_NI_Local_Put \" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_Get_NakVsinv__121:\n assumes a1: \"\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Nak src dst\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Nak_ClearVsinv__121:\n assumes a1: \"r=n_NI_Nak_Clear \" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_Get_Nak__part__0Vsinv__121:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__0 src\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_Get_GetVsinv__121:\n assumes a1: \"r=n_PI_Local_Get_Get \" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_Get_PutVsinv__121:\n assumes a1: \"\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Put src dst\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Nak_HomeVsinv__121:\n assumes a1: \"r=n_NI_Nak_Home \" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_InvAck_2Vsinv__121:\n assumes a1: \"\\ src. src\\N\\r=n_NI_InvAck_2 N src\" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_FAckVsinv__121:\n assumes a1: \"r=n_NI_FAck \" and\n a2: \"(f=inv__121 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \nend\n","avg_line_length":38.3349514563,"max_line_length":240,"alphanum_fraction":0.7101853024} {"size":126611,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"section {* Lemmas for Soundness Proof *}\n\ntheory Wasm_Properties imports Wasm_Properties_Aux begin\n\nsubsection {* Preservation *}\n\nlemma t_cvt: assumes \"cvt t sx v = Some v'\" shows \"t = typeof v'\"\n using assms\n unfolding cvt_def typeof_def\n apply (cases t)\n apply (simp add: option.case_eq_if, metis option.discI option.inject v.simps(17))\n apply (simp add: option.case_eq_if, metis option.discI option.inject v.simps(18))\n apply (simp add: option.case_eq_if, metis option.discI option.inject v.simps(19))\n apply (simp add: option.case_eq_if, metis option.discI option.inject v.simps(20))\n done\n\nlemma reduce_store_extension:\n assumes \"\\s;vs;es\\ \\_i \\s';vs';es'\\\"\n \"store_typing s\"\n \"inst_typing s i \\i\"\n \"s\\\\ \\ es : (ts _> ts')\"\n \"\\ = \\i\\local := local \\i @ (map typeof vs), label := arb_label, return := arb_return\\\"\n shows \"store_extension s s' \\ store_typing s'\"\n using assms\nproof (induction arbitrary: \\i \\ ts ts' arb_label arb_return rule: reduce.induct)\n case (invoke_host_Some cl t1s t2s f ves vcs n m s hs s' vcs' vs i)\n obtain ts'' where ts''_def:\"s\\\\ \\ ves : (ts _> ts'')\"\n \"s\\\\ \\ [Invoke cl] : (ts'' _> ts')\"\n using e_type_comp[OF invoke_host_Some(9)]\n by blast\n then obtain ts''' where ts'''_def:\"ts'' = ts'''@t1s\"\n using e_type_invoke_host invoke_host_Some(1)\n by blast\n hence \"s\\\\ \\ ves : ([] _> t1s)\"\n using ts'''_def invoke_host_Some(2,3,4)\n e_type_const_list[OF is_const_list[OF invoke_host_Some(2)] ts''_def(1)]\n by fastforce\n thus ?case\n using host_apply_preserve_store[OF invoke_host_Some(6)] invoke_host_Some(2,7)\n by blast\nnext\n case (set_global s i j v s' vs)\n have \"tg_t (global \\i ! j) = typeof v\"\n \"tg_mut (global \\i ! j) = T_mut\"\n \"j < length (global \\i)\"\n using types_preserved_set_global_aux(2,3,4)[OF set_global(4)] set_global(5)\n by simp_all\n thus ?case\n using update_glob_store_extension[OF set_global(2,1)]\n by (metis glob_typing_def set_global.prems(2) sglob_def store_typing_imp_glob_agree(2))\nnext\n case (store_Some t v s i j m k off mem' vs a)\n show ?case\n using store_size[OF store_Some(4)] store_max[OF store_Some(4)]\n store_typing_in_mem_agree store_Some(2,3,5,6)\n store_extension_mem_leq[OF store_Some(5,3), of mem']\n by (metis inst_typing_imp_memi_agree memi_agree_def order_refl)\nnext\n case (store_packed_Some t v s i j m k off tp mem' vs a)\n show ?case\n using store_packed_size[OF store_packed_Some(4)] store_packed_max[OF store_packed_Some(4)]\n store_typing_in_mem_agree store_packed_Some(2,3,5,6)\n store_extension_mem_leq[OF store_packed_Some(5,3), of mem']\n unfolding store_packed_def\n by (metis inst_typing_imp_memi_agree memi_agree_def order_refl)\nnext\n case (grow_memory s i j m n c mem' vs)\n have \"mem_agree m\"\n using inst_typing_imp_memi_agree[OF grow_memory(6,1)]\n unfolding memi_agree_def\n by (metis grow_memory.hyps(2) grow_memory.prems(1) list_all_length store_typing.simps)\n thus ?case\n using store_extension_mem_leq[OF grow_memory(5,2) _ _ mem_grow_max1[OF grow_memory(4)]]\n mem_grow_size[OF grow_memory(4)] mem_grow_max2[OF grow_memory(4)]\n by auto\nnext\n case (label s vs es i s' vs' es' k lholed les les')\n show ?case\n using types_exist_lfilled_weak[OF label(2,7)]\n label(4)[OF label(5,6)] label(8)\n by fastforce\nnext\n case (local s vs es i s' vs' es' v0s n j)\n obtain tls \\i' where tls_def:\"inst_typing s i \\i'\"\n \"length tls = n\"\n \"s\\\\i'\\local := local \\i' @ map typeof vs,return := Some tls\\ \\ es : ([] _> tls)\"\n \"ts' = ts @ tls\"\n using e_type_local[OF local(5)]\n by blast\n thus ?case\n using local(2)[OF local(3) tls_def(1,3), of _ \"(label \\i')\"]\n by force\nqed (auto simp add: store_extension_refl store_extension.intros)\n\nlemma store_preserved:\n assumes \"\\s;vs;es\\ \\_i \\s';vs';es'\\\"\n \"store_typing s\"\n \"s\\None \\_i vs;es : ts\"\n shows \"store_extension s s' \\ store_typing s'\"\nproof -\n obtain \\i where \\i_def:\"inst_typing s i \\i\"\n \"s\\(\\i\\local := local \\i @ map typeof vs, return := None\\) \\ es : ([] _> ts)\"\n using s_type_unfold[OF assms(3)]\n by fastforce\n thus ?thesis\n using reduce_store_extension[OF assms(1,2) \\i_def(1,2), of None \"label \\i\"]\n by fastforce\nqed\n\nlemma typeof_unop_testop:\n assumes \"s\\\\ \\ [$C v, $e] : (ts _> ts')\"\n \"(e = (Unop t uop)) \\ (e = (Testop t top'))\"\n shows \"(typeof v) = t\"\n \"e = Unop t uop \\ unop_t_agree uop t\"\n \"e = Testop t top' \\ is_int_t t\"\nproof -\n have \"\\ \\ [C v, e] : (ts _> ts')\"\n using unlift_b_e assms(1)\n by simp\n then obtain ts'' where ts''_def:\"\\ \\ [C v] : (ts _> ts'')\" \"\\ \\ [e] : (ts'' _> ts')\"\n using b_e_type_comp[where ?e = e and ?es = \"[C v]\"]\n by fastforce\n show \"(typeof v) = t\"\n \"e = Unop t uop \\ unop_t_agree uop t\"\n \"e = Testop t top' \\ is_int_t t\"\n using b_e_type_value[OF ts''_def(1)] assms(2) b_e_type_unop_testop[OF ts''_def(2)]\n by simp_all\nqed\n\nlemma typeof_cvtop:\n assumes \"s\\\\ \\ [$C v, $e] : (ts _> ts')\"\n \"e = Cvtop t1 cvtop t sx\"\n shows \"(typeof v) = t\"\n \"cvtop = Convert \\ (t1 \\ t) \\ ((sx = None) = ((is_float_t t1 \\ is_float_t t) \\ (is_int_t t1 \\ is_int_t t \\ (t_length t1 < t_length t))))\"\n \"cvtop = Reinterpret \\ (t1 \\ t) \\ t_length t1 = t_length t\"\nproof -\n have \"\\ \\ [C v, e] : (ts _> ts')\"\n using unlift_b_e assms(1)\n by simp\n then obtain ts'' where ts''_def:\"\\ \\ [C v] : (ts _> ts'')\" \"\\ \\ [e] : (ts'' _> ts')\"\n using b_e_type_comp[where ?e = e and ?es = \"[C v]\"]\n by fastforce\n show \"(typeof v) = t\"\n \"cvtop = Convert \\ (t1 \\ t) \\ (sx = None) = ((is_float_t t1 \\ is_float_t t) \\ (is_int_t t1 \\ is_int_t t \\ (t_length t1 < t_length t)))\"\n \"cvtop = Reinterpret \\ (t1 \\ t) \\ t_length t1 = t_length t\"\n using b_e_type_value[OF ts''_def(1)] b_e_type_cvtop[OF ts''_def(2) assms(2)]\n by simp_all\nqed\n\nlemma types_preserved_unop_testop_cvtop:\n assumes \"\\[$C v, $e]\\ \\ \\[$C v']\\\"\n \"s\\\\ \\ [$C v, $e] : (ts _> ts')\"\n \"(e = (Unop t op)) \\ (e = (Testop t testop)) \\ (e = (Cvtop t2 cvtop t sx))\"\n shows \"s\\\\ \\ [$C v'] : (ts _> ts')\"\nproof -\n have \"\\ \\ [C v, e] : (ts _> ts')\"\n using unlift_b_e assms(2)\n by simp\n then obtain ts'' where ts''_def:\"\\ \\ [C v] : (ts _> ts'')\" \"\\ \\ [e] : (ts'' _> ts')\"\n using b_e_type_comp[where ?e = e and ?es = \"[C v]\"]\n by fastforce\n have \"ts@[arity_1_result e] = ts'\" \"(typeof v) = t\"\n using b_e_type_value[OF ts''_def(1)] assms(3) b_e_type_unop_testop(1)[OF ts''_def(2)]\n b_e_type_cvtop(1)[OF ts''_def(2)]\n by (metis butlast_snoc, metis last_snoc)\n moreover\n have \"arity_1_result e = typeof (v')\"\n using assms(1,3) calculation(2)\n apply (cases rule: reduce_simple.cases)\n apply (simp_all add: arity_1_result_def wasm_deserialise_type t_cvt typeof_app_testop typeof_app_unop)\n done\n hence \"\\ \\ [C v'] : ([] _> [arity_1_result e])\"\n using b_e_typing.const\n by metis\n ultimately\n show \"s\\\\ \\ [$C v'] : (ts _> ts')\"\n using e_typing_s_typing.intros(1)\n b_e_typing.weakening[of \\ \"[C v']\" \"[]\" \"[arity_1_result e]\" ts]\n by fastforce\nqed\n\nlemma typeof_binop_relop:\n assumes \"s\\\\ \\ [$C v1, $C v2, $e] : (ts _> ts')\"\n \"e = Binop t bop \\ e = Relop t rop\"\n shows \"typeof v1 = t\"\n \"typeof v2 = t\"\n \"e = Binop t bop \\ binop_t_agree bop t\"\n \"e = Relop t rop \\ relop_t_agree rop t\"\nproof -\n have \"\\ \\ [C v1, C v2, e] : (ts _> ts')\"\n using unlift_b_e assms(1)\n by simp\n then obtain ts'' where ts''_def:\"\\ \\ [C v1, C v2] : (ts _> ts'')\" \"\\ \\ [e] : (ts'' _> ts')\"\n using b_e_type_comp[where ?e = e and ?es = \"[C v1, C v2]\"]\n by fastforce\n then obtain ts_id where ts_id_def:\"ts_id@[t,t] = ts''\" \"ts' = ts_id @ [arity_2_result e]\"\n \"e = Binop t bop \\ binop_t_agree bop t\"\n \"e = Relop t rop \\ relop_t_agree rop t\"\n using assms(2) b_e_type_binop_relop[of \\ e ts'' ts' t]\n by blast\n thus \"typeof v1 = t\"\n \"typeof v2 = t\"\n \"e = Binop t bop \\ binop_t_agree bop t\"\n \"e = Relop t rop \\ relop_t_agree rop t\"\n using ts''_def b_e_type_comp[of \\ \"[C v1]\" \"C v2\" ts ts''] b_e_type_value2\n by fastforce+\nqed\n\nlemma types_preserved_binop_relop:\n assumes \"\\[$C v1, $C v2, $e]\\ \\ \\[$C v']\\\"\n \"s\\\\ \\ [$C v1, $C v2, $e] : (ts _> ts')\"\n \"e = Binop t bop \\ e = Relop t rop\"\n shows \"s\\\\ \\ [$C v'] : (ts _> ts')\"\nproof -\n have \"\\ \\ [C v1, C v2, e] : (ts _> ts')\"\n using unlift_b_e assms(2)\n by simp\n then obtain ts'' where ts''_def:\"\\ \\ [C v1, C v2] : (ts _> ts'')\" \"\\ \\ [e] : (ts'' _> ts')\"\n using b_e_type_comp[where ?e = e and ?es = \"[C v1, C v2]\"]\n by fastforce\n then obtain ts_id where ts_id_def:\"ts_id@[t,t] = ts''\" \"ts' = ts_id @ [arity_2_result e]\"\n using assms(3) b_e_type_binop_relop[of \\ e ts'' ts' t]\n by blast\n hence \"\\ \\ [C v1] : (ts _> ts_id@[t])\"\n using ts''_def b_e_type_comp[of \\ \"[C v1]\" \"C v2\" ts ts''] b_e_type_value\n by fastforce\n hence \"ts@[arity_2_result e] = ts'\"\n using b_e_type_value ts_id_def(2)\n by fastforce\n moreover\n have \"arity_2_result e = typeof (v')\"\n using assms(1,3)\n unfolding arity_2_result_def\n apply (cases rule: reduce_simple.cases)\n apply (simp_all add: typeof_app_relop)\n apply (metis typeof_app_binop assms(2) typeof_binop_relop(1,2))\n done\n hence \"\\ \\ [C v'] : ([] _> [arity_2_result e])\"\n using b_e_typing.const\n by metis\n ultimately show ?thesis\n using e_typing_s_typing.intros(1)\n b_e_typing.weakening[of \\ \"[C v']\" \"[]\" \"[arity_2_result e]\" ts]\n by fastforce\nqed\n\nlemma types_preserved_drop:\n assumes \"\\[$C v, $e]\\ \\ \\[]\\\"\n \"s\\\\ \\ [$C v, $e] : (ts _> ts')\"\n \"(e = (Drop))\"\n shows \"s\\\\ \\ [] : (ts _> ts')\"\nproof -\n have \"\\ \\ [C v, e] : (ts _> ts')\"\n using unlift_b_e assms(2)\n by simp\n then obtain ts'' where ts''_def:\"\\ \\ [C v] : (ts _> ts'')\" \"\\ \\ [e] : (ts'' _> ts')\"\n using b_e_type_comp[where ?e = e and ?es = \"[C v]\"]\n by fastforce\n hence \"ts'' = ts@[typeof v]\"\n using b_e_type_value\n by blast\n hence \"ts = ts'\"\n using ts''_def assms(3) b_e_type_drop\n by blast\n hence \"\\ \\ [] : (ts _> ts')\"\n using b_e_type_empty\n by simp\n thus ?thesis\n using e_typing_s_typing.intros(1)\n by fastforce\nqed\n\nlemma types_preserved_select:\n assumes \"\\[$C v1, $C v2, $C vn, $e]\\ \\ \\[$C v3]\\\"\n \"s\\\\ \\ [$C v1, $C v2, $C vn, $e] : (ts _> ts')\"\n \"(e = Select)\"\n shows \"s\\\\ \\ [$C v3] : (ts _> ts')\"\nproof -\n have \"\\ \\ [C v1, C v2, C vn, e] : (ts _> ts')\"\n using unlift_b_e assms(2)\n by simp\n then obtain t1s where t1s_def:\"\\ \\ [C v1, C v2, C vn] : (ts _> t1s)\" \"\\ \\ [e] : (t1s _> ts')\"\n using b_e_type_comp[where ?e = e and ?es = \"[C v1, C v2, C vn]\"]\n by fastforce\n then obtain t2s t where t2s_def:\"t1s = t2s @ [t, t, (T_i32)]\" \"ts' = t2s@[t]\"\n using b_e_type_select[of \\ e t1s] assms\n by fastforce\n hence \"\\ \\ [C v1, C v2] : (ts _> t2s@[t,t])\"\n using t1s_def t2s_def b_e_type_value_list[of \\ \"[C v1, C v2]\" \"vn\" ts \"t2s@[t,t]\"]\n by fastforce\n hence v2_t_def:\"\\ \\ [C v1] : (ts _> t2s@[t])\" \"typeof v2 = t\"\n using t1s_def t2s_def b_e_type_value_list[of \\ \"[C v1]\" \"v2\" ts \"t2s@[t]\"]\n by fastforce+\n hence v1_t_def:\"ts = t2s\" \"typeof v1 = t\"\n using b_e_type_value\n by fastforce+\n have \"typeof v3 = t\"\n using assms(1) v2_t_def(2) v1_t_def(2)\n by (cases rule: reduce_simple.cases, simp_all)\n hence \"\\ \\ [C v3] : (ts _> ts')\"\n using b_e_typing.const b_e_typing.weakening t2s_def(2) v1_t_def(1)\n by fastforce\n thus ?thesis\n using e_typing_s_typing.intros(1)\n by fastforce\nqed\n\nlemma types_preserved_block:\n assumes \"\\vs @ [$Block (tn _> tm) es]\\ \\ \\[Label m [] (vs @ ($* es))]\\\"\n \"s\\\\ \\ vs @ [$Block (tn _> tm) es] : (ts _> ts')\"\n \"const_list vs\"\n \"length vs = n\"\n \"length tn = n\"\n \"length tm = m\"\n shows \"s\\\\ \\ [Label m [] (vs @ ($* es))] : (ts _> ts')\"\nproof -\n obtain \\' where c_def:\"\\' = \\\\label := [tm] @ label \\\\\" by blast\n obtain ts'' where ts''_def:\"s\\\\ \\ vs : (ts _> ts'')\" \"s\\\\ \\ [$Block (tn _> tm) es] : (ts'' _> ts')\"\n using assms(2) e_type_comp[of s \\ vs \"$Block (tn _> tm) es\" ts ts']\n by fastforce\n hence \"\\ \\ [Block (tn _> tm) es] : (ts'' _> ts')\"\n using unlift_b_e\n by auto\n then obtain ts_c tfn tfm where ts_c_def:\"(tn _> tm) = (tfn _> tfm)\" \"ts'' = ts_c@tfn\" \"ts' = ts_c@tfm\" \" (\\\\label := [tfm] @ label \\\\ \\ es : (tn _> tm))\"\n using b_e_type_block[of \\ \"Block (tn _> tm) es\" ts'' ts' \"(tn _> tm)\" es]\n by fastforce\n hence tfn_l:\"length tfn = n\"\n using assms(5)\n by simp\n obtain tvs' where tvs'_def:\"ts'' = ts@tvs'\" \"length tvs' = n\" \"s\\\\' \\ vs : ([] _> tvs')\"\n using e_type_const_list assms(3,4) ts''_def(1)\n by fastforce\n hence \"s\\\\' \\ vs : ([] _> tn)\" \"s\\\\' \\ $*es : (tn _> tm)\"\n using ts_c_def tvs'_def tfn_l ts''_def c_def e_typing_s_typing.intros(1)\n by simp_all\n hence \"s\\\\' \\ (vs @ ($* es)) : ([] _> tm)\" using e_type_comp_conc\n by simp\n moreover\n have \"s\\\\ \\ [] : (tm _> tm)\"\n using b_e_type_empty[of \\ \"[]\" \"[]\"]\n e_typing_s_typing.intros(1)[where ?b_es = \"[]\"]\n e_typing_s_typing.intros(3)[of s \\ \"[]\" \"[]\" \"[]\" \"tm\"]\n by fastforce\n ultimately\n show ?thesis\n using e_typing_s_typing.intros(7)[of s \\ \"[]\" tm _ \"vs @ ($* es)\" m]\n ts_c_def tvs'_def assms(5,6) e_typing_s_typing.intros(3) c_def\n by fastforce\nqed\n\nlemma types_preserved_if:\n assumes \"\\[$C ConstInt32 n, $If tf e1s e2s]\\ \\ \\[$Block tf es']\\\"\n \"s\\\\ \\ [$C ConstInt32 n, $If tf e1s e2s] : (ts _> ts')\"\n shows \"s\\\\ \\ [$Block tf es'] : (ts _> ts')\"\nproof -\n have \"\\ \\ [C ConstInt32 n, If tf e1s e2s] : (ts _> ts')\"\n using unlift_b_e assms(2)\n by fastforce\n then obtain ts_i where ts_i_def:\"\\ \\ [C ConstInt32 n] : (ts _> ts_i)\" \"\\ \\ [If tf e1s e2s] : (ts_i _> ts')\"\n using b_e_type_comp\n by (metis append_Cons append_Nil)\n then obtain ts'' tfn tfm where ts_def:\"tf = (tfn _> tfm)\"\n \"ts_i = ts''@tfn @ [T_i32]\"\n \"ts' = ts''@tfm\"\n \"(\\\\label := [tfm] @ label \\\\ \\ e1s : tf)\"\n \"(\\\\label := [tfm] @ label \\\\ \\ e2s : tf)\"\n using b_e_type_if[of \\ \"If tf e1s e2s\"]\n by fastforce\n have \"ts_i = ts @ [(T_i32)]\"\n using ts_i_def(1) b_e_type_value\n unfolding typeof_def\n by fastforce\n moreover\n have \"(\\\\label := [tfm] @ label \\\\ \\ es' : (tfn _> tfm))\"\n using assms(1) ts_def(4,5) ts_def(1)\n by (cases rule: reduce_simple.cases, simp_all)\n hence \"\\ \\ [Block tf es'] : (tfn _> tfm)\"\n using ts_def(1) b_e_typing.block[of tf tfn tfm \\ es']\n by simp\n ultimately\n show ?thesis\n using ts_def(2,3) e_typing_s_typing.intros(1,3)\n by fastforce\nqed\n\nlemma types_preserved_tee_local:\n assumes \"\\[v, $Tee_local i]\\ \\ \\[v, v, $Set_local i]\\\"\n \"s\\\\ \\ [v, $Tee_local i] : (ts _> ts')\"\n \"is_const v\"\n shows \"s\\\\ \\ [v, v, $Set_local i] : (ts _> ts')\"\nproof -\n obtain bv where bv_def:\"v = $C bv\"\n using e_type_const_unwrap assms(3)\n by fastforce\n hence \"\\ \\ [C bv, Tee_local i] : (ts _> ts')\"\n using unlift_b_e assms(2)\n by fastforce\n then obtain ts'' where ts''_def:\"\\ \\ [C bv] : (ts _> ts'')\" \"\\ \\ [Tee_local i] : (ts'' _> ts')\"\n using b_e_type_comp[of _ \"[C bv]\" \"Tee_local i\"]\n by fastforce\n then obtain ts_c t where ts_c_def:\"ts'' = ts_c@[t]\" \"ts' = ts_c@[t]\" \"(local \\)!i = t\" \"i < length(local \\)\"\n using b_e_type_tee_local[of \\ \"Tee_local i\" ts'' ts' i]\n by fastforce\n hence t_bv:\"t = typeof bv\" \"ts = ts_c\"\n using b_e_type_value ts''_def\n by fastforce+\n have \"\\ \\ [Set_local i] : ([t,t] _> [t])\"\n using ts_c_def(3,4) b_e_typing.set_local[of i \\ t]\n b_e_typing.weakening[of \\ \"[Set_local i]\" \"[t]\" \"[]\" \"[t]\"]\n by fastforce\n moreover\n have \"\\ \\ [C bv] : ([t] _> [t,t])\"\n using t_bv b_e_typing.const[of \\ bv] b_e_typing.weakening[of \\ \"[C bv]\" \"[]\" \"[t]\" \"[t]\"]\n by fastforce\n hence \"\\ \\ [C bv, C bv] : ([] _> [t,t])\"\n using t_bv b_e_typing.const[of \\ bv] b_e_typing.composition[of \\ \"[C bv]\" \"[]\" \"[t]\"]\n by fastforce\n ultimately\n have \"\\ \\ [C bv, C bv, Set_local i] : (ts _> ts@[t])\"\n using b_e_typing.composition b_e_typing.weakening[of \\ \"[C bv, C bv, Set_local i]\"]\n by fastforce\n thus ?thesis\n using t_bv(2) ts_c_def(2) bv_def e_typing_s_typing.intros(1)\n by fastforce\nqed\n\nlemma types_preserved_loop:\n assumes \"\\vs @ [$Loop (t1s _> t2s) es]\\ \\ \\[Label n [$Loop (t1s _> t2s) es] (vs @ ($* es))]\\\"\n \"s\\\\ \\ vs @ [$Loop (t1s _> t2s) es] : (ts _> ts')\"\n \"const_list vs\"\n \"length vs = n\"\n \"length t1s = n\"\n \"length t2s = m\"\n shows \"s\\\\ \\ [Label n [$Loop (t1s _> t2s) es] (vs @ ($* es))] : (ts _> ts')\"\nproof -\n obtain ts'' where ts''_def:\"s\\\\ \\ vs : (ts _> ts'')\" \"s\\\\ \\ [$Loop (t1s _> t2s) es] : (ts'' _> ts')\"\n using assms(2) e_type_comp\n by fastforce\n then have \"\\ \\ [Loop (t1s _> t2s) es] : (ts'' _> ts')\"\n using unlift_b_e assms(2)\n by fastforce\n then obtain ts_c tfn tfm \\' where t_loop:\"(t1s _> t2s) = (tfn _> tfm)\"\n \"(ts'' = ts_c@tfn)\"\n \"(ts' = ts_c@tfm)\"\n \"\\' = \\\\label := [t1s] @ label \\\\\"\n \"(\\' \\ es : (tfn _> tfm))\"\n using b_e_type_loop[of \\ \"Loop (t1s _> t2s) es\" ts'' ts']\n by fastforce\n obtain tvs where tvs_def:\"ts'' = ts @ tvs\" \"length vs = length tvs\" \"s\\\\' \\ vs : ([] _> tvs)\"\n using e_type_const_list assms(3) ts''_def(1)\n by fastforce\n then have tvs_eq:\"tvs = t1s\" \"tfn = t1s\"\n using assms(4,5) t_loop(1,2)\n by simp_all\n have \"s\\\\ \\ [$Loop (t1s _> t2s) es] : (t1s _> t2s)\"\n using t_loop b_e_typing.loop e_typing_s_typing.intros(1)\n by fastforce\n moreover\n have \"s\\\\' \\ $*es : (t1s _> t2s)\"\n using t_loop e_typing_s_typing.intros(1)\n by fastforce\n then have \"s\\\\' \\ vs@($*es) : ([] _> t2s)\"\n using tvs_eq tvs_def(3) e_type_comp_conc\n by blast\n ultimately\n have \"s\\\\ \\ [Label n [$Loop (t1s _> t2s) es] (vs @ ($* es))] : ([] _> t2s)\"\n using e_typing_s_typing.intros(7)[of s \\ \"[$Loop (t1s _> t2s) es]\" t1s t2s \"vs @ ($* es)\"]\n t_loop(4) assms(5)\n by fastforce\n then show ?thesis\n using t_loop e_typing_s_typing.intros(3) tvs_def(1) tvs_eq(1)\n by fastforce\nqed\n\nlemma types_preserved_label_value:\n assumes \"\\[Label n es0 vs]\\ \\ \\vs\\\"\n \"s\\\\ \\ [Label n es0 vs] : (ts _> ts')\"\n \"const_list vs\"\n shows \"s\\\\ \\ vs : (ts _> ts')\"\nproof -\n obtain tls t2s where t2s_def:\"(ts' = (ts@t2s))\"\n \"(s\\\\ \\ es0 : (tls _> t2s))\"\n \"(s\\\\\\label := [tls] @ (label \\)\\ \\ vs : ([] _> t2s))\"\n using assms e_type_label\n by fastforce\n thus ?thesis\n using e_type_const_list[of vs s \"\\\\label := [tls] @ (label \\)\\\" \"[]\" t2s]\n assms(3) e_typing_s_typing.intros(3)\n by fastforce\nqed\n\nlemma types_preserved_br_if:\n assumes \"\\[$C ConstInt32 n, $Br_if i]\\ \\ \\e\\\"\n \"s\\\\ \\ [$C ConstInt32 n, $Br_if i] : (ts _> ts')\"\n \"e = [$Br i] \\ e = []\"\n shows \"s\\\\ \\ e : (ts _> ts')\"\nproof -\n have \"\\ \\ [C ConstInt32 n, Br_if i] : (ts _> ts')\"\n using unlift_b_e assms(2)\n by fastforce\n then obtain ts'' where ts''_def:\"\\ \\ [C ConstInt32 n] : (ts _> ts'')\" \"\\ \\ [Br_if i] : (ts'' _> ts')\"\n using b_e_type_comp[of _ \"[C ConstInt32 n]\" \"Br_if i\"]\n by fastforce\n then obtain ts_c ts_b where ts_bc_def:\"i < length(label \\)\"\n \"ts'' = ts_c @ ts_b @ [T_i32]\"\n \"ts' = ts_c @ ts_b\"\n \"(label \\)!i = ts_b\"\n using b_e_type_br_if[of \\ \"Br_if i\" ts'' ts' i]\n by fastforce\n hence ts_def:\"ts = ts_c @ ts_b\"\n using ts''_def(1) b_e_type_value\n by fastforce\n show ?thesis\n using assms(3)\n proof (rule disjE)\n assume \"e = [$Br i]\"\n thus ?thesis\n using ts_def e_typing_s_typing.intros(1) b_e_typing.br ts_bc_def\n by fastforce\n next\n assume \"e = []\"\n thus ?thesis\n using ts_def b_e_type_empty ts_bc_def(3)\n e_typing_s_typing.intros(1)[of _ \"[]\" \"(ts _> ts')\"]\n by fastforce\n qed\nqed\n\nlemma types_preserved_br_table:\n assumes \"\\[$C ConstInt32 c, $Br_table is i]\\ \\ \\[$Br i']\\\"\n \"s\\\\ \\ [$C ConstInt32 c, $Br_table is i] : (ts _> ts')\"\n \"(i' = (is ! nat_of_int c) \\ length is > nat_of_int c) \\ i' = i\"\n shows \"s\\\\ \\ [$Br i'] : (ts _> ts')\"\nproof -\n have \"\\ \\ [C ConstInt32 c, Br_table is i] : (ts _> ts')\"\n using unlift_b_e assms(2)\n by fastforce\n then obtain ts'' where ts''_def:\"\\ \\ [C ConstInt32 c] : (ts _> ts'')\" \"\\ \\ [Br_table is i] : (ts'' _> ts')\"\n using b_e_type_comp[of _ \"[C ConstInt32 c]\" \"Br_table is i\"]\n by fastforce\n then obtain ts_l ts_c where ts_c_def:\"list_all (\\i. i < length(label \\) \\ (label \\)!i = ts_l) (is@[i])\"\n \"ts'' = ts_c @ ts_l@[T_i32]\"\n using b_e_type_br_table[of \\ \"Br_table is i\" ts'' ts']\n by fastforce\n hence ts_def:\"ts = ts_c @ ts_l\"\n using ts''_def(1) b_e_type_value\n by fastforce\n have \"\\ \\ [Br i'] : (ts _> ts')\"\n using assms(3) ts_c_def(1,2) b_e_typing.br[of i' \\ ts_l ts_c ts'] ts_def\n unfolding list_all_length\n by (fastforce simp add: less_Suc_eq nth_append)\n thus ?thesis\n using e_typing_s_typing.intros(1)\n by fastforce\nqed\n\nlemma types_preserved_local_const:\n assumes \"\\[Local n i vs es]\\ \\ \\es\\\"\n \"s\\\\ \\ [Local n i vs es] : (ts _> ts')\"\n \"const_list es\"\n shows \"s\\\\ \\ es: (ts _> ts')\"\nproof -\n obtain tls \\i where \"(s\\\\i\\local := (local \\i) @ (map typeof vs), return := Some tls\\ \\ es : ([] _> tls))\"\n \"ts' = ts @ tls\"\n using e_type_local[OF assms(2)]\n by blast+\n moreover\n then have \"s\\\\ \\ es : ([] _> tls)\"\n using assms(3) e_type_const_list\n by fastforce\n ultimately\n show ?thesis\n using e_typing_s_typing.intros(3)\n by fastforce\nqed\n\nlemma typing_map_typeof:\n assumes \"ves = $$* vs\"\n \"s\\\\ \\ ves : ([] _> tvs)\"\n shows \"tvs = map typeof vs\"\n using assms\nproof (induction ves arbitrary: vs tvs rule: List.rev_induct)\n case Nil\n hence \"\\ \\ [] : ([] _> tvs)\"\n using unlift_b_e\n by auto\n thus ?case\n using Nil\n by auto\nnext\n case (snoc a ves)\n obtain vs' v' where vs'_def:\"ves @ [a] = $$* (vs'@[v'])\" \"vs = vs'@[v']\"\n using snoc(2)\n by (metis Nil_is_map_conv append_is_Nil_conv list.distinct(1) rev_exhaust)\n obtain tvs' where tvs'_def:\"s\\\\ \\ ves: ([] _> tvs')\" \"s\\\\ \\ [a] : (tvs' _> tvs)\"\n using snoc(3) e_type_comp\n by fastforce\n hence \"tvs' = map typeof vs'\"\n using snoc(1) vs'_def\n by fastforce\n moreover\n have \"is_const a\"\n using vs'_def\n unfolding is_const_def\n by auto\n then obtain t where t_def:\"tvs = tvs' @ [t]\" \"s\\\\ \\ [a] : ([] _> [t])\"\n using tvs'_def(2) e_type_const[of a s \\ tvs' tvs]\n by fastforce\n have \"a = $ C v'\"\n using vs'_def(1)\n by auto\n hence \"t = typeof v'\"\n using t_def unlift_b_e[of s \\ \"[C v']\" \"([] _> [t])\"] b_e_type_value[of \\ \"C v'\" \"[]\" \"[t]\" v']\n by fastforce\n ultimately\n show ?case\n using vs'_def t_def\n by simp\nqed\n\nlemma types_preserved_call_indirect_Some:\n assumes \"s\\\\ \\ [$C ConstInt32 c, $Call_indirect j] : (ts _> ts')\"\n \"stab s i' (nat_of_int c) = Some cl\"\n \"stypes s i' j = tf\"\n \"cl_type cl = tf\"\n \"store_typing s\"\n \"inst_typing s i' \\i\"\n \"\\ = \\i\\local := local \\i @ tvs, label := arb_labs, return := arb_return\\\"\n shows \"s\\\\ \\ [Invoke cl] : (ts _> ts')\"\nproof -\n obtain t1s t2s where tf_def:\"tf = (t1s _> t2s)\"\n using tf.exhaust by blast\n obtain ts'' where ts''_def:\"\\ \\ [C ConstInt32 c] : (ts _> ts'')\"\n \"\\ \\ [Call_indirect j] : (ts'' _> ts')\"\n using e_type_comp[of s \\ \"[$C ConstInt32 c]\" \"$Call_indirect j\" ts ts']\n assms(1)\n unlift_b_e[of s \\ \"[C ConstInt32 c]\"]\n unlift_b_e[of s \\ \"[Call_indirect j]\"]\n by fastforce\n hence \"ts'' = ts@[(T_i32)]\"\n using b_e_type_value\n unfolding typeof_def\n by fastforce\n moreover\n obtain ts''a where ts''a_def:\"j < length (types_t \\)\"\n \"ts'' = ts''a @ t1s @ [T_i32]\"\n \"ts' = ts''a @ t2s\"\n \"types_t \\ ! j = (t1s _> t2s)\"\n using b_e_type_call_indirect[OF ts''_def(2), of j] tf_def assms(3,7)\n store_typing_imp_types_eq[OF assms(6)]\n unfolding stypes_def\n by fastforce\n moreover\n obtain tf' where tf'_def:\"cl_typing s cl tf'\"\n using assms(2,5,6) stab_typed_some_imp_cl_typed\n by blast\n hence \"cl_typing s cl tf\"\n using assms(4)\n unfolding cl_typing.simps cl_type_def\n by auto\n hence \"s\\\\ \\ [Invoke cl] : tf\"\n using e_typing_s_typing.intros(6) assms(6,7) ts''a_def(1)\n by fastforce\n ultimately\n show \"s\\\\ \\ [Invoke cl] : (ts _> ts')\"\n using tf_def e_typing_s_typing.intros(3)\n by auto\nqed\n\nlemma types_preserved_call_indirect_None:\n assumes \"s\\\\ \\ [$C ConstInt32 c, $Call_indirect j] : (ts _> ts')\"\n shows \"s\\\\ \\ [Trap] : (ts _> ts')\"\n using e_typing_s_typing.intros(4)\n by blast\n\nlemma types_preserved_invoke_native:\n assumes \"s\\\\ \\ ves @ [Invoke cl] : (ts _> ts')\"\n \"cl = Func_native i (t1s _> t2s) tfs es\"\n \"ves = $$* vs\"\n \"length vs = n\"\n \"length tfs = k\"\n \"length t1s = n\"\n \"length t2s = m\"\n \"n_zeros tfs = zs\"\n \"store_typing s\"\n shows \"s\\\\ \\ [Local m i (vs @ zs) [$Block ([] _> t2s) es]] : (ts _> ts')\"\nproof -\n obtain ts'' where ts''_def:\"s\\\\ \\ ves : (ts _> ts'')\" \"s\\\\ \\ [Invoke cl] : (ts'' _> ts')\"\n using assms(1) e_type_comp\n by fastforce\n have ves_c:\"const_list ves\"\n using is_const_list[OF assms(3)]\n by simp\n then obtain tvs where tvs_def:\"ts'' = ts @ tvs\"\n \"length t1s = length tvs\"\n \"s\\\\ \\ ves : ([] _> tvs)\"\n using ts''_def(1) e_type_const_list[of ves s \\ ts ts''] assms\n by fastforce \n obtain ts_c \\' where ts_c_def:\"(ts'' = ts_c @ t1s)\"\n \"(ts' = ts_c @ t2s)\"\n \"inst_typing s i \\'\"\n \"(\\'\\local := (local \\') @ t1s @ tfs, label := ([t2s] @ (label \\')), return := Some t2s\\ \\ es : ([] _> t2s))\"\n using e_type_invoke_native[OF ts''_def(2) assms(2)]\n by fastforce\n obtain \\'' where c''_def:\"\\'' = \\'\\local := (local \\') @ t1s @ tfs, return := Some t2s\\\"\n by blast\n hence \"\\''\\label := ([t2s] @ (label \\''))\\ = \\'\\local := (local \\') @ t1s @ tfs, label := ([t2s] @ (label \\')), return := Some t2s\\\"\n by fastforce\n hence \"s\\\\'' \\ [$Block ([] _> t2s) es] : ([] _> t2s)\"\n using ts_c_def b_e_typing.block[of \"([] _> t2s)\" \"[]\" \"t2s\" _ es] e_typing_s_typing.intros(1)[of _ \"[Block ([] _> t2s) es]\"]\n by fastforce\n moreover\n have t_eqs:\"ts = ts_c\" \"t1s = tvs\"\n using tvs_def(1,2) ts_c_def(1)\n by simp_all\n have 1:\"tfs = map typeof zs\"\n using n_zeros_typeof assms(8)\n by (simp add: n_zeros_typeof)\n have \"t1s = map typeof vs\"\n using typing_map_typeof assms(3) tvs_def t_eqs\n by fastforce\n hence \"(t1s @ tfs) = map typeof (vs @ zs)\"\n using 1\n by simp\n ultimately\n have \"s\\Some t2s \\_i (vs @ zs);([$Block ([] _> t2s) es]) : t2s\"\n using e_typing_s_typing.intros(8) ts_c_def c''_def\n by fastforce\n thus ?thesis\n using e_typing_s_typing.intros(3,5) ts_c_def t_eqs(1) assms(2,7)\n by fastforce\nqed\n\nlemma types_preserved_invoke_host_some:\n assumes \"s\\\\ \\ ves @ [Invoke cl] : (ts _> ts')\"\n \"cl = Func_host (t1s _> t2s) f\"\n \"ves = $$* vcs\"\n \"length vcs = n\"\n \"length t1s = n\"\n \"length t2s = m\"\n \"host_apply s (t1s _> t2s) f vcs hs = Some (s', vcs')\"\n \"store_typing s\"\n shows \"s'\\\\ \\ $$* vcs' : (ts _> ts')\"\nproof -\n obtain ts'' where ts''_def:\"s\\\\ \\ ves : (ts _> ts'')\" \"s\\\\ \\ [Invoke cl] : (ts'' _> ts')\"\n using assms(1) e_type_comp\n by fastforce\n have ves_c:\"const_list ves\"\n using is_const_list[OF assms(3)]\n by simp\n then obtain tvs where tvs_def:\"ts'' = ts @ tvs\"\n \"length t1s = length tvs\"\n \"s\\\\ \\ ves : ([] _> tvs)\"\n using ts''_def(1) e_type_const_list[of ves s \\ ts ts''] assms\n by fastforce\n hence \"ts'' = ts @ t1s\"\n \"ts' = ts @ t2s\"\n using e_type_invoke_host[OF ts''_def(2) assms(2)]\n by auto\n moreover\n hence \"list_all2 types_agree t1s vcs\"\n using e_typing_imp_list_types_agree[where ?ts' = \"[]\"] assms(3) tvs_def(1,3)\n by fastforce\n hence \"s'\\\\ \\ $$* vcs' : ([] _> t2s)\"\n using list_types_agree_imp_e_typing host_apply_respect_type[OF _ assms(7)]\n by fastforce\n ultimately\n show ?thesis\n using e_typing_s_typing.intros(3)\n by fastforce\nqed\n\nlemma types_imp_concat:\n assumes \"s\\\\ \\ es @ [e] @ es' : (ts _> ts')\"\n \"\\tes tes'. ((s\\\\ \\ [e] : (tes _> tes')) \\ (s\\\\ \\ [e'] : (tes _> tes')))\"\n shows \"s\\\\ \\ es @ [e'] @ es' : (ts _> ts')\"\nproof -\n obtain ts'' where \"s\\\\ \\ es : (ts _> ts'')\"\n \"s\\\\ \\ [e] @ es' : (ts'' _> ts')\"\n using e_type_comp_conc1[of _ _ es \"[e] @ es'\"] assms(1)\n by fastforce\n moreover\n then obtain ts''' where \"s\\\\ \\ [e] : (ts'' _> ts''')\" \"s\\\\ \\ es' : (ts''' _> ts')\"\n using e_type_comp_conc1[of _ _ \"[e]\" es' ts'' ts'] assms\n by fastforce\n ultimately\n show ?thesis\n using assms(2) e_type_comp_conc[of _ _ es ts ts'' \"[e']\" ts''']\n e_type_comp_conc[of _ _ \"es @ [e']\" ts ts''']\n by fastforce\nqed\n\nlemma type_const_return:\n assumes \"Lfilled i lholed (vs @ [$Return]) LI\"\n \"(return \\) = Some tcs\"\n \"length tcs = length vs\"\n \"s\\\\ \\ LI : (ts _> ts')\"\n \"const_list vs\"\n shows \"s\\\\' \\ vs : ([] _> tcs)\"\n using assms\nproof (induction i arbitrary: ts ts' lholed \\ LI \\')\n case 0\n obtain vs' es' where \"LI = (vs' @ (vs @ [$Return]) @ es')\"\n using Lfilled.simps[of 0 lholed \"(vs @ [$Return])\" LI] 0(1)\n by fastforce\n then obtain ts'' ts''' where \"s\\\\ \\ vs' : (ts _> ts'')\"\n \"s\\\\ \\ (vs @ [$Return]) : (ts'' _> ts''')\"\n \"s\\\\ \\ es' : (ts''' _> ts')\"\n using e_type_comp_conc2[of s \\ vs' \"(vs @ [$Return])\" es'] 0(4)\n by fastforce\n then obtain ts_b where ts_b_def:\"s\\\\ \\ vs : (ts'' _> ts_b)\" \"s\\\\ \\ [$Return] : (ts_b _> ts''')\"\n using e_type_comp_conc1\n by fastforce\n then obtain ts_c where ts_c_def:\"ts_b = ts_c @ tcs\" \"(return \\) = Some tcs\"\n using 0(2) b_e_type_return[of \\] unlift_b_e[of s \\ \"[Return]\" \"ts_b _> ts'''\"]\n by fastforce\n obtain tcs' where \"ts_b = ts'' @ tcs'\" \"length vs = length tcs'\" \"s\\\\' \\ vs : ([] _> tcs')\"\n using ts_b_def(1) e_type_const_list 0(5)\n by fastforce\n thus ?case\n using 0(3) ts_c_def\n by simp\nnext\n case (Suc i)\n obtain vs' n l les les' LK where es_def:\"lholed = (LRec vs' n les l les')\"\n \"Lfilled i l (vs @ [$Return]) LK\"\n \"LI = (vs' @ [Label n les LK] @ les')\"\n using Lfilled.simps[of \"(Suc i)\" lholed \"(vs @ [$Return])\" LI] Suc(2)\n by fastforce\n then obtain ts'' ts''' where \"s\\\\ \\ [Label n les LK] : (ts'' _> ts''')\"\n using e_type_comp_conc2[of s \\ vs' \"[Label n les LK]\" les'] Suc(5)\n by fastforce\n then obtain tls t2s where\n \"ts''' = ts'' @ t2s\"\n \"length tls = n\"\n \"s\\\\ \\ les : (tls _> t2s)\"\n \"s\\\\\\label := [tls] @ label \\\\ \\ LK : ([] _> t2s)\"\n \"return (\\\\label := [tls] @ label \\\\) = Some tcs\"\n using e_type_label[of s \\ n les LK ts'' ts'''] Suc(3)\n by fastforce\n then show ?case\n using Suc(1)[OF es_def(2) _ assms(3) _ assms(5)]\n by fastforce\nqed\n\nlemma types_preserved_return:\n assumes \"\\[Local n i vls LI]\\ \\ \\ves\\\"\n \"s\\\\ \\ [Local n i vls LI] : (ts _> ts')\"\n \"const_list ves\"\n \"length ves = n\"\n \"Lfilled j lholed (ves @ [$Return]) LI\"\n shows \"s\\\\ \\ ves : (ts _> ts')\"\nproof -\n obtain tls \\' \\i where l_def:\n \"inst_typing s i \\i\"\n \"\\' = \\i\\local := (local \\i) @ (map typeof vls), return := Some tls\\\"\n \"s\\\\' \\ LI : ([] _> tls)\"\n \"ts' = ts @ tls\"\n \"length tls = n\"\n using e_type_local[OF assms(2)]\n by blast\n hence \"s\\\\ \\ ves : ([] _> tls)\"\n using type_const_return[OF assms(5) _ _ l_def(3)] assms(3-5)\n by fastforce\n thus ?thesis\n using e_typing_s_typing.intros(3) l_def(4)\n by fastforce\nqed\n\nlemma type_const_br:\n assumes \"Lfilled i lholed (vs @ [$Br (i+k)]) LI\"\n \"length (label \\) > k\"\n \"(label \\)!k = tcs\"\n \"length tcs = length vs\"\n \"s\\\\ \\ LI : (ts _> ts')\"\n \"const_list vs\"\n shows \"s\\\\' \\ vs : ([] _> tcs)\"\n using assms\nproof (induction i arbitrary: k ts ts' lholed \\ LI \\')\n case 0\n obtain vs' es' where \"LI = (vs' @ (vs @ [$Br (0+k)]) @ es')\"\n using Lfilled.simps[of 0 lholed \"(vs @ [$Br (0 + k)])\" LI] 0(1)\n by fastforce\n then obtain ts'' ts''' where \"s\\\\ \\ vs' : (ts _> ts'')\"\n \"s\\\\ \\ (vs @ [$Br (0+k)]) : (ts'' _> ts''')\"\n \"s\\\\ \\ es' : (ts''' _> ts')\"\n using e_type_comp_conc2[of s \\ vs' \"(vs @ [$Br (0+k)])\" es'] 0(5)\n by fastforce\n then obtain ts_b where ts_b_def:\"s\\\\ \\ vs : (ts'' _> ts_b)\" \"s\\\\ \\ [$Br (0+k)] : (ts_b _> ts''')\"\n using e_type_comp_conc1\n by fastforce\n then obtain ts_c where ts_c_def:\"ts_b = ts_c @ tcs\" \"(label \\)!k = tcs\"\n using 0(3) b_e_type_br[of \\ \"Br (0 + k)\"] unlift_b_e[of s \\ \"[Br (0 + k)]\" \"ts_b _> ts'''\"]\n by fastforce\n obtain tcs' where \"ts_b = ts'' @ tcs'\" \"length vs = length tcs'\" \"s\\\\' \\ vs : ([] _> tcs')\"\n using ts_b_def(1) e_type_const_list 0(6)\n by fastforce\n thus ?case\n using 0(4) ts_c_def\n by simp\nnext\n case (Suc i k ts ts' lholed \\ LI)\n obtain vs' n l les les' LK where es_def:\"lholed = (LRec vs' n les l les')\"\n \"Lfilled i l (vs @ [$Br (i + (Suc k))]) LK\"\n \"LI = (vs' @ [Label n les LK] @ les')\"\n using Lfilled.simps[of \"(Suc i)\" lholed \"(vs @ [$Br ((Suc i) + k)])\" LI] Suc(2)\n by fastforce\n then obtain ts'' ts''' where \"s\\\\ \\ [Label n les LK] : (ts'' _> ts''')\"\n using e_type_comp_conc2[of s \\ vs' \"[Label n les LK]\" les'] Suc(6)\n by fastforce\n moreover\n then obtain lts \\'' ts'''' where \"s\\\\'' \\ LK : ([] _> ts'''')\" \"\\'' = \\\\label := [lts] @ (label \\)\\\"\n \"length (label \\'') > (Suc k)\"\n \"(label \\'')!(Suc k) = tcs\"\n using e_type_label[of s \\ n les LK ts'' ts'''] Suc(3,4)\n by fastforce\n then show ?case\n using Suc(1) es_def(2) assms(4,6)\n by fastforce\nqed\n\nlemma types_preserved_br:\n assumes \"\\[Label n es0 LI]\\ \\ \\vs @ es0\\\"\n \"s\\\\ \\ [Label n es0 LI] : (ts _> ts')\"\n \"const_list vs\"\n \"length vs = n\"\n \"Lfilled i lholed (vs @ [$Br i]) LI\"\n shows \"s\\\\ \\ (vs @ es0) : (ts _> ts')\"\nproof -\n obtain tls t2s \\' where l_def:\"(ts' = (ts@t2s))\"\n \"(s\\\\ \\ es0 : (tls _> t2s))\"\n \"\\' = \\\\label := [tls] @ (label \\)\\\"\n \"length (label \\') > 0\"\n \"(label \\')!0 = tls\"\n \"length tls = n\"\n \"(s\\\\\\label := [tls] @ (label \\)\\ \\ LI : ([] _> t2s))\"\n using e_type_label[of s \\ n es0 LI ts ts'] assms(2)\n by fastforce\n hence \"s\\\\ \\ vs : ([] _> tls)\"\n using assms(3-5) type_const_br[of i lholed vs 0 LI \\' tls]\n by fastforce\n thus ?thesis\n using l_def(1,2) e_type_comp_conc e_typing_s_typing.intros(3)\n by fastforce\nqed\n\nlemma store_local_label_empty:\n assumes \"inst_typing s i \\\"\n shows \"label \\ = []\" \"local \\ = []\"\n using assms\n unfolding inst_typing.simps\n by auto\n\nlemma types_preserved_b_e1:\n assumes \"\\es\\ \\ \\es'\\\"\n \"store_typing s\"\n \"s\\\\ \\ es : (ts _> ts')\"\n shows \"s\\\\ \\ es' : (ts _> ts')\"\n using assms(1)\nproof (cases rule: reduce_simple.cases)\n case (unop c oop)\n thus ?thesis\n using assms(1,3) types_preserved_unop_testop_cvtop\n by simp\nnext\n case (binop_Some op c1 c2 c)\n thus ?thesis\n using assms(1, 3) types_preserved_binop_relop\n by simp\nnext\n case (binop_None op c1 c2)\n then show ?thesis\n by (simp add: e_typing_s_typing.intros(4))\nnext\n case (testop c testop)\n then show ?thesis\n using assms(1, 3) types_preserved_unop_testop_cvtop\n by simp\nnext\n case (relop c1 c2 op)\n then show ?thesis\n using assms(1, 3) types_preserved_binop_relop\n by simp\nnext\n case (convert_Some t1 v t2 sx v')\n then show ?thesis\n using assms(1, 3) types_preserved_unop_testop_cvtop\n by simp\nnext\n case (convert_None t1 v t2 sx)\n then show ?thesis\n using e_typing_s_typing.intros(4)\n by simp\nnext\n case (reinterpret t1 v t2)\n then show ?thesis\n using assms(1, 3) types_preserved_unop_testop_cvtop\n by simp\nnext\n case unreachable\n then show ?thesis\n using e_typing_s_typing.intros(4)\n by simp\nnext\n case nop\n then have \"\\ \\ [Nop] : (ts _> ts')\"\n using assms(3) unlift_b_e\n by simp\n then show ?thesis\n using nop b_e_typing.empty e_typing_s_typing.intros(1,3)\n apply (induction \"[Nop]\" \"ts _> ts'\" arbitrary: ts ts')\n apply simp_all\n apply (metis list.simps(8))\n apply blast\n done\nnext\n case (drop v)\n then show ?thesis\n using assms(1, 3) types_preserved_drop\n by simp\nnext\n case (select_false v1 v2)\n then show ?thesis\n using assms(1, 3) types_preserved_select\n by simp\nnext\n case (select_true n v1 v2)\n then show ?thesis\n using assms(1, 3) types_preserved_select\n by simp\nnext\n case (block vs n t1s t2s m es)\n then show ?thesis\n using assms(1, 3) types_preserved_block\n by simp\nnext\n case (loop vs n t1s t2s m es)\n then show ?thesis\n using assms(1, 3) types_preserved_loop\n by simp\nnext\n case (if_false tf e1s e2s)\n then show ?thesis\n using assms(1, 3) types_preserved_if\n by simp\nnext\n case (if_true n tf e1s e2s)\n then show ?thesis\n using assms(1, 3) types_preserved_if\n by simp\nnext\n case (label_const ts es)\n then show ?thesis\n using assms(1, 3) types_preserved_label_value\n by simp\nnext\n case (label_trap ts es)\n then show ?thesis\n by (simp add: e_typing_s_typing.intros(4))\nnext\n case (br vs n i lholed LI es)\n then show ?thesis\n using assms(1, 3) types_preserved_br\n by fastforce\nnext\n case (br_if_false n i)\n then show ?thesis\n using assms(1, 3) types_preserved_br_if\n by fastforce\nnext\n case (br_if_true n i)\n then show ?thesis\n using assms(1, 3) types_preserved_br_if\n by fastforce\nnext\n case (br_table is' c i')\n then show ?thesis\n using assms(1, 3) types_preserved_br_table\n by fastforce\nnext\n case (br_table_length is' c i')\n then show ?thesis\n using assms(1, 3) types_preserved_br_table\n by fastforce\nnext\n case (local_const i vs)\n then show ?thesis\n using assms(1, 3) types_preserved_local_const\n by fastforce\nnext\n case (local_trap i vs)\n then show ?thesis\n by (simp add: e_typing_s_typing.intros(4))\nnext\n case (return n j lholed es i vls)\n then show ?thesis\n using assms(1, 3) types_preserved_return\n by fastforce\nnext\n case (tee_local v i)\n then show ?thesis\n using assms(1, 3) types_preserved_tee_local\n by simp\nnext\n case (trap lholed)\n then show ?thesis\n by (simp add: e_typing_s_typing.intros(4))\nqed\n\nlemma types_preserved_b_e:\n assumes \"\\es\\ \\ \\es'\\\"\n \"store_typing s\"\n \"s\\None \\_i vs;es : ts\"\n shows \"s\\None \\_i vs;es' : ts\"\nproof -\n obtain tvs \\ \\i where defs:\"tvs = map typeof vs\"\n \"inst_typing s i \\i\"\n \"\\ = \\i\\local := (local \\i @ tvs), return := None\\\"\n \"s\\\\ \\ es : ([] _> ts)\"\n using assms(3)\n unfolding s_typing.simps\n by blast\n have \"s\\\\ \\ es' : ([] _> ts)\"\n using assms(1,2) defs(4) types_preserved_b_e1\n by simp\n thus ?thesis\n using defs\n unfolding s_typing.simps\n by auto\nqed\n\nlemma types_preserved_store:\n assumes \"s\\\\ \\ [$C ConstInt32 k, $C v, $Store t tp a off] : (ts _> ts')\"\n shows \"s'\\\\ \\ [] : (ts _> ts')\"\n \"types_agree t v\"\nproof -\n obtain ts'' ts''' where ts_def:\"s\\\\ \\ [$C ConstInt32 k] : (ts _> ts'')\"\n \"s\\\\ \\ [$C v] : (ts'' _> ts''')\"\n \"s\\\\ \\ [$Store t tp a off] : (ts''' _> ts')\"\n using assms e_type_comp_conc2[of s \\ \"[$C ConstInt32 k]\" \"[$C v]\" \"[$Store t tp a off]\"]\n by fastforce\n then have \"ts'' = ts@[(T_i32)]\"\n using b_e_type_value[of \\ \"C ConstInt32 k\" \"ts\" ts'']\n unlift_b_e[of s \\ \"[C (ConstInt32 k)]\" \"(ts _> ts'')\"]\n unfolding typeof_def\n by fastforce\n hence \"ts''' = ts@[(T_i32), (typeof v)]\"\n using ts_def(2) b_e_type_value[of \\ \"C v\" ts'' ts''']\n unlift_b_e[of s \\ \"[C v]\" \"(ts'' _> ts''')\"]\n by fastforce\n hence \"ts = ts'\" \"types_agree t v\"\n using ts_def(3) b_e_type_store[of \\ \"Store t tp a off\" ts''' ts']\n unlift_b_e[of s \\ \"[Store t tp a off]\" \"(ts''' _> ts')\"]\n unfolding types_agree_def\n by fastforce+\n thus \"s'\\\\ \\ [] : (ts _> ts')\" \"types_agree t v\"\n using b_e_type_empty[of \\ \"ts\" \"ts'\"] e_typing_s_typing.intros(1)\n by fastforce+\nqed\n\nlemma types_preserved_current_memory:\n assumes \"s\\\\ \\ [$Current_memory] : (ts _> ts')\"\n shows \"s'\\\\ \\ [$C ConstInt32 c] : (ts _> ts')\"\nproof -\n have \"ts' = ts@[T_i32]\"\n using assms b_e_type_current_memory unlift_b_e[of s \\ \"[Current_memory]\"]\n by fastforce\n thus ?thesis\n using b_e_typing.const[of \\ \"ConstInt32 c\"] e_typing_s_typing.intros(1,3)\n unfolding typeof_def\n by fastforce\nqed\n\nlemma types_preserved_grow_memory:\n assumes \"s\\\\ \\ [$C ConstInt32 c, $Grow_memory] : (ts _> ts')\"\n shows \"s'\\\\ \\ [$C ConstInt32 c'] : (ts _> ts')\"\nproof -\n obtain ts'' where ts''_def:\"s\\\\ \\ [$C ConstInt32 c] : (ts _> ts'')\" \n \"s\\\\ \\ [$Grow_memory] : (ts'' _> ts')\"\n using e_type_comp assms\n by (metis append_butlast_last_id butlast.simps(2) last.simps list.distinct(1))\n have \"ts'' = ts@[(T_i32)]\"\n using b_e_type_value[of \\ \"C ConstInt32 c\" ts ts'']\n unlift_b_e[of s \\ \"[C ConstInt32 c]\"] ts''_def(1)\n unfolding typeof_def\n by fastforce\n moreover\n hence \"ts'' = ts'\"\n using ts''_def b_e_type_grow_memory[of _ _ ts'' ts'] unlift_b_e[of s \\ \"[Grow_memory]\"]\n by fastforce\n ultimately\n show \"s'\\\\ \\ [$C ConstInt32 c'] : (ts _> ts')\"\n using e_typing_s_typing.intros(1,3)\n b_e_typing.const[of \\ \"ConstInt32 c'\"]\n unfolding typeof_def\n by fastforce\nqed\n\nlemmas types_preserved_set_global = types_preserved_set_global_aux\n\nlemma types_preserved_load:\n assumes \"s\\\\ \\ [$C ConstInt32 k, $Load t tp a off] : (ts _> ts')\"\n \"typeof v = t\"\n shows \"s'\\\\ \\ [$C v] : (ts _> ts')\"\nproof -\n obtain ts'' where ts''_def:\"s\\\\ \\ [$C ConstInt32 k] : (ts _> ts'')\" \n \"s\\\\ \\ [$Load t tp a off] : (ts'' _> ts')\"\n using e_type_comp assms\n by (metis append_butlast_last_id butlast.simps(2) last.simps list.distinct(1))\n hence \"ts'' = ts@[(T_i32)]\"\n using b_e_type_value unlift_b_e[of s \\ \"[C ConstInt32 k]\"]\n unfolding typeof_def\n by fastforce\n hence ts_def:\"ts' = ts@[t]\" \"load_store_t_bounds a (option_projl tp) t\" \n using ts''_def(2) b_e_type_load unlift_b_e[of s \\ \"[Load t tp a off]\"]\n by fastforce+\n moreover\n hence \"\\ \\ [C v] : (ts _> ts@[t])\"\n using assms(2) b_e_typing.const b_e_typing.weakening\n by fastforce\n ultimately\n show \"s'\\\\ \\ [$C v] : (ts _> ts')\"\n using e_typing_s_typing.intros(1)\n by fastforce\nqed\n\nlemma types_preserved_get_local:\n assumes \"s\\\\ \\ [$Get_local i] : (ts _> ts')\"\n \"length vi = i\"\n \"(local \\) = map typeof (vi @ [v] @ vs)\"\n shows \"s'\\\\ \\ [$C v] : (ts _> ts')\"\nproof -\n have \"(local \\)!i = typeof v\"\n using assms(2,3)\n by (metis (no_types, hide_lams) append_Cons length_map list.simps(9) map_append nth_append_length)\n hence \"ts' = ts@[typeof v]\"\n using assms(1) unlift_b_e[of s \\ \"[Get_local i]\"] b_e_type_get_local\n by fastforce\n thus ?thesis\n using b_e_typing.const e_typing_s_typing.intros(1,3)\n by fastforce\nqed\n\nlemma types_preserved_set_local:\n assumes \"s\\\\ \\ [$C v', $Set_local i] : (ts _> ts')\"\n \"length vi = i\"\n \"(local \\) = map typeof (vi @ [v] @ vs)\"\n shows \"(s'\\\\ \\ [] : (ts _> ts')) \\ map typeof (vi @ [v] @ vs) = map typeof (vi @ [v'] @ vs)\"\nproof -\n have v_type:\"(local \\)!i = typeof v\"\n using assms(2,3)\n by (metis (no_types, hide_lams) append_Cons length_map list.simps(9) map_append nth_append_length)\n obtain ts'' where ts''_def:\"s\\\\ \\ [$C v'] : (ts _> ts'')\" \n \"s\\\\ \\ [$Set_local i] : (ts'' _> ts')\"\n using e_type_comp assms\n by (metis append_butlast_last_id butlast.simps(2) last.simps list.distinct(1))\n hence \"ts'' = ts@[typeof v']\"\n using b_e_type_value unlift_b_e[of s \\ \"[C v']\"]\n by fastforce\n hence \"typeof v = typeof v'\" \"ts' = ts\"\n using v_type b_e_type_set_local[of \\ \"Set_local i\" ts'' ts'] ts''_def(2) unlift_b_e[of s \\ \"[Set_local i]\"]\n by fastforce+\n thus ?thesis\n using b_e_type_empty[of \\ \"ts\" \"ts'\"] e_typing_s_typing.intros(1)\n by fastforce\nqed\n\nlemma types_preserved_get_global:\n assumes \"typeof (sglob_val s i j) = tg_t (global \\ ! j)\"\n \"s\\\\ \\ [$Get_global j] : (ts _> ts')\"\n shows \"s'\\\\ \\ [$C sglob_val s i j] : (ts _> ts')\"\nproof -\n have \"ts' = ts@[tg_t (global \\ ! j)]\"\n using b_e_type_get_global assms(2) unlift_b_e[of _ _ \"[Get_global j]\"]\n by fastforce\n thus ?thesis\n using b_e_typing.const[of \\ \"sglob_val s i j\"] assms(1) e_typing_s_typing.intros(1,3)\n by fastforce\nqed\n\nlemma lholed_same_type:\n assumes \"Lfilled k lholed es les\"\n \"Lfilled k lholed es' les'\"\n \"s\\\\ \\ les : (ts _> ts')\"\n \"\\arb_labs ts ts'.\n s\\(\\\\label := arb_labs@(label \\)\\) \\ es : (ts _> ts')\n \\ s'\\(\\\\label := arb_labs@(label \\)\\) \\ es' : (ts _> ts')\"\n \"store_extension s s'\"\n shows \"(s'\\\\ \\ les' : (ts _> ts'))\"\n using assms\nproof (induction arbitrary: ts ts' es' \\ les' rule: Lfilled.induct)\n case (L0 vs lholed es' es ts ts' es'')\n obtain ts'' ts''' where \"s\\\\ \\ vs : (ts _> ts'')\"\n \"s\\\\ \\ es : (ts'' _> ts''')\"\n \"s\\\\ \\ es' : (ts''' _> ts')\"\n using e_type_comp_conc2 L0(4)\n by blast\n moreover\n hence \"(s'\\\\ \\ es'' : (ts'' _> ts'''))\"\n using L0(5)[of \"[]\" ts'' ts''']\n by fastforce\n ultimately\n have \"(s'\\\\ \\ vs @ es'' @ es' : (ts _> ts'))\"\n using e_type_comp_conc\n by (meson assms(5) e_typing_s_typing_store_extension_inv(1))\n thus ?case\n using L0(2,3) Lfilled.simps[of 0 lholed es'' les']\n by fastforce\nnext\n case (LN vs lholed n es' l es'' k es lfilledk t1s t2s es''' \\ les')\n obtain lfilledk' where l'_def:\"Lfilled k l es''' lfilledk'\" \"les' = vs @ [Label n es' lfilledk'] @ es''\"\n using LN Lfilled.simps[of \"k+1\" lholed es''' les']\n by fastforce\n obtain ts' ts'' where lab_def:\"s\\\\ \\ vs : (t1s _> ts')\"\n \"s\\\\ \\ [Label n es' lfilledk] : (ts' _> ts'')\"\n \"s\\\\ \\ es'' : (ts'' _> t2s)\"\n using e_type_comp_conc2[OF LN(6)]\n by blast\n obtain tls ts_c \\_int where int_def:\" ts'' = ts' @ ts_c\"\n \"length tls = n\"\n \"s\\\\ \\ es' : (tls _> ts_c)\"\n \"\\_int = \\\\label := [tls] @ label \\\\\"\n \"s\\\\_int \\ lfilledk : ([] _> ts_c)\"\n using e_type_label[OF lab_def(2)]\n by blast\n have \"(\\\\' arb_labs' ts ts'.\n \\' = \\_int\\label := arb_labs' @ label \\_int\\ \\\n s\\\\' \\ es : (ts _> ts') \\\n (s'\\\\' \\ es''' : (ts _> ts')))\"\n proof -\n fix \\'' arb_labs'' tts tts'\n assume \"\\'' = \\_int\\label := arb_labs'' @ label \\_int\\\"\n \"s\\\\'' \\ es : (tts _> tts')\"\n thus \"(s'\\\\'' \\ es''' : (tts _> tts'))\"\n using LN(7)[of \"arb_labs'' @ [tls]\" tts tts'] int_def(4)\n by fastforce\n qed\n hence \"(s'\\\\_int \\ lfilledk' : ([] _> ts_c))\"\n using LN(4)[OF l'_def(1) int_def(5)] assms(5)\n by blast\n hence \"(s'\\\\ \\ [Label n es' lfilledk'] : (ts' _> ts''))\"\n using int_def e_typing_s_typing.intros(3,7) e_typing_s_typing_store_extension_inv(1)[OF assms(5)]\n by (metis append.right_neutral)\n thus ?case\n using lab_def e_type_comp_conc l'_def(2) e_typing_s_typing_store_extension_inv(1)[OF assms(5)]\n by blast\nqed\n\nlemma types_preserved_e1:\n assumes \"\\s;vs;es\\ \\_i \\s';vs';es'\\\"\n \"store_typing s\"\n \"inst_typing s i \\i\"\n \"tvs = map typeof vs\"\n \"\\ = \\i\\local := (local \\i @ tvs), label := arb_labs, return := arb_return\\\"\n \"s\\\\ \\ es : (ts _> ts')\"\n shows \"(s'\\\\ \\ es' : (ts _> ts')) \\ (map typeof vs = map typeof vs')\"\n using assms\nproof (induction arbitrary: tvs \\ \\i ts ts' arb_labs arb_return rule: reduce.induct)\n case (basic e e' s vs i)\n then show ?case\n using types_preserved_b_e1[OF basic(1,2)]\n by fastforce\nnext\n case (call s vs j i)\n obtain ts'' tf1 tf2 where l_func_t: \"length (func_t \\) > j\"\n \"ts = ts''@tf1\"\n \"ts' = ts''@tf2\"\n \"((func_t \\)!j) = (tf1 _> tf2)\"\n using b_e_type_call[of \\ \"Call j\" ts ts' j] call(5)\n unlift_b_e[of _ _ \"[Call j]\" \"(ts _> ts')\"]\n by fastforce\n have \"j < length (func_t \\i)\"\n using l_func_t(1) call(4)\n by simp\n hence \"cl_typing s (sfunc s i j) (tf1 _> tf2)\"\n using l_func_t(4) call(4) store_typing_imp_func_agree[OF call(1,2)]\n inst_typing_func_length[OF call(2)]\n by fastforce\n thus ?case\n using e_typing_s_typing.intros(3,6) l_func_t\n by fastforce\nnext\n case (call_indirect_Some s i' c cl j tf vs)\n show ?case\n using types_preserved_call_indirect_Some[OF call_indirect_Some(8,1)]\n call_indirect_Some(2,3,4,5,7)\n by blast\nnext\n case (call_indirect_None s i c cl j vs)\n thus ?case\n using e_typing_s_typing.intros(4)\n by blast\nnext\n case (invoke_native cl j t1s t2s ts es ves vcs n k m zs s vs i)\n thus ?case\n using types_preserved_invoke_native\n by fastforce\nnext\n case (invoke_host_Some cl t1s t2s f ves vcs n m s hs s' vcs' vs i)\n thus ?case\n using types_preserved_invoke_host_some\n by fastforce\nnext\n case (invoke_host_None cl t1s t2s f ves vcs n m s hs vs i)\n thus ?case\n using e_typing_s_typing.intros(4)\n by blast\nnext\n case (get_local vi j s v vs i)\n have \"local \\ = tvs\"\n using store_local_label_empty assms(2) get_local\n by fastforce\n then show ?case\n using types_preserved_get_local get_local\n by fastforce\nnext\n case (set_local vi j s v vs v' i)\n have \"local \\ = tvs\"\n using store_local_label_empty assms(2) set_local\n by fastforce\n thus ?case\n using set_local types_preserved_set_local\n by simp\nnext\n case (get_global s vs j i)\n have \"length (global \\) > j\"\n using b_e_type_get_global get_global(5) unlift_b_e[of _ _ \"[Get_global j]\" \"(ts _> ts')\"]\n by fastforce\n hence \"glob_typing (sglob s i j) ((global \\)!j)\"\n using get_global(3,4) store_typing_imp_glob_agree[OF get_global(2)]\n by fastforce\n hence \"typeof (g_val (sglob s i j)) = tg_t (global \\ ! j)\"\n unfolding glob_typing_def\n by simp\n thus ?case\n using get_global(5) types_preserved_get_global\n unfolding glob_typing_def sglob_val_def\n by fastforce\nnext\n case (set_global s i j v s' vs)\n then show ?case\n using types_preserved_set_global\n by fastforce\nnext\n case (load_Some s i j m k off t bs vs a)\n then show ?case\n using types_preserved_load(1) wasm_deserialise_type\n by blast\nnext\n case (load_None s i j m k off t vs a)\n then show ?case\n using e_typing_s_typing.intros(4)\n by blast\nnext\n case (load_packed_Some s i j m sx k off tp bs vs t a)\n then show ?case\n using types_preserved_load(1) wasm_deserialise_type\n by blast\nnext\n case (load_packed_None s i j m sx k off tp vs t a)\n then show ?case\n using e_typing_s_typing.intros(4)\n by blast\nnext\n case (store_Some t v s i j m k off mem' vs a)\n then show ?case\n using types_preserved_store\n by blast\nnext\n case (store_None t v s i j m k off vs a)\n then show ?case\n using e_typing_s_typing.intros(4)\n by blast\nnext\n case (store_packed_Some t v s i j m k off tp mem' vs a)\n then show ?case\n using types_preserved_store\n by blast\nnext\n case (store_packed_None t v s i j m k off tp vs a)\n then show ?case\n using e_typing_s_typing.intros(4)\n by blast\nnext\n case (current_memory s i j m n vs)\n then show ?case\n using types_preserved_current_memory\n by fastforce\nnext\n case (grow_memory s i j m n c mem' vs)\n then show ?case\n using types_preserved_grow_memory\n by fastforce\nnext\n case (grow_memory_fail s i j m n vs c)\n thus ?case\n using types_preserved_grow_memory\n by blast\nnext\n case (label s vs es i s' vs' es' k lholed les les')\n {\n fix \\' arb_labs' ts ts'\n assume local_assms:\"\\' = \\\\label := arb_labs'@(label \\), return := (return \\)\\\"\n hence \"(s\\\\' \\ es : (ts _> ts')) \\\n ((s'\\\\' \\ es' : (ts _> ts')) \\ map typeof vs = map typeof vs' \\ store_extension s s')\"\n using label(4)[OF label(5,6,7,8)] label(4,5,6,7,8)\n reduce_store_extension[OF label(1,5,6), of \\' _ _ \"return \\'\" \"label \\'\"]\n by fastforce\n hence \"(s\\\\\\label := arb_labs'@(label \\)\\ \\ es : (ts _> ts'))\n \\ (s'\\\\\\label := arb_labs'@(label \\)\\ \\ es' : (ts _> ts')) \\\n map typeof vs = map typeof vs' \\ store_extension s s'\"\n using local_assms\n by simp\n }\n hence \"\\arb_labs' ts ts'. s\\\\\\label := arb_labs'@(label \\)\\ \\ es : (ts _> ts')\n \\ (s'\\\\\\label := arb_labs'@(label \\)\\ \\ es' : (ts _> ts'))\"\n \"map typeof vs = map typeof vs'\"\n \"store_extension s s'\"\n using types_exist_lfilled[OF label(2,9)]\n by auto\n thus ?case\n using lholed_same_type[OF label(2,3,9)]\n by fastforce\nnext\n case (local s vls es i s' vs' es' vs n j)\n obtain \\' tls \\i' where es_def:\"inst_typing s i \\i'\"\n \"length tls = n\"\n \"\\' = \\i'\\local := local \\i' @ map typeof vls, label := label \\i', return := Some tls\\\"\n \"s\\\\' \\ es : ([] _> tls)\"\n \"ts' = ts @ tls\"\n using e_type_local[OF local(7)]\n by fastforce\n moreover\n obtain ts'' where \"ts' = ts@ts''\" \"(s\\(Some ts'') \\_i vls;es : ts'')\"\n using e_type_local_shallow local(7)\n by fastforce\n ultimately\n have \"s'\\\\' \\ es' : ([] _> tls)\" \"map typeof vls = map typeof vs'\"\n using local(2,3)\n by blast+\n moreover\n have \"inst_typing s' i \\i'\"\n using inst_typing_store_extension_inv[OF es_def(1)] reduce_store_extension[OF local(1,3) es_def(1,4,3)]\n by blast\n ultimately\n have \"s'\\(Some tls) \\_ i vs';es' : tls\"\n using e_typing_s_typing.intros(8) es_def(1,3)\n by fastforce\n thus ?case\n using e_typing_s_typing.intros(3,5) es_def(2,5)\n by fastforce\nqed\n\nlemma types_preserved_e:\n assumes \"\\s;vs;es\\ \\_i \\s';vs';es'\\\"\n \"store_typing s\"\n \"s\\None \\_i vs;es : ts\"\n shows \"s'\\None \\_i vs';es' : ts\"\n using assms\nproof -\n obtain tvs \\ \\i where defs: \"tvs = map typeof vs\"\n \"inst_typing s i \\i\"\n \"\\ = \\i\\local := (local \\i @ tvs), label := (label \\i), return := None\\\"\n \"s\\\\ \\ es : ([] _> ts)\"\n using assms(3)\n unfolding s_typing.simps\n by fastforce\n have \"(s'\\\\ \\ es' : ([] _> ts)) \\ (map typeof vs = map typeof vs')\"\n using types_preserved_e1[OF assms(1,2) defs(2,1,3,4)]\n by simp\n moreover\n have \"inst_typing s' i \\i\"\n using defs(2) store_preserved(1)[OF assms] inst_typing_store_extension_inv\n by blast\n ultimately\n show ?thesis\n using defs\n unfolding s_typing.simps\n by auto\nqed\n\nsubsection {* Progress *}\n\nlemma const_list_no_progress:\n assumes \"const_list es\"\n shows \"\\\\s;vs;es\\ \\_ i \\s';vs';es'\\\"\nproof -\n {\n assume \"\\s;vs;es\\ \\_ i \\s';vs';es'\\\"\n hence \"False\"\n using assms\n proof (induction rule: reduce.induct)\n case (basic e e' s vs i)\n thus ?thesis\n proof (induction rule: reduce_simple.induct)\n case (trap es lholed)\n show ?case\n using trap(2)\n proof (cases rule: Lfilled.cases)\n case (L0 vs es')\n thus ?thesis\n using trap(3) list_all_append const_list_cons_last(2)[of vs Trap]\n unfolding const_list_def\n by (simp add: is_const_def)\n next\n case (LN vs n es' l es'' k lfilledk)\n thus ?thesis\n by (simp add: is_const_def)\n qed\n qed (fastforce simp add: const_list_cons_last(2) is_const_def const_list_def)+\n next\n case (label s vs es i s' vs' es' k lholed les les')\n show ?case\n using label(2)\n proof (cases rule: Lfilled.cases)\n case (L0 vs es')\n thus ?thesis\n using label(4,5) list_all_append\n unfolding const_list_def\n by fastforce\n next\n case (LN vs n es' l es'' k lfilledk)\n thus ?thesis\n using label(4,5)\n unfolding const_list_def\n by (simp add: is_const_def)\n qed\n qed (fastforce simp add: const_list_cons_last(2) is_const_def const_list_def)+\n }\n thus ?thesis\n by blast\nqed\n\nlemma empty_no_progress:\n assumes \"es = []\"\n shows \"\\\\s;vs;es\\ \\_ i \\s';vs';es'\\\"\nproof -\n {\n assume \"\\s;vs;es\\ \\_ i \\s';vs';es'\\\"\n hence False\n using assms\n proof (induction rule: reduce.induct)\n case (basic e e' s vs i)\n thus ?thesis\n proof (induction rule: reduce_simple.induct)\n case (trap es lholed)\n thus ?case\n using Lfilled.simps[of 0 lholed \"[Trap]\" es]\n by auto\n qed auto\n next\n case (label s vs es i s' vs' es' k lholed les les')\n thus ?case\n using Lfilled.simps[of k lholed es \"[]\"]\n by auto\n qed auto\n }\n thus ?thesis\n by blast\nqed\n \nlemma trap_no_progress:\n assumes \"es = [Trap]\"\n shows \"\\\\s;vs;es\\ \\_ i \\s';vs';es'\\\"\nproof -\n {\n assume \"\\s;vs;es\\ \\_ i \\s';vs';es'\\\"\n hence False\n using assms\n proof (induction rule: reduce.induct)\n case (basic e e' s vs i)\n thus ?case\n by (induction rule: reduce_simple.induct) auto\n next\n case (label s vs es i s' vs' es' k lholed les les')\n show ?case\n using label(2)\n proof (cases rule: Lfilled.cases)\n case (L0 vs es')\n show ?thesis\n using L0(2) label(1,4,5) empty_no_progress\n by (auto simp add: Cons_eq_append_conv)\n next\n case (LN vs n es' l es'' k' lfilledk)\n show ?thesis\n using LN(2) label(5)\n by (simp add: Cons_eq_append_conv)\n qed\n qed auto\n }\n thus ?thesis\n by blast\nqed\n\nlemma terminal_no_progress:\n assumes \"const_list es \\ es = [Trap]\"\n shows \"\\\\s;vs;es\\ \\_ i \\s';vs';es'\\\"\n using const_list_no_progress trap_no_progress assms\n by blast\n\nlemma progress_L0:\n assumes \"\\s;vs;es\\ \\_ i \\s';vs';es'\\\"\n \"const_list cs\"\n shows \"\\s;vs;cs@es@es_c\\ \\_ i \\s';vs';cs@es'@es_c\\\"\nproof -\n have \"\\es. Lfilled 0 (LBase cs es_c) es (cs@es@es_c)\"\n using Lfilled.intros(1)[of cs \"(LBase cs es_c)\" es_c] assms(2)\n unfolding const_list_def\n by fastforce\n thus ?thesis\n using reduce.intros(23) assms(1)\n by blast\nqed\n\nlemma progress_L0_left:\n assumes \"\\s;vs;es\\ \\_ i \\s';vs';es'\\\"\n \"const_list cs\"\n shows \"\\s;vs;cs@es\\ \\_ i \\s';vs';cs@es'\\\"\n using assms progress_L0[where ?es_c = \"[]\"]\n by fastforce\n\nlemma progress_L0_trap:\n assumes \"const_list cs\"\n \"cs \\ [] \\ es \\ []\"\n shows \"\\a. \\s;vs;cs@[Trap]@es\\ \\_ i \\s;vs;[Trap]\\\"\nproof -\n have \"cs @ [Trap] @ es \\ [Trap]\"\n using assms(2)\n by (cases \"cs = []\") (auto simp add: append_eq_Cons_conv)\n thus ?thesis\n using reduce.intros(1) assms(2) reduce_simple.trap\n Lfilled.intros(1)[OF assms(1), of _ es \"[Trap]\"]\n by blast\nqed\n\nlemma progress_LN:\n assumes \"(Lfilled j lholed [$Br (j+k)] es)\"\n \"s\\\\ \\ es : ([] _> ts)\"\n \"(label \\)!k = tvs\"\n shows \"\\lholed' vs \\'. (Lfilled j lholed' (vs@[$Br (j+k)]) es)\n \\ (s\\\\' \\ vs : ([] _> tvs))\n \\ const_list vs\"\n using assms\nproof (induction \"[$Br (j+k)]\" es arbitrary: k \\ ts rule: Lfilled.induct)\n case (L0 vs lholed es')\n obtain ts' ts'' where ts_def:\"s\\\\ \\ vs : ([] _> ts')\"\n \"s\\\\ \\ [$Br k] : (ts' _> ts'')\"\n \"s\\\\ \\ es' : (ts'' _> ts)\"\n using e_type_comp_conc2[OF L0(3)]\n by fastforce\n obtain ts_c where \"ts' = ts_c @ tvs\"\n using b_e_type_br[of \\ \"Br k\" ts' ts''] L0(3,4) ts_def(2) unlift_b_e\n by fastforce\n then obtain vs1 vs2 where vs_def:\"s\\\\ \\ vs1 : ([] _> ts_c)\"\n \"s\\\\ \\ vs2 : (ts_c _> (ts_c@tvs))\"\n \"vs = vs1@vs2\"\n \"const_list vs1\"\n \"const_list vs2\"\n using e_type_const_list_cons[OF L0(1)] ts_def(1)\n by fastforce\n hence \"s\\\\ \\ vs2 : ([] _> tvs)\"\n using e_type_const_list by blast\n thus ?case\n using Lfilled.intros(1)[OF vs_def(4), of _ es' \"vs2@[$Br k]\"] vs_def(3,5)\n by fastforce\nnext\n case (LN vs lholed n es' l es'' j lfilledk)\n obtain t1s t2s where ts_def:\"s\\\\ \\ vs : ([] _> t1s)\"\n \"s\\\\ \\ [Label n es' lfilledk] : (t1s _> t2s)\"\n \"s\\\\ \\ es'' : (t2s _> ts)\"\n using e_type_comp_conc2[OF LN(5)]\n by fastforce\n obtain ts' ts_l where ts_l_def:\"s\\\\\\label := [ts'] @ label \\\\ \\ lfilledk : ([] _> ts_l)\"\n using e_type_label[OF ts_def(2)]\n by fastforce\n obtain lholed' vs' \\' where lfilledk_def:\"Lfilled j lholed' (vs' @ [$Br (j + (1 + k))]) lfilledk\"\n \"s\\\\' \\ vs' : ([] _> tvs)\"\n \"const_list vs'\"\n using LN(4)[OF _ ts_l_def, of \"1 + k\"] LN(5,6)\n by fastforce\n thus ?case\n using Lfilled.intros(2)[OF LN(1) _ lfilledk_def(1)]\n by fastforce\nqed\n\nlemma progress_LN_return:\n assumes \"(Lfilled j lholed [$Return] es)\"\n \"s\\\\ \\ es : ([] _> ts)\"\n \"(return \\) = Some tvs\"\n shows \"\\lholed' vs \\'. (Lfilled j lholed' (vs@[$Return]) es)\n \\ (s\\\\' \\ vs : ([] _> tvs))\n \\ const_list vs\"\n using assms\nproof (induction \"[$Return]\" es arbitrary: k \\ ts rule: Lfilled.induct)\n case (L0 vs lholed es')\n obtain ts' ts'' where ts_def:\"s\\\\ \\ vs : ([] _> ts')\"\n \"s\\\\ \\ [$Return] : (ts' _> ts'')\"\n \"s\\\\ \\ es' : (ts'' _> ts)\"\n using e_type_comp_conc2[OF L0(3)]\n by fastforce\n obtain ts_c where \"ts' = ts_c @ tvs\"\n using b_e_type_return[of \\ \"Return\" ts' ts''] L0(3,4) ts_def(2) unlift_b_e\n by fastforce\n then obtain vs1 vs2 where vs_def:\"s\\\\ \\ vs1 : ([] _> ts_c)\"\n \"s\\\\ \\ vs2 : (ts_c _> (ts_c@tvs))\"\n \"vs = vs1@vs2\"\n \"const_list vs1\"\n \"const_list vs2\"\n using e_type_const_list_cons[OF L0(1)] ts_def(1)\n by fastforce\n hence \"s\\\\ \\ vs2 : ([] _> tvs)\"\n using e_type_const_list by blast\n thus ?case\n using Lfilled.intros(1)[OF vs_def(4), of _ es' \"vs2@[$Return]\"] vs_def(3,5)\n by fastforce\nnext\n case (LN vs lholed n es' l es'' j lfilledk)\n obtain t1s t2s where ts_def:\"s\\\\ \\ vs : ([] _> t1s)\"\n \"s\\\\ \\ [Label n es' lfilledk] : (t1s _> t2s)\"\n \"s\\\\ \\ es'' : (t2s _> ts)\"\n using e_type_comp_conc2[OF LN(5)]\n by fastforce\n obtain ts' ts_l where ts_l_def:\"s\\\\\\label := [ts'] @ label \\\\ \\ lfilledk : ([] _> ts_l)\"\n using e_type_label[OF ts_def(2)]\n by fastforce\n obtain lholed' vs' \\' where lfilledk_def:\"Lfilled j lholed' (vs' @ [$Return]) lfilledk\"\n \"s\\\\' \\ vs' : ([] _> tvs)\"\n \"const_list vs'\"\n using LN(4)[OF ts_l_def] LN(6)\n by fastforce\n thus ?case\n using Lfilled.intros(2)[OF LN(1) _ lfilledk_def(1)]\n by fastforce\nqed\n\nlemma progress_LN1:\n assumes \"(Lfilled j lholed [$Br (j+k)] es)\"\n \"s\\\\ \\ es : (ts _> ts')\"\n shows \"length (label \\) > k\"\n using assms\nproof (induction \"[$Br (j+k)]\" es arbitrary: k \\ ts ts' rule: Lfilled.induct)\n case (L0 vs lholed es')\n obtain ts'' ts''' where ts_def:\"s\\\\ \\ vs : (ts _> ts'')\"\n \"s\\\\ \\ [$Br k] : (ts'' _> ts''')\"\n \"s\\\\ \\ es' : (ts''' _> ts')\"\n using e_type_comp_conc2[OF L0(3)]\n by fastforce\n thus ?case\n using b_e_type_br(1)[of _ \"Br k\" ts'' ts'''] unlift_b_e\n by fastforce\nnext\n case (LN vs lholed n es' l es'' k' lfilledk)\n obtain t1s t2s where ts_def:\"s\\\\ \\ vs : (ts _> t1s)\"\n \"s\\\\ \\ [Label n es' lfilledk] : (t1s _> t2s)\"\n \"s\\\\ \\ es'' : (t2s _> ts')\"\n using e_type_comp_conc2[OF LN(5)]\n by fastforce\n obtain ts'' ts_l where ts_l_def:\"s\\\\\\label := [ts''] @ label \\\\ \\ lfilledk : ([] _> ts_l)\"\n using e_type_label[OF ts_def(2)]\n by fastforce\n thus ?case\n using LN(4)[of \"1+k\"]\n by fastforce\nqed\n\nlemma progress_LN2:\n assumes \"(Lfilled j lholed e1s lfilled)\"\n shows \"\\lfilled'. (Lfilled j lholed e2s lfilled')\"\n using assms\nproof (induction rule: Lfilled.induct)\n case (L0 vs lholed es' es)\n thus ?case\n using Lfilled.intros(1)\n by fastforce\nnext\n case (LN vs lholed n es' l es'' k es lfilledk)\n thus ?case\n using Lfilled.intros(2)\n by fastforce\nqed\n\nlemma progress_label:\n assumes \"\\s;vs;es\\ \\_ i \\s';vs';es'\\\"\n shows \"\\s;vs;[Label n les es]\\ \\_ i \\s';vs';[Label n les es']\\\"\nproof -\n have \"Lfilled 1 (LRec [] n les (LBase [] []) []) es [Label n les es]\"\n using Lfilled.intros(2)[OF _ _ Lfilled.intros(1)[of \"[]\" \"(LBase [] [])\"], of \"[]\" _ n les \"[]\"]\n unfolding const_list_def\n by simp\n moreover\n have \"Lfilled 1 (LRec [] n les (LBase [] []) []) es' [Label n les es']\"\n using Lfilled.intros(2)[OF _ _ Lfilled.intros(1)[of \"[]\" \"(LBase [] [])\"], of \"[]\" _ n les \"[]\"]\n unfolding const_list_def\n by simp\n ultimately\n show ?thesis\n using reduce.label[OF assms]\n by blast\nqed\n\nlemma const_of_const_list:\n assumes \"length cs = 1\"\n \"const_list cs\"\n shows \"\\v. cs = [$C v]\"\n using e_type_const_unwrap assms\n unfolding const_list_def list_all_length\n by (metis append_butlast_last_id append_self_conv2 gr_zeroI last_conv_nth length_butlast\n length_greater_0_conv less_numeral_extra(1,4) zero_less_diff)\n\nlemma const_of_i32:\n assumes \"const_list cs\"\n \"s\\\\ \\ cs : ([] _> [(T_i32)])\"\n shows \"\\c. cs = [$C ConstInt32 c]\"\nproof - \n obtain v where \"cs = [$C v]\"\n using const_of_const_list assms(1) e_type_const_list[OF assms]\n by fastforce\n moreover\n hence \"\\ \\ [C v] : ([] _> [(T_i32)])\"\n using assms(2) unlift_b_e\n by fastforce\n hence \"\\c. v = ConstInt32 c\"\n proof (induction \"[C v]\" \"([] _> [(T_i32)])\" rule: b_e_typing.induct)\n case (const \\)\n then show ?case\n unfolding typeof_def\n by (cases v, auto)\n qed auto\n ultimately\n show ?thesis\n by fastforce\nqed\n\nlemma const_of_i64:\n assumes \"const_list cs\"\n \"s\\\\ \\ cs : ([] _> [(T_i64)])\"\n shows \"\\c. cs = [$C ConstInt64 c]\"\nproof - \n obtain v where \"cs = [$C v]\"\n using const_of_const_list assms(1) e_type_const_list[OF assms]\n by fastforce\n moreover\n hence \"\\ \\ [C v] : ([] _> [(T_i64)])\"\n using assms(2) unlift_b_e\n by fastforce\n hence \"\\c. v = ConstInt64 c\"\n proof (induction \"[C v]\" \"([] _> [(T_i64)])\" rule: b_e_typing.induct)\n case (const \\)\n then show ?case\n unfolding typeof_def\n by (cases v, auto)\n qed auto\n ultimately\n show ?thesis\n by fastforce\nqed\n\nlemma const_of_f32:\n assumes \"const_list cs\"\n \"s\\\\ \\ cs : ([] _> [T_f32])\"\n shows \"\\c. cs = [$C ConstFloat32 c]\"\nproof - \n obtain v where \"cs = [$C v]\"\n using const_of_const_list assms(1) e_type_const_list[OF assms]\n by fastforce\n moreover\n hence \"\\ \\ [C v] : ([] _> [T_f32])\"\n using assms(2) unlift_b_e\n by fastforce\n hence \"\\c. v = ConstFloat32 c\"\n proof (induction \"[C v]\" \"([] _> [T_f32])\" rule: b_e_typing.induct)\n case (const \\)\n then show ?case\n unfolding typeof_def\n by (cases v, auto)\n qed auto\n ultimately\n show ?thesis\n by fastforce\nqed\n\nlemma const_of_f64:\n assumes \"const_list cs\"\n \"s\\\\ \\ cs : ([] _> [T_f64])\"\n shows \"\\c. cs = [$C ConstFloat64 c]\"\nproof - \n obtain v where \"cs = [$C v]\"\n using const_of_const_list assms(1) e_type_const_list[OF assms]\n by fastforce\n moreover\n hence \"\\ \\ [C v] : ([] _> [T_f64])\"\n using assms(2) unlift_b_e\n by fastforce\n hence \"\\c. v = ConstFloat64 c\"\n proof (induction \"[C v]\" \"([] _> [T_f64])\" rule: b_e_typing.induct)\n case (const \\)\n then show ?case\n unfolding typeof_def\n by (cases v, auto)\n qed auto\n ultimately\n show ?thesis\n by fastforce\nqed\n\nlemma const_of_typed_const_1:\n assumes \"const_list cs\"\n \"s\\\\ \\ cs : ([] _> [t])\"\n shows \"\\v. cs = [$C v]\"\n using assms(2)\n apply (cases t)\n apply (metis const_of_i32[OF assms(1)])\n apply (metis const_of_i64[OF assms(1)])\n apply (metis const_of_f32[OF assms(1)])\n apply (metis const_of_f64[OF assms(1)])\n done\n\nlemma progress_testop:\n assumes \"s\\\\ \\ cs : ([] _> [t])\"\n \"const_list cs\"\n \"e = Testop t testop\"\n shows \"\\a s' vs' es'. \\s;vs;cs@([$e])\\ \\_i \\s';vs';es'\\\"\n using assms reduce.intros(1)[OF reduce_simple.intros(4)] const_of_typed_const_1\n by fastforce\n\nlemma progress_unop:\n assumes \"s\\\\ \\ cs : ([] _> [t])\"\n \"const_list cs\"\n \"e = Unop t iop\"\n shows \"\\a s' vs' es'. \\s;vs;cs@([$e])\\ \\_i \\s';vs';es'\\\"\n using assms reduce.intros(1)[OF reduce_simple.intros(1)] const_of_typed_const_1\n by fastforce\n\nlemma const_list_split_2:\n assumes \"const_list cs\"\n \"s\\\\ \\ cs : ([] _> [t1, t2])\"\n shows \"\\c1 c2. (s\\\\ \\ [c1] : ([] _> [t1]))\n \\ (s\\\\ \\ [c2] : ([] _> [t2]))\n \\ cs = [c1, c2]\n \\ const_list [c1]\n \\ const_list [c2]\"\nproof -\n have l_cs:\"length cs = 2\"\n using assms e_type_const_list[OF assms]\n by simp\n then obtain c1 c2 where \"cs!0 = c1\" \"cs!1 = c2\"\n by fastforce\n hence \"cs = [c1] @ [c2]\"\n using assms e_type_const_conv_vs typing_map_typeof\n by fastforce\n thus ?thesis\n using assms e_type_comp[of s \\ \"[c1]\" c2] e_type_const[of c2 s \\ _ \"[t1,t2]\"]\n unfolding const_list_def\n by fastforce\nqed\n\nlemma const_list_split_3:\n assumes \"const_list cs\"\n \"s\\\\ \\ cs : ([] _> [t1, t2, t3])\"\n shows \"\\c1 c2 c3. (s\\\\ \\ [c1] : ([] _> [t1]))\n \\ (s\\\\ \\ [c2] : ([] _> [t2]))\n \\ (s\\\\ \\ [c3] : ([] _> [t3]))\n \\ cs = [c1, c2, c3]\"\nproof -\n have l_cs:\"length cs = 3\"\n using assms e_type_const_list[OF assms]\n by simp\n then obtain c1 c2 c3 where \"cs!0 = c1\" \"cs!1 = c2\" \"cs!2 = c3\"\n by fastforce\n hence \"cs = [c1] @ [c2] @ [c3]\"\n using assms e_type_const_conv_vs typing_map_typeof\n by fastforce\n thus ?thesis\n using assms e_type_comp_conc2[of s \\ \"[c1]\" \"[c2]\" \"[c3]\" \"[]\" \"[t1,t2,t3]\"]\n e_type_const[of c1] e_type_const[of c2] e_type_const[of c3]\n unfolding const_list_def\n by fastforce\nqed\n\nlemma const_of_typed_const_2:\n assumes \"const_list cs\"\n \"s\\\\ \\ cs : ([] _> [t,t])\"\n shows \"\\v1 v2. cs = [$C v1, $C v2]\"\n using const_list_split_2[OF assms] const_list_def e_type_const_unwrap\n by auto\n\nlemma progress_relop:\n assumes \"const_list cs\"\n \"s\\\\ \\ cs : ([] _> [t, t])\"\n \"e = Relop t rop\"\n shows \"\\a s' vs' es'. \\s;vs;cs@([$e])\\ \\_i \\s';vs';es'\\\"\n using const_of_typed_const_2[OF assms(1,2)] assms(3) reduce_simple.intros(5) reduce.intros(1)\n by fastforce\n\nlemma progress_binop:\n assumes \"const_list cs\"\n \"s\\\\ \\ cs : ([] _> [t, t])\"\n \"e = Binop t fop\"\n shows \"\\a s' vs' es'. \\s;vs;cs@([$e])\\ \\_i \\s';vs';es'\\\"\n using const_of_typed_const_2[OF assms(1,2)] assms(3) reduce_simple.intros(2,3) reduce.intros(1)\n by fastforce\n\nlemma progress_b_e:\n assumes \"\\ \\ b_es : (ts _> ts')\"\n \"s\\\\ \\ cs : ([] _> ts)\"\n \"(\\lholed. \\(Lfilled 0 lholed [$Return] (cs@($*b_es))))\"\n \"\\ i lholed. \\(Lfilled 0 lholed [$Br (i)] (cs@($*b_es)))\"\n \"const_list cs\"\n \"\\ const_list ($* b_es)\"\n \"length (local \\) = length (vs)\"\n \"length (memory \\) = length (inst.mems i)\"\n shows \"\\a s' vs' es'. \\s;vs;cs@($*b_es)\\ \\_i \\s';vs';es'\\\"\n using assms\nproof (induction b_es \"(ts _> ts')\" arbitrary: ts ts' cs rule: b_e_typing.induct)\n case (const \\ v)\n then show ?case\n unfolding const_list_def is_const_def\n by simp\nnext\n case (unop t \\ uu)\n thus ?case\n using progress_unop\n by fastforce\nnext\n case (binop t \\ uw)\n thus ?case\n using progress_binop\n by fastforce\nnext\n case (testop t \\ uy)\n thus ?case\n using progress_testop\n by fastforce\nnext\n case (relop t \\ uz)\n thus ?case\n using progress_relop\n by fastforce\nnext\n case (convert t1 t2 sx \\)\n obtain v where cs_def:\"cs = [$ C v]\" \"typeof v = t2\"\n using const_typeof const_of_const_list[OF _ convert(6)] e_type_const_list[OF convert(6,3)]\n by fastforce\n thus ?case\n proof (cases \"cvt t1 sx v\")\n case None\n thus ?thesis\n using reduce.intros(1)[OF reduce_simple.convert_None[OF _ None]] cs_def\n unfolding types_agree_def\n by fastforce\n next\n case (Some a)\n thus ?thesis\n using reduce.intros(1)[OF reduce_simple.convert_Some[OF _ Some]] cs_def\n unfolding types_agree_def\n by fastforce\n qed\nnext\n case (reinterpret t1 t2 \\)\n obtain v where cs_def:\"cs = [$ C v]\" \"typeof v = t2\"\n using const_typeof const_of_const_list[OF _ reinterpret(6)] e_type_const_list[OF reinterpret(6,3)]\n by fastforce\n thus ?case\n using reduce.intros(1)[OF reduce_simple.reinterpret]\n unfolding types_agree_def\n by fastforce\nnext\n case (unreachable \\ ts ts')\n thus ?case\n using reduce.intros(1)[OF reduce_simple.unreachable] progress_L0[OF _ unreachable(4)]\n by fastforce\nnext\n case (nop \\)\n thus ?case\n using reduce.intros(1)[OF reduce_simple.nop] progress_L0[OF _ nop(4)]\n by fastforce\nnext\n case (drop \\ t)\n obtain v where \"cs = [$C v]\"\n using const_of_const_list drop(4) e_type_const_list[OF drop(4,1)]\n by fastforce\n thus ?case\n using reduce.intros(1)[OF reduce_simple.drop] progress_L0[OF _ drop(4)]\n by fastforce\nnext\n case (select \\ t)\n obtain v1 v2 v3 where cs_def:\"s\\\\ \\ [$ C v3] : ([] _> [T_i32])\"\n \"cs = [$C v1, $C v2, $ C v3]\"\n using const_list_split_3[OF select(4,1)] select(4)\n unfolding const_list_def\n by (metis list_all_simps(1) e_type_const_unwrap)\n obtain c3 where c_def:\"v3 = ConstInt32 c3\"\n using cs_def select(4) const_of_i32[OF _ cs_def(1)]\n unfolding const_list_def\n by fastforce\n have \"\\a s' vs' es'. \\s;vs;[$C v1, $C v2, $ C ConstInt32 c3, $Select]\\ \\_i \\s';vs';es'\\\"\n proof (cases \"int_eq c3 0\")\n case True\n thus ?thesis\n using reduce.intros(1)[OF reduce_simple.select_false]\n by fastforce\n next\n case False\n thus ?thesis\n using reduce.intros(1)[OF reduce_simple.select_true]\n by fastforce\n qed\n thus ?case\n using c_def cs_def\n by fastforce\nnext\n case (block tf tn tm \\ es)\n show ?case\n using reduce_simple.block[OF block(7), of _ tn tm _ es]\n e_type_const_list[OF block(7,4)] reduce.intros(1) block(1)\n by fastforce\nnext\n case (loop tf tn tm \\ es)\n show ?case\n using reduce_simple.loop[OF loop(7), of _ tn tm _ es]\n e_type_const_list[OF loop(7,4)] reduce.intros(1) loop(1) \n by fastforce\nnext\n case (if_wasm tf tn tm \\ es1 es2)\n obtain c1s c2s where cs_def:\"s\\\\ \\ c1s : ([] _> tn)\"\n \"s\\\\ \\ c2s : ([] _> [T_i32])\"\n \"const_list c1s\"\n \"const_list c2s\"\n \"cs = c1s @ c2s\"\n using e_type_const_list_cons[OF if_wasm(9,6)] e_type_const_list\n by fastforce\n obtain c where c_def: \"c2s = [$ C (ConstInt32 c)]\"\n using const_of_i32 cs_def\n by fastforce\n have \"\\a s' vs' es'. \\s;vs;[$ C (ConstInt32 c), $ If tf es1 es2]\\ \\_i \\s';vs';es'\\\"\n proof (cases \"int_eq c 0\")\n case True\n thus ?thesis\n using reduce.intros(1)[OF reduce_simple.if_false]\n by fastforce\n next\n case False\n thus ?thesis\n using reduce.intros(1)[OF reduce_simple.if_true]\n by fastforce\n qed\n thus ?case\n using c_def cs_def progress_L0\n by fastforce\nnext\n case (br i \\ ts t1s t2s)\n thus ?case\n using Lfilled.intros(1)[OF br(6), of _ \"[]\" \"[$Br i]\"]\n by fastforce\nnext\n case (br_if j \\ ts)\n obtain cs1 cs2 where cs_def:\"s\\\\ \\ cs1 : ([] _> ts)\"\n \"s\\\\ \\ cs2 : ([] _> [T_i32])\"\n \"const_list cs1\"\n \"const_list cs2\"\n \"cs = cs1 @ cs2\"\n using e_type_const_list_cons[OF br_if(6,3)] e_type_const_list\n by fastforce\n obtain c where c_def:\"cs2 = [$C ConstInt32 c]\"\n using const_of_i32[OF cs_def(4,2)]\n by blast\n have \"\\a s' vs' es'. \\s;vs;cs2@($* [Br_if j])\\ \\_i \\s';vs';es'\\\"\n proof (cases \"int_eq c 0\")\n case True\n thus ?thesis\n using c_def reduce.intros(1)[OF reduce_simple.br_if_false]\n by fastforce\n next\n case False\n thus ?thesis\n using c_def reduce.intros(1)[OF reduce_simple.br_if_true]\n by fastforce\n qed\n thus ?case\n using cs_def(5) progress_L0[OF _ cs_def(3), of s vs \"cs2 @ ($* [Br_if j])\" _ _ _ _ \"[]\"]\n by fastforce\nnext\n case (br_table \\ ts \"is\" i' t1s t2s)\n obtain cs1 cs2 where cs_def:\"s\\\\ \\ cs1 : ([]_> (t1s @ ts))\"\n \"s\\\\ \\ cs2 : ([] _> [T_i32])\"\n \"const_list cs1\"\n \"const_list cs2\"\n \"cs = cs1 @ cs2\"\n using e_type_const_list_cons[OF br_table(5), of s \\ \"(t1s @ ts)\" \"[T_i32]\"]\n e_type_const_list[of _ s \\ \"t1s @ ts\" \"(t1s @ ts) @ [T_i32]\"]\n br_table(2,5)\n unfolding const_list_def\n by fastforce\n obtain c where c_def:\"cs2 = [$C ConstInt32 c]\"\n using const_of_i32[OF cs_def(4,2)]\n by blast\n have \"\\a s' vs' es'. \\s;vs;[$C ConstInt32 c, $Br_table is i']\\ \\_i \\s';vs';es'\\\"\n proof (cases \"(nat_of_int c) < length is\")\n case True\n show ?thesis\n using reduce.intros(1)[OF reduce_simple.br_table[OF True]]\n by fastforce\n next\n case False\n hence \"length is \\ nat_of_int c\"\n by fastforce\n thus ?thesis\n using reduce.intros(1)[OF reduce_simple.br_table_length]\n by fastforce\n qed\n thus ?case\n using c_def cs_def progress_L0\n by fastforce\nnext\n case (return \\ ts t1s t2s)\n thus ?case\n using Lfilled.intros(1)[OF return(5), of _ \"[]\" \"[$Return]\"]\n by fastforce\nnext\n case (call j \\)\n show ?case\n using progress_L0[OF reduce.intros(2) call(6)]\n by fastforce\nnext\n case (call_indirect j \\ t1s t2s)\n obtain cs1 cs2 where cs_def:\"s\\\\ \\ cs1 : ([]_> t1s)\"\n \"s\\\\ \\ cs2 : ([] _> [T_i32])\"\n \"const_list cs1\"\n \"const_list cs2\"\n \"cs = cs1 @ cs2\"\n using e_type_const_list_cons[OF call_indirect(7), of s \\ t1s \"[T_i32]\"]\n e_type_const_list[of _ s \\ t1s \"t1s @ [T_i32]\"]\n call_indirect(4)\n by fastforce\n obtain c where c_def:\"cs2 = [$C ConstInt32 c]\"\n using cs_def(2,4) const_of_i32\n by fastforce\n consider \n (1) \"\\cl tf. stab s i (nat_of_int c) = Some cl \\ stypes s i j = tf \\ cl_type cl = tf\"\n | (2) \"\\cl. stab s i (nat_of_int c) = Some cl \\ stypes s i j \\ cl_type cl\"\n | (3) \"stab s i (nat_of_int c) = None\"\n by (metis option.collapse)\n hence \"\\a s' vs' es'. \\s;vs;[$C ConstInt32 c, $Call_indirect j]\\ \\_i \\s';vs';es'\\\"\n proof (cases)\n case 1\n thus ?thesis\n using reduce.intros(3)\n by blast\n next\n case 2\n thus ?thesis\n using reduce.intros(4)\n by blast\n next\n case 3\n thus ?thesis\n using reduce.intros(4)\n by blast\n qed\n then show ?case\n using c_def cs_def progress_L0\n by fastforce\nnext\n case (get_local j \\ t)\n obtain v vj vj' where v_def:\"v = vs ! j\" \"vj = (take j vs)\" \"vj' = (drop (j+1) vs)\"\n by blast\n have j_def:\"j < length vs\"\n using get_local(1,8)\n by simp\n hence vj_len:\"length vj = j\"\n using v_def(2)\n by fastforce\n hence \"vs = vj @ [v] @ vj'\"\n using v_def id_take_nth_drop j_def\n by fastforce\n thus ?case\n using progress_L0[OF reduce.intros(8)[OF vj_len, of s v vj'] get_local(6)]\n by fastforce\nnext\n case (set_local j \\ t)\n obtain v vj vj' where v_def:\"v = vs ! j\" \"vj = (take j vs)\" \"vj' = (drop (j+1) vs)\"\n by blast\n obtain v' where cs_def: \"cs = [$C v']\"\n using const_of_const_list set_local(3,6) e_type_const_list\n by fastforce\n have j_def:\"j < length vs\"\n using set_local(1,8)\n by simp\n hence vj_len:\"length vj = j\"\n using v_def(2)\n by fastforce\n hence \"vs = vj @ [v] @ vj'\"\n using v_def id_take_nth_drop j_def\n by fastforce\n thus ?case\n using reduce.intros(9)[OF vj_len, of s v vj' v' i] cs_def\n by fastforce\nnext\n case (tee_local i \\ t)\n obtain v where \"cs = [$C v]\"\n using const_of_const_list tee_local(3,6) e_type_const_list\n by fastforce\n thus ?case\n using reduce.intros(1)[OF reduce_simple.tee_local] tee_local(6)\n unfolding const_list_def\n by fastforce\nnext\n case (get_global j \\ t)\n thus ?case\n using reduce.intros(10)[of s vs j i] progress_L0\n by fastforce\nnext\n case (set_global j \\ t)\n obtain v where \"cs = [$C v]\"\n using const_of_const_list set_global(4,7) e_type_const_list\n by fastforce\n thus ?case\n using reduce.intros(11)[of s i j v _ vs]\n by fastforce\nnext\n case (load \\ a tp_sx t off)\n obtain c where c_def: \"cs = [$C ConstInt32 c]\"\n using const_of_i32 load(3,6) e_type_const_unwrap\n unfolding const_list_def\n by fastforce\n obtain j where mem_some:\"smem_ind s i = Some j\"\n using load(1,9)\n unfolding smem_ind_def\n by (fastforce split: list.splits)\n have \"\\a' s' vs' es'. \\s;vs;[$C ConstInt32 c, $Load t tp_sx a off]\\ \\_i \\s';vs';es'\\\"\n proof (cases tp_sx)\n case None\n note tp_none = None\n show ?thesis\n proof (cases \"load ((mems s)!j) (nat_of_int c) off (t_length t)\")\n case None\n show ?thesis\n using reduce.intros(13)[OF mem_some _ None, of vs] tp_none load(2)\n by fastforce\n next\n case (Some a)\n show ?thesis\n using reduce.intros(12)[OF mem_some _ Some, of vs] tp_none load(2)\n by fastforce\n qed\n next\n case (Some a)\n obtain tp sx where tp_some:\"tp_sx = Some (tp, sx)\"\n using Some\n by fastforce\n show ?thesis\n proof (cases \"load_packed sx ((mems s)!j) (nat_of_int c) off (tp_length tp) (t_length t)\")\n case None\n show ?thesis\n using reduce.intros(15)[OF mem_some _ None, of vs] tp_some load(2)\n by fastforce\n next\n case (Some a)\n show ?thesis\n using reduce.intros(14)[OF mem_some _ Some, of vs] tp_some load(2)\n by fastforce\n qed\n qed\n then show ?case\n using c_def progress_L0\n by fastforce\nnext\n case (store \\ a tp t off)\n obtain cs' v where cs_def:\"s\\\\ \\ [cs'] : ([] _> [T_i32])\"\n \"s\\\\ \\ [$ C v] : ([] _> [t])\"\n \"cs = [cs',$ C v]\"\n using const_list_split_2[OF store(6,3)] e_type_const_unwrap\n unfolding const_list_def\n by fastforce\n have t_def:\"typeof v = t\"\n using cs_def(2) b_e_type_value[OF unlift_b_e[of s \\ \"[C v]\" \"([] _> [t])\"]]\n by fastforce\n obtain j where mem_some:\"smem_ind s i = Some j\"\n using store(1,9)\n unfolding smem_ind_def\n by (fastforce split: list.splits)\n obtain c where c_def:\"cs' = $C ConstInt32 c\"\n using const_of_i32[OF _ cs_def(1)] cs_def(3) store(6)\n unfolding const_list_def\n by fastforce\n have \"\\a' s' vs' es'. \\s;vs;[$C ConstInt32 c, $C v, $Store t tp a off]\\ \\_i \\s';vs';es'\\\"\n proof (cases tp)\n case None\n note tp_none = None\n show ?thesis\n proof (cases \"store (s.mems s ! j) (nat_of_int c) off (bits v) (t_length t)\")\n case None\n show ?thesis\n using reduce.intros(17)[OF _ mem_some _ None, of vs] t_def tp_none store(2)\n unfolding types_agree_def\n by fastforce\n next\n case (Some a)\n show ?thesis\n using reduce.intros(16)[OF _ mem_some _ Some, of vs] t_def tp_none store(2)\n unfolding types_agree_def\n by fastforce\n qed\n next\n case (Some a)\n note tp_some = Some\n show ?thesis\n proof (cases \"store_packed (s.mems s ! j) (nat_of_int c) off (bits v) (tp_length a)\")\n case None\n show ?thesis\n using reduce.intros(19)[OF _ mem_some _ None, of t vs] t_def tp_some store(2)\n unfolding types_agree_def\n by fastforce\n next\n case (Some a)\n show ?thesis\n using reduce.intros(18)[OF _ mem_some _ Some, of t vs] t_def tp_some store(2)\n unfolding types_agree_def\n by fastforce\n qed\n qed\n then show ?case\n using c_def cs_def progress_L0\n by fastforce\nnext\n case (current_memory \\)\n obtain j where mem_some:\"smem_ind s i = Some j\"\n using current_memory(1,8)\n unfolding smem_ind_def\n by (fastforce split: list.splits)\n thus ?case\n using progress_L0[OF reduce.intros(20)[OF mem_some] current_memory(5), of _ _ vs \"[]\"]\n by fastforce\nnext\n case (grow_memory \\)\n obtain c where c_def:\"cs = [$C ConstInt32 c]\"\n using const_of_i32 grow_memory(2,5)\n by fastforce\n obtain j where mem_some:\"smem_ind s i = Some j\"\n using grow_memory(1,8)\n unfolding smem_ind_def\n by (fastforce split: list.splits)\n show ?case\n using reduce.intros(22)[OF mem_some, of _] c_def\n by fastforce\nnext\n case (empty \\)\n thus ?case\n unfolding const_list_def\n by simp\nnext\n case (composition \\ es t1s t2s e t3s)\n consider (1) \"\\ const_list ($* es)\" | (2) \"const_list ($* es)\" \"\\ const_list ($*[e])\"\n using composition(9)\n unfolding const_list_def\n by fastforce\n thus ?case\n proof (cases)\n case 1\n have \"(\\lholed. \\ Lfilled 0 lholed [$Return] (cs @ ($* es)))\"\n \"(\\i lholed. \\ Lfilled 0 lholed [$Br i] (cs @ ($* es)))\"\n proof safe\n fix lholed\n assume \"Lfilled 0 lholed [$Return] (cs @ ($* es))\"\n hence \"\\lholed'. Lfilled 0 lholed' [$Return] (cs @ ($* es @ [e]))\"\n proof (cases rule: Lfilled.cases)\n case (L0 vs es')\n thus ?thesis\n using Lfilled.intros(1)[of \"vs\" _ \"es'@ ($*[e])\" \"[$Return]\"]\n by (metis append.assoc map_append)\n qed simp\n thus False\n using composition(6)\n by simp\n next\n fix i lholed\n assume \"Lfilled 0 lholed [$Br i] (cs @ ($* es))\"\n hence \"\\lholed'. Lfilled 0 lholed' [$Br i] (cs @ ($* es @ [e]))\"\n proof (cases rule: Lfilled.cases)\n case (L0 vs es')\n thus ?thesis\n using Lfilled.intros(1)[of \"vs\" _ \"es'@ ($*[e])\" \"[$Br i]\"]\n by (metis append.assoc map_append)\n qed simp\n thus False\n using composition(7)\n by simp\n qed\n thus ?thesis\n using composition(8,10,11) composition(2)[OF composition(5) _ _ _ 1]\n progress_L0[of s vs \"(cs @ ($* es))\" i _ _ _ \"[]\" \"$*[e]\"]\n unfolding const_list_def\n by (metis append_assoc list_all_simps(2) map_append self_append_conv2)\n next\n case 2\n hence \"const_list (cs@($* es))\"\n using composition(8)\n unfolding const_list_def\n by simp\n moreover\n have \"s\\\\ \\ (cs@($* es)) : ([] _> t2s)\"\n using composition(5) e_typing_s_typing.intros(1)[OF composition(1)] e_type_comp_conc\n by fastforce\n ultimately\n show ?thesis\n using composition(4)[of \"(cs@($* es))\"] 2(2) composition(6,7) composition(10-)\n by fastforce\n qed\nnext\n case (weakening \\ es t1s t2s ts)\n obtain cs1 cs2 where cs_def:\"s\\\\ \\ cs1 : ([] _> ts)\"\n \"s\\\\ \\ cs2 : ([] _> t1s)\"\n \"cs = cs1 @ cs2\"\n \"const_list cs1\"\n \"const_list cs2\"\n using e_type_const_list_cons[OF weakening(6,3)] e_type_const_list[of _ s \\ \"ts\" \"ts @ t1s\"]\n by fastforce\n have \"(\\lholed. \\ Lfilled 0 lholed [$Return] (cs2 @ ($* es)))\"\n \"(\\i lholed. \\ Lfilled 0 lholed [$Br i] (cs2 @ ($* es)))\"\n proof safe\n fix lholed\n assume \"Lfilled 0 lholed [$Return] (cs2 @ ($* es))\"\n hence \"\\lholed'. Lfilled 0 lholed' [$Return] (cs1 @ cs2 @ ($* es))\"\n proof (cases rule: Lfilled.cases)\n case (L0 vs es')\n thus ?thesis\n using Lfilled.intros(1)[of \"cs1 @ vs\" _ \"es'\" \"[$Return]\"] cs_def(4)\n unfolding const_list_def\n by fastforce\n qed simp\n thus False\n using weakening(4) cs_def(3)\n by simp\n next\n fix i lholed\n assume \"Lfilled 0 lholed [$Br i] (cs2 @ ($* es))\"\n hence \"\\lholed'. Lfilled 0 lholed' [$Br i] (cs1 @ cs2 @ ($* es))\"\n proof (cases rule: Lfilled.cases)\n case (L0 vs es')\n thus ?thesis\n using Lfilled.intros(1)[of \"cs1 @ vs\" _ \"es'\" \"[$Br i]\"] cs_def(4)\n unfolding const_list_def\n by fastforce\n qed simp\n thus False\n using weakening(5) cs_def(3)\n by simp\n qed\n hence \"\\a s' vs' es'. \\s;vs;cs2@($*es)\\ \\_i \\s';vs';es'\\\"\n using weakening(2)[OF cs_def(2) _ _ cs_def(5) weakening(7)] weakening(8-)\n by fastforce\n thus ?case\n using progress_L0[OF _ cs_def(4), of s vs \"cs2 @ ($* es)\" i _ _ _ \"[]\"] cs_def(3)\n by fastforce\nqed\n\nlemma progress_e:\n assumes \"s\\None \\_i vs;cs_es : ts'\"\n \"\\ k lholed. \\(Lfilled k lholed [$Return] cs_es)\"\n \"\\ i k lholed. (Lfilled k lholed [$Br (i)] cs_es) \\ i < k\"\n \"cs_es \\ [Trap]\"\n \"\\ const_list (cs_es)\"\n \"store_typing s\"\n shows \"\\a s' vs' es'. \\s;vs;cs_es\\ \\_i \\s';vs';es'\\\"\nproof -\n fix \\ cs es ts_c\n have prems1:\n \"s\\\\ \\ es : (ts_c _> ts') \\\n s\\\\ \\ cs_es : ([] _> ts') \\\n cs_es = cs@es \\\n const_list cs \\\n s\\\\ \\ cs : ([] _> ts_c) \\\n (\\ k lholed. \\(Lfilled k lholed [$Return] cs_es)) \\\n (\\ i k lholed. (Lfilled k lholed [$Br (i)] cs_es) \\ i < k) \\\n cs_es \\ [Trap] \\\n \\ const_list (cs_es) \\\n store_typing s \\\n length (local \\) = length (vs) \\\n length (memory \\) = length (inst.mems i) \\\n \\a s' vs' cs_es'. \\s;vs;cs_es\\ \\_i \\s';vs';cs_es'\\\"\n and prems2:\n \"s\\None \\_i vs;cs_es : ts' \\\n (\\ k lholed. \\(Lfilled k lholed [$Return] cs_es)) \\\n (\\ i k lholed. (Lfilled k lholed [$Br (i)] cs_es) \\ i < k) \\\n cs_es \\ [Trap] \\\n \\ const_list (cs_es) \\\n store_typing s \\\n \\a s' vs' cs_es'. \\s;vs;cs_es\\ \\_i \\s';vs';cs_es'\\\"\n proof (induction arbitrary: vs ts_c ts' i cs_es cs rule: e_typing_s_typing.inducts)\n case (1 \\ b_es tf s)\n hence \"\\ \\ b_es : (ts_c _> ts')\"\n using e_type_comp_conc1[of s \\ cs \"($* b_es)\" \"[]\" \"ts'\"] unlift_b_e\n by (metis e_type_const_conv_vs typing_map_typeof)\n then show ?case\n using progress_b_e[OF _ 1(5) _ _ 1(4) _ 1(11,12)] 1(3,4,6,7,9) list_all_append\n unfolding const_list_def\n by fastforce\n next\n case (2 s \\ es t1s t2s e t3s)\n show ?case\n proof (cases \"const_list es\")\n case True\n hence \"const_list (cs@es)\"\n using 2(7)\n unfolding const_list_def\n by simp\n moreover\n have \"\\ts''. (s\\\\ \\ (cs @ es) : ([] _> ts''))\"\n using 2(5,6)\n by (metis append.assoc e_type_comp_conc1)\n ultimately\n show ?thesis\n using 2(4)[OF 2(5) _ _ _ 2(9,10,11,12,13,14,15), of \"(cs@es)\"] 2(6,15)\n by fastforce\n next\n case False\n hence \"\\const_list (cs@es)\"\n unfolding const_list_def\n by simp\n moreover\n have \"\\ts''. (s\\\\ \\ (cs @ es) : ([] _> ts''))\"\n using 2(5,6)\n by (metis append.assoc e_type_comp_conc1)\n moreover\n have \"\\k lholed. \\ Lfilled k lholed [$Return] (cs @ es)\"\n proof -\n {\n assume \"\\k lholed. Lfilled k lholed [$Return] (cs @ es)\"\n then obtain k lholed where local_assms:\"Lfilled k lholed [$Return] (cs @ es)\"\n by blast\n hence \"\\lholed'. Lfilled k lholed' [$Return] (cs @ es @ [e])\"\n proof (cases rule: Lfilled.cases)\n case (L0 vs es')\n obtain lholed' where \"lholed' = LBase vs (es'@[e])\"\n by blast\n thus ?thesis\n using L0\n by (metis Lfilled.intros(1) append.assoc)\n next\n case (LN vs ts es' l es'' k lfilledk)\n obtain lholed' where \"lholed' = LRec vs ts es' l (es''@[e])\"\n by blast\n thus ?thesis\n using LN\n by (metis Lfilled.intros(2) append.assoc)\n qed\n hence False\n using 2(6,9)\n by blast\n }\n thus \"\\k lholed. \\ Lfilled k lholed [$Return] (cs @ es)\"\n by blast\n qed\n moreover\n have \"\\i k lholed. Lfilled k lholed [$Br i] (cs @ es) \\ i < k\"\n proof -\n {\n assume \"\\i k lholed. Lfilled k lholed [$Br i] (cs @ es) \\ \\(i < k)\"\n then obtain i k lholed where local_assms:\"Lfilled k lholed [$Br i] (cs @ es)\" \"\\(i < k)\"\n by blast\n hence \"\\lholed'. Lfilled k lholed' [$Br i] (cs @ es @ [e]) \\ \\(i < k)\"\n proof (cases rule: Lfilled.cases)\n case (L0 vs es')\n obtain lholed' where \"lholed' = LBase vs (es'@[e])\"\n by blast\n thus ?thesis\n using L0 local_assms(2)\n by (metis Lfilled.intros(1) append.assoc)\n next\n case (LN vs ts es' l es'' k lfilledk)\n obtain lholed' where \"lholed' = LRec vs ts es' l (es''@[e])\"\n by blast\n thus ?thesis\n using LN local_assms(2)\n by (metis Lfilled.intros(2) append.assoc)\n qed\n hence False\n using 2(6,10)\n by blast\n }\n thus \"\\i k lholed. Lfilled k lholed [$Br i] (cs @ es) \\ i < k\"\n by blast\n qed\n moreover\n note preds = calculation\n show ?thesis\n proof (cases \"cs @ es = [Trap]\")\n case True\n thus ?thesis\n using reduce_simple.trap[of _ \"(LBase [] [e])\"]\n Lfilled.intros(1)[of \"[]\" \"LBase [] [e]\" \"[e]\" \"cs @ es\"]\n reduce.intros(1) 2(6,11)\n unfolding const_list_def\n by (metis append.assoc append_Nil list.pred_inject(1))\n next\n case False\n thus ?thesis\n using 2(3)[OF _ _ 2(7,8) _ _ _ _ 2(13,14,15)] preds 2(6,15)\n progress_L0[of s vs \"(cs @ es)\" _ _ _ _ \"[]\" \"[e]\"]\n unfolding const_list_def\n by (metis append.assoc append_Nil list.pred_inject(1))\n qed\n qed\n next\n case (3 s \\ es t1s t2s ts)\n thus ?case\n by fastforce\n next\n case (4 s \\)\n have cs_es_def:\"Lfilled 0 (LBase cs []) [Trap] cs_es\"\n using Lfilled.intros(1)[OF 4(3), of _ \"[]\" \"[Trap]\"] 4(2)\n by fastforce\n thus ?case\n using reduce_simple.trap[OF 4(7) cs_es_def] reduce.intros(1)\n by blast\n next\n case (5 s ts j vls es n \\)\n consider (1) \"(\\k lholed. \\ Lfilled k lholed [$Return] es)\"\n \"(\\k lholed i. (Lfilled k lholed [$Br i] es) \\ i < k)\"\n \"es \\ [Trap]\"\n \"\\ const_list es\"\n | (2) \"\\k lholed. Lfilled k lholed [$Return] es\"\n | (3) \"const_list es \\ (es = [Trap])\"\n | (4) \"\\k lholed i. (Lfilled k lholed [$Br i] es) \\ i \\ k\"\n using not_le_imp_less\n by blast\n thus ?case\n proof (cases)\n case 1\n obtain s' vs'' a where temp1:\"\\s;vls;es\\ \\_ j \\s';vs'';a\\\"\n using 5(3)[OF 1(1) _ 1(3,4) 5(12)] 1(2)\n by fastforce\n show ?thesis\n using reduce.intros(24)[OF temp1, of vs] progress_L0[where ?cs = cs, OF _ 5(6)] 5(5)\n by fastforce\n next\n case 2\n then obtain k lholed where local_assms:\"(Lfilled k lholed [$Return] es)\"\n by blast\n then obtain lholed' vs' \\' where lholed'_def:\"(Lfilled k lholed' (vs'@[$Return]) es)\"\n \"s\\\\' \\ vs' : ([] _> ts)\"\n \"const_list vs'\"\n using progress_LN_return[OF local_assms, of s _ ts ts] s_type_unfold[OF 5(1)]\n by fastforce\n hence temp1:\"\\a. \\[Local n j vls es]\\ \\ \\vs'\\\"\n using reduce_simple.return[OF lholed'_def(3)]\n e_type_const_list[OF lholed'_def(3,2)] 5(2)\n by fastforce\n show ?thesis\n using temp1 progress_L0[OF reduce.intros(1) 5(6)] 5(5)\n by fastforce\n next\n case 3\n then consider (1) \"const_list es\" | (2) \"es = [Trap]\"\n by blast\n hence temp1:\"\\a. \\s;vs;[Local n j vls es]\\ \\_ i \\s;vs;es\\\"\n proof (cases)\n case 1\n have \"length es = length ts\"\n using s_type_unfold[OF 5(1)] e_type_const_list[OF 1]\n by fastforce\n thus ?thesis\n using reduce_simple.local_const[OF 1] reduce.intros(1) 5(2)\n by fastforce\n next\n case 2\n thus ?thesis\n using reduce_simple.local_trap reduce.intros(1)\n by fastforce\n qed\n thus ?thesis\n using progress_L0[where ?cs = cs, OF _ 5(6)] 5(5)\n by fastforce\n next\n case 4\n then obtain k' lholed' i' where temp1:\"Lfilled k' lholed' [$Br (k'+i')] es\"\n using le_Suc_ex\n by blast\n obtain \\' \\j where c_def:\"s\\\\' \\ es : ([] _> ts)\"\n \"inst_typing s j \\j\"\n \"\\' = \\j\\local := (local \\j) @ (map typeof vls), return := Some ts\\\"\n using 5(1) s_type_unfold\n by metis\n hence \"length (label \\') = 0\"\n using c_def store_local_label_empty 5(12)\n by fastforce\n thus ?thesis \n using progress_LN1[OF temp1 c_def(1)]\n by linarith\n qed\n next\n case (6 s cl tf \\)\n obtain ts'' where ts''_def:\"s\\\\ \\ cs : ([] _> ts'')\" \"s\\\\ \\ [Invoke cl] : (ts'' _> ts')\"\n using 6(2,3) e_type_comp_conc1\n by fastforce\n obtain ts_c t1s t2s where cl_def:\"(ts'' = ts_c @ t1s)\"\n \"(ts' = ts_c @ t2s)\"\n \"cl_type cl = (t1s _> t2s)\"\n using e_type_invoke[OF ts''_def(2)]\n by fastforce\n obtain vs1 vs2 where vs_def:\"s\\\\ \\ vs1 : ([] _> ts_c)\"\n \"s\\\\ \\ vs2 : (ts_c _> ts_c @ t1s)\"\n \"cs = vs1 @ vs2\"\n \"const_list vs1\"\n \"const_list vs2\"\n using e_type_const_list_cons[OF 6(4)] ts''_def(1) cl_def(1)\n by fastforce\n have l:\"(length vs2) = (length t1s)\"\n using e_type_const_list vs_def(2,5)\n by fastforce\n show ?case\n proof (cases cl)\n case (Func_native x11 x12 x13 x14)\n hence func_native_def:\"cl = Func_native x11 (t1s _> t2s) x13 x14\"\n using cl_def(3)\n unfolding cl_type_def\n by simp\n have \"\\a a'. \\s;vs;vs2 @ [Invoke cl]\\ \\_ i \\s;vs;a\\\"\n using reduce.intros(5)[OF func_native_def] e_type_const_conv_vs[OF vs_def(5)] l\n unfolding n_zeros_def\n by fastforce\n thus ?thesis\n using progress_L0 vs_def(3,4) 6(3)\n by fastforce\n next\n case (Func_host x21 x22)\n hence func_host_def:\"cl = Func_host (t1s _> t2s) x22\"\n using cl_def(3)\n unfolding cl_type_def\n by simp\n obtain vcs where vcs_def:\"vs2 = $$* vcs\"\n using e_type_const_conv_vs[OF vs_def(5)]\n by blast\n fix hs\n have \"\\s' a a'. \\s;vs;vs2 @ [Invoke cl]\\ \\_ i \\s';vs;a\\\"\n proof (cases \"host_apply s (t1s _> t2s) x22 vcs hs\")\n case None\n thus ?thesis\n using reduce.intros(7)[OF func_host_def] l vcs_def\n by fastforce\n next\n case (Some a)\n then obtain s' vcs' where ha_def:\"host_apply s (t1s _> t2s) x22 vcs hs = Some (s', vcs')\"\n by (metis surj_pair)\n have \"list_all2 types_agree t1s vcs\"\n using e_typing_imp_list_types_agree vs_def(2,4) vcs_def\n by simp\n thus ?thesis\n using reduce.intros(6)[OF func_host_def _ _ _ _ ha_def] l vcs_def\n host_apply_respect_type[OF _ ha_def]\n by fastforce\n qed\n thus ?thesis\n using vs_def(3,4) 6(3) progress_L0\n by fastforce\n qed\n next\n case (7 s \\ e0s ts t2s es n)\n consider (1) \"(\\k lholed. \\ Lfilled k lholed [$Return] es)\"\n \"(\\k lholed i. (Lfilled k lholed [$Br i] es) \\ i < k)\"\n \"es \\ [Trap]\"\n \"\\ const_list es\"\n | (2) \"\\k lholed. Lfilled k lholed [$Return] es\"\n | (3) \"const_list es \\ (es = [Trap])\"\n | (4) \"\\k lholed i. (Lfilled k lholed [$Br i] es) \\ i = k\"\n | (5) \"\\k lholed i. (Lfilled k lholed [$Br i] es) \\ i > k\"\n using linorder_neqE_nat\n by blast\n thus ?case\n proof (cases)\n case 1\n have temp1:\"es = [] @ es\" \"const_list []\"\n unfolding const_list_def\n by auto\n have temp2:\"s\\\\\\label := [ts] @ label \\\\ \\ [] : ([] _> [])\"\n using b_e_typing.empty e_typing_s_typing.intros(1)\n by fastforce\n have \"\\s' vs' a. \\s;vs;es\\ \\_ i \\s';vs';a\\\"\n using 7(5)[OF 7(2), of \"[]\" \"[]\", OF temp1 temp2 1(1) _ 1(3,4) 7(14)]\n 1(2) 7(15,16)\n unfolding const_list_def\n by fastforce\n then obtain s' vs' a where red_def:\"\\s;vs;es\\ \\_ i \\s';vs';a\\\"\n by blast\n have temp4:\"\\es. Lfilled 0 (LBase [] []) es es\"\n using Lfilled.intros(1)[of \"[]\" \"(LBase [] [])\" \"[]\"]\n unfolding const_list_def\n by fastforce\n hence temp5:\"Lfilled 1 (LRec cs n e0s (LBase [] []) []) es (cs@[Label n e0s es])\"\n using Lfilled.intros(2)[of cs \"(LRec cs n e0s (LBase [] []) [])\" n e0s \"(LBase [] [])\" \"[]\" 0 es es] 7(8)\n unfolding const_list_def\n by fastforce\n have temp6:\"Lfilled 1 (LRec cs n e0s (LBase [] []) []) a (cs@[Label n e0s a])\"\n using temp4 Lfilled.intros(2)[of cs \"(LRec cs n e0s (LBase [] []) [])\" n e0s \"(LBase [] [])\" \"[]\" 0 a a] 7(8)\n unfolding const_list_def\n by fastforce\n show ?thesis\n using reduce.intros(23)[OF _ temp5 temp6] 7(7) red_def\n by fastforce\n next\n case 2\n then obtain k lholed where \"(Lfilled k lholed [$Return] es)\"\n by blast\n hence \"(Lfilled (k+1) (LRec cs n e0s lholed []) [$Return] (cs@[Label n e0s es]))\"\n using Lfilled.intros(2) 7(8)\n by fastforce\n thus ?thesis\n using 7(10)[of \"k+1\"] 7(7)\n by fastforce\n next\n case 3\n hence temp1:\"\\a. \\s;vs;[Label n e0s es]\\ \\_ i \\s;vs;es\\\"\n using reduce_simple.label_const reduce_simple.label_trap reduce.intros(1)\n by fastforce\n show ?thesis\n using progress_L0[OF _ 7(8)] 7(7) temp1\n by fastforce\n next\n case 4\n then obtain k lholed where lholed_def:\"(Lfilled k lholed [$Br (k+0)] es)\"\n by fastforce\n then obtain lholed' vs' \\' where lholed'_def:\"(Lfilled k lholed' (vs'@[$Br (k)]) es)\"\n \"s\\\\' \\ vs' : ([] _> ts)\"\n \"const_list vs'\"\n using progress_LN[OF lholed_def 7(2), of ts]\n by fastforce\n have \"\\es' a. \\[Label n e0s es]\\ \\ \\vs'@e0s\\\"\n using reduce_simple.br[OF lholed'_def(3) _ lholed'_def(1)] 7(3)\n e_type_const_list[OF lholed'_def(3,2)]\n by fastforce\n hence \"\\es' a. \\s;vs;[Label n e0s es]\\ \\_ i \\s;vs;es'\\\"\n using reduce.intros(1)\n by fastforce\n thus ?thesis\n using progress_L0 7(7,8)\n by fastforce\n next\n case 5\n then obtain i k lholed where lholed_def:\"(Lfilled k lholed [$Br i] es)\" \"i > k\"\n using less_imp_add_positive\n by blast\n have k1_def:\"Lfilled (k+1) (LRec cs n e0s lholed []) [$Br i] cs_es\"\n using 7(7) Lfilled.intros(2)[OF 7(8) _ lholed_def(1), of _ n e0s \"[]\"]\n by fastforce\n thus ?thesis\n using 7(11)[OF k1_def] lholed_def(2)\n by simp\n qed\n next\n case (8 tvs vs \\ i \\i \\ rs es ts)\n have \"length (local \\) = length vs\"\n using 8(1,3) store_local_label_empty[OF 8(2)]\n by fastforce\n moreover\n have \"length (memory \\) = length (inst.mems i)\"\n using store_mem_exists[OF 8(2)] 8(3)\n by simp\n ultimately show ?case\n using 8(6)[OF 8(4) _ _ _ 8(7,8,9,10,11)]\n e_typing_s_typing.intros(1)[OF b_e_typing.empty[of \\]]\n unfolding const_list_def\n by fastforce\n qed\n show ?thesis\n using prems2[OF assms]\n by fastforce\nqed\n\nlemma progress_e1:\n assumes \"s\\None \\_i vs;es : ts\"\n shows \"\\(Lfilled k lholed [$Return] es)\"\nproof -\n {\n assume \"\\k lholed. (Lfilled k lholed [$Return] es)\"\n then obtain k lholed where local_assms:\"(Lfilled k lholed [$Return] es)\"\n by blast\n obtain \\ \\i where c_def:\"inst_typing s i \\i\"\n \"\\ = \\i\\local := (local \\i) @ (map typeof vs), return := None\\\"\n \"(s\\\\ \\ es : ([] _> ts))\"\n using assms s_type_unfold\n by metis\n have \"\\rs. return \\ = Some rs\"\n using local_assms c_def(3)\n proof (induction \"[$Return]\" es arbitrary: \\ ts rule: Lfilled.induct)\n case (L0 vs lholed es')\n thus ?case\n using e_type_comp_conc2[OF L0(3)] unlift_b_e[of s \\ \"[Return]\"] b_e_type_return\n by fastforce\n next\n case (LN vs lholed tls es' l es'' k lfilledk)\n thus ?case\n using e_type_comp_conc2[OF LN(5)] e_type_label[of s \\ tls es' lfilledk]\n by fastforce\n qed\n hence False\n using c_def(2)\n by fastforce\n }\n thus \"\\ k lholed. \\(Lfilled k lholed [$Return] es)\"\n by blast\nqed\n\nlemma progress_e2:\n assumes \"s\\None \\_i vs;es : ts\"\n \"store_typing s\"\n shows \"(Lfilled k lholed [$Br (j)] es) \\ j < k\"\nproof -\n {\n assume \"(\\i k lholed. (Lfilled k lholed [$Br (i)] es) \\ i \\ k)\"\n then obtain j k lholed where local_assms:\"(Lfilled k lholed [$Br (k+j)] es)\"\n by (metis le_iff_add)\n obtain \\ \\i where c_def:\"inst_typing s i \\i\"\n \"\\ = \\i\\local := (local \\i) @ (map typeof vs), return := None\\\"\n \"(s\\\\ \\ es : ([] _> ts))\"\n using assms s_type_unfold\n by metis\n have \"j < length (label \\)\"\n using progress_LN1[OF local_assms c_def(3)]\n by -\n hence False\n using store_local_label_empty(1)[OF c_def(1)] c_def(2)\n by fastforce\n }\n thus \"(\\ j k lholed. (Lfilled k lholed [$Br (j)] es) \\ j < k)\"\n by fastforce\nqed\n\nlemma progress_e3:\n assumes \"s\\None \\_i vs;cs_es : ts'\"\n \"cs_es \\ [Trap]\"\n \"\\ const_list (cs_es)\"\n \"store_typing s\"\n shows \"\\a s' vs' es'. \\s;vs;cs_es\\ \\_i \\s';vs';es'\\\"\n using assms progress_e progress_e1 progress_e2\n by fastforce\n\nlemma reduce_trans_app:\n assumes \"\\s;vs;es\\ \\_i \\s'';vs'';es''\\\"\n \"reduce_trans i (s'',vs'',es'') (s',vs',es')\"\n shows \"reduce_trans i (s,vs,es) (s',vs',es')\"\nproof -\n have 1:\"(\\(s,vs,es) (s',vs',es'). \\s;vs;es\\ \\_i \\s';vs';es'\\) (s,vs,es) (s'',vs'',es'')\"\n using assms\n by auto\n thus ?thesis\n using assms converse_rtranclp_into_rtranclp\n unfolding reduce_trans_def\n by (metis (no_types, lifting))\nqed\n\nlemma reduce_length_locals:\n assumes \"\\s;vs;es\\ \\_i \\s';vs';es'\\\"\n shows \"length vs = length vs'\"\n using assms\n apply (induction rule: reduce.induct)\n apply auto\n done\n\nlemma reduce_trans_length_locals:\n assumes \"reduce_trans i (s,vs,es) (s',vs', es')\"\n shows \"length vs = length vs'\"\n using assms\n unfolding reduce_trans_def\n apply (induction \"(s',vs', es')\" arbitrary: s' vs' es' rule: rtranclp_induct)\n apply (auto simp add: reduce_length_locals split: prod.splits)\n done\n\nlemma reduce_trans_app_end:\n assumes \"\\s'';vs'';es''\\ \\_i \\s';vs';es'\\\"\n \"reduce_trans i (s,vs,es) (s'',vs'',es'')\"\n shows \"reduce_trans i (s,vs,es) (s',vs',es')\"\nproof -\n have 1:\"(\\(s,vs,es) (s',vs',es'). \\s;vs;es\\ \\_i \\s';vs';es'\\) (s'',vs'',es'') (s',vs',es')\"\n using assms\n by auto\n thus ?thesis\n using assms \n unfolding reduce_trans_def\n by (simp add: rtranclp.rtrancl_into_rtrancl)\nqed\nthm rtranclp_induct\n\nlemma reduce_trans_L0:\n assumes \"reduce_trans i (s,vs,es) (s',vs',es')\"\n shows \"reduce_trans i (s,vs,($$*ves)@es@es_f) (s',vs',($$*ves)@es'@es_f)\"\n using assms\n unfolding reduce_trans_def\nproof (induction \"(s',vs',es')\" arbitrary: s' vs' es' rule: rtranclp_induct)\n case base\n thus ?case\n by (auto split: prod.splits)\nnext\n case (step y)\n obtain s'' vs'' es'' where y_is:\"y = (s'', vs'',es'')\"\n by (cases y) blast\n hence \"reduce_trans i (s,vs,($$*ves)@es@es_f) (s'',vs'',($$*ves)@es''@es_f)\"\n using step(3)\n unfolding reduce_trans_def\n by simp\n moreover\n have \"\\s'';vs'';es''\\ \\_i \\s';vs';es'\\\"\n using step(2) y_is\n by blast\n hence \"\\s'';vs'';($$*ves)@es''@es_f\\ \\_i \\s';vs';($$*ves)@es'@es_f\\\"\n using progress_L0 is_const_list\n by fastforce\n ultimately\n show ?case\n using y_is reduce_trans_app_end reduce_trans_def\n by auto\nqed\n\nlemma reduce_trans_lfilled:\n assumes \"reduce_trans i (s,vs,es) (s',vs',es')\"\n \"Lfilled n lfilled es lfes\"\n \"Lfilled n lfilled es' lfes'\"\n shows \"reduce_trans i (s,vs,lfes) (s',vs',lfes')\"\n using assms\n unfolding reduce_trans_def\nproof (induction \"(s',vs',es')\" arbitrary: s' vs' es' lfes' rule: rtranclp_induct)\n case base\n thus ?case\n using lfilled_deterministic\n by blast\nnext\n case (step y)\n obtain s'' vs'' es'' where y_is:\"y = (s'', vs'',es'')\"\n by (cases y) blast\n then obtain lfes'' where lfes'':\"Lfilled n lfilled es'' lfes''\"\n \"reduce_trans i (s,vs,lfes) (s'',vs'',lfes'')\"\n using step(3,4) progress_LN2\n unfolding reduce_trans_def\n by simp metis\n moreover\n have 1:\"\\s'';vs'';es''\\ \\_i \\s';vs';es'\\\"\n using step(2) y_is\n by blast\n hence \"\\s'';vs'';lfes''\\ \\_i \\s';vs';lfes'\\\"\n using step(5) lfes''(1) reduce.label\n by blast\n ultimately\n show ?case\n using y_is reduce_trans_app_end reduce_trans_def\n by auto\nqed\n\nlemma reduce_trans_label:\n assumes \"reduce_trans i (s,vs,es) (s',vs',es')\"\n shows \"reduce_trans i (s,vs,[Label n les es]) (s',vs',[Label n les es'])\"\n using assms\n unfolding reduce_trans_def\nproof (induction \"(s',vs',es')\" arbitrary: s' vs' es' rule: rtranclp_induct)\n case base\n thus ?case\n by auto\nnext\n case (step y)\n obtain s'' vs'' es'' where y_is:\"y = (s'', vs'',es'')\"\n by (cases y) blast\n hence \"reduce_trans i (s,vs,[Label n les es]) (s'',vs'',[Label n les es''])\"\n using step(3)\n unfolding reduce_trans_def\n by simp\n moreover\n have 1:\"\\s'';vs'';es''\\ \\_i \\s';vs';es'\\\"\n using step(2) y_is\n by blast\n have \"\\s'';vs'';[Label n les es'']\\ \\_i \\s';vs';[Label n les es']\\\"\n using reduce.label[OF 1] Lfilled.intros(2)[of \"[]\" _ n les \"LBase [] []\" \"[]\" 0]\n apply simp\n apply (meson Lfilled_exact.L0 Lfilled_exact_imp_Lfilled const_list_def list_all_simps(2))\n done\n ultimately\n show ?case\n using y_is reduce_trans_app_end reduce_trans_def\n by auto\nqed\n\nlemma reduce_trans_consts:\n assumes \"reduce_trans inst (s, vs, $$*ves) (s', vs', $$*ves')\"\n shows \"s = s' \\ vs = vs' \\ ves = ves'\"\n using assms\n unfolding reduce_trans_def\nproof (induction \"(s, vs, $$*ves)\" rule: converse_rtranclp_induct)\n case base\n thus ?case\n using inj_basic_econst\n by auto\nnext\n case (step y)\n thus ?case\n using const_list_no_progress is_const_list\n by auto\nqed\n\nlemma reduce_trans_local:\n assumes \"reduce_trans j (s,vs,es) (s',vs',es')\"\n shows \"reduce_trans i (s,v0s,[Local n j vs es]) (s',v0s,[Local n j vs' es'])\"\n using assms\n unfolding reduce_trans_def\nproof (induction \"(s',vs',es')\" arbitrary: s' vs' es' rule: rtranclp_induct)\n case base\n thus ?case\n by auto\nnext\n case (step y)\n obtain s'' vs'' es'' where y_is:\"y = (s'', vs'',es'')\"\n by (cases y) blast\n hence \"reduce_trans i (s,v0s,[Local n j vs es]) (s'',v0s,[Local n j vs'' es''])\"\n using step(3)\n unfolding reduce_trans_def\n by simp\n moreover\n have 1:\"\\s'';vs'';es''\\ \\_j \\s';vs';es'\\\"\n using step(2) y_is\n by blast\n have \"\\s'';v0s;[Local n j vs'' es'']\\ \\_i \\s';v0s;[Local n j vs' es']\\\"\n using reduce.local[OF 1]\n by blast\n ultimately\n show ?case\n using y_is reduce_trans_app_end reduce_trans_def\n by auto\nqed\n\nlemma reduce_trans_compose:\n assumes \"reduce_trans i (s,vs,es) (s'',vs'',es'')\"\n \"reduce_trans i (s'',vs'',es'') (s',vs',es')\"\n shows \"reduce_trans i (s,vs,es) (s',vs',es')\"\n using assms\n unfolding reduce_trans_def\n by auto\n\nend","avg_line_length":37.975704859,"max_line_length":192,"alphanum_fraction":0.5783146804} {"size":35073,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"(*\n File: RealAlg_Arith.thy\n Author: Wenda Li, University of Cambridge\n*)\ntheory RealAlg_Arith \n imports \n RealAlg_Imp\nbegin\n\nhide_const Fraction_Field.Fract\n\nSML_import \\val println = Output.writeln\\\nSML_import \\val zz_gcd = Integer.gcd\\\nSML_import \\val zz_lcm = Integer.lcm\\\nSML_import \\val pointerEq = pointer_eq\\\n\n(*code from MetiTarski*)\nSML_file \"..\/MetiTarski_source\/Random.sig\" SML_file \"..\/MetiTarski_source\/Random.sml\"\nSML_file \"..\/MetiTarski_source\/Portable.sig\" SML_file \"..\/MetiTarski_source\/PortablePolyml.sml\"\nSML_file \"..\/MetiTarski_source\/Polyhash.sig\" SML_file \"..\/MetiTarski_source\/Polyhash.sml\"\nSML_file \"..\/MetiTarski_source\/Useful.sig\" SML_file \"..\/MetiTarski_source\/Useful.sml\"\nSML_file \"..\/MetiTarski_source\/rat.sml\"\nSML_file \"..\/MetiTarski_source\/Lazy.sig\" SML_file \"..\/MetiTarski_source\/Lazy.sml\"\nSML_file \"..\/MetiTarski_source\/Map.sig\" SML_file \"..\/MetiTarski_source\/Map.sml\"\nSML_file \"..\/MetiTarski_source\/Ordered.sig\" SML_file \"..\/MetiTarski_source\/Ordered.sml\"\nSML_file \"..\/MetiTarski_source\/KeyMap.sig\" SML_file \"..\/MetiTarski_source\/KeyMap.sml\"\nSML_file \"..\/MetiTarski_source\/ElementSet.sig\" SML_file \"..\/MetiTarski_source\/ElementSet.sml\"\nSML_file \"..\/MetiTarski_source\/Sharing.sig\" SML_file \"..\/MetiTarski_source\/Sharing.sml\"\nSML_file \"..\/MetiTarski_source\/Stream.sig\" SML_file \"..\/MetiTarski_source\/Stream.sml\"\nSML_file \"..\/MetiTarski_source\/Print.sig\" SML_file \"..\/MetiTarski_source\/Print.sml\"\nSML_file \"..\/MetiTarski_source\/Parse.sig\" SML_file \"..\/MetiTarski_source\/Parse.sml\"\nSML_file \"..\/MetiTarski_source\/Name.sig\" SML_file \"..\/MetiTarski_source\/Name.sml\"\nSML_file \"..\/MetiTarski_source\/NameArity.sig\" SML_file \"..\/MetiTarski_source\/NameArity.sml\"\nSML_file \"..\/MetiTarski_source\/Term.sig\" SML_file \"..\/MetiTarski_source\/Term.sml\"\nSML_file \"..\/MetiTarski_source\/Subst.sig\" SML_file \"..\/MetiTarski_source\/Subst.sml\"\nSML_file \"..\/MetiTarski_source\/Atom.sig\" SML_file \"..\/MetiTarski_source\/Atom.sml\"\nSML_file \"..\/MetiTarski_source\/Formula.sig\" SML_file \"..\/MetiTarski_source\/Formula.sml\"\nSML_file \"..\/MetiTarski_source\/RCF\/Common.sig\" SML_file \"..\/MetiTarski_source\/RCF\/Common.sml\"\nSML_file \"..\/MetiTarski_source\/RCF\/Algebra.sig\" SML_file \"..\/MetiTarski_source\/RCF\/Algebra.sml\"\nSML_file \"..\/MetiTarski_source\/RCF\/Groebner.sig\" SML_file \"..\/MetiTarski_source\/RCF\/Groebner.sml\"\nSML_file \"..\/MetiTarski_source\/RCF\/SMT.sig\" SML_file \"..\/MetiTarski_source\/RCF\/SMT.sml\"\nSML_file \"..\/MetiTarski_source\/RCF\/Resultant.sig\" SML_file \"..\/MetiTarski_source\/RCF\/Resultant.sml\"\nSML_file \"..\/MetiTarski_source\/RCF\/IntvlsFP.sig\" SML_file \"..\/MetiTarski_source\/RCF\/IntvlsFP.sml\"\nSML_file \"..\/MetiTarski_source\/RCF\/Sturm.sig\" SML_file \"..\/MetiTarski_source\/RCF\/Sturm.sml\"\n\n(*Modified a little by adding an implementation of substraction of real algebraic numbers*)\nSML_file \"..\/MetiTarski_source\/RCF\/RealAlg.sig\" SML_file \"..\/MetiTarski_source\/RCF\/RealAlg.sml\"\n\n\n(*interface to connect Isabelle\/ML and MetiTarski*)\nSML_file \"RealAlg_Arith.sml\"\nSML_export \\\n val untrustedAdd = RealAlg_Arith.alg_add;\n val untrustedMult = RealAlg_Arith.alg_mult;\n val untrustedMinus = RealAlg_Arith.alg_minus;\n val untrustedInverse = RealAlg_Arith.alg_inverse\\ \n\nconsts alg_inverse:: \"integer list \\ (integer \\ integer) \\ (integer \\ integer) \n \\ (integer \\ integer) \\ (integer \\ integer)\"\n\nconsts alg_add:: \"integer list \\ (integer \\ integer) \\ (integer \\ integer) \n \\ integer list \\ (integer \\ integer) \\ (integer \\ integer) \n \\ integer list \\ (integer\\ integer) \\ (integer \\ integer) \\ ((integer \\ integer) option)\"\n\nconsts alg_mult:: \"integer list \\ (integer \\ integer) \\ (integer \\ integer) \n \\ integer list \\ (integer \\ integer) \\ (integer \\ integer) \n \\ integer list \\ (integer\\ integer) \\ (integer \\ integer) \\ ((integer \\ integer) option)\"\n\nconsts alg_minus:: \"integer list \\ (integer \\ integer) \\ (integer \\ integer) \n \\ integer list \\ (integer \\ integer) \\ (integer \\ integer) \n \\ integer list \\ (integer\\ integer) \\ (integer \\ integer) \\ ((integer \\ integer) option)\"\n\n\ndefinition to_alg_code::\"int poly \\ float \\ float \\ integer list \\ (integer \\ integer) \\ (integer \\ integer)\" where\n \"to_alg_code p lb ub = (let \n (lb1,lb2) = quotient_of (rat_of_float lb);\n (ub1,ub2) = quotient_of (rat_of_float ub)\n in (map integer_of_int (coeffs p),(integer_of_int lb1,integer_of_int lb2)\n ,(integer_of_int ub1,integer_of_int ub2)) \n )\"\n\ndefinition of_rat_code::\"integer \\ integer \\ rat\" where\n \"of_rat_code r1 r2 =Fract (int_of_integer r1) (int_of_integer r2)\"\n\ndefinition of_alg_code::\"integer list \\ integer \\ integer \\ integer \\ integer \\\n int poly \\ float \\ float\" where\n \"of_alg_code ps lb1 lb2 ub1 ub2 = (poly_of_list (map int_of_integer ps)\n ,lapprox_rat 10 (int_of_integer lb1) (int_of_integer lb2), \n rapprox_rat 10 (int_of_integer ub1) (int_of_integer ub2))\"\n\ncode_printing constant alg_inverse \\ (SML) \"untrustedInverse\"\n\ncode_printing constant alg_add \\ (SML) \"untrustedAdd\"\n\ncode_printing constant alg_mult \\ (SML) \"untrustedMult\"\n\ncode_printing constant alg_minus \\ (SML) \"untrustedMinus\"\n\nlemma poly_y_pcompose:\"poly_y (pcompose p q) y = pcompose (poly_y p y) (poly_y q y)\"\n apply (induct p)\n by (auto simp add:pcompose_pCons poly_y_add poly_y_mult)\n \nlemma bpoly_pcompose:\n shows \"bpoly (pcompose p q) x y = bpoly p (bpoly q x y) y\" \nunfolding bpoly_def \n by (simp add:poly_y_pcompose poly_pcompose)\n\nlemma alg_add_bsgn:\n fixes p1 p2 p3::\"int poly\" and lb1 lb2 lb3 ub1 ub2 ub3::\"float\"\n defines \"x\\Alg p1 lb1 ub1\" and \"y\\Alg p2 lb2 ub2\" and \"z\\Alg p3 lb3 ub3\"\n and \"pxy\\[:[:0::real,1:],[:1:]:]\"\n assumes valid:\"valid_alg p3 lb3 ub3\"\n and bsgn1:\"bsgn_at (pcompose (lift_x (of_int_poly p3)) pxy) x y = 0\"\n and bsgn2:\"bsgn_at ([:[:Ratreal (- rat_of_float lb3),1:],[:1:]:]) x y > 0\"\n and bsgn3:\"bsgn_at ([:[:Ratreal (- rat_of_float ub3),1:],[:1:]:]) x y < 0\"\n shows \"Alg p3 lb3 ub3 = Alg p1 lb1 ub1 + Alg p2 lb2 ub2\"\nproof -\n def xy\\\"x+y\"\n have \"poly (of_int_poly p3) xy = 0\" \n using bsgn1 unfolding bsgn_at_def pxy_def xy_def\n apply (auto simp add:sgn_zero_iff bpoly_pcompose)\n by (simp add:bpoly_def algebra_simps)\n moreover have \"xy>real_of_float lb3\"\n using bsgn2 unfolding bsgn_at_def pxy_def xy_def \n by (auto simp:of_rat_minus)\n moreover have \"xyAlg p1 lb1 ub1\" and \"y\\Alg p2 lb2 ub2\"\n and \"pxy\\[:[:0::real,1:],[:1:]:]\"\n assumes bsgn:\"bsgn_at (pcompose (lift_x (of_rat_poly [:-r,1:])) pxy) x y = 0\"\n shows \"of_rat r = Alg p1 lb1 ub1 + Alg p2 lb2 ub2\"\nusing bsgn unfolding pxy_def bsgn_at_def\napply (fold x_def y_def)\nby (auto simp add:sgn_zero_iff bpoly_pcompose of_rat_minus)\n\nlemma alg_minus_bsgn:\n fixes p1 p2 p3::\"int poly\" and lb1 lb2 lb3 ub1 ub2 ub3::\"float\"\n defines \"x\\Alg p1 lb1 ub1\" and \"y\\Alg p2 lb2 ub2\" and \"z\\Alg p3 lb3 ub3\"\n and \"pxy\\[:[:0::real,-1:],[:1:]:]\"\n assumes valid:\"valid_alg p3 lb3 ub3\"\n and bsgn1:\"bsgn_at (pcompose (lift_x (of_int_poly p3)) pxy) x y = 0\"\n and bsgn2:\"bsgn_at [:[:Ratreal (- rat_of_float lb3),-1:],[:1:]:] x y > 0\"\n and bsgn3:\"bsgn_at [:[:Ratreal (- rat_of_float ub3),-1:],[:1:]:] x y < 0\"\n shows \"Alg p3 lb3 ub3 = Alg p1 lb1 ub1 - Alg p2 lb2 ub2\"\nproof -\n def xy\\\"x-y\"\n have \"poly (of_int_poly p3) xy = 0\" \n using bsgn1 unfolding bsgn_at_def pxy_def xy_def\n apply (auto simp add:sgn_zero_iff bpoly_pcompose)\n by (simp add:bpoly_def algebra_simps)\n moreover have \"xy>real_of_float lb3 \\ xyAlg p1 lb1 ub1\" and \"y\\Alg p2 lb2 ub2\"\n and \"pxy\\[:[:0::real,-1:],[:1:]:]\"\n assumes bsgn:\"bsgn_at (pcompose (lift_x (of_rat_poly [:-r,1:])) pxy) x y = 0\"\n shows \"of_rat r = Alg p1 lb1 ub1 - Alg p2 lb2 ub2\"\nusing bsgn unfolding pxy_def bsgn_at_def\napply (fold x_def y_def)\nby (auto simp add:sgn_zero_iff bpoly_pcompose of_rat_minus)\n\nlemma alg_mult_bsgn:\n fixes p1 p2 p3::\"int poly\" and lb1 lb2 lb3 ub1 ub2 ub3::\"float\"\n defines \"x\\Alg p1 lb1 ub1\" and \"y\\Alg p2 lb2 ub2\" and \"z\\Alg p3 lb3 ub3\"\n and \"pxy\\[:0,[:0,1::real:]:]\"\n assumes valid:\"valid_alg p3 lb3 ub3\"\n and bsgn1:\"bsgn_at (pcompose (lift_x (of_int_poly p3)) pxy) x y = 0\"\n and bsgn2:\"bsgn_at [:[:Ratreal (- rat_of_float lb3):],[:0,1:]:] x y > 0\"\n and bsgn3:\"bsgn_at [:[:Ratreal (- rat_of_float ub3):],[:0,1:]:] x y < 0\"\n shows \"Alg p3 lb3 ub3 = Alg p1 lb1 ub1 * Alg p2 lb2 ub2\"\nproof -\n def xy\\\"x*y\"\n have \"poly (of_int_poly p3) xy = 0\" \n using bsgn1 unfolding bsgn_at_def pxy_def xy_def\n apply (auto simp add:sgn_zero_iff bpoly_pcompose)\n by (simp add:bpoly_def algebra_simps)\n moreover have \"xy>real_of_float lb3 \\ xy\"Alg p lb ub\" and q\\\"pcompose p [:0,-1:]\"\n have \"poly (of_int_poly p) x=0\" and \"real_of_float lb\"roots_btw (of_int_poly p) (real_of_float lb) (real_of_float ub)\" \n and S'\\\"roots_btw (of_int_poly q) (-real_of_float ub) (-real_of_float lb)\"\n have \"\\y. y\\S \\ -y \\ S'\" \n unfolding S_def S'_def roots_btw_def q_def\n by (auto simp add:poly_pcompose of_rat_minus)\n hence \"card S= card S'\" \n apply (intro Fun.bij_betw_byWitness[THEN bij_betw_same_card,of _ uminus uminus])\n by force+\n thus ?thesis using valid unfolding valid_alg_def \n apply simp\n apply (fold S_def S'_def)\n by (auto simp add:of_rat_minus q_def poly_pcompose algebra_simps)\n qed\n ultimately have \"- x = Alg q (-ub) (-lb)\" \n by (intro alg_eq,auto simp add:of_rat_minus)\n thus ?thesis unfolding x_def q_def by auto\nqed\n\ndefinition rat_to_alg::\"rat \\ int poly \\ float \\ float\" where\n \"rat_to_alg r = (\n if r=0 then \n ([:0,1:],-1,1) \n else if r>0 then (\n let\n (r1,r2) = quotient_of r;\n lb = lapprox_rat 0 r1 r2 * Float 1 (-1);\n ub = rapprox_rat 0 r1 r2 * Float 1 1\n in\n ([:-r1,r2:],lb,ub)\n ) else (\n let\n (r1,r2) = quotient_of r;\n lb = lapprox_rat 0 r1 r2*Float 1 1;\n ub = rapprox_rat 0 r1 r2 * Float 1 (-1)\n in\n ([:-r1,r2:],lb,ub)\n ))\"\n\nlemma rat_to_alg_eq:\"of_rat r = (let (p,lb,ub) = rat_to_alg r in Alg p lb ub)\"\nproof (cases \"r=0\")\n case True\n moreover have \"0 = Alg [:0, 1:] (- 1) 1\"\n proof (rule alg_eq)\n have \"{x::real. x = 0 \\ - 1 < x \\ x < 1} = {0}\" by auto\n then show \"valid_alg [:0, 1:] (- 1) 1\" unfolding valid_alg_def roots_btw_def by simp\n qed auto\n then show ?thesis unfolding rat_to_alg_def using True by auto\nnext\n case False\n obtain p lb ub where to_alg:\"rat_to_alg r = (p,lb,ub)\" by (metis prod_cases3) \n obtain r1 r2 where r1r2:\"quotient_of r = (r1,r2)\" by (metis small_lazy'.cases)\n let ?lb = \"real_of_float lb\" and ?ub = \"real_of_float ub\"\n have p_alt:\"p=[:-r1,r2:]\"\n using to_alg False unfolding rat_to_alg_def Let_def r1r2 by (auto split:if_splits)\n have \"r2>0\" using quotient_of_denom_pos[OF r1r2] .\n\n have r_btw:\"real_of_float lb of_rat r0\")\n case True\n then have \"real_of_float lb = real_of_float (lapprox_rat 0 r1 r2 * Float 1 (- 1))\"\n using to_alg r1r2 unfolding rat_to_alg_def by auto\n also have \"... \\ (real_of_int r1 \/ real_of_int r2) \/ 2\"\n using lapprox_rat[of 0 r1 r2] by (auto simp add:powr_neg_one)\n also have \"... < of_rat r\"\n using \\r2>0\\ True unfolding quotient_of_div[OF r1r2] \n by (auto simp add:of_rat_divide field_simps)\n finally have *:\"real_of_float lb < real_of_rat r\" .\n have \"real_of_rat r < real_of_float (rapprox_rat 0 r1 r2 * Float 1 1)\"\n using rapprox_rat[of r1 r2 0] \\r2>0\\ True unfolding quotient_of_div[OF r1r2] \n by (auto simp add:of_rat_divide field_simps)\n also have \"... = real_of_float ub\"\n using to_alg r1r2 True unfolding rat_to_alg_def by auto\n finally have \"real_of_rat r < real_of_float ub\" .\n with * show ?thesis by simp\n next\n case False\n then have \"r<0\" using \\r\\0\\ by auto\n then have \"real_of_float lb = real_of_float (lapprox_rat 0 r1 r2 * Float 1 1)\"\n using to_alg r1r2 unfolding rat_to_alg_def by auto\n also have \"... < of_rat r\"\n using lapprox_rat[of 0 r1 r2] \\r2>0\\ \\r<0\\ unfolding quotient_of_div[OF r1r2] \n by (auto simp add:of_rat_divide field_simps)\n finally have *:\"real_of_float lb < of_rat r\" .\n have \"real_of_rat r < real_of_float (rapprox_rat 0 r1 r2 * Float 1 (-1))\"\n using rapprox_rat[of r1 r2 0] \\r2>0\\ \\r<0\\ unfolding quotient_of_div[OF r1r2] \n by (auto simp add:of_rat_divide field_simps powr_neg_one)\n also have \"... = real_of_float ub\"\n using to_alg r1r2 \\r<0\\ unfolding rat_to_alg_def by auto\n finally have \"real_of_rat r < real_of_float ub\" .\n with * show ?thesis by simp\n qed\n moreover have \"valid_alg p lb ub\"\n proof -\n have \"lb < ub\" using r_btw by auto\n moreover have \"poly (of_int_poly p) lb * poly (of_int_poly p) ub < 0\"\n using r_btw \\r2>0\\ unfolding p_alt quotient_of_div[OF r1r2] \n by (auto simp add:of_rat_divide divide_simps mult_neg_pos)\n moreover have \"card (roots_btw (of_int_poly p) ?lb ?ub) = 1\"\n proof -\n have \"{x. poly (of_int_poly p) x = 0 \\ ?lb < x \\ x < ?ub} = {of_rat r}\"\n using \\r2>0\\ r_btw unfolding quotient_of_div[OF r1r2] p_alt\n by (auto simp add:of_rat_divide divide_simps mult_neg_pos)\n then show ?thesis unfolding roots_btw_def by auto\n qed\n ultimately show ?thesis unfolding valid_alg_def by auto\n qed\n moreover have \"poly (of_int_poly p) (of_rat r) = 0\"\n using r_btw \\r2>0\\ unfolding p_alt quotient_of_div[OF r1r2]\n by (auto simp add:of_rat_divide divide_simps)\n ultimately show ?thesis using alg_eq unfolding to_alg by auto\nqed\n\ndefinition ter_ub :: \"int poly \\ rat \\ nat\" where\n \"ter_ub p ub = (let \n x= Real (to_cauchy (of_int_poly p, 0, ub)) \n in\n (LEAST n. (of_rat ub)\/2^n < x))\"\n\ndefinition ter_lb :: \"int poly \\ rat \\ nat\" where\n \"ter_lb p lb = (let \n x= Real (to_cauchy (of_int_poly p, lb, 0)) \n in\n (LEAST n. x<(of_rat lb)\/2^n ))\"\n\nlemma vanishes_shift:\n assumes \"cauchy X\" and shift:\"\\n. X (n+k) = Y n\"\n shows \"vanishes (\\n. X n - Y n)\"\nunfolding vanishes_def\nproof clarify\n fix r::rat assume \"r>0\"\n obtain k1 where k1:\"\\m\\k1.\\n\\k1. \\X m - X n\\ < r\" \n using `cauchy X` `0 < r` unfolding cauchy_def \n using half_gt_zero_iff by blast\n have \"\\m\\k1. \\X m - X (m+k)\\ < r\"\n using k1 by auto\n then show \"\\k. \\n\\k. \\X n - Y n\\ < r\" using shift by auto\nqed\n\n(* something useful for the next version\nlemma ter_lb_Suc:\n fixes p::\"int poly\" and lb ::rat\n assumes \"lb<0\" \n and sgn_diff1: \"poly (of_int_poly p) lb * poly (of_int_poly p) 0 <0\" \n and sgn_diff2:\"poly p (lb\/2) * poly p 0 > 0\"\n shows \"ter_lb p lb = Suc (ter_ub p (lb\/2))\"\nsorry\n*)\n\nlemma power_Archimedean':\n fixes x y a::real\n assumes \"x>0\" \"a>1\"\n shows \"\\n. y < a^n * x\" \nproof (cases \"y>0\")\n assume \"\\ 0 < y\" \n thus \" \\n. y < a ^ n * x\" using assms \n apply (rule_tac x=0 in exI)\n by auto\nnext\n assume \"y>0\"\n obtain n::nat where \"of_nat n > log a (y\/x)\" \n using reals_Archimedean2 by auto\n hence \"a powr (of_nat n) > a powr (log a (y\/x))\" \n by (intro powr_less_mono,auto simp add:`a>1`)\n hence \"a ^ n > y\/x\" using `y>0` `x>0` `a>1`\n apply (subst (asm) powr_realpow,simp)\n by (subst (asm) powr_log_cancel,auto)\n thus \"\\n. y < a ^ n * x\" by (auto simp add:field_simps `x>0`)\nqed\n\nlemma ter_ub_Suc:\n fixes p::\"int poly\" and ub ::rat\n assumes \"ub>0\" \n and sgn_diff1: \"poly (of_int_poly p) 0 * poly (of_int_poly p) ub <0\" \n and sgn_diff2:\"poly (of_int_poly p) 0 * poly (of_int_poly p) (ub\/2) \\ 0\"\n shows \"ter_ub p ub = Suc (ter_ub p (ub\/2))\"\nproof -\n define X where \"X\\to_cauchy (of_int_poly p, 0, ub)\"\n define Y where \"Y\\to_cauchy (of_int_poly p, 0, ub\/2)\"\n define x y where \"x\\Real X\" and \"y\\Real Y\"\n define P1 P2 where \"P1\\\\n. (of_rat ub)\/2^n < x\" and \"P2\\\\n. (of_rat (ub\/2))\/2^n < y\" \n define ter1 ter2 where \"ter1\\ter_ub p ub\" and \"ter2\\ter_ub p (ub\/2)\"\n have ter1:\"ter1= (LEAST n. P1 n)\" and ter2:\"ter2=(LEAST n. P2 n)\"\n unfolding ter1_def P1_def ter2_def P2_def ter_ub_def x_def X_def y_def Y_def \n by auto\n have \"x=y\"\n proof -\n have \"\\n. Y n = X (Suc n)\"\n unfolding X_def Y_def using sgn_diff2 \n by (simp add:Let_def of_int_poly_poly)\n moreover have \"cauchy X\" and \"cauchy Y\"\n unfolding X_def Y_def\n by (auto simp:to_cauchy_cauchy `ub>0`)\n ultimately show ?thesis\n unfolding x_def y_def\n apply (auto simp add: eq_Real cauchy_def vanishes_def)\n by (meson le_less le_less_trans lessI)\n qed\n have \"x>0\" and \"x0` sgn_diff1] unfolding x_def X_def by auto\n have p12:\"\\n. P1 (Suc n) \\ P2 n\"\n unfolding P1_def P2_def `x=y`\n by (auto simp add:field_simps of_rat_divide)\n have \"P1 ter1\" and \"P2 ter2\" \n proof -\n have \"\\n. P1 n\" and \"\\n. P2 n\"\n unfolding P1_def P2_def\n using power_Archimedean'[OF `x>0`,of 2] \n by (auto simp add:field_simps of_rat_power `x=y`) \n thus \"P1 ter1\" and \"P2 ter2\" using LeastI_ex unfolding ter1 ter2 by auto \n qed\n have \"ter1 \\Suc ter2\" \n using Least_le[of P1 \"Suc ter2\",folded ter1] p12[of ter2] `P2 ter2` by auto\n moreover have \"Suc ter2 \\ ter1\"\n proof -\n have \"ter1\\0\"\n proof\n assume \"ter1=0\"\n hence \"of_rat ub0`\n apply (subgoal_tac \"ter1=Suc (nat.pred ter1)\")\n by auto\n qed\n ultimately have \"ter1=Suc ter2\" by auto\n thus ?thesis unfolding ter1_def ter2_def .\nqed\n\nfunction refine_pos::\"int poly \\ rat \\ (rat \\ rat) \\ rat option \" where\n \"refine_pos p ub = (\n if ub\\0 \\ poly (of_int_poly p) 0 * poly (of_int_poly p) ub \\0 then \n undefined\n else if poly (of_int_poly p) 0 * poly (of_int_poly p) (ub\/2) <0 then\n refine_pos p (ub\/2)\n else if poly (of_int_poly p) (ub\/2) =0 then\n (undefined,Some (ub\/2))\n else\n ((ub\/2,ub),None))\n \"\nby auto\ntermination\n apply (relation \"measure (\\(p,ub). ter_ub p ub )\")\n apply auto\n using ter_ub_Suc\n by (metis le_less lessI not_less of_int_0 of_int_poly_def of_int_poly_poly)\n\n\n(* something useful for the next version\nlemma\n fixes p::\"int poly\" and ub ub' lb'::rat\n assumes \"ub>0\" and sgn_diff:\"poly (of_int_poly p) 0 * poly (of_int_poly p) ub < 0\"\n defines\n \"X\\ (\\p ub. to_cauchy (of_int_poly p, 0, ub))\" and\n \"Y\\ (\\p ub. case refine_pos p ub of\n (_,Some r) \\ (\\n. r) | \n ((lb',ub'),None) \\ to_cauchy (of_int_poly p, lb',ub'))\"\n shows \"\\k. X p ub (n+k) = Y p ub n\" using `ub>0` sgn_diff\nproof (induct rule:refine_pos.induct[of _ p ub])\n case (1 p ub)\n obtain k where k:\" X p (ub \/ 2) (n + k) = Y p (ub \/ 2) n\" sorry\n show ?case using k \"1.prems\" unfolding X_def Y_def\n apply (rule_tac x=\"if poly (of_int_poly p) 0 * poly (of_int_poly p) (ub \/ 2) < 0 \n then Suc k else if poly (of_int_poly p) (ub\/2) = 0 then undefined else 1\" in exI)\n apply (subst refine_pos.simps)\n apply (auto simp del:refine_pos.simps simp add: Let_def)\n\n\nlemma\n fixes p::\"int poly\" and ub ub' lb'::rat\n assumes \"ub>0\" and sgn_diff:\"poly (of_int_poly p) 0 * poly (of_int_poly p) ub < 0\"\n defines\n \"r \\ refine_pos p ub\" \n defines\n \"x\\ Real (to_cauchy (of_int_poly p, 0, ub))\" and\n \"y\\ Real (to_cauchy (of_int_poly p, fst r, snd r))\"\n shows \"x=y\" using sgn_diff\nproof (induct rule:refine_pos.induct)\n \n*)\n\n(*\nIt would be interesting to have such function, but certifying its termination seems not so easy :-(\n\nfunction refine_alg:: \"int poly \\ rat \\ rat \\ int poly \\ rat \\ rat\" where\n \"refine_alg p lb ub = (\n if lb>0 \\ ub <0 \\ poly (of_int_poly p) lb * poly (of_int_poly p) ub \\0 then \n (p,lb,ub) \n else \n let c=(if lb<0 \\ ub>0 then 0 else (lb+ub)\/2) \n in\n if poly (of_int_poly p) lb * poly (of_int_poly p) c \\0 then refine_alg p lb c\n else refine_alg p c ub)\"\nby auto\n\ntermination\n apply (relation \"measure (\\(p,lb,ub). if lb=0 then ter_ub p ub else ter_lb p lb)\")\n apply auto\noops\n*)\n\nlemma alg_inverse_code:\n assumes valid1:\"valid_alg p a1 b1\" and valid2:\"valid_alg (rev_poly p) a2 b2\" \n and ineq_asm:\"(a2>0 \\ a2 * b1 \\ 1 \\ a1 * b2 \\ 1) \\ (b2<0 \\ a2*b1 \\ 1 \\ a1 * b2\\1)\"\n shows \"inverse (Alg p a1 b1) = (\n if a1 < 0 \\ 0 < b1 \\ poly p 0=0 then 0 else Alg (rev_poly p) a2 b2)\"\nproof -\n have ?thesis when \"a1 < 0 \\ 0 < b1 \\ poly p 0=0\"\n proof -\n have \"0 = Alg p a1 b1\"\n apply (rule alg_eq[OF valid1,of 0])\n using that by (auto,metis of_int_0 of_int_poly_poly)\n then show ?thesis using that by auto\n qed\n moreover have ?thesis when \"\\(a1 < 0 \\ 0 < b1 \\ poly p 0=0)\" \n proof -\n define x1 where \"x1=Alg p a1 a2\"\n define x2 where \"x2=Alg (rev_poly p) a2 b2\"\n then have *:\"real_of_float a2 < x2 \\ x2 < real_of_float b2\" \"x2\\0\"\n using alg_bound_and_root[OF valid2] ineq_asm by auto\n from this(1) ineq_asm\n have \"inverse (real_of_float b2) < inverse x2 \\ inverse x2 < inverse (real_of_float a2)\"\n by auto\n moreover have \"real_of_float a1 \\ inverse (real_of_float b2)\"\n \"inverse (real_of_float a2) \\ real_of_float b1\"\n using ineq_asm * by (auto simp add:field_simps)\n ultimately have \"real_of_float a1 < inverse x2 \\ inverse x2 < real_of_float b1\"\n by auto\n moreover have \"poly (of_int_poly p) (inverse x2) = 0\"\n apply (subst rev_poly_poly_iff[symmetric])\n subgoal using \\x2\\0\\ by auto\n subgoal using alg_bound_and_root[OF valid2,folded x2_def] by (simp add: of_int_poly_rev_poly)\n done\n ultimately have \"Alg p a1 b1 = inverse x2\"\n using alg_eq[OF valid1,of \"inverse x2\"] by auto\n then show ?thesis using that(1) unfolding x2_def by auto \n qed\n ultimately show ?thesis by auto\nqed\n\nlemma [code]:\"inverse (Alg p1 lb1 ub1) = \n (if valid_alg p1 lb1 ub1 then \n if lb1 < 0 \\ 0 poly p1 0 =0 then\n 0\n else \n let ((lb2_1,lb2_2),(ub2_1,ub2_2)) = alg_inverse (to_alg_code p1 lb1 ub1);\n lb2 = lapprox_rat 10 (int_of_integer lb2_1) (int_of_integer lb2_2);\n ub2 = rapprox_rat 10 (int_of_integer ub2_1) (int_of_integer ub2_2);\n p2 = rev_poly p1 \n in \n (if valid_alg p2 lb2 ub2 \\ \n ((lb2>0 \\ lb2 * ub1 \\ 1 \\ lb1 * ub2 \\ 1) \\ (ub2<0 \\ lb2*ub1 \\ 1 \\ lb1 * ub2\\1)) \n then \n Alg p2 lb2 ub2\n else \n Code.abort (STR ''alg_inverse fails to compute a valid answer'') \n (%_. inverse (Alg p1 lb1 ub1))\n )\n else \n Code.abort (STR ''invalid Alg'') (%_. inverse (Alg p1 lb1 ub1)))\"\nproof -\n have ?thesis when \"lb1 < 0 \\ 0 poly p1 0 =0\" \n proof (cases \"valid_alg p1 lb1 ub1\")\n case True\n have \"0 = Alg p1 lb1 ub1\"\n apply (rule alg_eq[OF True,of 0])\n using that by (auto,metis of_int_0 of_int_poly_poly)\n then show ?thesis using that by auto\n next\n case False\n then show ?thesis by auto\n qed\n moreover have ?thesis when \"\\ (lb1 < 0 \\ 0 poly p1 0 =0)\"\n using that alg_inverse_code[of p1 lb1 ub1,symmetric] \n by (auto simp add:Let_def split: prod.split option.split)\n ultimately show ?thesis by fastforce\nqed\n\nlemma [code]:\"- Alg p lb ub = \n (if valid_alg p lb ub then \n Alg (pcompose p [:0,-1:]) (-ub) (-lb)\n else \n Code.abort (STR ''invalid Alg'') (%_. - Alg p lb ub))\"\nusing alg_minus_code by auto\n\nlemma [code]:\"Alg p1 lb1 ub1 + Alg p2 lb2 ub2 = \n (if valid_alg p1 lb1 ub1 \\ valid_alg p2 lb2 ub2 then\n (let \n (ns,(lb3_1,lb3_2),(ub3_1,ub3_2),r') = alg_add (to_alg_code p1 lb1 ub1) (to_alg_code p2 lb2 ub2)\n in\n (case r' of\n None \\ (let (p3,lb3,ub3) = of_alg_code ns lb3_1 lb3_2 ub3_1 ub3_2 in\n (if (valid_alg p3 lb3 ub3 \\\n bsgn_at (pcompose (lift_x (of_int_poly p3)) [:[:0, 1:], [:1:]:]) \n (Alg p1 lb1 ub1) (Alg p2 lb2 ub2) = 0 \\\n bsgn_at ([:[:Ratreal (- rat_of_float lb3),1:],[:1:]:]) (Alg p1 lb1 ub1) (Alg p2 lb2 ub2) > 0\n \\ \n bsgn_at ([:[:Ratreal (- rat_of_float ub3),1:],[:1:]:]) (Alg p1 lb1 ub1) (Alg p2 lb2 ub2) < 0)\n then \n Alg p3 lb3 ub3\n else\n Code.abort (STR ''alg_add fails to compute a valid answer'') \n (%_. Alg p1 lb1 ub1 + Alg p2 lb2 ub2)))|\n Some (r1,r2) \\ ( let r = of_rat_code r1 r2 in\n (if bsgn_at (pcompose (lift_x (of_rat_poly [:- r, 1:])) [:[:0, 1:], [:1:]:])\n (Alg p1 lb1 ub1) (Alg p2 lb2 ub2) = 0\n then\n Ratreal r \n else \n Code.abort (STR ''alg_add fails to compute a valid answer'') \n (%_. Alg p1 lb1 ub1 + Alg p2 lb2 ub2))\n )\n ))\n else \n Code.abort (STR ''alg_add fails to compute a valid answer'') (%_. Alg p1 lb1 ub1 + Alg p2 lb2 ub2)\n )\" \nusing alg_add_bsgn[of _ _ _ p1 lb1 ub1 p2 lb2 ub2,symmetric] \n alg_add_bsgn'[of _ p1 lb1 ub1 p2 lb2 ub2,symmetric]\nby (auto simp add:Let_def split: prod.split option.split)\n\nlemma [code]:\"Alg p1 lb1 ub1 - Alg p2 lb2 ub2 = \n (if valid_alg p1 lb1 ub1 \\ valid_alg p2 lb2 ub2 then\n (let \n (ns,(lb3_1,lb3_2),(ub3_1,ub3_2),r') = alg_minus (to_alg_code p1 lb1 ub1) (to_alg_code p2 lb2 ub2)\n \n in\n (case r' of\n None \\ (let (p3,lb3,ub3) = of_alg_code ns lb3_1 lb3_2 ub3_1 ub3_2 in\n (if (valid_alg p3 lb3 ub3 \\\n bsgn_at (pcompose (lift_x (of_int_poly p3)) [:[:0, -1:], [:1:]:]) \n (Alg p1 lb1 ub1) (Alg p2 lb2 ub2) = 0 \\\n bsgn_at [:[:Ratreal (- rat_of_float lb3),-1:],[:1:]:] (Alg p1 lb1 ub1) (Alg p2 lb2 ub2) > 0 \\\n bsgn_at [:[:Ratreal (- rat_of_float ub3),-1:],[:1:]:] (Alg p1 lb1 ub1) (Alg p2 lb2 ub2) < 0)\n then \n Alg p3 lb3 ub3\n else\n Code.abort (STR ''alg_add fails to compute a valid answer'') \n (%_. Alg p1 lb1 ub1 - Alg p2 lb2 ub2)))|\n Some (r1,r2) \\ ( let r = of_rat_code r1 r2 in\n (if bsgn_at (pcompose (lift_x (of_rat_poly [:- r, 1:])) [:[:0, -1:], [:1:]:])\n (Alg p1 lb1 ub1) (Alg p2 lb2 ub2) = 0\n then\n Ratreal r \n else \n Code.abort (STR ''alg_add fails to compute a valid answer'') \n (%_. Alg p1 lb1 ub1 - Alg p2 lb2 ub2))\n )))\n else \n Code.abort (STR ''alg_add fails to compute a valid answer'') \n (%_. Alg p1 lb1 ub1 - Alg p2 lb2 ub2))\n\" \nusing alg_minus_bsgn[of _ _ _ p1 lb1 ub1 p2 lb2 ub2,symmetric] \n alg_minus_bsgn'[of _ p1 lb1 ub1 p2 lb2 ub2,symmetric]\nby (auto simp add:Let_def split:prod.split option.split) \n \nlemma [code]:\"Alg p1 lb1 ub1 * Alg p2 lb2 ub2 = \n (if valid_alg p1 lb1 ub1 \\ valid_alg p2 lb2 ub2 then \n (let \n (ns,(lb3_1,lb3_2),(ub3_1,ub3_2),_) = alg_mult (to_alg_code p1 lb1 ub1) (to_alg_code p2 lb2 ub2);\n (p3,lb3,ub3) = of_alg_code ns lb3_1 lb3_2 ub3_1 ub3_2\n in\n (if (valid_alg p3 lb3 ub3 \\\n bsgn_at (pcompose (lift_x (of_int_poly p3)) [:0, [:0,1:]:]) \n (Alg p1 lb1 ub1) (Alg p2 lb2 ub2) = 0 \\\n bsgn_at ([:[:Ratreal (- rat_of_float lb3):],[:0,1:]:]) (Alg p1 lb1 ub1) (Alg p2 lb2 ub2) > 0 \\\n bsgn_at ([:[:Ratreal (- rat_of_float ub3):],[:0,1:]:]) (Alg p1 lb1 ub1) (Alg p2 lb2 ub2) < 0)\n then \n Alg p3 lb3 ub3\n else\n Code.abort (STR ''alg_mult fails to compute a valid answer'') \n (%_. Alg p1 lb1 ub1 * Alg p2 lb2 ub2)))\n else\n Code.abort (STR ''invalid alg in alg mult'') \n (%_. Alg p1 lb1 ub1 * Alg p2 lb2 ub2))\n \" \nusing alg_mult_bsgn[of _ _ _ p1 lb1 ub1 p2 lb2 ub2,symmetric]\nby (auto simp add:prod.split)\n\nlemma [code]: \"Alg p1 lb1 ub1 \/ Alg p2 lb2 ub2 = Alg p1 lb1 ub1 * (inverse (Alg p2 lb2 ub2))\"\n using Real.divide_real_def by auto\n\n(*TODO: This can be optimized by exploiting something like\n poly (pcompose p [:-r1,r2:]) (Alg p lb ub + r) =0\n where r=(of_int r1)\/(of_int r2)\n *)\nlemma [code]:\n \"Alg p lb ub + Ratreal r = (let (p', lb', ub') = rat_to_alg r in Alg p lb ub + Alg p' lb' ub')\"\n \"Ratreal r + Alg p lb ub = (let (p', lb', ub') = rat_to_alg r in Alg p' lb' ub'+ Alg p lb ub)\"\n \"Alg p lb ub - Ratreal r = (let (p', lb', ub') = rat_to_alg r in Alg p lb ub - Alg p' lb' ub')\"\n \"Ratreal r - Alg p lb ub = (let (p', lb', ub') = rat_to_alg r in Alg p' lb' ub' - Alg p lb ub )\"\n \"Alg p lb ub * Ratreal r = (let (p', lb', ub') = rat_to_alg r in Alg p lb ub * Alg p' lb' ub')\"\n \"Ratreal r * Alg p lb ub = (let (p', lb', ub') = rat_to_alg r in Alg p' lb' ub' * Alg p lb ub)\"\n \"Alg p lb ub \/ Ratreal r = (let (p', lb', ub') = rat_to_alg r in Alg p lb ub \/ Alg p' lb' ub')\"\n \"Ratreal r \/ Alg p lb ub = (let (p', lb', ub') = rat_to_alg r in Alg p' lb' ub' \/ Alg p lb ub)\"\n using rat_to_alg_eq[of r]\n by (auto split:prod.split)\n\nlemma alg_sgn_code:\n fixes p::\"int poly\" and lb ub ::float\n defines \"x\\Alg p lb ub\"\n assumes valid:\"valid_alg p lb ub\"\n shows \"if lb\\0 then x>0 else if ub\\0 then x<0 else \n sgn x= sgn_at_core_old [:0,1:] p lb ub\"\nproof -\n have \"x>real_of_float lb\" and \"x0 \\ ub\\0 \\ ?thesis\" \n using order.strict_trans[of x \"real_of_float ub\" 0,simplified] \n order.strict_trans[of 0 \"real_of_float lb\" x,simplified]\n by auto\n moreover have \"\\ (lb\\0 \\ ub\\0) \\ ?thesis\"\n proof -\n assume asm:\"\\ (lb\\0 \\ ub\\0)\"\n have \"sgn x = sgn (poly [:0,1:] x)\" by auto\n also have \"... = sgn_at_core_old [:0,1:] p lb ub\"\n using sgn_at_core_old[OF valid,symmetric] unfolding x_def by blast\n finally have \"sgn x = sgn_at_core_old [:0,1:] p lb ub\" .\n then show ?thesis using asm by auto\n qed\n ultimately show ?thesis by auto\nqed\n\nlemma [code]: \"sgn (Alg p lb ub) = \n (if valid_alg p lb ub then \n if lb \\ 0 then 1\n else if ub \\ 0 then -1\n else sgn_at_core_old [:0,1:] p lb ub\n else \n Code.abort (STR ''invalid Alg'') (%_. sgn (Alg p lb ub)))\"\nusing alg_sgn_code[of p lb ub]\nby auto\n\nlemma [code]: \"sgn (Ratreal r) = Ratreal (sgn r)\" unfolding sgn_if by auto\n\n(*could be refined further for computational efficiency by eliminating the minus operation*)\ndefinition compare::\"real \\ real \\ real\" where\n \"compare x y = sgn (x-y)\"\n\nlemma [code]: \"(x::real)y = (let s=compare x y in s=-1 \\ s=0)\"\n unfolding compare_def sgn_if by auto\n\nlemma [code]: \"(HOL.equal (Alg p1 lb1 ub1) (Alg p2 lb2 ub2)) \n \\ (compare (Alg p1 lb1 ub1) (Alg p2 lb2 ub2) = 0)\"\n \"(HOL.equal (Ratreal r) (Alg p2 lb2 ub2)) \n \\ (compare (Ratreal r) (Alg p2 lb2 ub2) = 0)\"\n \"(HOL.equal (Alg p2 lb2 ub2) (Ratreal r)) \n \\ (compare (Alg p2 lb2 ub2) (Ratreal r) = 0)\"\n unfolding compare_def sgn_if equal_real_def by auto\n\nend","avg_line_length":46.3928571429,"max_line_length":179,"alphanum_fraction":0.6327374334} {"size":32492,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"theory Monotonicity_Rules\n imports \"..\/Properties\/Monotonicity_Properties\"\n \"..\/Properties\/Disjoint_Compatibility\"\n \"..\/..\/Social_Choice_Properties\/Weak_Monotonicity\"\n \"..\/Components\/Compositional_Structures\/Parallel_Composition\"\n \"..\/Components\/Compositional_Structures\/Sequential_Composition\"\n \"..\/Components\/Basic_Modules\/Maximum_Aggregator\"\n Result_Rules\n Monotonicity_Facts\n\nbegin\n\n(*\n Composing a defer-invariant-monotone electoral module in sequence before\n a non-electing, defer-monotone electoral module that defers exactly\n 1 alternative results in a defer-lift-invariant electoral module.\n*)\ntheorem def_inv_mono_imp_def_lift_inv[simp]:\n assumes\n strong_def_mon_m: \"defer_invariant_monotonicity m\" and\n non_electing_n: \"non_electing n\" and\n defers_1: \"defers 1 n\" and\n defer_monotone_n: \"defer_monotonicity n\"\n shows \"defer_lift_invariance (m \\ n)\"\n unfolding defer_lift_invariance_def\nproof (safe)\n have electoral_mod_m: \"electoral_module m\"\n using defer_invariant_monotonicity_def\n strong_def_mon_m\n by auto\n have electoral_mod_n: \"electoral_module n\"\n using defers_1 defers_def\n by auto\n show \"electoral_module (m \\ n)\"\n using electoral_mod_m electoral_mod_n\n by simp\nnext\n fix\n A :: \"'a set\" and\n p :: \"'a Profile\" and\n q :: \"'a Profile\" and\n a :: \"'a\"\n assume\n defer_a_p: \"a \\ defer (m \\ n) A p\" and\n lifted_a: \"Profile.lifted A p q a\"\n from strong_def_mon_m\n have non_electing_m: \"non_electing m\"\n by (simp add: defer_invariant_monotonicity_def)\n have electoral_mod_m: \"electoral_module m\"\n using strong_def_mon_m defer_invariant_monotonicity_def\n by auto\n have electoral_mod_n: \"electoral_module n\"\n using defers_1 defers_def\n by auto\n have finite_profile_q: \"finite_profile A q\"\n using lifted_a\n by (simp add: Profile.lifted_def)\n have finite_profile_p: \"profile A p\"\n using lifted_a\n by (simp add: Profile.lifted_def)\n show \"(m \\ n) A p = (m \\ n) A q\"\n proof cases\n assume not_unchanged: \"defer m A q \\ defer m A p\"\n hence a_single_defer: \"{a} = defer m A q\"\n using strong_def_mon_m electoral_mod_n defer_a_p\n defer_invariant_monotonicity_def lifted_a\n seq_comp_def_set_trans finite_profile_p\n finite_profile_q\n by metis\n moreover have\n \"{a} = defer m A q \\ defer (m \\ n) A q \\ {a}\"\n using finite_profile_q electoral_mod_m electoral_mod_n\n seq_comp_def_set_sound\n by (metis (no_types, hide_lams))\n ultimately have\n \"(a \\ defer m A p) \\ defer (m \\ n) A q \\ {a}\"\n by blast (* lifted defer-subset of a *)\n moreover have\n \"(a \\ defer m A p) \\ card (defer (m \\ n) A q) = 1\"\n using One_nat_def a_single_defer card_eq_0_iff\n card_insert_disjoint defers_1 defers_def\n electoral_mod_m empty_iff finite.emptyI\n seq_comp_defers_def_set order_refl\n def_presv_fin_prof finite_profile_q\n by metis (* lifted defer set size 1 *)\n moreover have defer_a_in_m_p:\n \"a \\ defer m A p\"\n using electoral_mod_m electoral_mod_n defer_a_p\n seq_comp_def_set_bounded finite_profile_p\n finite_profile_q\n by blast\n ultimately have\n \"defer (m \\ n) A q = {a}\" (* lifted defer set = a *)\n using Collect_mem_eq card_1_singletonE empty_Collect_eq\n insertCI subset_singletonD\n by metis\n moreover have\n \"defer (m \\ n) A p = {a}\" (* regular defer set = a *)\n using card_mono defers_def insert_subset Diff_insert_absorb\n seq_comp_def_set_bounded elect_in_alts non_electing_def\n non_electing_n defers_1 One_nat_def card_0_eq empty_iff\n card_1_singletonE card_Diff_singleton finite.emptyI\n card_insert_disjoint def_presv_fin_prof defer_a_p\n electoral_mod_m finite_Diff insertCI insert_Diff\n finite_profile_p finite_profile_q seq_comp_defers_def_set\n by (smt (verit))\n ultimately have (* defer sets equal *)\n \"defer (m \\ n) A p = defer (m \\ n) A q\"\n by blast\n moreover have (* elect sets sets equal *)\n \"elect (m \\ n) A p = elect (m \\ n) A q\"\n using finite_profile_p finite_profile_q\n non_electing_m non_electing_n\n seq_comp_presv_non_electing\n non_electing_def\n by metis (* elect sets equal *)\n thus ?thesis\n using calculation eq_def_and_elect_imp_eq\n electoral_mod_m electoral_mod_n\n finite_profile_p seq_comp_sound\n finite_profile_q\n by metis\n next\n assume not_different_alternatives:\n \"\\(defer m A q \\ defer m A p)\"\n have \"elect m A p = {}\"\n using non_electing_m finite_profile_p finite_profile_q\n by (simp add: non_electing_def)\n moreover have \"elect m A q = {}\"\n using non_electing_m finite_profile_q\n by (simp add: non_electing_def)\n ultimately have elect_m_equal:\n \"elect m A p = elect m A q\"\n by simp (* m elects the same stuff *)\n from not_different_alternatives\n have same_alternatives: \"defer m A q = defer m A p\"\n by simp\n hence\n \"(limit_profile (defer m A p) p) =\n (limit_profile (defer m A p) q) \\\n lifted (defer m A q)\n (limit_profile (defer m A p) p)\n (limit_profile (defer m A p) q) a\"\n using defer_in_alts electoral_mod_m\n lifted_a finite_profile_q\n limit_prof_eq_or_lifted\n by metis\n thus ?thesis\n proof\n assume\n \"limit_profile (defer m A p) p =\n limit_profile (defer m A p) q\"\n hence same_profile:\n \"limit_profile (defer m A p) p =\n limit_profile (defer m A q) q\"\n using same_alternatives\n by simp\n hence results_equal_n:\n \"n (defer m A q) (limit_profile (defer m A q) q) =\n n (defer m A p) (limit_profile (defer m A p) p)\"\n by (simp add: same_alternatives)\n moreover have results_equal_m: \"m A p = m A q\"\n using elect_m_equal same_alternatives\n finite_profile_p finite_profile_q\n by (simp add: electoral_mod_m eq_def_and_elect_imp_eq)\n hence \"(m \\ n) A p = (m \\ n) A q\"\n using same_profile\n by auto\n thus ?thesis\n by blast\n next\n assume still_lifted:\n \"lifted (defer m A q) (limit_profile (defer m A p) p)\n (limit_profile (defer m A p) q) a\"\n hence a_in_def_p:\n \"a \\ defer n (defer m A p)\n (limit_profile (defer m A p) p)\"\n using electoral_mod_m electoral_mod_n\n finite_profile_p defer_a_p\n seq_comp_def_set_trans\n finite_profile_q\n by metis\n hence a_still_deferred_p:\n \"{a} \\ defer n (defer m A p)\n (limit_profile (defer m A p) p)\"\n by simp\n have card_le_1_p: \"card (defer m A p) \\ 1\"\n using One_nat_def Suc_leI card_gt_0_iff\n electoral_mod_m electoral_mod_n\n equals0D finite_profile_p defer_a_p\n seq_comp_def_set_trans def_presv_fin_prof\n finite_profile_q\n by metis\n hence\n \"card (defer n (defer m A p)\n (limit_profile (defer m A p) p)) = 1\"\n using defers_1 defers_def electoral_mod_m\n finite_profile_p def_presv_fin_prof\n finite_profile_q\n by metis\n hence def_set_is_a_p:\n \"{a} = defer n (defer m A p) (limit_profile (defer m A p) p)\"\n using a_still_deferred_p card_1_singletonE\n insert_subset singletonD\n by metis\n have a_still_deferred_q:\n \"a \\ defer n (defer m A q)\n (limit_profile (defer m A p) q)\"\n using still_lifted a_in_def_p\n defer_monotonicity_def\n defer_monotone_n electoral_mod_m\n same_alternatives\n def_presv_fin_prof finite_profile_q\n by metis\n have \"card (defer m A q) \\ 1\"\n using card_le_1_p same_alternatives\n by auto\n hence\n \"card (defer n (defer m A q)\n (limit_profile (defer m A q) q)) = 1\"\n using defers_1 defers_def electoral_mod_m\n finite_profile_q def_presv_fin_prof\n by metis\n hence def_set_is_a_q:\n \"{a} =\n defer n (defer m A q)\n (limit_profile (defer m A q) q)\"\n using a_still_deferred_q card_1_singletonE\n same_alternatives singletonD\n by metis\n have\n \"defer n (defer m A p)\n (limit_profile (defer m A p) p) =\n defer n (defer m A q)\n (limit_profile (defer m A q) q)\"\n using def_set_is_a_q def_set_is_a_p\n by auto\n thus ?thesis\n using seq_comp_presv_non_electing\n eq_def_and_elect_imp_eq non_electing_def\n finite_profile_p finite_profile_q\n non_electing_m non_electing_n\n seq_comp_defers_def_set\n by metis\n qed\n qed\nqed\n\n(*\n Using the max aggregator, composing two compatible\n electoral modules in parallel preserves defer-lift-invariance.\n*)\ntheorem par_comp_def_lift_inv[simp]:\n assumes\n compatible: \"disjoint_compatibility m n\" and\n monotone_m: \"defer_lift_invariance m\" and\n monotone_n: \"defer_lift_invariance n\"\n shows \"defer_lift_invariance (m \\\\<^sub>\\ n)\"\n unfolding defer_lift_invariance_def\nproof (safe)\n have electoral_mod_m: \"electoral_module m\"\n using monotone_m\n by (simp add: defer_lift_invariance_def)\n have electoral_mod_n: \"electoral_module n\"\n using monotone_n\n by (simp add: defer_lift_invariance_def)\n show \"electoral_module (m \\\\<^sub>\\ n)\"\n using electoral_mod_m electoral_mod_n\n by simp\nnext\n fix\n S :: \"'a set\" and\n p :: \"'a Profile\" and\n q :: \"'a Profile\" and\n x :: \"'a\"\n assume\n defer_x: \"x \\ defer (m \\\\<^sub>\\ n) S p\" and\n lifted_x: \"Profile.lifted S p q x\"\n hence f_profs: \"finite_profile S p \\ finite_profile S q\"\n by (simp add: lifted_def)\n from compatible obtain A::\"'a set\" where A:\n \"A \\ S \\ (\\x \\ A. indep_of_alt m S x \\\n (\\p. finite_profile S p \\ x \\ reject m S p)) \\\n (\\x \\ S-A. indep_of_alt n S x \\\n (\\p. finite_profile S p \\ x \\ reject n S p))\"\n using disjoint_compatibility_def f_profs\n by (metis (no_types, lifting))\n have\n \"\\x \\ S. prof_contains_result (m \\\\<^sub>\\ n) S p q x\"\n proof cases\n assume a0: \"x \\ A\"\n hence \"x \\ reject m S p\"\n using A f_profs\n by blast\n with defer_x have defer_n: \"x \\ defer n S p\"\n using compatible disjoint_compatibility_def\n mod_contains_result_def f_profs max_agg_rej4\n by metis\n have\n \"\\x \\ A. mod_contains_result (m \\\\<^sub>\\ n) n S p x\"\n using A compatible disjoint_compatibility_def\n max_agg_rej4 f_profs\n by metis\n moreover have \"\\x \\ S. prof_contains_result n S p q x\"\n using defer_n lifted_x prof_contains_result_def monotone_n f_profs\n defer_lift_invariance_def\n by (smt (verit, del_insts))\n moreover have\n \"\\x \\ A. mod_contains_result n (m \\\\<^sub>\\ n) S q x\"\n using A compatible disjoint_compatibility_def\n max_agg_rej3 f_profs\n by metis\n ultimately have 00:\n \"\\x \\ A. prof_contains_result (m \\\\<^sub>\\ n) S p q x\"\n by (simp add: mod_contains_result_def prof_contains_result_def)\n have\n \"\\x \\ S-A. mod_contains_result (m \\\\<^sub>\\ n) m S p x\"\n using A max_agg_rej2 monotone_m monotone_n f_profs\n defer_lift_invariance_def\n by metis\n moreover have \"\\x \\ S. prof_contains_result m S p q x\"\n using A lifted_x a0 prof_contains_result_def indep_of_alt_def\n lifted_imp_equiv_prof_except_a f_profs IntI\n electoral_mod_defer_elem empty_iff result_disj\n by (smt (verit, ccfv_threshold))\n moreover have\n \"\\x \\ S-A. mod_contains_result m (m \\\\<^sub>\\ n) S q x\"\n using A max_agg_rej1 monotone_m monotone_n f_profs\n defer_lift_invariance_def\n by metis\n ultimately have 01:\n \"\\x \\ S-A. prof_contains_result (m \\\\<^sub>\\ n) S p q x\"\n by (simp add: mod_contains_result_def prof_contains_result_def)\n from 00 01\n show ?thesis\n by blast\n next\n assume \"x \\ A\"\n hence a1: \"x \\ S-A\"\n using DiffI lifted_x compatible f_profs\n Profile.lifted_def\n by (metis (no_types, lifting))\n hence \"x \\ reject n S p\"\n using A f_profs\n by blast\n with defer_x have defer_n: \"x \\ defer m S p\"\n using DiffD1 DiffD2 compatible dcompat_dec_by_one_mod\n defer_not_elec_or_rej disjoint_compatibility_def\n not_rej_imp_elec_or_def mod_contains_result_def\n max_agg_sound par_comp_sound f_profs\n maximum_parallel_composition.simps\n by metis\n have\n \"\\x \\ A. mod_contains_result (m \\\\<^sub>\\ n) n S p x\"\n using A compatible disjoint_compatibility_def\n max_agg_rej4 f_profs\n by metis\n moreover have \"\\x \\ S. prof_contains_result n S p q x\"\n using A lifted_x a1 prof_contains_result_def indep_of_alt_def\n lifted_imp_equiv_prof_except_a f_profs\n electoral_mod_defer_elem\n by (smt (verit, ccfv_threshold))\n moreover have\n \"\\x \\ A. mod_contains_result n (m \\\\<^sub>\\ n) S q x\"\n using A compatible disjoint_compatibility_def\n max_agg_rej3 f_profs\n by metis\n ultimately have 10:\n \"\\x \\ A. prof_contains_result (m \\\\<^sub>\\ n) S p q x\"\n by (simp add: mod_contains_result_def prof_contains_result_def)\n have\n \"\\x \\ S-A. mod_contains_result (m \\\\<^sub>\\ n) m S p x\"\n using A max_agg_rej2 monotone_m monotone_n\n f_profs defer_lift_invariance_def\n by metis\n moreover have \"\\x \\ S. prof_contains_result m S p q x\"\n using lifted_x defer_n prof_contains_result_def monotone_m\n f_profs defer_lift_invariance_def\n by (smt (verit, ccfv_threshold))\n moreover have\n \"\\x \\ S-A. mod_contains_result m (m \\\\<^sub>\\ n) S q x\"\n using A max_agg_rej1 monotone_m monotone_n\n f_profs defer_lift_invariance_def\n by metis\n ultimately have 11:\n \"\\x \\ S-A. prof_contains_result (m \\\\<^sub>\\ n) S p q x\"\n using electoral_mod_defer_elem\n by (simp add: mod_contains_result_def prof_contains_result_def)\n from 10 11\n show ?thesis\n by blast\n qed\n thus \"(m \\\\<^sub>\\ n) S p = (m \\\\<^sub>\\ n) S q\"\n using compatible disjoint_compatibility_def f_profs\n eq_alts_in_profs_imp_eq_results max_par_comp_sound\n by metis\nqed\n\nlemma def_lift_inv_seq_comp_help:\n assumes\n monotone_m: \"defer_lift_invariance m\" and\n monotone_n: \"defer_lift_invariance n\" and\n def_and_lifted: \"a \\ (defer (m \\ n) A p) \\ lifted A p q a\"\n shows \"(m \\ n) A p = (m \\ n) A q\"\nproof -\n let ?new_Ap = \"defer m A p\"\n let ?new_Aq = \"defer m A q\"\n let ?new_p = \"limit_profile ?new_Ap p\"\n let ?new_q = \"limit_profile ?new_Aq q\"\n from monotone_m monotone_n have modules:\n \"electoral_module m \\ electoral_module n\"\n by (simp add: defer_lift_invariance_def)\n hence \"finite_profile A p \\ defer (m \\ n) A p \\ defer m A p\"\n using seq_comp_def_set_bounded\n by metis\n moreover have profile_p: \"lifted A p q a \\ finite_profile A p\"\n by (simp add: lifted_def)\n ultimately have defer_subset: \"defer (m \\ n) A p \\ defer m A p\"\n using def_and_lifted\n by blast\n hence mono_m: \"m A p = m A q\"\n using monotone_m defer_lift_invariance_def def_and_lifted\n modules profile_p seq_comp_def_set_trans\n by metis\n hence new_A_eq: \"?new_Ap = ?new_Aq\"\n by presburger\n have defer_eq:\n \"defer (m \\ n) A p = defer n ?new_Ap ?new_p\"\n using sequential_composition.simps snd_conv\n by metis\n hence mono_n:\n \"n ?new_Ap ?new_p = n ?new_Aq ?new_q\"\n proof cases\n assume \"lifted ?new_Ap ?new_p ?new_q a\"\n thus ?thesis\n using defer_eq mono_m monotone_n\n defer_lift_invariance_def def_and_lifted\n by (metis (no_types, lifting))\n next\n assume a2: \"\\lifted ?new_Ap ?new_p ?new_q a\"\n from def_and_lifted have \"finite_profile A q\"\n by (simp add: lifted_def)\n with modules new_A_eq have 1:\n \"finite_profile ?new_Ap ?new_q\"\n using def_presv_fin_prof\n by (metis (no_types))\n moreover from modules profile_p def_and_lifted\n have 0:\n \"finite_profile ?new_Ap ?new_p\"\n using def_presv_fin_prof\n by (metis (no_types))\n moreover from defer_subset def_and_lifted\n have 2: \"a \\ ?new_Ap\"\n by blast\n moreover from def_and_lifted have eql_lengths:\n \"length ?new_p = length ?new_q\"\n by (simp add: lifted_def)\n ultimately have 0:\n \"(\\i::nat. i < length ?new_p \\\n \\Preference_Relation.lifted ?new_Ap (?new_p!i) (?new_q!i) a) \\\n (\\i::nat. i < length ?new_p \\\n \\Preference_Relation.lifted ?new_Ap (?new_p!i) (?new_q!i) a \\\n (?new_p!i) \\ (?new_q!i))\"\n using a2 lifted_def\n by (metis (no_types, lifting))\n from def_and_lifted modules have\n \"\\i. (0 \\ i \\ i < length ?new_p) \\\n (Preference_Relation.lifted A (p!i) (q!i) a \\ (p!i) = (q!i))\"\n using defer_in_alts Profile.lifted_def limit_prof_presv_size\n by metis\n with def_and_lifted modules mono_m have\n \"\\i. (0 \\ i \\ i < length ?new_p) \\\n (Preference_Relation.lifted ?new_Ap (?new_p!i) (?new_q!i) a \\\n (?new_p!i) = (?new_q!i))\"\n using limit_lifted_imp_eq_or_lifted defer_in_alts\n Profile.lifted_def limit_prof_presv_size\n limit_profile.simps nth_map\n by (metis (no_types, lifting))\n with 0 eql_lengths mono_m\n show ?thesis\n using leI not_less_zero nth_equalityI\n by metis\n qed\n from mono_m mono_n\n show ?thesis\n using sequential_composition.simps\n by (metis (full_types))\nqed\n\n(*Sequential composition preserves the property defer-lift-invariance.*)\ntheorem seq_comp_presv_def_lift_inv[simp]:\n assumes\n monotone_m: \"defer_lift_invariance m\" and\n monotone_n: \"defer_lift_invariance n\"\n shows \"defer_lift_invariance (m \\ n)\"\n using monotone_m monotone_n def_lift_inv_seq_comp_help\n seq_comp_sound defer_lift_invariance_def\n by (metis (full_types))\n\nlemma loop_comp_helper_def_lift_inv_helper:\n assumes\n monotone_m: \"defer_lift_invariance m\" and\n f_prof: \"finite_profile A p\"\n shows\n \"(defer_lift_invariance acc \\ n = card (defer acc A p)) \\\n (\\q a.\n (a \\ (defer (loop_comp_helper acc m t) A p) \\\n lifted A p q a) \\\n (loop_comp_helper acc m t) A p =\n (loop_comp_helper acc m t) A q)\"\nproof (induct n arbitrary: acc rule: less_induct)\n case (less n)\n have defer_card_comp:\n \"defer_lift_invariance acc \\\n (\\q a. (a \\ (defer (acc \\ m) A p) \\ lifted A p q a) \\\n card (defer (acc \\ m) A p) = card (defer (acc \\ m) A q))\"\n using monotone_m def_lift_inv_seq_comp_help\n by metis\n have defer_card_acc:\n \"defer_lift_invariance acc \\\n (\\q a. (a \\ (defer (acc) A p) \\ lifted A p q a) \\\n card (defer (acc) A p) = card (defer (acc) A q))\"\n by (simp add: defer_lift_invariance_def)\n hence defer_card_acc_2:\n \"defer_lift_invariance acc \\\n (\\q a. (a \\ (defer (acc \\ m) A p) \\ lifted A p q a) \\\n card (defer (acc) A p) = card (defer (acc) A q))\"\n using monotone_m f_prof defer_lift_invariance_def seq_comp_def_set_trans\n by metis\n thus ?case\n proof cases\n assume card_unchanged: \"card (defer (acc \\ m) A p) = card (defer acc A p)\"\n with defer_card_comp defer_card_acc monotone_m\n have\n \"defer_lift_invariance (acc) \\\n (\\q a. (a \\ (defer (acc) A p) \\ lifted A p q a) \\\n (loop_comp_helper acc m t) A q = acc A q)\"\n using card_subset_eq defer_in_alts less_irrefl\n loop_comp_helper.simps(1) f_prof psubset_card_mono\n sequential_composition.simps def_presv_fin_prof snd_conv\n defer_lift_invariance_def seq_comp_def_set_bounded\n loop_comp_code_helper\n by (smt (verit))\n moreover from card_unchanged have\n \"(loop_comp_helper acc m t) A p = acc A p\"\n using loop_comp_helper.simps(1) order.strict_iff_order\n psubset_card_mono\n by metis\n ultimately have\n \"(defer_lift_invariance (acc \\ m) \\ defer_lift_invariance acc) \\\n (\\q a. (a \\ (defer (loop_comp_helper acc m t) A p) \\\n lifted A p q a) \\\n (loop_comp_helper acc m t) A p =\n (loop_comp_helper acc m t) A q)\"\n using defer_lift_invariance_def\n by metis\n thus ?thesis\n using monotone_m seq_comp_presv_def_lift_inv\n by blast\n next\n assume card_changed:\n \"\\ (card (defer (acc \\ m) A p) = card (defer acc A p))\"\n with f_prof seq_comp_def_card_bounded have card_smaller_for_p:\n \"electoral_module (acc) \\\n (card (defer (acc \\ m) A p) < card (defer acc A p))\"\n using monotone_m order.not_eq_order_implies_strict\n defer_lift_invariance_def\n by (metis (full_types))\n with defer_card_acc_2 defer_card_comp have card_changed_for_q:\n \"defer_lift_invariance (acc) \\\n (\\q a. (a \\ (defer (acc \\ m) A p) \\ lifted A p q a) \\\n (card (defer (acc \\ m) A q) < card (defer acc A q)))\"\n using defer_lift_invariance_def\n by (metis (no_types, lifting))\n thus ?thesis\n proof cases\n assume t_not_satisfied_for_p: \"\\ t (acc A p)\"\n hence t_not_satisfied_for_q:\n \"defer_lift_invariance (acc) \\\n (\\q a. (a \\ (defer (acc \\ m) A p) \\ lifted A p q a) \\\n \\ t (acc A q))\"\n using monotone_m f_prof defer_lift_invariance_def seq_comp_def_set_trans\n by metis\n from card_changed defer_card_comp defer_card_acc\n have\n \"(defer_lift_invariance (acc \\ m) \\ defer_lift_invariance (acc)) \\\n (\\q a. (a \\ (defer (acc \\ m) A p) \\ lifted A p q a) \\\n card (defer (acc \\ m) A q) \\ (card (defer acc A q)))\"\n proof -\n have\n \"\\f. (defer_lift_invariance f \\\n (\\A rs rsa a. f A rs \\ f A rsa \\\n Profile.lifted A rs rsa (a::'a) \\\n a \\ defer f A rs) \\ \\ electoral_module f) \\\n ((\\A rs rsa a. f A rs = f A rsa \\ \\ Profile.lifted A rs rsa a \\\n a \\ defer f A rs) \\ electoral_module f \\ \\ defer_lift_invariance f)\"\n using defer_lift_invariance_def\n by blast\n thus ?thesis\n using card_changed monotone_m f_prof seq_comp_def_set_trans\n by (metis (no_types, hide_lams))\n qed\n hence\n \"defer_lift_invariance (acc \\ m) \\ defer_lift_invariance (acc) \\\n (\\q a. (a \\ (defer (acc \\ m) A p) \\ lifted A p q a) \\\n defer (acc \\ m) A q \\ defer acc A q)\"\n using defer_card_acc defer_in_alts monotone_m prod.sel(2) f_prof\n psubsetI sequential_composition.simps def_presv_fin_prof\n defer_lift_invariance_def subsetCE Profile.lifted_def\n seq_comp_def_set_bounded\n by (smt (verit))\n with t_not_satisfied_for_p have rec_step_q:\n \"(defer_lift_invariance (acc \\ m) \\ defer_lift_invariance (acc)) \\\n (\\q a. (a \\ (defer (acc \\ m) A p) \\ lifted A p q a) \\\n loop_comp_helper acc m t A q =\n loop_comp_helper (acc \\ m) m t A q)\"\n using defer_in_alts loop_comp_helper.simps(2) monotone_m subsetCE\n prod.sel(2) f_prof sequential_composition.simps card_eq_0_iff\n def_presv_fin_prof defer_lift_invariance_def card_changed_for_q\n gr_implies_not0 t_not_satisfied_for_q\n by (smt (verit, ccfv_SIG))\n have rec_step_p:\n \"electoral_module acc \\\n loop_comp_helper acc m t A p = loop_comp_helper (acc \\ m) m t A p\"\n using card_changed defer_in_alts loop_comp_helper.simps(2)\n monotone_m prod.sel(2) f_prof psubsetI def_presv_fin_prof\n sequential_composition.simps defer_lift_invariance_def\n t_not_satisfied_for_p seq_comp_def_set_bounded\n by (smt (verit, best))\n thus ?thesis\n using card_smaller_for_p less.hyps\n loop_comp_helper_imp_no_def_incr monotone_m\n seq_comp_presv_def_lift_inv f_prof rec_step_q\n defer_lift_invariance_def subsetCE subset_eq\n by (smt (verit, ccfv_threshold))\n next\n assume t_satisfied_for_p: \"\\ \\t (acc A p)\"\n thus ?thesis\n using loop_comp_helper.simps(1) defer_lift_invariance_def\n by metis\n qed\n qed\nqed\n\nlemma loop_comp_helper_def_lift_inv:\n assumes\n monotone_m: \"defer_lift_invariance m\" and\n monotone_acc: \"defer_lift_invariance acc\" and\n profile: \"finite_profile A p\"\n shows\n \"\\q a. (lifted A p q a \\ a \\ (defer (loop_comp_helper acc m t) A p)) \\\n (loop_comp_helper acc m t) A p = (loop_comp_helper acc m t) A q\"\n using loop_comp_helper_def_lift_inv_helper\n monotone_m monotone_acc profile\n by blast\n\nlemma loop_comp_helper_def_lift_inv2:\n assumes\n monotone_m: \"defer_lift_invariance m\" and\n monotone_acc: \"defer_lift_invariance acc\"\n shows\n \"\\A p q a. (finite_profile A p \\\n lifted A p q a \\\n a \\ (defer (loop_comp_helper acc m t) A p)) \\\n (loop_comp_helper acc m t) A p = (loop_comp_helper acc m t) A q\"\n using loop_comp_helper_def_lift_inv monotone_acc monotone_m\n by blast\n\nlemma lifted_imp_fin_prof:\n assumes \"lifted A p q a\"\n shows \"finite_profile A p\"\n using assms Profile.lifted_def\n by fastforce\n\nlemma loop_comp_helper_presv_def_lift_inv:\n assumes\n monotone_m: \"defer_lift_invariance m\" and\n monotone_acc: \"defer_lift_invariance acc\"\n shows \"defer_lift_invariance (loop_comp_helper acc m t)\"\nproof -\n have\n \"\\f. (defer_lift_invariance f \\\n (\\A rs rsa a. f A rs \\ f A rsa \\\n Profile.lifted A rs rsa (a::'a) \\\n a \\ defer f A rs) \\\n \\ electoral_module f) \\\n ((\\A rs rsa a. f A rs = f A rsa \\ \\ Profile.lifted A rs rsa a \\\n a \\ defer f A rs) \\\n electoral_module f \\ \\ defer_lift_invariance f)\"\n using defer_lift_invariance_def\n by blast\n thus ?thesis\n using electoral_module_def lifted_imp_fin_prof\n loop_comp_helper_def_lift_inv loop_comp_helper_imp_partit\n monotone_acc monotone_m\n by (metis (full_types))\nqed\n\n(*The loop composition preserves defer-lift-invariance.*)\ntheorem loop_comp_presv_def_lift_inv[simp]:\n assumes monotone_m: \"defer_lift_invariance m\"\n shows \"defer_lift_invariance (m \\\\<^sub>t)\"\nproof -\n fix\n A :: \"'a set\"\n have\n \"\\ p q a. (a \\ (defer (m \\\\<^sub>t) A p) \\ lifted A p q a) \\\n (m \\\\<^sub>t) A p = (m \\\\<^sub>t) A q\"\n using defer_module.simps monotone_m lifted_imp_fin_prof\n loop_composition.simps(1) loop_composition.simps(2)\n loop_comp_helper_def_lift_inv2\n by (metis (full_types))\n thus ?thesis\n using def_mod_def_lift_inv monotone_m loop_composition.simps(1)\n loop_composition.simps(2) defer_lift_invariance_def\n loop_comp_sound loop_comp_helper_def_lift_inv2\n lifted_imp_fin_prof\n by (smt (verit, best))\nqed\n\n(*\n Revising an invariant monotone electoral module results in a\n defer-invariant-monotone electoral module.\n*)\ntheorem rev_comp_def_inv_mono[simp]:\n assumes \"invariant_monotonicity m\"\n shows \"defer_invariant_monotonicity (m\\)\"\nproof -\n have \"\\A p q w. (w \\ defer (m\\) A p \\ lifted A p q w) \\\n (defer (m\\) A q = defer (m\\) A p \\ defer (m\\) A q = {w})\"\n using assms\n by (simp add: invariant_monotonicity_def)\n moreover have \"electoral_module (m\\)\"\n using assms rev_comp_sound invariant_monotonicity_def\n by auto\n moreover have \"non_electing (m\\)\"\n using assms rev_comp_non_electing invariant_monotonicity_def\n by auto\n ultimately have \"electoral_module (m\\) \\ non_electing (m\\) \\\n (\\A p q w. (w \\ defer (m\\) A p \\ lifted A p q w) \\\n (defer (m\\) A q = defer (m\\) A p \\ defer (m\\) A q = {w}))\"\n by blast\n thus ?thesis\n using defer_invariant_monotonicity_def\n by (simp add: defer_invariant_monotonicity_def)\nqed\n\n(*\n Every electoral module which is defer-lift-invariant is\n also defer-monotone.\n*)\ntheorem dl_inv_imp_def_mono[simp]:\n assumes \"defer_lift_invariance m\"\n shows \"defer_monotonicity m\"\n using assms defer_monotonicity_def defer_lift_invariance_def\n by fastforce\n\n(*\n Composing a defer-lift invariant and a non-electing\n electoral module that defers exactly one alternative\n in sequence with an electing electoral module\n results in a monotone electoral module.\n*)\ntheorem seq_comp_mono[simp]:\n assumes\n def_monotone_m: \"defer_lift_invariance m\" and\n non_ele_m: \"non_electing m\" and\n def_one_m: \"defers 1 m\" and\n electing_n: \"electing n\"\n shows \"monotonicity (m \\ n)\"\n unfolding monotonicity_def\nproof (safe)\n have electoral_mod_m: \"electoral_module m\"\n using non_ele_m\n by (simp add: non_electing_def)\n have electoral_mod_n: \"electoral_module n\"\n using electing_n\n by (simp add: electing_def)\n show \"electoral_module (m \\ n)\"\n using electoral_mod_m electoral_mod_n\n by simp\nnext\n fix\n A :: \"'a set\" and\n p :: \"'a Profile\" and\n q :: \"'a Profile\" and\n w :: \"'a\"\n assume\n fin_A: \"finite A\" and\n elect_w_in_p: \"w \\ elect (m \\ n) A p\" and\n lifted_w: \"Profile.lifted A p q w\"\n have\n \"finite_profile A p \\ finite_profile A q\"\n using lifted_w lifted_def\n by metis\n thus \"w \\ elect (m \\ n) A q\"\n using seq_comp_def_then_elect defer_lift_invariance_def\n elect_w_in_p lifted_w def_monotone_m non_ele_m\n def_one_m electing_n\n by metis\nqed\n\nend","avg_line_length":40.4632627646,"max_line_length":114,"alphanum_fraction":0.6589006525} {"size":8982,"ext":"thy","lang":"Isabelle","max_stars_count":4.0,"content":"chapter \\Generated by Lem from \\..\/..\/src\/gen_lib\/sail2_prompt.lem\\.\\\n\ntheory \"Sail2_prompt\" \n\nimports\n Main\n \"LEM.Lem_pervasives_extra\"\n \"Sail2_values\"\n \"Sail2_prompt_monad\"\n \"Sail2_prompt_monad_lemmas\"\n\nbegin \n\n\\ \\\\open import Pervasives_extra\\\\\n\\ \\\\open import Sail_impl_base\\\\\n\\ \\\\open import Sail2_values\\\\\n\\ \\\\open import Sail2_prompt_monad\\\\\n\\ \\\\open import {isabelle} `Sail2_prompt_monad_lemmas`\\\\\n\n\\ \\\\val >>= : forall 'rv 'a 'b 'e. monad 'rv 'a 'e -> ('a -> monad 'rv 'b 'e) -> monad 'rv 'b 'e\\\\\n\n\\ \\\\val >> : forall 'rv 'b 'e. monad 'rv unit 'e -> monad 'rv 'b 'e -> monad 'rv 'b 'e\\\\\n\n\\ \\\\val iter_aux : forall 'rv 'a 'e. integer -> (integer -> 'a -> monad 'rv unit 'e) -> list 'a -> monad 'rv unit 'e\\\\\nfun iter_aux :: \" int \\(int \\ 'a \\('rv,(unit),'e)monad)\\ 'a list \\('rv,(unit),'e)monad \" where \n \" iter_aux i f (x # xs) = ( f i x \\ iter_aux (i +( 1 :: int)) f xs )\"\n|\" iter_aux i f ([]) = ( return () )\"\n\n\n\\ \\\\val iteri : forall 'rv 'a 'e. (integer -> 'a -> monad 'rv unit 'e) -> list 'a -> monad 'rv unit 'e\\\\\ndefinition iteri :: \"(int \\ 'a \\('rv,(unit),'e)monad)\\ 'a list \\('rv,(unit),'e)monad \" where \n \" iteri f xs = ( iter_aux(( 0 :: int)) f xs )\"\n\n\n\\ \\\\val iter : forall 'rv 'a 'e. ('a -> monad 'rv unit 'e) -> list 'a -> monad 'rv unit 'e\\\\\ndefinition iter :: \"('a \\('rv,(unit),'e)monad)\\ 'a list \\('rv,(unit),'e)monad \" where \n \" iter f xs = ( iteri ( \\x . \n (case x of _ => \\ x . f x )) xs )\"\n\n\n\\ \\\\val foreachM : forall 'a 'rv 'vars 'e.\n list 'a -> 'vars -> ('a -> 'vars -> monad 'rv 'vars 'e) -> monad 'rv 'vars 'e\\\\\nfun foreachM :: \" 'a list \\ 'vars \\('a \\ 'vars \\('rv,'vars,'e)monad)\\('rv,'vars,'e)monad \" where \n \" foreachM ([]) vars body = ( return vars )\"\n|\" foreachM (x # xs) vars body = (\n body x vars \\ (\\ vars . \n foreachM xs vars body))\"\n\n\n\\ \\\\val genlistM : forall 'a 'rv 'e. (nat -> monad 'rv 'a 'e) -> nat -> monad 'rv (list 'a) 'e\\\\\ndefinition genlistM :: \"(nat \\('rv,'a,'e)monad)\\ nat \\('rv,('a list),'e)monad \" where \n \" genlistM f n = (\n (let indices = (genlist (\\ n . n) n) in\n foreachM indices [] (\\ n xs . (f n \\ (\\ x . return (xs @ [x]))))))\"\n\n\n\\ \\\\val and_boolM : forall 'rv 'e. monad 'rv bool 'e -> monad 'rv bool 'e -> monad 'rv bool 'e\\\\\ndefinition and_boolM :: \"('rv,(bool),'e)monad \\('rv,(bool),'e)monad \\('rv,(bool),'e)monad \" where \n \" and_boolM l r = ( l \\ (\\ l . if l then r else return False))\"\n\n\n\\ \\\\val or_boolM : forall 'rv 'e. monad 'rv bool 'e -> monad 'rv bool 'e -> monad 'rv bool 'e\\\\\ndefinition or_boolM :: \"('rv,(bool),'e)monad \\('rv,(bool),'e)monad \\('rv,(bool),'e)monad \" where \n \" or_boolM l r = ( l \\ (\\ l . if l then return True else r))\"\n\n\n\\ \\\\val bool_of_bitU_fail : forall 'rv 'e. bitU -> monad 'rv bool 'e\\\\\ndefinition bool_of_bitU_fail :: \" bitU \\('rv,(bool),'e)monad \" where \n \" bool_of_bitU_fail = ( \\x . \n (case x of\n B0 => return False\n | B1 => return True\n | BU => Fail (''bool_of_bitU'')\n ) )\"\n\n\n\\ \\\\val bool_of_bitU_nondet : forall 'rv 'e. bitU -> monad 'rv bool 'e\\\\\ndefinition bool_of_bitU_nondet :: \" bitU \\('rv,(bool),'e)monad \" where \n \" bool_of_bitU_nondet = ( \\x . \n (case x of\n B0 => return False\n | B1 => return True\n | BU => choose_bool (''bool_of_bitU'')\n ) )\"\n\n\n\\ \\\\val bools_of_bits_nondet : forall 'rv 'e. list bitU -> monad 'rv (list bool) 'e\\\\\ndefinition bools_of_bits_nondet :: \"(bitU)list \\('rv,((bool)list),'e)monad \" where \n \" bools_of_bits_nondet bits = (\n foreachM bits []\n (\\ b bools . \n bool_of_bitU_nondet b \\ (\\ b . \n return (bools @ [b]))))\"\n\n\n\\ \\\\val of_bits_nondet : forall 'rv 'a 'e. Bitvector 'a => list bitU -> monad 'rv 'a 'e\\\\\ndefinition of_bits_nondet :: \" 'a Bitvector_class \\(bitU)list \\('rv,'a,'e)monad \" where \n \" of_bits_nondet dict_Sail2_values_Bitvector_a bits = (\n bools_of_bits_nondet bits \\ (\\ bs . \n return ((of_bools_method dict_Sail2_values_Bitvector_a) bs)))\"\n\n\n\\ \\\\val of_bits_fail : forall 'rv 'a 'e. Bitvector 'a => list bitU -> monad 'rv 'a 'e\\\\\ndefinition of_bits_fail :: \" 'a Bitvector_class \\(bitU)list \\('rv,'a,'e)monad \" where \n \" of_bits_fail dict_Sail2_values_Bitvector_a bits = ( maybe_fail (''of_bits'') (\n (of_bits_method dict_Sail2_values_Bitvector_a) bits))\"\n\n\n\\ \\\\val mword_nondet : forall 'rv 'a 'e. Size 'a => unit -> monad 'rv (mword 'a) 'e\\\\\ndefinition mword_nondet :: \" unit \\('rv,(('a::len)Word.word),'e)monad \" where \n \" mword_nondet _ = (\n bools_of_bits_nondet (repeat [BU] (int (len_of (TYPE(_) :: 'a itself)))) \\ (\\ bs . \n return (Word.of_bl bs)))\"\n\n\n\\ \\\\val whileM : forall 'rv 'vars 'e. 'vars -> ('vars -> monad 'rv bool 'e) ->\n ('vars -> monad 'rv 'vars 'e) -> monad 'rv 'vars 'e\\\\\nfunction (sequential,domintros) whileM :: \" 'vars \\('vars \\('rv,(bool),'e)monad)\\('vars \\('rv,'vars,'e)monad)\\('rv,'vars,'e)monad \" where \n \" whileM vars cond body = (\n cond vars \\ (\\ cond_val . \n if cond_val then\n body vars \\ (\\ vars . whileM vars cond body)\n else return vars))\" \nby pat_completeness auto\n\n\n\\ \\\\val untilM : forall 'rv 'vars 'e. 'vars -> ('vars -> monad 'rv bool 'e) ->\n ('vars -> monad 'rv 'vars 'e) -> monad 'rv 'vars 'e\\\\\nfunction (sequential,domintros) untilM :: \" 'vars \\('vars \\('rv,(bool),'e)monad)\\('vars \\('rv,'vars,'e)monad)\\('rv,'vars,'e)monad \" where \n \" untilM vars cond body = (\n body vars \\ (\\ vars . \n cond vars \\ (\\ cond_val . \n if cond_val then return vars else untilM vars cond body)))\" \nby pat_completeness auto\n\n\n\\ \\\\val choose_bools : forall 'rv 'e. string -> nat -> monad 'rv (list bool) 'e\\\\\ndefinition choose_bools :: \" string \\ nat \\('rv,((bool)list),'e)monad \" where \n \" choose_bools descr n = ( genlistM ( \\x . \n (case x of _ => choose_bool descr )) n )\"\n\n\n\\ \\\\val choose : forall 'rv 'a 'e. string -> list 'a -> monad 'rv 'a 'e\\\\\ndefinition chooseM :: \" string \\ 'a list \\('rv,'a,'e)monad \" where \n \" chooseM descr xs = (\n \\ \\\\ Use sufficiently many nondeterministically chosen bits and convert into an\n index into the list \\\\\n choose_bools descr (List.length xs) \\ (\\ bs . \n (let idx = (( (nat_of_bools bs)) mod List.length xs) in\n (case index xs idx of\n Some x => return x\n | None => Fail ((''choose '') @ descr)\n ))))\"\n\n\n\\ \\\\val internal_pick : forall 'rv 'a 'e. list 'a -> monad 'rv 'a 'e\\\\\ndefinition internal_pick :: \" 'a list \\('rv,'a,'e)monad \" where \n \" internal_pick xs = ( chooseM (''internal_pick'') xs )\"\n\n\n\\ \\\\let write_two_regs r1 r2 vec =\n let is_inc =\n let is_inc_r1 = is_inc_of_reg r1 in\n let is_inc_r2 = is_inc_of_reg r2 in\n let () = ensure (is_inc_r1 = is_inc_r2)\n \"write_two_regs called with vectors of different direction\" in\n is_inc_r1 in\n\n let (size_r1 : integer) = size_of_reg r1 in\n let (start_vec : integer) = get_start vec in\n let size_vec = length vec in\n let r1_v =\n if is_inc\n then slice vec start_vec (size_r1 - start_vec - 1)\n else slice vec start_vec (start_vec - size_r1 - 1) in\n let r2_v =\n if is_inc\n then slice vec (size_r1 - start_vec) (size_vec - start_vec)\n else slice vec (start_vec - size_r1) (start_vec - size_vec) in\n write_reg r1 r1_v >> write_reg r2 r2_v\\\\\nend\n","avg_line_length":49.3516483516,"max_line_length":201,"alphanum_fraction":0.6203518147} {"size":10902,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/n_german_lemma_on_inv__17.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_german Protocol Case Study*} \n\ntheory n_german_lemma_on_inv__17 imports n_german_base\nbegin\nsection{*All lemmas on causal relation between inv__17 and some rule r*}\nlemma n_SendInvEVsinv__17:\nassumes a1: \"(\\ i. i\\N\\r=n_SendInvE i)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_SendInvE i\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i=p__Inv3)\\(i~=p__Inv3\\i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i=p__Inv3)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv3\\i~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_SendInvSVsinv__17:\nassumes a1: \"(\\ i. i\\N\\r=n_SendInvS i)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_SendInvS i\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i=p__Inv3)\\(i~=p__Inv3\\i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i=p__Inv3)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv3\\i~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_SendInvAckVsinv__17:\nassumes a1: \"(\\ i. i\\N\\r=n_SendInvAck i)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_SendInvAck i\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i=p__Inv3)\\(i~=p__Inv3\\i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i=p__Inv3)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv3\\i~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_SendGntSVsinv__17:\nassumes a1: \"(\\ i. i\\N\\r=n_SendGntS i)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_SendGntS i\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i=p__Inv3)\\(i~=p__Inv3\\i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i=p__Inv3)\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (eqn (IVar (Ident ''ExGntd'')) (Const false)) (eqn (IVar (Field (Para (Ident ''Cache'') p__Inv4) ''State'')) (Const E))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv3\\i~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_SendGntEVsinv__17:\nassumes a1: \"(\\ i. i\\N\\r=n_SendGntE N i)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_SendGntE N i\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i=p__Inv3)\\(i~=p__Inv3\\i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i=p__Inv3)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv3\\i~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_RecvGntSVsinv__17:\nassumes a1: \"(\\ i. i\\N\\r=n_RecvGntS i)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_RecvGntS i\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i=p__Inv3)\\(i~=p__Inv3\\i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i=p__Inv3)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv3\\i~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_RecvGntEVsinv__17:\nassumes a1: \"(\\ i. i\\N\\r=n_RecvGntE i)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_RecvGntE i\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i=p__Inv3)\\(i~=p__Inv3\\i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (eqn (IVar (Field (Para (Ident ''Chan2'') p__Inv3) ''Cmd'')) (Const GntS)) (eqn (IVar (Field (Para (Ident ''Chan2'') p__Inv4) ''Cmd'')) (Const GntE))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i=p__Inv3)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv3\\i~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_StoreVsinv__17:\n assumes a1: \"\\ i d. i\\N\\d\\N\\r=n_Store i d\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_SendReqESVsinv__17:\n assumes a1: \"\\ i. i\\N\\r=n_SendReqES i\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_RecvInvAckVsinv__17:\n assumes a1: \"\\ i. i\\N\\r=n_RecvInvAck i\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_RecvReqVsinv__17:\n assumes a1: \"\\ i. i\\N\\r=n_RecvReq N i\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_SendReqSVsinv__17:\n assumes a1: \"\\ j. j\\N\\r=n_SendReqS j\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_SendReqEIVsinv__17:\n assumes a1: \"\\ i. i\\N\\r=n_SendReqEI i\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \nend\n","avg_line_length":42.5859375,"max_line_length":230,"alphanum_fraction":0.6920748487} {"size":8814,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/n_germanSimp_lemma_on_inv__39.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_germanSimp Protocol Case Study*} \n\ntheory n_germanSimp_lemma_on_inv__39 imports n_germanSimp_base\nbegin\nsection{*All lemmas on causal relation between inv__39 and some rule r*}\nlemma n_SendInv__part__0Vsinv__39:\nassumes a1: \"(\\ i. i\\N\\r=n_SendInv__part__0 i)\" and\na2: \"(\\ p__Inv4. p__Inv4\\N\\f=inv__39 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_SendInv__part__0 i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\N\\f=inv__39 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (eqn (IVar (Para (Ident ''InvSet'') p__Inv4)) (Const true)) (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv4) ''Cmd'')) (Const InvAck))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_SendInv__part__1Vsinv__39:\nassumes a1: \"(\\ i. i\\N\\r=n_SendInv__part__1 i)\" and\na2: \"(\\ p__Inv4. p__Inv4\\N\\f=inv__39 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_SendInv__part__1 i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\N\\f=inv__39 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (eqn (IVar (Para (Ident ''InvSet'') p__Inv4)) (Const true)) (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv4) ''Cmd'')) (Const InvAck))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_SendInvAckVsinv__39:\nassumes a1: \"(\\ i. i\\N\\r=n_SendInvAck i)\" and\na2: \"(\\ p__Inv4. p__Inv4\\N\\f=inv__39 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_SendInvAck i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\N\\f=inv__39 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_RecvInvAckVsinv__39:\nassumes a1: \"(\\ i. i\\N\\r=n_RecvInvAck i)\" and\na2: \"(\\ p__Inv4. p__Inv4\\N\\f=inv__39 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_RecvInvAck i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\N\\f=inv__39 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_SendGntSVsinv__39:\nassumes a1: \"(\\ i. i\\N\\r=n_SendGntS i)\" and\na2: \"(\\ p__Inv4. p__Inv4\\N\\f=inv__39 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_SendGntS i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\N\\f=inv__39 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_SendGntEVsinv__39:\nassumes a1: \"(\\ i. i\\N\\r=n_SendGntE N i)\" and\na2: \"(\\ p__Inv4. p__Inv4\\N\\f=inv__39 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_SendGntE N i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\N\\f=inv__39 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_RecvGntSVsinv__39:\nassumes a1: \"(\\ i. i\\N\\r=n_RecvGntS i)\" and\na2: \"(\\ p__Inv4. p__Inv4\\N\\f=inv__39 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_RecvGntS i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\N\\f=inv__39 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_RecvGntEVsinv__39:\nassumes a1: \"(\\ i. i\\N\\r=n_RecvGntE i)\" and\na2: \"(\\ p__Inv4. p__Inv4\\N\\f=inv__39 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_RecvGntE i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\N\\f=inv__39 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_StoreVsinv__39:\n assumes a1: \"\\ i d. i\\N\\d\\N\\r=n_Store i d\" and\n a2: \"(\\ p__Inv4. p__Inv4\\N\\f=inv__39 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_RecvReqE__part__0Vsinv__39:\n assumes a1: \"\\ i. i\\N\\r=n_RecvReqE__part__0 N i\" and\n a2: \"(\\ p__Inv4. p__Inv4\\N\\f=inv__39 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_RecvReqE__part__1Vsinv__39:\n assumes a1: \"\\ i. i\\N\\r=n_RecvReqE__part__1 N i\" and\n a2: \"(\\ p__Inv4. p__Inv4\\N\\f=inv__39 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_RecvReqSVsinv__39:\n assumes a1: \"\\ i. i\\N\\r=n_RecvReqS N i\" and\n a2: \"(\\ p__Inv4. p__Inv4\\N\\f=inv__39 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \nend\n","avg_line_length":39.5246636771,"max_line_length":217,"alphanum_fraction":0.6903789426} {"size":145,"ext":"thy","lang":"Isabelle","max_stars_count":7.0,"content":"theory T =\nthy\n set s\n stable relation p : s * s\n\n implicit x : s\n\n axiom foo = true and all x .\n (p (x, x) and p (x, x) => p (x, x))\n\nend","avg_line_length":13.1818181818,"max_line_length":39,"alphanum_fraction":0.5172413793} {"size":2743,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: Serial_Rel.thy\n Author: Sebastian Ullrich\n*)\n\nsubsection \"Serial Relations\"\n\ntext {* A serial relation on a finite carrier induces a cycle. *}\n\ntheory Serial_Rel\nimports Main\nbegin\n\ndefinition \"serial_on A r \\ (\\x \\ A. \\y \\ A. (x,y) \\ r)\"\nlemmas serial_onI = serial_on_def[THEN iffD2, rule_format]\nlemmas serial_onE = serial_on_def[THEN iffD1, rule_format, THEN bexE]\n\nfun iterated_serial_on :: \"'a set \\ 'a rel \\ 'a \\ nat \\ 'a\" where\n \"iterated_serial_on A r x 0 = x\"\n| \"iterated_serial_on A r x (Suc n) = (SOME y. y \\ A \\ (iterated_serial_on A r x n,y) \\ r)\"\n\nlemma iterated_serial_on_linear: \"iterated_serial_on A r x (n+m) = iterated_serial_on A r (iterated_serial_on A r x n) m\"\nby (induction m) auto\n\nlemma iterated_serial_on_in_A:\n assumes \"serial_on A r\" \"a \\ A\"\n shows \"iterated_serial_on A r a n \\ A\"\nproof (induct n)\n case (Suc n)\n thus ?case\n using assms(1, 2) by (subst iterated_serial_on.simps(2)) (rule someI2_ex, auto elim: serial_onE)\nqed (simp add:assms(2))\n\nlemma iterated_serial_on_in_power:\n assumes \"serial_on A r\" \"a \\ A\"\n shows \"(a,iterated_serial_on A r a n) \\ r ^^ n\"\nproof (induct n)\n case (Suc n)\n moreover obtain b where \"(iterated_serial_on A r a n,b) \\ r\" \"b \\ A\"\n using iterated_serial_on_in_A[OF assms, of n] assms(1) by - (rule serial_onE)\n ultimately show ?case by (subst iterated_serial_on.simps(2)) (rule someI2_ex, auto)\nqed simp\n\nlemma trancl_powerI: \"a \\ R ^^ n \\ n > 0 \\ a \\ R\\<^sup>+\"\nby (auto simp:trancl_power)\n\ntheorem serial_on_finite_cycle:\n assumes \"serial_on A r\" \"A \\ {}\" \"finite A\"\n obtains a where \"a \\ A\" \"(a,a) \\ r\\<^sup>+\"\nproof-\n from assms(2) obtain a where a: \"a \\ A\" by auto\n let ?f = \"iterated_serial_on A r a\"\n from a have \"range ?f \\ A\" using assms(1) by (auto intro: iterated_serial_on_in_A)\n with assms(3) have \"\\m\\UNIV.\\ finite {n \\ UNIV. ?f n = ?f m}\"\n by - (rule pigeonhole_infinite, auto simp: finite_subset)\n then obtain n m where \"?f m = ?f n\" and[simp]: \"n < m\"\n by (metis (mono_tags, lifting) finite_nat_set_iff_bounded mem_Collect_eq not_less_eq)\n hence \"?f n = iterated_serial_on A r (?f n) (m-n)\"\n using iterated_serial_on_linear[of A r a n \"m-n\"] by (auto simp:less_imp_le_nat)\n also have \"(?f n,iterated_serial_on A r (?f n) (m-n)) \\ r ^^ (m - n)\"\n by (rule iterated_serial_on_in_power[OF assms(1)], rule iterated_serial_on_in_A[OF assms(1) a])\n finally show ?thesis\n by - (rule that[of \"?f n\"], rule iterated_serial_on_in_A[OF assms(1) a], rule trancl_powerI, auto)\nqed\n\nend","avg_line_length":42.2,"max_line_length":121,"alphanum_fraction":0.6850164054} {"size":3278,"ext":"thy","lang":"Isabelle","max_stars_count":27.0,"content":"(*\n * Copyright Florian Haftmann\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\nsection \\Ancient comprehensive Word Library\\\n\ntheory Word_Lib_Sumo\nimports\n \"HOL-Library.Word\"\n Aligned\n Ancient_Numeral\n Bit_Comprehension\n Bits_Int\n Bitwise_Signed\n Bitwise\n Enumeration_Word\n Generic_set_bit\n Hex_Words\n Least_significant_bit\n More_Arithmetic\n More_Divides\n More_Sublist\n Even_More_List\n More_Misc\n Strict_part_mono\n Legacy_Aliases\n Most_significant_bit\n Next_and_Prev\n Norm_Words\n Reversed_Bit_Lists\n Rsplit\n Signed_Words\n Traditional_Infix_Syntax\n Typedef_Morphisms\n Type_Syntax\n Word_EqI\n Word_Lemmas\n Word_8\n Word_16\n Word_32\n Word_Syntax\n Signed_Division_Word\n More_Word_Operations\n Many_More\nbegin\n\ndeclare word_induct2[induct type]\ndeclare word_nat_cases[cases type]\n\ndeclare signed_take_bit_Suc [simp]\n\n(* these generate take_bit terms, which we often don't want for concrete lengths *)\nlemmas of_int_and_nat = unsigned_of_nat unsigned_of_int signed_of_int signed_of_nat\n\nbundle no_take_bit\nbegin\n declare of_int_and_nat[simp del]\nend\n\nlemmas bshiftr1_def = bshiftr1_eq\nlemmas is_down_def = is_down_eq\nlemmas is_up_def = is_up_eq\nlemmas mask_def = mask_eq\nlemmas scast_def = scast_eq\nlemmas shiftl1_def = shiftl1_eq\nlemmas shiftr1_def = shiftr1_eq\nlemmas sshiftr1_def = sshiftr1_eq\nlemmas sshiftr_def = sshiftr_eq_funpow_sshiftr1\nlemmas to_bl_def = to_bl_eq\nlemmas ucast_def = ucast_eq\nlemmas unat_def = unat_eq_nat_uint\nlemmas word_cat_def = word_cat_eq\nlemmas word_reverse_def = word_reverse_eq_of_bl_rev_to_bl\nlemmas word_roti_def = word_roti_eq_word_rotr_word_rotl\nlemmas word_rotl_def = word_rotl_eq\nlemmas word_rotr_def = word_rotr_eq\nlemmas word_sle_def = word_sle_eq\nlemmas word_sless_def = word_sless_eq\n\nlemmas uint_0 = uint_nonnegative\nlemmas uint_lt = uint_bounded\nlemmas uint_mod_same = uint_idem\nlemmas of_nth_def = word_set_bits_def\n\nlemmas of_nat_word_eq_iff = word_of_nat_eq_iff\nlemmas of_nat_word_eq_0_iff = word_of_nat_eq_0_iff\nlemmas of_int_word_eq_iff = word_of_int_eq_iff\nlemmas of_int_word_eq_0_iff = word_of_int_eq_0_iff\n\nlemmas word_next_def = word_next_unfold\n\nlemmas word_prev_def = word_prev_unfold\n\nlemmas is_aligned_def = is_aligned_iff_dvd_nat\n\nlemma shiftl_transfer [transfer_rule]:\n includes lifting_syntax\n shows \"(pcr_word ===> (=) ===> pcr_word) (<<) (<<)\"\n by (unfold shiftl_eq_push_bit) transfer_prover\n\nlemmas word_and_max_simps =\n word8_and_max_simp\n word16_and_max_simp\n word32_and_max_simp\n\nlemma distinct_lemma: \"f x \\ f y \\ x \\ y\" by auto\n\nlemmas and_bang = word_and_nth\n\nlemmas sdiv_int_def = signed_divide_int_def\nlemmas smod_int_def = signed_modulo_int_def\n\n(* shortcut for some specific lengths *)\nlemma word_fixed_sint_1[simp]:\n \"sint (1::8 word) = 1\"\n \"sint (1::16 word) = 1\"\n \"sint (1::32 word) = 1\"\n \"sint (1::64 word) = 1\"\n by (auto simp: sint_word_ariths)\n\ndeclare of_nat_diff [simp]\n\n(* Haskellish names\/syntax *)\nnotation (input)\n test_bit (\"testBit\")\n\nlemmas cast_simps = cast_simps ucast_down_bl\n\n(* shadows the slightly weaker Word.nth_ucast *)\nlemma nth_ucast:\n \"(ucast (w::'a::len word)::'b::len word) !! n =\n (w !! n \\ n < min LENGTH('a) LENGTH('b))\"\n by transfer (simp add: bit_take_bit_iff ac_simps)\n\nend\n","avg_line_length":23.7536231884,"max_line_length":83,"alphanum_fraction":0.793166565} {"size":14105,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"theory HEAP1CBJNoLemmas\nimports HEAP1\nbegin\n\nlemma l1: \"disjoint s1 s2 \\ s3 \\ s2 \\ disjoint s1 s3\"\nby (metis Int_absorb2 Int_assoc Int_empty_right disjoint_def le_infI1 order_refl)\n\nlemma l2v0: \"disjoint s1 s2 \\ disjoint s2 s3 \\ disjoint (s1 \\ s2) s3\"\nnitpick\noops\nlemma l2v1: \"s2 \\ {} \\ disjoint s1 s2 \\ disjoint s2 s3 \\ disjoint (s1 \\ s2) s3\"\nnitpick\noops\n\nlemma l2v2: \"s2 \\ s1 \\ disjoint s1 s3 \\ disjoint (s1 \\ s2) s3\"\noops\n\nlemma l2: \"disjoint s1 s2 \\ disjoint s1 s3 \\ disjoint s2 s3 \\ disjoint (s1 \\ s2) s3\"\nby (metis Un_empty_left disjoint_def inf_sup_distrib2)\n\nlemma l2o: \"disjoint s1 s3 \\ disjoint s2 s3 \\ disjoint (s1 \\ s2) s3\"\napply (metis Int_commute Un_empty_left disjoint_def inf_sup_distrib1)\ndone\n\nlemma l3_1: \"nat1_map f \\ nat1_map(S -\\ f)\"\nby (metis Diff_iff f_in_dom_ar_apply_subsume l_dom_dom_ar nat1_map_def)\n\nlemma l3_2: \"l \\ dom (S -\\ f) \\ l \\ dom f\"\nunfolding dom_antirestr_def\nby (cases \"l\\S\", auto)\n\nlemma l3_3: \"l \\ dom (S -\\ f) \\ the ((S -\\ f) l) = the (f l)\"\nunfolding dom_antirestr_def\nby (cases \"l\\S\", auto)\n\nlemma l3: \"nat1_map f \\ locs(S -\\ f) \\ locs f\"\napply (rule subsetI)\nunfolding locs_def\napply (simp add: l3_1)\napply (erule bexE)\napply (frule l3_2)\napply (frule l3_3,simp)\napply (rule_tac x=s in bexI)\nsledgehammer\n\nlemma l4: \"nat1 n \\ nat1 m \\ locs_of d (n+m) = (locs_of d n) \\ (locs_of (d+n) m)\"\nunfolding locs_of_def\nby auto\n\n\\ \\ New lemmas (relatively trivial)\\\nlemma l5: \"nat1_map f \\ x \\ dom f \\ nat1 (the(f x))\"\nby (metis nat1_map_def)\n\nlemma l6: \"nat1 y \\ y < s \\ locs_of (d+s) y \\ locs_of d s\"\nunfolding locs_of_def\napply simp\napply (rule subsetI)\nfind_theorems \"_ \\ {_ . _}\"\napply (elim conjE CollectE)\napply (intro conjI CollectI)\napply (simp)\noops\n\nlemma l6_1: \"x \\ dom f \\ nat1_map f \\ x \\ locs_of x (the(f x))\"\nunfolding locs_of_def\napply (frule l5)\nby auto\n\nlemma l6: \"x \\ dom f \\ nat1_map f \\ x \\ locs f\"\nunfolding locs_def\nby (metis UN_iff l6_1) \n\\ \\ UNUSED, but discovered through the failure to prove l6 above, which led to change in l2v2 \\\n\nlemma l7v0: \"d \\ dom f \\ x \\ locs_of d s \\ nat1_map f \\ x \\ locs f\"\nunfolding locs_def\napply simp\noops\n\nlemma l7: \"d \\ dom f \\ x \\ locs_of d (the(f d)) \\ nat1_map f \\ x \\ locs f\"\nunfolding locs_def\nby (simp,rule bexI,simp_all)\n\n\\ \\ Going directly top bottom of proof - used wrong l2 lemma! \\\ntheorem try1: \"F1_inv f \\ nat1 s \\ d+s \\ dom f \\ disjoint (locs_of d s) (locs f) \\\n disjoint (locs_of d (s+ (the(f(d+s))))) (locs ({d+s} -\\ f))\"\n unfolding F1_inv_def\n apply (elim conjE)\napply (frule l3[of f \"{d+s}\"]) \\ \\ S4 : L3 \\\napply (frule l1[of \"locs_of d s\" \"locs f\" \"(locs ({d+s} -\\ f))\"],simp) \\ \\ S5 : L1(S4,h)\\\n\\ \\ step 6 is strange: it is already what you want to conclude, yet it comes from h? \\\n \\ \\ here S6 comes from Disjoint f \\\noops\n\n\\ \\ Going in the order of steps \\\ntheorem try2: \n \\ \\ h1 h2 h3 h4 \\\n \"F1_inv f \\ nat1 s \\ d+s \\ dom f \\ disjoint (locs_of d s) (locs f) \\\n disjoint (locs_of d (s+ (the(f(d+s))))) (locs ({d+s} -\\ f))\"\n unfolding F1_inv_def\n apply (elim conjE)\napply (frule l4[of s \"the(f(d+s))\" d]) \\ \\ S1 : L4(S2) \\\napply (rule l5,simp,simp) \\ \\ S2 : L5(h1[3],h3) \\\napply (erule ssubst) \\ \\ infer : subs(S1) ; Nothing about S6 \\\n thm l2[of \"locs_of d s\" \n \"locs_of (d+s) \n (s+(the(f(d+s))))\" \n \"locs ({d+s} -\\ f)\"]\napply (rule l2) \\ \\ S3 : L2(S5, S6) \\\ndefer\n thm l1[of \"locs_of d s\"\n \"locs f\"\n \"locs ({d+s} -\\ f)\"]\n l3[of f \"{d+s}\"]\n \napply (frule l3[of f \"{d+s}\"]) \\ \\ S4 : L3 \\\napply (frule l1[of \"locs_of d s\" \n \"locs f\" \n \"(locs ({d+s} -\\ f))\"],\n simp) \\ \\ S5 : L1(S4,h) \\\n\\ \\ To me the backward steps towards the goal are harder to follow? How about S6? Will try backward \\\noops\n\n\\ \\Just like try2 but going underneath disjoint definition\\\ntheorem try3: \n \\ \\ h1 h2 h3 h4 \\\n \"F1_inv f \\ nat1 s \\ d+s \\ dom f \\ disjoint (locs_of d s) (locs f) \\\n disjoint (locs_of d (s+ (the(f(d+s))))) (locs ({d+s} -\\ f))\"\n unfolding F1_inv_def\n apply (elim conjE)\napply (frule l4[of s \"the(f(d+s))\" d]) \\ \\ S1 : L4(S2) \\\napply (rule l5,simp,simp) \\ \\ S2 : L5(h1[3],h3) \\\napply (erule ssubst) \\ \\ infer : subs(S1) ; Nothing about S6 \\\napply (rule l2) \\ \\ S3 : L2(S5, S6) \\\ndefer\napply (rule l1[of _ \"locs f\" _],simp) \\ \\ S5 : L1(S4,h4) \\\napply (rule l3,simp) \\ \\ S4 : L3(h1[3]) \\\ndefer\n \\ \\ If I had a lemma (should create? no general enough?); \\\nunfolding disjoint_def\n apply (simp add: disjoint_iff_not_equal)\n apply (intro ballI)\n apply (erule_tac x=x in ballE,simp_all)\n apply (erule_tac x=y in ballE,simp)\n apply (erule notE)\n apply (rule l7[of \"d+s\" f _],simp_all)\n\n apply (fold disjoint_def)\n apply (unfold disjoint_def)\n apply (simp add: disjoint_iff_not_equal)\n apply (frule l6,simp)\n apply (intro ballI)\n apply (frule l3_1[of f \"{d+s}\"])\n unfolding locs_def\n apply simp\n apply (elim bexE)\n thm l3 l3_1 l3_2 l5\n apply (frule l3_2)\n apply (simp add: l3_3)\n apply (frule l5[of _ \"d+s\"],simp)\n apply (frule l5,simp) back\n apply (frule l5,simp) back back\n apply (erule ballE)+\n (*\n apply (erule_tac x=saa in ballE)\n apply (erule_tac x=y in ballE)\n *)\n apply simp \n prefer 3\n apply (erule notE)\n unfolding locs_of_def\n apply simp\n nitpick\noops\n\n\\ \\ Version shown to Cliff - in step order and using l2 new \\\ntheorem try4: \n \\ \\ h1 h2 h3 h4 \\\n \"F1_inv f \\ nat1 s \\ d+s \\ dom f \\ disjoint (locs_of d s) (locs f) \\\n disjoint (locs_of d (s+ (the(f(d+s))))) (locs ({d+s} -\\ f))\"\n unfolding F1_inv_def\n apply (elim conjE)\napply (frule l4[of s \"the(f(d+s))\" d]) \\ \\ S1 : L4(S2) \\\napply (rule l5,simp,simp) \\ \\ S2 : L5(h1[3],h3) \\\napply (erule ssubst) \\ \\ infer : subs(S1) ; Nothing about S6 \\\napply (rule l2) \\ \\ S3 : L2(S5, S6) \\\ndefer\napply (rule l1[of _ \"locs f\" _],simp) \\ \\ S5 : L1(S4,h4) \\\napply (rule l3,simp) \\ \\ S4 : L3(h1[3]) \\\ndefer\nunfolding disjoint_def\n apply (simp add: disjoint_iff_not_equal)\n apply (intro ballI)\n apply (erule_tac x=x in ballE,simp_all)\n apply (erule_tac x=y in ballE,simp)\n apply (erule notE)\n apply (rule l7[of \"d+s\" f _],simp_all)\noops\n\nlemma l3half_1: \"nat1_map f \\ (x \\ locs f) = (\\y \\ dom f . x \\ locs_of y (the(f y)))\"\nunfolding locs_def\nby (metis (mono_tags) UN_iff)\n\n\\ \\ Version shown to Cliff - in step order and using l2original + new lemma\\\nlemma l3half: \n\\ \\see lemma l_locs_dom_ar_iff:\\\n \"nat1_map f \\ Disjoint f \\ r \\ dom f \\ locs({r} -\\ f) = locs f - locs_of r (the(f r))\"\napply (rule equalityI)\napply (rule_tac [1-] subsetI)\napply (frule_tac [1-] l3_1[of _ \"{r}\"])\napply (simp_all add: l3half_1)\ndefer \napply (elim conjE)\ndefer \napply (intro conjI)\napply (metis f_in_dom_ar_subsume f_in_dom_ar_the_subsume)\napply (erule_tac [1-] bexE)\ndefer \napply (rule_tac x=y in bexI)\napply (metis f_in_dom_ar_apply_not_elem singleton_iff)\napply (metis l_dom_dom_ar member_remove remove_def)\napply (frule f_in_dom_ar_subsume)\napply (frule f_in_dom_ar_the_subsume)\nunfolding Disjoint_def disjoint_def Locs_of_def\napply (simp)\nby (metis disjoint_iff_not_equal f_in_dom_ar_notelem)\n\nthm f_in_dom_ar_subsume\n f_in_dom_ar_the_subsume\n f_in_dom_ar_notelem\n f_in_dom_ar_apply_not_elem\n l_dom_dom_ar\n\nlemma l8: \"disjoint A (B - A)\"\nunfolding disjoint_def\nby (metis Diff_disjoint)\n\n\\ \\ LATEST version from Cliff that avoids expanding locs def through lemmas (caveat: 3.5 is hard to prove \\\ntheorem try7: \n \\ \\ h1 h2 h3 h4 \\\n \"F1_inv f \\ nat1 s \\ d+s \\ dom f \\ disjoint (locs_of d s) (locs f) \\\n disjoint (locs_of d (s+ (the(f(d+s))))) (locs ({d+s} -\\ f))\"\n unfolding F1_inv_def\n apply (elim conjE)\napply (frule l4[of s \"the(f(d+s))\" d]) \\ \\ S1 : L4(S2) \\\napply (rule l5,simp,simp) \\ \\ S2 : L5(h1[3],h3) \\\napply (erule ssubst) \\ \\ infer : subs(S1) ; Nothing about S6 \\\napply (rule l2o) \\ \\ S3 : L2(S4, S6) \\\napply (metis (full_types) l1 l3)\nby (metis l3half l8)\n\n\\ \\ trial lemma extracted from the last part of the next try proofs (try5\/6 below)\\\nlemma trial: \"nat1_map f \\ Disjoint f \\ d+s \\ dom f \\ disjoint (locs_of (d + s) (the (f (d + s)))) (locs ({d+s} -\\ f))\"\nunfolding Disjoint_def Locs_of_def \n apply (erule_tac x=\"d+s\" in ballE) \\ \\ S6 : S8 \\\n apply (simp_all)\n unfolding disjoint_def\n apply (simp add: disjoint_iff_not_equal)\n apply (intro ballI)\n unfolding locs_def\n apply (frule l3_1[of _ \"{d+s}\"])\n apply simp\n apply (erule bexE)\n apply (frule l3_2)\n apply (frule f_in_dom_ar_notelem)\n apply (erule_tac x=sa in ballE,simp_all)\n apply (metis f_in_dom_ar_apply_subsume)\ndone\n\ntheorem try5: \n \\ \\ h1 h2 h3 h4 \\\n \"F1_inv f \\ nat1 s \\ d+s \\ dom f \\ disjoint (locs_of d s) (locs f) \\\n disjoint (locs_of d (s+ (the(f(d+s))))) (locs ({d+s} -\\ f))\"\n unfolding F1_inv_def\n apply (elim conjE)\napply (frule l4[of s \"the(f(d+s))\" d]) \\ \\ S1 : L4(S2) \\\napply (rule l5,simp,simp) \\ \\ S2 : L5(h1[3],h3) \\\napply (erule ssubst) \\ \\ infer : subs(S1) ; Nothing about S6 \\\napply (rule l2o) \\ \\ S3 : L2(S4, S6) \\\napply (rule l1[of _ \"locs f\" _],simp) \\ \\ S4 : L1(S5,h4) \\\napply (rule l3,simp) \\ \\ S5 : L3(h1[3]) \\\n\napply (frule l3half,simp,simp,simp) \\ \\ S8 : L3.5(h1[1]) \\\n(*\napply (rule l1[of _ \"locs f\"]) \\ \\ S8_1 : L1(h4) \\\n defer thm Diff_subset l3 \\ \\ either work \\\n apply (metis Diff_subset) \\ \\ S8_2 : L3 or set-thy \\\napply (rule trial,simp,simp,simp) \\ \\ S9 : ? S6 ? \\\n \\ \\ cannot loose anti-restriction \\\n*)\noops\n\ntheorem try6: \n \\ \\ h1 h2 h3 h4 \\\n \"F1_inv f \\ nat1 s \\ d+s \\ dom f \\ disjoint (locs_of d s) (locs f) \\\n disjoint (locs_of d (s+ (the(f(d+s))))) (locs ({d+s} -\\ f))\"\n unfolding F1_inv_def\n apply (elim conjE)\n thm l4[of s \"the(f(d+s))\" d] \n thm l5 \n thm l1[of _ \"locs f\" _]\n thm trial\napply (frule l4[of s \"the(f(d+s))\" d]) \\ \\ S1 : L4(S2) \\\napply (rule l5,simp,simp) \\ \\ S2 : L5(h1[3],h3) \\\napply (erule ssubst) \\ \\ infer : subs(S1) ; Nothing about S6 \\\napply (rule l2o) \\ \\ S3 : L2(S4, S6) \\\napply (rule l1[of _ \"locs f\" _],simp) \\ \\ S4 : L1(S5,h4) \\\napply (rule l3,simp) \\ \\ S5 : L3(h1[3]) \\\napply (rule trial,simp,simp,simp)\ndone\n\nend\n","avg_line_length":45.2083333333,"max_line_length":185,"alphanum_fraction":0.6148174406} {"size":33222,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"theory Lambda\nimports \n \"..\/Nominal2\"\n \"~~\/src\/HOL\/Library\/Monad_Syntax\"\nbegin\n\nlemma perm_commute: \n \"a \\ p \\ a' \\ p \\ (a \\ a') + p = p + (a \\ a')\"\napply(rule plus_perm_eq)\napply(simp add: supp_swap fresh_def)\ndone\n\natom_decl name\n\nthm obtain_atom\n\nlemma \n \"(\\thesis. (finite X \\ (\\a. ((a \\ X \\ sort_of a = s) \\ thesis)) \\ thesis)) \\\n (finite X \\ (\\ a. (a \\ X \\ sort_of a = s)))\"\napply(auto) \ndone\n\n\n\nML {* trace := true *}\n\nnominal_datatype lam =\n Var \"name\"\n| App \"lam\" \"lam\"\n| Lam x::\"name\" l::\"lam\" binds x in l (\"Lam [_]. _\" [100, 100] 100)\n\nnominal_datatype environment = \n Ni\n | En name closure environment\nand closure = \n Clos \"lam\" \"environment\"\n\nthm environment_closure.exhaust(1)\n\nnominal_function \n env_lookup :: \"environment => name => closure\"\nwhere\n \"env_lookup Ni x = Clos (Var x) Ni\"\n| \"env_lookup (En v clos rest) x = (if (v = x) then clos else env_lookup rest x)\"\n apply (auto)\n apply (simp add: env_lookup_graph_aux_def eqvt_def)\n by (metis environment_closure.strong_exhaust(1))\n\n\nlemma \n \"Lam [x]. Var x = Lam [y]. Var y\"\nproof -\n obtain c::name where fresh: \"atom c \\ (Lam [x]. Var x, Lam [y]. Var y)\"\n by (metis obtain_fresh)\n have \"Lam [x]. Var x = (c \\ x) \\ Lam [x]. Var x\"\n using fresh by (rule_tac flip_fresh_fresh[symmetric]) (simp_all add: fresh_Pair)\n also have \"... = Lam [c].Var c\" by simp\n also have \"... = (c \\ y) \\ Lam [c]. Var c\"\n using fresh by (rule_tac flip_fresh_fresh[symmetric]) (auto simp add: fresh_Pair)\n also have \"... = Lam [y]. Var y\" by simp\n finally show \"Lam [x]. Var x = Lam [y]. Var y\" .\nqed\n\ndefinition \n Name :: \"nat \\ name\" \nwhere \n \"Name n = Abs_name (Atom (Sort ''name'' []) n)\"\n\ndefinition\n \"Ident2 = Lam [Name 1].(Var (Name 1))\"\n\ndefinition \n \"Ident x = Lam [x].(Var x)\"\n\nlemma \"Ident2 = Ident x\"\nunfolding Ident_def Ident2_def\nby simp\n\nlemma \"Ident x = Ident y\"\nunfolding Ident_def\nby simp\n\nthm lam.strong_induct\n\nlemma alpha_lam_raw_eqvt[eqvt]: \"p \\ (alpha_lam_raw x y) = alpha_lam_raw (p \\ x) (p \\ y)\"\n unfolding alpha_lam_raw_def\n by perm_simp rule\n\nlemma abs_lam_eqvt[eqvt]: \"(p \\ abs_lam t) = abs_lam (p \\ t)\"\nproof -\n have \"alpha_lam_raw (rep_lam (abs_lam t)) t\"\n using rep_abs_rsp_left Quotient3_lam equivp_reflp lam_equivp by metis\n then have \"alpha_lam_raw (p \\ rep_lam (abs_lam t)) (p \\ t)\"\n unfolding alpha_lam_raw_eqvt[symmetric] permute_pure .\n then have \"abs_lam (p \\ rep_lam (abs_lam t)) = abs_lam (p \\ t)\"\n using Quotient3_rel Quotient3_lam by metis\n thus ?thesis using permute_lam_def id_apply map_fun_apply by metis\nqed\n\n\nsection {* Simple examples from Norrish 2004 *}\n\nnominal_function \n is_app :: \"lam \\ bool\"\nwhere\n \"is_app (Var x) = False\"\n| \"is_app (App t1 t2) = True\"\n| \"is_app (Lam [x]. t) = False\"\nthm is_app_graph_def is_app_graph_aux_def\napply(simp add: eqvt_def is_app_graph_aux_def)\napply(rule TrueI)\napply(rule_tac y=\"x\" in lam.exhaust)\napply(auto)[3]\napply(all_trivials)\ndone\n\nnominal_termination (eqvt) by lexicographic_order\n\nthm is_app_def\nthm is_app.eqvt\n\nthm eqvts\n\nnominal_function \n rator :: \"lam \\ lam option\"\nwhere\n \"rator (Var x) = None\"\n| \"rator (App t1 t2) = Some t1\"\n| \"rator (Lam [x]. t) = None\"\napply(simp add: eqvt_def rator_graph_aux_def)\napply(rule TrueI)\napply(rule_tac y=\"x\" in lam.exhaust)\napply(auto)[3]\napply(simp_all)\ndone\n\nnominal_termination (eqvt) by lexicographic_order\n\nnominal_function \n rand :: \"lam \\ lam option\"\nwhere\n \"rand (Var x) = None\"\n| \"rand (App t1 t2) = Some t2\"\n| \"rand (Lam [x]. t) = None\"\napply(simp add: eqvt_def rand_graph_aux_def)\napply(rule TrueI)\napply(rule_tac y=\"x\" in lam.exhaust)\napply(auto)[3]\napply(simp_all)\ndone\n\nnominal_termination (eqvt) by lexicographic_order\n\nnominal_function \n is_eta_nf :: \"lam \\ bool\"\nwhere\n \"is_eta_nf (Var x) = True\"\n| \"is_eta_nf (App t1 t2) = (is_eta_nf t1 \\ is_eta_nf t2)\"\n| \"is_eta_nf (Lam [x]. t) = (is_eta_nf t \\ \n ((is_app t \\ rand t = Some (Var x)) \\ atom x \\ supp (rator t)))\"\napply(simp add: eqvt_def is_eta_nf_graph_aux_def)\napply(rule TrueI)\napply(rule_tac y=\"x\" in lam.exhaust)\napply(auto)[3]\nusing [[simproc del: alpha_lst]]\napply(simp_all)\napply(erule_tac c=\"()\" in Abs_lst1_fcb2')\napply(simp_all add: pure_fresh fresh_star_def)[3]\napply(simp add: eqvt_at_def conj_eqvt)\napply(simp add: eqvt_at_def conj_eqvt)\ndone\n\nnominal_termination (eqvt) by lexicographic_order\n\nnominal_datatype path = Left | Right | In\n\nsection {* Paths to a free variables *} \n\ninstance path :: pure\napply(default)\napply(induct_tac \"x::path\" rule: path.induct)\napply(simp_all)\ndone\n\nnominal_function \n var_pos :: \"name \\ lam \\ (path list) set\"\nwhere\n \"var_pos y (Var x) = (if y = x then {[]} else {})\"\n| \"var_pos y (App t1 t2) = (Cons Left ` (var_pos y t1)) \\ (Cons Right ` (var_pos y t2))\"\n| \"atom x \\ y \\ var_pos y (Lam [x]. t) = (Cons In ` (var_pos y t))\"\napply(simp add: eqvt_def var_pos_graph_aux_def)\napply(rule TrueI)\napply(case_tac x)\napply(rule_tac y=\"b\" and c=\"a\" in lam.strong_exhaust)\napply(auto simp add: fresh_star_def)[3]\nusing [[simproc del: alpha_lst]]\napply(simp_all)\napply(erule conjE)+\napply(erule_tac Abs_lst1_fcb2)\napply(simp add: pure_fresh)\napply(simp add: fresh_star_def)\napply(simp only: eqvt_at_def)\napply(perm_simp)\napply(simp)\napply(simp add: perm_supp_eq)\napply(simp only: eqvt_at_def)\napply(perm_simp)\napply(simp)\napply(simp add: perm_supp_eq)\ndone\n\nnominal_termination (eqvt) by lexicographic_order\n\nlemma var_pos1:\n assumes \"atom y \\ supp t\"\n shows \"var_pos y t = {}\"\nusing assms\napply(induct t rule: var_pos.induct)\napply(simp_all add: lam.supp supp_at_base fresh_at_base)\ndone\n\nlemma var_pos2:\n shows \"var_pos y (Lam [y].t) = {}\"\napply(rule var_pos1)\napply(simp add: lam.supp)\ndone\n\n\ntext {* strange substitution operation *}\n\nnominal_function\n subst' :: \"lam \\ name \\ lam \\ lam\" (\"_ [_ ::== _]\" [90, 90, 90] 90)\nwhere\n \"(Var x)[y ::== s] = (if x = y then s else (Var x))\"\n| \"(App t1 t2)[y ::== s] = App (t1[y ::== s]) (t2[y ::== s])\"\n| \"atom x \\ (y, s) \\ (Lam [x]. t)[y ::== s] = Lam [x].(t[y ::== (App (Var y) s)])\"\n apply(simp add: eqvt_def subst'_graph_aux_def)\n apply(rule TrueI)\n apply(case_tac x)\n apply(rule_tac y=\"a\" and c=\"(b, c)\" in lam.strong_exhaust)\n apply(auto simp add: fresh_star_def)[3]\n using [[simproc del: alpha_lst]]\n apply(simp_all)\n apply(erule conjE)+\n apply (erule_tac c=\"(ya,sa)\" in Abs_lst1_fcb2)\n apply(simp_all add: Abs_fresh_iff)\n apply(simp add: fresh_star_def fresh_Pair)\n apply(simp only: eqvt_at_def)\n apply(perm_simp)\n apply(simp)\n apply(simp add: fresh_star_Pair perm_supp_eq)\n apply(simp only: eqvt_at_def)\n apply(perm_simp)\n apply(simp)\n apply(simp add: fresh_star_Pair perm_supp_eq)\ndone\n\nnominal_termination (eqvt) by lexicographic_order\n\n\nsection {* free name function *}\n\n\nlemma fresh_removeAll_name:\n fixes x::\"name\"\n and xs:: \"name list\"\n shows \"atom x \\ (removeAll y xs) \\ (atom x \\ xs \\ x = y)\"\n apply (induct xs)\n apply(auto simp add: fresh_def supp_Nil supp_Cons supp_at_base)\n done\n\n\ntext {* first returns an atom list *}\n\nnominal_function \n frees_lst :: \"lam \\ atom list\"\nwhere\n \"frees_lst (Var x) = [atom x]\"\n| \"frees_lst (App t1 t2) = frees_lst t1 @ frees_lst t2\"\n| \"frees_lst (Lam [x]. t) = removeAll (atom x) (frees_lst t)\"\napply(simp add: eqvt_def frees_lst_graph_aux_def)\napply(rule TrueI)\napply(rule_tac y=\"x\" in lam.exhaust)\nusing [[simproc del: alpha_lst]]\napply(auto)\napply (erule_tac c=\"()\" in Abs_lst1_fcb2)\napply(simp add: supp_removeAll fresh_def)\napply(simp add: fresh_star_def fresh_Unit)\napply(simp add: eqvt_at_def removeAll_eqvt atom_eqvt)\napply(simp add: eqvt_at_def removeAll_eqvt atom_eqvt)\ndone\n\nnominal_termination (eqvt) by lexicographic_order\n\ntext {* a small test lemma *}\nlemma shows \"supp t = set (frees_lst t)\"\n by (induct t rule: frees_lst.induct) (simp_all add: lam.supp supp_at_base)\n\ntext {* second returns an atom set - therefore needs an invariant *}\n\nnominal_function (invariant \"\\x (y::atom set). finite y\")\n frees_set :: \"lam \\ atom set\"\nwhere\n \"frees_set (Var x) = {atom x}\"\n| \"frees_set (App t1 t2) = frees_set t1 \\ frees_set t2\"\n| \"frees_set (Lam [x]. t) = (frees_set t) - {atom x}\"\n apply(simp add: eqvt_def frees_set_graph_aux_def)\n apply(erule frees_set_graph.induct)\n apply(auto)[9]\n apply(rule_tac y=\"x\" in lam.exhaust)\n apply(auto)[3]\n using [[simproc del: alpha_lst]]\n apply(simp)\n apply(erule_tac c=\"()\" in Abs_lst1_fcb2)\n apply(simp add: fresh_minus_atom_set)\n apply(simp add: fresh_star_def fresh_Unit)\n apply(simp add: Diff_eqvt eqvt_at_def)\n apply(simp add: Diff_eqvt eqvt_at_def)\n done\n\nnominal_termination (eqvt) \n by lexicographic_order\n\nlemma \"frees_set t = supp t\"\n by (induct rule: frees_set.induct) (simp_all add: lam.supp supp_at_base)\n\nsection {* height function *}\n\nnominal_function\n height :: \"lam \\ int\"\nwhere\n \"height (Var x) = 1\"\n| \"height (App t1 t2) = max (height t1) (height t2) + 1\"\n| \"height (Lam [x].t) = height t + 1\"\n apply(simp add: eqvt_def height_graph_aux_def)\n apply(rule TrueI)\n apply(rule_tac y=\"x\" in lam.exhaust)\n using [[simproc del: alpha_lst]]\n apply(auto)\n apply (erule_tac c=\"()\" in Abs_lst1_fcb2)\n apply(simp_all add: fresh_def pure_supp eqvt_at_def fresh_star_def)\n done\n\nnominal_termination (eqvt)\n by lexicographic_order\n \nthm height.simps\n\n \nsection {* capture-avoiding substitution *}\n\nnominal_function\n subst :: \"lam \\ name \\ lam \\ lam\" (\"_ [_ ::= _]\" [90, 90, 90] 90)\nwhere\n \"(Var x)[y ::= s] = (if x = y then s else (Var x))\"\n| \"(App t1 t2)[y ::= s] = App (t1[y ::= s]) (t2[y ::= s])\"\n| \"atom x \\ (y, s) \\ (Lam [x]. t)[y ::= s] = Lam [x].(t[y ::= s])\"\n apply(simp add: eqvt_def subst_graph_aux_def)\n apply(rule TrueI)\n using [[simproc del: alpha_lst]]\n apply(auto)\n apply(rule_tac y=\"a\" and c=\"(aa, b)\" in lam.strong_exhaust)\n apply(blast)+\n using [[simproc del: alpha_lst]]\n apply(simp_all add: fresh_star_def fresh_Pair_elim)\n apply (erule_tac c=\"(ya,sa)\" in Abs_lst1_fcb2)\n apply(simp_all add: Abs_fresh_iff)\n apply(simp add: fresh_star_def fresh_Pair)\n apply(simp only: eqvt_at_def)\n apply(perm_simp)\n apply(simp)\n apply(simp add: fresh_star_Pair perm_supp_eq)\n apply(simp only: eqvt_at_def)\n apply(perm_simp)\n apply(simp)\n apply(simp add: fresh_star_Pair perm_supp_eq)\ndone\n\nnominal_termination (eqvt)\n by lexicographic_order\n\nthm subst.eqvt\n\nlemma forget:\n shows \"atom x \\ t \\ t[x ::= s] = t\"\n by (nominal_induct t avoiding: x s rule: lam.strong_induct)\n (auto simp add: fresh_at_base)\n\ntext {* same lemma but with subst.induction *}\nlemma forget2:\n shows \"atom x \\ t \\ t[x ::= s] = t\"\n apply(induct t x s rule: subst.induct)\n using [[simproc del: alpha_lst]]\n apply(auto simp add: flip_fresh_fresh fresh_Pair fresh_at_base)\n done\n\nlemma fresh_fact:\n fixes z::\"name\"\n assumes a: \"atom z \\ s\"\n and b: \"z = y \\ atom z \\ t\"\n shows \"atom z \\ t[y ::= s]\"\n using a b\n by (nominal_induct t avoiding: z y s rule: lam.strong_induct)\n (auto simp add: fresh_at_base)\n\nlemma substitution_lemma: \n assumes a: \"x \\ y\" \"atom x \\ u\"\n shows \"t[x ::= s][y ::= u] = t[y ::= u][x ::= s[y ::= u]]\"\nusing a \nby (nominal_induct t avoiding: x y s u rule: lam.strong_induct)\n (auto simp add: fresh_fact forget)\n\nlemma subst_rename: \n assumes a: \"atom y \\ t\"\n shows \"t[x ::= s] = ((y \\ x) \\t)[y ::= s]\"\nusing a \napply (nominal_induct t avoiding: x y s rule: lam.strong_induct)\napply (auto simp add: fresh_at_base)\ndone\n\nlemma height_ge_one:\n shows \"1 \\ (height e)\"\nby (induct e rule: lam.induct) (simp_all)\n\ntheorem height_subst:\n shows \"height (e[x::=e']) \\ ((height e) - 1) + (height e')\"\nproof (nominal_induct e avoiding: x e' rule: lam.strong_induct)\n case (Var y)\n have \"1 \\ height e'\" by (rule height_ge_one)\n then show \"height (Var y[x::=e']) \\ height (Var y) - 1 + height e'\" by simp\nnext\n case (Lam y e1)\n hence ih: \"height (e1[x::=e']) \\ ((height e1) - 1) + (height e')\" by simp\n moreover\n have vc: \"atom y\\x\" \"atom y\\e'\" by fact+ (* usual variable convention *)\n ultimately show \"height ((Lam [y]. e1)[x::=e']) \\ height (Lam [y]. e1) - 1 + height e'\" by simp\nnext\n case (App e1 e2)\n hence ih1: \"height (e1[x::=e']) \\ ((height e1) - 1) + (height e')\"\n and ih2: \"height (e2[x::=e']) \\ ((height e2) - 1) + (height e')\" by simp_all\n then show \"height ((App e1 e2)[x::=e']) \\ height (App e1 e2) - 1 + height e'\" by simp\nqed\n\nsubsection {* single-step beta-reduction *}\n\ninductive \n beta :: \"lam \\ lam \\ bool\" (\" _ \\b _\" [80,80] 80)\nwhere\n b1[intro]: \"t1 \\b t2 \\ App t1 s \\b App t2 s\"\n| b2[intro]: \"s1 \\b s2 \\ App t s1 \\b App t s2\"\n| b3[intro]: \"t1 \\b t2 \\ Lam [x]. t1 \\b Lam [x]. t2\"\n| b4[intro]: \"atom x \\ s \\ App (Lam [x]. t) s \\b t[x ::= s]\"\n\nequivariance beta\n\nnominal_inductive beta\n avoids b4: \"x\"\n by (simp_all add: fresh_star_def fresh_Pair fresh_fact)\n\nthm beta.strong_induct\n\ntext {* One-Reduction *}\n\ninductive \n One :: \"lam \\ lam \\ bool\" (\" _ \\1 _\" [80,80] 80)\nwhere\n o1[intro]: \"Var x \\1 Var x\"\n| o2[intro]: \"\\t1 \\1 t2; s1 \\1 s2\\ \\ App t1 s1 \\1 App t2 s2\"\n| o3[intro]: \"t1 \\1 t2 \\ Lam [x].t1 \\1 Lam [x].t2\"\n| o4[intro]: \"\\atom x \\ (s1, s2); t1 \\1 t2; s1 \\1 s2\\ \\ App (Lam [x].t1) s1 \\1 t2[x ::= s2]\"\n\nequivariance One\n\nnominal_inductive One \n avoids o3: \"x\"\n | o4: \"x\"\n by (simp_all add: fresh_star_def fresh_Pair fresh_fact)\n\nlemma One_refl:\n shows \"t \\1 t\"\nby (nominal_induct t rule: lam.strong_induct) (auto)\n\nlemma One_subst: \n assumes a: \"t1 \\1 t2\" \"s1 \\1 s2\"\n shows \"t1[x ::= s1] \\1 t2[x ::= s2]\" \nusing a \napply(nominal_induct t1 t2 avoiding: s1 s2 x rule: One.strong_induct)\napply(auto simp add: substitution_lemma fresh_at_base fresh_fact fresh_Pair)\ndone\n\nlemma better_o4_intro:\n assumes a: \"t1 \\1 t2\" \"s1 \\1 s2\"\n shows \"App (Lam [x]. t1) s1 \\1 t2[ x ::= s2]\"\nproof -\n obtain y::\"name\" where fs: \"atom y \\ (x, t1, s1, t2, s2)\" by (rule obtain_fresh)\n have \"App (Lam [x]. t1) s1 = App (Lam [y]. ((y \\ x) \\ t1)) s1\" using fs\n by (auto simp add: Abs1_eq_iff' flip_def fresh_Pair fresh_at_base)\n also have \"\\ \\1 ((y \\ x) \\ t2)[y ::= s2]\" using fs a by (auto simp add: One.eqvt)\n also have \"\\ = t2[x ::= s2]\" using fs by (simp add: subst_rename[symmetric])\n finally show \"App (Lam [x].t1) s1 \\1 t2[x ::= s2]\" by simp\nqed\n\nsection {* Locally Nameless Terms *}\n\nnominal_datatype ln = \n LNBnd nat\n| LNVar name\n| LNApp ln ln\n| LNLam ln\n\nfun\n lookup :: \"name list \\ nat \\ name \\ ln\" \nwhere\n \"lookup [] n x = LNVar x\"\n| \"lookup (y # ys) n x = (if x = y then LNBnd n else (lookup ys (n + 1) x))\"\n\nlemma supp_lookup:\n shows \"supp (lookup xs n x) \\ {atom x}\"\n apply(induct arbitrary: n rule: lookup.induct)\n apply(simp add: ln.supp supp_at_base)\n apply(simp add: ln.supp pure_supp)\n done\n\nlemma supp_lookup_in:\n shows \"x \\ set xs \\ supp (lookup xs n x) = {}\"\n by (induct arbitrary: n rule: lookup.induct)(auto simp add: ln.supp pure_supp)\n\nlemma supp_lookup_notin:\n shows \"x \\ set xs \\ supp (lookup xs n x) = {atom x}\"\n by (induct arbitrary: n rule: lookup.induct) (auto simp add: ln.supp pure_supp supp_at_base)\n\nlemma supp_lookup_fresh:\n shows \"atom ` set xs \\* lookup xs n x\"\n by (case_tac \"x \\ set xs\") (auto simp add: fresh_star_def fresh_def supp_lookup_in supp_lookup_notin)\n\nlemma lookup_eqvt[eqvt]:\n shows \"(p \\ lookup xs n x) = lookup (p \\ xs) (p \\ n) (p \\ x)\"\n by (induct xs arbitrary: n) (simp_all add: permute_pure)\n\ntext {* Function that translates lambda-terms into locally nameless terms *}\n\nnominal_function (invariant \"\\(_, xs) y. atom ` set xs \\* y\")\n trans :: \"lam \\ name list \\ ln\"\nwhere\n \"trans (Var x) xs = lookup xs 0 x\"\n| \"trans (App t1 t2) xs = LNApp (trans t1 xs) (trans t2 xs)\"\n| \"atom x \\ xs \\ trans (Lam [x]. t) xs = LNLam (trans t (x # xs))\"\n apply (simp add: eqvt_def trans_graph_aux_def)\n apply (erule trans_graph.induct)\n apply (auto simp add: ln.fresh)[3]\n apply (simp add: supp_lookup_fresh)\n apply (simp add: fresh_star_def ln.fresh)\n apply (simp add: ln.fresh fresh_star_def)\n apply(auto)[1]\n apply (rule_tac y=\"a\" and c=\"b\" in lam.strong_exhaust)\n apply (auto simp add: fresh_star_def)[3]\n using [[simproc del: alpha_lst]]\n apply(simp_all)\n apply(erule conjE)+\n apply (erule_tac c=\"xsa\" in Abs_lst1_fcb2')\n apply (simp add: fresh_star_def)\n apply (simp add: fresh_star_def)\n apply(simp only: eqvt_at_def)\n apply(perm_simp)\n apply(simp add: fresh_star_Pair perm_supp_eq)\n apply(simp only: eqvt_at_def)\n apply(perm_simp)\n apply(simp add: fresh_star_Pair perm_supp_eq)\n done\n\nnominal_termination (eqvt)\n by lexicographic_order\n\n\ntext {* count the occurences of lambdas in a term *}\n\nnominal_function\n cntlams :: \"lam \\ nat\"\nwhere\n \"cntlams (Var x) = 0\"\n| \"cntlams (App t1 t2) = (cntlams t1) + (cntlams t2)\"\n| \"cntlams (Lam [x]. t) = Suc (cntlams t)\"\n apply(simp add: eqvt_def cntlams_graph_aux_def)\n apply(rule TrueI)\n apply(rule_tac y=\"x\" in lam.exhaust)\n apply(auto)[3]\n apply(all_trivials)\n apply(simp)\n using [[simproc del: alpha_lst]]\n apply(simp)\n apply(erule_tac c=\"()\" in Abs_lst1_fcb2')\n apply(simp add: pure_fresh)\n apply(simp add: fresh_star_def pure_fresh)\n apply(simp add: eqvt_at_def atom_eqvt fresh_star_Pair perm_supp_eq)\n apply(simp add: eqvt_at_def atom_eqvt fresh_star_Pair perm_supp_eq)\n done\n\nnominal_termination (eqvt)\n by lexicographic_order\n\n\ntext {* count the bound-variable occurences in a lambda-term *}\n\nnominal_function\n cntbvs :: \"lam \\ name list \\ nat\"\nwhere\n \"cntbvs (Var x) xs = (if x \\ set xs then 1 else 0)\"\n| \"cntbvs (App t1 t2) xs = (cntbvs t1 xs) + (cntbvs t2 xs)\"\n| \"atom x \\ xs \\ cntbvs (Lam [x]. t) xs = cntbvs t (x # xs)\"\n apply(simp add: eqvt_def cntbvs_graph_aux_def)\n apply(rule TrueI)\n apply(case_tac x)\n apply(rule_tac y=\"a\" and c=\"b\" in lam.strong_exhaust)\n apply(auto simp add: fresh_star_def)[3]\n apply(all_trivials)\n apply(simp)\n apply(simp)\n using [[simproc del: alpha_lst]]\n apply(simp)\n apply(erule conjE)\n apply(erule Abs_lst1_fcb2')\n apply(simp add: pure_fresh fresh_star_def)\n apply(simp add: fresh_star_def)\n apply(simp only: eqvt_at_def)\n apply(perm_simp)\n apply(simp add: fresh_star_Pair perm_supp_eq)\n apply(simp only: eqvt_at_def)\n apply(perm_simp)\n apply(simp add: fresh_star_Pair perm_supp_eq)\n done\n\nnominal_termination (eqvt)\n by lexicographic_order\n\nsection {* De Bruijn Terms *}\n\nnominal_datatype db = \n DBVar nat\n| DBApp db db\n| DBLam db\n\ninstance db :: pure\n apply default\n apply (induct_tac x rule: db.induct)\n apply (simp_all add: permute_pure)\n done\n\nlemma fresh_at_list: \"atom x \\ xs \\ x \\ set xs\"\n unfolding fresh_def supp_set[symmetric]\n by (induct xs) (auto simp add: supp_of_finite_insert supp_at_base supp_set_empty)\n\nfun\n vindex :: \"name list \\ name \\ nat \\ db option\" \nwhere\n \"vindex [] v n = None\"\n| \"vindex (h # t) v n = (if v = h then (Some (DBVar n)) else (vindex t v (Suc n)))\"\n\nlemma vindex_eqvt[eqvt]:\n \"(p \\ vindex l v n) = vindex (p \\ l) (p \\ v) (p \\ n)\"\n by (induct l arbitrary: n) (simp_all add: permute_pure)\n\nnominal_function\n transdb :: \"lam \\ name list \\ db option\"\nwhere\n \"transdb (Var x) l = vindex l x 0\"\n| \"transdb (App t1 t2) xs = \n Option.bind (transdb t1 xs) (\\d1. Option.bind (transdb t2 xs) (\\d2. Some (DBApp d1 d2)))\"\n| \"x \\ set xs \\ transdb (Lam [x].t) xs = Option.map_option DBLam (transdb t (x # xs))\"\n apply(simp add: eqvt_def transdb_graph_aux_def)\n apply(rule TrueI)\n apply (case_tac x)\n apply (rule_tac y=\"a\" and c=\"b\" in lam.strong_exhaust)\n apply (auto simp add: fresh_star_def fresh_at_list)[3]\n using [[simproc del: alpha_lst]]\n apply(simp_all)\n apply(elim conjE)\n apply (erule_tac c=\"xsa\" in Abs_lst1_fcb2')\n apply (simp add: pure_fresh)\n apply(simp add: fresh_star_def fresh_at_list)\n apply(simp only: eqvt_at_def)\n apply(perm_simp)\n apply(simp)\n apply(simp add: fresh_star_Pair perm_supp_eq)\n apply(simp only: eqvt_at_def)\n apply(perm_simp)\n apply(simp)\n apply(simp add: fresh_star_Pair perm_supp_eq)\n done\n\nnominal_termination (eqvt)\n by lexicographic_order\n\nlemma transdb_eqvt[eqvt]:\n \"p \\ transdb t l = transdb (p \\t) (p \\l)\"\n apply (nominal_induct t avoiding: l rule: lam.strong_induct)\n apply (simp add: vindex_eqvt)\n apply (simp_all add: permute_pure)\n apply (simp add: fresh_at_list)\n apply (subst transdb.simps)\n apply (simp add: fresh_at_list[symmetric])\n apply (drule_tac x=\"name # l\" in meta_spec)\n apply auto\n done\n\nlemma db_trans_test:\n assumes a: \"y \\ x\"\n shows \"transdb (Lam [x]. Lam [y]. App (Var x) (Var y)) [] = \n Some (DBLam (DBLam (DBApp (DBVar 1) (DBVar 0))))\"\n using a by simp\n\nlemma supp_subst:\n shows \"supp (t[x ::= s]) \\ (supp t - {atom x}) \\ supp s\"\n by (induct t x s rule: subst.induct) (auto simp add: lam.supp supp_at_base)\n\nlemma var_fresh_subst:\n \"atom x \\ s \\ atom x \\ (t[x ::= s])\"\n by (induct t x s rule: subst.induct) (auto simp add: lam.supp fresh_at_base)\n\n(* function that evaluates a lambda term *)\nnominal_function\n eval :: \"lam \\ lam\" and\n apply_subst :: \"lam \\ lam \\ lam\"\nwhere\n \"eval (Var x) = Var x\"\n| \"eval (Lam [x].t) = Lam [x].(eval t)\"\n| \"eval (App t1 t2) = apply_subst (eval t1) (eval t2)\"\n| \"apply_subst (Var x) t2 = App (Var x) t2\"\n| \"apply_subst (App t0 t1) t2 = App (App t0 t1) t2\"\n| \"atom x \\ t2 \\ apply_subst (Lam [x].t1) t2 = eval (t1[x::= t2])\"\n apply(simp add: eval_apply_subst_graph_aux_def eqvt_def)\n apply(rule TrueI)\n apply (case_tac x)\n apply (case_tac a rule: lam.exhaust)\n using [[simproc del: alpha_lst]]\n apply simp_all[3]\n apply (case_tac b)\n apply (rule_tac y=\"a\" and c=\"ba\" in lam.strong_exhaust)\n apply simp_all[3]\n apply (simp add: Abs1_eq_iff fresh_star_def)\n using [[simproc del: alpha_lst]]\n apply(simp_all)\n apply(erule_tac c=\"()\" in Abs_lst1_fcb2)\n apply (simp add: Abs_fresh_iff)\n apply(simp add: fresh_star_def fresh_Unit)\n apply(simp add: eqvt_at_def atom_eqvt fresh_star_Pair perm_supp_eq)\n apply(simp add: eqvt_at_def atom_eqvt fresh_star_Pair perm_supp_eq)\n apply(erule conjE)\n apply(erule_tac c=\"t2a\" in Abs_lst1_fcb2')\n apply (erule fresh_eqvt_at)\n apply (simp add: finite_supp)\n apply (simp add: fresh_Inl var_fresh_subst)\n apply(simp add: fresh_star_def)\n apply(simp only: eqvt_at_def)\n apply(perm_simp)\n apply(simp add: fresh_star_Pair perm_supp_eq)\n apply(simp only: eqvt_at_def)\n apply(perm_simp)\n apply(simp add: fresh_star_Pair perm_supp_eq)\ndone\n\n\n(* a small test\nnominal_termination (eqvt) sorry\n\nlemma \n assumes \"x \\ y\"\n shows \"eval (App (Lam [x].App (Var x) (Var x)) (Var y)) = App (Var y) (Var y)\"\nusing assms\napply(simp add: lam.supp fresh_def supp_at_base)\ndone\n*)\n\n\ntext {* TODO: eqvt_at for the other side *}\nnominal_function q where\n \"atom c \\ (x, M) \\ q (Lam [x]. M) (N :: lam) = Lam [x]. (Lam [c]. (App M (q (Var c) N)))\"\n| \"q (Var x) N = Var x\"\n| \"q (App l r) N = App l r\"\napply(simp add: eqvt_def q_graph_aux_def)\napply (rule TrueI)\napply (case_tac x)\napply (rule_tac y=\"a\" in lam.exhaust)\nusing [[simproc del: alpha_lst]]\napply simp_all\napply (rule_tac x=\"(name, lam)\" and ?'a=\"name\" in obtain_fresh)\napply blast\napply clarify\napply (rule_tac x=\"(x, xa, M, Ma, c, ca, Na)\" and ?'a=\"name\" in obtain_fresh)\napply (subgoal_tac \"eqvt_at q_sumC (Var ca, Na)\") --\"Could come from nominal_function?\"\napply (subgoal_tac \"Lam [c]. App M (q_sumC (Var c, Na)) = Lam [a]. App M (q_sumC (Var a, Na))\")\napply (subgoal_tac \"Lam [ca]. App Ma (q_sumC (Var ca, Na)) = Lam [a]. App Ma (q_sumC (Var a, Na))\")\napply (simp only:)\napply (erule Abs_lst1_fcb)\noops\n\ntext {* Working Examples *}\n\nnominal_function\n map_term :: \"(lam \\ lam) \\ lam \\ lam\"\nwhere\n \"eqvt f \\ map_term f (Var x) = f (Var x)\"\n| \"eqvt f \\ map_term f (App t1 t2) = App (f t1) (f t2)\"\n| \"eqvt f \\ map_term f (Lam [x].t) = Lam [x].(f t)\"\n| \"\\eqvt f \\ map_term f t = t\"\n apply (simp add: eqvt_def map_term_graph_aux_def)\n apply(rule TrueI)\n apply (case_tac x, case_tac \"eqvt a\", case_tac b rule: lam.exhaust)\n using [[simproc del: alpha_lst]]\n apply auto\n apply (erule Abs_lst1_fcb)\n apply (simp_all add: Abs_fresh_iff fresh_fun_eqvt_app)\n apply (simp add: eqvt_def permute_fun_app_eq)\n done\n\nnominal_termination (eqvt)\n by lexicographic_order\n\n\n(*\nabbreviation\n mbind :: \"'a option => ('a => 'b option) => 'b option\" (\"_ \\= _\" [65,65] 65) \nwhere \n \"c \\= f \\ case c of None => None | (Some v) => f v\"\n\nlemma mbind_eqvt:\n fixes c::\"'a::pt option\"\n shows \"(p \\ (c \\= f)) = ((p \\ c) \\= (p \\ f))\"\napply(cases c)\napply(simp_all)\napply(perm_simp)\napply(rule refl)\ndone\n\nlemma mbind_eqvt_raw[eqvt_raw]:\n shows \"(p \\ option_case) \\ option_case\"\napply(rule eq_reflection)\napply(rule ext)+\napply(case_tac xb)\napply(simp_all)\napply(rule_tac p=\"-p\" in permute_boolE)\napply(perm_simp add: permute_minus_cancel)\napply(simp)\napply(rule_tac p=\"-p\" in permute_boolE)\napply(perm_simp add: permute_minus_cancel)\napply(simp)\ndone\n\nfun\n index :: \"atom list \\ nat \\ atom \\ nat option\" \nwhere\n \"index [] n x = None\"\n| \"index (y # ys) n x = (if x = y then (Some n) else (index ys (n + 1) x))\"\n\nlemma [eqvt]:\n shows \"(p \\ index xs n x) = index (p \\ xs) (p \\ n) (p \\ x)\"\napply(induct xs arbitrary: n)\napply(simp_all add: permute_pure)\ndone\n*)\n\n(*\nnominal_function\n trans2 :: \"lam \\ atom list \\ db option\"\nwhere\n \"trans2 (Var x) xs = (index xs 0 (atom x) \\= (\\n::nat. Some (DBVar n)))\"\n| \"trans2 (App t1 t2) xs = \n ((trans2 t1 xs) \\= (\\db1::db. (trans2 t2 xs) \\= (\\db2::db. Some (DBApp db1 db2))))\"\n| \"trans2 (Lam [x].t) xs = (trans2 t (atom x # xs) \\= (\\db::db. Some (DBLam db)))\"\noops\n*)\n\nnominal_function\n CPS :: \"lam \\ (lam \\ lam) \\ lam\"\nwhere\n \"CPS (Var x) k = Var x\"\n| \"CPS (App M N) k = CPS M (\\m. CPS N (\\n. n))\"\noops\n\nconsts b :: name\nnominal_function\n Z :: \"lam \\ (lam \\ lam) \\ lam\"\nwhere\n \"Z (App M N) k = Z M (%m. (Z N (%n.(App m n))))\"\n| \"Z (App M N) k = Z M (%m. (Z N (%n.(App (App m n) (Abs b (k (Var b)))))))\"\napply(simp add: eqvt_def Z_graph_aux_def)\napply (rule, perm_simp, rule)\noops\n\nlemma test:\n assumes \"t = s\"\n and \"supp p \\* t\" \"supp p \\* x\"\n and \"(p \\ t) = s \\ (p \\ x) = y\"\n shows \"x = y\"\nusing assms by (simp add: perm_supp_eq)\n\nlemma test2:\n assumes \"cs \\ as \\ bs\"\n and \"as \\* x\" \"bs \\* x\"\n shows \"cs \\* x\"\nusing assms\nby (auto simp add: fresh_star_def) \n\nlemma test3:\n assumes \"cs \\ as\"\n and \"as \\* x\"\n shows \"cs \\* x\"\nusing assms\nby (auto simp add: fresh_star_def) \n\n\n\nnominal_function (invariant \"\\(_, _, xs) y. atom ` fst ` set xs \\* y \\ atom ` snd ` set xs \\* y\")\n aux :: \"lam \\ lam \\ (name \\ name) list \\ bool\"\nwhere\n \"aux (Var x) (Var y) xs = ((x, y) \\ set xs)\"\n| \"aux (App t1 t2) (App s1 s2) xs = (aux t1 s1 xs \\ aux t2 s2 xs)\"\n| \"aux (Var x) (App t1 t2) xs = False\"\n| \"aux (Var x) (Lam [y].t) xs = False\"\n| \"aux (App t1 t2) (Var x) xs = False\"\n| \"aux (App t1 t2) (Lam [x].t) xs = False\"\n| \"aux (Lam [x].t) (Var y) xs = False\"\n| \"aux (Lam [x].t) (App t1 t2) xs = False\"\n| \"\\{atom x} \\* (s, xs); {atom y} \\* (t, xs); x \\ y\\ \\ \n aux (Lam [x].t) (Lam [y].s) xs = aux t s ((x, y) # xs)\"\n apply (simp add: eqvt_def aux_graph_aux_def)\n apply(erule aux_graph.induct)\n apply(simp_all add: fresh_star_def pure_fresh)[9]\n apply(case_tac x)\n apply(simp)\n apply(rule_tac y=\"a\" and c=\"(b, c)\" in lam.strong_exhaust)\n apply(simp)\n apply(rule_tac y=\"b\" and c=\"c\" in lam.strong_exhaust)\n apply(metis)+\n apply(simp)\n apply(rule_tac y=\"b\" and c=\"c\" in lam.strong_exhaust)\n apply(metis)+\n apply(simp)\n apply(rule_tac y=\"b\" and c=\"(lam, c, name)\" in lam.strong_exhaust)\n apply(metis)+\n apply(simp)\n apply(drule_tac x=\"name\" in meta_spec)\n apply(drule_tac x=\"lama\" in meta_spec)\n apply(drule_tac x=\"c\" in meta_spec)\n apply(drule_tac x=\"namea\" in meta_spec)\n apply(drule_tac x=\"lam\" in meta_spec)\n apply(simp add: fresh_star_Pair)\n apply(simp add: fresh_star_def fresh_at_base )\n apply(auto)[1]\n apply(simp_all)[44]\n apply(simp del: Product_Type.prod.inject) \n oops\n\nlemma abs_same_binder:\n fixes t ta s sa :: \"_ :: fs\"\n and x y::\"'a::at\"\n shows \"[[atom x]]lst. t = [[atom y]]lst. ta \\ [[atom x]]lst. s = [[atom y]]lst. sa\n \\ [[atom x]]lst. (t, s) = [[atom y]]lst. (ta, sa)\"\n by (cases \"atom x = atom y\") (auto simp add: Abs1_eq_iff assms fresh_Pair)\n\nnominal_function\n aux2 :: \"lam \\ lam \\ bool\"\nwhere\n \"aux2 (Var x) (Var y) = (x = y)\"\n| \"aux2 (App t1 t2) (App s1 s2) = (aux2 t1 s1 \\ aux2 t2 s2)\"\n| \"aux2 (Var x) (App t1 t2) = False\"\n| \"aux2 (Var x) (Lam [y].t) = False\"\n| \"aux2 (App t1 t2) (Var x) = False\"\n| \"aux2 (App t1 t2) (Lam [x].t) = False\"\n| \"aux2 (Lam [x].t) (Var y) = False\"\n| \"aux2 (Lam [x].t) (App t1 t2) = False\"\n| \"x = y \\ aux2 (Lam [x].t) (Lam [y].s) = aux2 t s\"\n apply(simp add: eqvt_def aux2_graph_aux_def)\n apply(rule TrueI)\n apply(case_tac x)\n apply(rule_tac y=\"a\" and c=\"b\" in lam.strong_exhaust)\n apply(rule_tac y=\"b\" in lam.exhaust)\n apply(auto)[3]\n apply(rule_tac y=\"b\" in lam.exhaust)\n apply(auto)[3]\n apply(rule_tac y=\"b\" and c=\"(name, lam)\" in lam.strong_exhaust)\n using [[simproc del: alpha_lst]]\n apply(auto)[3]\n apply(drule_tac x=\"name\" in meta_spec)\n apply(drule_tac x=\"name\" in meta_spec)\n apply(drule_tac x=\"lam\" in meta_spec)\n apply(drule_tac x=\"(name \\ namea) \\ lama\" in meta_spec)\n using [[simproc del: alpha_lst]]\n apply(simp add: Abs1_eq_iff fresh_star_def fresh_Pair_elim fresh_at_base flip_def)\n apply (metis Nominal2_Base.swap_commute fresh_permute_iff sort_of_atom_eq swap_atom_simps(2))\n using [[simproc del: alpha_lst]]\n apply simp_all\n apply (simp add: abs_same_binder)\n apply (erule_tac c=\"()\" in Abs_lst1_fcb2)\n apply (simp_all add: pure_fresh fresh_star_def eqvt_at_def)\n done\n\ntext {* tests of functions containing if and case *}\n\nconsts P :: \"lam \\ bool\"\n\n(*\nnominal_function \n A :: \"lam => lam\"\nwhere \n \"A (App M N) = (if (True \\ P M) then (A M) else (A N))\"\n| \"A (Var x) = (Var x)\" \n| \"A (App M N) = (if True then M else A N)\"\noops\n\nnominal_function \n C :: \"lam => lam\"\nwhere \n \"C (App M N) = (case (True \\ P M) of True \\ (A M) | False \\ (A N))\"\n| \"C (Var x) = (Var x)\" \n| \"C (App M N) = (if True then M else C N)\"\noops\n\nnominal_function \n A :: \"lam => lam\"\nwhere \n \"A (Lam [x].M) = (Lam [x].M)\"\n| \"A (Var x) = (Var x)\"\n| \"A (App M N) = (if True then M else A N)\"\noops\n\nnominal_function \n B :: \"lam => lam\"\nwhere \n \"B (Lam [x].M) = (Lam [x].M)\"\n| \"B (Var x) = (Var x)\"\n| \"B (App M N) = (if True then M else (B N))\"\nunfolding eqvt_def\nunfolding B_graph_def\napply(perm_simp)\napply(rule allI)\napply(rule refl)\noops\n*)\nend\n\n\n\n","avg_line_length":31.8523489933,"max_line_length":179,"alphanum_fraction":0.6747637108} {"size":64806,"ext":"thy","lang":"Isabelle","max_stars_count":2.0,"content":"\ntheory chat_sendMessage_line3\n imports Main\nbegin\n\ndatatype CallId = CallId nat\n\ndatatype TxId = TxId nat\n\ndatatype ChatId = ChatId nat\n\ndatatype MessageId = MessageId nat\n\ndatatype String = String nat\n\ndatatype UserId = UserId nat\n\ndatatype callInfo =\n queryop_chat_exists (key8: \"ChatId\") (result1: \"bool\")\n | queryop_message_content_mv_contains (key14: \"MessageId\") (elem4: \"String\") (result7: \"bool\")\n | message_chat_assign (key5: \"MessageId\") (value2: \"ChatId\")\n | queryop_chat_messages_contains (key7: \"ChatId\") (elem2: \"MessageId\") (result: \"bool\")\n | chat_messages_add (key: \"ChatId\") (elem: \"MessageId\")\n | chat_messages_remove (key1: \"ChatId\") (elem1: \"MessageId\")\n | message_content_assign (key4: \"MessageId\") (value1: \"String\")\n | message_delete (key6: \"MessageId\")\n | queryop_message_content_get (key12: \"MessageId\") (result5: \"String\")\n | queryop_message_author_getFirst (key10: \"MessageId\") (result3: \"UserId\")\n | queryop_message_chat_getFirst (key16: \"MessageId\") (result9: \"ChatId\")\n | queryop_message_chat_mv_contains (key17: \"MessageId\") (elem5: \"ChatId\") (result10: \"bool\")\n | queryop_message_chat_get (key15: \"MessageId\") (result8: \"ChatId\")\n | no_call \n | message_author_assign (key3: \"MessageId\") (qvalue: \"UserId\")\n | chat_delete (key2: \"ChatId\")\n | queryop_message_exists (key18: \"MessageId\") (result11: \"bool\")\n | queryop_message_content_getFirst (key13: \"MessageId\") (result6: \"String\")\n | queryop_message_author_get (key9: \"MessageId\") (result2: \"UserId\")\n | queryop_message_author_mv_contains (key11: \"MessageId\") (elem3: \"UserId\") (result4: \"bool\")\n\ndatatype InvocationId = InvocationId nat\n\ndatatype invocationResult =\n sendMessage_res (sendMessage_res_arg: \"MessageId\")\n | NoResult \n\ndatatype invocationInfo =\n sendMessage (qfrom: \"UserId\") (content: \"String\") (toC: \"ChatId\")\n | no_invocation \n\nlemma \"sendMessage_line3\":\n fixes happensBefore3 :: \"CallId => CallId set\"\n\nfixes calls4 :: \"CallId => callInfo\"\n\nfixes knownIds_MessageId1 :: \"MessageId set\"\n\nfixes message_author_mv_contains_res6 :: \"MessageId => UserId => bool\"\n\nfixes transactionOrigin1 :: \"TxId => InvocationId option\"\n\nfixes c11 :: \"CallId\"\n\nfixes invocationRes :: \"InvocationId => invocationResult\"\n\nfixes chat_messages_contains_res3 :: \"ChatId => MessageId => bool\"\n\nfixes message_exists_res4 :: \"MessageId => bool\"\n\nfixes message_author_mv_contains_res :: \"MessageId => UserId => bool\"\n\nfixes message_author_mv_contains_res1 :: \"MessageId => UserId => bool\"\n\nfixes vis1 :: \"CallId set\"\n\nfixes calls1 :: \"CallId => callInfo\"\n\nfixes content_init :: \"String\"\n\nfixes message_author_mv_contains_res5 :: \"MessageId => UserId => bool\"\n\nfixes invocationOp :: \"InvocationId => invocationInfo\"\n\nfixes callOrigin :: \"CallId => TxId option\"\n\nfixes happensBefore4 :: \"CallId => CallId set\"\n\nfixes invocationCalls :: \"InvocationId => CallId set\"\n\nfixes calls :: \"CallId => callInfo\"\n\nfixes calls3 :: \"CallId => callInfo\"\n\nfixes newCalls :: \"CallId set\"\n\nfixes m :: \"MessageId\"\n\nfixes vis :: \"CallId set\"\n\nfixes message_exists_res6 :: \"MessageId => bool\"\n\nfixes transactionOrigin :: \"TxId => InvocationId option\"\n\nfixes callOrigin1 :: \"CallId => TxId option\"\n\nfixes message_author_mv_contains_res2 :: \"MessageId => UserId => bool\"\n\nfixes message_exists_res3 :: \"MessageId => bool\"\n\nfixes vis2 :: \"CallId set\"\n\nfixes calls2 :: \"CallId => callInfo\"\n\nfixes chat_messages_contains_res2 :: \"ChatId => MessageId => bool\"\n\nfixes c21 :: \"CallId\"\n\nfixes snapshotAddition :: \"CallId set\"\n\nfixes happensBefore1 :: \"CallId => CallId set\"\n\nfixes chat_messages_contains_res5 :: \"ChatId => MessageId => bool\"\n\nfixes generatedIds_MessageId1 :: \"MessageId => InvocationId option\"\n\nfixes generatedIds_MessageId :: \"MessageId => InvocationId option\"\n\nfixes happensBefore5 :: \"CallId => CallId set\"\n\nfixes chat_messages_contains_res :: \"ChatId => MessageId => bool\"\n\nfixes message_exists_res7 :: \"MessageId => bool\"\n\nfixes c31 :: \"CallId\"\n\nfixes message_author_mv_contains_res4 :: \"MessageId => UserId => bool\"\n\nfixes snapshotAddition1 :: \"CallId set\"\n\nfixes currentInvocation :: \"InvocationId\"\n\nfixes message_exists_res2 :: \"MessageId => bool\"\n\nfixes message_exists_res8 :: \"MessageId => bool\"\n\nfixes invocationCalls1 :: \"InvocationId => CallId set\"\n\nfixes c0 :: \"CallId\"\n\nfixes chat_messages_contains_res1 :: \"ChatId => MessageId => bool\"\n\nfixes vis3 :: \"CallId set\"\n\nfixes calls5 :: \"CallId => callInfo\"\n\nfixes knownIds_MessageId :: \"MessageId set\"\n\nfixes message_exists_res :: \"MessageId => bool\"\n\nfixes happensBefore2 :: \"CallId => CallId set\"\n\nfixes message_exists_res1 :: \"MessageId => bool\"\n\nfixes from_init :: \"UserId\"\n\nfixes message_exists_res5 :: \"MessageId => bool\"\n\nfixes message_exists_res9 :: \"MessageId => bool\"\n\nfixes tx :: \"TxId\"\n\nfixes message_author_mv_contains_res7 :: \"MessageId => UserId => bool\"\n\nfixes chat_messages_contains_res4 :: \"ChatId => MessageId => bool\"\n\nfixes toC_init :: \"ChatId\"\n\nfixes message_author_mv_contains_res3 :: \"MessageId => UserId => bool\"\n\nfixes vis4 :: \"CallId set\"\n\nfixes happensBefore :: \"CallId => CallId set\"\n\nfixes newTxns :: \"TxId set\"\n\nassumes before_procedure_invocation_snapshot_addition_transaction_consistent:\n\n\"(\\bound_c116.\n (\\bound_c216.\n (((bound_c116 \\ snapshotAddition) \\ (bound_c216 \\ (happensBefore bound_c116))) \\ (bound_c216 \\ snapshotAddition))))\"\n\nassumes before_procedure_invocation_snapshot_addition_transaction_consistent_2:\n\n\"(\\bound_c115.\n (\\bound_c215.\n (((bound_c115 \\ snapshotAddition) \\ ((callOrigin bound_c115) = (callOrigin bound_c215)))\n \\ (bound_c215 \\ snapshotAddition))))\"\n\nassumes before_procedure_invocation_snapshot_addition_subset_calls:\n\n\"(\\bound_c34. ((bound_c34 \\ snapshotAddition) \\ ((calls bound_c34) \\ no_call)))\"\n\nassumes before_procedure_invocation_MessageId_knownIds_are_generated:\n\n\"(\\bound_x3. ((bound_x3 \\ knownIds_MessageId) \\ \\((generatedIds_MessageId bound_x3) = None)))\"\n\nassumes before_procedure_invocation_message_delete_call_parameter_key_generated:\n\n\"(\\bound_c33.\n (\\bound_key5. (((calls bound_c33) = (message_delete bound_key5)) \\ \\((generatedIds_MessageId bound_key5) = None))))\"\n\nassumes before_procedure_invocation_message_chat_assign_call_parameter_key_generated:\n\n\"(\\bound_c32.\n (\\bound_key4.\n (\\bound_value2.\n (((calls bound_c32) = (message_chat_assign bound_key4 bound_value2))\n \\ \\((generatedIds_MessageId bound_key4) = None)))))\"\n\nassumes before_procedure_invocation_message_content_assign_call_parameter_key_generated:\n\n\"(\\bound_c31.\n (\\bound_key3.\n (\\bound_value1.\n (((calls bound_c31) = (message_content_assign bound_key3 bound_value1))\n \\ \\((generatedIds_MessageId bound_key3) = None)))))\"\n\nassumes before_procedure_invocation_message_author_assign_call_parameter_key_generated:\n\n\"(\\bound_c30.\n (\\bound_key2.\n (\\bound_value.\n (((calls bound_c30) = (message_author_assign bound_key2 bound_value))\n \\ \\((generatedIds_MessageId bound_key2) = None)))))\"\n\nassumes before_procedure_invocation_chat_messages_remove_call_parameter_elem_generated:\n\n\"(\\bound_c20.\n (\\bound_key1.\n (\\bound_elem1.\n (((calls bound_c20) = (chat_messages_remove bound_key1 bound_elem1))\n \\ \\((generatedIds_MessageId bound_elem1) = None)))))\"\n\nassumes before_procedure_invocation_chat_messages_add_call_parameter_elem_generated:\n\n\"(\\bound_c10.\n (\\bound_key.\n (\\bound_elem.\n (((calls bound_c10) = (chat_messages_add bound_key bound_elem)) \\ \\((generatedIds_MessageId bound_elem) = None)))))\"\n\nassumes before_procedure_invocation_sendMessage_result_known:\n\n\"(\\bound_i4.\n (\\bound_result. (((invocationRes bound_i4) = (sendMessage_res bound_result)) \\ (bound_result \\ knownIds_MessageId))))\"\n\nassumes before_procedure_invocation_WF_transactionOrigin_exists:\n\n\"(\\bound_tx6.\n (\\bound_i3. (((transactionOrigin bound_tx6) = (Some bound_i3)) \\ ((invocationOp bound_i3) \\ no_invocation))))\"\n\nassumes before_procedure_invocation_WF_callOrigin_exists:\n\n\"(\\bound_ca1. (\\bound_tx5. (((callOrigin bound_ca1) = (Some bound_tx5)) \\ \\((transactionOrigin bound_tx5) = None))))\"\n\nassumes before_procedure_invocation_WF_no_call_implies_not_in_happensBefore:\n\n\"(\\bound_ca. (\\bound_cb. (((callOrigin bound_ca) = None) \\ \\(bound_ca \\ (happensBefore bound_cb)))))\"\n\nassumes before_procedure_invocation_WF_no_call_implies_no_happensBefore:\n\n\"(\\bound_c9. (((callOrigin bound_c9) = None) \\ ((happensBefore bound_c9) = {})))\"\n\nassumes before_procedure_invocation_WF_transactionOrigin_callOrigin:\n\n\"(\\bound_tx4. (((transactionOrigin bound_tx4) = None) \\ (\\bound_c8. ((callOrigin bound_c8) \\ (Some bound_tx4)))))\"\n\nassumes before_procedure_invocation_WF_callOrigin:\n\n\"(\\bound_c7. (((callOrigin bound_c7) = None) = ((calls bound_c7) = no_call)))\"\n\nassumes before_procedure_invocation_WF_invocationCalls:\n\n\"(\\bound_i2.\n (\\bound_c6.\n ((bound_c6 \\ (invocationCalls bound_i2))\n = (\\bound_tx3. (((callOrigin bound_c6) = (Some bound_tx3)) \\ ((transactionOrigin bound_tx3) = (Some bound_i2)))))))\"\n\nassumes before_procedure_invocation_no_invocation_implies_no_result:\n\n\"(\\bound_x11.\n (\\bound_x2.\n (\\bound_y11.\n (\\bound_y21.\n ((((((callOrigin bound_x11) = (callOrigin bound_x2)) \\ ((callOrigin bound_y11) = (callOrigin bound_y21)))\n \\ \\((callOrigin bound_x11) = (callOrigin bound_y11)))\n \\ (bound_x2 \\ (happensBefore bound_y11)))\n \\ (bound_x2 \\ (happensBefore bound_y21)))))))\"\n\nassumes before_procedure_invocation_no_invocation_implies_no_result_2:\n\n\"(\\bound_i1. (((invocationOp bound_i1) = no_invocation) \\ ((invocationRes bound_i1) = NoReturn)))\"\n\nassumes before_procedure_invocation_happensBefore_antisym:\n\n\"(\\bound_x1.\n (\\bound_y1. (((bound_x1 \\ (happensBefore bound_y1)) \\ (bound_y1 \\ (happensBefore bound_x1))) \\ (bound_x1 = bound_y1))))\"\n\nassumes before_procedure_invocation_happensBefore_trans:\n\n\"(\\bound_x.\n (\\bound_y.\n (\\bound_z.\n (((bound_x \\ (happensBefore bound_y)) \\ (bound_y \\ (happensBefore bound_z))) \\ (bound_x \\ (happensBefore bound_y))))))\"\n\nassumes before_procedure_invocation_happensBefore_reflex:\n\n\"(\\bound_c5. (((calls bound_c5) \\ no_call) \\ (bound_c5 \\ (happensBefore bound_c5))))\"\n\nassumes before_procedure_invocation_visibleCalls_causally_consistent:\n\n\"(\\bound_c114. (\\bound_c214. (((bound_c214 \\ {}) \\ (bound_c114 \\ (happensBefore bound_c214))) \\ (bound_c114 \\ {}))))\"\n\nassumes before_procedure_invocation_visibleCalls_transaction_consistent1:\n\n\"(\\bound_c113.\n (\\bound_c213.\n ((((bound_c113 \\ {}) \\ ((callOrigin bound_c113) = (callOrigin bound_c213))) \\ ((calls bound_c213) \\ no_call))\n \\ (bound_c213 \\ {}))))\"\n\nassumes before_procedure_invocation_visibleCalls_exist:\n\n\"(\\bound_c4. ((bound_c4 \\ {}) \\ ((calls bound_c4) \\ no_call)))\"\n\nassumes before_procedure_invocation_invocation_sequential:\n\n\"(\\bound_c112.\n (\\bound_tx1.\n (\\bound_i.\n (\\bound_c212.\n (\\bound_tx2.\n ((((((callOrigin bound_c112) = (Some bound_tx1)) \\ ((transactionOrigin bound_tx1) = (Some bound_i)))\n \\ ((callOrigin bound_c212) = (Some bound_tx2)))\n \\ ((transactionOrigin bound_tx2) = (Some bound_i)))\n \\ ((bound_c112 \\ (happensBefore bound_c212)) \\ (bound_c212 \\ (happensBefore bound_c112)))))))))\"\n\nassumes before_procedure_invocation_happensBefore_exists_r:\n\n\"(\\bound_c111. (\\bound_c211. (((calls bound_c111) = no_call) \\ \\(bound_c111 \\ (happensBefore bound_c211)))))\"\n\nassumes before_procedure_invocation_happensBefore_exists_l:\n\n\"(\\bound_c110. (\\bound_c210. (((calls bound_c110) = no_call) \\ \\(bound_c110 \\ (happensBefore bound_c210)))))\"\n\nassumes no_call_in_new_invocation:\n\n\"((invocationCalls currentInvocation) = {})\"\n\nassumes message_exists_res:\n\n\"(\\bound_m2.\n ((message_exists_res bound_m2)\n = (\\bound_c14.\n (((((bound_c14 \\ snapshotAddition)\n \\ (\\bound_args6. ((calls bound_c14) = (message_author_assign bound_m2 bound_args6))))\n \\ ((bound_c14 \\ snapshotAddition)\n \\ (\\bound_args7. ((calls bound_c14) = (message_content_assign bound_m2 bound_args7)))))\n \\ ((bound_c14 \\ snapshotAddition)\n \\ (\\bound_args8. ((calls bound_c14) = (message_chat_assign bound_m2 bound_args8)))))\n \\ (\\bound_c24.\n (((bound_c24 \\ snapshotAddition) \\ ((calls bound_c24) = (message_delete bound_m2)))\n \\ (bound_c24 \\ (happensBefore bound_c14))))))))\"\n\nassumes message_author_mv_contains_res:\n\n\"(\\bound_m2.\n (\\bound_a1.\n (((message_author_mv_contains_res bound_m2) bound_a1)\n = (\\bound_c15.\n (((bound_c15 \\ snapshotAddition)\n \\ (((calls bound_c15) = (message_author_assign bound_m2 bound_a1))\n \\ (\\bound_d4.\n (((bound_d4 \\ snapshotAddition) \\ ((calls bound_d4) = (message_delete bound_m2)))\n \\ (bound_d4 \\ (happensBefore bound_c15))))))\n \\ \\(\\bound_c25.\n (\\bound_anyArgs.\n ((((bound_c25 \\ snapshotAddition) \\ (bound_c15 \\ bound_c25))\n \\ (((calls bound_c25) = (message_author_assign bound_m2 bound_anyArgs))\n \\ (\\bound_d5.\n (((bound_d5 \\ snapshotAddition) \\ ((calls bound_d5) = (message_delete bound_m2)))\n \\ (bound_d5 \\ (happensBefore bound_c25))))))\n \\ (bound_c15 \\ (happensBefore bound_c25))))))))))\"\n\nassumes message_author_mv_contains_res_2:\n\n\"(\\bound_m2.\n (\\bound_a2.\n (((message_author_mv_contains_res1 bound_m2) bound_a2)\n = (\\bound_c16.\n (((bound_c16 \\ snapshotAddition)\n \\ (((calls bound_c16) = (message_author_assign bound_m2 bound_a2))\n \\ (\\bound_d6.\n (((bound_d6 \\ snapshotAddition) \\ ((calls bound_d6) = (message_delete bound_m2)))\n \\ (bound_d6 \\ (happensBefore bound_c16))))))\n \\ \\(\\bound_c26.\n (\\bound_anyArgs1.\n ((((bound_c26 \\ snapshotAddition) \\ (bound_c16 \\ bound_c26))\n \\ (((calls bound_c26) = (message_author_assign bound_m2 bound_anyArgs1))\n \\ (\\bound_d7.\n (((bound_d7 \\ snapshotAddition) \\ ((calls bound_d7) = (message_delete bound_m2)))\n \\ (bound_d7 \\ (happensBefore bound_c26))))))\n \\ (bound_c16 \\ (happensBefore bound_c26))))))))))\"\n\nassumes message_exists_res_2:\n\n\"(\\bound_m3.\n ((message_exists_res1 bound_m3)\n = (\\bound_c17.\n (((((bound_c17 \\ ({} \\ snapshotAddition))\n \\ (\\bound_args9. ((calls bound_c17) = (message_author_assign bound_m3 bound_args9))))\n \\ ((bound_c17 \\ ({} \\ snapshotAddition))\n \\ (\\bound_args10. ((calls bound_c17) = (message_content_assign bound_m3 bound_args10)))))\n \\ ((bound_c17 \\ ({} \\ snapshotAddition))\n \\ (\\bound_args11. ((calls bound_c17) = (message_chat_assign bound_m3 bound_args11)))))\n \\ (\\bound_c27.\n (((bound_c27 \\ ({} \\ snapshotAddition)) \\ ((calls bound_c27) = (message_delete bound_m3)))\n \\ (bound_c27 \\ (happensBefore bound_c17))))))))\"\n\nassumes message_author_mv_contains_res_3:\n\n\"(\\bound_m3.\n (\\bound_a11.\n (((message_author_mv_contains_res2 bound_m3) bound_a11)\n = (\\bound_c18.\n (((bound_c18 \\ ({} \\ snapshotAddition))\n \\ (((calls bound_c18) = (message_author_assign bound_m3 bound_a11))\n \\ (\\bound_d8.\n (((bound_d8 \\ ({} \\ snapshotAddition)) \\ ((calls bound_d8) = (message_delete bound_m3)))\n \\ (bound_d8 \\ (happensBefore bound_c18))))))\n \\ \\(\\bound_c28.\n (\\bound_anyArgs2.\n ((((bound_c28 \\ ({} \\ snapshotAddition)) \\ (bound_c18 \\ bound_c28))\n \\ (((calls bound_c28) = (message_author_assign bound_m3 bound_anyArgs2))\n \\ (\\bound_d9.\n (((bound_d9 \\ ({} \\ snapshotAddition)) \\ ((calls bound_d9) = (message_delete bound_m3)))\n \\ (bound_d9 \\ (happensBefore bound_c28))))))\n \\ (bound_c18 \\ (happensBefore bound_c28))))))))))\"\n\nassumes message_author_mv_contains_res_4:\n\n\"(\\bound_m3.\n (\\bound_a21.\n (((message_author_mv_contains_res3 bound_m3) bound_a21)\n = (\\bound_c19.\n (((bound_c19 \\ ({} \\ snapshotAddition))\n \\ (((calls bound_c19) = (message_author_assign bound_m3 bound_a21))\n \\ (\\bound_d10.\n (((bound_d10 \\ ({} \\ snapshotAddition)) \\ ((calls bound_d10) = (message_delete bound_m3)))\n \\ (bound_d10 \\ (happensBefore bound_c19))))))\n \\ \\(\\bound_c29.\n (\\bound_anyArgs3.\n ((((bound_c29 \\ ({} \\ snapshotAddition)) \\ (bound_c19 \\ bound_c29))\n \\ (((calls bound_c29) = (message_author_assign bound_m3 bound_anyArgs3))\n \\ (\\bound_d11.\n (((bound_d11 \\ ({} \\ snapshotAddition)) \\ ((calls bound_d11) = (message_delete bound_m3)))\n \\ (bound_d11 \\ (happensBefore bound_c29))))))\n \\ (bound_c19 \\ (happensBefore bound_c29))))))))))\"\n\nassumes before_procedure_invocation_invariant_1:\n\n\"((\\bound_m2.\n (\\bound_a1.\n (\\bound_a2.\n ((((message_exists_res bound_m2) \\ ((message_author_mv_contains_res bound_m2) bound_a1))\n \\ ((message_author_mv_contains_res1 bound_m2) bound_a2))\n \\ (bound_a1 = bound_a2)))))\n \\ (\\bound_m3.\n (\\bound_a11.\n (\\bound_a21.\n ((((message_exists_res1 bound_m3) \\ ((message_author_mv_contains_res2 bound_m3) bound_a11))\n \\ ((message_author_mv_contains_res3 bound_m3) bound_a21))\n \\ (bound_a11 = bound_a21))))))\"\n\nassumes chat_messages_contains_res:\n\n\"(\\bound_c.\n (\\bound_m.\n (((chat_messages_contains_res bound_c) bound_m)\n = (\\bound_c1.\n (((bound_c1 \\ snapshotAddition)\n \\ (((calls bound_c1) = (chat_messages_add bound_c bound_m))\n \\ (\\bound_d.\n (((bound_d \\ snapshotAddition) \\ ((calls bound_d) = (chat_delete bound_c)))\n \\ (bound_d \\ (happensBefore bound_c1))))))\n \\ (\\bound_c2.\n (((bound_c2 \\ snapshotAddition)\n \\ (((calls bound_c2) = (chat_messages_remove bound_c bound_m))\n \\ (\\bound_d1.\n (((bound_d1 \\ snapshotAddition) \\ ((calls bound_d1) = (chat_delete bound_c)))\n \\ (bound_d1 \\ (happensBefore bound_c2))))))\n \\ (bound_c2 \\ (happensBefore bound_c1)))))))))\"\n\nassumes message_exists_res_3:\n\n\"(\\bound_m.\n ((message_exists_res2 bound_m)\n = (\\bound_c11.\n (((((bound_c11 \\ snapshotAddition) \\ (\\bound_args. ((calls bound_c11) = (message_author_assign bound_m bound_args))))\n \\ ((bound_c11 \\ snapshotAddition)\n \\ (\\bound_args1. ((calls bound_c11) = (message_content_assign bound_m bound_args1)))))\n \\ ((bound_c11 \\ snapshotAddition)\n \\ (\\bound_args2. ((calls bound_c11) = (message_chat_assign bound_m bound_args2)))))\n \\ (\\bound_c21.\n (((bound_c21 \\ snapshotAddition) \\ ((calls bound_c21) = (message_delete bound_m)))\n \\ (bound_c21 \\ (happensBefore bound_c11))))))))\"\n\nassumes chat_messages_contains_res_2:\n\n\"(\\bound_c3.\n (\\bound_m1.\n (((chat_messages_contains_res1 bound_c3) bound_m1)\n = (\\bound_c12.\n (((bound_c12 \\ ({} \\ snapshotAddition))\n \\ (((calls bound_c12) = (chat_messages_add bound_c3 bound_m1))\n \\ (\\bound_d2.\n (((bound_d2 \\ ({} \\ snapshotAddition)) \\ ((calls bound_d2) = (chat_delete bound_c3)))\n \\ (bound_d2 \\ (happensBefore bound_c12))))))\n \\ (\\bound_c22.\n (((bound_c22 \\ ({} \\ snapshotAddition))\n \\ (((calls bound_c22) = (chat_messages_remove bound_c3 bound_m1))\n \\ (\\bound_d3.\n (((bound_d3 \\ ({} \\ snapshotAddition)) \\ ((calls bound_d3) = (chat_delete bound_c3)))\n \\ (bound_d3 \\ (happensBefore bound_c22))))))\n \\ (bound_c22 \\ (happensBefore bound_c12)))))))))\"\n\nassumes message_exists_res_4:\n\n\"(\\bound_m1.\n ((message_exists_res3 bound_m1)\n = (\\bound_c13.\n (((((bound_c13 \\ ({} \\ snapshotAddition))\n \\ (\\bound_args3. ((calls bound_c13) = (message_author_assign bound_m1 bound_args3))))\n \\ ((bound_c13 \\ ({} \\ snapshotAddition))\n \\ (\\bound_args4. ((calls bound_c13) = (message_content_assign bound_m1 bound_args4)))))\n \\ ((bound_c13 \\ ({} \\ snapshotAddition))\n \\ (\\bound_args5. ((calls bound_c13) = (message_chat_assign bound_m1 bound_args5)))))\n \\ (\\bound_c23.\n (((bound_c23 \\ ({} \\ snapshotAddition)) \\ ((calls bound_c23) = (message_delete bound_m1)))\n \\ (bound_c23 \\ (happensBefore bound_c13))))))))\"\n\nassumes before_procedure_invocation_invariant_0:\n\n\"((\\bound_c. (\\bound_m. (((chat_messages_contains_res bound_c) bound_m) \\ (message_exists_res2 bound_m))))\n \\ (\\bound_c3. (\\bound_m1. (((chat_messages_contains_res1 bound_c3) bound_m1) \\ (message_exists_res3 bound_m1)))))\"\n\nassumes i_fresh:\n\n\"((invocationOp currentInvocation) = no_invocation)\"\n\nassumes old_transactions_unchanged:\n\n\"(\\c5.\n (\\tx3.\n (((((calls c5) = no_call) \\ ((calls1 c5) \\ no_call)) \\ ((callOrigin1 c5) = (Some tx3)))\n \\ ((transactionOrigin tx3) = None))))\"\n\nassumes growth_invocation_res:\n\n\"(\\i1. (((invocationRes i1) \\ NoReturn) \\ ((invocationRes i1) = (invocationRes i1))))\"\n\nassumes growth_invocation_op:\n\n\"(\\i.\n ((((invocationOp(currentInvocation := (sendMessage from_init content_init toC_init))) i) \\ no_invocation)\n \\ (((invocationOp(currentInvocation := (sendMessage from_init content_init toC_init))) i)\n = ((invocationOp(currentInvocation := (sendMessage from_init content_init toC_init))) i))))\"\n\nassumes growth_tx_origin:\n\n\"(\\tx2. (\\((transactionOrigin tx2) = None) \\ ((transactionOrigin1 tx2) = (transactionOrigin tx2))))\"\n\nassumes growth_call_tx:\n\n\"(\\c4. (((calls c4) \\ no_call) \\ ((callOrigin1 c4) = (callOrigin c4))))\"\n\nassumes growth_happensbefore:\n\n\"(\\c3. (((calls c3) \\ no_call) \\ ((happensBefore1 c3) = (happensBefore c3))))\"\n\nassumes growth_calls:\n\n\"(\\c2. (((calls c2) \\ no_call) \\ ((calls1 c2) = (calls c2))))\"\n\nassumes growth_visible_calls:\n\n\"(\\c1. ((c1 \\ {}) \\ (c1 \\ {})))\"\n\nassumes growth_callOrigin:\n\n\"(\\c. (\\tx1. (((callOrigin c) = (Some tx1)) \\ ((callOrigin1 c) = (Some tx1)))))\"\n\nassumes transaction_begin_snapshot_addition_transaction_consistent:\n\n\"(\\bound_c143.\n (\\bound_c243.\n (((bound_c143 \\ snapshotAddition1) \\ (bound_c243 \\ (happensBefore1 bound_c143))) \\ (bound_c243 \\ snapshotAddition1))))\"\n\nassumes transaction_begin_snapshot_addition_transaction_consistent_2:\n\n\"(\\bound_c142.\n (\\bound_c242.\n (((bound_c142 \\ snapshotAddition1) \\ ((callOrigin1 bound_c142) = (callOrigin1 bound_c242)))\n \\ (bound_c242 \\ snapshotAddition1))))\"\n\nassumes transaction_begin_snapshot_addition_subset_calls:\n\n\"(\\bound_c51. ((bound_c51 \\ snapshotAddition1) \\ ((calls1 bound_c51) \\ no_call)))\"\n\nassumes transaction_begin_MessageId_knownIds_are_generated:\n\n\"(\\bound_x6. ((bound_x6 \\ knownIds_MessageId1) \\ \\((generatedIds_MessageId1 bound_x6) = None)))\"\n\nassumes transaction_begin_message_delete_call_parameter_key_generated:\n\n\"(\\bound_c50.\n (\\bound_key11. (((calls1 bound_c50) = (message_delete bound_key11)) \\ \\((generatedIds_MessageId1 bound_key11) = None))))\"\n\nassumes transaction_begin_message_chat_assign_call_parameter_key_generated:\n\n\"(\\bound_c49.\n (\\bound_key10.\n (\\bound_value5.\n (((calls1 bound_c49) = (message_chat_assign bound_key10 bound_value5))\n \\ \\((generatedIds_MessageId1 bound_key10) = None)))))\"\n\nassumes transaction_begin_message_content_assign_call_parameter_key_generated:\n\n\"(\\bound_c48.\n (\\bound_key9.\n (\\bound_value4.\n (((calls1 bound_c48) = (message_content_assign bound_key9 bound_value4))\n \\ \\((generatedIds_MessageId1 bound_key9) = None)))))\"\n\nassumes transaction_begin_message_author_assign_call_parameter_key_generated:\n\n\"(\\bound_c47.\n (\\bound_key8.\n (\\bound_value3.\n (((calls1 bound_c47) = (message_author_assign bound_key8 bound_value3))\n \\ \\((generatedIds_MessageId1 bound_key8) = None)))))\"\n\nassumes transaction_begin_chat_messages_remove_call_parameter_elem_generated:\n\n\"(\\bound_c46.\n (\\bound_key7.\n (\\bound_elem3.\n (((calls1 bound_c46) = (chat_messages_remove bound_key7 bound_elem3))\n \\ \\((generatedIds_MessageId1 bound_elem3) = None)))))\"\n\nassumes transaction_begin_chat_messages_add_call_parameter_elem_generated:\n\n\"(\\bound_c45.\n (\\bound_key6.\n (\\bound_elem2.\n (((calls1 bound_c45) = (chat_messages_add bound_key6 bound_elem2))\n \\ \\((generatedIds_MessageId1 bound_elem2) = None)))))\"\n\nassumes transaction_begin_sendMessage_result_known:\n\n\"(\\bound_i9.\n (\\bound_result1.\n (((invocationRes bound_i9) = (sendMessage_res bound_result1)) \\ (bound_result1 \\ knownIds_MessageId1))))\"\n\nassumes transaction_begin_WF_transactionOrigin_exists:\n\n\"(\\bound_tx10.\n (\\bound_i8.\n (((transactionOrigin1 bound_tx10) = (Some bound_i8))\n \\ (((invocationOp(currentInvocation := (sendMessage from_init content_init toC_init))) bound_i8) \\ no_invocation))))\"\n\nassumes transaction_begin_WF_callOrigin_exists:\n\n\"(\\bound_ca3. (\\bound_tx9. (((callOrigin1 bound_ca3) = (Some bound_tx9)) \\ \\((transactionOrigin1 bound_tx9) = None))))\"\n\nassumes transaction_begin_WF_no_call_implies_not_in_happensBefore:\n\n\"(\\bound_ca2. (\\bound_cb1. (((callOrigin1 bound_ca2) = None) \\ \\(bound_ca2 \\ (happensBefore1 bound_cb1)))))\"\n\nassumes transaction_begin_WF_no_call_implies_no_happensBefore:\n\n\"(\\bound_c44. (((callOrigin1 bound_c44) = None) \\ ((happensBefore1 bound_c44) = {})))\"\n\nassumes transaction_begin_WF_transactionOrigin_callOrigin:\n\n\"(\\bound_tx8. (((transactionOrigin1 bound_tx8) = None) \\ (\\bound_c43. ((callOrigin1 bound_c43) \\ (Some bound_tx8)))))\"\n\nassumes transaction_begin_WF_callOrigin:\n\n\"(\\bound_c42. (((callOrigin1 bound_c42) = None) = ((calls1 bound_c42) = no_call)))\"\n\nassumes transaction_begin_WF_invocationCalls:\n\n\"(\\bound_i7.\n (\\bound_c41.\n ((bound_c41 \\ (invocationCalls1 bound_i7))\n = (\\bound_tx7. (((callOrigin1 bound_c41) = (Some bound_tx7)) \\ ((transactionOrigin1 bound_tx7) = (Some bound_i7)))))))\"\n\nassumes transaction_begin_no_invocation_implies_no_result:\n\n\"(\\bound_x12.\n (\\bound_x21.\n (\\bound_y12.\n (\\bound_y22.\n ((((((callOrigin1 bound_x12) = (callOrigin1 bound_x21)) \\ ((callOrigin1 bound_y12) = (callOrigin1 bound_y22)))\n \\ \\((callOrigin1 bound_x12) = (callOrigin1 bound_y12)))\n \\ (bound_x21 \\ (happensBefore1 bound_y12)))\n \\ (bound_x21 \\ (happensBefore1 bound_y22)))))))\"\n\nassumes transaction_begin_no_invocation_implies_no_result_2:\n\n\"(\\bound_i6.\n ((((invocationOp(currentInvocation := (sendMessage from_init content_init toC_init))) bound_i6) = no_invocation)\n \\ ((invocationRes bound_i6) = NoReturn)))\"\n\nassumes transaction_begin_happensBefore_antisym:\n\n\"(\\bound_x5.\n (\\bound_y4.\n (((bound_x5 \\ (happensBefore1 bound_y4)) \\ (bound_y4 \\ (happensBefore1 bound_x5))) \\ (bound_x5 = bound_y4))))\"\n\nassumes transaction_begin_happensBefore_trans:\n\n\"(\\bound_x4.\n (\\bound_y3.\n (\\bound_z1.\n (((bound_x4 \\ (happensBefore1 bound_y3)) \\ (bound_y3 \\ (happensBefore1 bound_z1)))\n \\ (bound_x4 \\ (happensBefore1 bound_y3))))))\"\n\nassumes transaction_begin_happensBefore_reflex:\n\n\"(\\bound_c40. (((calls1 bound_c40) \\ no_call) \\ (bound_c40 \\ (happensBefore1 bound_c40))))\"\n\nassumes transaction_begin_visibleCalls_causally_consistent:\n\n\"(\\bound_c141. (\\bound_c241. (((bound_c241 \\ vis) \\ (bound_c141 \\ (happensBefore1 bound_c241))) \\ (bound_c141 \\ vis))))\"\n\nassumes transaction_begin_visibleCalls_transaction_consistent1:\n\n\"(\\bound_c140.\n (\\bound_c240.\n ((((bound_c140 \\ vis) \\ ((callOrigin1 bound_c140) = (callOrigin1 bound_c240))) \\ ((calls1 bound_c240) \\ no_call))\n \\ (bound_c240 \\ vis))))\"\n\nassumes transaction_begin_visibleCalls_exist:\n\n\"(\\bound_c39. ((bound_c39 \\ vis) \\ ((calls1 bound_c39) \\ no_call)))\"\n\nassumes transaction_begin_invocation_sequential:\n\n\"(\\bound_c139.\n (\\bound_tx11.\n (\\bound_i5.\n (\\bound_c239.\n (\\bound_tx21.\n ((((((callOrigin1 bound_c139) = (Some bound_tx11)) \\ ((transactionOrigin1 bound_tx11) = (Some bound_i5)))\n \\ ((callOrigin1 bound_c239) = (Some bound_tx21)))\n \\ ((transactionOrigin1 bound_tx21) = (Some bound_i5)))\n \\ ((bound_c139 \\ (happensBefore1 bound_c239)) \\ (bound_c239 \\ (happensBefore1 bound_c139)))))))))\"\n\nassumes transaction_begin_happensBefore_exists_r:\n\n\"(\\bound_c138. (\\bound_c238. (((calls1 bound_c138) = no_call) \\ \\(bound_c138 \\ (happensBefore1 bound_c238)))))\"\n\nassumes transaction_begin_happensBefore_exists_l:\n\n\"(\\bound_c137. (\\bound_c237. (((calls1 bound_c137) = no_call) \\ \\(bound_c137 \\ (happensBefore1 bound_c237)))))\"\n\nassumes message_exists_res_5:\n\n\"(\\bound_m10.\n ((message_exists_res4 bound_m10)\n = (\\bound_c131.\n (((((bound_c131 \\ snapshotAddition1)\n \\ (\\bound_args30. ((calls1 bound_c131) = (message_author_assign bound_m10 bound_args30))))\n \\ ((bound_c131 \\ snapshotAddition1)\n \\ (\\bound_args31. ((calls1 bound_c131) = (message_content_assign bound_m10 bound_args31)))))\n \\ ((bound_c131 \\ snapshotAddition1)\n \\ (\\bound_args32. ((calls1 bound_c131) = (message_chat_assign bound_m10 bound_args32)))))\n \\ (\\bound_c231.\n (((bound_c231 \\ snapshotAddition1) \\ ((calls1 bound_c231) = (message_delete bound_m10)))\n \\ (bound_c231 \\ (happensBefore1 bound_c131))))))))\"\n\nassumes message_author_mv_contains_res_5:\n\n\"(\\bound_m10.\n (\\bound_a14.\n (((message_author_mv_contains_res4 bound_m10) bound_a14)\n = (\\bound_c132.\n (((bound_c132 \\ snapshotAddition1)\n \\ (((calls1 bound_c132) = (message_author_assign bound_m10 bound_a14))\n \\ (\\bound_d28.\n (((bound_d28 \\ snapshotAddition1) \\ ((calls1 bound_d28) = (message_delete bound_m10)))\n \\ (bound_d28 \\ (happensBefore1 bound_c132))))))\n \\ \\(\\bound_c232.\n (\\bound_anyArgs8.\n ((((bound_c232 \\ snapshotAddition1) \\ (bound_c132 \\ bound_c232))\n \\ (((calls1 bound_c232) = (message_author_assign bound_m10 bound_anyArgs8))\n \\ (\\bound_d29.\n (((bound_d29 \\ snapshotAddition1) \\ ((calls1 bound_d29) = (message_delete bound_m10)))\n \\ (bound_d29 \\ (happensBefore1 bound_c232))))))\n \\ (bound_c132 \\ (happensBefore1 bound_c232))))))))))\"\n\nassumes message_author_mv_contains_res_6:\n\n\"(\\bound_m10.\n (\\bound_a24.\n (((message_author_mv_contains_res5 bound_m10) bound_a24)\n = (\\bound_c133.\n (((bound_c133 \\ snapshotAddition1)\n \\ (((calls1 bound_c133) = (message_author_assign bound_m10 bound_a24))\n \\ (\\bound_d30.\n (((bound_d30 \\ snapshotAddition1) \\ ((calls1 bound_d30) = (message_delete bound_m10)))\n \\ (bound_d30 \\ (happensBefore1 bound_c133))))))\n \\ \\(\\bound_c233.\n (\\bound_anyArgs9.\n ((((bound_c233 \\ snapshotAddition1) \\ (bound_c133 \\ bound_c233))\n \\ (((calls1 bound_c233) = (message_author_assign bound_m10 bound_anyArgs9))\n \\ (\\bound_d31.\n (((bound_d31 \\ snapshotAddition1) \\ ((calls1 bound_d31) = (message_delete bound_m10)))\n \\ (bound_d31 \\ (happensBefore1 bound_c233))))))\n \\ (bound_c133 \\ (happensBefore1 bound_c233))))))))))\"\n\nassumes message_exists_res_6:\n\n\"(\\bound_m11.\n ((message_exists_res5 bound_m11)\n = (\\bound_c134.\n (((((bound_c134 \\ (vis \\ snapshotAddition1))\n \\ (\\bound_args33. ((calls1 bound_c134) = (message_author_assign bound_m11 bound_args33))))\n \\ ((bound_c134 \\ (vis \\ snapshotAddition1))\n \\ (\\bound_args34. ((calls1 bound_c134) = (message_content_assign bound_m11 bound_args34)))))\n \\ ((bound_c134 \\ (vis \\ snapshotAddition1))\n \\ (\\bound_args35. ((calls1 bound_c134) = (message_chat_assign bound_m11 bound_args35)))))\n \\ (\\bound_c234.\n (((bound_c234 \\ (vis \\ snapshotAddition1)) \\ ((calls1 bound_c234) = (message_delete bound_m11)))\n \\ (bound_c234 \\ (happensBefore1 bound_c134))))))))\"\n\nassumes message_author_mv_contains_res_7:\n\n\"(\\bound_m11.\n (\\bound_a15.\n (((message_author_mv_contains_res6 bound_m11) bound_a15)\n = (\\bound_c135.\n (((bound_c135 \\ (vis \\ snapshotAddition1))\n \\ (((calls1 bound_c135) = (message_author_assign bound_m11 bound_a15))\n \\ (\\bound_d32.\n (((bound_d32 \\ (vis \\ snapshotAddition1)) \\ ((calls1 bound_d32) = (message_delete bound_m11)))\n \\ (bound_d32 \\ (happensBefore1 bound_c135))))))\n \\ \\(\\bound_c235.\n (\\bound_anyArgs10.\n ((((bound_c235 \\ (vis \\ snapshotAddition1)) \\ (bound_c135 \\ bound_c235))\n \\ (((calls1 bound_c235) = (message_author_assign bound_m11 bound_anyArgs10))\n \\ (\\bound_d33.\n (((bound_d33 \\ (vis \\ snapshotAddition1)) \\ ((calls1 bound_d33) = (message_delete bound_m11)))\n \\ (bound_d33 \\ (happensBefore1 bound_c235))))))\n \\ (bound_c135 \\ (happensBefore1 bound_c235))))))))))\"\n\nassumes message_author_mv_contains_res_8:\n\n\"(\\bound_m11.\n (\\bound_a25.\n (((message_author_mv_contains_res7 bound_m11) bound_a25)\n = (\\bound_c136.\n (((bound_c136 \\ (vis \\ snapshotAddition1))\n \\ (((calls1 bound_c136) = (message_author_assign bound_m11 bound_a25))\n \\ (\\bound_d34.\n (((bound_d34 \\ (vis \\ snapshotAddition1)) \\ ((calls1 bound_d34) = (message_delete bound_m11)))\n \\ (bound_d34 \\ (happensBefore1 bound_c136))))))\n \\ \\(\\bound_c236.\n (\\bound_anyArgs11.\n ((((bound_c236 \\ (vis \\ snapshotAddition1)) \\ (bound_c136 \\ bound_c236))\n \\ (((calls1 bound_c236) = (message_author_assign bound_m11 bound_anyArgs11))\n \\ (\\bound_d35.\n (((bound_d35 \\ (vis \\ snapshotAddition1)) \\ ((calls1 bound_d35) = (message_delete bound_m11)))\n \\ (bound_d35 \\ (happensBefore1 bound_c236))))))\n \\ (bound_c136 \\ (happensBefore1 bound_c236))))))))))\"\n\nassumes at_transaction_begin_invariant_1:\n\n\"((\\bound_m10.\n (\\bound_a14.\n (\\bound_a24.\n ((((message_exists_res4 bound_m10) \\ ((message_author_mv_contains_res4 bound_m10) bound_a14))\n \\ ((message_author_mv_contains_res5 bound_m10) bound_a24))\n \\ (bound_a14 = bound_a24)))))\n \\ (\\bound_m11.\n (\\bound_a15.\n (\\bound_a25.\n ((((message_exists_res5 bound_m11) \\ ((message_author_mv_contains_res6 bound_m11) bound_a15))\n \\ ((message_author_mv_contains_res7 bound_m11) bound_a25))\n \\ (bound_a15 = bound_a25))))))\"\n\nassumes chat_messages_contains_res_3:\n\n\"(\\bound_c37.\n (\\bound_m8.\n (((chat_messages_contains_res2 bound_c37) bound_m8)\n = (\\bound_c127.\n (((bound_c127 \\ snapshotAddition1)\n \\ (((calls1 bound_c127) = (chat_messages_add bound_c37 bound_m8))\n \\ (\\bound_d24.\n (((bound_d24 \\ snapshotAddition1) \\ ((calls1 bound_d24) = (chat_delete bound_c37)))\n \\ (bound_d24 \\ (happensBefore1 bound_c127))))))\n \\ (\\bound_c227.\n (((bound_c227 \\ snapshotAddition1)\n \\ (((calls1 bound_c227) = (chat_messages_remove bound_c37 bound_m8))\n \\ (\\bound_d25.\n (((bound_d25 \\ snapshotAddition1) \\ ((calls1 bound_d25) = (chat_delete bound_c37)))\n \\ (bound_d25 \\ (happensBefore1 bound_c227))))))\n \\ (bound_c227 \\ (happensBefore1 bound_c127)))))))))\"\n\nassumes message_exists_res_7:\n\n\"(\\bound_m8.\n ((message_exists_res6 bound_m8)\n = (\\bound_c128.\n (((((bound_c128 \\ snapshotAddition1)\n \\ (\\bound_args24. ((calls1 bound_c128) = (message_author_assign bound_m8 bound_args24))))\n \\ ((bound_c128 \\ snapshotAddition1)\n \\ (\\bound_args25. ((calls1 bound_c128) = (message_content_assign bound_m8 bound_args25)))))\n \\ ((bound_c128 \\ snapshotAddition1)\n \\ (\\bound_args26. ((calls1 bound_c128) = (message_chat_assign bound_m8 bound_args26)))))\n \\ (\\bound_c228.\n (((bound_c228 \\ snapshotAddition1) \\ ((calls1 bound_c228) = (message_delete bound_m8)))\n \\ (bound_c228 \\ (happensBefore1 bound_c128))))))))\"\n\nassumes chat_messages_contains_res_4:\n\n\"(\\bound_c38.\n (\\bound_m9.\n (((chat_messages_contains_res3 bound_c38) bound_m9)\n = (\\bound_c129.\n (((bound_c129 \\ (vis \\ snapshotAddition1))\n \\ (((calls1 bound_c129) = (chat_messages_add bound_c38 bound_m9))\n \\ (\\bound_d26.\n (((bound_d26 \\ (vis \\ snapshotAddition1)) \\ ((calls1 bound_d26) = (chat_delete bound_c38)))\n \\ (bound_d26 \\ (happensBefore1 bound_c129))))))\n \\ (\\bound_c229.\n (((bound_c229 \\ (vis \\ snapshotAddition1))\n \\ (((calls1 bound_c229) = (chat_messages_remove bound_c38 bound_m9))\n \\ (\\bound_d27.\n (((bound_d27 \\ (vis \\ snapshotAddition1)) \\ ((calls1 bound_d27) = (chat_delete bound_c38)))\n \\ (bound_d27 \\ (happensBefore1 bound_c229))))))\n \\ (bound_c229 \\ (happensBefore1 bound_c129)))))))))\"\n\nassumes message_exists_res_8:\n\n\"(\\bound_m9.\n ((message_exists_res7 bound_m9)\n = (\\bound_c130.\n (((((bound_c130 \\ (vis \\ snapshotAddition1))\n \\ (\\bound_args27. ((calls1 bound_c130) = (message_author_assign bound_m9 bound_args27))))\n \\ ((bound_c130 \\ (vis \\ snapshotAddition1))\n \\ (\\bound_args28. ((calls1 bound_c130) = (message_content_assign bound_m9 bound_args28)))))\n \\ ((bound_c130 \\ (vis \\ snapshotAddition1))\n \\ (\\bound_args29. ((calls1 bound_c130) = (message_chat_assign bound_m9 bound_args29)))))\n \\ (\\bound_c230.\n (((bound_c230 \\ (vis \\ snapshotAddition1)) \\ ((calls1 bound_c230) = (message_delete bound_m9)))\n \\ (bound_c230 \\ (happensBefore1 bound_c130))))))))\"\n\nassumes at_transaction_begin_invariant_0:\n\n\"((\\bound_c37. (\\bound_m8. (((chat_messages_contains_res2 bound_c37) bound_m8) \\ (message_exists_res6 bound_m8))))\n \\ (\\bound_c38. (\\bound_m9. (((chat_messages_contains_res3 bound_c38) bound_m9) \\ (message_exists_res7 bound_m9)))))\"\n\nassumes no_new_calls_addded_to_current:\n\n\"((invocationCalls currentInvocation) = (invocationCalls1 currentInvocation))\"\n\nassumes no_new_transactions_added_to_current:\n\n\"(\\bound_t.\n (((transactionOrigin bound_t) = (Some currentInvocation)) = ((transactionOrigin1 bound_t) = (Some currentInvocation))))\"\n\nassumes tx_fresh:\n\n\"((transactionOrigin1 tx) = None)\"\n\nassumes vis_update:\n\n\"(vis = ({} \\ newCalls))\"\n\nassumes new_transactions_exist:\n\n\"(newTxns \\ (dom transactionOrigin1))\"\n\nassumes m_new_id_fresh:\n\n\"((generatedIds_MessageId1 m) = None)\"\n\nassumes c0_freshB:\n\n\"((calls1 c0) = no_call)\"\n\nassumes c0_freshA:\n\n\"distinct [c0]\"\n\nassumes calls:\n\n\"(calls2 = (calls1(c0 := (message_author_assign m from_init))))\"\n\nassumes c11_freshB:\n\n\"((calls2 c11) = no_call)\"\n\nassumes c11_freshA:\n\n\"distinct [c11 , c0]\"\n\nassumes calls_2:\n\n\"(calls3 = (calls2(c11 := (message_content_assign m content_init))))\"\n\nassumes c21_freshB:\n\n\"((calls3 c21) = no_call)\"\n\nassumes c21_freshA:\n\n\"distinct [c21 , c0 , c11]\"\n\nassumes calls_3:\n\n\"(calls4 = (calls3(c21 := (message_chat_assign m toC_init))))\"\n\nassumes c31_freshB:\n\n\"((calls4 c31) = no_call)\"\n\nassumes c31_freshA:\n\n\"distinct [c31 , c0 , c11 , c21]\"\n\nassumes calls_4:\n\n\"(calls5 = (calls4(c31 := (chat_messages_add toC_init m))))\"\n\nassumes vis:\n\n\"(vis1 = (vis \\ {c0}))\"\n\nassumes vis_2:\n\n\"(vis2 = (vis1 \\ {c11}))\"\n\nassumes vis_3:\n\n\"(vis3 = (vis2 \\ {c21}))\"\n\nassumes happensBefore:\n\n\"(happensBefore2 = (happensBefore1(c0 := (vis \\ {c0}))))\"\n\nassumes happensBefore_2:\n\n\"(happensBefore3 = (happensBefore2(c11 := (vis1 \\ {c11}))))\"\n\nassumes happensBefore_3:\n\n\"(happensBefore4 = (happensBefore3(c21 := (vis2 \\ {c21}))))\"\n\nassumes happensBefore_4:\n\n\"(happensBefore5 = (happensBefore4(c31 := (vis3 \\ {c31}))))\"\n\nassumes chat_messages_contains_res_5:\n\n\"(\\bound_c65.\n (\\bound_m12.\n (((chat_messages_contains_res4 bound_c65) bound_m12)\n = (\\bound_c151.\n (((bound_c151 \\ snapshotAddition1)\n \\ (((calls5 bound_c151) = (chat_messages_add bound_c65 bound_m12))\n \\ (\\bound_d36.\n (((bound_d36 \\ snapshotAddition1) \\ ((calls5 bound_d36) = (chat_delete bound_c65)))\n \\ (bound_d36 \\ (happensBefore5 bound_c151))))))\n \\ (\\bound_c251.\n (((bound_c251 \\ snapshotAddition1)\n \\ (((calls5 bound_c251) = (chat_messages_remove bound_c65 bound_m12))\n \\ (\\bound_d37.\n (((bound_d37 \\ snapshotAddition1) \\ ((calls5 bound_d37) = (chat_delete bound_c65)))\n \\ (bound_d37 \\ (happensBefore5 bound_c251))))))\n \\ (bound_c251 \\ (happensBefore5 bound_c151)))))))))\"\n\nassumes message_exists_res_9:\n\n\"(\\bound_m12.\n ((message_exists_res8 bound_m12)\n = (\\bound_c152.\n (((((bound_c152 \\ snapshotAddition1)\n \\ (\\bound_args36. ((calls5 bound_c152) = (message_author_assign bound_m12 bound_args36))))\n \\ ((bound_c152 \\ snapshotAddition1)\n \\ (\\bound_args37. ((calls5 bound_c152) = (message_content_assign bound_m12 bound_args37)))))\n \\ ((bound_c152 \\ snapshotAddition1)\n \\ (\\bound_args38. ((calls5 bound_c152) = (message_chat_assign bound_m12 bound_args38)))))\n \\ (\\bound_c252.\n (((bound_c252 \\ snapshotAddition1) \\ ((calls5 bound_c252) = (message_delete bound_m12)))\n \\ (bound_c252 \\ (happensBefore5 bound_c152))))))))\"\n\nassumes vis_4:\n\n\"(vis4 = (vis3 \\ {c31}))\"\n\nassumes chat_messages_contains_res_6:\n\n\"(\\bound_c66.\n (\\bound_m13.\n (((chat_messages_contains_res5 bound_c66) bound_m13)\n = (\\bound_c153.\n (((bound_c153 \\ (vis4 \\ snapshotAddition1))\n \\ (((calls5 bound_c153) = (chat_messages_add bound_c66 bound_m13))\n \\ (\\bound_d38.\n (((bound_d38 \\ (vis4 \\ snapshotAddition1)) \\ ((calls5 bound_d38) = (chat_delete bound_c66)))\n \\ (bound_d38 \\ (happensBefore5 bound_c153))))))\n \\ (\\bound_c253.\n (((bound_c253 \\ (vis4 \\ snapshotAddition1))\n \\ (((calls5 bound_c253) = (chat_messages_remove bound_c66 bound_m13))\n \\ (\\bound_d39.\n (((bound_d39 \\ (vis4 \\ snapshotAddition1)) \\ ((calls5 bound_d39) = (chat_delete bound_c66)))\n \\ (bound_d39 \\ (happensBefore5 bound_c253))))))\n \\ (bound_c253 \\ (happensBefore5 bound_c153)))))))))\"\n\nassumes message_exists_res_10:\n\n\"(\\bound_m13.\n ((message_exists_res9 bound_m13)\n = (\\bound_c154.\n (((((bound_c154 \\ (vis4 \\ snapshotAddition1))\n \\ (\\bound_args39. ((calls5 bound_c154) = (message_author_assign bound_m13 bound_args39))))\n \\ ((bound_c154 \\ (vis4 \\ snapshotAddition1))\n \\ (\\bound_args40. ((calls5 bound_c154) = (message_content_assign bound_m13 bound_args40)))))\n \\ ((bound_c154 \\ (vis4 \\ snapshotAddition1))\n \\ (\\bound_args41. ((calls5 bound_c154) = (message_chat_assign bound_m13 bound_args41)))))\n \\ (\\bound_c254.\n (((bound_c254 \\ (vis4 \\ snapshotAddition1)) \\ ((calls5 bound_c254) = (message_delete bound_m13)))\n \\ (bound_c254 \\ (happensBefore5 bound_c154))))))))\"\n\nassumes invariant_not_violated:\n\n\"\\((\\bound_c65. (\\bound_m12. (((chat_messages_contains_res4 bound_c65) bound_m12) \\ (message_exists_res8 bound_m12))))\n \\ (\\bound_c66. (\\bound_m13. (((chat_messages_contains_res5 bound_c66) bound_m13) \\ (message_exists_res9 bound_m13)))))\"\nshows False\n using invariant_not_violated\nproof (rule notE)\n have \"c0 \\ snapshotAddition1\"\n using c0_freshB transaction_begin_snapshot_addition_subset_calls by auto\n have \"c11 \\ snapshotAddition1\"\n using c11_freshA c11_freshB calls transaction_begin_snapshot_addition_subset_calls by auto\n have \"c21 \\ snapshotAddition1\"\n using c21_freshA c21_freshB calls calls_2 transaction_begin_snapshot_addition_subset_calls by auto\n have \"c31 \\ snapshotAddition1\"\n using c31_freshA c31_freshB calls calls_2 calls_3 transaction_begin_snapshot_addition_subset_calls by auto\n\n\n have s0[simp]:\"x \\ c0\" if \"x \\ snapshotAddition1\" for x\n using \\c0 \\ snapshotAddition1\\ that by blast\n have s2[simp]:\"x \\ c11\" if \"x \\ snapshotAddition1\" for x\n using \\c11 \\ snapshotAddition1\\ that by blast\n have s2[simp]:\"x \\ c21\" if \"x \\ snapshotAddition1\" for x\n using \\c21 \\ snapshotAddition1\\ that by blast\n have s3[simp]:\"x \\ c31\" if \"x \\ snapshotAddition1\" for x\n using \\c31 \\ snapshotAddition1\\ that by blast\n\n\n from c31_freshA have [simp]: \"c31 \\ c0\" by simp\n from c31_freshA have [simp]: \"c0 \\ c11\" by simp\n from c31_freshA have [simp]: \"c0 \\ c21\" by simp\n from c31_freshA have [simp]: \"c0 \\ c31\" by force \n from c31_freshA have [simp]: \"c11 \\ c21\" by simp\n from c31_freshA have [simp]: \"c11 \\ c31\" by force\n from c31_freshA have [simp]: \"c21 \\ c31\" by force\n\n have [simp]: \"c0 \\ vis\"\n using c0_freshB transaction_begin_visibleCalls_exist by blast\n have [simp]: \"c21 \\ vis\"\n by (metis \\c0 \\ c21\\ \\c11 \\ c21\\ c21_freshB calls calls_2 fun_upd_apply transaction_begin_visibleCalls_exist)\n\n have [simp]: \"c11 \\ vis\"\n by (metis \\c0 \\ c11\\ c11_freshB calls fun_upd_apply transaction_begin_visibleCalls_exist)\n\n have [simp]: \"c31 \\ vis\"\n by (metis \\c11 \\ c31\\ \\c21 \\ c31\\ \\c31 \\ c0\\ assms(102) assms(105) assms(108) assms(109) assms(78) fun_upd_apply)\n\n\n show \"(\\bound_c65 bound_m12. chat_messages_contains_res4 bound_c65 bound_m12 \\ message_exists_res8 bound_m12) \\\n (\\bound_c66 bound_m13. chat_messages_contains_res5 bound_c66 bound_m13 \\ message_exists_res9 bound_m13)\"\n proof (intro allI conjI impI)\n fix c m\n assume a1: \"chat_messages_contains_res4 c m\"\n\n\n\n from a1 have \"chat_messages_contains_res2 c m\"\n apply (auto simp add: chat_messages_contains_res_5 chat_messages_contains_res_3)\n apply (auto simp add: calls_4 calls_3 calls_2 calls cong: conj_cong)\n apply (auto simp add: happensBefore_4 happensBefore_3 happensBefore_2 happensBefore )\n done\n\n find_theorems \" happensBefore5 \"\n\n find_theorems calls2\n\n have \"chat_messages_contains_res2 c m \\ message_exists_res6 m\"\n by (simp add: at_transaction_begin_invariant_0)\n\n hence \"message_exists_res6 m\"\n using \\chat_messages_contains_res2 c m\\ by blast\n\n from `message_exists_res6 m` \n show \"message_exists_res8 m\"\n apply (auto simp add: message_exists_res_7 message_exists_res_9)\n apply (auto simp add: calls_4 calls_3 calls_2 calls happensBefore_4 happensBefore_3 happensBefore_2 happensBefore cong: conj_cong)\n using \\c11 \\ snapshotAddition1\\ s0 s2 s3 apply blast\n using \\c0 \\ snapshotAddition1\\ \\c11 \\ snapshotAddition1\\ \\c21 \\ snapshotAddition1\\ \\c31 \\ snapshotAddition1\\ apply auto[1]\n using \\c11 \\ snapshotAddition1\\ s0 s2 s3 by blast\n next\n fix c m\n assume a1: \"chat_messages_contains_res5 c m\"\n\n from a1 obtain cm\n where c1: \"(cm \\ vis4 \\ cm \\ snapshotAddition1)\"\n and c2: \"calls5 cm = chat_messages_add c m\"\n and c3: \"(\\bound_d38. (bound_d38 \\ vis4 \\ bound_d38 \\ snapshotAddition1) \\ calls5 bound_d38 = chat_delete c \\ bound_d38 \\ happensBefore5 cm)\"\n and c4: \"\n (\\bound_c253.\n (bound_c253 \\ vis4 \\ bound_c253 \\ snapshotAddition1) \\\n calls5 bound_c253 = chat_messages_remove c m \\\n (\\bound_d39. (bound_d39 \\ vis4 \\ bound_d39 \\ snapshotAddition1) \\ calls5 bound_d39 = chat_delete c \\ bound_d39 \\ happensBefore5 bound_c253) \\\n bound_c253 \\ happensBefore5 cm)\"\n by (auto simp add: chat_messages_contains_res_6)\n\n show \" message_exists_res9 m\"\n proof (cases \"cm \\ snapshotAddition1\")\n case True\n from a1 c2 c3 c4 have \"chat_messages_contains_res3 c m\"\n apply (auto simp add: chat_messages_contains_res_6 chat_messages_contains_res_4)\n apply (auto simp add: calls_4 calls_3 calls_2 calls happensBefore_4 happensBefore_3 happensBefore_2 happensBefore cong: conj_cong)\n using True \\c31 \\ snapshotAddition1\\ apply (auto simp add: split: if_splits)\n using m_new_id_fresh transaction_begin_chat_messages_add_call_parameter_elem_generated apply auto[1]\n apply (rule_tac x=bound_c153 in exI)\n apply (auto simp add: vis vis_2 vis_3 vis_4)\n using \\c11 \\ snapshotAddition1\\ \\c21 \\ snapshotAddition1\\ c0_freshB transaction_begin_snapshot_addition_subset_calls apply blast\n apply (smt \\c21 \\ snapshotAddition1\\ c0_freshB c11_freshB calls fun_upd_apply transaction_begin_snapshot_addition_subset_calls)\n\n apply (rule_tac x=bound_c153 in exI)\n apply (auto simp add: vis vis_2 vis_3 vis_4)\n apply (metis \\c11 \\ snapshotAddition1\\ s0 s2)\n by (metis \\c21 \\ snapshotAddition1\\ c0_freshB c11_freshB calls fun_upd_apply transaction_begin_snapshot_addition_subset_calls)\n also have \"chat_messages_contains_res3 c m \\ message_exists_res7 m\"\n by (simp add: at_transaction_begin_invariant_0)\n ultimately have \"message_exists_res7 m\"\n by simp\n thus \"message_exists_res9 m\"\n apply (auto simp add: message_exists_res_10 message_exists_res_8)\n apply (auto simp add: calls_4 calls_3 calls_2 calls happensBefore_4 happensBefore_3 happensBefore_2 happensBefore vis vis_2 vis_3 vis_4 cong: conj_cong)\n apply (smt c0_freshB c11_freshB c21_freshB c31_freshB calls calls_2 calls_3 fun_upd_apply transaction_begin_visibleCalls_exist)\n apply (smt \\c11 \\ snapshotAddition1\\ \\c21 \\ snapshotAddition1\\ \\c31 \\ snapshotAddition1\\ c0_freshB transaction_begin_snapshot_addition_subset_calls)\n apply (smt c0_freshB c11_freshB c21_freshB c31_freshB calls calls_2 calls_3 fun_upd_apply transaction_begin_visibleCalls_exist)\n apply (smt \\c11 \\ snapshotAddition1\\ \\c21 \\ snapshotAddition1\\ \\c31 \\ snapshotAddition1\\ c0_freshB transaction_begin_snapshot_addition_subset_calls)\n apply (smt c0_freshB c11_freshB c21_freshB c31_freshB calls calls_2 calls_3 fun_upd_apply transaction_begin_visibleCalls_exist)\n by (smt \\c11 \\ snapshotAddition1\\ \\c21 \\ snapshotAddition1\\ \\c31 \\ snapshotAddition1\\ c0_freshB transaction_begin_snapshot_addition_subset_calls)\n\n next\n case False\n hence \"cm \\ snapshotAddition1\" .\n hence \"cm \\ vis4\"\n using c1 by auto\n show \"message_exists_res9 m\"\n proof (cases \"cm \\ vis\")\n case True\n\n\n\n from a1 c2 c3 c4 have \"chat_messages_contains_res3 c m\"\n apply (auto simp add: chat_messages_contains_res_6 chat_messages_contains_res_4)\n apply (auto simp add: calls_4 calls_3 calls_2 calls happensBefore_4 happensBefore_3 happensBefore_2 happensBefore cong: conj_cong)\n using True \\c31 \\ snapshotAddition1\\ apply (auto simp add: split: if_splits)\n using m_new_id_fresh transaction_begin_chat_messages_add_call_parameter_elem_generated apply auto[1]\n apply (rule_tac x=bound_c153 in exI)\n apply (auto simp add: vis vis_2 vis_3 vis_4)\n using \\c11 \\ snapshotAddition1\\ \\c21 \\ snapshotAddition1\\ c0_freshB transaction_begin_snapshot_addition_subset_calls apply blast\n apply (smt \\c21 \\ snapshotAddition1\\ c0_freshB c11_freshB calls fun_upd_apply transaction_begin_snapshot_addition_subset_calls)\n\n apply (rule_tac x=bound_c153 in exI)\n apply (auto simp add: vis vis_2 vis_3 vis_4)\n apply (metis \\c11 \\ snapshotAddition1\\ s0 s2)\n by (metis \\c21 \\ snapshotAddition1\\ c0_freshB c11_freshB calls fun_upd_apply transaction_begin_snapshot_addition_subset_calls)\n also have \"chat_messages_contains_res3 c m \\ message_exists_res7 m\"\n by (simp add: at_transaction_begin_invariant_0)\n ultimately have \"message_exists_res7 m\"\n by simp\n thus \"message_exists_res9 m\"\n apply (auto simp add: message_exists_res_10 message_exists_res_8)\n apply (auto simp add: calls_4 calls_3 calls_2 calls happensBefore_4 happensBefore_3 happensBefore_2 happensBefore vis vis_2 vis_3 vis_4 cong: conj_cong)\n apply (smt c0_freshB c11_freshB c21_freshB c31_freshB calls calls_2 calls_3 fun_upd_apply transaction_begin_visibleCalls_exist)\n apply (smt \\c11 \\ snapshotAddition1\\ \\c21 \\ snapshotAddition1\\ \\c31 \\ snapshotAddition1\\ c0_freshB transaction_begin_snapshot_addition_subset_calls)\n apply (smt c0_freshB c11_freshB c21_freshB c31_freshB calls calls_2 calls_3 fun_upd_apply transaction_begin_visibleCalls_exist)\n apply (smt \\c11 \\ snapshotAddition1\\ \\c21 \\ snapshotAddition1\\ \\c31 \\ snapshotAddition1\\ c0_freshB transaction_begin_snapshot_addition_subset_calls)\n apply (smt c0_freshB c11_freshB c21_freshB c31_freshB calls calls_2 calls_3 fun_upd_apply transaction_begin_visibleCalls_exist)\n by (smt \\c11 \\ snapshotAddition1\\ \\c21 \\ snapshotAddition1\\ \\c31 \\ snapshotAddition1\\ c0_freshB transaction_begin_snapshot_addition_subset_calls)\n\n next\n case False\n with c2 c3 c4 show ?thesis\n apply (auto simp add: message_exists_res_10)\n apply (rule_tac x=c21 in exI)\n apply (auto simp add: )\n apply (auto simp add: vis_3 vis_4)[7]\n using \\cm \\ snapshotAddition1\\ c1 calls calls_2 calls_3 calls_4 vis vis_2 vis_3 vis_4 apply force\n using calls_4 happensBefore_3 happensBefore_4 vis_3 vis_4 apply force\n using \\cm \\ snapshotAddition1\\ c0_freshB c1 c11_freshB callInfo.distinct(143) callInfo.distinct(159) calls calls_2 calls_3 calls_4 fun_upd_apply m_new_id_fresh transaction_begin_message_delete_call_parameter_key_generated vis vis_2 vis_3 vis_4 by fastforce\n qed\n qed\n qed\nqed\n\n","avg_line_length":48.8733031674,"max_line_length":286,"alphanum_fraction":0.6557726136} {"size":22194,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/n_flash_lemma_inv__159_on_rules.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_flash Protocol Case Study*} \n\ntheory n_flash_lemma_inv__159_on_rules imports n_flash_lemma_on_inv__159\nbegin\nsection{*All lemmas on causal relation between inv__159*}\nlemma lemma_inv__159_on_rules:\n assumes b1: \"r \\ rules N\" and b2: \"(\\ p__Inv4. p__Inv4\\N\\f=inv__159 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n proof -\n have c1: \"(\\ src data. src\\N\\data\\N\\r=n_Store src data)\\\n (\\ data. data\\N\\r=n_Store_Home data)\\\n (\\ src. src\\N\\r=n_PI_Remote_Get src)\\\n (\\ src. src\\N\\r=n_PI_Remote_GetX src)\\\n (\\ dst. dst\\N\\r=n_PI_Remote_PutX dst)\\\n (\\ src. src\\N\\r=n_PI_Remote_Replace src)\\\n (\\ dst. dst\\N\\r=n_NI_Nak dst)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__0 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__1 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__2 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Get__part__0 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Get__part__1 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Put_Head N src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Put src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Put_Dirty src)\\\n (\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Nak src dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_Get_Nak_Home dst)\\\n (\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Put src dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_Get_Put_Home dst)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__0 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__1 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__2 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__0 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__1 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_1 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_2 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_3 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_4 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_5 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_6 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__0 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__1 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src)\\\n (\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8 N src pp)\\\n (\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__0 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__1 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_10_Home N src)\\\n (\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_10 N src pp)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_11 N src)\\\n (\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_Nak src dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_GetX_Nak_Home dst)\\\n (\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_PutX src dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_GetX_PutX_Home dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_Put dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_PutX dst)\\\n (\\ dst. dst\\N\\r=n_NI_Inv dst)\\\n (\\ src. src\\N\\r=n_NI_InvAck_exists_Home src)\\\n (\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_InvAck_exists src pp)\\\n (\\ src. src\\N\\r=n_NI_InvAck_1 N src)\\\n (\\ src. src\\N\\r=n_NI_InvAck_2 N src)\\\n (\\ src. src\\N\\r=n_NI_InvAck_3 N src)\\\n (\\ src. src\\N\\r=n_NI_Replace src)\\\n (r=n_PI_Local_Get_Get )\\\n (r=n_PI_Local_Get_Put )\\\n (r=n_PI_Local_GetX_GetX__part__0 )\\\n (r=n_PI_Local_GetX_GetX__part__1 )\\\n (r=n_PI_Local_GetX_PutX_HeadVld__part__0 N )\\\n (r=n_PI_Local_GetX_PutX_HeadVld__part__1 N )\\\n (r=n_PI_Local_GetX_PutX__part__0 )\\\n (r=n_PI_Local_GetX_PutX__part__1 )\\\n (r=n_PI_Local_PutX )\\\n (r=n_PI_Local_Replace )\\\n (r=n_NI_Nak_Home )\\\n (r=n_NI_Nak_Clear )\\\n (r=n_NI_Local_Put )\\\n (r=n_NI_Local_PutXAcksDone )\\\n (r=n_NI_Wb )\\\n (r=n_NI_FAck )\\\n (r=n_NI_ShWb N )\\\n (r=n_NI_Replace_Home )\"\n apply (cut_tac b1, auto) done\n moreover {\n assume d1: \"(\\ src data. src\\N\\data\\N\\r=n_Store src data)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_StoreVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ data. data\\N\\r=n_Store_Home data)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_Store_HomeVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_PI_Remote_Get src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Remote_GetVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_PI_Remote_GetX src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Remote_GetXVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_PI_Remote_PutX dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Remote_PutXVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_PI_Remote_Replace src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Remote_ReplaceVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Nak dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_NakVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__0 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Nak__part__0Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__1 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Nak__part__1Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__2 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Nak__part__2Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Get__part__0 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Get__part__0Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Get__part__1 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Get__part__1Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Put_Head N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Put_HeadVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Put src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_PutVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Put_Dirty src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Put_DirtyVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Nak src dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_Get_NakVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_Get_Nak_Home dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_Get_Nak_HomeVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Put src dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_Get_PutVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_Get_Put_Home dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_Get_Put_HomeVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__0 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_Nak__part__0Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__1 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_Nak__part__1Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__2 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_Nak__part__2Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__0 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_GetX__part__0Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__1 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_GetX__part__1Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_1Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_2 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_2Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_3 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_3Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_4 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_4Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_5 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_5Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_6 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_6Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__0 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_7__part__0Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_7__part__1Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_7_NODE_Get__part__0Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_7_NODE_Get__part__1Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_8_HomeVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_8_Home_NODE_GetVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8 N src pp)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_8Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_8_NODE_GetVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__0 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_9__part__0Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_9__part__1Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_10_Home N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_10_HomeVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_10 N src pp)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_10Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_11 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_11Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_Nak src dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_GetX_NakVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_GetX_Nak_Home dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_GetX_Nak_HomeVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_PutX src dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_GetX_PutXVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_GetX_PutX_Home dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_GetX_PutX_HomeVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_Put dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_PutVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_PutX dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_PutXVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Inv dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_InvAck_exists_Home src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_exists_HomeVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_InvAck_exists src pp)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_existsVsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_InvAck_1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_1Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_InvAck_2 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_2Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_InvAck_3 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_3Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Replace src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_ReplaceVsinv__159) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_Get_Get )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_Get_GetVsinv__159) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_Get_Put )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_Get_PutVsinv__159) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_GetX__part__0 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_GetX__part__0Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_GetX__part__1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_GetX__part__1Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_PutX_HeadVld__part__0 N )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_PutX_HeadVld__part__0Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_PutX_HeadVld__part__1 N )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_PutX_HeadVld__part__1Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_PutX__part__0 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_PutX__part__0Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_PutX__part__1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_PutX__part__1Vsinv__159) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_PutX )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_PutXVsinv__159) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_Replace )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_ReplaceVsinv__159) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Nak_Home )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Nak_HomeVsinv__159) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Nak_Clear )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Nak_ClearVsinv__159) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Local_Put )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_PutVsinv__159) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Local_PutXAcksDone )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_PutXAcksDoneVsinv__159) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Wb )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_WbVsinv__159) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_FAck )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_FAckVsinv__159) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_ShWb N )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_ShWbVsinv__159) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Replace_Home )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Replace_HomeVsinv__159) done\n }\n\n ultimately show \"invHoldForRule s f r (invariants N)\"\n by satx\nqed\n\nend\n","avg_line_length":41.1762523191,"max_line_length":132,"alphanum_fraction":0.6640533478} {"size":280,"ext":"thy","lang":"Isabelle","max_stars_count":102.0,"content":"(*\n Authors: Wenda Li\n*)\n\ntheory amc12b_2003_p9 imports\n Complex_Main\nbegin\n\ntheorem amc12b_2003_p9:\n fixes a b ::real and f :: \"real \\ real\"\n assumes \"\\ x. f x = a * x + b\"\n and \" f 6 - f 2 = 12\"\n shows \"f 12 - f 2 = 30\"\n using assms by auto\n \nend \n","avg_line_length":16.4705882353,"max_line_length":53,"alphanum_fraction":0.6107142857} {"size":207,"ext":"thy","lang":"Isabelle","max_stars_count":10.0,"content":"theory Universe_Instances_Bounded_Operators\n imports Complex_Bounded_Operators.Complex_L2 Universe_Instances_Complex_Main\nbegin\n\nderive universe ell2\nderive universe ccsubspace\nderive universe cblinfun\n\nend","avg_line_length":23.0,"max_line_length":78,"alphanum_fraction":0.9033816425} {"size":5890,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"(*************************************************************************\n * Copyright (C) \n * 2019 The University of Exeter \n * 2018-2019 The University of Paris-Saclay\n * 2018 The University of Sheffield\n *\n * License:\n * This program can be redistributed and\/or modified under the terms\n * of the 2-clause BSD-style license.\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *************************************************************************)\n\nchapter\\Term Antiquotations\\\n\ntext\\Terms are represented by \"Inner Syntax\" parsed by an Earley parser in Isabelle.\nFor historical reasons, \\<^emph>\\term antiquotations\\ are called therefore somewhat misleadingly\n\"Inner Syntax Antiquotations\". \\\n\ntheory \n TermAntiquotations\nimports \n \"Isabelle_DOF.Conceptual\"\nbegin\n\ntext\\Since the syntax chosen for values of doc-class attributes is HOL-syntax --- requiring\na fast read on the ``What's in Main''-documentation, but not additional knowledge on, say, SML --- \nan own syntax for references to types, terms, theorems, etc. are necessary. These are the\n``Inner Syntax Antiquotations'' since they make only sense \\emph{inside} the Inner-Syntax\nof Isabelle\/Isar, so inside the \\verb+\" ... \"+ parenthesis.\n\nThey are the key-mechanism to denote \n\\<^item> Ontological Links, i.e. attributes refering to document classes defined by the ontology\n\\<^item> Ontological F-Links, i.e. attributes referring to formal entities inside Isabelle (such as thm's)\n\nThis file contains a number of examples resulting from the \n% @ {theory \"Isabelle_DOF-tests.Conceptual\"} does not work here --- why ?\n\\<^theory_text>\\Conceptual\\ - ontology; the emphasis of this presentation is to present the expressivity of \nODL on a paradigmatical example.\n\\\n\n\ntext\\Voila the content of the Isabelle_DOF environment so far:\\\nML\\ \nval {docobj_tab={tab = x, ...},docclass_tab, ISA_transformer_tab,...} = DOF_core.get_data @{context}; \n Symtab.dest ISA_transformer_tab; \n\\\n\ntext\\Some sample lemma:\\\nlemma murks : \"Example=Example\" by simp\n\ntext\\Example for a meta-attribute of ODL-type @{typ \"file\"} with an appropriate ISA for the\n file @{file \"TermAntiquotations.thy\"}\\\n(* not working: \ntext*[xcv::F, u=\"@{file ''InnerSyntaxAntiquotations.thy''}\"]\\Lorem ipsum ...\\\n*)\n\ntext*[xcv1::A, x=5]\\Lorem ipsum ...\\\ntext*[xcv3::A, x=7]\\Lorem ipsum ...\\\n\ntext\\Example for a meta-attribute of ODL-type @{typ \"typ\"} with an appropriate ISA for the\n theorem @{thm \"refl\"}}\\\ntext*[xcv2::C, g=\"@{thm ''HOL.refl''}\"]\\Lorem ipsum ...\\\n\ntext\\A warning about the usage of the \\docitem\\ TA:\nThe \\docitem\\ TA offers a way to check the reference of class instances\nwithout checking the instances type.\nSo one will be able to reference \\docitem\\s (class instances) and have them checked,\nwithout the burden of the type checking required otherwise.\nBut it may give rise to unwanted behaviors, due to its polymorphic type.\nIt must not be used for certification.\n\\\n\ntext\\Major sample: test-item of doc-class \\F\\ with a relational link between class instances, \n and links to formal Isabelle items like \\typ\\, \\term\\ and \\thm\\. \\\ntext*[xcv4::F, r=\"[@{thm ''HOL.refl''}, \n @{thm \\TermAntiquotations.murks\\}]\", (* long names required *)\n b=\"{(@{docitem ''xcv1''},@{docitem \\xcv2\\})}\", (* notations \\...\\ vs. ''...'' *)\n s=\"[@{typ \\int list\\}]\", \n properties = \"[@{term \\H \\ H\\}]\" (* notation \\...\\ required for UTF8*)\n]\\Lorem ipsum ...\\\n\ntext*[xcv5::G, g=\"@{thm \\HOL.sym\\}\"]\\Lorem ipsum ...\\\n\ntext\\... and here we add a relation between @{docitem \\xcv3\\} and @{docitem \\xcv2\\} \ninto the relation \\verb+b+ of @{docitem \\xcv5\\}. Note that in the link-relation,\na @{typ \"C\"}-type is required, but a @{typ \"G\"}-type is offered which is legal in\n\\verb+Isa_DOF+ because of the sub-class relation between those classes: \\\nupdate_instance*[xcv4::F, b+=\"{(@{docitem ''xcv3''},@{docitem ''xcv5''})}\"]\n\ntext\\And here is the results of some ML-term antiquotations:\\\nML\\ @{docitem_attribute b::xcv4} \\\nML\\ @{docitem xcv4} \\\nML\\ @{trace_attribute aaa} \\\n\ntext\\Now we might need to reference a class instance in a term command and we would like\nIsabelle to check that this instance is indeed an instance of this class.\nHere, we want to reference the instance @{docitem \\xcv4\\} previously defined.\nWe can use the term* command which extends the classic term command\nand does the appropriate checking.\\\nterm*\\@{F \\xcv4\\}\\\n\ntext\\We can also reference an attribute of the instance.\nHere we reference the attribute r of the class F which has the type @{typ \\thm list\\}.\\\nterm*\\r @{F \\xcv4\\}\\\n\nterm \\@{A \\xcv2\\}\\\n\ntext\\We declare a new text element. Note that the class name contains an underscore \"_\".\\\ntext*[te::text_element]\\Lorem ipsum...\\\n\ntext\\Unfortunately due to different lexical conventions for constant symbols and mixfix symbols\n this term antiquotation has to be denoted like this: @{term\\@{text-element \\ee\\}\\}.\n We need to substitute an hyphen \"-\" for the underscore \"_\".\\\nterm*\\@{text-element \\te\\}\\\n\nend\n\n","avg_line_length":49.4957983193,"max_line_length":140,"alphanum_fraction":0.6748726655} {"size":9619,"ext":"thy","lang":"Isabelle","max_stars_count":30.0,"content":"theory lscmnec_Lsc__ec__two_point_mult__subprogram_def_WP_parameter_def_6\nimports \"..\/Elliptic_Spec\"\nbegin\n\nwhy3_open \"lscmnec_Lsc__ec__two_point_mult__subprogram_def_WP_parameter_def_6.xml\"\n\nwhy3_vc WP_parameter_def\nproof (simp add: two_point_mult_spec_def Let_def, (rule allI impI)+, goal_cases)\n case (1 b)\n let ?L = \"x1_last - x1_first + 1\"\n def M \\ \"num_of_big_int (word32_to_int \\ elts m) m_first ?L\"\n def A \\ \"num_of_big_int (word32_to_int \\ elts a) a_first ?L\"\n def X\\<^sub>1 \\ \"num_of_big_int (word32_to_int \\ elts x1) x1_first ?L\"\n def Y\\<^sub>1 \\ \"num_of_big_int (word32_to_int \\ elts y1) y1_first ?L\"\n def Z\\<^sub>1 \\ \"num_of_big_int (word32_to_int \\ elts z1) z1_first ?L\"\n def X\\<^sub>2 \\ \"num_of_big_int (word32_to_int \\ elts x2) x2_first ?L\"\n def Y\\<^sub>2 \\ \"num_of_big_int (word32_to_int \\ elts y2) y2_first ?L\"\n def Z\\<^sub>2 \\ \"num_of_big_int (word32_to_int \\ elts z2) z2_first ?L\"\n def X\\<^sub>3\\<^sub>2 \\ \"num_of_big_int (word32_to_int \\ x32) x3_first ?L\"\n def Y\\<^sub>3\\<^sub>2 \\ \"num_of_big_int (word32_to_int \\ y32) y3_first ?L\"\n def Z\\<^sub>3\\<^sub>2 \\ \"num_of_big_int (word32_to_int \\ z32) z3_first ?L\"\n def X\\<^sub>3\\<^sub>3 \\ \"num_of_big_int (word32_to_int \\ x33) x3_first ?L\"\n def Y\\<^sub>3\\<^sub>3 \\ \"num_of_big_int (word32_to_int \\ y33) y3_first ?L\"\n def Z\\<^sub>3\\<^sub>3 \\ \"num_of_big_int (word32_to_int \\ z33) z3_first ?L\"\n def DX\\<^sub>2 \\ \"num_of_big_int (word32_to_int \\ lsc__ec__point_double__x2) 0 ?L\"\n def DY\\<^sub>2 \\ \"num_of_big_int (word32_to_int \\ lsc__ec__point_double__y2) 0 ?L\"\n def DZ\\<^sub>2 \\ \"num_of_big_int (word32_to_int \\ lsc__ec__point_double__z2) 0 ?L\"\n def INV \\ \"minv M (int_of_math_int (base ())) ^ nat ?L\"\n let ?e1 = \"num_of_big_int (word32_to_int \\ elts e1) (o1 + 1) (e1_last - o1)\"\n let ?e2 = \"num_of_big_int (word32_to_int \\ elts e2) (e2_first + (o1 - e1_first) + 1) (e1_last - o1)\"\n let ?a = \"A * INV mod M\"\n\n note defs [symmetric] =\n M_def A_def X\\<^sub>1_def Y\\<^sub>1_def Z\\<^sub>1_def X\\<^sub>2_def Y\\<^sub>2_def Z\\<^sub>2_def\n X\\<^sub>3\\<^sub>2_def Y\\<^sub>3\\<^sub>2_def Z\\<^sub>3\\<^sub>2_def X\\<^sub>3\\<^sub>3_def Y\\<^sub>3\\<^sub>3_def Z\\<^sub>3\\<^sub>3_def\n DX\\<^sub>2_def DY\\<^sub>2_def DZ\\<^sub>2_def\n INV_def\n\n note nonsingular = `ell_field.nonsingular _ _ b` [simplified defs]\n note on_curvep1 = `cring.on_curvep _ _ b (num_of_big_int (word32_to_int \\ elts x1) _ _, _, _)` [simplified defs]\n note on_curvep2 = `cring.on_curvep _ _ b (num_of_big_int (word32_to_int \\ elts x2) _ _, _, _)` [simplified defs]\n note prime = `prime (nat _)` [simplified defs]\n\n then interpret residues_prime_ell \"nat M\" \"residue_ring M\"\n rewrites \"int (nat M) = M\"\n by unfold_locales (insert `2 < _`, simp_all add: defs)\n\n let ?x1 = \"make_affine (X\\<^sub>1, Y\\<^sub>1, Z\\<^sub>1)\"\n let ?x2 = \"make_affine (X\\<^sub>2, Y\\<^sub>2, Z\\<^sub>2)\"\n\n from gt2\n have ge0: \"0 \\ A\" \"0 \\ INV\" \"0 \\ DX\\<^sub>2\" \"0 \\ DY\\<^sub>2\" \"0 \\ DZ\\<^sub>2\"\n \"0 \\ X\\<^sub>3\\<^sub>2\" \"0 \\ Y\\<^sub>3\\<^sub>2\" \"0 \\ Z\\<^sub>3\\<^sub>2\" \"0 \\ X\\<^sub>3\\<^sub>3\" \"0 \\ Y\\<^sub>3\\<^sub>3\" \"0 \\ Z\\<^sub>3\\<^sub>3\"\n by (simp_all add: A_def INV_def DX\\<^sub>2_def DY\\<^sub>2_def DZ\\<^sub>2_def\n X\\<^sub>3\\<^sub>2_def Y\\<^sub>3\\<^sub>2_def Z\\<^sub>3\\<^sub>2_def X\\<^sub>3\\<^sub>3_def Y\\<^sub>3\\<^sub>3_def Z\\<^sub>3\\<^sub>3_def\n num_of_lint_lower word32_to_int_lower base_eq minv_def)\n\n from gt2 have \"2 < M\" by simp\n\n with gt2 have a: \"?a \\ carrier (residue_ring M)\"\n by (simp add: res_carrier_eq defs)\n\n note bM = `b < _` [simplified defs]\n with `0 \\ b`\n have b: \"b \\ carrier (residue_ring M)\"\n by (simp add: res_carrier_eq)\n\n from ge0\n `(num_of_big_int' (Array x32 _) _ _ < _) = _`\n `(num_of_big_int' (Array y32 _) _ _ < _) = _`\n `(num_of_big_int' (Array z32 _) _ _ < _) = _`\n have p\\<^sub>3\\<^sub>2: \"in_carrierp (X\\<^sub>3\\<^sub>2, Y\\<^sub>3\\<^sub>2, Z\\<^sub>3\\<^sub>2)\"\n by (simp add: in_carrierp_def res_carrier_eq defs)\n\n from ge0\n `(num_of_big_int' (Array lsc__ec__point_double__x2 _) _ _ < _) = _`\n `(num_of_big_int' (Array lsc__ec__point_double__y2 _) _ _ < _) = _`\n `(num_of_big_int' (Array lsc__ec__point_double__z2 _) _ _ < _) = _`\n have d\\<^sub>2: \"in_carrierp (DX\\<^sub>2, DY\\<^sub>2, DZ\\<^sub>2)\"\n by (simp add: in_carrierp_def res_carrier_eq defs)\n\n note eq1 =\n `two_point_mult_spec _ _ _ _ _ _ _ _ _ _ (num_of_big_int' (Array x32 _) _ _) _ _ = _`\n [my_simplified two_point_mult_spec_def Let_def prime defs,\n rule_format, OF `2 < M` `0 \\ b` bM nonsingular on_curvep1 on_curvep2,\n my_simplified a b p\\<^sub>3\\<^sub>2 on_curvep1 on_curvep2\n on_curvep_imp_in_carrierp [of ?a b] ppoint_mult_correct [of _ b]\n padd_correct [of _ b] padd_closed\n make_affine_proj_eq_iff, symmetric]\n\n with a b on_curvep1 on_curvep2\n have p\\<^sub>3\\<^sub>2': \"on_curvep ?a b (X\\<^sub>3\\<^sub>2, Y\\<^sub>3\\<^sub>2, Z\\<^sub>3\\<^sub>2)\"\n by (simp add: on_curvep_iff_on_curve [OF a b p\\<^sub>3\\<^sub>2] point_mult_closed add_closed\n on_curvep_iff_on_curve [symmetric])\n\n note eq2 =\n `point_double_spec _ _ (num_of_big_int' (Array x32 _) _ _) _ _ _ _ _ = _`\n [my_simplified point_double_spec_def Let_def defs\n make_affine_proj_eq_iff a p\\<^sub>3\\<^sub>2 d\\<^sub>2 pdouble_in_carrierp pdouble_correct,\n symmetric]\n\n with a b p\\<^sub>3\\<^sub>2'\n have d\\<^sub>2': \"on_curvep ?a b (DX\\<^sub>2, DY\\<^sub>2, DZ\\<^sub>2)\"\n by (simp add: on_curvep_iff_on_curve [OF a b d\\<^sub>2] add_closed\n on_curvep_iff_on_curve [symmetric])\n\n from\n `\\k. _ \\ (_ \\ x33 k = _) \\ _`\n `\\k. _ \\ (_ \\ y33 k = _) \\ _`\n `\\k. _ \\ (_ \\ z33 k = _) \\ _`\n `\\x3__first\\\\<^sub>\\ \\ x3_first`\n `x3_first + (x1_last - x1_first) \\ \\x3__last\\\\<^sub>\\`\n `\\y3__first\\\\<^sub>\\ \\ y3_first`\n `y3_first + (x1_last - x1_first) \\ \\y3__last\\\\<^sub>\\`\n `\\z3__first\\\\<^sub>\\ \\ z3_first`\n `z3_first + (x1_last - x1_first) \\ \\z3__last\\\\<^sub>\\`\n have eq3: \"(X\\<^sub>3\\<^sub>3, Y\\<^sub>3\\<^sub>3, Z\\<^sub>3\\<^sub>3) = (DX\\<^sub>2, DY\\<^sub>2, DZ\\<^sub>2)\"\n by (simp add: X\\<^sub>3\\<^sub>3_def Y\\<^sub>3\\<^sub>3_def Z\\<^sub>3\\<^sub>3_def DX\\<^sub>2_def DY\\<^sub>2_def DZ\\<^sub>2_def num_of_lint_def\n slide_eq mk_bounds_eqs integer_in_range_def)\n\n from eq1 eq2 a b nonsingular on_curvep1 on_curvep2\n have \"make_affine (DX\\<^sub>2, DY\\<^sub>2, DZ\\<^sub>2) =\n add ?a\n (point_mult ?a (nat ((?e1 * 2 ^ nat (31 - j) +\n \\elts e1 o1\\\\<^sub>s div 2 ^ nat (j + 1)) * 2)) ?x1)\n (point_mult ?a (nat ((?e2 * 2 ^ nat (31 - j) +\n \\elts e2 (e2_first + (o1 - e1_first))\\\\<^sub>s div 2 ^ nat (j + 1)) * 2)) ?x2)\"\n by (simp only: nat_mult_distrib [of 2, simplified, simplified mult.commute])\n (simp add: point_mult_mult point_mult2_eq_double word32_to_int_def\n on_curvep_iff_on_curve [symmetric] add_assoc [symmetric] add_comm add_comm'\n add_closed point_mult_closed)\n also from `0 \\ j` `j \\ 31`\n have \"(?e1 * 2 ^ nat (31 - j) +\n \\elts e1 o1\\\\<^sub>s div 2 ^ nat (j + 1)) * 2 =\n ?e1 * 2 ^ nat (31 - j + 1) +\n \\elts e1 o1\\\\<^sub>s div 2 ^ nat j div 2 * 2\"\n by (simp only: nat_add_distrib)\n (simp add: zdiv_zmult2_eq [of 2, simplified mult.commute [of _ 2]])\n also from `(if (if elts e1 o1 AND _ = of_int 0 then _ else _) \\ _ then _ else _) \\ _`\n power_increasing [OF nat_mono [OF `j \\ 31`], of \"2::int\"] `0 \\ j` `j \\ 31`\n have \"\\ = ?e1 * 2 ^ nat (31 - j + 1) +\n \\elts e1 o1\\\\<^sub>s div 2 ^ nat j div 2 * 2 +\n \\elts e1 o1\\\\<^sub>s div 2 ^ nat j mod 2\"\n by (simp add: AND_div_mod word_uint_eq_iff uint_pow uint_and\n word32_to_int_def unat_def uint_word_of_int word_of_int)\n also from `0 \\ j` `j \\ 31`\n have \"(?e2 * 2 ^ nat (31 - j) +\n \\elts e2 (e2_first + (o1 - e1_first))\\\\<^sub>s div 2 ^ nat (j + 1)) * 2 =\n ?e2 * 2 ^ nat (31 - j + 1) +\n \\elts e2 (e2_first + (o1 - e1_first))\\\\<^sub>s div 2 ^ nat j div 2 * 2\"\n by (simp only: nat_add_distrib)\n (simp add: zdiv_zmult2_eq [of 2, simplified mult.commute [of _ 2]])\n also from `(if (if elts e2 (e2_first + (o1 - e1_first)) AND _ = of_int 0\n then _ else _) \\ _ then _ else _) \\ _`\n power_increasing [OF nat_mono [OF `j \\ 31`], of \"2::int\"] `0 \\ j` `j \\ 31`\n have \"\\ = ?e2 * 2 ^ nat (31 - j + 1) +\n \\elts e2 (e2_first + (o1 - e1_first))\\\\<^sub>s div 2 ^ nat j div 2 * 2 +\n \\elts e2 (e2_first + (o1 - e1_first))\\\\<^sub>s div 2 ^ nat j mod 2\"\n by (simp add: AND_div_mod word_uint_eq_iff uint_pow uint_and\n word32_to_int_def unat_def uint_word_of_int word_of_int)\n finally show ?case\n by (simp add: defs make_affine_proj_eq_iff on_curvep1 on_curvep2 eq3 d\\<^sub>2' a b\n ppoint_mult_correct [of _ b] padd_correct [of _ b] on_curvep_imp_in_carrierp [of ?a b]\n padd_closed)\n (simp add: add.commute word32_to_int_def o_def)\nqed\n\nwhy3_end\n\nend\n","avg_line_length":56.2514619883,"max_line_length":171,"alphanum_fraction":0.6354090862} {"size":16489,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"theory Generalised_Binomial_Theorem\nimports Main Complex_Main \n \"~~\/src\/HOL\/Multivariate_Analysis\/Multivariate_Analysis\"\n \"~~\/src\/HOL\/Number_Theory\/Number_Theory\"\n \"~~\/src\/HOL\/Multivariate_Analysis\/Complex_Transcendental\"\n Summation\n Lemma_Bucket\n Binomial_Lemma_Bucket\nbegin\n\nsubsection \\The generalised binomial theorem\\\n\ntext \\\n We prove the generalised binomial theorem for complex numbers, following the proof at:\n https:\/\/proofwiki.org\/wiki\/Binomial_Theorem\/General_Binomial_Theorem\n\\\n\nlemma gbinomial_ratio_limit:\n fixes a :: \"'a :: real_normed_field\"\n assumes \"a \\ \\\"\n shows \"(\\n. (a gchoose n) \/ (a gchoose Suc n)) ----> -1\"\nproof (rule Lim_transform_eventually)\n let ?f = \"\\n. inverse (a \/ of_nat (Suc n) - of_nat n \/ of_nat (Suc n))\"\n from eventually_gt_at_top[of \"0::nat\"]\n show \"eventually (\\n. ?f n = (a gchoose n) \/(a gchoose Suc n)) sequentially\"\n proof eventually_elim\n fix n :: nat assume n: \"n > 0\"\n let ?P = \"\\i = 0..n - 1. a - of_nat i\"\n from n have \"(a gchoose n) \/ (a gchoose Suc n) = (of_nat (Suc n) :: 'a) *\n (?P \/ (\\i = 0..n. a - of_nat i))\" by (simp add: gbinomial_def)\n also from n have \"(\\i = 0..n. a - of_nat i) = ?P * (a - of_nat n)\"\n by (cases n) (simp_all add: setprod_nat_ivl_Suc)\n also have \"?P \/ \\ = (?P \/ ?P) \/ (a - of_nat n)\" by (rule divide_divide_eq_left[symmetric])\n also from assms have \"?P \/ ?P = 1\" by auto\n also have \"of_nat (Suc n) * (1 \/ (a - of_nat n)) = \n inverse (inverse (of_nat (Suc n)) * (a - of_nat n))\" by (simp add: field_simps)\n also have \"inverse (of_nat (Suc n)) * (a - of_nat n) = a \/ of_nat (Suc n) - of_nat n \/ of_nat (Suc n)\"\n by (simp add: field_simps del: of_nat_Suc)\n finally show \"?f n = (a gchoose n) \/ (a gchoose Suc n)\" by simp\n qed\n\n have \"(\\n. norm a \/ (of_nat (Suc n))) ----> 0\" \n unfolding divide_inverse real_of_nat_def[symmetric]\n by (intro tendsto_mult_right_zero LIMSEQ_inverse_real_of_nat)\n hence \"(\\n. a \/ of_nat (Suc n)) ----> 0\"\n by (subst tendsto_norm_zero_iff[symmetric]) (simp add: norm_divide del: of_nat_Suc)\n hence \"?f ----> inverse (0 - 1)\"\n by (intro tendsto_inverse tendsto_diff LIMSEQ_n_over_Suc_n) simp_all\n thus \"?f ----> -1\" by simp\nqed\n\nlemma conv_radius_gchoose:\n fixes a :: \"'a :: {real_normed_field,banach}\"\n shows \"conv_radius (\\n. a gchoose n) = (if a \\ \\ then \\ else 1)\"\nproof (cases \"a \\ \\\")\n assume a: \"a \\ \\\"\n have \"eventually (\\n. (a gchoose n) = 0) sequentially\"\n using eventually_gt_at_top[of \"nat \\norm a\\\"]\n by eventually_elim (insert a, auto elim!: Nats_cases simp: binomial_gbinomial[symmetric])\n from conv_radius_cong[OF this] a show ?thesis by simp\nnext\n assume a: \"a \\ \\\"\n from tendsto_norm[OF gbinomial_ratio_limit[OF this]]\n have \"conv_radius (\\n. a gchoose n) = 1\"\n by (intro conv_radius_ratio_limit_nonzero[of _ 1]) (simp_all add: norm_divide)\n with a show ?thesis by simp\nqed\n\nlemma gen_binomial_complex:\n fixes z :: complex\n assumes \"norm z < 1\"\n shows \"(\\n. (a gchoose n) * z^n) sums (1 + z) powr a\"\nproof -\n def K \\ \"1 - (1 - norm z) \/ 2\"\n from assms have K: \"K > 0\" \"K < 1\" \"norm z < K\"\n unfolding K_def by (auto simp: field_simps intro!: add_pos_nonneg)\n let ?f = \"\\n. a gchoose n\" and ?f' = \"diffs (\\n. a gchoose n)\"\n have summable_strong: \"summable (\\n. ?f n * z ^ n)\" if \"norm z < 1\" for z using that\n by (intro summable_in_conv_radius) (simp_all add: conv_radius_gchoose)\n with K have summable: \"summable (\\n. ?f n * z ^ n)\" if \"norm z < K\" for z using that by auto\n hence summable': \"summable (\\n. ?f' n * z ^ n)\" if \"norm z < K\" for z using that\n by (intro termdiff_converges[of _ K]) simp_all\n \n def f \\ \"\\z. \\n. ?f n * z ^ n\" and f' \\ \"\\z. \\n. ?f' n * z ^ n\"\n {\n fix z :: complex assume z: \"norm z < K\"\n from summable_mult2[OF summable'[OF z], of z]\n have summable1: \"summable (\\n. ?f' n * z ^ Suc n)\" by (simp add: mult_ac)\n hence summable2: \"summable (\\n. of_nat n * ?f n * z^n)\" \n unfolding diffs_def by (subst (asm) summable_Suc_iff)\n\n have \"(1 + z) * f' z = (\\n. ?f' n * z^n) + (\\n. ?f' n * z^Suc n)\"\n unfolding f'_def using summable' z by (simp add: algebra_simps suminf_mult)\n also have \"(\\n. ?f' n * z^n) = (\\n. of_nat (Suc n) * ?f (Suc n) * z^n)\"\n by (intro suminf_cong) (simp add: diffs_def)\n also have \"(\\n. ?f' n * z^Suc n) = (\\n. of_nat n * ?f n * z ^ n)\" \n using summable1 suminf_split_initial_segment[OF summable1] unfolding diffs_def\n by (subst suminf_split_head, subst (asm) summable_Suc_iff) simp_all\n also have \"(\\n. of_nat (Suc n) * ?f (Suc n) * z^n) + (\\n. of_nat n * ?f n * z^n) =\n (\\n. a * ?f n * z^n)\"\n by (subst gbinomial_mult_1, subst suminf_add)\n (insert summable'[OF z] summable2, \n simp_all add: summable_powser_split_head algebra_simps diffs_def)\n also have \"\\ = a * f z\" unfolding f_def\n by (subst suminf_mult[symmetric]) (simp_all add: summable[OF z] mult_ac)\n finally have \"a * f z = (1 + z) * f' z\" by simp\n } note deriv = this\n\n have [derivative_intros]: \"(f has_field_derivative f' z) (at z)\" if \"norm z < of_real K\" for z\n unfolding f_def f'_def using K that\n by (intro termdiffs_strong[of \"?f\" K z] summable_strong) simp_all\n have \"f 0 = (\\n. if n = 0 then 1 else 0)\" unfolding f_def by (intro suminf_cong) simp\n also have \"\\ = 1\" using sums_single[of 0 \"\\_. 1::complex\"] unfolding sums_iff by simp\n finally have [simp]: \"f 0 = 1\" .\n\n have \"\\c. \\z\\ball 0 K. f z * (1 + z) powr (-a) = c\"\n proof (rule has_field_derivative_zero_constant)\n fix z :: complex assume z': \"z \\ ball 0 K\"\n hence z: \"norm z < K\" by (simp add: dist_0_norm)\n with K have nz: \"1 + z \\ 0\" by (auto dest!: minus_unique)\n from z K have \"norm z < 1\" by simp\n hence \"Im (1 + z) \\ 0 \\ Re (1 + z) > 0\" by (cases z) auto\n hence \"((\\z. f z * (1 + z) powr (-a)) has_field_derivative \n f' z * (1 + z) powr (-a) - a * f z * (1 + z) powr (-a-1)) (at z)\" using z\n by (auto intro!: derivative_eq_intros)\n also from z have \"a * f z = (1 + z) * f' z\" by (rule deriv)\n finally show \"((\\z. f z * (1 + z) powr (-a)) has_field_derivative 0) (at z within ball 0 K)\" \n using nz by (simp add: field_simps powr_diff_complex at_within_open[OF z'])\n qed simp_all\n then obtain c where c: \"\\z. z \\ ball 0 K \\ f z * (1 + z) powr (-a) = c\" by blast\n from c[of 0] and K have \"c = 1\" by simp\n with c[of z] have \"f z = (1 + z) powr a\" using K \n by (simp add: powr_minus_complex field_simps dist_complex_def)\n with summable K show ?thesis unfolding f_def by (simp add: sums_iff)\nqed\n\nlemma gen_binomial_complex':\n fixes x y :: real and a :: complex\n assumes \"\\x\\ < \\y\\\"\n shows \"(\\n. (a gchoose n) * of_real x^n * of_real y powr (a - of_nat n)) sums \n of_real (x + y) powr a\" (is \"?P x y\")\nproof -\n {\n fix x y :: real assume xy: \"\\x\\ < \\y\\\" \"y \\ 0\"\n hence \"y > 0\" by simp\n note xy = xy this\n from xy have \"(\\n. (a gchoose n) * of_real (x \/ y) ^ n) sums (1 + of_real (x \/ y)) powr a\"\n by (intro gen_binomial_complex) (simp add: norm_divide)\n hence \"(\\n. (a gchoose n) * of_real (x \/ y) ^ n * y powr a) sums \n ((1 + of_real (x \/ y)) powr a * y powr a)\"\n by (rule sums_mult2)\n also have \"(1 + complex_of_real (x \/ y)) = complex_of_real (1 + x\/y)\" by simp\n also from xy have \"\\ powr a * of_real y powr a = (\\ * y) powr a\"\n by (subst powr_times_real[symmetric]) (simp_all add: field_simps)\n also from xy have \"complex_of_real (1 + x \/ y) * complex_of_real y = of_real (x + y)\"\n by (simp add: field_simps)\n finally have \"?P x y\" using xy by (simp add: field_simps powr_diff_complex powr_nat)\n } note A = this\n\n show ?thesis\n proof (cases \"y < 0\")\n assume y: \"y < 0\"\n with assms have xy: \"x + y < 0\" by simp\n with assms have \"\\-x\\ < \\-y\\\" \"-y \\ 0\" by simp_all\n note A[OF this]\n also have \"complex_of_real (-x + -y) = - complex_of_real (x + y)\" by simp\n also from xy assms have \"... powr a = (-1) powr -a * of_real (x + y) powr a\"\n by (subst powr_neg_real_complex) (simp add: abs_real_def split: split_if_asm)\n also {\n fix n :: nat\n from y have \"(a gchoose n) * of_real (-x) ^ n * of_real (-y) powr (a - of_nat n) = \n (a gchoose n) * (-of_real x \/ -of_real y) ^ n * (- of_real y) powr a\"\n by (subst power_divide) (simp add: powr_diff_complex powr_nat)\n also from y have \"(- of_real y) powr a = (-1) powr -a * of_real y powr a\"\n by (subst powr_neg_real_complex) simp\n also have \"-complex_of_real x \/ -complex_of_real y = complex_of_real x \/ complex_of_real y\"\n by simp\n also have \"... ^ n = of_real x ^ n \/ of_real y ^ n\" by (simp add: power_divide)\n also have \"(a gchoose n) * ... * ((-1) powr -a * of_real y powr a) = \n (-1) powr -a * ((a gchoose n) * of_real x ^ n * of_real y powr (a - n))\"\n by (simp add: algebra_simps powr_diff_complex powr_nat)\n finally have \"(a gchoose n) * of_real (- x) ^ n * of_real (- y) powr (a - of_nat n) =\n (-1) powr -a * ((a gchoose n) * of_real x ^ n * of_real y powr (a - of_nat n))\" .\n }\n note sums_cong[OF this]\n finally show ?thesis by (simp add: sums_mult_iff)\n qed (insert A[of x y] assms, simp_all add: not_less)\nqed\n\nlemma gen_binomial_complex'':\n fixes x y :: real and a :: complex\n assumes \"\\y\\ < \\x\\\"\n shows \"(\\n. (a gchoose n) * of_real x powr (a - of_nat n) * of_real y ^ n) sums \n of_real (x + y) powr a\"\n using gen_binomial_complex'[OF assms] by (simp add: mult_ac add.commute)\n\n\n(*\nlemma gen_binomial_real:\n fixes z :: real\n assumes \"\\z\\ < 1\"\n shows \"(\\n. (a gchoose n) * z^n) sums (1 + z) powr a\"\nproof -\n from assms have \"norm (of_real z :: complex) < 1\" by simp\n from gen_binomial_complex[OF this]\n have \"(\\n. (of_real a gchoose n :: complex) * of_real z ^ n) sums\n (of_real (1 + z)) powr (of_real a)\" by simp\n also have \"(of_real (1 + z) :: complex) powr (of_real a) = of_real ((1 + z) powr a)\"\n using assms by (subst powr_of_real) simp_all\n also have \"(of_real a gchoose n :: complex) = of_real (a gchoose n)\" for n \n by (simp add: gbinomial_def)\n hence \"(\\n. (of_real a gchoose n :: complex) * of_real z ^ n) =\n (\\n. of_real ((a gchoose n) * z ^ n))\" by (intro ext) simp\n finally show ?thesis by (simp only: sums_of_real_iff)\nqed *)\n\n\nlemma gen_binomial_real:\n fixes z :: real\n assumes \"\\z\\ < 1\"\n shows \"(\\n. (a gchoose n) * z^n) sums (1 + z) powr a\"\nproof -\n def K \\ \"1 - (1 - norm z) \/ 2\"\n from assms have K: \"K > 0\" \"K < 1\" \"norm z < K\"\n unfolding K_def by (auto simp: field_simps intro!: add_pos_nonneg)\n let ?f = \"\\n. a gchoose n\" and ?f' = \"diffs (\\n. a gchoose n)\"\n have summable_strong: \"summable (\\n. ?f n * z ^ n)\" if \"norm z < 1\" for z using that\n by (intro summable_in_conv_radius) (simp_all add: conv_radius_gchoose)\n with K have summable: \"summable (\\n. ?f n * z ^ n)\" if \"norm z < K\" for z using that by auto\n hence summable': \"summable (\\n. ?f' n * z ^ n)\" if \"norm z < K\" for z using that\n by (intro termdiff_converges[of _ K]) simp_all\n \n def f \\ \"\\z. \\n. ?f n * z ^ n\" and f' \\ \"\\z. \\n. ?f' n * z ^ n\"\n {\n fix z :: real assume z: \"norm z < K\"\n from summable_mult2[OF summable'[OF z], of z]\n have summable1: \"summable (\\n. ?f' n * z ^ Suc n)\" by (simp add: mult_ac)\n hence summable2: \"summable (\\n. of_nat n * ?f n * z^n)\" \n unfolding diffs_def by (subst (asm) summable_Suc_iff)\n\n have \"(1 + z) * f' z = (\\n. ?f' n * z^n) + (\\n. ?f' n * z^Suc n)\"\n unfolding f'_def using summable' z by (simp add: algebra_simps suminf_mult)\n also have \"(\\n. ?f' n * z^n) = (\\n. of_nat (Suc n) * ?f (Suc n) * z^n)\"\n by (intro suminf_cong) (simp add: diffs_def)\n also have \"(\\n. ?f' n * z^Suc n) = (\\n. of_nat n * ?f n * z ^ n)\" \n using summable1 suminf_split_initial_segment[OF summable1] unfolding diffs_def\n by (subst suminf_split_head, subst (asm) summable_Suc_iff) simp_all\n also have \"(\\n. of_nat (Suc n) * ?f (Suc n) * z^n) + (\\n. of_nat n * ?f n * z^n) =\n (\\n. a * ?f n * z^n)\"\n by (subst gbinomial_mult_1, subst suminf_add)\n (insert summable'[OF z] summable2, \n simp_all add: summable_powser_split_head algebra_simps diffs_def)\n also have \"\\ = a * f z\" unfolding f_def\n by (subst suminf_mult[symmetric]) (simp_all add: summable[OF z] mult_ac)\n finally have \"a * f z = (1 + z) * f' z\" by simp\n } note deriv = this\n\n have [derivative_intros]: \"(f has_field_derivative f' z) (at z)\" if \"norm z < of_real K\" for z\n unfolding f_def f'_def using K that\n by (intro termdiffs_strong[of \"?f\" K z] summable_strong) simp_all\n have \"f 0 = (\\n. if n = 0 then 1 else 0)\" unfolding f_def by (intro suminf_cong) simp\n also have \"\\ = 1\" using sums_single[of 0 \"\\_. 1::real\"] unfolding sums_iff by simp\n finally have [simp]: \"f 0 = 1\" .\n\n have \"\\c. \\z\\ball 0 K. f z * (1 + z) powr (-a) = c\"\n proof (rule has_field_derivative_zero_constant)\n fix z :: real assume z': \"z \\ ball 0 K\"\n hence z: \"norm z < K\" by (simp add: dist_0_norm)\n with K have nz: \"1 + z > 0\" by (auto dest!: minus_unique)\n hence \"((\\z. f z * (1 + z) powr (-a)) has_field_derivative \n f' z * (1 + z) powr (-a) - a * f z * (1 + z) powr (-a-1)) (at z)\" using z\n by (auto intro!: derivative_eq_intros)\n also from z have \"a * f z = (1 + z) * f' z\" by (rule deriv)\n finally show \"((\\z. f z * (1 + z) powr (-a)) has_field_derivative 0) (at z within ball 0 K)\" \n using nz by (simp add: field_simps powr_divide2 [symmetric] at_within_open[OF z'])\n qed simp_all\n then obtain c where c: \"\\z. z \\ ball 0 K \\ f z * (1 + z) powr (-a) = c\" by blast\n from c[of 0] and K have \"c = 1\" by simp\n with c[of z] have \"f z = (1 + z) powr a\" using K \n by (simp add: powr_minus field_simps dist_real_def)\n with summable K show ?thesis unfolding f_def by (simp add: sums_iff)\nqed\n\nlemma gen_binomial_real':\n fixes x y a :: real\n assumes \"\\x\\ < y\"\n shows \"(\\n. (a gchoose n) * x^n * y powr (a - of_nat n)) sums (x + y) powr a\"\nproof -\n from assms have \"y > 0\" by simp\n note xy = this assms\n from assms have \"\\x \/ y\\ < 1\" by simp\n hence \"(\\n. (a gchoose n) * (x \/ y) ^ n) sums (1 + x \/ y) powr a\"\n by (rule gen_binomial_real)\n hence \"(\\n. (a gchoose n) * (x \/ y) ^ n * y powr a) sums ((1 + x \/ y) powr a * y powr a)\"\n by (rule sums_mult2)\n with xy show ?thesis by (simp add: field_simps powr_divide powr_divide2[symmetric] \n real_of_nat_def[symmetric] powr_realpow)\nqed\n\nlemma one_plus_neg_powr_powser:\n fixes z s :: complex\n assumes \"norm (z :: complex) < 1\"\n shows \"(\\n. (-1)^n * ((s + n - 1) gchoose n) * z^n) sums (1 + z) powr (-s)\"\n using gen_binomial_complex[OF assms, of \"-s\"] by (simp add: gbinomial_minus)\n\nlemma gen_binomial_real'':\n fixes x y a :: real\n assumes \"\\y\\ < x\"\n shows \"(\\n. (a gchoose n) * x powr (a - of_nat n) * y^n) sums (x + y) powr a\"\n using gen_binomial_real'[OF assms] by (simp add: mult_ac add.commute)\n\nlemma sqrt_series':\n \"\\z\\ < a \\ (\\n. ((1\/2) gchoose n) * a powr (1\/2 - real_of_nat n) * z ^ n) sums \n sqrt (a + z :: real)\"\n using gen_binomial_real''[of z a \"1\/2\"] by (simp add: powr_half_sqrt)\n\nlemma sqrt_series:\n \"\\z\\ < 1 \\ (\\n. ((1\/2) gchoose n) * z ^ n) sums sqrt (1 + z)\"\n using gen_binomial_real[of z \"1\/2\"] by (simp add: powr_half_sqrt)\n\nend","avg_line_length":51.3676012461,"max_line_length":115,"alphanum_fraction":0.6074959064} {"size":11647,"ext":"thy","lang":"Isabelle","max_stars_count":95.0,"content":"section {* Basic Parametricity Reasoning *}\ntheory Param_Tool\nimports \"Relators\"\nbegin\n\n subsection {* Auxiliary Lemmas *}\n lemma tag_both: \"\\ (Let x f,Let x' f')\\R \\ \\ (f x,f' x')\\R\" by simp\n lemma tag_rhs: \"\\ (c,Let x f)\\R \\ \\ (c,f x)\\R\" by simp\n lemma tag_lhs: \"\\ (Let x f,a)\\R \\ \\ (f x,a)\\R\" by simp\n\n lemma tagged_fun_relD_both: \n \"\\ (f,f')\\A\\B; (x,x')\\A \\ \\ (Let x f,Let x' f')\\B\"\n and tagged_fun_relD_rhs: \"\\ (f,f')\\A\\B; (x,x')\\A \\ \\ (f x,Let x' f')\\B\"\n and tagged_fun_relD_lhs: \"\\ (f,f')\\A\\B; (x,x')\\A \\ \\ (Let x f,f' x')\\B\"\n and tagged_fun_relD_none: \"\\ (f,f')\\A\\B; (x,x')\\A \\ \\ (f x,f' x')\\B\"\n by (simp_all add: fun_relD)\n\n\n subsection {* ML-Setup*}\n\n ML {*\n signature PARAMETRICITY = sig\n type param_ruleT = {\n lhs: term,\n rhs: term,\n R: term,\n rhs_head: term,\n arity: int\n }\n \n val dest_param_term: term -> param_ruleT\n val dest_param_rule: thm -> param_ruleT\n val dest_param_goal: int -> thm -> param_ruleT\n\n val safe_fun_relD_tac: Proof.context -> tactic'\n\n val adjust_arity: int -> thm -> thm\n val adjust_arity_tac: int -> Proof.context -> tactic'\n val unlambda_tac: Proof.context -> tactic'\n val prepare_tac: Proof.context -> tactic'\n\n val fo_rule: thm -> thm\n\n (*** Basic tactics ***)\n val param_rule_tac: Proof.context -> thm -> tactic'\n val param_rules_tac: Proof.context -> thm list -> tactic'\n val asm_param_tac: Proof.context -> tactic'\n\n\n (*** Nets of parametricity rules ***)\n type param_net\n val net_empty: param_net\n val net_add: thm -> param_net -> param_net\n val net_del: thm -> param_net -> param_net\n val net_add_int: Context.generic -> thm -> param_net -> param_net\n val net_del_int: Context.generic -> thm -> param_net -> param_net\n val net_tac: param_net -> Proof.context -> tactic'\n \n (*** Default parametricity rules ***)\n val add_dflt: thm -> Context.generic -> Context.generic\n val add_dflt_attr: attribute\n val del_dflt: thm -> Context.generic -> Context.generic\n val del_dflt_attr: attribute\n val get_dflt: Proof.context -> param_net\n\n (** Configuration **)\n val cfg_use_asm: bool Config.T\n val cfg_single_step: bool Config.T\n\n (** Setup **)\n val setup: theory -> theory\n end\n\n structure Parametricity : PARAMETRICITY = struct\n type param_ruleT = {\n lhs: term,\n rhs: term,\n R: term,\n rhs_head: term,\n arity: int\n }\n\n fun dest_param_term t = \n case \n strip_all_body t |> Logic.strip_imp_concl |> HOLogic.dest_Trueprop\n of \n @{mpat \"(?lhs,?rhs):?R\"} => let \n val (rhs_head,arity) = \n case strip_comb rhs of\n (c as Const _,l) => (c,length l)\n | (c as Free _,l) => (c,length l)\n | (c as Abs _,l) => (c,length l)\n | _ => raise TERM (\"dest_param_term: Head\",[t])\n in \n { lhs = lhs, rhs = rhs, R=R, rhs_head = rhs_head, arity = arity }\n end\n | t => raise TERM (\"dest_param_term: Expected (_,_):_\",[t])\n\n val dest_param_rule = dest_param_term o Thm.prop_of\n fun dest_param_goal i st = \n if i > Thm.nprems_of st then\n raise THM (\"dest_param_goal\",i,[st])\n else\n dest_param_term (Logic.concl_of_goal (Thm.prop_of st) i)\n\n\n fun safe_fun_relD_tac ctxt = let\n fun t a b = fo_resolve_tac [a] ctxt THEN' resolve_tac ctxt [b]\n in\n DETERM o (\n t @{thm tag_both} @{thm tagged_fun_relD_both} ORELSE'\n t @{thm tag_rhs} @{thm tagged_fun_relD_rhs} ORELSE'\n t @{thm tag_lhs} @{thm tagged_fun_relD_lhs} ORELSE'\n resolve_tac ctxt @{thms tagged_fun_relD_none}\n )\n end\n\n fun adjust_arity i thm = \n if i = 0 then thm \n else if i<0 then funpow (~i) (fn thm => thm RS @{thm fun_relI}) thm\n else funpow i (fn thm => thm RS @{thm fun_relD}) thm\n\n fun NTIMES k tac = \n if k <= 0 then K all_tac \n else tac THEN' NTIMES (k-1) tac\n\n fun adjust_arity_tac n ctxt i st = \n (if n = 0 then K all_tac\n else if n>0 then NTIMES n (DETERM o resolve_tac ctxt @{thms fun_relI})\n else NTIMES (~n) (safe_fun_relD_tac ctxt)) i st\n\n fun unlambda_tac ctxt i st = \n case try (dest_param_goal i) st of\n NONE => Seq.empty\n | SOME g => let\n val n = Term.strip_abs (#rhs_head g) |> #1 |> length\n in NTIMES n (resolve_tac ctxt @{thms fun_relI}) i st end\n\n fun prepare_tac ctxt = \n Subgoal.FOCUS (K (PRIMITIVE (Drule.eta_contraction_rule))) ctxt\n THEN' unlambda_tac ctxt\n\n\n fun could_param_rl rl i st = \n if i > Thm.nprems_of st then NONE\n else (\n case (try (dest_param_goal i) st, try dest_param_term rl) of\n (SOME g, SOME r) =>\n if Term.could_unify (#rhs_head g, #rhs_head r) then\n SOME (#arity r - #arity g)\n else NONE\n | _ => NONE\n )\n\n fun param_rule_tac_aux ctxt rl i st = \n case could_param_rl (Thm.prop_of rl) i st of\n SOME adj => (adjust_arity_tac adj ctxt THEN' resolve_tac ctxt [rl]) i st\n | _ => Seq.empty\n\n fun param_rule_tac ctxt rl = \n prepare_tac ctxt THEN' param_rule_tac_aux ctxt rl\n\n fun param_rules_tac ctxt rls = \n prepare_tac ctxt THEN' FIRST' (map (param_rule_tac_aux ctxt) rls)\n\n fun asm_param_tac_aux ctxt i st = \n if i > Thm.nprems_of st then Seq.empty\n else let\n val prems = Logic.prems_of_goal (Thm.prop_of st) i |> tag_list 1\n \n fun tac (n,t) i st = case could_param_rl t i st of\n SOME adj => (adjust_arity_tac adj ctxt THEN' rprem_tac n ctxt) i st\n | NONE => Seq.empty\n in\n FIRST' (map tac prems) i st\n end\n\n fun asm_param_tac ctxt = prepare_tac ctxt THEN' asm_param_tac_aux ctxt\n \n type param_net = (param_ruleT * thm) Item_Net.T\n\n local\n val param_get_key = single o #rhs_head o #1\n in \n val net_empty = Item_Net.init (Thm.eq_thm o apply2 #2) param_get_key\n end\n\n fun wrap_pr_op f context thm = case try (`dest_param_rule) thm of\n NONE => \n let \n val msg = \"Ignoring invalid parametricity theorem: \"\n ^ Thm.string_of_thm (Context.proof_of context) thm\n val _ = warning msg\n in I end\n | SOME p => f p\n \n val net_add_int = wrap_pr_op Item_Net.update \n val net_del_int = wrap_pr_op Item_Net.remove\n\n val net_add = Item_Net.update o `dest_param_rule\n val net_del = Item_Net.remove o `dest_param_rule\n\n fun net_tac_aux net ctxt i st = \n if i > Thm.nprems_of st then \n Seq.empty \n else\n let\n val g = dest_param_goal i st\n val rls = Item_Net.retrieve net (#rhs_head g)\n \n fun tac (r,thm) = \n adjust_arity_tac (#arity r - #arity g) ctxt \n THEN' DETERM o resolve_tac ctxt [thm]\n in \n FIRST' (map tac rls) i st\n end\n\n fun net_tac net ctxt = prepare_tac ctxt THEN' net_tac_aux net ctxt\n\n structure dflt_rules = Generic_Data (\n type T = param_net\n val empty = net_empty\n val extend = I\n val merge = Item_Net.merge\n )\n \n fun add_dflt thm context = dflt_rules.map (net_add_int context thm) context\n fun del_dflt thm context = dflt_rules.map (net_del_int context thm) context\n val add_dflt_attr = Thm.declaration_attribute add_dflt\n val del_dflt_attr = Thm.declaration_attribute del_dflt\n\n val get_dflt = dflt_rules.get o Context.Proof\n\n val cfg_use_asm = \n Attrib.setup_config_bool @{binding param_use_asm} (K true)\n val cfg_single_step = \n Attrib.setup_config_bool @{binding param_single_step} (K false)\n\n local\n open Refine_Util\n\n val param_modifiers =\n [Args.add -- Args.colon >> K (Method.modifier add_dflt_attr @{here}),\n Args.del -- Args.colon >> K (Method.modifier del_dflt_attr @{here}),\n Args.$$$ \"only\" -- Args.colon >>\n K {init = Context.proof_map (dflt_rules.map (K net_empty)),\n attribute = add_dflt_attr, pos = @{here}}]\n\n val param_flags = \n parse_bool_config \"use_asm\" cfg_use_asm\n || parse_bool_config \"single_step\" cfg_single_step\n\n in\n \n val parametricity_method = \n parse_paren_lists param_flags |-- Method.sections param_modifiers >> \n (fn _ => fn ctxt => \n let\n val net2 = get_dflt ctxt\n val asm_tac = \n if Config.get ctxt cfg_use_asm then \n asm_param_tac ctxt\n else K no_tac\n \n val RPT = \n if Config.get ctxt cfg_single_step then I\n else REPEAT_ALL_NEW_FWD\n \n in\n SIMPLE_METHOD' (\n RPT (\n (assume_tac ctxt \n ORELSE' net_tac net2 ctxt\n ORELSE' asm_tac)\n ) \n )\n end\n )\n end\n\n fun fo_rule thm = case Thm.concl_of thm of\n @{mpat \"Trueprop ((_,_)\\_\\_)\"} => fo_rule (thm RS @{thm fun_relD})\n | _ => thm \n \n val param_fo_attr = Scan.succeed (Thm.rule_attribute [] (K fo_rule))\n\n val setup = I\n #> Attrib.setup @{binding param} \n (Attrib.add_del add_dflt_attr del_dflt_attr)\n \"declaration of parametricity theorem\"\n #> Global_Theory.add_thms_dynamic (@{binding param}, \n map #2 o Item_Net.content o dflt_rules.get)\n #> Method.setup @{binding parametricity} parametricity_method \n \"Parametricity solver\"\n #> Attrib.setup @{binding param_fo} param_fo_attr \n \"Parametricity: Rule in first-order form\"\n\n end\n *}\n\n setup Parametricity.setup\n\n\n\n subsection \\Convenience Tools\\\n\n ML {*\n (* Prefix p_ or wrong type supresses generation of relAPP *)\n \n fun cnv_relAPP t = let\n fun consider (Var ((name,_),T)) =\n if String.isPrefix \"p_\" name then false \n else (\n case T of\n Type(@{type_name set},[Type(@{type_name prod},_)]) => true\n | _ => false)\n | consider _ = true\n \n fun strip_rcomb u : term * term list =\n let \n fun stripc (x as (f$t, ts)) = \n if consider t then stripc (f, t::ts) else x\n | stripc x = x\n in stripc(u,[]) end;\n \n val (f,a) = strip_rcomb t\n in \n Relators.list_relAPP a f\n end\n \n fun to_relAPP_conv ctxt = Refine_Util.f_tac_conv ctxt \n cnv_relAPP \n (ALLGOALS (simp_tac \n (put_simpset HOL_basic_ss ctxt addsimps @{thms relAPP_def})))\n \n \n val to_relAPP_attr = Thm.rule_attribute [] (fn context => let\n val ctxt = Context.proof_of context\n in\n Conv.fconv_rule (Conv.arg1_conv (to_relAPP_conv ctxt))\n end)\n *}\n \n attribute_setup to_relAPP = {* Scan.succeed (to_relAPP_attr) *} \n \"Convert relator definition to prefix-form\"\n\n\nend\n","avg_line_length":33.3724928367,"max_line_length":131,"alphanum_fraction":0.5782604963} {"size":418,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"name: hol-string\nversion: 1.1\ndescription: HOL string theories\nauthor: HOL OpenTheory Packager \nlicense: MIT\nrequires: base\nrequires: hol-base\nshow: \"HOL4\"\nshow: \"Data.Bool\"\nshow: \"Data.List\"\nshow: \"Data.Pair\"\nshow: \"Data.Option\"\nshow: \"Function\"\nshow: \"Number.Natural\"\nshow: \"Relation\"\nmain {\n article: \"hol4-string-unint.art\"\n interpretation: \"..\/opentheory\/hol4.int\"\n}\n","avg_line_length":20.9,"max_line_length":76,"alphanum_fraction":0.7416267943} {"size":20271,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"theory MixR\nimports MixRIR\nbegin\n\n\n(* First let us introduce some basic types used in the theory of Spider\n Diagrams. These are Isabelle counterparts of diagrammatic elements as defined\n by [Howse et al, Spider Diagrams, 2005]. *)\ntypes\n contour = \"nat\"\n zone = \"contour set\"\n region = \"zone set\"\n spider = \"nat\"\n\n(*lemma split_spiders: \"\\habs1 habs2.(list_all2 (\\r1 r2. (sd_region_sem r1 \\ sd_region_sem r2)) habs1 habs2 \\ (sd_sem (PrimarySD habs1 zones) \\ sd_sem (PrimarySD habs2 zones)))\"\n apply (auto simp del: sd_region_sem.simps simp add: list_all2_def size.simps)\n apply (induct_tac habs2)\n apply auto*)\n\ntext {* This record contains all necessary parameters for the SpiderDiagrams\nlocale. *}\nrecord 'e SpiderDiagram =\n\n (* A zone that is an element of this set is called a shaded zone. See\n 'only_spiders_in_shzon' in 'SpiderDiagram' locale for the properties of\n shaded zones. *)\n shaded_zones :: \"zone set\" (\"shzon\\\")\n\n (* contour_map takes a 'contour identifier' as its argument and returns a concrete set\n which is identified by the contour. It is basically an 'interpretation of\n contours IDs.' zone_map and region_map are analogous versions for zones and regions.\n *)\n contour_map :: \"contour \\ 'e set\" (\"cmap\\ _\")\n\n (* The 'spider_map' function returns the corresponding element for each\n spider. *)\n spider_map :: \"spider \\ 'e\" (\"smap\\ _\")\n\n (* The 'habitat_map' function that returns a given spider's habitat. Note that\n different spiders may inhabit the same region. *)\n habitat_map :: \"spider \\ region\" (\"hab\\ _\")\n\n\n\n (* The following is pretty much the definition of the function which maps the\n set of labels to Isabelle sets. This definition can be found in [Howse et al,\n Spider Diagrams, 2005, pg. 5]. *)\nfun zone_map :: \"('e, 'a) SpiderDiagram_scheme \\ zone \\ 'e set\" (\"zmap\\\")\n where\n \"zmap\\<^bsub>d\\<^esub> cs = (\\c \\ cs. cmap\\<^bsub>d\\<^esub> c) - (\\c \\ (-cs). cmap\\<^bsub>d\\<^esub> c)\"\n\n\n\n (* The definition of the function which maps a diagrammatic region to an\n actual set. *)\nfun region_map :: \"('e, 'a) SpiderDiagram_scheme \\ region \\ 'e set\" (\"rmap\\\")\n where\n \"rmap\\<^bsub>d\\<^esub> r = (\\z \\ r. zmap\\<^bsub>d\\<^esub> z)\"\n\n\n\n (* Maps a set of spiders to the set of elements that the spiders represent. *)\nfun spider_set_map :: \"('e, 'a) SpiderDiagram_scheme \\ spider set \\ 'e set\" (\"ssmap\\\")\n where\n \"ssmap\\<^bsub>d\\<^esub> ss = { (smap\\<^bsub>d\\<^esub> s) | s. s \\ ss }\"\n\n\n\ntext {* This is the first step towards the main locale for SpiderDiagrams. *}\nlocale SpiderDiagram_base =\n\n (* Some parameters to the locale: the actual model of the spider diagrams. *)\n fixes d :: \"('e, 'a) SpiderDiagram_scheme\" (structure)\n\n (* Some 'locale assumptions' expressing general properties of the concepts in\n abstract spider diagrams. *)\n\n (* Spiders: *)\n (* Two different spiders refer to two different elements. *)\n assumes ne_spiders_ne_elements: \"\\ s \\ s' \\ \\ (smap s) \\ (smap s')\"\n\n (* The spiders cannot live in zone-less regions. Which would mean that a\n spider is an element of an empty set. *)\n and spiders_in_nonempty_regions: \"hab s \\ {}\"\n\n (* Spiders in their habitats refer to mapped element inclusion in the set to\n which the habitat refers. *)\n and spiders_elements_in_region: \"smap s \\ rmap hab s\"\n\nbegin\n\ntext {* Definitions of useful operators and relations on Spider Diagram\nconcepts. *}\n\ndefinition subregion (infix \"\\\" 50)\n where\n \"r \\ r' = ((rmap r) \\ rmap r')\"\n\ndefinition regioninter (infix \"\\\" 70)\n where\n \"r \\ r' = ((rmap r) \\ rmap r')\"\n\ndefinition regionunion (infix \"\\\" 70)\n where\n \"r \\ r' = ((rmap r) \\ rmap r')\"\n\ndefinition regionminus (infix \"\\\" 70)\n where\n \"r \\ r' = ((rmap r) - rmap r')\"\n\ndefinition subregioneq (infix \"\\\" 50)\n where\n \"r \\ r' = ((rmap r) \\ rmap r')\"\n\ndefinition subzone (infix \"\\\" 50)\n where\n \"z \\ r = ((zmap z) \\ rmap r)\"\n\ndefinition subzoneeq (infix \"\\\" 50)\n where\n \"z \\ r = ((zmap z) \\ rmap r)\"\n\ndefinition zoneinter (infix \"\\\" 70)\n where\n \"z \\ z' = ((zmap z) \\ zmap z')\"\n\ndefinition zoneinterregion (infix \"\\\" 70)\n where\n \"z \\ r = ((zmap z) \\ rmap r)\"\n\ndefinition regioninterzone (infix \"\\\" 70)\n where\n \"r \\ z = ((rmap r) \\ zmap z)\"\n\ndefinition inhabiting_spiders (\"\\ _\" 80)\n where\n \"\\ (r::region) = {s. (hab s) \\ r }\"\n\ndefinition touching_spiders (\"\\ _\" 80)\n where\n \"\\ (r::region) = {s. (hab s) \\ r \\ {} }\"\n\ndefinition spiders_touching_zone (\"\\\\ _\" 80)\n where\n \"(\\\\ (z::zone)) = {s. z \\ hab s }\"\n\n\n\ntext {* These lemmas expose some useful properties about the connection between\nzones, regions, and their respective sets. *}\n\n(* Lemma 3.1 part 1:\n This lemma seems quite important to me. It says that two different zones\n represent two disjoint sets. *)\nlemma disjoint_zones: \"\\ z \\ (z'::zone) \\ \\ z \\ z' = {}\"\n by (auto simp: zoneinter_def)\n\n(* More about zones. If the mapped sets of zones contain one common element,\n then we are actually talking about the same zones. *)\nlemma shared_el_same_zone: \"\\ x \\ zmap z; x \\ zmap z' \\ \\ z = z'\"\n by(auto)\n\n(* More about zones. If two elements are in two different zones then these\n elements are necessarily not the same. *)\nlemma diff_zones_diff_el: \"\\ x \\ zmap z; x' \\ zmap z'; z \\ z' \\ \\ x \\ x'\"\n by(auto)\n\ndeclare zone_map.simps [simp del]\n\nML {* @{thm mod_Suc} *}\n\nlemma shared_el_zone_in_region: \"\\ x \\ zmap z; x \\ rmap r \\ \\ z \\ r\"\nproof (auto)\n fix z'\n assume xinz: \"x \\ zmap z\"\n assume z'inr: \"z' \\ r\"\n assume xinz': \"x \\ zmap z'\"\n hence \"z = z'\" using xinz\n by (simp add: shared_el_same_zone)\n thus \"z \\ r\" using z'inr\n by (simp)\nqed\n\n(* If two elements are in disjoint regions, they cannot be equal. *)\nlemma disj_rmap_diff_spider: \"\\ x \\ rmap r; x' \\ rmap r'; r \\ r' = {} \\ \\ x \\ x'\"\nproof (auto)\n fix z z'\n assume disj: \"r \\ r' = {}\"\n assume x'inz: \"x' \\ zmap z\"\n assume x'inz': \"x' \\ zmap z'\"\n assume zinr: \"z \\ r\"\n assume z'inr': \"z' \\ r'\"\n hence \"z \\ z'\" using zinr disj\n by (auto)\n thus False using x'inz x'inz'\n by (auto simp add: shared_el_same_zone)\nqed\n\n(* The map of a region that contains a zone, contains the map of the zone. *)\nlemma zone_inter_region_eq_zone: \"\\ z \\ r \\ \\ z \\ r = zmap z\"\nby(auto simp: zoneinterregion_def)\n\n(* If a region does not contain a zone, then the intersection of the map of this\nregion and the map of the zone is an empty set. *)\nlemma region_inter_other_zone_empty: \"\\ z \\ r \\ \\ r \\ z = {}\"\nproof (auto simp add: regioninterzone_def)\n fix e z'\n assume as1: \"z \\ r\"\n assume einz: \"e \\ zmap z\"\n assume zinr: \"z' \\ r\"\n assume einz': \"e \\ zmap z'\"\n have \"z \\ z'\" using as1 zinr\n by auto\n thus \"False\" using as1 einz einz'\n by (auto simp: zone_map.simps)\nqed\n\n(* If two regions contain the same zone, then their intersection set also\n contains all element of the zone's set. *)\nlemma inter_region_inter_rmap: \"\\ z \\ r \\ r' \\ \\ z \\ r \\ r'\"\nby (auto simp: subzoneeq_def)\n\n(* Lemma 3.1 part 2.i *)\nlemma rmap_inter_additive: \"rmap (r \\ r') = r \\ r'\"\nproof (auto simp add: regioninter_def simp del: zone_map.simps)\n fix e z z'\n assume einz: \"e \\ zmap z\"\n assume einz': \"e \\ zmap z'\"\n assume z'inr': \"z' \\ r'\"\n assume zinr: \"z \\ r\"\n have zeqz': \"z = z'\" using einz einz'\n by (auto simp: zone_map.simps)\n hence zinr': \"z \\ r'\" using z'inr'\n by auto\n thus \"\\z\\r \\ r'. e \\ zmap z\" using einz zinr\n by auto\nqed\n\n(* Lemma 3.1 part 2.ii *)\nlemma rmap_union_additive: \"rmap (r \\ r') = r \\ r'\"\nby (auto simp add: regionunion_def)\n\n(* Lemma 3.1 part 2.iii *)\nlemma rmap_minus_additive: \"rmap (r - r') = r \\ r'\"\nproof (auto simp add: regionminus_def)\n fix e z z'\n assume einz: \"e \\ zmap z\"\n assume einz': \"e \\ zmap z'\"\n assume z'inr': \"z' \\ r'\"\n assume zinr: \"z \\ r\"\n assume zninr': \"z \\ r'\"\n have zneqz': \"z \\ z'\" using zinr zninr' z'inr'\n by auto\n thus \"False\" using einz einz'\n by (auto simp: zone_map.simps)\nqed\n\n(* Lemma 3.1 part 2.iv *)\nlemma rmap_subseq_additive: \"\\ (r::region) \\ r' \\ \\ r \\ r'\"\nby (auto simp add: subregioneq_def)\n\n(* Intersection between regions that do not share any\n zones is empty. *)\nlemma diff_regions_inter_empty: \"\\ (r::region) \\ r' = {} \\ \\ r \\ r' = {}\"\nproof(auto)\n fix x\n assume iempty: \"r \\ r' = {}\"\n assume xininter: \"x \\ r \\ r'\"\n have \"r \\ r' = {}\" using iempty\n proof(auto simp: regioninter_def)\n fix e z z'\n assume einz: \"e \\ zmap z\"\n assume einz': \"e \\ zmap z'\"\n assume z'inr': \"z' \\ r'\"\n assume zinr: \"z \\ r\"\n have zeqz': \"z = z'\" using einz einz'\n by (auto simp: zone_map.simps)\n hence zinr': \"z \\ r'\" using z'inr'\n by auto\n hence \"z \\ r \\ r'\" using zinr' zinr\n by auto\n thus \"False\" using iempty\n by auto\n qed\n thus \"False\" using xininter\n by auto\nqed\n\ndeclare region_map.simps [simp del]\n\n(* A spider lives in a zone (but we don't necessarily know which zone). *)\nlemma spider_has_zone: \"\\z. smap s \\ zmap z\"\nproof -\n have rnotempty: \"hab s \\ {}\"\n by(simp add: spiders_in_nonempty_regions)\n hence sinr: \"smap s \\ rmap hab s\"\n by (auto simp add: spiders_elements_in_region)\n thus zone_exists: \"\\x. smap s \\ zmap x\" using rnotempty sinr\n by(auto simp: region_map.simps)\nqed\n\n(* This lemma shows that there exists a unique zone in which the spider\n actually resides. *)\nlemma spider_in_unique_zone: \"\\! z. smap s \\ zmap z\"\nproof (auto simp add: spider_has_zone disjoint_zones)\n fix z z' s'\n assume sinz: \"smap s \\ zmap z\"\n assume sinz': \"smap s \\ zmap z'\"\n assume s'inz: \"s' \\ z\"\n have \"z = z'\" using sinz sinz'\n by (auto simp add: shared_el_same_zone)\n thus \"s' \\ z'\" using s'inz\n by (simp)\nnext\n fix z z' s'\n assume sinz: \"smap s \\ zmap z\"\n assume sinz': \"smap s \\ zmap z'\"\n assume s'inz': \"s' \\ z'\"\n have \"z = z'\" using sinz sinz'\n by (auto simp add: shared_el_same_zone)\n thus \"s' \\ z\" using s'inz'\n by (simp)\nqed\n\n(* An element that corresponds to a spider is in the set of its habitat. *)\nlemma spider_elmnt_in_hab_set: \"\\ (hab s) = r \\ \\ smap s \\ rmap r\"\nproof (auto simp: region_map.simps)\n have rnotempty: \"hab s \\ {}\"\n by(simp add: spiders_in_nonempty_regions)\n hence sinr: \"smap s \\ rmap hab s\"\n by (auto simp add: spiders_elements_in_region)\n thus zone_exists: \"\\x \\ hab s. smap s \\ zmap x\" using rnotempty sinr\n by(auto simp: region_map.simps)\nqed\n\nlemma spider_zone_in_habitat: \"\\ smap s \\ zmap z \\ \\ z \\ hab s\"\nproof -\n assume sinz: \"smap s \\ zmap z\"\n hence sinhab: \"smap s \\ rmap hab s\"\n by (auto simp add: spiders_elements_in_region)\n thus \"z \\ hab s\" using sinz\n by (auto simp add: shared_el_zone_in_region)\nqed\n\nlemma diff_smap_diff_spider: \"\\ smap s \\ smap s' \\ \\ s \\ s'\"\nby (auto)\n\n\nend (* SpiderDiagram_base *)\n\n\n\n(* The final locale for spider diagrams. We need two locales to work around a\n limitation in the implementation of locales. *)\nlocale SpiderDiagram = SpiderDiagram_base +\n (* A shaded zone is a subset of the set of all spiders that touch this zone.\n This means that there may not be any other spiders in a shaded zone. *)\n assumes only_spiders_in_shzon: \"\\ z \\ shzon \\ \\ (zmap z) \\ ssmap (\\\\ r)\"\nbegin\n\ndeclare region_map.simps [simp add]\ndeclare zone_map.simps [simp add]\n\n(* Spider diagram transformation inference 3 (split spider). *)\nlemma sd_rule_split_spider: \"(smap s \\ r \\ r') = (smap s \\ rmap r \\ smap s \\ rmap r')\"\n by (auto simp add: regionunion_def)\n\n(* Spider diagram transformation inference 'adding feet to a spider'.\n Note: this inference is very obvious and quite frankly trivial in Isabelle, but it\n has a very interesting diagrammatic equivalent\\ so why not 'formalise' it\n here. *)\nlemma sd_rule_add_feet: \"\\ smap s \\ rmap r; r \\ r' \\ \\ smap s \\ rmap r'\"\n by (auto)\nlemma sd_rule_add_feet_2: \"\\ hab s \\ r; r \\ r' \\ \\ hab s \\ r'\"\n by (simp)\n\n(* Spider diagram transformation inference 'swap feet'. *)\nlemma sd_rule_swap_feet_2: \"\\ smap s \\ rmap r; smap s' \\ rmap r'; r' \\ r; rs \\ r - r' \\ \\ \\s1 s1'. smap s1 \\ rmap (r' \\ rs) \\ smap s1' \\ rmap (r - rs)\"\n by (auto)\n\n\n(* EXAMPLES *)\n\n(* This is the example Gem gave me. It took quite some work to prove it. It\n would really help to have a diagrammatic language which shortens it. *)\nlemma example_1_d: \"\\ hab s = { { 0, 1 } }; hab s' = { {0}, {1} } \\ \\ \\s s'. smap s \\ smap s' \\ smap s \\ cmap 0 \\ smap s' \\ cmap 1\"\nproof -\n assume habs: \"hab s = {{0, 1}}\"\n assume habs': \"hab s' = {{0}, {1}}\"\n have sneqs': \"s \\ s'\" using habs habs'\n by (auto)\n hence s_el_neq_s'_el: \"smap s \\ smap s'\"\n by (auto simp add: ne_spiders_ne_elements)\n have \"smap s \\ rmap {{0, 1}}\" using habs\n by (iprover intro: spider_elmnt_in_hab_set)\n hence s_el_in_0_and_1: \"smap s \\ cmap 0 \\ smap s \\ cmap 1\"\n by (auto)\n have \"smap s' \\ rmap {{0}, {1}}\" using habs'\n by (iprover intro: spider_elmnt_in_hab_set)\n hence \"smap s' \\ cmap 0 \\ smap s' \\ cmap 1\" using habs'\n by (auto)\n thus \"\\s s'. smap s \\ smap s' \\ smap s \\ cmap 0 \\ smap s' \\ cmap 1\" using s_el_in_0_and_1 s_el_neq_s'_el\n apply (auto)\n apply (rule_tac x = \"s'\" in exI)\n apply (rule_tac x = \"s\" in exI)\n by (simp)\nqed\n\ndeclare zone_map.simps [simp del]\n(*declare One_nat_def [simp del]*)\n\n(* This is the example Gem gave me. It took quite some work to prove it. It\n would really help to have a diagrammatic language which shortens it. *)\nlemma example_1_a: \"\\ hab s = { { 0, 1 } }; hab s' = { {0}, {1} } \\ \\ \\s s'. smap s \\ smap s' \\ smap s \\ rmap {{0}, {0, 1}} \\ smap s' \\ rmap {{1}, {0, 1}}\"\nproof -\n assume habs: \"hab s = {{0, 1}}\"\n assume habs': \"hab s' = {{0}, {1}}\"\n have sneqs': \"s \\ s'\" using habs habs'\n by (auto)\n hence s_el_neq_s'_el: \"smap s \\ smap s'\"\n by (auto simp add: ne_spiders_ne_elements)\n have \"smap s \\ rmap {{0, 1}}\" using habs\n by (iprover intro: spider_elmnt_in_hab_set)\n hence s_el_in_0_and_1: \"smap s \\ zmap {0, 1}\"\n by (auto)\n have \"smap s' \\ rmap {{0}, {1}}\" using habs'\n by (iprover intro: spider_elmnt_in_hab_set)\n hence \"smap s' \\ zmap {0} \\ smap s' \\ zmap {1}\" using habs'\n by (auto)\n thus \"\\s s'. smap s \\ smap s' \\ smap s \\ rmap {{0}, {0, 1}} \\ smap s' \\ rmap {{1}, {0, 1}}\" using s_el_in_0_and_1 s_el_neq_s'_el\n apply (auto)\n apply (rule_tac x = \"s'\" in exI)\n apply (rule_tac x = \"s\" in exI)\n by (simp)\nqed\n\n(* This is the example Gem gave me. It took quite some work to prove it. It\n would really help to have a diagrammatic language which shortens it. *)\nlemma example_1_b: \"\\ smap s \\ rmap {{ 0, 1 }}; smap s' \\ rmap {{0}, {1}} \\ \\ \\s s'. s \\ s' \\ smap s \\ rmap {{0}, {0, 1}} \\ smap s' \\ rmap {{1}, {0, 1}}\"\nproof -\n assume habs: \"smap s \\ rmap {{0, 1}}\"\n assume habs': \"smap s' \\ rmap {{0}, {1}}\"\n hence \"smap s \\ smap s'\" using habs\n apply (simp)\n apply (erule disjE)\n by (auto simp add: diff_zones_diff_el)\n hence sneqs': \"s \\ s'\"\n by (auto)\n have s_el_in_0_and_1: \"smap s \\ zmap {0, 1}\" using habs\n by (auto)\n have \"smap s' \\ zmap {0} \\ smap s' \\ zmap {1}\" using habs'\n by (simp)\n thus \"\\s s'. s \\ s' \\ smap s \\ rmap {{0}, {0, 1}} \\ smap s' \\ rmap {{1}, {0, 1}}\" using s_el_in_0_and_1 sneqs'\n apply (auto)\n apply (rule_tac x = \"s'\" in exI)\n apply (rule_tac x = \"s\" in exI)\n by (simp)\nqed\n\n(* Spoke with Thomas and he suggested I use some predicates like 'diagram(\\)'\n which nicely capture Isabelle expressions into some structure which is then\n easy to work with. *)\n\nthm \"exI\"\n\n(* This is another variant of the same example, only this time using the\n existential quantifier without the meta-level operator '\\'. *)\nlemma example_1_c: \"(\\s s'. smap s \\ rmap {{ 0, 1 }} \\ smap s' \\ rmap {{0}, {1}}) \\ (\\s s'. s \\ s' \\ smap s \\ rmap {{0}, {0, 1}} \\ smap s' \\ rmap {{1}, {0, 1}})\"\nproof (auto simp del: region_map.simps One_nat_def)\n fix s s'\n assume habs: \"smap s \\ rmap {{0, 1}}\"\n assume habs': \"smap s' \\ rmap {{0}, {1}}\"\n hence \"smap s \\ smap s'\" using habs\n apply (simp)\n apply (erule disjE)\n by (auto simp add: diff_zones_diff_el)\n hence sneqs': \"s \\ s'\"\n by (blast)\n have s_el_in_0_and_1: \"smap s \\ zmap {0, 1}\" using habs\n by (simp)\n have \"smap s' \\ zmap {0} \\ smap s' \\ zmap {1}\" using habs'\n by (simp)\n thus \"\\s s'. s \\ s' \\ smap s \\ rmap {{0}, {0, 1}} \\ smap s' \\ rmap {{1}, {0, 1}}\" using s_el_in_0_and_1 sneqs'\n apply (auto)\n apply (rule_tac x = \"s'\" in exI)\n apply (rule_tac x = \"s\" in exI)\n by (simp)\nqed\n\n\n\n(* This is another variant of the same example, only this time using the\n existential quantifier without the meta-level operator '\\'. *)\nlemma ex_1: \"(\\s s'. s \\ s' \\ smap s \\ rmap {{ 0, 1 }} \\ smap s' \\ rmap {{0}, {1}}) \\\n (\\s s'. s \\ s' \\ smap s \\ rmap {{0}, {0, 1}} \\ smap s' \\ rmap {{1}, {0, 1}})\"\n by (auto, iprover)\n\n\n\n(* This is another variant of the same example, only this time using the\n existential quantifier without the meta-level operator '\\'. *)\nlemma ex_1_a: \"(smap 1 \\ rmap {{ 0, 1 }} \\ smap 2 \\ rmap {{0}, {1}}) \\\n (\\s s'. s \\ s' \\ smap s \\ rmap {{0}, {0, 1}} \\ smap s' \\ rmap {{1}, {0, 1}})\"\n apply (auto)\n apply (rule_tac x = \"2\" in exI)\n apply (rule_tac x = \"1\" in exI)\n apply (auto)\n apply (rule_tac x = \"1\" in exI)\n apply (rule_tac x = \"2\" in exI)\n by (auto)\n\n(* Spider diagram transformation inference 'swap feet'. *)\n(*lemma sd_rule_swap_feet_N: \"\\s1 s2. s1 \\ s2 \\ s1 \\ r1 \\ s2 \\ r2 \\ r1 \\ r2 \\ rs \\ r2 - r1\"\n sorry\nlemma sd_rule_swap_feet: \"\\ s \\ s'; smap s \\ rmap r; smap s' \\ rmap r'; r' \\ r; rs \\ r - r' \\ \\ \\ss ss'. ss \\ ss' \\ ss \\ rmap (r' \\ rs) \\ ss' \\ rmap (r - rs)\"\n sorry*)\n\nend\n\nend","avg_line_length":38.9826923077,"max_line_length":264,"alphanum_fraction":0.6385970105} {"size":8097,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"theory Syntax\n imports Main\nbegin\n \ndatatype name = Var string\n\ndatatype tm = \n Bind name complex tm \n| Rslt name\n\nand complex = \n Unt \n| MkChn \n| Atom atom \n| Spwn tm \n| Sync name \n| Fst name \n| Snd name \n| Case name name tm name tm \n| App name name \n\nand atom = \n SendEvt name name \n| RecvEvt name \n| Pair name name \n| Lft name \n| Rht name \n| Fun name name tm\n\nfun freeVarsAtom :: \"atom \\ name set\"\nand freeVarsComplex :: \"complex \\ name set\"\nand freeVarsTerm :: \"tm \\ name set\" where\n \"freeVarsAtom (SendEvt x_ch x_m) = {x_ch, x_m}\"\n| \"freeVarsAtom (RecvEvt x_ch) = {x_ch}\"\n| \"freeVarsAtom (Pair x1 x2) = {x1, x2}\"\n| \"freeVarsAtom (Lft x) = {x}\"\n| \"freeVarsAtom (Rht x) = {x}\"\n| \"freeVarsAtom (Fun x_f x_p e_b) = freeVarsTerm e_b - {x_f, x_p}\"\n\n| \"freeVarsComplex Unt = {}\"\n| \"freeVarsComplex MkChn = {}\"\n| \"freeVarsComplex (Atom atom) = freeVarsAtom atom\"\n| \"freeVarsComplex (Spwn e) = freeVarsTerm e\"\n| \"freeVarsComplex (Sync x) = {x}\"\n| \"freeVarsComplex (Fst x) = {x}\"\n| \"freeVarsComplex (Snd x) = {x}\"\n| \"freeVarsComplex (Case x_sum x_l e_l x_r e_r) = \n {x_sum} \\ freeVarsTerm e_l \\ freeVarsTerm e_r - {x_l, x_r}\"\n| \"freeVarsComplex (App x_f x_a) = {x_f, x_a}\"\n\n| \"freeVarsTerm (Bind x b e) = freeVarsComplex b \\ freeVarsTerm e - {x}\" \n| \"freeVarsTerm (Rslt x) = {x}\"\n\ndatatype qtm =\n QBind name qtm qtm \n| QVar name \n| QUnt \n| QMkChn \n| QSendEvt qtm qtm \n| QRecvEvt qtm \n| QPair qtm qtm \n| QLft qtm \n| QRht qtm \n| QFun name name qtm \n| QSpwn qtm | QSync qtm \n| QFst qtm \n| QSnd qtm \n| QCase qtm name qtm name qtm \n| QApp qtm qtm\n \n \nfun program_size :: \"qtm \\ nat\" where\n \"program_size (QVar y) = 1\" \n| \"program_size (QBind x2 eb e) = 1 + (program_size eb) + (program_size e)\" \n| \"program_size (QUnt) = 1\" \n| \"program_size (QMkChn) = 1\" \n| \"program_size (QSendEvt e1 e2) = 1 + (program_size e1) + (program_size e2)\" \n| \"program_size (QRecvEvt e) = 1 + (program_size e)\" \n| \"program_size (QPair e1 e2) = 1 + (program_size e1) + (program_size e2)\" \n| \"program_size (QLft e) = 1 + (program_size e)\" \n| \"program_size (QRht e) = 1 + (program_size e)\" \n| \"program_size (QFun f x2 e) = 1 + (program_size e)\"\n| \"program_size (QSpwn e) = 1 + (program_size e)\" \n| \"program_size (QSync e) = 1 + (program_size e)\" \n| \"program_size (QFst e) = 1 + (program_size e)\" \n| \"program_size (QSnd e) = 1 + (program_size e)\" \n| \"program_size (QCase e1 x2 e2 x3 e3) = 1 + (program_size e1) + (program_size e2) + (program_size e3)\" \n| \"program_size (QApp e1 e2) = 1 + (program_size e1) + (program_size e2)\"\n \n \nfun rename :: \"name \\ name \\ qtm \\ qtm\" where\n \"rename x0 x1 (QVar y) = (if x0 = y then (QVar x1) else (QVar y))\" \n| \"rename x0 x1 (QBind x2 eb e) = (QBind x2 (rename x0 x1 eb)\n (if x0 = x2 then e else (rename x0 x1 e)))\" \n| \"rename x0 x1 (QUnt) = QUnt\" \n| \"rename x0 x1 (QMkChn) = QMkChn\" \n| \"rename x0 x1 (QSendEvt e1 e2) = QSendEvt (rename x0 x1 e1) (rename x0 x1 e2)\" \n| \"rename x0 x1 (QRecvEvt e) = QRecvEvt (rename x0 x1 e)\" \n| \"rename x0 x1 (QPair e1 e2) = QPair (rename x0 x1 e1) (rename x0 x1 e2)\" \n| \"rename x0 x1 (QLft e) = QLft (rename x0 x1 e)\" \n| \"rename x0 x1 (QRht e) = QRht (rename x0 x1 e)\" \n| \"rename x0 x1 (QFun f x2 e) = QFun f x2 \n (if x0 = f \\ x0 = x2 then e else (rename x0 x1 e))\"\n| \"rename x0 x1 (QSpwn e) = QSpwn (rename x0 x1 e)\" \n| \"rename x0 x1 (QSync e) = QSync (rename x0 x1 e)\" \n| \"rename x0 x1 (QFst e) = QFst (rename x0 x1 e)\" \n| \"rename x0 x1 (QSnd e) = QSnd (rename x0 x1 e)\" \n| \"rename x0 x1 (QCase e1 x2 e2 x3 e3) = \n (QCase (rename x0 x1 e1) \n x2 (if x0 = x2 then e2 else (rename x0 x1 e2)) \n x3 (if x0 = x3 then e3 else (rename x0 x1 e3)))\" \n| \"rename x0 x1 (QApp e1 e2) = QApp (rename x0 x1 e1) (rename x0 x1 e2)\"\n\n \ntheorem program_size_rename_equal[simp]: \"program_size (rename x0 x1 e) = program_size e\"\n by (induction e) auto\n \n \n(* code from John Wickerson https:\/\/stackoverflow.com\/questions\/23864965\/string-of-nat-in-isabelle *) \nfun string_of_nat :: \"nat \\ string\" where\n \"string_of_nat n = (\n if n < 10 then \n [char_of_nat (48 + n)] \n else \n string_of_nat (n div 10) @ [char_of_nat (48 + (n mod 10))]\n )\"\n \ndefinition sym :: \"nat \\ name\" where \"sym i = Var (''g'' @ (string_of_nat i))\"\n \n(*related normalize algorithm tmlained at http:\/\/matt.might.net\/articles\/a-normalization\/ *) \n(*tmination proofs tmlained in http:\/\/isabelle.in.tum.de\/doc\/functions.pdf*)\nfunction (sequential) normalize_cont :: \"nat \\ qtm \\ (nat \\ name \\ (tm \\ nat)) \\ (tm \\ nat)\" where\n \"normalize_cont i (QVar x) k = k i x\" \n| \"normalize_cont i (QBind x (QVar xb) e) k = \n normalize_cont i (rename x xb e) k\" \n| \"normalize_cont i (QBind x eb e) k = \n normalize_cont i eb (\\ i' xb . normalize_cont i' (rename x xb e) k)\" \n| \"normalize_cont i (QUnt) k =\n (let (ek, i') = k (i+1) (sym i) in\n (Bind (sym i) Unt ek, i'))\"\n| \"normalize_cont i QMkChn k =\n (let (ek, i') = k (i+1) (sym i) in\n (Bind (sym i) MkChn ek, i'))\" \n| \"normalize_cont i (QSendEvt e1 e2) k =\n normalize_cont i e1 (\\ i' x1 .\n normalize_cont i' e2 (\\ i'' x2 .\n (let (ek, i''') = (k (i''+1) (sym i'')) in\n (Bind (sym i'') (Atom (SendEvt x1 x2)) ek, i'''))))\" \n| \"normalize_cont i (QRecvEvt e) k =\n normalize_cont i e (\\ i' xb .\n (let (ek, i'') = (k (i'+1) (sym i')) in\n (Bind (sym i') (Atom (RecvEvt xb)) ek, i'')))\" \n|\n \"normalize_cont i (QPair e1 e2) k =\n normalize_cont i e1 (\\ i' x1 .\n normalize_cont i' e2 (\\ i'' x2 .\n (let (ek, i''') = (k (i''+1) (sym i'')) in\n (Bind (sym i'') (Atom (Pair x1 x2)) ek, i'''))))\" \n| \"normalize_cont i (QLft e) k =\n normalize_cont i e (\\ i' xb .\n (let (ek, i'') = (k (i'+1) (sym i')) in\n (Bind (sym i') (Atom (Lft xb)) ek, i'')))\" \n| \"normalize_cont i (QRht e) k =\n normalize_cont i e (\\ i' xb .\n (let (ek, i'') = (k (i'+1) (sym i')) in\n (Bind (sym i') (Atom (Rht xb)) ek, i'')))\" \n| \"normalize_cont i (QFun f x e) k =\n (let g = sym i in\n (let f' = sym (i+1) in\n (let x' = sym (i+2) in\n (let (e', i') = normalize_cont (i+3) (rename f f' (rename x x' e)) (\\ ik x . (Rslt x, ik)) in\n (let (ek, i'') = (k i' g) in\n (Bind g (Atom (Fun f' x' e')) ek, i''))))))\" \n| \"normalize_cont i (QSpwn e) k = \n (let (e', i') = normalize_cont (i+1) e (\\ ik x . (Rslt x, ik)) in\n (let (ek, i'') = k i' (sym i) in\n (Bind (sym i) (Spwn e') ek, i'')))\" \n| \"normalize_cont i (QSync e) k =\n normalize_cont i e (\\ i' xb .\n (let (ek, i'') = (k (i'+1) (sym i')) in\n (Bind (sym i') (Sync xb) ek, i'')))\" \n| \"normalize_cont i (QFst e) k =\n normalize_cont i e (\\ i' xb .\n (let (ek, i'') = (k (i'+1) (sym i')) in\n (Bind (sym i') (Fst xb) ek, i'')))\" \n| \"normalize_cont i (QSnd e) k =\n normalize_cont i e (\\ i' xb .\n (let (ek, i'') = (k (i'+1) (sym i')) in\n (Bind (sym i') (Snd xb) ek, i'')))\" \n| \"normalize_cont i (QCase e xl el xr er) k =\n normalize_cont i e (\\ i' x .\n (let xl' = sym (i'+1) in\n (let (el', i'') = normalize_cont (i'+2) (rename xl xl' el) (\\ il x . (Rslt x, il)) in\n (let xr' = sym i'' in \n (let (er', i''') = normalize_cont (i''+1) (rename xr xr' er) (\\ ir x . (Rslt x, ir)) in\n (let (ek, i'''') = k i''' (sym i') in\n (Bind (sym i')\n (Case x xl' el' xr' er') ek, i'''')))))))\" \n| \"normalize_cont i (QApp e1 e2) k =\n normalize_cont i e1 (\\ i' x1 .\n normalize_cont i' e2 (\\ i'' x2 .\n (let (e''', i''') = (k (i''+1) (sym i'')) in\n (Bind (sym i'') (App x1 x2) e''', i'''))))\"\nby pat_completeness auto\ntermination by (relation \"measure (\\(i, e, k). program_size e)\") auto\n\n \ndefinition normalize :: \"qtm \\ tm\" where\n \"normalize e = fst (normalize_cont 100 e (\\ i x . (Rslt x, i)))\"\n\nend\n","avg_line_length":38.1933962264,"max_line_length":172,"alphanum_fraction":0.5799678893} {"size":23875,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/flash_data_cub_lemma_on_inv__160.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The flash_data_cub Protocol Case Study*} \n\ntheory flash_data_cub_lemma_on_inv__160 imports flash_data_cub_base\nbegin\nsection{*All lemmas on causal relation between inv__160 and some rule r*}\nlemma n_PI_Local_GetX_PutX_HeadVld__part__0Vsinv__160:\nassumes a1: \"(r=n_PI_Local_GetX_PutX_HeadVld__part__0 N )\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_PI_Local_GetX_PutX_HeadVld__part__1Vsinv__160:\nassumes a1: \"(r=n_PI_Local_GetX_PutX_HeadVld__part__1 N )\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_PI_Remote_PutXVsinv__160:\nassumes a1: \"(\\ dst. dst\\N\\r=n_PI_Remote_PutX dst)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain dst where a1:\"dst\\N\\r=n_PI_Remote_PutX dst\" apply fastforce done\n have \"?P3 s\"\n apply (cut_tac a1 a2 , simp, rule_tac x=\"(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') dst) ''CacheState'')) (Const CACHE_E))))\" in exI, auto) done\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_Get_Put_HeadVsinv__160:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Put_Head N src)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_Get_Put_Head N src\" apply fastforce done\n have \"?P3 s\"\n apply (cut_tac a1 a2 , simp, rule_tac x=\"(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''WbMsg'') ''Cmd'')) (Const WB_Wb)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))\" in exI, auto) done\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_1Vsinv__160:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_1 N src)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_1 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_2Vsinv__160:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_2 N src)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_2 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_3Vsinv__160:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_3 N src)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_3 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_4Vsinv__160:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_4 N src)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_4 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_5Vsinv__160:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_5 N src)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_5 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_6Vsinv__160:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_6 N src)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_6 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_7__part__0Vsinv__160:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__0 N src)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_7__part__0 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_7__part__1Vsinv__160:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__1 N src)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_7__part__1 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_7_NODE_Get__part__0Vsinv__160:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_7_NODE_Get__part__1Vsinv__160:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_8_HomeVsinv__160:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home N src)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_8_Home N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_8_Home_NODE_GetVsinv__160:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_8Vsinv__160:\nassumes a1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8 N src pp)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src pp where a1:\"src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8 N src pp\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_8_NODE_GetVsinv__160:\nassumes a1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src pp where a1:\"src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_9__part__0Vsinv__160:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__0 N src)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_9__part__0 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_9__part__1Vsinv__160:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__1 N src)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_9__part__1 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_10_HomeVsinv__160:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_10_Home N src)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_10_Home N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_10Vsinv__160:\nassumes a1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_10 N src pp)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src pp where a1:\"src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_10 N src pp\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_GetX_PutX_11Vsinv__160:\nassumes a1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_11 N src)\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_NI_Local_GetX_PutX_11 N src\" apply fastforce done\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_WbVsinv__160:\nassumes a1: \"(r=n_NI_Wb )\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_ShWbVsinv__160:\nassumes a1: \"(r=n_NI_ShWb N )\" and\na2: \"(f=inv__160 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P3 s\"\n apply (cut_tac a1 a2 , simp, rule_tac x=\"(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''WbMsg'') ''Cmd'')) (Const WB_Wb)) (eqn (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''Cmd'')) (Const SHWB_ShWb))))\" in exI, auto) done\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_NI_Local_Get_Get__part__1Vsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Get__part__1 src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_GetX_PutX_HomeVsinv__160:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Remote_GetX_PutX_Home dst\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Remote_GetVsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_PI_Remote_Get src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_GetX_PutX__part__0Vsinv__160:\n assumes a1: \"r=n_PI_Local_GetX_PutX__part__0 \" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_StoreVsinv__160:\n assumes a1: \"\\ src data. src\\N\\data\\N\\r=n_Store src data\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_GetX__part__1Vsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__1 src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_InvAck_3Vsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_NI_InvAck_3 N src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_InvAck_1Vsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_NI_InvAck_1 N src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_GetX_GetX__part__1Vsinv__160:\n assumes a1: \"r=n_PI_Local_GetX_GetX__part__1 \" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_GetX_GetX__part__0Vsinv__160:\n assumes a1: \"r=n_PI_Local_GetX_GetX__part__0 \" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Remote_ReplaceVsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_PI_Remote_Replace src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_Store_HomeVsinv__160:\n assumes a1: \"\\ data. data\\N\\r=n_Store_Home data\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_ReplaceVsinv__160:\n assumes a1: \"r=n_PI_Local_Replace \" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_Nak__part__1Vsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__1 src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_Get_Nak__part__1Vsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__1 src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_Get_Get__part__0Vsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Get__part__0 src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_InvAck_existsVsinv__160:\n assumes a1: \"\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_InvAck_exists src pp\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_Nak__part__2Vsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__2 src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_Get_Put_HomeVsinv__160:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Remote_Get_Put_Home dst\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_InvVsinv__160:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Inv dst\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_PutXVsinv__160:\n assumes a1: \"r=n_PI_Local_PutX \" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_Get_Nak__part__2Vsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__2 src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_GetX__part__0Vsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__0 src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_Get_PutVsinv__160:\n assumes a1: \"r=n_PI_Local_Get_Put \" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_ReplaceVsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Replace src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_GetX_Nak_HomeVsinv__160:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Remote_GetX_Nak_Home dst\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_PutXAcksDoneVsinv__160:\n assumes a1: \"r=n_NI_Local_PutXAcksDone \" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_GetX_NakVsinv__160:\n assumes a1: \"\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_Nak src dst\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_NakVsinv__160:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Nak dst\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Remote_GetXVsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_PI_Remote_GetX src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_GetX_PutX__part__1Vsinv__160:\n assumes a1: \"r=n_PI_Local_GetX_PutX__part__1 \" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_Get_Nak_HomeVsinv__160:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Remote_Get_Nak_Home dst\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_PutXVsinv__160:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Remote_PutX dst\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_PutVsinv__160:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Remote_Put dst\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_Get_PutVsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Put src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_Nak__part__0Vsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__0 src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_InvAck_exists_HomeVsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_NI_InvAck_exists_Home src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Replace_HomeVsinv__160:\n assumes a1: \"r=n_NI_Replace_Home \" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_GetX_PutXVsinv__160:\n assumes a1: \"\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_PutX src dst\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_PutVsinv__160:\n assumes a1: \"r=n_NI_Local_Put \" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_Get_NakVsinv__160:\n assumes a1: \"\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Nak src dst\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Nak_ClearVsinv__160:\n assumes a1: \"r=n_NI_Nak_Clear \" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_Get_Put_DirtyVsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Put_Dirty src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_Get_Nak__part__0Vsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__0 src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_Get_GetVsinv__160:\n assumes a1: \"r=n_PI_Local_Get_Get \" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_Get_PutVsinv__160:\n assumes a1: \"\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Put src dst\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Nak_HomeVsinv__160:\n assumes a1: \"r=n_NI_Nak_Home \" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_InvAck_2Vsinv__160:\n assumes a1: \"\\ src. src\\N\\r=n_NI_InvAck_2 N src\" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_FAckVsinv__160:\n assumes a1: \"r=n_NI_FAck \" and\n a2: \"(f=inv__160 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \nend\n","avg_line_length":38.2,"max_line_length":251,"alphanum_fraction":0.7102827225} {"size":660,"ext":"thy","lang":"Isabelle","max_stars_count":102.0,"content":"(*\n Authors: Wenda Li\n*)\n\ntheory amc12_2000_p6\n imports Complex_Main \"HOL-Number_Theory.Number_Theory\"\nbegin\n\ntheorem amc12_2000_p6:\n fixes p q ::nat\n assumes h0: \"prime p \\ prime q\"\n and h1: \"4 \\ p \\ p \\ 18\"\n and h2: \"4 \\ q \\ q \\ 18\" \n shows \"((p * q)::int) - (p + q) \\ 194\"\nproof -\n have \"set (primes_upto 18) = set [2, 3, 5, 7, 11, 13, 17]\"\n by eval\n moreover have \"p\\set (primes_upto 18)\" \"q\\set (primes_upto 18)\"\n using h1 h0 h2 unfolding set_primes_upto by auto\n ultimately have \"p\\{5,7,11,13,17}\" \"q\\{5,7,11,13,17}\"\n using h1 h2 by auto\n then show ?thesis by auto\nqed\n\nend\n\n","avg_line_length":24.4444444444,"max_line_length":73,"alphanum_fraction":0.6151515152} {"size":461,"ext":"thy","lang":"Isabelle","max_stars_count":4.0,"content":"subsection \\IMO 2018 SL - A2\\\n\ntheory IMO_2018_SL_A2\nimports Complex_Main\nbegin\n\ntheorem IMO2018SL_A2:\n fixes n :: nat\n assumes \"n \\ 3\"\n shows \"(\\ a :: nat \\ real. a n = a 0 \\ a (n+1) = a 1 \\ \n (\\ i < n. (a i) * (a (i+1)) + 1 = a (i+2))) \\ \n 3 dvd n\" (is \"(\\ a. ?p1 a \\ ?p2 a \\ ?eq a) \\ 3 dvd n\")\n sorry\n\nend","avg_line_length":30.7333333333,"max_line_length":103,"alphanum_fraction":0.546637744} {"size":38350,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"(*\r\n File: Harmonic_Numbers_Are_Not_Integers.thy \r\n Author: Jose Manuel Rodriguez Caballero, University of Tartu\r\n*)\r\nsection \\Harmonic numbers are not integers, except for the trivial case of 1\\\r\ntheory Harmonic_Numbers_Are_Not_Integers\r\n\r\nimports \r\n Complex_Main \r\n Pnorm\r\nbegin\r\n\r\ntext \\\r\n In 1915, L. Theisinger ~\\cite{theisinger1915bemerkung} proved that, except for the trivial \r\n case of 1, the harmonic numbers are not integers. In 1918, \r\n J. K{\\\"u}rsch{\\'a}k ~\\cite{kurschak1918harmonic} provided a sufficient condition for the \r\n difference between two harmonic numbers not to be an integer. We formalize these result as theorems\r\n @{text Taeisinger} and @{text Kurschak}, respectively. These results will be deduced from the \r\n computation of the 2-adic norm of harmonic numbers (lemma @{text harmonic_numbers_2norm}).\r\n\\\r\n\r\nsubsection \\Main definition\\\r\n\r\n\r\ntext \\\r\n We start by defining the harmonic numbers.\r\n\\\r\n\r\nfun harmonic :: \\nat \\ rat\\ where\r\n \\harmonic 0 = 0\\ |\r\n \\harmonic (Suc n) = harmonic n + Fract 1 (Suc n)\\\r\n\r\nlemma harmonic_explicit:\r\n \\harmonic n = (\\k = 1..n. (Fract 1 (of_nat k)))\\\r\nproof(induction n)\r\n case 0\r\n thus ?case\r\n by simp \r\nnext\r\n case (Suc n)\r\n thus ?case\r\n by simp \r\nqed\r\n\r\nlemma harmonic_diff_explicit:\r\n \\n \\ m+1 \\ harmonic n - harmonic m = (\\k = m+1..n. (Fract 1 (of_nat k)))\\\r\nproof-\r\n assume \\n \\ m+1\\\r\n then obtain k::nat where \\n = m + 1 + k\\\r\n using le_Suc_ex \r\n by blast \r\n show ?thesis\r\n proof -\r\n have \"\\n na f nb. \\ (n::nat) \\ na + 1 \\ sum f {n..na + nb} = (sum f {n..na}::rat) + sum f {na + 1..na + nb}\"\r\n by (meson sum.ub_add_nat)\r\n then show ?thesis\r\n by (metis (no_types) \\n = m + 1 + k\\ add_diff_cancel_left' harmonic_explicit le_add2 linordered_field_class.sign_simps(1))\r\n qed \r\nqed\r\n\r\nsubsection \\Auxiliary result\\\r\n\r\nlemma sum_last:\r\n fixes n::nat and a::\\nat \\ real\\\r\n assumes \\n \\ 2\\\r\n shows \\(\\k = 1..n - 1. (a k)) + (a n) = (\\k = 1..n. (a k))\\\r\n using \\n \\ 2\\\r\n apply auto\r\n by (smt Suc_leD le_add_diff_inverse numeral_1_eq_Suc_0 numeral_2_eq_2 numeral_One plus_1_eq_Suc sum.nat_ivl_Suc')\r\n\r\nlemma harmonic_numbers_2norm:\r\n fixes n :: nat\r\n assumes \\n \\ 1\\\r\n shows \\pnorm 2 (harmonic n) = 2^(nat(\\log 2 n\\))\\\r\nproof(cases \\n = 1\\)\r\n case True\r\n have \\prime (2::nat)\\\r\n by simp\r\n hence \\harmonic (1::nat) = 1\\\r\n by (simp add: One_rat_def)\r\n hence \\pnorm 2 (harmonic (1::nat)) = pnorm 2 1\\\r\n by simp\r\n also have \\\\ = 1\\\r\n by (simp add: pnorm_1)\r\n also have \\\\ = 2^(nat(\\log 2 1\\))\\\r\n proof-\r\n have \\log 2 1 = 0\\\r\n by simp\r\n hence \\\\log 2 1\\ = 0\\\r\n by simp \r\n thus ?thesis\r\n by auto\r\n qed\r\n finally show ?thesis\r\n using \\n = 1\\\r\n by auto\r\nnext\r\n case False\r\n hence \\n \\ 2\\\r\n using \\n \\ 1\\\r\n by auto\r\n define l where \\l = nat(\\log 2 n\\)\\\r\n define H where \\H = (\\k = 1..n. (Fract 1 (of_nat k)))\\\r\n have \\prime (2::nat)\\\r\n by simp\r\n have \\l \\ 1\\\r\n proof-\r\n have \\log 2 n \\ 1\\\r\n using \\n \\ 2\\\r\n by auto\r\n hence \\\\log 2 n\\ \\ 1\\\r\n by simp\r\n thus ?thesis \r\n using \\l = nat(\\log 2 n\\)\\ \\1 \\ \\log 2 (real n)\\\\ \\l = nat \\log 2 (real n)\\\\ nat_mono \r\n by presburger \r\n qed\r\n hence \\(2::nat)^l \\ 2\\\r\n proof -\r\n have \"(2::nat) ^ 1 \\ 2 ^ l\"\r\n by (metis \\1 \\ l\\ one_le_numeral power_increasing)\r\n then show ?thesis\r\n by (metis semiring_normalization_rules(33))\r\n qed\r\n have \\pnorm 2 ((2^l) * H) = 1\\\r\n proof-\r\n define pre_H where \\pre_H = (\\k = 1..(2^l-1). (Fract 1 (of_nat k)))\\\r\n define post_H where \\post_H = (\\k = (2^l+1)..n. (Fract 1 (of_nat k)))\\\r\n have \\H = pre_H + (Fract 1 (of_nat (2^l))) + post_H\\\r\n proof-\r\n have \\pre_H + (Fract 1 (of_nat (2^l))) = (\\k = 1..(2^l-1). (Fract 1 (of_nat k))) \r\n + (Fract 1 (of_nat (2^l)))\\\r\n unfolding pre_H_def\r\n by auto\r\n also have \\\\ = (\\k = 1..2^l. (Fract 1 (of_nat k)))\\\r\n proof-\r\n have \\(\\k = 1..2 ^ l - 1. real_of_rat (Fract 1 (int k))) \r\n + real_of_rat (Fract 1 (int (2 ^ l))) \r\n = (\\k = 1..2 ^ l. real_of_rat (Fract 1 (int k)))\\\r\n using sum_last[where n = \\2^l\\ and a = \\(\\ k. of_rat (Fract 1 (of_nat k)))\\]\r\n \\(2::nat)^l \\ 2\\\r\n by auto\r\n moreover have \\(\\k = 1..2 ^ l - 1. real_of_rat (Fract 1 (int k))) \r\n + real_of_rat (Fract 1 (int (2 ^ l)))\r\n = real_of_rat ((\\k = 1..2 ^ l - 1. (Fract 1 (int k))) \r\n + (Fract 1 (int (2 ^ l))))\\\r\n by (simp add: of_rat_add of_rat_sum)\r\n moreover have \\(\\k = 1..2 ^ l. real_of_rat (Fract 1 (int k)))\r\n = real_of_rat (\\k = 1..2 ^ l. (Fract 1 (int k)))\\\r\n by (simp add: of_rat_sum)\r\n ultimately have \\real_of_rat ((\\k = 1..2 ^ l - 1. (Fract 1 (int k))) \r\n + (Fract 1 (int (2 ^ l)))) = real_of_rat (\\k = 1..2 ^ l. (Fract 1 (int k)))\\\r\n by simp\r\n thus ?thesis\r\n by simp\r\n qed\r\n finally have \\pre_H + Fract 1 (int (2 ^ l)) =\r\n (\\k = 1..2 ^ l. Fract 1 (int k))\\\r\n by blast\r\n moreover have \\(\\k = 1..2 ^ l. Fract 1 (int k)) + post_H = H\\\r\n proof-\r\n have \\(\\k = 1..2 ^ l. Fract 1 (int k)) + post_H\r\n = (\\k = 1..2 ^ l. Fract 1 (int k)) +\r\n (\\k = 2 ^ l + 1..n. Fract 1 (int k))\\\r\n unfolding post_H_def\r\n by blast\r\n also have \\\\ = (\\k = 1..n. Fract 1 (int k))\\\r\n proof-\r\n have \\2 ^ l \\ n\\\r\n proof-\r\n have \\2 ^ l = 2 ^ nat \\log 2 (real n)\\\\\r\n unfolding l_def\r\n by simp\r\n also have \\\\ = 2 powr (nat \\log 2 (real n)\\)\\\r\n by (simp add: powr_realpow) \r\n also have \\\\ \\ 2 powr (log 2 (real n))\\\r\n proof-\r\n have \\\\log 2 (real n)\\ \\ log 2 (real n)\\\r\n by simp\r\n moreover have \\(2::real) > 1\\\r\n by simp\r\n ultimately show ?thesis \r\n using Transcendental.powr_le_cancel_iff[where x = 2 \r\n and a = \"\\log 2 (real n)\\\" and b = \"log 2 (real n)\"]\r\n using assms \r\n by auto\r\n qed\r\n also have \\\\ = n\\\r\n proof-\r\n have \\(2::real) > 1\\\r\n by simp \r\n moreover have \\n > 0\\\r\n using \\n \\ 2\\\r\n by auto\r\n ultimately show ?thesis\r\n by simp\r\n qed\r\n finally show ?thesis \r\n by simp\r\n qed\r\n thus ?thesis\r\n by (metis le_add2 le_add_diff_inverse sum.ub_add_nat)\r\n qed\r\n finally have \\(\\k = 1..2 ^ l. Fract 1 (int k)) + post_H = (\\k = 1..n. Fract 1 (int k))\\\r\n by blast\r\n thus ?thesis\r\n unfolding pre_H_def H_def\r\n by blast\r\n qed\r\n ultimately show ?thesis\r\n by simp\r\n qed\r\n moreover have \\pnorm 2 ((2^l) * (Fract 1 (of_nat (2^l)))) = 1\\\r\n proof-\r\n have \\(2::nat)^l \\ 0\\\r\n by auto\r\n hence \\((2::nat)^l) * (Fract 1 (of_nat ((2::nat)^l))) = 1\\\r\n proof -\r\n have \"int (2 ^ l) \\ 0\"\r\n using \\2 ^ l \\ 0\\ by linarith\r\n hence \"1 = Fract (int (2 ^ l) * 1) (int (2 ^ l) * 1)\"\r\n by (metis (no_types) One_rat_def mult_rat_cancel)\r\n thus ?thesis\r\n by (metis (full_types) Fract_of_nat_eq mult_rat of_rat_1 of_rat_mult of_rat_of_nat_eq semiring_normalization_rules(7))\r\n qed \r\n hence \\pnorm 2 (((2::rat)^l) * (Fract 1 (of_nat ((2::nat)^l)))) = pnorm 2 1\\\r\n by (metis (mono_tags, lifting) of_nat_numeral of_nat_power of_rat_1 of_rat_eq_iff \r\n of_rat_mult of_rat_of_nat_eq)\r\n also have \\\\ = 1\\\r\n using pnorm_1\r\n by blast\r\n finally show ?thesis \r\n by blast\r\n qed\r\n moreover have \\pnorm 2 ((2^l) * pre_H) < 1\\\r\n proof-\r\n have \\(2^l) * pre_H = (\\k = 1..2 ^ l - 1. (2^l) * (Fract 1 (int k)))\\\r\n unfolding pre_H_def\r\n using Groups_Big.semiring_0_class.sum_distrib_left[where r = \\2^l\\ \r\n and f = \\(\\ k. Fract 1 (int k))\\ and A = \\{1..(2^l - 1)}\\]\r\n by blast\r\n also have \\\\ = (\\k = 1..2 ^ l - 1. (Fract (2^l) (int k)))\\\r\n by (metis Fract_of_nat_eq mult.left_neutral mult.right_neutral mult_rat of_nat_numeral \r\n of_nat_power)\r\n finally have \\2 ^ l * pre_H =\r\n (\\k = 1..2 ^ l - 1. Fract (2 ^ l) (int k))\\\r\n by blast\r\n hence \\pnorm 2 (2 ^ l * pre_H) =\r\n pnorm 2 (\\k = 1..2 ^ l - 1. Fract (2 ^ l) (int k))\\\r\n by simp\r\n also have \\\\ \\\r\n Max ((\\ k. pnorm 2 (Fract (2 ^ l) (int k)))`{1..2^l-1})\\\r\n proof-\r\n have \\pnorm 2 (\\k = 1..2 ^ l - 1. Fract (2 ^ l) (int k))\r\n = pnorm 2 (sum (\\ k. Fract (2 ^ l) (int k)) {1..(2::nat)^l-1})\\\r\n by blast\r\n also have \\\\ \\ Max ((\\ k. pnorm 2 (Fract (2 ^ l) (int k)))`{1..2^l-1})\\\r\n using \\prime 2\\ pnorm_ultrametric_sum[where p = 2 and A = \\{1..2^l-1}\\ \r\n and x = \\(\\ k. (Fract (2 ^ l) (int k)))\\]\r\n by (metis Nat.le_diff_conv2 \\2 \\ 2 ^ l\\ atLeastatMost_empty_iff2 finite_atLeastAtMost \r\n nat_1_add_1 one_le_power prime_ge_1_nat)\r\n finally show ?thesis\r\n using \\pnorm 2 (\\k = 1..2 ^ l - 1. Fract (2 ^ l) (int k)) \\ (MAX k\\{1..2 ^ l - 1}. \r\n pnorm 2 (Fract (2 ^ l) (int k)))\\ \r\n by blast\r\n qed\r\n also have \\\\ < 1\\\r\n proof-\r\n have \\finite ((\\ k. pnorm 2 (Fract (2 ^ l) (int k)))`{1..2^l-1})\\\r\n by blast \r\n moreover have \\((\\ k. pnorm 2 (Fract (2 ^ l) (int k)))`{1..2^l-1}) \\ {}\\\r\n proof-\r\n have \\(1::nat) \\ (2::nat)^l-1\\\r\n using \\(2::nat)^l \\ 2\\\r\n by auto\r\n hence \\{(1::nat)..(2::nat)^l-1} \\ {}\\\r\n using Set_Interval.order_class.atLeastatMost_empty_iff2[where a = \"1::nat\" \r\n and b = \"(2::nat)^l - 1\"]\r\n by auto\r\n thus ?thesis\r\n by blast\r\n qed\r\n moreover have \\x \\ ((\\ k. pnorm 2 (Fract (2 ^ l) (int k)))`{1..2^l-1}) \\ x < 1\\\r\n for x\r\n proof-\r\n assume \\x \\ ((\\ k. pnorm 2 (Fract (2 ^ l) (int k)))`{1..2^l-1})\\\r\n then obtain k where \\x = pnorm 2 (Fract (2 ^ l) (int k))\\ and \\k \\ {1..2^l-1}\\\r\n by blast\r\n have \\pnorm 2 (Fract (2 ^ l) (int k)) < 1\\\r\n proof-\r\n have \\Fract (2 ^ l) (int k) = (2 ^ l)*(Fract 1 (int k))\\\r\n by (metis (no_types) Fract_of_nat_eq mult_numeral_1 mult_of_nat_commute mult_rat \r\n numeral_One of_nat_numeral of_nat_power) \r\n hence \\pnorm 2 (Fract (2 ^ l) (int k)) = pnorm 2 ((2 ^ l)*(Fract 1 (int k)))\\\r\n by simp\r\n also have \\\\ < 1\\\r\n proof-\r\n have \\pnorm 2 ((2::rat)^l) = 1\/(2::nat)^l\\\r\n using \\prime (2::nat)\\ pnorm_primepow[where p = \"(2::nat)\"]\r\n by auto\r\n moreover have \\pnorm 2 (Fract 1 k) < (2::nat)^l\\\r\n proof-\r\n have \\2 powr (- pval 2 (Fract 1 k)) < (2::nat)^l\\\r\n proof-\r\n have \\pval 2 (Fract k 1) < l\\\r\n proof-\r\n have \\pval 2 (Fract k 1) = multiplicity (2::int) k\\\r\n using \\prime 2\\ pval_integer[where p = 2 and k = k]\r\n by auto\r\n also have \\\\ < l\\\r\n proof(rule classical)\r\n assume \\\\(multiplicity 2 (int k) < int l)\\\r\n hence \\multiplicity 2 (int k) \\ int l\\\r\n by simp\r\n hence \\((2::nat)^l) dvd k\\\r\n by (metis (full_types) int_dvd_int_iff multiplicity_dvd' of_nat_numeral\r\n of_nat_power zle_int)\r\n hence \\(2::nat)^l \\ k\\\r\n using \\k \\ {1..2 ^ l - 1}\\ dvd_nat_bounds\r\n by auto\r\n moreover have \\k < (2::nat)^l\\\r\n using \\k\\{1..(2::nat)^l - 1}\\\r\n by auto \r\n ultimately show ?thesis\r\n by linarith \r\n qed\r\n finally show ?thesis\r\n by blast\r\n qed\r\n hence \\- pval 2 (Fract 1 k) < l\\\r\n using \\prime 2\\ pval_inverse[where p = \"2\" and x = \\Fract 1 k\\] \r\n Fract_of_int_quotient \r\n by auto\r\n hence \\2 powr (- pval 2 (Fract 1 k)) < 2 powr l\\\r\n by auto\r\n also have \\\\ = (2::nat)^l\\\r\n proof -\r\n have f1: \"\\ 2 \\ (1::real)\"\r\n by auto\r\n have f2: \"\\x1. ((1::real) < x1) = (\\ x1 \\ 1)\"\r\n by force\r\n have \"real (2 ^ l) = 2 ^ l\"\r\n by simp\r\n hence \"real l = log 2 (real (2 ^ l))\"\r\n using f2 f1 by (meson log_of_power_eq)\r\n thus ?thesis\r\n by simp\r\n qed\r\n finally show ?thesis \r\n by blast\r\n qed\r\n moreover have \\pnorm 2 (Fract 1 k) = 2 powr (- pval 2 (Fract 1 k))\\\r\n proof-\r\n have \\k \\ 0\\\r\n using \\k\\{1..2^l - 1}\\\r\n by simp\r\n hence \\Fract 1 k \\ 0\\\r\n by (smt Fract_le_zero_iff le_numeral_extra(3) of_nat_le_0_iff)\r\n thus \\pnorm 2 (Fract 1 k) = 2 powr (- pval 2 (Fract 1 k))\\\r\n using \\prime 2\\\r\n by (simp add: pnorm_simplified)\r\n qed\r\n ultimately show ?thesis\r\n by simp\r\n qed\r\n moreover have \\pnorm 2 ((2::rat)^l) > 0\\\r\n proof-\r\n have \\(2::rat)^l \\ 0\\\r\n by simp \r\n moreover have \\pnorm 2 ((2::rat)^l) \\ 0\\\r\n using \\prime (2::nat)\\ pnorm_geq_zero\r\n by simp \r\n ultimately show ?thesis\r\n using pnorm_eq_zero \\prime (2::nat)\\\r\n by (simp add: less_eq_real_def) \r\n qed\r\n moreover have \\pnorm 2 (Fract 1 k) > 0\\\r\n proof-\r\n have \\Fract 1 k \\ 0\\\r\n using \\k \\ {1..2^l-1}\\\r\n by (metis Fract_le_zero_iff atLeastAtMost_iff int.nat_pow_one int.zero_not_one int_ops(1) less_le_not_le less_one linorder_neqE_nat nat_int_comparison(2) not_less0 order_refl power2_less_eq_zero_iff)\r\n moreover have \\pnorm 2 (Fract 1 k) \\ 0\\\r\n using \\prime (2::nat)\\ pnorm_geq_zero\r\n by blast\r\n ultimately show ?thesis\r\n using pnorm_eq_zero \\prime (2::nat)\\\r\n by (simp add: less_eq_real_def) \r\n qed\r\n ultimately have \\(pnorm 2 ((2::rat)^l))*(pnorm 2 (Fract 1 k)) \r\n < (1\/(2::nat)^l)*((2::nat)^l)\\\r\n by simp\r\n also have \\\\ = 1\\\r\n proof-\r\n have \\(2::nat)^l \\ 0\\\r\n by simp \r\n thus ?thesis\r\n by simp \r\n qed\r\n finally have \\(pnorm 2 ((2::rat)^l))*(pnorm 2 (Fract 1 k)) < 1\\\r\n by blast\r\n moreover have \\(pnorm 2 ((2::rat)^l))*(pnorm 2 (Fract 1 k)) \r\n = pnorm 2 (2 ^ l * Fract 1 (int k))\\\r\n using \\prime 2\\\r\n by (simp add: pnorm_multiplicativity)\r\n ultimately show ?thesis\r\n by simp\r\n qed\r\n finally show \\pnorm 2 (Fract (2 ^ l) (int k)) < 1\\\r\n by blast\r\n qed\r\n thus ?thesis\r\n using \\x = pnorm 2 (Fract (2 ^ l) (int k))\\\r\n by blast\r\n qed\r\n ultimately show ?thesis \r\n using Lattices_Big.linorder_class.Max_less_iff\r\n [where A = \"((\\ k. pnorm 2 (Fract (2 ^ l) (int k)))`{1..2^l-1})\"]\r\n by blast\r\n qed\r\n finally show \\pnorm 2 (2 ^ l * pre_H) < 1\\\r\n by blast\r\n qed\r\n ultimately have \\pnorm 2 ((2^l) * (Fract 1 (of_nat (2^l))) + (2^l) * pre_H) = 1\\\r\n using pnorm_unit_ball[where p = 2 and x = \"(2^l) * (Fract 1 (of_nat (2^l)))\" and y = \"(2^l) * pre_H\"]\r\n by simp\r\n moreover have \\pnorm 2 ((2^l) * post_H) < 1\\\r\n proof(cases \\2^l + 1 \\ n\\)\r\n case True\r\n have \\pnorm 2 ((2^l) * post_H) = pnorm 2 (\\k = 2 ^ l + 1..n. (2 ^ l)*(Fract 1 k))\\\r\n proof-\r\n have \\(2^l) * post_H = (\\k = 2 ^ l+1..n. (2 ^ l)*(Fract 1 k))\\\r\n unfolding post_H_def\r\n using Groups_Big.semiring_0_class.sum_distrib_left[where r = \\2^l\\ \r\n and f = \\(\\ k. Fract 1 k)\\ and A = \\{2 ^ l+1..n}\\]\r\n by auto\r\n thus ?thesis\r\n by simp\r\n qed\r\n also have \\\\\r\n = pnorm 2 (sum (\\ k. (2 ^ l)*(Fract 1 k)) {2 ^ l + 1..n})\\\r\n by blast\r\n also have \\\\\r\n \\ Max ((\\ k. pnorm 2 ((2 ^ l)*(Fract 1 k))) ` {2 ^ l + 1..n})\\\r\n proof-\r\n have \\finite {2 ^ l + 1..n}\\\r\n by simp \r\n moreover have \\{2 ^ l + 1..n} \\ {}\\\r\n using True \r\n by auto \r\n ultimately show ?thesis \r\n using \\prime 2\\ pnorm_ultrametric_sum[where p = 2 and A = \\{2 ^ l + 1..n}\\ \r\n and x = \\(\\ k. (2 ^ l)*(Fract 1 k))\\]\r\n by auto\r\n qed\r\n finally have \\pnorm 2 ((2^l) * post_H) \\ \r\n Max ((\\ k. pnorm 2 ((2 ^ l)*(Fract 1 k))) ` {2 ^ l + 1..n})\\\r\n using \\pnorm 2 (2 ^ l * post_H) = pnorm 2 (\\k = 2 ^ l + 1..n. 2 ^ l * Fract 1 (int k))\\ \\pnorm 2 (\\k = 2 ^ l + 1..n. 2 ^ l * Fract 1 (int k)) \\ (MAX k\\{2 ^ l + 1..n}. pnorm 2 (2 ^ l * Fract 1 (int k)))\\ \r\n by linarith\r\n moreover have \\((\\ k. pnorm 2 ((2 ^ l)*(Fract 1 k))) ` {2 ^ l + 1..n}) \\ {}\\\r\n using True \r\n by auto \r\n moreover have \\finite ((\\ k. pnorm 2 ((2 ^ l)*(Fract 1 k))) ` {2 ^ l + 1..n})\\\r\n by blast \r\n moreover have \\x \\ (\\ k. pnorm 2 ((2 ^ l)*(Fract 1 k))) ` {2 ^ l + 1..n} \\ x < 1\\\r\n for x\r\n proof-\r\n assume \\x \\ (\\ k. pnorm 2 ((2 ^ l)*(Fract 1 k))) ` {2 ^ l + 1..n}\\\r\n then obtain t where \\t \\ {2 ^ l + 1..n}\\ and \\x = pnorm 2 ((2 ^ l)*(Fract 1 t))\\\r\n by auto\r\n have \\x = (pnorm 2 (2 ^ l)) * (pnorm 2 (Fract 1 t))\\\r\n using \\prime 2\\ \\x = pnorm 2 ((2 ^ l)*(Fract 1 t))\\ pnorm_multiplicativity\r\n by auto\r\n moreover have \\pnorm 2 (2 ^ l) = 1\/(2^l)\\\r\n using \\prime 2\\ pval_primepow[where p = \"2::nat\"]\r\n by (metis of_int_numeral of_nat_numeral pnorm_primepow) \r\n moreover have \\pnorm 2 (Fract 1 t) < 2^l\\\r\n proof(rule classical)\r\n assume \\\\ (pnorm 2 (Fract 1 t) < 2^l)\\\r\n hence \\pnorm 2 (Fract 1 t) \\ 2^l\\\r\n by auto\r\n moreover have \\2 powr l = 2^l\\\r\n using powr_realpow \r\n by auto \r\n ultimately have \\pnorm 2 (Fract 1 t) \\ 2 powr l\\\r\n by auto\r\n moreover have \\pnorm 2 (Fract 1 t) = 2 powr (-pval 2 (Fract 1 t))\\\r\n proof-\r\n have \\t \\ 0\\\r\n using \\t \\ {2^l + 1 .. n}\\\r\n by simp\r\n hence \\Fract 1 t \\ 0\\\r\n proof -\r\n have \"\\ int t \\ 0\"\r\n by (metis \\t \\ 0\\ of_nat_le_0_iff)\r\n hence \"\\ Fract 1 (int t) \\ 0\"\r\n by (simp add: Fract_le_zero_iff)\r\n thus ?thesis\r\n by linarith\r\n qed \r\n thus ?thesis \r\n using pnorm_simplified\r\n by simp\r\n qed\r\n ultimately have \\-pval 2 (Fract 1 t) \\ l\\\r\n by simp \r\n hence \\-(multiplicity 2 (fst (quotient_of (Fract 1 t))))\r\n + (multiplicity 2 (snd (quotient_of (Fract 1 t))))\r\n \\ l\\\r\n unfolding pval_def \r\n by auto\r\n have \\quotient_of (Fract (1::int) t) = (1, t)\\\r\n proof-\r\n have \\coprime (1::int) t\\\r\n by simp \r\n moreover have \\t > 0\\\r\n using \\t \\ {2^l + 1 .. n}\\\r\n by simp\r\n ultimately show ?thesis\r\n by (simp add: quotient_of_Fract) \r\n qed\r\n hence \\fst (quotient_of (Fract 1 t)) = 1\\\r\n by simp\r\n moreover have \\snd (quotient_of (Fract 1 t)) = t\\\r\n using \\quotient_of (Fract (1::int) t) = (1, t)\\\r\n by auto\r\n ultimately have \\- int(multiplicity (2::int) 1) + int(multiplicity (2::int) t) \\ l\\\r\n using \\-(multiplicity 2 (fst (quotient_of (Fract 1 t))))\r\n + (multiplicity 2 (snd (quotient_of (Fract 1 t))))\r\n \\ l\\\r\n by auto\r\n moreover have \\multiplicity (2::int) 1 = 0\\\r\n by simp\r\n ultimately have \\multiplicity (2::int) t \\ l\\\r\n by auto\r\n hence \\2^l dvd t\\\r\n by (metis int_dvd_int_iff multiplicity_dvd' of_nat_numeral of_nat_power)\r\n hence \\\\ k::nat. 2^l * k = t\\\r\n by auto\r\n then obtain k::nat where \\2^l * k = t\\\r\n by blast\r\n have \\k \\ 2\\\r\n proof(rule classical)\r\n assume \\\\(k \\ 2)\\\r\n hence \\k < 2\\\r\n by simp\r\n moreover have \\k \\ 0\\\r\n proof(rule classical)\r\n assume \\\\(k \\ 0)\\\r\n hence \\k = 0\\\r\n by simp\r\n hence \\t = 0\\\r\n using \\2^l * k = t\\\r\n by auto\r\n thus ?thesis\r\n using \\t \\ {2^l + 1 .. n}\\\r\n by auto\r\n qed\r\n moreover have \\k \\ 1\\\r\n proof(rule classical)\r\n assume \\\\(k \\ 1)\\\r\n hence \\k = 1\\\r\n by simp\r\n hence \\t = 2^l\\\r\n using \\2^l * k = t\\\r\n by auto\r\n thus ?thesis\r\n using \\t \\ {2^l + 1 .. n}\\\r\n by auto\r\n qed\r\n ultimately show ?thesis\r\n by auto\r\n qed\r\n hence \\2^(Suc l) \\ t\\\r\n using \\2 ^ l * k = t\\ \r\n by auto\r\n hence \\2^(Suc l) \\ n\\\r\n using \\t \\ {2^l + 1 .. n}\\\r\n by auto\r\n moreover have \\n < 2^(Suc l)\\\r\n proof -\r\n have f1: \"\\n na. (n \\ na) = (int n + - 1 * int na \\ 0)\"\r\n by auto\r\n have f2: \"int (Suc (nat \\log 2 (real n)\\)) + - 1 * int (Suc l) \\ 0\"\r\n by (simp add: l_def)\r\n have f3: \"(- 1 * log 2 (real n) + real (Suc l) \\ 0) = (0 \\ log 2 (real n) + - 1 * real (Suc l))\"\r\n by fastforce\r\n have f4: \"real (Suc l) + - 1 * log 2 (real n) = - 1 * log 2 (real n) + real (Suc l)\"\r\n by auto\r\n have f5: \"\\n na. \\ 2 ^ n \\ na \\ real n + - 1 * log 2 (real na) \\ 0\"\r\n by (simp add: le_log2_of_power)\r\n have f6: \"\\x0 x1. (- 1 * int x0 + int (2 ^ x1) \\ 0) = (0 \\ int x0 + - 1 * int (2 ^ x1))\"\r\n by auto\r\n have f7: \"\\x0 x1. int (2 ^ x1) + - 1 * int x0 = - 1 * int x0 + int (2 ^ x1)\"\r\n by auto\r\n have \"\\ 0 \\ log 2 (real n) + - 1 * real (Suc l)\"\r\n using f2 by linarith\r\n then have \"\\ 0 \\ int n + - 1 * int (2 ^ Suc l)\"\r\n using f7 f6 f5 f4 f3 f1 by (metis (no_types))\r\n then show ?thesis\r\n by linarith\r\n qed \r\n ultimately show ?thesis\r\n by auto\r\n qed\r\n moreover have \\pnorm 2 (2 ^ l) \\ 0\\\r\n using \\prime 2\\ pnorm_geq_zero \r\n by blast\r\n moreover have \\pnorm 2 (Fract 1 t) \\ 0\\\r\n using \\prime 2\\ pnorm_geq_zero \r\n by blast\r\n ultimately show ?thesis \r\n by simp\r\n qed\r\n ultimately show ?thesis\r\n by (smt Max_in)\r\n next\r\n case False\r\n hence \\2 ^ l + 1 > n\\\r\n by simp\r\n hence \\{2 ^ l + 1..n} = {}\\\r\n by simp\r\n hence \\post_H = 0\\\r\n unfolding post_H_def\r\n by simp \r\n hence \\(2^l) * post_H = 0\\\r\n by (simp add: \\post_H = 0\\) \r\n thus ?thesis\r\n unfolding pnorm_def\r\n by auto\r\n qed\r\n ultimately have \\pnorm 2 (((2^l) * (Fract 1 (of_nat (2^l))) \r\n + (2^l) * pre_H) + ((2^l) * post_H)) = 1\\\r\n using pnorm_unit_ball[where p = 2 and x = \"(2^l) * (Fract 1 (of_nat (2^l))) + (2^l) * pre_H\" \r\n and y = \"(2^l) * post_H\"]\r\n by simp\r\n thus ?thesis\r\n by (simp add: \\H = pre_H + Fract 1 (int (2 ^ l)) + post_H\\ semiring_normalization_rules(24) semiring_normalization_rules(34)) \r\n qed\r\n hence \\(pnorm 2 (2^l)) * (pnorm 2 H) = 1\\\r\n using pnorm_multiplicativity\r\n by auto\r\n hence \\(1\/2^l) * (pnorm 2 H) = 1\\\r\n proof-\r\n have \\prime (2::nat)\\\r\n by simp\r\n hence \\pnorm 2 (2^l) = 1\/2^l\\\r\n using pnorm_primepow[where p = 2 and l = \"l\"] \r\n by simp\r\n thus ?thesis\r\n using \\pnorm 2 (2 ^ l) * pnorm 2 H = 1\\ \r\n by auto\r\n qed\r\n hence \\pnorm 2 H = 2^l\\\r\n by simp\r\n thus ?thesis\r\n using H_def l_def harmonic_explicit[where n = n]\r\n by simp \r\nqed\r\n\r\n\r\nsubsection \\Main results\\\r\n\r\ntext\\The following result is due to L. Taeisinger ~\\cite{theisinger1915bemerkung}.\\\r\ntheorem Taeisinger:\r\n fixes n :: nat\r\n assumes \\n \\ 2\\\r\n shows \\harmonic n \\ \\\\\r\nproof-\r\n have \\pnorm 2 (\\k = 1..n. (Fract 1 (of_nat k)) ) > 1\\\r\n using harmonic_numbers_2norm[where n = \"n\"] \\n \\ 2\\ harmonic_explicit \r\n by auto \r\n thus ?thesis\r\n proof -\r\n have \"\\ pnorm 2 (\\n = 1..n. Fract 1 (int n)) \\ 1\"\r\n using \\1 < pnorm 2 (\\k = 1..n. Fract 1 (int k))\\ by linarith\r\n then show ?thesis\r\n by (metis (no_types) harmonic_explicit integers_pnorm_D two_is_prime_nat)\r\n qed\r\nqed\r\n\r\ntext\\The following result is due to J. K{\\\"u}rsch{\\'a}k ~\\cite{kurschak1918harmonic}.\\\r\ntheorem Kurschak:\r\n fixes n m :: nat\r\n assumes \\m + 2 \\ n\\\r\n shows \\harmonic n - harmonic m \\ \\\\\r\nproof(cases \\2*m \\ n\\)\r\n case True\r\n show ?thesis\r\n proof(cases \\m = 0\\)\r\n case True\r\n thus ?thesis\r\n using Taeisinger assms \r\n by auto \r\n next\r\n case False\r\n hence \\m \\ 1\\\r\n by simp\r\n have \\n \\ 2\\\r\n using \\m+2 \\ n\\\r\n by auto\r\n have \\prime (2::nat)\\\r\n by auto\r\n have \\harmonic n = (harmonic n - harmonic m) + (harmonic m)\\\r\n by simp\r\n hence \\pnorm 2 (harmonic n) \\ max (pnorm 2 (harmonic n - harmonic m)) (pnorm 2 (harmonic m))\\\r\n using \\prime 2\\ pnorm_ultrametric[where p = \"2::nat\" and x = \"harmonic n - harmonic m\" \r\n and y = \"harmonic m\"]\r\n by auto\r\n moreover have \\pnorm 2 (harmonic m) < pnorm 2 (harmonic n)\\\r\n proof-\r\n have \\pnorm 2 (harmonic m) = 2 ^ nat \\log 2 (real m)\\\\\r\n using harmonic_numbers_2norm[where n = \"n\"] \\m \\ 1\\\r\n by (meson \\1 \\ m\\ harmonic_numbers_2norm)\r\n moreover have \\pnorm 2 (harmonic n) = 2 ^ nat \\log 2 (real n)\\\\\r\n using harmonic_numbers_2norm[where n = \"n\"] \\2 \\ n\\ \r\n by linarith\r\n moreover have \\(2::nat) ^ nat \\log 2 (real m)\\ < (2::nat) ^ nat \\log 2 (real n)\\\\\r\n proof-\r\n have \\log 2 (real m) + 1 = log 2 (real m) + log 2 (2::real)\\\r\n proof-\r\n have \\log 2 (real 2) = 1\\\r\n by simp\r\n thus ?thesis \r\n by simp\r\n qed\r\n also have \\\\ = log 2 ((real m) * (2::real)) \\\r\n proof-\r\n have \\(2::real) > 0\\\r\n by simp\r\n moreover have \\(2::real) \\ 1\\\r\n by simp\r\n moreover have \\m > 0\\\r\n using False \r\n by auto \r\n ultimately show ?thesis\r\n using log_mult[where a = 2 and x = \"real m\" and y = \"2::real\"]\r\n by simp\r\n qed\r\n also have \\\\ = log 2 (2*real m) \\\r\n proof-\r\n have \\(real m)*(2::real) = 2*m\\\r\n by auto\r\n thus ?thesis\r\n by (simp add: \\real m * 2 = real (2 * m)\\) \r\n qed\r\n also have \\\\ \\ log 2 (real n)\\\r\n using \\2*m \\ n\\ \\m \\ 0\\\r\n by auto\r\n finally have \\log 2 (real m) + 1 \\ log 2 (real n)\\\r\n by blast\r\n hence \\\\log 2 (real m)\\ < \\log 2 (real n)\\\\\r\n by linarith \r\n moreover have \\(2::nat) > 1\\\r\n by auto\r\n ultimately show ?thesis\r\n by (smt \\1 \\ m\\ floor_less_zero log_less_zero_cancel_iff nat_mono_iff of_nat_1 \r\n of_nat_mono power_strict_increasing)\r\n qed\r\n ultimately show ?thesis \r\n by auto\r\n qed\r\n ultimately have \\pnorm 2 (harmonic n) \\ pnorm 2 (harmonic n - harmonic m)\\\r\n by linarith\r\n moreover have \\1 < pnorm 2 (harmonic n)\\\r\n using harmonic_numbers_2norm[where n = \"n\"] \\n \\ 2\\\r\n by auto\r\n ultimately have \\1 < pnorm 2 (harmonic n - harmonic m) \\\r\n by auto\r\n thus ?thesis\r\n using integers_pnorm_D[where p = \"2::nat\" and x = \"harmonic n - harmonic m\"] \\prime 2\\\r\n by auto \r\n qed\r\nnext\r\n case False\r\n have explicit: \\harmonic n - harmonic m = (\\k = m + 1..n. Fract 1 (int k))\\\r\n using \\n \\ m + 2\\ harmonic_diff_explicit[where m = m and n = n]\r\n by linarith\r\n have \\harmonic n - harmonic m < 1\\\r\n proof-\r\n have \\(\\k = m + 1..n. Fract 1 (int k)) < 1\\\r\n proof-\r\n have \\finite {m + 1..n}\\\r\n by simp\r\n moreover have \\{m + 1..n} \\ {}\\\r\n using \\m+2 \\ n\\\r\n by simp\r\n moreover have \\k \\ {m + 1..n} \\ Fract 1 k \\ Fract 1 (m+1)\\\r\n for k\r\n proof-\r\n assume \\k \\ {m + 1..n}\\\r\n have \\k \\ m+1\\\r\n using \\k \\ {m + 1..n}\\\r\n by auto\r\n thus ?thesis\r\n by auto\r\n qed\r\n ultimately have \\(\\k = m + 1..n. Fract 1 k) \\ of_nat (card {m + 1..n})*Fract 1 (int (m + 1))\\\r\n using Groups_Big.sum_bounded_above[where A = \"{m+1..n}\" and K = \"Fract 1 (m+1)\"\r\n and f = \"\\ k. Fract 1 k\"]\r\n by auto\r\n also have \\\\ \\ of_nat m*Fract 1 ((m + 1))\\\r\n proof-\r\n have \\card {m+1..n} \\ m\\\r\n proof-\r\n have \\card {m+1..n} = n - m\\\r\n by auto\r\n thus ?thesis\r\n using False\r\n by simp\r\n qed\r\n moreover have \\card {m + 1..n} > 0\\\r\n using \\{m + 1..n} \\ {}\\ card_gt_0_iff \r\n by blast \r\n ultimately show ?thesis\r\n by (smt add_is_0 less_eq_rat_def mult_mono of_nat_0_le_iff of_nat_le_0_iff of_nat_mono \r\n zero_le_Fract_iff)\r\n qed\r\n also have \\\\ < 1\\\r\n proof -\r\n have \"Fract (int m * 1) (int (1 + m)) < 1\"\r\n by (simp add: Fract_less_one_iff)\r\n then show ?thesis\r\n by (metis (no_types) Fract_of_nat_eq add.commute mult.left_neutral mult_rat)\r\n qed\r\n finally show ?thesis\r\n by blast\r\n qed\r\n thus ?thesis\r\n using explicit \r\n by simp\r\n qed\r\n moreover have \\0 < harmonic n - harmonic m\\\r\n proof-\r\n have \\finite {m + 1..n}\\\r\n by simp\r\n moreover have \\{m + 1..n} \\ {}\\\r\n using \\m+2 \\ n\\\r\n by simp\r\n moreover have \\k \\ {m + 1..n} \\ 0 < Fract 1 k\\\r\n for k\r\n proof-\r\n assume \\k \\ {m + 1..n}\\\r\n hence \\k \\ 1\\\r\n by auto\r\n thus ?thesis\r\n by (simp add: zero_less_Fract_iff) \r\n qed\r\n ultimately have \\0 < (\\k = m + 1..n. Fract 1 k)\\\r\n using Groups_Big.ordered_comm_monoid_add_class.sum_pos[where I = \"{m+1..n}\" \r\n and f = \"\\ k. Fract 1 k\"]\r\n by blast\r\n thus ?thesis\r\n using explicit \r\n by simp\r\n qed\r\n ultimately show ?thesis\r\n proof -\r\n have f1: \"sgn (harmonic n - harmonic m) = 1\"\r\n by (metis \\0 < harmonic n - harmonic m\\ sgn_pos)\r\n have \"0 \\ harmonic n - harmonic m\"\r\n by (metis \\0 < harmonic n - harmonic m\\ less_eq_rat_def)\r\n thus ?thesis\r\n using f1 by (metis (no_types) Ints_0 \\harmonic n - harmonic m < 1\\ eq_iff_diff_eq_0 frac_eq_0_iff frac_unique_iff sgn_if zero_neq_one)\r\n qed \r\nqed\r\n\r\nend\r\n\r\n","avg_line_length":44.1820276498,"max_line_length":256,"alphanum_fraction":0.4884745763} {"size":28823,"ext":"thy","lang":"Isabelle","max_stars_count":62.0,"content":"(* Victor B. F. Gomes, University of Cambridge\n Martin Kleppmann, University of Cambridge\n Dominic P. Mulligan, University of Cambridge\n*)\n\nsection\\Axiomatic network models\\\n\ntext\\In this section we develop a formal definition of an \\emph{asynchronous unreliable causal broadcast network}.\n We choose this model because it satisfies the causal delivery requirements of many operation-based\n CRDTs~\\cite{Almeida:2015fc,Baquero:2014ed}. Moreover, it is suitable for use in decentralised settings,\n as motivated in the introduction, since it does not require waiting for communication with\n a central server or a quorum of nodes.\\\n\ntheory\n Network\nimports\n Convergence\nbegin\n\nsubsection\\Node histories\\\n \ntext\\We model a distributed system as an unbounded number of communicating nodes.\n We assume nothing about the communication pattern of nodes---we assume only that each node is\n uniquely identified by a natural number, and that the flow of execution at each node consists\n of a finite, totally ordered sequence of execution steps (events).\n We call that sequence of events at node $i$ the \\emph{history} of that node.\n For convenience, we assume that every event or execution step is unique within a node's history.\\\n\nlocale node_histories = \n fixes history :: \"nat \\ 'evt list\"\n assumes histories_distinct [intro!, simp]: \"distinct (history i)\"\n\nlemma (in node_histories) history_finite:\n shows \"finite (set (history i))\"\nby auto\n \ndefinition (in node_histories) history_order :: \"'evt \\ nat \\ 'evt \\ bool\" (\"_\/ \\\\<^sup>_\/ _\" [50,1000,50]50) where\n \"x \\\\<^sup>i z \\ \\xs ys zs. xs@x#ys@z#zs = history i\"\n\nlemma (in node_histories) node_total_order_trans:\n assumes \"e1 \\\\<^sup>i e2\"\n and \"e2 \\\\<^sup>i e3\"\n shows \"e1 \\\\<^sup>i e3\"\nusing assms unfolding history_order_def\n apply clarsimp\n apply (rename_tac xs xsa ys ysa zs zsa)\n apply(rule_tac x=xs in exI, rule_tac x=\"ys @ e2 # ysa\" in exI, rule_tac x=zsa in exI)\n apply(subgoal_tac \"xs @ e1 # ys = xsa \\ zs = ysa @ e3 # zsa\")\n apply clarsimp\n apply(rule_tac xs=\"history i\" and ys=\"[e2]\" in pre_suf_eq_distinct_list)\n apply auto\ndone\n\nlemma (in node_histories) local_order_carrier_closed:\n assumes \"e1 \\\\<^sup>i e2\"\n shows \"{e1,e2} \\ set (history i)\"\nusing assms by (clarsimp simp add: history_order_def)\n (metis in_set_conv_decomp Un_iff Un_subset_iff insert_subset list.simps(15) set_append set_subset_Cons)+\n\nlemma (in node_histories) node_total_order_irrefl:\n shows \"\\ (e \\\\<^sup>i e)\"\nby(clarsimp simp add: history_order_def)\n (metis Un_iff histories_distinct distinct_append distinct_set_notin list.set_intros(1) set_append)\n\nlemma (in node_histories) node_total_order_antisym:\n assumes \"e1 \\\\<^sup>i e2\"\n and \"e2 \\\\<^sup>i e1\"\n shows \"False\"\n using assms node_total_order_irrefl node_total_order_trans by blast\n\nlemma (in node_histories) node_order_is_total:\n assumes \"e1 \\ set (history i)\"\n and \"e2 \\ set (history i)\"\n and \"e1 \\ e2\"\n shows \"e1 \\\\<^sup>i e2 \\ e2 \\\\<^sup>i e1\"\n using assms unfolding history_order_def by(metis list_split_two_elems histories_distinct)\n\ndefinition (in node_histories) prefix_of_node_history :: \"'evt list \\ nat \\ bool\" (infix \"prefix of\" 50) where\n \"xs prefix of i \\ \\ys. xs@ys = history i\"\n\nlemma (in node_histories) carriers_head_lt:\n assumes \"y#ys = history i\"\n shows \"\\(x \\\\<^sup>i y)\"\nusing assms\n apply(clarsimp simp add: history_order_def)\n apply (rename_tac xs ysa zs)\n apply (subgoal_tac \"xs @ x # ysa = [] \\ zs = ys\")\n apply clarsimp\n apply (rule_tac xs=\"history i\" and ys=\"[y]\" in pre_suf_eq_distinct_list)\n apply auto\ndone\n\nlemma (in node_histories) prefix_of_ConsD [dest]:\n assumes \"x # xs prefix of i\"\n shows \"[x] prefix of i\"\nusing assms by(auto simp: prefix_of_node_history_def)\n\nlemma (in node_histories) prefix_of_appendD [dest]:\n assumes \"xs @ ys prefix of i\"\n shows \"xs prefix of i\"\nusing assms by(auto simp: prefix_of_node_history_def)\n\nlemma (in node_histories) prefix_distinct:\n assumes \"xs prefix of i\"\n shows \"distinct xs\"\nusing assms by(clarsimp simp: prefix_of_node_history_def) (metis histories_distinct distinct_append)\n\nlemma (in node_histories) prefix_to_carriers [intro]:\n assumes \"xs prefix of i\"\n shows \"set xs \\ set (history i)\"\nusing assms by(clarsimp simp: prefix_of_node_history_def) (metis Un_iff set_append)\n\nlemma (in node_histories) prefix_elem_to_carriers:\n assumes \"xs prefix of i\"\n and \"x \\ set xs\"\n shows \"x \\ set (history i)\"\nusing assms by(clarsimp simp: prefix_of_node_history_def) (metis Un_iff set_append)\n\nlemma (in node_histories) local_order_prefix_closed:\n assumes \"x \\\\<^sup>i y\"\n and \"xs prefix of i\"\n and \"y \\ set xs\"\n shows \"x \\ set xs\"\nusing assms\n apply -\n apply (frule prefix_distinct)\n apply (insert histories_distinct[where i=i])\n apply (clarsimp simp: history_order_def prefix_of_node_history_def)\n apply (frule split_list)\n apply clarsimp\n apply (subgoal_tac \"ysb = xsa @ x # ysa \\ zsa @ ys = zs\")\n apply clarsimp\n apply (rule_tac xs=\"history i\" and ys=\"[y]\" in pre_suf_eq_distinct_list)\n apply auto\ndone\n\nlemma (in node_histories) local_order_prefix_closed_last:\n assumes \"x \\\\<^sup>i y\"\n and \"xs@[y] prefix of i\"\n shows \"x \\ set xs\"\nusing assms\n apply -\n apply(frule local_order_prefix_closed, assumption, force)\n apply(auto simp add: node_total_order_irrefl prefix_to_carriers)\ndone\n\nlemma (in node_histories) events_before_exist:\n assumes \"x \\ set (history i)\"\n shows \"\\pre. pre @ [x] prefix of i\"\n using assms unfolding prefix_of_node_history_def apply -\n apply(subgoal_tac \"\\idx. idx < length (history i) \\ (history i) ! idx = x\")\n apply(metis append_take_drop_id take_Suc_conv_app_nth)\n apply(simp add: set_elem_nth)\ndone\n\nlemma (in node_histories) events_in_local_order:\n assumes \"pre @ [e2] prefix of i\"\n and \"e1 \\ set pre\"\n shows \"e1 \\\\<^sup>i e2\"\nusing assms split_list unfolding history_order_def prefix_of_node_history_def by fastforce\n\nsubsection\\Asynchronous broadcast networks\\\n \ntext\\We define a new locale $\\isa{network}$ containing three axioms that define how broadcast\n and deliver events may interact, with these axioms defining the properties of our network model.\\\n\ndatatype 'msg event\n = Broadcast 'msg\n | Deliver 'msg\n\nlocale network = node_histories history for history :: \"nat \\ 'msg event list\" +\n fixes msg_id :: \"'msg \\ 'msgid\"\n (* Broadcast\/Deliver interaction *)\n assumes delivery_has_a_cause: \"\\ Deliver m \\ set (history i) \\ \\\n \\j. Broadcast m \\ set (history j)\"\n and deliver_locally: \"\\ Broadcast m \\ set (history i) \\ \\\n Broadcast m \\\\<^sup>i Deliver m\"\n and msg_id_unique: \"\\ Broadcast m1 \\ set (history i);\n Broadcast m2 \\ set (history j);\n msg_id m1 = msg_id m2 \\ \\ i = j \\ m1 = m2\"\n\ntext\\\nThe axioms can be understood as follows:\n\\begin{description}\n \\item[delivery-has-a-cause:] If some message $\\isa{m}$ was delivered at some node, then there exists some node on which $\\isa{m}$ was broadcast.\n With this axiom, we assert that messages are not created ``out of thin air'' by the network itself, and that the only source of messages are the nodes.\n \\item[deliver-locally:] If a node broadcasts some message $\\isa{m}$, then the same node must subsequently also deliver $\\isa{m}$ to itself.\n Since $\\isa{m}$ does not actually travel over the network, this local delivery is always possible, even if the network is interrupted.\n Local delivery may seem redundant, since the effect of the delivery could also be implemented by the broadcast event itself; however, it is standard practice in the description of broadcast protocols that the sender of a message also sends it to itself, since this property simplifies the definition of algorithms built on top of the broadcast abstraction \\cite{Cachin:2011wt}.\n \\item[msg-id-unique:] We do not assume that the message type $\\isacharprime\\isa{msg}$ has any particular structure; we only assume the existence of a function $\\isa{msg-id} \\mathbin{\\isacharcolon\\isacharcolon} \\isacharprime\\isa{msg} \\mathbin{\\isasymRightarrow} \\isacharprime\\isa{msgid}$ that maps every message to some globally unique identifier of type $\\isacharprime\\isa{msgid}$.\n We assert this uniqueness by stating that if $\\isa{m1}$ and $\\isa{m2}$ are any two messages broadcast by any two nodes, and their $\\isa{msg-id}$s are the same, then they were in fact broadcast by the same node and the two messages are identical. \n In practice, these globally unique IDs can by implemented using unique node identifiers, sequence numbers or timestamps.\n\\end{description}\n\\\n \nlemma (in network) broadcast_before_delivery:\n assumes \"Deliver m \\ set (history i)\"\n shows \"\\j. Broadcast m \\\\<^sup>j Deliver m\"\n using assms deliver_locally delivery_has_a_cause by blast\n\nlemma (in network) broadcasts_unique:\n assumes \"i \\ j\"\n and \"Broadcast m \\ set (history i)\"\n shows \"Broadcast m \\ set (history j)\"\n using assms msg_id_unique by blast\n \ntext\\Based on the well-known definition by \\cite{Lamport:1978jq}, we say that\n $\\isa{m1}\\prec\\isa{m2}$ if any of the following is true:\n \\begin{enumerate}\n \\item $\\isa{m1}$ and $\\isa{m2}$ were broadcast by the same node, and $\\isa{m1}$ was broadcast before $\\isa{m2}$.\n \\item The node that broadcast $\\isa{m2}$ had delivered $\\isa{m1}$ before it broadcast $\\isa{m2}$.\n \\item There exists some operation $\\isa{m3}$ such that $\\isa{m1} \\prec \\isa{m3}$ and $\\isa{m3} \\prec \\isa{m2}$.\n \\end{enumerate}\\\n\ninductive (in network) hb :: \"'msg \\ 'msg \\ bool\" where\n \"\\ Broadcast m1 \\\\<^sup>i Broadcast m2 \\ \\ hb m1 m2\" |\n \"\\ Deliver m1 \\\\<^sup>i Broadcast m2 \\ \\ hb m1 m2\" |\n \"\\ hb m1 m2; hb m2 m3 \\ \\ hb m1 m3\"\n \ninductive_cases (in network) hb_elim: \"hb x y\"\n \ndefinition (in network) weak_hb :: \"'msg \\ 'msg \\ bool\" where\n \"weak_hb m1 m2 \\ hb m1 m2 \\ m1 = m2\"\n\nlocale causal_network = network +\n assumes causal_delivery: \"Deliver m2 \\ set (history j) \\ hb m1 m2 \\ Deliver m1 \\\\<^sup>j Deliver m2\"\n\nlemma (in causal_network) causal_broadcast:\n assumes \"Deliver m2 \\ set (history j)\"\n and \"Deliver m1 \\\\<^sup>i Broadcast m2\"\n shows \"Deliver m1 \\\\<^sup>j Deliver m2\"\n using assms causal_delivery hb.intros(2) by blast\n\nlemma (in network) hb_broadcast_exists1:\n assumes \"hb m1 m2\"\n shows \"\\i. Broadcast m1 \\ set (history i)\"\n using assms\n apply(induction rule: hb.induct)\n apply(meson insert_subset node_histories.local_order_carrier_closed node_histories_axioms)\n apply(meson delivery_has_a_cause insert_subset local_order_carrier_closed)\n apply simp\ndone\n \nlemma (in network) hb_broadcast_exists2:\n assumes \"hb m1 m2\"\n shows \"\\i. Broadcast m2 \\ set (history i)\"\n using assms\n apply(induction rule: hb.induct)\n apply(meson insert_subset node_histories.local_order_carrier_closed node_histories_axioms)\n apply(meson delivery_has_a_cause insert_subset local_order_carrier_closed)\n apply simp\ndone\n \nsubsection\\Causal networks\\\n\nlemma (in causal_network) hb_has_a_reason:\n assumes \"hb m1 m2\"\n and \"Broadcast m2 \\ set (history i)\"\n shows \"Deliver m1 \\ set (history i) \\ Broadcast m1 \\ set (history i)\"\n using assms\n apply(induction rule: hb.induct)\n apply(metis insert_subset local_order_carrier_closed network.broadcasts_unique network_axioms)\n apply(metis insert_subset local_order_carrier_closed network.broadcasts_unique network_axioms)\n apply(case_tac \"Deliver m2 \\ set (history i)\")\n apply(subgoal_tac \"Deliver m1 \\ set (history i)\")\n apply blast\n using causal_delivery local_order_carrier_closed apply blast\n apply(subgoal_tac \"Broadcast m2 \\ set (history i)\")\n apply blast+\ndone\n\nlemma (in causal_network) hb_cross_node_delivery:\n assumes \"hb m1 m2\"\n and \"Broadcast m1 \\ set (history i)\"\n and \"Broadcast m2 \\ set (history j)\"\n and \"i \\ j\"\n shows \"Deliver m1 \\ set (history j)\"\n using assms\n apply(induction rule: hb.induct)\n apply(metis broadcasts_unique insert_subset local_order_carrier_closed)\n apply(metis insert_subset local_order_carrier_closed network.broadcasts_unique network_axioms)\n apply(case_tac \"Deliver m2 \\ set (history j)\")\n apply(subgoal_tac \"Deliver m1 \\ set (history j)\")\n apply blast\n using broadcasts_unique hb.intros(3) hb_has_a_reason apply blast\n apply(subgoal_tac \"Broadcast m2 \\ set (history j)\")\n apply blast\n using hb_has_a_reason apply blast \n done\n \nlemma (in causal_network) hb_irrefl:\n assumes \"hb m1 m2\"\n shows \"m1 \\ m2\"\n using assms\n apply(induction rule: hb.induct)\n using node_total_order_antisym apply blast\n apply(meson causal_broadcast insert_subset local_order_carrier_closed\n node_total_order_irrefl)\n apply(subgoal_tac \"\\i. Broadcast m3 \\ set (history i)\")\n apply(subgoal_tac \"\\j. Broadcast m2 \\ set (history j)\")\n apply clarsimp\n apply(subgoal_tac \"Deliver m2 \\ set (history j) \\ Deliver m3 \\ set (history i)\")\n apply(meson causal_delivery hb.intros(3) insert_subset local_order_carrier_closed\n network.broadcast_before_delivery network_axioms node_total_order_irrefl)\n apply(meson deliver_locally insert_subset local_order_carrier_closed)\n apply(simp add: hb_broadcast_exists2)+\ndone\n\nlemma (in causal_network) hb_broadcast_broadcast_order:\n assumes \"hb m1 m2\"\n and \"Broadcast m1 \\ set (history i)\"\n and \"Broadcast m2 \\ set (history i)\"\n shows \"Broadcast m1 \\\\<^sup>i Broadcast m2\"\n using assms\n apply(induction rule: hb.induct)\n apply(metis insertI1 local_order_carrier_closed network.broadcasts_unique\n network_axioms subsetCE)\n apply(metis broadcasts_unique insert_subset local_order_carrier_closed\n network.broadcast_before_delivery network_axioms node_total_order_trans)\n apply(case_tac \"Broadcast m2 \\ set (history i)\")\n using node_total_order_trans apply blast\n apply(subgoal_tac \"Deliver m2 \\ set (history i)\")\n apply(subgoal_tac \"m1 \\ m2 \\ m2 \\ m3\")\n apply(metis event.inject(1) hb.intros(1) hb_irrefl network.hb.intros(3) network_axioms\n node_order_is_total hb_irrefl)\n using hb_has_a_reason apply blast+\ndone\n\nlemma (in causal_network) hb_antisym:\n assumes \"hb x y\"\n and \"hb y x\"\n shows \"False\"\nusing assms proof(induction rule: hb.induct)\n fix m1 i m2 \n assume \"hb m2 m1\" and \"Broadcast m1 \\\\<^sup>i Broadcast m2\"\n thus False\n apply - proof(erule hb_elim)\n show \"\\ia. Broadcast m1 \\\\<^sup>i Broadcast m2 \\ Broadcast m2 \\\\<^sup>ia Broadcast m1 \\ False\"\n by(metis broadcasts_unique insert_subset local_order_carrier_closed node_total_order_irrefl node_total_order_trans)\n next\n show \"\\ia. Broadcast m1 \\\\<^sup>i Broadcast m2 \\ Deliver m2 \\\\<^sup>ia Broadcast m1 \\ False\"\n by(metis broadcast_before_delivery broadcasts_unique insert_subset local_order_carrier_closed node_total_order_irrefl node_total_order_trans)\n next\n show \"\\m2a. Broadcast m1 \\\\<^sup>i Broadcast m2 \\ hb m2 m2a \\ hb m2a m1 \\ False\"\n using assms(1) assms(2) hb.intros(3) hb_irrefl by blast\n qed\nnext\n fix m1 i m2\n assume \"hb m2 m1\"\n and \"Deliver m1 \\\\<^sup>i Broadcast m2\"\n thus \"False\"\n apply - proof(erule hb_elim)\n show \"\\ia. Deliver m1 \\\\<^sup>i Broadcast m2 \\ Broadcast m2 \\\\<^sup>ia Broadcast m1 \\ False\"\n by (metis broadcast_before_delivery broadcasts_unique insert_subset local_order_carrier_closed node_total_order_irrefl node_total_order_trans)\n next\n show \"\\ia. Deliver m1 \\\\<^sup>i Broadcast m2 \\ Deliver m2 \\\\<^sup>ia Broadcast m1 \\ False\"\n by (meson causal_network.causal_delivery causal_network_axioms hb.intros(2) hb.intros(3) insert_subset local_order_carrier_closed node_total_order_irrefl)\n next\n show \"\\m2a. Deliver m1 \\\\<^sup>i Broadcast m2 \\ hb m2 m2a \\ hb m2a m1 \\ False\"\n by (meson causal_delivery hb.intros(2) insert_subset local_order_carrier_closed network.hb.intros(3) network_axioms node_total_order_irrefl)\n qed\nnext\n fix m1 m2 m3\n assume \"hb m1 m2\" \"hb m2 m3\" \"hb m3 m1\"\n and \"(hb m2 m1 \\ False)\" \"(hb m3 m2 \\ False)\"\n thus \"False\"\n using hb.intros(3) by blast\nqed\n\ndefinition (in network) node_deliver_messages :: \"'msg event list \\ 'msg list\" where\n \"node_deliver_messages cs \\ List.map_filter (\\e. case e of Deliver m \\ Some m | _ \\ None) cs\"\n\nlemma (in network) node_deliver_messages_empty [simp]:\n shows \"node_deliver_messages [] = []\"\nby(auto simp add: node_deliver_messages_def List.map_filter_simps)\n\nlemma (in network) node_deliver_messages_append:\n shows \"node_deliver_messages (xs@ys) = (node_deliver_messages xs)@(node_deliver_messages ys)\"\nby(auto simp add: node_deliver_messages_def map_filter_def)\n\nlemma (in network) node_deliver_messages_Broadcast [simp]:\n shows \"node_deliver_messages [Broadcast m] = []\"\nby(clarsimp simp: node_deliver_messages_def map_filter_def)\n\nlemma (in network) node_deliver_messages_Deliver [simp]:\n shows \"node_deliver_messages [Deliver m] = [m]\"\nby(clarsimp simp: node_deliver_messages_def map_filter_def)\n\nlemma (in network) prefix_msg_in_history:\n assumes \"es prefix of i\"\n and \"m \\ set (node_deliver_messages es)\"\n shows \"Deliver m \\ set (history i)\"\nusing assms\n apply(clarsimp simp: node_deliver_messages_def map_filter_def split: event.split_asm)\n using prefix_to_carriers apply auto\ndone\n\nlemma (in network) prefix_contains_msg:\n assumes \"es prefix of i\"\n and \"m \\ set (node_deliver_messages es)\"\n shows \"Deliver m \\ set es\"\n using assms by(auto simp: node_deliver_messages_def map_filter_def split: event.split_asm)\n \nlemma (in network) node_deliver_messages_distinct:\n assumes \"xs prefix of i\"\n shows \"distinct (node_deliver_messages xs)\"\nusing assms\n apply(induction xs rule: rev_induct, simp)\n apply(clarsimp simp add: node_deliver_messages_append)\n apply(safe, force)\n apply(clarsimp simp: node_deliver_messages_def map_filter_def)\n apply(frule prefix_distinct)\n apply(clarsimp simp add: map_filter_def node_deliver_messages_def)\n apply(rename_tac x xs y z)\n apply(case_tac x; clarsimp)\n apply(case_tac y; clarsimp)\ndone\n\nlemma (in network) drop_last_message:\n assumes \"evts prefix of i\"\n and \"node_deliver_messages evts = msgs @ [last_msg]\"\n shows \"\\pre. pre prefix of i \\ node_deliver_messages pre = msgs\"\nusing assms apply -\n apply(subgoal_tac \"\\pre suf. evts = pre @ (Deliver last_msg) # suf \\ node_deliver_messages suf = []\")\n apply(erule exE)+\n apply(simp)\n apply(rule_tac x=pre in exI)\n apply(rule conjI)\n using prefix_of_appendD apply blast\n apply(subgoal_tac \"node_deliver_messages ([Deliver last_msg] @ suf) = [last_msg]\")\n apply(simp add: node_deliver_messages_append)\n apply(metis append_Nil2 node_deliver_messages_append node_deliver_messages_Deliver)\n apply(subgoal_tac \"Deliver last_msg \\ set evts\")\n defer\n apply(simp add: prefix_contains_msg)\n apply(subgoal_tac \"\\idx. idx < length evts \\ evts ! idx = Deliver last_msg\")\n apply(erule exE)\n apply(subgoal_tac \"\\pre suf. evts = pre @ (evts ! idx) # suf\")\n defer\n using list_nth_split_technical id_take_nth_drop apply blast\n apply(simp add: set_elem_nth)\n apply(erule exE)+\n apply(rule_tac x=pre in exI, rule_tac x=suf in exI)\n apply(rule conjI, simp, simp)\n apply(subgoal_tac \"node_deliver_messages (pre @ Deliver last_msg # suf) =\n (node_deliver_messages pre) @ (node_deliver_messages (Deliver last_msg # suf))\")\n apply(subgoal_tac \"node_deliver_messages ([Deliver last_msg] @ suf) = [last_msg] @ []\")\n apply(metis node_deliver_messages_Deliver node_deliver_messages_append self_append_conv)\n apply(auto simp add: node_deliver_messages_append)\n apply(subgoal_tac \"node_deliver_messages ([Deliver last_msg] @ suf) = [last_msg] @ []\")\n apply(simp add: node_deliver_messages_append)\n apply(metis append_Cons node_deliver_messages_Deliver node_deliver_messages_append\n node_deliver_messages_distinct not_Cons_self2 pre_suf_eq_distinct_list self_append_conv2)\ndone\n\nlocale network_with_ops = causal_network history fst\n for history :: \"nat \\ ('msgid \\ 'op) event list\" +\n fixes interp :: \"'op \\ 'state \\ 'state\"\n and initial_state :: \"'state\"\n\ncontext network_with_ops begin\n\ndefinition interp_msg :: \"'msgid \\ 'op \\ 'state \\ 'state\" where\n \"interp_msg msg state \\ interp (snd msg) state\"\n\nsublocale hb: happens_before weak_hb hb interp_msg\nproof\n fix x y :: \"'msgid \\ 'op\"\n show \"hb x y = (weak_hb x y \\ \\ weak_hb y x)\"\n unfolding weak_hb_def using hb_antisym by blast\nnext\n fix x\n show \"weak_hb x x\"\n using weak_hb_def by blast\nnext\n fix x y z\n assume \"weak_hb x y\" \"weak_hb y z\"\n thus \"weak_hb x z\"\n using weak_hb_def by (metis network.hb.intros(3) network_axioms)\nqed\n\nend\n\ndefinition (in network_with_ops) apply_operations :: \"('msgid \\ 'op) event list \\ 'state\" where\n \"apply_operations es \\ hb.apply_operations (node_deliver_messages es) initial_state\"\n\ndefinition (in network_with_ops) node_deliver_ops :: \"('msgid \\ 'op) event list \\ 'op list\" where\n \"node_deliver_ops cs \\ map snd (node_deliver_messages cs)\"\n\nlemma (in network_with_ops) apply_operations_empty [simp]:\n shows \"apply_operations [] = Some initial_state\"\nby(auto simp add: apply_operations_def)\n\nlemma (in network_with_ops) apply_operations_Broadcast [simp]:\n shows \"apply_operations (xs @ [Broadcast m]) = apply_operations xs\"\nby(auto simp add: apply_operations_def node_deliver_messages_def map_filter_def)\n\nlemma (in network_with_ops) apply_operations_Deliver [simp]:\n shows \"apply_operations (xs @ [Deliver m]) = (apply_operations xs \\ interp_msg m)\"\nby(auto simp add: apply_operations_def node_deliver_messages_def map_filter_def kleisli_def)\n\nlemma (in network_with_ops) hb_consistent_technical:\n assumes \"\\m n. m < length cs \\ n < m \\ cs ! n \\\\<^sup>i cs ! m\"\n shows \"hb.hb_consistent (node_deliver_messages cs)\"\nusing assms\n apply -\n apply(induction cs rule: rev_induct)\n apply(unfold node_deliver_messages_def)\n apply(simp add: hb.hb_consistent.intros(1) map_filter_simps(2))\n apply(case_tac x; clarify)\n apply(simp add: List.map_filter_def)\n apply(subgoal_tac \"(\\m n. m < length xs \\ n < m \\ xs ! n \\\\<^sup>i xs ! m)\")\n apply clarsimp\n apply(erule_tac x=m in meta_allE, erule_tac x=n in meta_allE, clarsimp simp add: nth_append)\n apply(subst map_filter_append)\n apply(clarsimp simp add: map_filter_def)\n apply(rule hb.hb_consistent.intros)\n apply(subgoal_tac \"(\\m n. m < length xs \\ n < m \\ xs ! n \\\\<^sup>i xs ! m)\")\n apply clarsimp\n apply(erule_tac x=m in meta_allE, erule_tac x=n in meta_allE, clarsimp simp add: nth_append)\n apply clarsimp\n apply(case_tac x; clarsimp)\n apply(drule set_elem_nth, erule exE, erule conjE)\n apply(erule_tac x=\"length xs\" in meta_allE, erule_tac x=m in meta_allE)\n apply clarsimp\n apply(subst (asm) nth_append, simp)\n apply(meson causal_network.causal_delivery causal_network_axioms insert_subset node_histories.local_order_carrier_closed node_histories_axioms node_total_order_irrefl node_total_order_trans)\ndone\n\ncorollary (in network_with_ops)\n shows \"hb.hb_consistent (node_deliver_messages (history i))\"\n apply(subgoal_tac \"history i = [] \\ (\\c. history i = [c]) \\ (length (history i) \\ 2)\")\n apply(erule disjE, clarsimp simp add: node_deliver_messages_def map_filter_def)\n apply(erule disjE, clarsimp simp add: node_deliver_messages_def map_filter_def)\n apply blast\n apply(cases \"history i\"; clarsimp; case_tac \"list\"; clarsimp)\n apply(rule hb_consistent_technical[where i=i]) \n apply(subst history_order_def, clarsimp)\n apply(metis list_nth_split One_nat_def Suc_le_mono cancel_comm_monoid_add_class.diff_cancel\n le_imp_less_Suc length_Cons less_Suc_eq_le less_imp_diff_less neq0_conv nth_Cons_pos)\n apply(cases \"history i\"; clarsimp; case_tac \"list\"; clarsimp)\ndone\n\nlemma (in network_with_ops) hb_consistent_prefix:\n assumes \"xs prefix of i\"\n shows \"hb.hb_consistent (node_deliver_messages xs)\"\nusing assms\n apply(clarsimp simp: prefix_of_node_history_def)\n apply(rule_tac i=i in hb_consistent_technical)\n apply(subst history_order_def)\n apply(subgoal_tac \"xs = [] \\ (\\c. xs = [c]) \\ (length (xs) > 1)\")\n apply(erule disjE)\n apply clarsimp\n apply(erule disjE)\n apply clarsimp\n apply(drule list_nth_split)\n apply assumption\n apply clarsimp\n apply clarsimp\n apply(rule_tac x=xsa in exI)\n apply(rule_tac x=ysa in exI)\n apply(rule_tac x=\"zs@ys\" in exI)\n apply(metis Cons_eq_appendI append_assoc)\n apply force\n done\n\nlocale network_with_constrained_ops = network_with_ops history interp initial_state\n for history :: \"nat \\ ('msgid \\ 'op) event list\"\n and interp :: \"'op \\ 'state \\ 'state\"\n and initial_state :: \"'state\" +\n fixes valid_msgs :: \"nat \\ 'state \\ ('msgid \\ 'op) set\"\n\n assumes broadcast_only_valid_msgs: \"pre @ [Broadcast m] prefix of i \\\n \\state. apply_operations pre = Some state \\ m \\ valid_msgs i state\"\n\nlemma (in network_with_constrained_ops) broadcast_is_valid:\n assumes \"Broadcast m \\ set (history i)\"\n shows \"\\state. m \\ valid_msgs i state\"\n using assms\n apply(subgoal_tac \"\\pre. pre @ [Broadcast m] prefix of i\")\n using broadcast_only_valid_msgs apply blast\n using events_before_exist apply blast\ndone\n\nlemma (in network_with_constrained_ops) deliver_is_valid:\n assumes \"Deliver m \\ set (history i)\"\n shows \"\\j pre state. pre @ [Broadcast m] prefix of j \\ apply_operations pre = Some state \\ m \\ valid_msgs j state\"\n using assms apply -\n apply(drule delivery_has_a_cause)\n apply(erule exE)\n apply(subgoal_tac \"\\pre. pre @ [Broadcast m] prefix of j\")\n using broadcast_only_valid_msgs apply blast\n using events_before_exist apply blast\ndone\n\nlemma (in network_with_constrained_ops) deliver_in_prefix_is_valid:\n assumes \"xs prefix of i\"\n and \"Deliver m \\ set xs\"\n shows \"\\i state. m \\ valid_msgs i state\"\n using assms apply -\n apply(subgoal_tac \"Deliver m \\ set (history i)\")\n apply(drule delivery_has_a_cause)\n apply(erule exE, rule_tac x=j in exI)\n apply(rule broadcast_is_valid, assumption)\n apply(simp add: prefix_elem_to_carriers)\ndone\n\nsubsection\\Dummy network models\\\n\ninterpretation trivial_node_histories: node_histories \"\\m. []\"\n by standard auto\n\ninterpretation trivial_network: network \"\\m. []\" id\n by standard auto\n \ninterpretation trivial_causal_network: causal_network \"\\m. []\" id\n by standard auto\n\ninterpretation trivial_network_with_ops: network_with_ops \"\\m. []\" \"(\\x y. Some y)\" 0\n by standard auto\n\ninterpretation trivial_network_with_constrained_ops: network_with_constrained_ops \"\\m. []\" \"(\\x y. Some y)\" 0 \"\\i x. {}\"\n by standard (simp add: trivial_node_histories.prefix_of_node_history_def)\n\nend\n","avg_line_length":46.0431309904,"max_line_length":385,"alphanum_fraction":0.738576831} {"size":139,"ext":"thy","lang":"Isabelle","max_stars_count":2.0,"content":"header {* Minimalistic IsaPlanner for HOL *}\ntheory PreIsaP\nimports HOL IsaPHOLUtils PureIsaP RippleNotation EmbeddingNotation \nbegin\n\nend;","avg_line_length":23.1666666667,"max_line_length":67,"alphanum_fraction":0.8345323741} {"size":7219,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/n_g2kAbsAfter_lemma_on_inv__75.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_g2kAbsAfter Protocol Case Study*} \n\ntheory n_g2kAbsAfter_lemma_on_inv__75 imports n_g2kAbsAfter_base\nbegin\nsection{*All lemmas on causal relation between inv__75 and some rule r*}\nlemma n_n_RecvReq_i1Vsinv__75:\nassumes a1: \"(r=n_n_RecvReq_i1 )\" and\na2: \"(f=inv__75 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P3 s\"\n apply (cut_tac a1 a2 , simp, rule_tac x=\"(neg (andForm (eqn (IVar (Field (Ident ''Chan3_1'') ''Cmd'')) (Const InvAck)) (eqn (IVar (Ident ''CurCmd'')) (Const Empty))))\" in exI, auto) done\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_SendInvE_i1Vsinv__75:\nassumes a1: \"(r=n_n_SendInvE_i1 )\" and\na2: \"(f=inv__75 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_SendInvS_i1Vsinv__75:\nassumes a1: \"(r=n_n_SendInvS_i1 )\" and\na2: \"(f=inv__75 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_SendInvAck_i1Vsinv__75:\nassumes a1: \"(r=n_n_SendInvAck_i1 )\" and\na2: \"(f=inv__75 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P3 s\"\n apply (cut_tac a1 a2 , simp, rule_tac x=\"(neg (andForm (eqn (IVar (Ident ''InvSet_1'')) (Const true)) (eqn (IVar (Field (Ident ''Chan2_1'') ''Cmd'')) (Const Inv))))\" in exI, auto) done\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_RecvInvAck_i1Vsinv__75:\nassumes a1: \"(r=n_n_RecvInvAck_i1 )\" and\na2: \"(f=inv__75 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P1 s\"\n proof(cut_tac a1 a2 , auto) qed\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_ARecvReq_i1Vsinv__75:\nassumes a1: \"(r=n_n_ARecvReq_i1 )\" and\na2: \"(f=inv__75 )\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\n have \"?P3 s\"\n apply (cut_tac a1 a2 , simp, rule_tac x=\"(neg (andForm (eqn (IVar (Field (Ident ''Chan3_1'') ''Cmd'')) (Const InvAck)) (eqn (IVar (Ident ''CurCmd'')) (Const Empty))))\" in exI, auto) done\n then show \"invHoldForRule s f r (invariants N)\" by auto\nqed\n\nlemma n_n_SendReqEI_i1Vsinv__75:\n assumes a1: \"r=n_n_SendReqEI_i1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendReqEI_i1Vsinv__75:\n assumes a1: \"r=n_n_ASendReqEI_i1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendReqIS_j1Vsinv__75:\n assumes a1: \"r=n_n_ASendReqIS_j1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_SendGntE_i1Vsinv__75:\n assumes a1: \"r=n_n_SendGntE_i1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendReqES_i1Vsinv__75:\n assumes a1: \"r=n_n_ASendReqES_i1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ARecvGntE_i1Vsinv__75:\n assumes a1: \"r=n_n_ARecvGntE_i1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendGntS_i1Vsinv__75:\n assumes a1: \"r=n_n_ASendGntS_i1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ARecvGntS_i1Vsinv__75:\n assumes a1: \"r=n_n_ARecvGntS_i1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendInvE_i1Vsinv__75:\n assumes a1: \"r=n_n_ASendInvE_i1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_SendGntS_i1Vsinv__75:\n assumes a1: \"r=n_n_SendGntS_i1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendInvS_i1Vsinv__75:\n assumes a1: \"r=n_n_ASendInvS_i1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_SendReqES_i1Vsinv__75:\n assumes a1: \"r=n_n_SendReqES_i1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendReqSE_j1Vsinv__75:\n assumes a1: \"r=n_n_ASendReqSE_j1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_RecvGntS_i1Vsinv__75:\n assumes a1: \"r=n_n_RecvGntS_i1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_SendReqEE_i1Vsinv__75:\n assumes a1: \"r=n_n_SendReqEE_i1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_RecvGntE_i1Vsinv__75:\n assumes a1: \"r=n_n_RecvGntE_i1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_Store_i1Vsinv__75:\n assumes a1: \"\\ d. d\\N\\r=n_n_Store_i1 d\" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_AStore_i1Vsinv__75:\n assumes a1: \"\\ d. d\\N\\r=n_n_AStore_i1 d\" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_SendReqS_j1Vsinv__75:\n assumes a1: \"r=n_n_SendReqS_j1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ARecvInvAck_i1Vsinv__75:\n assumes a1: \"r=n_n_ARecvInvAck_i1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendInvAck_i1Vsinv__75:\n assumes a1: \"r=n_n_ASendInvAck_i1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_n_ASendGntE_i1Vsinv__75:\n assumes a1: \"r=n_n_ASendGntE_i1 \" and\n a2: \"(f=inv__75 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \nend\n","avg_line_length":32.0844444444,"max_line_length":188,"alphanum_fraction":0.6989887796} {"size":14244,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/n_germanSimp_lemma_on_inv__60.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_germanSimp Protocol Case Study*} \n\ntheory n_germanSimp_lemma_on_inv__60 imports n_germanSimp_base\nbegin\nsection{*All lemmas on causal relation between inv__60 and some rule r*}\nlemma n_RecvReqSVsinv__60:\nassumes a1: \"(\\ i. i\\N\\r=n_RecvReqS N i)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_RecvReqS N i\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i=p__Inv3)\\(i~=p__Inv3\\i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (andForm (eqn (IVar (Para (Ident ''ShrSet'') p__Inv4)) (Const true)) (eqn (IVar (Ident ''ExGntd'')) (Const true))) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv3)) (Const true))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i=p__Inv3)\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (andForm (eqn (IVar (Para (Ident ''ShrSet'') p__Inv4)) (Const true)) (eqn (IVar (Ident ''ExGntd'')) (Const true))) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv3)) (Const true))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv3\\i~=p__Inv4)\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (andForm (eqn (IVar (Para (Ident ''ShrSet'') p__Inv4)) (Const true)) (eqn (IVar (Ident ''ExGntd'')) (Const true))) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv3)) (Const true))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_RecvReqE__part__0Vsinv__60:\nassumes a1: \"(\\ i. i\\N\\r=n_RecvReqE__part__0 N i)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_RecvReqE__part__0 N i\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i=p__Inv3)\\(i~=p__Inv3\\i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (andForm (eqn (IVar (Para (Ident ''ShrSet'') p__Inv4)) (Const true)) (eqn (IVar (Ident ''ExGntd'')) (Const true))) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv3)) (Const true))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i=p__Inv3)\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (andForm (eqn (IVar (Para (Ident ''ShrSet'') p__Inv4)) (Const true)) (eqn (IVar (Ident ''ExGntd'')) (Const true))) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv3)) (Const true))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv3\\i~=p__Inv4)\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (andForm (eqn (IVar (Para (Ident ''ShrSet'') p__Inv4)) (Const true)) (eqn (IVar (Ident ''ExGntd'')) (Const true))) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv3)) (Const true))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_RecvReqE__part__1Vsinv__60:\nassumes a1: \"(\\ i. i\\N\\r=n_RecvReqE__part__1 N i)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_RecvReqE__part__1 N i\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i=p__Inv3)\\(i~=p__Inv3\\i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (eqn (IVar (Ident ''ExGntd'')) (Const true)) (eqn (IVar (Field (Para (Ident ''Cache'') p__Inv4) ''State'')) (Const S))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i=p__Inv3)\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (eqn (IVar (Ident ''ExGntd'')) (Const true)) (eqn (IVar (Field (Para (Ident ''Cache'') p__Inv3) ''State'')) (Const S))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv3\\i~=p__Inv4)\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (eqn (IVar (Ident ''ExGntd'')) (Const true)) (eqn (IVar (Field (Para (Ident ''Cache'') i) ''State'')) (Const S))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_SendInv__part__0Vsinv__60:\nassumes a1: \"(\\ i. i\\N\\r=n_SendInv__part__0 i)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_SendInv__part__0 i\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i=p__Inv3)\\(i~=p__Inv3\\i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i=p__Inv3)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv3\\i~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_SendInv__part__1Vsinv__60:\nassumes a1: \"(\\ i. i\\N\\r=n_SendInv__part__1 i)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_SendInv__part__1 i\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i=p__Inv3)\\(i~=p__Inv3\\i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i=p__Inv3)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv3\\i~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_RecvInvAckVsinv__60:\nassumes a1: \"(\\ i. i\\N\\r=n_RecvInvAck i)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_RecvInvAck i\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i=p__Inv3)\\(i~=p__Inv3\\i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\\((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))\" by auto\n moreover {\n assume c1: \"((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1 c1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n }\n moreover {\n assume c1: \"((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1 c1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n }\n ultimately have \"invHoldForRule s f r (invariants N)\" by satx\n}\nmoreover {\n assume b1: \"(i=p__Inv3)\"\n have \"((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\\((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))\" by auto\n moreover {\n assume c1: \"((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1 c1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n }\n moreover {\n assume c1: \"((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1 c1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n }\n ultimately have \"invHoldForRule s f r (invariants N)\" by satx\n}\nmoreover {\n assume b1: \"(i~=p__Inv3\\i~=p__Inv4)\"\n have \"((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\\((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))\" by auto\n moreover {\n assume c1: \"((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1 c1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n }\n moreover {\n assume c1: \"((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1 c1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n }\n ultimately have \"invHoldForRule s f r (invariants N)\" by satx\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_SendGntEVsinv__60:\nassumes a1: \"(\\ i. i\\N\\r=n_SendGntE N i)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\N\\r=n_SendGntE N i\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\(i=p__Inv3)\\(i~=p__Inv3\\i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(i=p__Inv4)\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (eqn (IVar (Para (Ident ''InvSet'') p__Inv4)) (Const true)) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv4)) (Const false))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i=p__Inv3)\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (eqn (IVar (Para (Ident ''InvSet'') p__Inv4)) (Const true)) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv4)) (Const false))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(i~=p__Inv3\\i~=p__Inv4)\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (eqn (IVar (Para (Ident ''InvSet'') p__Inv4)) (Const true)) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv4)) (Const false))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_StoreVsinv__60:\n assumes a1: \"\\ i d. i\\N\\d\\N\\r=n_Store i d\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_RecvGntSVsinv__60:\n assumes a1: \"\\ i. i\\N\\r=n_RecvGntS i\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_SendGntSVsinv__60:\n assumes a1: \"\\ i. i\\N\\r=n_SendGntS i\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_RecvGntEVsinv__60:\n assumes a1: \"\\ i. i\\N\\r=n_RecvGntE i\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_SendInvAckVsinv__60:\n assumes a1: \"\\ i. i\\N\\r=n_SendInvAck i\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__60 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \nend\n","avg_line_length":50.5106382979,"max_line_length":255,"alphanum_fraction":0.6759337265} {"size":2013,"ext":"thy","lang":"Isabelle","max_stars_count":1.0,"content":"theory T30\nimports Main\nbegin\nlemma \"(\n(\\ x::nat. \\ y::nat. meet(x, y) = meet(y, x)) &\n(\\ x::nat. \\ y::nat. join(x, y) = join(y, x)) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(x, meet(y, z)) = meet(meet(x, y), z)) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(x, join(y, z)) = join(join(x, y), z)) &\n(\\ x::nat. \\ y::nat. meet(x, join(x, y)) = x) &\n(\\ x::nat. \\ y::nat. join(x, meet(x, y)) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(x, join(y, z)) = join(mult(x, y), mult(x, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(join(x, y), z) = join(mult(x, z), mult(y, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(x, over(join(mult(x, y), z), y)) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(y, undr(x, join(mult(x, y), z))) = y) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(mult(over(x, y), y), x) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(mult(y, undr(y, x)), x) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(meet(x, y), z) = meet(mult(x, z), mult(y, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. undr(x, join(y, z)) = join(undr(x, y), undr(x, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. over(join(x, y), z) = join(over(x, z), over(y, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. over(x, meet(y, z)) = join(over(x, y), over(x, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. undr(meet(x, y), z) = join(undr(x, z), undr(y, z))) &\n(\\ x::nat. \\ y::nat. invo(join(x, y)) = meet(invo(x), invo(y))) &\n(\\ x::nat. \\ y::nat. invo(meet(x, y)) = join(invo(x), invo(y))) &\n(\\ x::nat. invo(invo(x)) = x)\n) \\\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(x, meet(y, z)) = meet(mult(x, y), mult(x, z)))\n\"\nnitpick[card nat=4,timeout=86400]\noops\nend","avg_line_length":67.1,"max_line_length":108,"alphanum_fraction":0.5325384998} {"size":4420,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/n_germanSymIndex_lemma_inv__37_on_rules.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_germanSymIndex Protocol Case Study*} \n\ntheory n_germanSymIndex_lemma_inv__37_on_rules imports n_germanSymIndex_lemma_on_inv__37\nbegin\nsection{*All lemmas on causal relation between inv__37*}\nlemma lemma_inv__37_on_rules:\n assumes b1: \"r \\ rules N\" and b2: \"(\\ p__Inv2. p__Inv2\\N\\f=inv__37 p__Inv2)\"\n shows \"invHoldForRule s f r (invariants N)\"\n proof -\n have c1: \"(\\ i d. i\\N\\d\\N\\r=n_Store i d)\\\n (\\ i. i\\N\\r=n_SendReqS i)\\\n (\\ i. i\\N\\r=n_SendReqE__part__0 i)\\\n (\\ i. i\\N\\r=n_SendReqE__part__1 i)\\\n (\\ i. i\\N\\r=n_RecvReqS N i)\\\n (\\ i. i\\N\\r=n_RecvReqE N i)\\\n (\\ i. i\\N\\r=n_SendInv__part__0 i)\\\n (\\ i. i\\N\\r=n_SendInv__part__1 i)\\\n (\\ i. i\\N\\r=n_SendInvAck i)\\\n (\\ i. i\\N\\r=n_RecvInvAck i)\\\n (\\ i. i\\N\\r=n_SendGntS i)\\\n (\\ i. i\\N\\r=n_SendGntE N i)\\\n (\\ i. i\\N\\r=n_RecvGntS i)\\\n (\\ i. i\\N\\r=n_RecvGntE i)\"\n apply (cut_tac b1, auto) done\n moreover {\n assume d1: \"(\\ i d. i\\N\\d\\N\\r=n_Store i d)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_StoreVsinv__37) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendReqS i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendReqSVsinv__37) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendReqE__part__0 i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendReqE__part__0Vsinv__37) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendReqE__part__1 i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendReqE__part__1Vsinv__37) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvReqS N i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvReqSVsinv__37) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvReqE N i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvReqEVsinv__37) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendInv__part__0 i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendInv__part__0Vsinv__37) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendInv__part__1 i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendInv__part__1Vsinv__37) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendInvAck i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendInvAckVsinv__37) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvInvAck i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvInvAckVsinv__37) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendGntS i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendGntSVsinv__37) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendGntE N i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendGntEVsinv__37) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvGntS i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvGntSVsinv__37) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvGntE i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvGntEVsinv__37) done\n }\n\n ultimately show \"invHoldForRule s f r (invariants N)\"\n by satx\nqed\n\nend\n","avg_line_length":37.1428571429,"max_line_length":132,"alphanum_fraction":0.6334841629} {"size":22142,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/flash_data_cub_lemma_inv__90_on_rules.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The flash_data_cub Protocol Case Study*} \n\ntheory flash_data_cub_lemma_inv__90_on_rules imports flash_data_cub_lemma_on_inv__90\nbegin\nsection{*All lemmas on causal relation between inv__90*}\nlemma lemma_inv__90_on_rules:\n assumes b1: \"r \\ rules N\" and b2: \"(\\ p__Inv4. p__Inv4\\N\\f=inv__90 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n proof -\n have c1: \"(\\ src data. src\\N\\data\\N\\r=n_Store src data)\\\n (\\ data. data\\N\\r=n_Store_Home data)\\\n (\\ src. src\\N\\r=n_PI_Remote_Get src)\\\n (r=n_PI_Local_Get_Get )\\\n (r=n_PI_Local_Get_Put )\\\n (\\ src. src\\N\\r=n_PI_Remote_GetX src)\\\n (r=n_PI_Local_GetX_GetX__part__0 )\\\n (r=n_PI_Local_GetX_GetX__part__1 )\\\n (r=n_PI_Local_GetX_PutX_HeadVld__part__0 N )\\\n (r=n_PI_Local_GetX_PutX_HeadVld__part__1 N )\\\n (r=n_PI_Local_GetX_PutX__part__0 )\\\n (r=n_PI_Local_GetX_PutX__part__1 )\\\n (\\ dst. dst\\N\\r=n_PI_Remote_PutX dst)\\\n (r=n_PI_Local_PutX )\\\n (\\ src. src\\N\\r=n_PI_Remote_Replace src)\\\n (r=n_PI_Local_Replace )\\\n (\\ dst. dst\\N\\r=n_NI_Nak dst)\\\n (r=n_NI_Nak_Home )\\\n (r=n_NI_Nak_Clear )\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__0 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__1 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__2 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Get__part__0 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Get__part__1 src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Put_Head N src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Put src)\\\n (\\ src. src\\N\\r=n_NI_Local_Get_Put_Dirty src)\\\n (\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Nak src dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_Get_Nak_Home dst)\\\n (\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Put src dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_Get_Put_Home dst)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__0 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__1 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__2 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__0 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__1 src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_1 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_2 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_3 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_4 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_5 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_6 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__0 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__1 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src)\\\n (\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8 N src pp)\\\n (\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__0 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__1 N src)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_10_Home N src)\\\n (\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_10 N src pp)\\\n (\\ src. src\\N\\r=n_NI_Local_GetX_PutX_11 N src)\\\n (\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_Nak src dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_GetX_Nak_Home dst)\\\n (\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_PutX src dst)\\\n (\\ dst. dst\\N\\r=n_NI_Remote_GetX_PutX_Home dst)\\\n (r=n_NI_Local_Put )\\\n (\\ dst. dst\\N\\r=n_NI_Remote_Put dst)\\\n (r=n_NI_Local_PutXAcksDone )\\\n (\\ dst. dst\\N\\r=n_NI_Remote_PutX dst)\\\n (\\ dst. dst\\N\\r=n_NI_Inv dst)\\\n (\\ src. src\\N\\r=n_NI_InvAck_exists_Home src)\\\n (\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_InvAck_exists src pp)\\\n (\\ src. src\\N\\r=n_NI_InvAck_1 N src)\\\n (\\ src. src\\N\\r=n_NI_InvAck_2 N src)\\\n (\\ src. src\\N\\r=n_NI_InvAck_3 N src)\\\n (r=n_NI_Wb )\\\n (r=n_NI_FAck )\\\n (r=n_NI_ShWb N )\\\n (\\ src. src\\N\\r=n_NI_Replace src)\\\n (r=n_NI_Replace_Home )\"\n apply (cut_tac b1, auto) done\n moreover {\n assume d1: \"(\\ src data. src\\N\\data\\N\\r=n_Store src data)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_StoreVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ data. data\\N\\r=n_Store_Home data)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_Store_HomeVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_PI_Remote_Get src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Remote_GetVsinv__90) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_Get_Get )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_Get_GetVsinv__90) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_Get_Put )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_Get_PutVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_PI_Remote_GetX src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Remote_GetXVsinv__90) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_GetX__part__0 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_GetX__part__0Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_GetX__part__1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_GetX__part__1Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_PutX_HeadVld__part__0 N )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_PutX_HeadVld__part__0Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_PutX_HeadVld__part__1 N )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_PutX_HeadVld__part__1Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_PutX__part__0 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_PutX__part__0Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_GetX_PutX__part__1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_GetX_PutX__part__1Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_PI_Remote_PutX dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Remote_PutXVsinv__90) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_PutX )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_PutXVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_PI_Remote_Replace src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Remote_ReplaceVsinv__90) done\n }\n\n moreover {\n assume d1: \"(r=n_PI_Local_Replace )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_PI_Local_ReplaceVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Nak dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_NakVsinv__90) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Nak_Home )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Nak_HomeVsinv__90) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Nak_Clear )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Nak_ClearVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__0 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Nak__part__0Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__1 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Nak__part__1Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__2 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Nak__part__2Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Get__part__0 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Get__part__0Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Get__part__1 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Get__part__1Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Put_Head N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Put_HeadVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Put src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_PutVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_Get_Put_Dirty src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_Get_Put_DirtyVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Nak src dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_Get_NakVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_Get_Nak_Home dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_Get_Nak_HomeVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Put src dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_Get_PutVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_Get_Put_Home dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_Get_Put_HomeVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__0 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_Nak__part__0Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__1 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_Nak__part__1Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__2 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_Nak__part__2Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__0 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_GetX__part__0Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__1 src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_GetX__part__1Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_1Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_2 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_2Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_3 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_3Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_4 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_4Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_5 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_5Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_6 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_6Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__0 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_7__part__0Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_7__part__1Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_7_NODE_Get__part__0Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_7_NODE_Get__part__1Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_8_HomeVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_8_Home_NODE_GetVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8 N src pp)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_8Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_8_NODE_GetVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__0 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_9__part__0Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_9__part__1Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_10_Home N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_10_HomeVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_10 N src pp)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_10Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Local_GetX_PutX_11 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_GetX_PutX_11Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_Nak src dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_GetX_NakVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_GetX_Nak_Home dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_GetX_Nak_HomeVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_PutX src dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_GetX_PutXVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_GetX_PutX_Home dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_GetX_PutX_HomeVsinv__90) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Local_Put )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_PutVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_Put dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_PutVsinv__90) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Local_PutXAcksDone )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Local_PutXAcksDoneVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Remote_PutX dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Remote_PutXVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ dst. dst\\N\\r=n_NI_Inv dst)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_InvAck_exists_Home src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_exists_HomeVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_InvAck_exists src pp)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_existsVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_InvAck_1 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_1Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_InvAck_2 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_2Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_InvAck_3 N src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_InvAck_3Vsinv__90) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Wb )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_WbVsinv__90) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_FAck )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_FAckVsinv__90) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_ShWb N )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_ShWbVsinv__90) done\n }\n\n moreover {\n assume d1: \"(\\ src. src\\N\\r=n_NI_Replace src)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_ReplaceVsinv__90) done\n }\n\n moreover {\n assume d1: \"(r=n_NI_Replace_Home )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_NI_Replace_HomeVsinv__90) done\n }\n\n ultimately show \"invHoldForRule s f r (invariants N)\"\n by satx\nqed\n\nend\n","avg_line_length":41.0797773655,"max_line_length":132,"alphanum_fraction":0.6632643844} {"size":13825,"ext":"thy","lang":"Isabelle","max_stars_count":1.0,"content":"theory Simply\nimports CR\nbegin\n\nsection {* Simply typed *}\n\nsubsection {* Typing rules *}\n\nnominal_datatype simply = TVar string | TArr simply simply (infixr \"\\\" 90)\n\ninductive valid :: \"(var \\ simply) list \\ bool\" where\n valid_nil: \"valid []\"\n| valid_cons: \"\\ valid \\; x \\ \\ \\ \\ valid ((x,T)#\\)\"\n\nequivariance valid\n\nlemma elim_valid_cons: \"valid ((x,T)#\\) \\ valid \\ \\ x \\ \\\"\nby (cases rule: valid.cases, auto)\n\nlemma fresh_notin:\n fixes x :: var and \\ :: \"(var \\ simply) list\"\n assumes \"x \\ \\\"\n shows \"(x,y) \\ set \\\"\nusing assms\napply (induction \\ arbitrary: x, simp, simp add: fresh_list_cons)\napply (rule, auto simp add: fresh_prod fresh_atm)\ndone\n\nlemma valid_ctx_unique:\n assumes \"valid \\\" \"(x,\\) \\ set \\\" \"(x,\\) \\ set \\\"\n shows \"\\ = \\\"\nusing assms apply (induction \\ arbitrary: x, auto)\n using fresh_notin apply simp\n using fresh_notin apply simp\ndone\n\ninductive typed (\"_ \\ _ : _\" 40) where\n st_var: \"\\ valid \\; (x,\\) \\ set \\ \\ \\ \\ \\ Var x : \\\"\n| st_app: \"\\ \\ \\ M : (\\ \\ \\); \\ \\ N : \\ \\ \\ \\ \\ App M N : \\\"\n| st_abs: \"\\ x \\ \\; (x,\\)#\\ \\ M : \\ \\ \\ \\ \\ (lam [x]. M) : (\\ \\ \\)\"\n\nequivariance typed\n\nlemma fresh_type:\n fixes x :: var\n and T :: simply\n shows \"x \\ T\"\nby (nominal_induct T rule:simply.strong_induct, simp_all add: fresh_string)\n \nnominal_inductive typed\n by (simp_all add: fresh_type abs_fresh)\n\nfun dom where\n \"dom \\ = (\\(x,y). x) ` \\\"\n\nsubsubsection {* lemma *}\n \nlemma weak_ctx:\n assumes \"set \\ \\ set \\'\" \"valid \\'\" \"\\ \\ M : \\\"\n shows \"\\' \\ M : \\\"\nusing assms(1) assms(2) apply (nominal_induct avoiding: \\' rule: typed.strong_induct [OF assms(3)])\napply (rule, simp, fastforce)\nusing st_app apply blast\napply (rule, simp, simp)\nby (simp add: subset_insertI2 valid.intros(2))\n\nlemma typed_valid: \"\\ \\ M : A \\ valid \\\"\napply (nominal_induct rule: typed.strong_induct, auto)\nusing elim_valid_cons by blast\n\nlemma ctx_swap_head_typed: \"(x,t) # (y,s) # \\ \\ M : A \\ (y,s) # (x,t) # \\ \\ M : A\"\nproof (rule weak_ctx [of \"(x,t) # (y,s) # \\\"], auto)\n assume \"(x, t) # (y, s) # \\ \\ M : A\"\n hence \"valid ((x,t) # (y, s) # \\)\" by (simp add: typed_valid)\n hence \"valid ((y,s) # \\) \\ x \\ (y,\\)\"\n using elim_valid_cons\n by (meson fresh_list_cons fresh_prod)\n hence fresh: \"valid \\\" \"y \\ \\\" \"x \\ y\" \"x \\ \\\"\n using elim_valid_cons apply blast\n using \\valid ((y, s) # \\) \\ x \\ (y, \\)\\ elim_valid_cons apply blast\n apply (metis \\valid ((x, t) # (y, s) # \\)\\ elim_valid_cons fresh_notin list.set_intros(1))\n by (simp add: \\valid ((y, s) # \\) \\ x \\ (y, \\)\\)\n show \"valid ((y, s) # (x, t) # \\)\"\n apply (rule, rule, rule fresh, rule fresh)\n by (metis fresh(2) fresh(3) fresh_atm fresh_list_cons fresh_prod fresh_type)\nqed \n\nsubsubsection {* coherence *}\n\nlemma gen_typed_valid: \"\\ \\ M : \\ \\ valid \\\"\napply (nominal_induct rule: typed.strong_induct)\n apply (auto)\n by (metis list.distinct(1) list.inject valid.simps)\n\nlemma gen_typed_var: \"\\ \\ Var x : \\ \\ (x,\\) \\ set \\\"\nby (cases rule:typed.cases, auto simp add: lambda.inject)\n\nlemma gen_typed_app:\n assumes \"\\ \\ M $ N : \\\"\n obtains \\ where \"\\ \\ M : (\\ \\ \\)\" \"\\ \\ N : \\\"\nby (cases rule:typed.cases [OF assms], auto simp add: lambda.inject)\n\nlemma gen_typed_abs:\n assumes \"\\ \\ lam [x]. M : \\\" \"x \\ \\\"\n obtains \\ \\ where \"(x,\\)#\\ \\ M : \\\" \"\\ = \\ \\ \\\"\nusing assms\napply (cases rule: typed.strong_cases [of _ _ _ _ x], auto)\nby (metis abs_fresh(1) abs_fun_eq1 fresh_type lambda.inject(3))\n\nsubsubsection {* Soundness *}\n\nlemma typed_var_unique: \"(x,\\)#\\ \\ Var x : \\ \\ \\ = \\\"\napply (cases rule: typed.strong_cases, auto simp add: lambda.inject)\nusing elim_valid_cons apply (rule, simp)\n using fresh_notin apply auto\napply (generate_fresh var)\nby (meson gen_typed_valid gen_typed_var list.set_intros(1) valid_ctx_unique)\n\nlemma subst_typed: \"\\ (x,\\)#\\ \\ M : \\; \\ \\ N : \\ \\ \\ \\ \\ M[x::=N] : \\\"\napply (nominal_induct M avoiding: x N \\ \\ arbitrary: \\ rule: lambda.strong_induct)\n apply (auto elim!: gen_typed_var)\n using typed_var_unique apply fastforce\n using gen_typed_var [of \"(x,\\)#\\\" _ \\] apply simp\n apply (meson Pair_inject gen_typed_valid gen_typed_var set_ConsD st_var)\n apply (rule gen_typed_app, simp)\n apply (rule, blast, blast)\nproof-\n fix name lambda x N \\ \\ \\\n assume name_fresh: \"name \\ x\" \"name \\ N\" \"name \\ \\\" \"name \\ \\\"\n and IH: \"\\b ba bb bc \\. (b, bb) # bc \\ lambda : \\ \\ bc \\ ba : bb \\ bc \\ lambda[b::=ba] : \\\"\n and hyp: \"(x, \\) # \\ \\ lam [name].lambda : \\\" \"\\ \\ N : \\\"\n \n obtain \\1 \\2 where tau: \"\\ = \\1 \\ \\2\" \"(name, \\1) # (x, \\) # \\ \\ lambda : \\2\"\n by (metis fresh_list_cons fresh_prod fresh_type gen_typed_abs hyp(1) name_fresh(1) name_fresh(4))\n have \"(name,\\1) # \\ \\ lambda[x::=N] : \\2\"\n apply (rule IH)\n apply (rule ctx_swap_head_typed)\n apply (rule tau)\n apply (rule weak_ctx [of \\], auto)\n apply (rule, rule typed_valid, rule hyp, rule name_fresh, rule hyp)\n done\n thus \"\\ \\ lam [name]. (lambda[x::=N]) : \\\"\n apply (simp add: tau(1))\n by (simp add: name_fresh(4) st_abs)\nqed\n\nlemma preservation_one:\n assumes \"M \\\\ M'\"\n shows \"\\ \\ M : \\ \\ \\ \\ M' : \\\"\napply (nominal_induct avoiding: \\ arbitrary: \\ rule: beta.strong_induct [OF assms])\napply (erule gen_typed_app, rule)\nprefer 2 apply (simp, simp)\napply (erule gen_typed_app, rule)\napply (simp, simp)\napply (erule gen_typed_abs, simp, simp, rule, simp, simp)\napply (erule gen_typed_app, erule gen_typed_abs, simp)\napply (rule subst_typed, simp add: simply.inject, simp add: simply.inject)\ndone\n\nlemma preservation:\n assumes \"M \\\\* M'\"\n shows \"\\ \\ M : \\ \\ \\ \\ M' : \\\"\nby (induct rule: long_beta.induct [OF assms], auto simp add: preservation_one)\n\nnominal_primrec Value :: \"lambda \\ bool\" where\n \"Value (lam [_]._) = True\"\n | \"Value (Var _) = False\"\n | \"Value (App _ _) = False\"\nby (finite_guess+, rule+, fresh_guess+)\n\nlemma Value_eqvt[eqvt]:\n fixes \\ :: \"var prm\" and M :: lambda\n shows \"\\ \\ Value M = Value (\\ \\ M)\"\nby (nominal_induct M rule: lambda.strong_induct, auto)\n\nlemma Value_abs:\n assumes \"Value M\"\n obtains x M' where \"M = lam [x]. M'\"\nusing assms by (nominal_induct M rule: lambda.strong_induct, auto)\n \nlemma progress: \"[] \\ M : \\ \\ Value M \\ (\\M'. M \\\\ M')\"\nproof-\n have \"\\\\. \\ \\ \\ M : \\; \\ = [] \\ \\ Value M \\ (\\M'. M \\\\ M')\"\n proof-\n fix \\\n show \"\\ \\ \\ M : \\; \\ = [] \\ \\ Value M \\ (\\M'. M \\\\ M')\"\n apply (nominal_induct rule: typed.strong_induct, auto)\n apply (erule Value_abs, simp, rule, rule b_beta)\n done\n qed\n thus \"[] \\ M : \\ \\ Value M \\ (\\M'. M \\\\ M')\" by simp\nqed\n\ntheorem soundness:\n assumes \"[] \\ M : \\\" \"M \\\\* M'\"\n shows \"Value M' \\ (\\ M''. M' \\\\ M'')\"\nby (rule progress, rule preservation, rule assms, rule assms)\n\ninductive SN where\n SN: \"(\\M'. M \\\\ M' \\ SN M') \\ SN M\"\n\nnominal_primrec RED where\n \"RED (TVar x) = {t. SN t}\"\n| \"RED (A \\ B) = {t. \\u. u \\ RED A \\ t $ u \\ RED B}\"\nby (rule+)\n\nlemma RED_forward:\n assumes \"M \\\\ M'\"\n shows \"M \\ RED A \\ M' \\ RED A\"\nusing assms apply (nominal_induct A arbitrary: M M' rule: simply.strong_induct, auto)\napply (cases rule: SN.cases, simp, simp)\napply blast\ndone\n\nlemma SN_elim_app1_var: \"SN (M $ Var x) \\ SN M\"\nproof-\n { fix N\n have \"\\ SN N; N = (M $ Var x) \\ \\ SN M\"\n apply (induct arbitrary: M rule: SN.induct, auto, rule)\n apply (cases rule: beta.cases, auto)\n done\n }\n thus \"SN (M $ Var x) \\ SN M\" by simp\nqed\n\nlemma SN_var: \"SN (Var x)\"\nby (rule, cases rule: beta.cases, auto)\n\nlemma elim_app_beta:\n assumes \"M $ N \\\\ L\" and \"nonabs M\"\n shows \"(\\M'. M \\\\ M' \\ L = M' $ N \\ thesis) \\ (\\N'. N \\\\ N' \\ L = M $ N' \\ thesis) \\ thesis\"\napply (cases rule: beta.cases [OF assms(1)], auto simp add: lambda.inject)\nusing assms(2) apply simp\ndone\n\nlemma RED_sn_and_neutral_backward:\n \"M \\ RED A \\ SN M\" and \"\\ nonabs M; (\\M'. M \\\\ M' \\ M' \\ RED A) \\ \\ M \\ RED A\"\napply (nominal_induct A arbitrary: M rule: simply.strong_induct, auto)\n apply (rule, simp)\nproof-\n fix t1 t2 M\n assume \"(\\M. M \\ RED t1 \\ SN M)\" and hyp: \"(\\M. nonabs M \\ \\M'. M \\\\ M' \\ M' \\ RED t1 \\ M \\ RED t1)\"\n and hyp3: \"(\\M. M \\ RED t2 \\ SN M)\" and \"(\\M. nonabs M \\ \\M'. M \\\\ M' \\ M' \\ RED t2 \\ M \\ RED t2)\"\n and hyp2: \"\\u. u \\ RED t1 \\ M $ u \\ RED t2\"\n \n fix x\n have \"Var x \\ RED t1\"\n apply (rule hyp, auto)\n apply (cases rule: beta.cases, auto)\n done\n hence \"M $ Var x \\ RED t2\" by (simp add: hyp2)\n hence \"SN (M $ Var x)\" by (rule hyp3)\n thus \"SN M\" by (rule SN_elim_app1_var)\nnext\n fix t1 t2 M u\n assume \"(\\M. M \\ RED t1 \\ SN M)\" \"(\\M. nonabs M \\ \\M'. M \\\\ M' \\ M' \\ RED t1 \\ M \\ RED t1)\"\n and \"(\\M. M \\ RED t2 \\ SN M)\" \"(\\M. nonabs M \\ \\M'. M \\\\ M' \\ M' \\ RED t2 \\ M \\ RED t2)\"\n and \"nonabs M\"\n and hyp: \"\\M'. M \\\\ M' \\ (\\u. u \\ RED t1 \\ M' $ u \\ RED t2)\" \"u \\ RED t1\"\n \n { fix N\n have \"\\ SN N; N \\ RED t1 \\ \\ M $ N \\ RED t2\"\n proof (induct rule: SN.induct)\n fix P\n assume \"\\P'. P \\\\ P' \\ SN P'\"\n and \"\\P'. P \\\\ P' \\ P' \\ RED t1 \\ M $ P' \\ RED t2\"\n and \"P \\ RED t1\"\n \n have P: \"\\M'. M $ P \\\\ M' \\ M' \\ RED t2\"\n apply (erule elim_app_beta, auto)\n apply fact\n using `P \\ RED t1` hyp apply simp\n by (simp add: RED_forward \\P \\ RED t1\\ \\\\P'. \\P \\\\ P'; P' \\ RED t1\\ \\ M $ P' \\ RED t2\\)\n show \"M $ P \\ RED t2\"\n apply (rule `\\M. nonabs M \\ \\M'. M \\\\ M' \\ M' \\ RED t2 \\ M \\ RED t2`)\n using `nonabs M` apply simp\n apply (simp add: P)\n done\n qed\n }\n thus \"M $ u \\ RED t2\"\n using `M \\ RED t1 \\ SN M` `u \\ RED t1`\n using \\\\M. M \\ RED t1 \\ SN M\\ by auto\nqed\n\n(*\nlemma SN_abs:\n assumes \"SN M\"\n shows \"SN (lam [x]. M)\"\nproof rule\n fix M'\n assume \"lam [x]. M \\\\ M'\"\n then obtain M'' where \"M \\\\ M''\" \"M' = lam [x]. M''\"\n apply (cases rule: beta.strong_cases [of _ _ _ x x], auto simp add: abs_fresh)\n show \"SN M'\"\n\nlemma RED_subst:\n assumes \"N \\ RED t'\" \"M [x ::= N] \\ RED t\"\n shows \"(lam [x]. M) $ N \\ RED t\"\n*)\n \nend\n","avg_line_length":45.6270627063,"max_line_length":236,"alphanum_fraction":0.6312477396} {"size":308,"ext":"thy","lang":"Isabelle","max_stars_count":13.0,"content":"name: group-abelian\nversion: 1.9\ndescription: Abelian groups\nauthor: Joe Leslie-Hurd \nlicense: MIT\nprovenance: HOL Light theory extracted on 2012-12-02\nrequires: bool\nrequires: group-thm\nrequires: group-witness\nshow: \"Algebra.Group\"\nshow: \"Data.Bool\"\n\nmain {\n article: \"group-abelian.art\"\n}\n","avg_line_length":19.25,"max_line_length":52,"alphanum_fraction":0.762987013} {"size":24856,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"(*\n * Copyright 2016, NTU\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * Author: Zhe Hou.\n *)\n\ntheory VHDL_Power_Properties\nimports Main VHDL_Hoare VHDL_Power VHDL_Power_Comp\nbegin\n\ndefinition f:: \"nat \\ nat\" where \"f x = x + 1\"\n\ndefinition val_op_power:: \"val option \\ val option \\ val option\" where\n\"val_op_power vop1 vop2 \\ \n case (vop1,vop2) of (Some (val_i v1), Some (val_i v2)) \\ Some (val_i (v1 ^ (nat v2)))\n | _ \\ None\n\"\n\ndefinition input_state_p:: \"int \\ int \\ vhdl_state\" where\n\"input_state_p i j \\ init_state\\state_sp := \n(state_sp init_state)((sp_p p_arg1_p) := (Some (val_i i)), \n (sp_p p_arg2_p) := (Some (val_i j)))\\\"\n\ndefinition input_state_pc:: \"int \\ int \\ vhdl_arch_state\" where\n\"input_state_pc i j \\ arch_state (''POWER'',init_state\\state_sp := \n(state_sp init_state)((sp_p p_arg1_pc) := (Some (val_i i)), \n (sp_p p_arg2_pc) := (Some (val_i j)))\\,\n [(mult_unit_comp_map,init_arch_state_mult)])\"\n\ndefinition final_state where \"final_state \\ \nsimulation 15 (trans_vhdl_desc_complex vhdl_power) (input_state_p 4 2)\"\n\ndefinition final_state_n where \"final_state_n n x y \\ \nsimulation n (trans_vhdl_desc_complex vhdl_power) (input_state_p x y)\"\n\ndefinition vhdl_power_core:: \"vhdl_desc\" where\n\"vhdl_power_core \\ trans_vhdl_desc_complex vhdl_power\"\n\ndefinition mult_proc:: \"conc_stmt\" where\n\"mult_proc \\ cst_ps ''MULTIPLIER'' [sp_p p_clk]\n [(sst_if '''' (bexpr (exp_sig s_req_p) [=] (exp_con (vhdl_bit, (val_c (CHR ''1'')))))\n [(sst_sa '''' (clhs_sp (lhs_s (sp_s s_result_p))) \n (rhs_e (bexpa (exp_sig s_reg1_p) [*] (exp_sig s_reg2_p))))\n ] []),\n (sst_sa '''' (clhs_sp (lhs_s (sp_s s_ack_p))) (rhs_e (exp_sig s_req_p)))\n ]\n\"\n\ndefinition ctrl_proc:: \"conc_stmt\" where\n\"ctrl_proc \\ cst_ps ''CONTROLLER'' [sp_p p_clk] \n [(sst_if '''' (bexpr (exp_sig s_state_p) [=] (exp_con (vhdl_natural, (val_i 0))))\n [(sst_if '''' (bexpr (exp_prt p_start_p) [=] (exp_con (vhdl_bit, (val_c (CHR ''1'')))))\n [(sst_sa '''' (clhs_sp (lhs_s (sp_s s_reg1_p))) (rhs_e (exp_prt p_arg1_p))),\n (sst_sa '''' (clhs_sp (lhs_s (sp_s s_reg2_p))) (rhs_e (exp_con (vhdl_natural, (val_i 1))))),\n (sst_sa '''' (clhs_sp (lhs_s (sp_s s_count_p))) (rhs_e (exp_prt p_arg2_p))),\n (sst_sa '''' (clhs_sp (lhs_s (sp_s s_state_p))) (rhs_e (exp_con (vhdl_natural, (val_i 1)))))\n ] [])\n ] [\n (sst_if '''' (bexpr (exp_sig s_state_p) [=] (exp_con (vhdl_natural, (val_i 1))))\n [(sst_if '''' (bexpr (exp_sig s_count_p) [=] (exp_con (vhdl_natural, (val_i 0))))\n [(sst_sa '''' (clhs_sp (lhs_s (sp_p p_res_p))) (rhs_e (exp_sig s_reg2_p))),\n (sst_sa '''' (clhs_sp (lhs_s (sp_p p_done_p))) (rhs_e (exp_con (vhdl_bit, (val_c (CHR ''1'')))))),\n (sst_sa '''' (clhs_sp (lhs_s (sp_s s_state_p))) (rhs_e (exp_con (vhdl_natural, (val_i 4)))))\n ] [\n (sst_sa '''' (clhs_sp (lhs_s (sp_s s_req_p))) (rhs_e (exp_con (vhdl_bit, (val_c (CHR ''1'')))))),\n (sst_sa '''' (clhs_sp (lhs_s (sp_s s_state_p))) (rhs_e (exp_con (vhdl_natural, (val_i 2)))))\n ])\n ] [\n (sst_if '''' (bexpr (exp_sig s_state_p) [=] (exp_con (vhdl_natural, (val_i 2))))\n [(sst_if '''' (bexpr (exp_sig s_ack_p) [=] (exp_con (vhdl_bit, (val_c (CHR ''1'')))))\n [(sst_sa '''' (clhs_sp (lhs_s (sp_s s_reg2_p))) (rhs_e (exp_sig s_result_p))),\n (sst_sa '''' (clhs_sp (lhs_s (sp_s s_req_p))) (rhs_e (exp_con (vhdl_bit, (val_c (CHR ''0'')))))),\n (sst_sa '''' (clhs_sp (lhs_s (sp_s s_state_p))) (rhs_e (exp_con (vhdl_natural, (val_i 3)))))\n ] [])\n ] [\n (sst_if '''' (bexpr (exp_sig s_state_p) [=] (exp_con (vhdl_natural, (val_i 3))))\n [(sst_sa '''' (clhs_sp (lhs_s (sp_s s_count_p))) (rhs_e (bexpa (exp_sig s_count_p) [-] (exp_con (vhdl_natural, (val_i 1)))))),\n (sst_sa '''' (clhs_sp (lhs_s (sp_s s_state_p))) (rhs_e (exp_con (vhdl_natural, (val_i 1)))))\n ] [\n (sst_if '''' (bexpr (exp_sig s_state_p) [=] (exp_con (vhdl_natural, (val_i 4))))\n [(sst_if '''' (bexpr (exp_prt p_start_p) [=] (exp_con (vhdl_bit, (val_c (CHR ''0'')))))\n [(sst_sa '''' (clhs_sp (lhs_s (sp_p p_done_p))) (rhs_e (exp_con (vhdl_bit, (val_c (CHR ''0'')))))),\n (sst_sa '''' (clhs_sp (lhs_s (sp_s s_state_p))) (rhs_e (exp_con (vhdl_natural, (val_i 1)))))\n ] [])\n ] [])\n ])\n ])\n ])\n ])\n ]\n\"\n\ntext {* Functional correctness of the MULTIPLIER process. *}\n\nlemma fun_cor_mult_sub3: \"valid_hoare_tuple (multi_proc, [], \n((\\y. (\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))\n (y\\state_dr_val := (state_dr_val y)\n ((sp_s s_result_p) := ((state_dr_val y) (sp_s s_result_p))\n (multi_proc := state_val_exp_t \n (bexpa (exp_sig s_reg1_p) [*] (exp_sig s_reg2_p)) y))\\))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x)))),\n[(sst_sa '''' (clhs_sp (lhs_s (sp_s s_result_p))) \n (rhs_e (bexpa (exp_sig s_reg1_p) [*] (exp_sig s_reg2_p))))],\n((\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))))\n)\n\"\nusing VHDL_Hoare.sig_asmt by meson\n\nlemma \"\\w. (\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. (state_val_exp_t (bexpa (exp_sig s_reg1_p) [*] (exp_sig s_reg2_p)) x = Some (val_i r) \\ \n r = v1 * v2)))) w \\\n(\\y. (\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))\n (y\\state_dr_val := (state_dr_val y)\n ((sp_s s_result_p) := ((state_dr_val y) (sp_s s_result_p))\n (multi_proc := state_val_exp_t \n (bexpa (exp_sig s_reg1_p) [*] (exp_sig s_reg2_p)) y))\\)) w\"\nby auto\n\nlemma \"\\w. (\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) w \\\n (\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. (state_val_exp_t (bexpa (exp_sig s_reg1_p) [*] (exp_sig s_reg2_p)) x = Some (val_i r) \\ \n r = v1 * v2)))) w\" \napply clarsimp\napply (simp add: state_val_exp_t_def s_reg1_p_def s_reg2_p_def)\napply (simp add: val_arith_def)\nby (simp add: vhdl_natural_def vhdl_positive_def vhdl_real_def)\n\nlemma fun_cor_mult_sub3_1: \"valid_hoare_tuple (multi_proc, [], \n((\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))) \n \\ (\\x. (state_val_exp_t (bexpr (exp_sig s_req_p) [=] \n (exp_con (vhdl_bit, (val_c (CHR ''1''))))) x = Some (val_b True)))),\n[(sst_sa '''' (clhs_sp (lhs_s (sp_s s_result_p))) \n (rhs_e (bexpa (exp_sig s_reg1_p) [*] (exp_sig s_reg2_p))))],\n((\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))))\n)\n\"\nproof -\ndef \"P\" \\ \"((\\y. (\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))\n (y\\state_dr_val := (state_dr_val y)\n ((sp_s s_result_p) := ((state_dr_val y) (sp_s s_result_p))\n (multi_proc := state_val_exp_t \n (bexpa (exp_sig s_reg1_p) [*] (exp_sig s_reg2_p)) y))\\))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))))\"\ndef \"C\" \\ \"[(sst_sa '''' (clhs_sp (lhs_s (sp_s s_result_p))) \n (rhs_e (bexpa (exp_sig s_reg1_p) [*] (exp_sig s_reg2_p))))]\"\ndef \"Q\" \\ \"((\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))))\"\ndef \"P'\" \\ \"(\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. (state_val_exp_t (bexpa (exp_sig s_reg1_p) [*] (exp_sig s_reg2_p)) x = Some (val_i r) \\ \n r = v1 * v2)))) \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x)))\"\ndef \"P''\" \\ \"(\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x)))\"\ndef \"P'''\" \\ \"((\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))) \n \\ (\\x. (state_val_exp_t (bexpr (exp_sig s_req_p) [=] \n (exp_con (vhdl_bit, (val_c (CHR ''1''))))) x = Some (val_b True))))\"\n have f0: \"valid_hoare_tuple (multi_proc, [], P, C, Q)\" \n using fun_cor_mult_sub3 unfolding P_def C_def Q_def by auto\n have f1: \"\\w. P' w \\ P w\" unfolding P'_def P_def asst_and_def \n by auto\n have f2: \"\\w. P'' w \\ P' w\" unfolding P''_def P'_def asst_and_def\n apply clarsimp\n apply (simp add: state_val_exp_t_def s_reg1_p_def s_reg2_p_def)\n apply (simp add: val_arith_def)\n by (simp add: vhdl_natural_def vhdl_positive_def vhdl_real_def)\n have f3: \"\\w. P''' w \\ P'' w\" unfolding P'''_def P''_def asst_and_def\n by auto\n from f1 f2 f3 have f4: \"\\w. P''' w \\ P w\" by auto\n have f5: \"\\w. Q w \\ Q w\" by auto\n from f0 f4 f5 have \"valid_hoare_tuple (multi_proc, [], P''', C, Q)\"\n using consequence by auto \n then show ?thesis using P'''_def C_def Q_def by auto\nqed\n\nlemma fun_cor_mult_sub4: \"valid_hoare_tuple (multi_proc, [], \n((\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))) \n \\ (\\x. (state_val_exp_t (bexpr (exp_sig s_req_p) [=] \n (exp_con (vhdl_bit, (val_c (CHR ''1''))))) x \\ Some (val_b True)))),\n[],\n((\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))))\n)\n\"\nproof -\ndef \"Q\" \\ \"((\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))))\"\ndef \"P\" \\ \"((\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))) \n \\ (\\x. (state_val_exp_t (bexpr (exp_sig s_req_p) [=] \n (exp_con (vhdl_bit, (val_c (CHR ''1''))))) x \\ Some (val_b True))))\"\n have f1: \"valid_hoare_tuple (multi_proc, [], Q, [], Q)\" using skip by auto\n have f2: \"\\w. P w \\ Q w\" unfolding P_def Q_def asst_and_def\n apply auto\n apply (simp add: state_val_exp_t_def s_req_p_def)\n apply (simp add: val_rel_def)\n by (simp add: vhdl_bit_def vhdl_boolean_def)\n then have \"valid_hoare_tuple (multi_proc, [], P, [], Q)\" using f1 consequence\n by auto\n then show ?thesis unfolding P_def Q_def\n by auto\nqed\n\nlemma fun_cor_mult_sub2: \"valid_hoare_tuple (multi_proc, [], \n(\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))),\n[(sst_if '''' (bexpr (exp_sig s_req_p) [=] (exp_con (vhdl_bit, (val_c (CHR ''1'')))))\n [(sst_sa '''' (clhs_sp (lhs_s (sp_s s_result_p))) \n (rhs_e (bexpa (exp_sig s_reg1_p) [*] (exp_sig s_reg2_p))))\n ] [])],\n((\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n ((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n ((state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))))\n)\n\"\nusing fun_cor_mult_sub3_1 fun_cor_mult_sub4 if_stmt\nby auto\n\nlemma fun_cor_mult_sub1: \"valid_hoare_tuple (multi_proc, [], \n((\\y. (\\x. (state_dr_val x) (sp_s s_ack_p) multi_proc = Some (val_c (CHR ''1'')) \\\n (((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))\n (y\\state_dr_val := (state_dr_val y)\n ((sp_s s_ack_p) := ((state_dr_val y) (sp_s s_ack_p))\n (multi_proc := state_val_exp_t (exp_sig s_req_p) y))\\))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x)))),\n[(sst_sa '''' (clhs_sp (lhs_s (sp_s s_ack_p))) (rhs_e (exp_sig s_req_p)))],\n((\\x. (state_dr_val x) (sp_s s_ack_p) multi_proc = Some (val_c (CHR ''1'')) \\\n (((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))))\n)\n\"\nusing VHDL_Hoare.sig_asmt by meson\n\nlemma fun_cor_mult_sub1_1: \"valid_hoare_tuple (multi_proc, [], \n((\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x)))),\n[(sst_sa '''' (clhs_sp (lhs_s (sp_s s_ack_p))) (rhs_e (exp_sig s_req_p)))],\n((\\x. (state_dr_val x) (sp_s s_ack_p) multi_proc = Some (val_c (CHR ''1'')) \\\n (((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))))\n)\n\"\nproof -\ndef \"P\" \\ \"((\\y. (\\x. (state_dr_val x) (sp_s s_ack_p) multi_proc = Some (val_c (CHR ''1'')) \\\n ((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n ((state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))\n (y\\state_dr_val := (state_dr_val y)\n ((sp_s s_ack_p) := ((state_dr_val y) (sp_s s_ack_p))\n (multi_proc := state_val_exp_t (exp_sig s_req_p) y))\\))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))))\"\ndef \"C\" \\ \"[(sst_sa '''' (clhs_sp (lhs_s (sp_s s_ack_p))) (rhs_e (exp_sig s_req_p)))]\"\ndef \"Q\" \\ \"((\\x. (state_dr_val x) (sp_s s_ack_p) multi_proc = Some (val_c (CHR ''1'')) \\\n ((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n ((state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))))\"\ndef \"P'\" \\ \"((\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n ((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n ((state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))))\"\n have f1: \"valid_hoare_tuple (multi_proc, [], P, C, Q)\"\n unfolding P_def C_def Q_def using fun_cor_mult_sub1 by auto\n have f2: \"\\x. P' x \\ P x\" unfolding P'_def P_def\n unfolding asst_and_def\n apply auto\n unfolding state_val_exp_t_def\n apply (cases \"exp_type (exp_sig s_req_p) = None\")\n apply auto\n unfolding s_result_p_def s_ack_p_def\n by auto\n have f3: \"\\x. Q x \\ Q x\" by auto\n then have \"valid_hoare_tuple (multi_proc, [], P', C, Q)\"\n using consequence f1 f2 f3 by auto\n then show ?thesis unfolding P'_def C_def Q_def\n by auto\nqed\n\nlemma fun_cor_mult: \"valid_hoare_tuple (multi_proc, [], \n(\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))), \n[(sst_if '''' (bexpr (exp_sig s_req_p) [=] (exp_con (vhdl_bit, (val_c (CHR ''1'')))))\n [(sst_sa '''' (clhs_sp (lhs_s (sp_s s_result_p))) \n (rhs_e (bexpa (exp_sig s_reg1_p) [*] (exp_sig s_reg2_p))))\n ] []),\n (sst_sa '''' (clhs_sp (lhs_s (sp_s s_ack_p))) (rhs_e (exp_sig s_req_p)))\n], \n((\\x. (state_dr_val x) (sp_s s_ack_p) multi_proc = Some (val_c (CHR ''1'')) \\\n (((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))\n \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x))))\n)\"\nproof -\ndef \"P\" \\ \"(\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n (state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2))::asst\"\ndef \"C1\" \\ \"[(sst_if '''' (bexpr (exp_sig s_req_p) [=] (exp_con (vhdl_bit, (val_c (CHR ''1'')))))\n [(sst_sa '''' (clhs_sp (lhs_s (sp_s s_result_p))) \n (rhs_e (bexpa (exp_sig s_reg1_p) [*] (exp_sig s_reg2_p))))\n ] [])]\"\ndef \"Q\" \\ \"(\\x. (state_sp x) (sp_s s_req_p) = Some (val_c (CHR ''1'')) \\\n ((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n ((state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))::asst\"\ndef \"C2\" \\ \"[(sst_sa '''' (clhs_sp (lhs_s (sp_s s_ack_p))) (rhs_e (exp_sig s_req_p)))]\"\ndef \"R\" \\ \"(\\x. (state_dr_val x) (sp_s s_ack_p) multi_proc = Some (val_c (CHR ''1'')) \\\n (((state_sp x) (sp_s s_reg1_p) = Some (val_i v1) \\\n (state_sp x) (sp_s s_reg2_p) = Some (val_i v2)) \\\n (\\r. ((state_dr_val x) (sp_s s_result_p) multi_proc = Some (val_i r) \\ \n r = v1 * v2))))::asst\"\n from fun_cor_mult_sub2 have f1: \"valid_hoare_tuple (multi_proc, [], \n (P \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x)))), C1, \n (Q \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x)))))\" \n unfolding P_def C1_def Q_def by auto\n from fun_cor_mult_sub1_1 have f2: \"valid_hoare_tuple (multi_proc, [], \n (Q \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x)))), C2, \n (R \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x)))))\"\n unfolding Q_def C2_def R_def by auto\n from f1 f2 if_stmt_seq have \"valid_hoare_tuple (multi_proc, [], \n (P \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x)))), C1@C2, \n (R \\ (\\x. \\ (snd (next_flag x))) \\ (\\x. \\(snd (exit_flag x)))))\"\n unfolding C1_def by auto\n then show ?thesis unfolding P_def R_def C1_def C2_def by auto\nqed\n\n\ntheorem power_correct: \"\\(m::nat). (\\(n::nat). \n(((n \\ m)) \\ \n(((state_sp (simulation n (trans_vhdl_desc_complex vhdl_power) init_state)) (sp_p p_res_p)) = \nval_op_power ((state_sp init_state) (sp_p p_arg1_p)) ((state_sp init_state) (sp_p p_arg2_p)))))\"\n\nsorry\n\ntheorem power_comp_correct: \"\\(m::nat). (\\(n::nat). \n(((n \\ m)) \\ \n(((state_sp (state_of_arch (sim_arch n vhdl_power_comp init_arch_state_power))) (sp_p p_res_pc)) = \nval_op_power ((state_sp (state_of_arch init_arch_state_power)) (sp_p p_arg1_pc)) \n ((state_sp (state_of_arch init_arch_state_power)) (sp_p p_arg2_pc)))))\"\nsorry\n\ntheorem power_eq: \"\\(m::nat). (\\(n::nat). \n(((((state_sp init_state) (sp_p p_arg1_p)) = \n((state_sp (state_of_arch init_arch_state_power)) (sp_p p_arg1_pc)) \\ \n((state_sp init_state) (sp_p p_arg2_p)) = \n((state_sp (state_of_arch init_arch_state_power)) (sp_p p_arg2_pc))) \\ \n(n \\ m)) \\ \n(((state_sp (simulation n (trans_vhdl_desc_complex vhdl_power) init_state)) (sp_p p_res_p)) = \n((state_sp (state_of_arch (sim_arch n vhdl_power_comp init_arch_state_power))) (sp_p p_res_pc)))))\"\nby (metis add_leE power_comp_correct power_correct)\n\nend","avg_line_length":57.1402298851,"max_line_length":136,"alphanum_fraction":0.6135741873} {"size":10407,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"(*<*)\ntheory ClimateEngineering_old\nimports embedding\nbegin\n(* Configuration defaults *)\nnitpick_params[assms=true, user_axioms=true, show_all, expect=genuine, format = 3] (*default settings*)\n(*>*)\n\nsection\\Case Study: Arguments in the Climate Engineering Debate\\\n(**\nFormalisation and evaluation of an extract of the argument network presented by Gregor Betz and\nSebastian Cacean in their work \"Ethical Aspects of Climate Engineering\", freely available for download at: \nhttp:\/\/books.openedition.org\/ksp\/pdf\/1780\n*)\n\nsubsection\\Individual (Component) Arguments\\\n(**The arguments below primarily support the thesis: \"CE deployment is morally wrong\"\nand make for an argument cluster with a non-trivial dialectical structure which we aim at\nreconstructing in this section. We focus on six arguments from the ethics of risk,\nwhich entail that the deployment of CE technologies (today as in the future) is not desirable\nbecause of being morally wrong (argument A22). Supporting arguments of A22 are: A45, A46, A47, A48, A49.\nIn particular, two of these arguments, namely A48 and A49, are further attacked by A50 and A51.\n*)\n\nsubsubsection\\Ethics of Risk Argument (A22)\\\n(**The argument has as premise: \"CE deployment is morally wrong\" and as conclusion:\n\"CE deployment is not desirable\". Notice that both are formalised as (modally) valid propositions,\ni.e. true in all possible worlds or situations. We are thus presupossing a possible-worlds semantics.*)\n\nconsts CEisWrong::\"w\\bool\" (**notice type for world-contingent propositions*)\nconsts CEisNotDesirable::\"w\\bool\"\n\ndefinition \"A22_P1 \\ [\\ CEisWrong]\" (*CE is wrong (in all situations)*)\ndefinition \"A22_P2 \\ [\\ CEisWrong \\<^bold>\\ CEisNotDesirable]\" (*implicit premise*)\ndefinition \"A22_C \\ [\\ CEisNotDesirable]\" (*...also in all situations*)\n\n(**We use Nitpick to find a model satisfying the premises and the conclusion of the formalised argument.*)\nlemma assumes A22_P1 and A22_P2 and A22_C shows True \n nitpick [satisfy] oops (**consistency is shown: nitpick presents a simple model*)\n\ntheorem A22_valid: assumes A22_P1 and A22_P2 shows A22_C\n using A22_C_def A22_P2_def A22_P1_def assms(1) assms(2) by blast\n\nsubsubsection\\Termination Problem (A45)\\\n(**CE measures do not possess viable exit options. If deployment is terminated abruptly,\ncatastrophic climate change ensues.\n*)\nconsts CEisTerminated::\"w\\bool\" (**world-contingent propositional constants*)\nconsts CEisCatastrophic::\"w\\bool\"\n\ndefinition \"A45_P1 \\ [\\ \\<^bold>\\CEisTerminated]\" (*implicit premise*)\ndefinition \"A45_P2 \\ [\\ CEisTerminated \\<^bold>\\ CEisCatastrophic]\"\ndefinition \"A45_C \\ [\\ \\<^bold>\\CEisCatastrophic]\"\n\n(**Notice that we have introduced in the above formalisation the @{text \"\\\"}\nmodal operator to signify that a proposition is possibly true (e.g. at a future point in time).*)\ntheorem A45_valid: assumes A45_P1 and A45_P2 shows \"A45_C\"\n using A45_C_def A45_P1_def A45_P2_def assms(1) assms(2) by blast\n\nsubsubsection\\No Long-term Risk Control (A46)\\\n(**Our social systems and institutions are possibly not capable of controlling risk technologies\non long time scales and of ensuring that they are handled with proper technical care.\nNotice that we can make best sense of this objection as (implicitly?) presupossing a risk of \nCE-caused catastrophes.*)\n\nconsts RiskControlAbility::\"w\\bool\"\ndefinition \"A46_P1 \\ [\\ \\<^bold>\\\\<^bold>\\RiskControlAbility]\"\ndefinition \"A46_P2 \\ [\\ \\<^bold>\\RiskControlAbility \\<^bold>\\ \\<^bold>\\CEisCatastrophic]\" (*implicit premise*)\ndefinition \"A46_C \\ [\\ \\<^bold>\\CEisCatastrophic]\"\n\n(**The argument A46 needs a modal logic \"K4\" to succeed.\nThe implicit premise thus being: @{text \"Ax4: [\\ \\\\. \\\\\\ \\ \\\\]\"}. *)\nlemma assumes A46_P1 and A46_P2 shows A46_C\n nitpick oops (**counterexample found, since modal axiom 4 is needed here*)\ntheorem A46_valid: assumes A46_P1 and A46_P2 and Ax4 shows A46_C\n using A46_C_def A46_P1_def A46_P2_def assms(1) assms(2) assms(3) by blast\n\nsubsubsection\\CE Interventions are Irreversible (A47)\\\n(**This argument consists of a simple sentence (its conclusion), which\nstates that CE represents an irreversible intervention, i.e., that once the first\ninterventions on world's climate have been set in motion, there is no way to \"undo\" them. \nFor the following arguments we work with a predicate logic (incl. quantification), and\nthus introduce a type (\"e\") for actions (interventions).*)\n\ntypedecl e (**introduces a new type for actions*)\nconsts CEAction::\"e\\w\\bool\" (**notice type for (world-dependent) predicates*)\nconsts Irreversible::\"e\\w\\bool\"\n\ndefinition \"A47_C \\ [\\ \\<^bold>\\I. CEAction(I) \\<^bold>\\ Irreversible(I)]\"\n\nsubsubsection\\No Ability to Retain Options after Irreversible Interventions (A48)\\\n(**Irreversible interventions (of any kind) narrow the options of future generations in an unacceptable way,\ni.e., it is wrong to carry them out.*)\n\nconsts WrongAction::\"e\\w\\bool\"\ndefinition \"A48_C \\ [\\ \\<^bold>\\I. Irreversible(I) \\<^bold>\\ WrongAction(I)]\"\n\nsubsubsection\\Unpredictable Side-Effects are Wrong (A49)\\\n(**As long as side-effects of CE technologies cannot be reliably predicted,\ntheir deployment is morally wrong.*)\n\nconsts USideEffects::\"e\\w\\bool\"\n\ndefinition \"A49_P1 \\ [\\\\<^bold>\\I. CEAction(I) \\<^bold>\\ USideEffects(I)]\"\ndefinition \"A49_P2 \\ [\\\\<^bold>\\I. USideEffects(I) \\<^bold>\\ WrongAction(I)]\" (*implicit premise*)\ndefinition \"A49_C \\ [\\\\<^bold>\\I. CEAction(I) \\<^bold>\\ WrongAction(I)]\"\n\ntheorem A49_valid: assumes A49_P1 and A49_P2 shows A49_C (*blast verifies validity*)\n using A49_C_def A49_P1_def A49_P2_def assms(1) assms(2) by blast\n\nsubsubsection\\Mitigation is also Irreversible (A50)\\\n(**Mitigation of climate change (i.e., the \"preventive alternative\" to CE), too, is, at least to some\nextent, an irreversible intervention with unforeseen side-effects.*)\n\nconsts Mitigation::e (**constant of same type as actions\/interventions*)\n\ndefinition \"A50_C \\ [\\ Irreversible(Mitigation) \\<^bold>\\ USideEffects(Mitigation)]\"\n\nsubsubsection\\All Interventions have Unpredictable Side-Effects (A51)\\\n(**This defense of CE states that we do never completely foresee the consequences of our actions anyways,\nand thus aims at somehow trivializing the concerns regarding unforeseen side-effects of CE.*)\n\ndefinition \"A51_C \\ [\\ \\<^bold>\\I. USideEffects(I)]\"\n\nsubsection\\Reconstructing the Argument Graph\\\n(**Below we introduce our generalized attack\/support relations between arguments.*)\n\nabbreviation \"attacks1 \\ \\ \\ (\\ \\ \\) \\ False\" (**one attacker*)\nabbreviation \"supports1 \\ \\ \\ \\ \\ \\\" (**only one supporter*)\nabbreviation \"attacks2 \\ \\ \\ \\ (\\ \\ \\ \\ \\) \\ False\" (*two attackers *)\nabbreviation \"supports2 \\ \\ \\ \\ (\\ \\ \\) \\ \\\" (**two supporters*)\n\nsubsubsection\\Does A45 support A22?\\\n(**Implicit premise needed.*)\nlemma \"supports1 A45_C A22_P1\" nitpick oops (**countermodel found*)\ntheorem assumes \"[\\ \\<^bold>\\CEisCatastrophic \\<^bold>\\ CEisWrong]\" (**implicit*)\n shows \"supports1 A45_C A22_P1\" using A22_P1_def A45_C_def assms(1) by blast\n\nsubsubsection\\Does A46 support A22?\\\n(**The same implicit premise as before is needed.*)\nlemma \"supports1 A46_C A22_P1\" nitpick oops (**countermodel found*)\ntheorem assumes \"[\\ \\<^bold>\\CEisCatastrophic \\<^bold>\\ CEisWrong]\" (**implicit*)\n shows \"supports1 A46_C A22_P1\" using A22_P1_def A46_C_def assms(1) by blast\n\nsubsubsection\\Do A47 and A48 (together) support A22?\\\n(**An implicit premise is also needed.*)\nlemma \"supports2 A47_C A48_C A22_P1\" nitpick oops (**countermodel found*)\ntheorem assumes \"[\\\\<^bold>\\I. CEAction(I) \\<^bold>\\ WrongAction(I)]\\[\\ CEisWrong]\" (*implicit*)\n shows \"supports2 A47_C A48_C A22_P1\"\n using A22_P1_def A47_C_def A48_C_def assms(1) by blast (**assms(1) implicit*)\n\nsubsubsection\\Does A49 support A22?\\\n(**The same implicit premise as before is needed.*)\nlemma \"supports1 A49_C A22_P1\" nitpick oops (**countermodel found*)\ntheorem assumes \"[\\ \\<^bold>\\I. CEAction(I) \\<^bold>\\ WrongAction(I)] \\ [\\ CEisWrong]\" (*implicit*)\n shows \"supports1 A49_C A22_P1\" using A22_P1_def A49_C_def assms(1) by blast\n\nsubsubsection\\Does A50 attack both A48 and A49?\\\n(**We reconstruct the arguments corresponding to the \\emph{attack} relations,\nnoting that here, too, is an additional implicit premise needed.*)\n\nlemma \"attacks1 A50_C A48_C\" nitpick oops (** countermodel found*)\nlemma \"attacks1 A50_C A49_P2\" nitpick oops (** countermodel found*)\n\ntheorem assumes \"[\\ \\<^bold>\\WrongAction(Mitigation)]\" (** implicit premise*)\n shows \"attacks1 A50_C A48_C\"\n using A48_C_def A50_C_def assms(1) by blast\n\ntheorem assumes \"[\\ \\<^bold>\\WrongAction(Mitigation)]\" (** implicit premise*)\n shows \"attacks1 A50_C A49_P2\" \n using A49_P2_def A50_C_def assms(1) by blast\n\nsubsubsection\\Does A51 attack A49?\\\n(**The same implicit premise as before is needed.*)\nlemma \"attacks1 A51_C A49_P2\" nitpick oops (** countermodel found*)\n\ntheorem assumes \"[\\ \\<^bold>\\WrongAction(Mitigation)]\" (**implicit premise *)\n shows \"attacks1 A51_C A49_P2\" using A49_P2_def A51_C_def assms(1) by blast\n\n(*<*)\nend\n(*>*)\n","avg_line_length":56.868852459,"max_line_length":157,"alphanum_fraction":0.7485346401} {"size":4478,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"theory mp1_sol\nimports Main\nbegin\n\n(*\nIn this exercise, you will prove some lemmas of propositional\nlogic with the aid of a calculus of natural deduction.\n\nFor the proofs, you may only use \"assumption\", and the following rules\nwith rule, erule, rule_tac or erule_tac. You may also use lemmas that\nyou have proved so long as they meet the same restriction.\n*)\n\nthm notI\nthm notE\nthm conjI\nthm conjE\nthm disjI1\nthm disjI2\nthm disjE\nthm impI\nthm impE\nthm iffI\nthm iffE\n\n(*\nnotI: (P \\ False) \\ \\ P\nnotE: \\ \\ P; P \\ \\ Q\nconjI: \\ P; Q \\ \\ P \\ Q\nconjE: \\ P \\ Q; \\ P; Q \\ \\ R \\ \\ R\ndisjI1: P \\ P \\ Q\ndisjI2: Q \\ P \\ Q\ndisjE: \\ P \\ Q; P \\ R; Q \\ R \\ \\ R\nimpI: (P \\ Q) \\ P \\ Q\nimpE: \\ P \\ Q; P; Q \\ R \\ \\ R\niffI: \\ P \\ Q; Q \\ P \\ \\ P = Q\niffE: \\ P = Q; \\ P \\ Q; Q \\ P \\ \\ R \\ \\ R\n\nProve:\n*)\n\n(* +3 *)\nlemma problem1: \"(A \\ B) \\ (B \\ A)\"\napply (rule impI)\napply (erule conjE)\napply (rule conjI)\napply assumption\napply assumption\ndone\n\n(* + 4 *)\nlemma problem2: \"(A \\ A) \\ (B \\ A)\"\napply (rule impI)\napply (rule disjI2)\napply (erule disjE)\napply (assumption)\napply (assumption)\ndone\n\n(* +4 *)\nlemma problem3: \"(A \\ B) \\ ((\\B) \\ (\\A))\"\napply (rule impI)\napply (erule conjE)\napply (rule impI)\napply (erule notE)\napply assumption\ndone\n\n(* + 5 *)\nlemma problem4: \" (A \\ B) \\ ((\\ B) \\ (\\ A))\"\napply (rule impI)\napply (rule impI)\napply (rule notI)\napply (rule impE, assumption, assumption)\napply (rule notE, assumption, assumption)\ndone\n\n(* + 5 *)\nlemma problem5: \"((A \\ B) \\ C) \\ (A \\ (B \\ C))\"\napply (rule impI)\napply (rule impI)\napply (rule impI)\napply (rule impE, assumption)\napply (rule conjI, assumption, assumption)\napply assumption\ndone\n\n(* + 7 *)\nlemma problem6: \"((\\ B) \\ (\\ A)) \\ (\\(A \\ B))\"\napply (rule impI)\napply (rule notI)\napply (rule conjE, assumption)\napply (rule disjE, assumption)\napply (rule notE, assumption, assumption)\napply (rule notE, assumption, assumption)\ndone\n\n(* + 7 *)\nlemma problem7: \"(\\A \\ \\B) \\ (\\(A \\ B))\"\napply (rule impI)\napply (rule notI)\napply (rule conjE, assumption)\napply (rule disjE, assumption)\napply (rule notE, assumption, assumption)\napply (rule notE, assumption, assumption)\ndone\n\n(* Extra Credit *)\nthm classical\n\n(* + 1 *)\nlemma problem8: \"\\ \\ A \\ A\"\napply(rule impI)\napply(rule classical)\napply(erule notE)\napply assumption\ndone\n\n(* + 2 *)\nlemma problem9: \"A \\ \\ A\"\napply(rule classical)\napply(rule disjI2)\napply(rule notI)\napply(erule notE)\napply(rule disjI1)\napply assumption\ndone\n\n(* + 2 *)\nlemma problem10: \"(\\ A \\ B) \\ (\\ B \\ A)\"\napply(rule impI)\napply(rule impI)\napply(rule classical)\napply(erule impE)\napply(assumption)\napply(erule notE)\napply assumption\ndone\n\n(* +2 *)\nlemma problem11: \"((A \\ B) \\ A) \\ A\"\napply(rule impI)\napply(rule classical)\napply(erule impE)\napply(rule impI)\napply(erule notE)\napply assumption\napply assumption\ndone\n\n(* + 5 *)\nlemma problem12: \"(\\ (A \\ B)) = (\\ A \\ \\ B)\"\napply (rule iffI)\napply (rule classical)\napply (rule disjI1)\napply (rule notI)\napply (erule notE)\napply (rule conjI)\napply assumption\napply (rule classical)\napply (erule notE)\napply (rule disjI2)\napply assumption\napply (rule notI)\napply (erule conjE)\napply (erule disjE)\napply (erule notE)\napply assumption\napply (erule notE)\napply assumption\ndone\n\n(* + 3 *)\nlemma problem13: \"(\\ A \\ False) \\ A\"\napply (rule impI)\napply (rule classical)\napply (erule impE)\napply assumption\napply (rule_tac P = \"\\ A\" in notE)\napply (rule notI)\napply assumption\napply assumption\ndone\n\nend\n","avg_line_length":24.0752688172,"max_line_length":137,"alphanum_fraction":0.6949531041} {"size":1497,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"(* Title: HOL\/Auth\/n_deadlock_on_ini.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\n(*header{*The n_deadlock Protocol Case Study*}*) \n\ntheory n_deadlock_on_ini imports n_deadlock_base\nbegin\nlemma iniImply_inv__1:\nassumes a1: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\nand a2: \"formEval (andList (allInitSpecs N)) s\"\nshows \"formEval f s\"\nusing a1 a2 by auto\n\nlemma iniImply_inv__2:\nassumes a1: \"(\\ p__Inv4. p__Inv4\\N\\f=inv__2 p__Inv4)\"\nand a2: \"formEval (andList (allInitSpecs N)) s\"\nshows \"formEval f s\"\nusing a1 a2 by auto\n\nlemma iniImply_inv__3:\nassumes a1: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__3 p__Inv3 p__Inv4)\"\nand a2: \"formEval (andList (allInitSpecs N)) s\"\nshows \"formEval f s\"\nusing a1 a2 by auto\n\nlemma iniImply_inv__4:\nassumes a1: \"(\\ p__Inv4. p__Inv4\\N\\f=inv__4 p__Inv4)\"\nand a2: \"formEval (andList (allInitSpecs N)) s\"\nshows \"formEval f s\"\nusing a1 a2 by auto\n\nlemma iniImply_inv__5:\nassumes a1: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__5 p__Inv3 p__Inv4)\"\nand a2: \"formEval (andList (allInitSpecs N)) s\"\nshows \"formEval f s\"\nusing a1 a2 by auto\nend\n","avg_line_length":37.425,"max_line_length":132,"alphanum_fraction":0.7374749499} {"size":269,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"theory OTP\n imports QRHL.QRHL\nbegin\n\ndeclare_variable_type msg :: \\{finite, xor_group}\\\n\ntype_synonym key = msg\ntype_synonym ciph = msg\n\ndefinition otp :: \\key \\ msg \\ ciph\\ where\n \\otp k m = k + m\\\n\nend\n","avg_line_length":19.2142857143,"max_line_length":79,"alphanum_fraction":0.7063197026} {"size":539,"ext":"thy","lang":"Isabelle","max_stars_count":30.0,"content":"theory lscmnbignum_Lsc__bignum__mod_add__subprogram_def_WP_parameter_def_1\nimports \"..\/LibSPARKcrypto\"\nbegin\n\nwhy3_open \"lscmnbignum_Lsc__bignum__mod_add__subprogram_def_WP_parameter_def_1.xml\"\n\nwhy3_vc WP_parameter_def\nproof -\n let ?k = \"a_last - a_first + 1\"\n have \"num_of_big_int (word32_to_int o a) a_first ?k < Base ^ nat ?k\"\n by (simp add: num_of_lint_upper word32_to_int_upper')\n with `(num_of_big_int' b _ _ + num_of_big_int' c _ _ = _) = _`\n `carry \\ True`\n show ?thesis by (simp add: base_eq)\nqed\n\nwhy3_end\n\nend\n","avg_line_length":26.95,"max_line_length":83,"alphanum_fraction":0.7643784787} {"size":11257,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"(* $Id$ *)\ntheory HEAP01ReifyLemmas\nimports HEAP01Reify HEAP1Lemmas\nbegin\n\n(*========================================================================*)\nsection {* Refinement L0-L1 lemmas *}\n(*========================================================================*)\n\n(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)\nsubsubsection {* Lemmas for invariant sub parts over empty maps *}\n(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)\n\nlemma l_disjoint_empty: \"Disjoint empty\"\nunfolding Disjoint_def disjoint_def Locs_of_def locs_of_def\nby (metis dom_empty ex_in_conv)\n\nlemma l_sep_empty: \"sep empty\"\nunfolding sep_def\nby (metis dom_empty empty_iff)\n\n(*lemma l_nat1_map_empty: \"nat1_map empty\"\nunfolding nat1_map_def\nby (metis dom_empty empty_iff) - already above to help proofs of l_locs_empty_iff*)\n\nlemma l_finite_empty: \"finite (dom empty)\"\nby (metis dom_empty finite.emptyI)\n\nlemma l_F1_inv_empty: \"F1_inv empty\"\nby (metis F1_inv_def l_nat1_map_empty dom_empty finite.emptyI l_disjoint_empty l_sep_empty)\n\n(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)\nsubsubsection {* Lemmas for HEAP definitions - properties of interest *}\n(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)\n\ntext {* This lemma I tried to prove earlier on when doing the proof for\n memory_shrink property of DISPOSE1 alongside the lemma that NEW\n followed by dispose lead to identify map. In there I failed and\n simplified the goal to be simply new1_postcondition_diff_f_locs_headon\n\n Now, if I am to prove that the retrieve is functional, I still need \n the same lemma again, which is given below.\n\n I know how to prove it now, though: I just need Disjoint to show that's true,\n phrased through a couple of lemmas that say:\n a \\ dom f \\ a \\ locs_of a (the(f a)) [f_dom_locs_of]\n \n a \\ dom f \\ b \\ dom f \\\n Disjoint f \\ a \\ locs_of b (the (f b)) \\ a = b (!!!) ???\n *}\n\nlemma l_locs_of_uniqueness:\n \"a \\ dom f \\ b \\ dom f \\ Disjoint f \\ a \\ locs_of b (the (f b)) \\ a = b\"\nunfolding Disjoint_def disjoint_def\nfind_theorems \"Locs_of _ _\"\napply (simp add: l_locs_of_Locs_of_iff)\napply (erule_tac x=a in ballE)\napply (erule_tac x=b in ballE,simp_all)\nfind_theorems simp:\"_ \\ _ = _\"\nthm contrapos_pp[of \"locs_of a (the (f a)) \\ locs_of b (the (f b)) = {}\" \"a=b\"]\napply (rule contrapos_np[of \"locs_of a (the (f a)) \\ locs_of b (the (f b)) = {}\" \"a=b\"],simp_all)\nsorry \n\nlemma l_locs_ext:\n \"nat1_map f \\ nat1_map g \\ Disjoint f \\ Disjoint g \\ locs f = locs g \\ f = g\"\nunfolding locs_def\n(*\n\"locs f = locs g \\ dom f = dom g\"\n\"\\ x \\ dom f. locs_of x f x = locs_of x g x\"\n\"locs_of x f x = locs_of x g x \\ f x = g x\"\n*)\napply (rule ext)\napply (case_tac \"x \\ dom f\")\nthm fun_eq_iff \napply (rule fun_eq_iff)\n\nfind_theorems name:set name:iff\nfind_theorems (200) \"_ = (_::('a \\ 'b))\" -name:HEAP -name:VDMMaps\nthm map_le_antisym[of f g] fun_eq_iff[of f g]\napply (rule map_le_antisym)\n (* NOTE: This is better than simply using fun_eq_iff because of \\ dom extra *)\nfind_theorems simp:\"_ \\\\<^sub>m _\" \n (* hum... could this help with an induction principle? i.e. lemmas about \\\\<^sub>m giving hints for the shape *)\nunfolding map_le_def\napply (rule_tac[!] ballI)\nfind_theorems \"_ \\ dom _ \\ _ \\ locs_of _ _\"\nfind_theorems \"_ \\ dom _ \\ _ \\ locs _\"\nfind_theorems simp:\"_ \\ _\" name:Set\napply (erule equalityE)\napply (simp add: subset_eq)\napply (frule f_dom_locs_of,simp)\napply (frule f_in_dom_locs,simp)\napply (erule_tac x=a in ballE)\ndefer\n apply simp\n defer\nfind_theorems \"_ \\ locs _\"\nthm k_in_locs_iff[of f _, THEN subst[of _ _ \"(\\ x . x)\"]]\n (* NOTE: Whaa... we need the complicated expression because of assumption equality :-( *)\npr\nthm k_in_locs_iff\napply (frule_tac x=a in k_in_locs_iff) \napply (frule_tac f=g and x=a in k_in_locs_iff) \napply simp\napply (elim bexE)\nthm l_locs_of_uniqueness\napply (cut_tac a=a and b=y and f=f in l_locs_of_uniqueness,simp_all)\napply (simp add: l_locs_of_uniqueness)\napply simp_all\napply (frule k_in_locs_iff[of f _],simp)\nunfolding locs_def\nfind_theorems name:\"fun\" name:iff\nsorry\n\nlemma l_locs_of_itself:\n \"nat1 y \\ x \\ locs_of x y\"\nunfolding locs_of_def\nby auto\n\n(*========================================================================*)\nsection {* Refinement L0-L1 adequacy proof lemmas *}\n(*========================================================================*)\n\n(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)\nsubsubsection {* Lemmas about L0-L1 definitions *}\n(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)\n\nlemma l_nat1_card:\n \"finite F \\ F \\ {} \\ nat1 (card F)\"\nby (simp add: card_gt_0_iff)\n\nlemma l_loc_of_singleton: \n \"locs_of x (Suc 0) = {x}\"\nunfolding locs_of_def\nby auto\n\nlemma \"nat1 y \\ Min(locs_of x y) \\ locs_of x y\"\napply (rule Min_in)\napply (metis b_locs_of_finite)\nby (metis b_locs_of_non_empty)\n\n(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)\nsubsubsection {* Lemmas about retrieve function *}\n(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)\n\nlemma l_nat1_map_dom_in_retr0: \"nat1_map f \\ x\\dom f \\ x \\ (retr0 f)\"\nunfolding retr0_def locs_def \nby (simp, metis f_dom_locs_of)\n\nlemma l_dom_within_retr0: \"nat1_map f \\ dom f \\ retr0 f\"\nby (metis l_nat1_map_dom_in_retr0 subsetI)\n\nlemma l_disjoint_retr0_not_in_dom: \n \"F' \\ {} \\ finite F' \\ nat1_map f1 \\ disjoint F' (retr0 f1) \\ Min F' \\ dom f1\"\nunfolding disjoint_def\nby (metis Min_in disjoint_iff_not_equal l_nat1_map_dom_in_retr0)\n\n(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)\nsubsubsection {* Lemmas about Level0 contiguousness function *}\n(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)\n\nlemma f_contiguous_finite:\n \"contiguous F \\ finite F\"\nunfolding contiguous_def\nby (metis b_locs_of_finite)\nfind_theorems \"finite(locs_of _ _)\" --\"changed definition of contiguous!\"\n\nlemma f_contiguous_non_empty:\n \"contiguous F \\ F \\ {}\"\nunfolding contiguous_def\nby (metis b_locs_of_non_empty)\n\n(* Thanks to IJW eq_locs \nlemma b_contiguous_locs_off_iff:\n \"contiguous F \\ locs_of (Min F) (card F) = F\"\napply (frule f_contiguous_finite)\napply (frule f_contiguous_non_empty)\n(*apply (induct_tac F rule: finite_induct) \n WAHHHA... Here if I used \\ instead of \\ it wouldn't complain\n yet it wouldn't give me the other bits I need for the frule above...\napply (rule finite_induct) - wrong rule!\n *)\nfind_theorems name:indu name:Finite\napply (rule finite_ne_induct)\napply (simp_all add: l_loc_of_singleton)\nunfolding locs_of_def\nfind_theorems \"card _ > 0\"\napply (simp_all add: card_gt_0_iff)\nfind_theorems \"_ = (_::'a set)\" name:Set -name:Inter\napply (rule equalityI)\napply (rule subsetI)\nunfolding min_def\napply (simp_all split: split_if_asm)\noops\n*)\n\nlemma l_locs_of_min:\n \"nat1 y \\ Min(locs_of x y) = x\"\n(*\nfind_theorems name:Nat name:ind\nthm strict_inc_induct[of x _ \"(\\ l . Min(locs_of x y )=l)\"]\nthm nat_less_induct[of \"(\\ l . Min(locs_of x y )=l)\" x]\nthm full_nat_induct[of \"(\\ l . Min(locs_of x y )=l)\" x]\nthm less_induct\napply (induct y rule: full_nat_induct)\napply (metis less_not_refl nat1_def)\nunfolding nat1_def locs_of_def\napply simp\nfind_theorems \"Min {_ . _}\"\nthm add_Min_commute[of \"{x.. F \\ {} \\ contiguous F \\ locs_of (Min F) (card F) = F\"\nunfolding contiguous_def\napply (elim exE conjE)\nby (simp add: l_locs_of_min l_locs_of_card)\n\n(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)\nsubsubsection {* Induction principle for adequacy proof *}\n(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)\n\n(* TODO: adjust this to get closer to the F1_inv (i.e. IJW's \"invariant preserving induction\") *)\n(* Induction rule as suggested by Cliff *) \nlemma contig_nonabut_finite_set_induct [case_names empty extend, induct set: finite]:\n assumes fin: \"finite F\" (* Requires a finite set *)\n and empty: \"P {}\" (* Base case for the empty set *)\n and extend: \"\\ F F'. finite F \\ \n finite F' \\ \n F' \\ {} \\ \n contiguous F' \\\n (* keep this order F' F for convenience because of locs_of \\ locs lemmas *)\n disjoint F' F \\ \n non_abutting F' F \\ \n P F \\ \n P (F \\ F')\"\n shows \"P F\"\nusing `finite F`\nfind_theorems name:Finite_Set name:induc\nproof (induct rule: finite_induct)\n show \"P {}\" by fact\n fix x F assume F: \"finite F\" and P: \"P F\"\n show \"P (insert x F)\"\n proof cases\n assume \"x \\ F\"\n hence \"insert x F = F\" by (rule insert_absorb)\n with P show ?thesis by (simp only:)\n next\n assume \"x \\ F\"\n from F this P show ?thesis sorry\n qed\nqed\n\n(*\nusing assms\nproof induct\n case empty then show ?case by simp\nnext\n case (insert x F) then show ?case by cases auto\nqed\n*)\n\n\n(* ~~~~~~~~~~~~~~~~~~~~~~~~~~ F1_inv update ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *)\n\n(* Coalesce together (rather artificially) the conditions needed for the invariant proofs.\n They come from the separate lemmas created for each part of the invariant. This makes\n the underlying refinement proof a little bit shorter\/direct. In a way, that could be\n viewed as a proof pattern\/family being reused?\n *)\nlemma l_F1_inv_singleton_upd:\n \"nat1 y \\ x \\ dom f \\ F1_inv f \\ \n disjoint (locs_of x y) (locs f) \\ \n sep0 f [x\\y] \\ x+y \\ dom f \\ F1_inv(f \\m [x \\ y])\" \nunfolding F1_inv_def\napply (elim conjE)\napply (intro conjI)\napply (simp add: l_disjoint_singleton_upd)\napply (simp add: l_sep_singleton_upd)\napply (simp add: l_nat1_map_singleton_upd)\napply (simp add: l_finite_singleton_upd)\ndone\n\n\nend\n","avg_line_length":38.1593220339,"max_line_length":160,"alphanum_fraction":0.6338278405} {"size":60504,"ext":"thy","lang":"Isabelle","max_stars_count":2.0,"content":"(* @TAG(OTHER_LGPL) *)\n\n(*\n Author: Norbert Schirmer\n Maintainer: Norbert Schirmer, norbert.schirmer at web de\n License: LGPL\n*)\n\n(* Title: VcgEx.thy\n Author: Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and\/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection {* Examples using the Verification Environment *}\n\ntheory VcgEx imports \"..\/HeapList\" \"..\/Vcg\" begin\n\ntext {* Some examples, especially the single-step Isar proofs are taken from\n\\texttt{HOL\/Isar\\_examples\/HoareEx.thy}. \n*}\n\nsubsection {* State Spaces *}\n\ntext {*\n First of all we provide a store of program variables that\n occur in the programs considered later. Slightly unexpected\n things may happen when attempting to work with undeclared variables.\n*}\n\nrecord 'g vars = \"'g state\" +\n A_' :: nat\n I_' :: nat\n M_' :: nat\n N_' :: nat\n R_' :: nat\n S_' :: nat\n B_' :: bool\n Arr_' :: \"nat list\"\n Abr_':: string\n\n\n\ntext {* We decorate the state components in the record with the suffix @{text \"_'\"},\nto avoid cluttering the namespace with the simple names that could no longer\nbe used for logical variables otherwise. \n*}\n\ntext {* We will first consider programs without procedures, later on\nwe will regard procedures without global variables and finally we\nwill get the full pictures: mutually recursive procedures with global\nvariables (including heap).\n*}\n\nsubsection {* Basic Examples *}\n\ntext {*\n We look at few trivialities involving assignment and sequential\n composition, in order to get an idea of how to work with our\n formulation of Hoare Logic.\n*}\n\ntext {*\n Using the basic rule directly is a bit cumbersome.\n*}\n \nlemma \"\\\\ {|\\N = 5|} \\N :== 2 * \\N {|\\N = 10|}\"\n apply (rule HoarePartial.Basic) apply simp\n done\n\ntext {*\n If we refer to components (variables) of the state-space of the program\n we always mark these with @{text \"\\\"}. It is the acute-symbol and is present on\n most keyboards. So all program variables are marked with the acute and all\n logical variables are not.\n The assertions of the Hoare tuple are\n ordinary Isabelle sets. As we usually want to refer to the state space\n in the assertions, we provide special brackets for them. They can be written \n as {\\verb+{| |}+} in ASCII or @{text \"\\ \\\"} with X-symbols. Internally\n marking variables has two effects. First of all we refer to the implicit\n state and secondary we get rid of the suffix @{text \"_'\"}.\n So the assertion @{term \"{|\\N = 5|}\"} internally gets expanded to \n @{text \"{s. N_' s = 5}\"} written in ordinary set comprehension notation of\n Isabelle. It describes the set of states where the @{text \"N_'\"} component\n is equal to @{text \"5\"}. \n*}\n\n\ntext {*\n Certainly we want the state modification already done, e.g.\\ by\n simplification. The @{text vcg} method performs the basic state\n update for us; we may apply the Simplifier afterwards to achieve\n ``obvious'' consequences as well.\n*}\n\n\nlemma \"\\\\ \\True\\ \\N :== 10 \\\\N = 10\\\"\n by vcg\n\nlemma \"\\\\ \\2 * \\N = 10\\ \\N :== 2 * \\N \\\\N = 10\\\"\n by vcg\n\nlemma \"\\\\ \\\\N = 5\\ \\N :== 2 * \\N \\\\N = 10\\\"\n apply vcg\n apply simp\n done\n\nlemma \"\\\\ \\\\N + 1 = a + 1\\ \\N :== \\N + 1 \\\\N = a + 1\\\"\n by vcg \n\nlemma \"\\\\ \\\\N = a\\ \\N :== \\N + 1 \\\\N = a + 1\\\"\n by vcg\n \n\nlemma \"\\\\ \\a = a \\ b = b\\ \\M :== a;; \\N :== b \\\\M = a \\ \\N = b\\\"\n by vcg\n \n\nlemma \"\\\\ \\True\\ \\M :== a;; \\N :== b \\\\M = a \\ \\N = b\\\"\n by vcg\n\nlemma \"\\\\ \\\\M = a \\ \\N = b\\\n \\I :== \\M;; \\M :== \\N;; \\N :== \\I\n \\\\M = b \\ \\N = a\\\"\n by vcg\n\ntext {*\nWe can also perform verification conditions generation step by step by using\nthe @{text vcg_step} method.\n*}\n\nlemma \"\\\\ \\\\M = a \\ \\N = b\\\n \\I :== \\M;; \\M :== \\N;; \\N :== \\I\n \\\\M = b \\ \\N = a\\\"\n apply vcg_step\n apply vcg_step\n apply vcg_step\n apply vcg_step\n done\n\ntext {*\n It is important to note that statements like the following one can\n only be proven for each individual program variable. Due to the\n extra-logical nature of record fields, we cannot formulate a theorem\n relating record selectors and updates schematically.\n*}\n\nlemma \"\\\\ \\\\N = a\\ \\N :== \\N \\\\N = a\\\"\n by vcg\n\n\n(*\nlemma \"\\\\ \\\\x = a\\ \\x :== \\x \\\\x = a\\\"\n apply (rule HoarePartial.Basic)\n -- {* We can't proof this since we don't know what @{text \"x_'_update\"} is. *}\n oops\n *)\nlemma \"\\\\{s. x_' s = a} (Basic (\\s. x_'_update (x_' s) s)) {s. x_' s = a}\"\n oops\n\n\ntext {*\n In the following assignments we make use of the consequence rule in\n order to achieve the intended precondition. Certainly, the\n @{text vcg} method is able to handle this case, too.\n*}\n\nlemma \"\\\\ \\\\M = \\N\\ \\M :== \\M + 1 \\\\M \\ \\N\\\"\nproof -\n have \"\\\\M = \\N\\ \\ \\\\M + 1 \\ \\N\\\"\n by auto\n also have \"\\\\ \\ \\M :== \\M + 1 \\\\M \\ \\N\\\"\n by vcg\n finally show ?thesis .\nqed\n\nlemma \"\\\\ \\\\M = \\N\\ \\M :== \\M + 1 \\\\M \\ \\N\\\"\nproof -\n have \"\\m n::nat. m = n \\ m + 1 \\ n\"\n -- {* inclusion of assertions expressed in ``pure'' logic, *}\n -- {* without mentioning the state space *}\n by simp\n also have \"\\\\ \\\\M + 1 \\ \\N\\ \\M :== \\M + 1 \\\\M \\ \\N\\\"\n by vcg\n finally show ?thesis .\nqed\n\nlemma \"\\\\ \\\\M = \\N\\ \\M :== \\M + 1 \\\\M \\ \\N\\\"\n apply vcg\n apply simp\n done\n\nsubsection {* Multiplication by Addition *}\n\ntext {*\n We now do some basic examples of actual \\texttt{WHILE} programs.\n This one is a loop for calculating the product of two natural\n numbers, by iterated addition. We first give detailed structured\n proof based on single-step Hoare rules.\n*}\n\nlemma \"\\\\ \\\\M = 0 \\ \\S = 0\\\n WHILE \\M \\ a\n DO \\S :== \\S + b;; \\M :== \\M + 1 OD\n \\\\S = a * b\\\"\nproof -\n let \"\\\\ _ ?while _\" = ?thesis\n let \"\\\\?inv\\\" = \"\\\\S = \\M * b\\\"\n\n have \"\\\\M = 0 & \\S = 0\\ \\ \\\\?inv\\\" by auto\n also have \"\\\\ \\ ?while \\\\?inv \\ \\ (\\M \\ a)\\\"\n proof\n let ?c = \"\\S :== \\S + b;; \\M :== \\M + 1\"\n have \"\\\\?inv \\ \\M \\ a\\ \\ \\\\S + b = (\\M + 1) * b\\\"\n by auto\n also have \"\\\\ \\ ?c \\\\?inv\\\" by vcg\n finally show \"\\\\ \\\\?inv \\ \\M \\ a\\ ?c \\\\?inv\\\" .\n qed\n also have \"\\\\?inv \\ \\ (\\M \\ a)\\ \\ \\\\S = a * b\\\" by auto\n finally show ?thesis by blast\nqed\n\n\ntext {*\n The subsequent version of the proof applies the @{text vcg} method\n to reduce the Hoare statement to a purely logical problem that can be\n solved fully automatically. Note that we have to specify the\n \\texttt{WHILE} loop invariant in the original statement.\n*}\n\nlemma \"\\\\ \\\\M = 0 \\ \\S = 0\\\n WHILE \\M \\ a\n INV \\\\S = \\M * b\\\n DO \\S :== \\S + b;; \\M :== \\M + 1 OD\n \\\\S = a * b\\\"\n apply vcg \n apply auto\n done\n\ntext {* Here some examples of ``breaking'' out of a loop *}\n\nlemma \"\\\\ \\\\M = 0 \\ \\S = 0\\\n TRY \n WHILE True\n INV \\\\S = \\M * b\\\n DO IF \\M = a THEN THROW ELSE \\S :== \\S + b;; \\M :== \\M + 1 FI OD\n CATCH\n SKIP\n END\n \\\\S = a * b\\\"\napply vcg\napply auto\ndone\n\nlemma \"\\\\ \\\\M = 0 \\ \\S = 0\\\n TRY \n WHILE True\n INV \\\\S = \\M * b\\\n DO IF \\M = a THEN \\Abr :== ''Break'';;THROW \n ELSE \\S :== \\S + b;; \\M :== \\M + 1 \n FI \n OD\n CATCH\n IF \\Abr = ''Break'' THEN SKIP ELSE Throw FI\n END\n \\\\S = a * b\\\"\napply vcg\napply auto\ndone\n\n\ntext {* Some more syntactic sugar, the label statement @{text \"\\ \\ \\\"} as shorthand\nfor the @{text \"TRY-CATCH\"} above, and the @{text \"RAISE\"} for an state-update followed\nby a @{text \"THROW\"}. \n*}\nlemma \"\\\\ \\\\M = 0 \\ \\S = 0\\\n \\\\Abr = ''Break''\\\\ WHILE True INV \\\\S = \\M * b\\\n DO IF \\M = a THEN RAISE \\Abr :== ''Break'' \n ELSE \\S :== \\S + b;; \\M :== \\M + 1 \n FI \n OD\n \\\\S = a * b\\\"\napply vcg\napply auto\ndone\n\nlemma \"\\\\ \\\\M = 0 \\ \\S = 0\\\n TRY \n WHILE True\n INV \\\\S = \\M * b\\\n DO IF \\M = a THEN RAISE \\Abr :== ''Break'' \n ELSE \\S :== \\S + b;; \\M :== \\M + 1 \n FI \n OD\n CATCH\n IF \\Abr = ''Break'' THEN SKIP ELSE Throw FI\n END\n \\\\S = a * b\\\"\napply vcg\napply auto\ndone\n\nlemma \"\\\\ \\\\M = 0 \\ \\S = 0\\\n \\\\Abr = ''Break''\\ \\ WHILE True\n INV \\\\S = \\M * b\\\n DO IF \\M = a THEN RAISE \\Abr :== ''Break'' \n ELSE \\S :== \\S + b;; \\M :== \\M + 1 \n FI \n OD\n \\\\S = a * b\\\"\napply vcg\napply auto\ndone\n\ntext {* Blocks *}\n\nlemma \"\\\\\\\\I = i\\ LOC \\I;; \\I :== 2 COL \\\\I \\ i\\\"\n apply vcg\n by simp\nlemma \"\\\\ \\\\N = n\\ LOC \\N :== 10;; \\N :== \\N + 2 COL \\\\N = n\\\"\n by vcg\n\nlemma \"\\\\ \\\\N = n\\ LOC \\N :== 10, \\M;; \\N :== \\N + 2 COL \\\\N = n\\\"\n by vcg\n\n\nsubsection {* Summing Natural Numbers *}\n\ntext {*\n We verify an imperative program to sum natural numbers up to a given\n limit. First some functional definition for proper specification of\n the problem.\n*}\n\nprimrec\n sum :: \"(nat => nat) => nat => nat\"\nwhere\n \"sum f 0 = 0\"\n| \"sum f (Suc n) = f n + sum f n\"\n\nsyntax\n \"_sum\" :: \"idt => nat => nat => nat\"\n (\"SUMM _<_. _\" [0, 0, 10] 10)\ntranslations\n \"SUMM jj. b) k\"\n\ntext {*\n The following proof is quite explicit in the individual steps taken,\n with the @{text vcg} method only applied locally to take care of\n assignment and sequential composition. Note that we express\n intermediate proof obligation in pure logic, without referring to the\n state space.\n*}\n\ntheorem \"\\\\ \\True\\\n \\S :== 0;; \\I :== 1;;\n WHILE \\I \\ n\n DO\n \\S :== \\S + \\I;;\n \\I :== \\I + 1\n OD\n \\\\S = (SUMM j\"\n (is \"\\\\ _ (_;; ?while) _\")\nproof -\n let ?sum = \"\\k. SUMM js i. s = ?sum i\"\n\n have \"\\\\ \\True\\ \\S :== 0;; \\I :== 1 \\?inv \\S \\I\\\"\n proof -\n have \"True \\ 0 = ?sum 1\"\n by simp\n also have \"\\\\ \\\\\\ \\S :== 0;; \\I :== 1 \\?inv \\S \\I\\\"\n by vcg\n finally show ?thesis .\n qed\n also have \"\\\\ \\?inv \\S \\I\\ ?while \\?inv \\S \\I \\ \\ \\I \\ n\\\"\n proof\n let ?body = \"\\S :== \\S + \\I;; \\I :== \\I + 1\"\n have \"\\s i. ?inv s i \\ i \\ n \\ ?inv (s + i) (i + 1)\"\n by simp\n also have \"\\\\ \\\\S + \\I = ?sum (\\I + 1)\\ ?body \\?inv \\S \\I\\\"\n by vcg\n finally show \"\\\\ \\?inv \\S \\I \\ \\I \\ n\\ ?body \\?inv \\S \\I\\\" .\n qed\n also have \"\\s i. s = ?sum i \\ \\ i \\ n \\ s = ?sum n\"\n by simp \n finally show ?thesis .\nqed\n\ntext {*\n The next version uses the @{text vcg} method, while still explaining\n the resulting proof obligations in an abstract, structured manner.\n*}\n\ntheorem \"\\\\ \\True\\\n \\S :== 0;; \\I :== 1;;\n WHILE \\I \\ n\n INV \\\\S = (SUMM j<\\I. j)\\\n DO\n \\S :== \\S + \\I;;\n \\I :== \\I + 1\n OD\n \\\\S = (SUMM j\"\nproof -\n let ?sum = \"\\k. SUMM js i. s = ?sum i\"\n\n show ?thesis\n proof vcg\n show \"?inv 0 1\" by simp\n next\n fix i s assume \"?inv s i\" \"i \\ n\"\n thus \"?inv (s + i) (i + 1)\" by simp\n next \n fix i s assume x: \"?inv s i\" \"\\ i \\ n\" \n thus \"s = ?sum n\" by simp\n qed\nqed\n\ntext {*\n Certainly, this proof may be done fully automatically as well, provided\n that the invariant is given beforehand.\n*}\n\ntheorem \"\\\\ \\True\\\n \\S :== 0;; \\I :== 1;;\n WHILE \\I \\ n\n INV \\\\S = (SUMM j<\\I. j)\\\n DO\n \\S :== \\S + \\I;;\n \\I :== \\I + 1\n OD\n \\\\S = (SUMM j\"\n apply vcg \n apply auto\n done\n\nsubsection {* SWITCH *}\n\nlemma \"\\\\ \\\\N = 5\\ SWITCH \\B \n {True} \\ \\N :== 6\n | {False} \\ \\N :== 7\n END\n \\\\N > 5\\\"\napply vcg\napply simp\ndone\n\nlemma \"\\\\ \\\\N = 5\\ SWITCH \\N \n {v. v < 5} \\ \\N :== 6\n | {v. v \\ 5} \\ \\N :== 7\n END\n \\\\N > 5\\\"\napply vcg\napply simp\ndone\n\nsubsection {* (Mutually) Recursive Procedures *}\n\nsubsubsection {* Factorial *}\n\ntext {* We want to define a procedure for the factorial. We first\ndefine a HOL functions that calculates it to specify the procedure later on.\n*}\n\nprimrec fac:: \"nat \\ nat\"\nwhere\n\"fac 0 = 1\" |\n\"fac (Suc n) = (Suc n) * fac n\"\n\nlemma fac_simp [simp]: \"0 < i \\ fac i = i * fac (i - 1)\"\n by (cases i) simp_all\n\ntext {* Now we define the procedure *}\n\nprocedures\n Fac (N|R) = \"IF \\N = 0 THEN \\R :== 1\n ELSE \\R :== CALL Fac(\\N - 1);;\n \\R :== \\N * \\R\n FI\"\n\n\n\ntext {* A procedure is given by the signature of the procedure\nfollowed by the procedure body.\nThe signature consists of the name of the procedure and a list of \nparameters. The parameters in front of the pipe @{text \"|\"} are value parameters \nand behind the pipe are the result parameters. Value parameters model call by value\nsemantics. The value of a result parameter at the end of the procedure is passed back\nto the caller. \n*}\n\n\n\ntext {*\nBehind the scenes the @{text \"procedures\"} command provides us convenient syntax\nfor procedure calls, defines a constant for the procedure body \n(named @{term \"Fac_body\"}) and creates some locales. The purpose of locales \nis to set up logical contexts to support modular reasoning.\nA locale is named @{text Fac_impl} and extends the @{text hoare} locale\nwith a theorem @{term \"\\ ''Fac'' = Fac_body\"} that simply states how the \nprocedure is defined in the procedure context. Check out the locales. \nThe purpose of the locales is to give us easy means to setup the context \nin which we will prove programs correct. \nIn these locales the procedure context @{term \"\\\"} is fixed. \nSo always use this letter in procedure\nspecifications. This is crucial, if we later on prove some tuples under the\nassumption of some procedure specifications.\n*}\n\nthm Fac_body.Fac_body_def\nprint_locale Fac_impl\n\ntext {*\nTo see how a call is syntactically translated you can switch off the\nprinting translation via the configuration option @{text hoare_use_call_tr'}\n*}\n\ncontext Fac_impl\nbegin\ntext {*\n@{term \"CALL Fac(\\N,\\M)\"} is internally:\n*}\ndeclare [[hoare_use_call_tr' = false]]\ntext {*\n@{term \"CALL Fac(\\N,\\M)\"}\n*}\nterm \"CALL Fac(\\N,\\M)\"\ndeclare [[hoare_use_call_tr' = true]]\nend\n\ntext {*\nNow let us prove that @{term \"Fac\"} meets its specification. \n*}\n\ntext {*\nProcedure specifications are ordinary Hoare tuples. We use the parameterless\ncall for the specification; @{text \"\\R :== PROC Fac(\\N)\"} is syntactic sugar\nfor @{text \"Call ''Fac''\"}. This emphasises that the specification \ndescribes the internal behaviour of the procedure, whereas parameter passing\ncorresponds to the procedure call.\n*}\n\n\nlemma (in Fac_impl) \n shows \"\\n. \\,\\\\\\\\N=n\\ PROC Fac(\\N,\\R) \\\\R = fac n\\\"\n apply (hoare_rule HoarePartial.ProcRec1)\n apply vcg\n apply simp\n done\n\n\ntext {* \nSince the factorial was implemented recursively,\nthe main ingredient of this proof is, to assume that the specification holds for \nthe recursive call of @{term Fac} and prove the body correct.\nThe assumption for recursive calls is added to the context by\nthe rule @{thm [source] HoarePartial.ProcRec1} \n(also derived from general rule for mutually recursive procedures):\n@{thm [display] HoarePartial.ProcRec1 [no_vars]}\nThe verification condition generator will infer the specification out of the\ncontext when it encounters a recursive call of the factorial.\n*}\n\ntext {* We can also step through verification condition generation. When\nthe verification condition generator encounters a procedure call it tries to\nuse the rule @{text ProcSpec}. To be successful there must be a specification\nof the procedure in the context. \n*}\n\nlemma (in Fac_impl)\n shows \"\\n. \\\\\\\\N=n\\ \\R :== PROC Fac(\\N) \\\\R = fac n\\\"\n apply (hoare_rule HoarePartial.ProcRec1)\n apply vcg_step\n apply vcg_step\n apply vcg_step\n apply vcg_step\n apply vcg_step\n apply simp\n done\n\n\ntext {* Here some Isar style version of the proof *}\nlemma (in Fac_impl)\n shows \"\\n. \\\\\\\\N=n\\ \\R :== PROC Fac(\\N) \\\\R = fac n\\\"\nproof (hoare_rule HoarePartial.ProcRec1)\n have Fac_spec: \"\\n. \\,(\\n. {(\\\\N=n\\, Fac_'proc, \\\\R = fac n\\,{})})\n \\ \\\\N=n\\ \\R :== PROC Fac(\\N) \\\\R = fac n\\\"\n apply (rule allI)\n apply (rule hoarep.Asm) \n by auto\n show \"\\n. \\,(\\n. {(\\\\N=n\\, Fac_'proc, \\\\R = fac n\\,{})})\n \\ \\\\N=n\\ IF \\N = 0 THEN \\R :== 1\n ELSE \\R :== CALL Fac(\\N - 1);; \\R :== \\N * \\R FI \\\\R = fac n\\\"\n apply vcg\n apply simp\n done\nqed\n\ntext {* To avoid retyping of potentially large pre and postconditions in \nthe previous proof we can use the casual term abbreviations of the Isar \nlanguage.\n*}\n\nlemma (in Fac_impl)\n shows \"\\n. \\\\\\\\N=n\\ \\R :== PROC Fac(\\N) \\\\R = fac n\\\" \n (is \"\\n. \\\\(?Pre n) ?Fac (?Post n)\")\nproof (hoare_rule HoarePartial.ProcRec1)\n have Fac_spec: \"\\n. \\,(\\n. {(?Pre n, Fac_'proc, ?Post n,{})})\n \\(?Pre n) ?Fac (?Post n)\"\n apply (rule allI)\n apply (rule hoarep.Asm) \n by auto\n show \"\\n. \\,(\\n. {(?Pre n, Fac_'proc, ?Post n,{})})\n \\ (?Pre n) IF \\N = 0 THEN \\R :== 1\n ELSE \\R :== CALL Fac(\\N - 1);; \\R :== \\N * \\R FI (?Post n)\"\n apply vcg\n apply simp\n done\nqed\n\ntext {* The previous proof pattern has still some kind of inconvenience.\nThe augmented context is always printed in the proof state. That can\nmess up the state, especially if we have large specifications. This may\nbe annoying if we want to develop single step or structured proofs. In this\ncase it can be a good idea to introduce a new variable for the augmented\ncontext.\n*}\n\nlemma (in Fac_impl) Fac_spec:\n shows \"\\n. \\\\\\\\N=n\\ \\R :== PROC Fac(\\N) \\\\R = fac n\\\" \n (is \"\\n. \\\\(?Pre n) ?Fac (?Post n)\")\nproof (hoare_rule HoarePartial.ProcRec1)\n def \"\\'\"==\"(\\n. {(?Pre n, Fac_'proc, ?Post n,{}::('a, 'b) vars_scheme set)})\"\n have Fac_spec: \"\\n. \\,\\'\\(?Pre n) ?Fac (?Post n)\"\n by (unfold \\'_def, rule allI, rule hoarep.Asm) auto\n txt {* We have to name the fact @{text \"Fac_spec\"}, so that the vcg can\n use the specification for the recursive call, since it cannot infer it\n from the opaque @{term \"\\'\"}. *}\n show \"\\\\. \\,\\'\\ (?Pre \\) IF \\N = 0 THEN \\R :== 1\n ELSE \\R :== CALL Fac(\\N - 1);; \\R :== \\N * \\R FI (?Post \\)\"\n apply vcg\n apply simp\n done\nqed\n\ntext {* There are different rules available to prove procedure calls,\ndepending on the kind of postcondition and whether or not the\nprocedure is recursive or even mutually recursive. \nSee for example @{thm [source] HoarePartial.ProcRec1}, \n@{thm [source] HoarePartial.ProcNoRec1}. \nThey are all derived from the most general rule\n@{thm [source] HoarePartial.ProcRec}. \nAll of them have some side-condition concerning definedness of the procedure. \nThey can be\nsolved in a uniform fashion. Thats why we have created the method \n@{text \"hoare_rule\"}, which behaves like the method @{text \"rule\"} but automatically\ntries to solve the side-conditions.\n*}\n\nsubsubsection {* Odd and Even *}\n\ntext {* Odd and even are defined mutually recursive here. In the \n@{text \"procedures\"} command we conjoin both definitions with @{text \"and\"}.\n*}\n\nprocedures \n odd(N | A) = \"IF \\N=0 THEN \\A:==0\n ELSE IF \\N=1 THEN CALL even (\\N - 1,\\A)\n ELSE CALL odd (\\N - 2,\\A)\n FI\n FI\"\n\n \nand\n even(N | A) = \"IF \\N=0 THEN \\A:==1\n ELSE IF \\N=1 THEN CALL odd (\\N - 1,\\A)\n ELSE CALL even (\\N - 2,\\A)\n FI\n FI\"\n\nprint_theorems\nthm odd_body.odd_body_def\nthm even_body.even_body_def\nprint_locale odd_even_clique \n\n\ntext {* To prove the procedure calls to @{term \"odd\"} respectively \n@{term \"even\"} correct we first derive a rule to justify that we\ncan assume both specifications to verify the bodies. This rule can\nbe derived from the general @{thm [source] HoarePartial.ProcRec} rule. An ML function does \nthis work:\n*}\n\nML {* ML_Thms.bind_thm (\"ProcRec2\", Hoare.gen_proc_rec @{context} Hoare.Partial 2) *}\n\n\nlemma (in odd_even_clique)\n shows odd_spec: \"\\n. \\\\\\\\N=n\\ \\A :== PROC odd(\\N) \n \\(\\b. n = 2 * b + \\A) \\ \\A < 2 \\\" (is ?P1)\n and even_spec: \"\\n. \\\\\\\\N=n\\ \\A :== PROC even(\\N)\n \\(\\b. n + 1 = 2 * b + \\A) \\ \\A < 2 \\\" (is ?P2)\nproof -\n have \"?P1 \\ ?P2\"\n apply (hoare_rule ProcRec2)\n apply vcg\n apply clarsimp\n apply (rule_tac x=\"b + 1\" in exI)\n apply arith\n apply vcg\n apply clarsimp\n apply arith\n done\n thus \"?P1\" \"?P2\"\n by iprover+\nqed\n\nsubsection {*Expressions With Side Effects *}\n\n\ntext {* \\texttt{R := N++ + M++} *}\nlemma \"\\\\ \\True\\ \n \\N \\ n. \\N :== \\N + 1 \\ \n \\M \\ m. \\M :== \\M + 1 \\\n \\R :== n + m\n \\\\R = \\N + \\M - 2\\\"\napply vcg\napply simp\ndone\n\ntext {*\\texttt{R := Fac (N) + Fac (M)} *}\nlemma (in Fac_impl) shows \n \"\\\\ \\True\\ \n CALL Fac(\\N) \\ n. CALL Fac(\\M) \\ m. \n \\R :== n + m\n \\\\R = fac \\N + fac \\M\\\"\napply vcg\ndone\n\n\ntext {*\\texttt{ R := (Fac(Fac (N)))}*}\nlemma (in Fac_impl) shows \n \"\\\\ \\True\\ \n CALL Fac(\\N) \\ n. CALL Fac(n) \\ m. \n \\R :== m\n \\\\R = fac (fac \\N)\\\"\napply vcg\ndone\n\n\nsubsection {* Global Variables and Heap *}\n\n\ntext {*\nNow we define and verify some procedures on heap-lists. We consider\nlist structures consisting of two fields, a content element @{term \"cont\"} and\na reference to the next list element @{term \"next\"}. We model this by the \nfollowing state space where every field has its own heap.\n*}\n\nrecord globals_list = \n next_' :: \"ref \\ ref\"\n cont_' :: \"ref \\ nat\"\n\nrecord 'g list_vars = \"'g state\" +\n p_' :: \"ref\"\n q_' :: \"ref\"\n r_' :: \"ref\"\n root_' :: \"ref\"\n tmp_' :: \"ref\"\n\ntext {* Updates to global components inside a procedure will\nalways be propagated to the caller. This is implicitly done by the\nparameter passing syntax translations. The record containing the global variables must begin with the prefix \"globals\".\n*}\n\ntext {* We first define an append function on lists. It takes two \nreferences as parameters. It appends the list referred to by the first\nparameter with the list referred to by the second parameter, and returns\nthe result right into the first parameter.\n*}\n\nprocedures\n append(p,q|p) = \n \"IF \\p=Null THEN \\p :== \\q ELSE \\p \\\\next:== CALL append(\\p\\\\next,\\q) FI\"\n\n(*\n append_spec: \n \"\\\\ Ps Qs. \n \\\\ \\\\. List \\p \\next Ps \\ List \\q \\next Qs \\ set Ps \\ set Qs = {}\\\n \\p :== PROC append(\\p,\\q) \n \\List \\p \\next (Ps@Qs) \\ (\\x. x\\set Ps \\ \\next x = \\<^bsup>\\\\<^esup>next x)\\\"\n\n append_modifies:\n \"\\\\. \\\\ {\\} \\p :== PROC append(\\p,\\q){t. t may_only_modify_globals \\ in [next]}\"\n*)\n\ncontext append_impl\nbegin\ndeclare [[hoare_use_call_tr' = false]]\nterm \"CALL append(\\p,\\q,\\p\\\\next)\"\ndeclare [[hoare_use_call_tr' = true]]\nend\ntext {* Below we give two specifications this time.\nOne captures the functional behaviour and focuses on the\nentities that are potentially modified by the procedure, the other one\nis a pure frame condition.\nThe list in the modifies clause has to list all global state components that\nmay be changed by the procedure. Note that we know from the modifies clause\nthat the @{term cont} parts of the lists will not be changed. Also a small\nside note on the syntax. We use ordinary brackets in the postcondition\nof the modifies clause, and also the state components do not carry the\nacute, because we explicitly note the state @{term t} here. \n\nThe functional specification now introduces two logical variables besides the\nstate space variable @{term \"\\\"}, namely @{term \"Ps\"} and @{term \"Qs\"}.\nThey are universally quantified and range over both the pre and the postcondition, so \nthat we are able to properly instantiate the specification\nduring the proofs. The syntax @{text \"\\\\. \\\\\"} is a shorthand to fix the current \nstate: @{text \"{s. \\ = s \\}\"}. \n*}\n\nlemma (in append_impl) append_spec:\n shows \"\\\\ Ps Qs. \\\\ \n \\\\. List \\p \\next Ps \\ List \\q \\next Qs \\ set Ps \\ set Qs = {}\\\n \\p :== PROC append(\\p,\\q) \n \\List \\p \\next (Ps@Qs) \\ (\\x. x\\set Ps \\ \\next x = \\<^bsup>\\\\<^esup>next x)\\\"\n apply (hoare_rule HoarePartial.ProcRec1)\n apply vcg\n apply fastforce\n done\n\n\ntext {* The modifies clause is equal to a proper record update specification\nof the following form. \n*}\n\n\nlemma \"{t. t may_only_modify_globals Z in [next]} \n = \n {t. \\next. globals t=next_'_update (\\_. next) (globals Z)}\"\n apply (unfold mex_def meq_def)\n apply (simp)\n done\n\ntext {* If the verification condition generator works on a procedure call\nit checks whether it can find a modified clause in the context. If one\nis present the procedure call is simplified before the Hoare rule \n@{thm [source] HoarePartial.ProcSpec} is applied. Simplification of the procedure call means,\nthat the ``copy back'' of the global components is simplified. Only those\ncomponents that occur in the modifies clause will actually be copied back.\nThis simplification is justified by the rule @{thm [source] HoarePartial.ProcModifyReturn}. \nSo after this simplification all global components that do not appear in\nthe modifies clause will be treated as local variables. \n*}\n\ntext {* You can study the effect of the modifies clause on the following two\nexamples, where we want to prove that @{term \"append\"} does not change\nthe @{term \"cont\"} part of the heap.\n*}\n\nlemma (in append_impl)\n shows \"\\\\ \\\\p=Null \\ \\cont=c\\ \\p :== CALL append(\\p,Null) \\\\cont=c\\\" \n apply vcg\n oops\n\ntext {* To prove the frame condition, \nwe have to tell the verification condition generator to use only the\nmodifies clauses and not to search for functional specifications by \nthe parameter @{text \"spec=modifies\"} It will also try to solve the \nverification conditions automatically.\n*}\n\nlemma (in append_impl) append_modifies: \n shows\n \"\\\\. \\\\ {\\} \\p :== PROC append(\\p,\\q){t. t may_only_modify_globals \\ in [next]}\"\n apply (hoare_rule HoarePartial.ProcRec1)\n apply (vcg spec=modifies)\n done\n\n\nlemma (in append_impl)\n shows \"\\\\ \\\\p=Null \\ \\cont=c\\ \\p\\\\next :== CALL append(\\p,Null) \\\\cont=c\\\"\n apply vcg\n apply simp\n done\n\ntext {*\nOf course we could add the modifies clause to the functional specification as \nwell. But separating both has the advantage that we split up the verification\nwork. We can make use of the modifies clause before we apply the\nfunctional specification in a fully automatic fashion.\n*}\n \n\ntext {* To verify the body of @{term \"append\"} we do not need the modifies\nclause, since the specification does not talk about @{term \"cont\"} at all, and\nwe don't access @{term \"cont\"} inside the body. This may be different for \nmore complex procedures.\n*}\n\ntext {* \nTo prove that a procedure respects the modifies clause, we only need\nthe modifies clauses of the procedures called in the body. We do not need\nthe functional specifications. So we can always prove the modifies\nclause without functional specifications, but me may need the modifies\nclause to prove the functional specifications.\n*}\n\n\n\n\n\n\n\n \nsubsubsection {*Insertion Sort*}\n\nprimrec sorted:: \"('a \\ 'a \\ bool) \\ 'a list \\ bool\"\nwhere\n\"sorted le [] = True\" |\n\"sorted le (x#xs) = ((\\y\\set xs. le x y) \\ sorted le xs)\"\n\n\n \nprocedures\n insert(r,p | p) =\n \"IF \\r=Null THEN SKIP\n ELSE IF \\p=Null THEN \\p :== \\r;; \\p\\\\next :== Null\n ELSE IF \\r\\\\cont \\ \\p\\\\cont \n THEN \\r\\\\next :== \\p;; \\p:==\\r\n ELSE \\p\\\\next :== CALL insert(\\r,\\p\\\\next)\n FI\n FI\n FI\"\n\n\ntext {*\nIn the postcondition of the functional specification there is a small but \nimportant subtlety. Whenever we talk about the @{term \"cont\"} part we refer to \nthe one of the pre-state, even in the conclusion of the implication.\nThe reason is, that we have separated out, that @{term \"cont\"} is not modified\nby the procedure, to the modifies clause. So whenever we talk about unmodified\nparts in the postcondition we have to use the pre-state part, or explicitly\nstate an equality in the postcondition.\nThe reason is simple. If the postcondition would talk about @{text \"\\cont\"}\ninstead of @{text \"\\<^bsup>\\\\<^esup>cont\"}, we get a new instance of @{text \"cont\"} during\nverification and the postcondition would only state something about this\nnew instance. But as the verification condition generator uses the\nmodifies clause the caller of @{text \"insert\"} instead still has the\nold @{text \"cont\"} after the call. Thats the very reason for the modifies clause.\nSo the caller and the specification will simply talk about two different things,\nwithout being able to relate them (unless an explicit equality is added to\nthe specification). \n*}\n\nlemma (in insert_impl) insert_modifies:\n \"\\\\. \\\\ {\\} \\p :== PROC insert(\\r,\\p){t. t may_only_modify_globals \\ in [next]}\"\napply (hoare_rule HoarePartial.ProcRec1)\napply (vcg spec=modifies)\ndone\n\n\nlemma (in insert_impl) insert_spec:\n \"\\\\ Ps . \\\\ \\\\. List \\p \\next Ps \\ sorted (op \\) (map \\cont Ps) \\ \n \\r \\ Null \\ \\r \\ set Ps\\ \n \\p :== PROC insert(\\r,\\p) \n \\\\Qs. List \\p \\next Qs \\ sorted (op \\) (map \\<^bsup>\\\\<^esup>cont Qs) \\\n set Qs = insert \\<^bsup>\\\\<^esup>r (set Ps) \\\n (\\x. x \\ set Qs \\ \\next x = \\<^bsup>\\\\<^esup>next x)\\\"\n\napply (hoare_rule HoarePartial.ProcRec1)\napply vcg\napply (intro conjI impI)\napply fastforce\napply fastforce\napply fastforce\napply (clarsimp) \napply force\ndone\n\nprocedures\n insertSort(p | p) =\n \"\\r:==Null;;\n WHILE (\\p \\ Null) DO\n \\q :== \\p;;\n \\p :== \\p\\\\next;;\n \\r :== CALL insert(\\q,\\r)\n OD;;\n \\p:==\\r\"\n\n\n\n\nlemma (in insertSort_impl) insertSort_modifies: \n shows\n \"\\\\. \\\\ {\\} \\p :== PROC insertSort(\\p)\n {t. t may_only_modify_globals \\ in [next]}\"\napply (hoare_rule HoarePartial.ProcRec1)\napply (vcg spec=modifies)\ndone\n\n\ntext {* Insertion sort is not implemented recursively here but with a while\nloop. Note that the while loop is not annotated with an invariant in the\nprocedure definition. The invariant only comes into play during verification.\nTherefore we will annotate the body during the proof with the\nrule @{thm [source] HoarePartial.annotateI}.\n*}\n\n\nlemma (in insertSort_impl) insertSort_body_spec:\n shows \"\\\\ Ps. \\,\\\\ \\\\. List \\p \\next Ps \\ \n \\p :== PROC insertSort(\\p)\n \\\\Qs. List \\p \\next Qs \\ sorted (op \\) (map \\<^bsup>\\\\<^esup>cont Qs) \\\n set Qs = set Ps\\\"\n apply (hoare_rule HoarePartial.ProcRec1) \n apply (hoare_rule anno= \n \"\\r :== Null;;\n WHILE \\p \\ Null\n INV \\\\Qs Rs. List \\p \\next Qs \\ List \\r \\next Rs \\ \n set Qs \\ set Rs = {} \\\n sorted (op \\) (map \\cont Rs) \\ set Qs \\ set Rs = set Ps \\\n \\cont = \\<^bsup>\\\\<^esup>cont \\\n DO \\q :== \\p;; \\p :== \\p\\\\next;; \\r :== CALL insert(\\q,\\r) OD;;\n \\p :== \\r\" in HoarePartial.annotateI)\n apply vcg\n apply fastforce\n prefer 2\n apply fastforce\n apply (clarsimp)\n apply (rule_tac x=ps in exI)\n apply (intro conjI)\n apply (rule heap_eq_ListI1)\n apply assumption\n apply clarsimp\n apply (subgoal_tac \"x\\p \\ x \\ set Rs\")\n apply auto\n done\n\nsubsubsection \"Memory Allocation and Deallocation\"\n\ntext {* The basic idea of memory management is to keep a list of allocated\nreferences in the state space. Allocation of a new reference adds a\nnew reference to the list deallocation removes a reference. Moreover\nwe keep a counter \"free\" for the free memory.\n*}\n\nrecord globals_list_alloc = globals_list +\n alloc_'::\"ref list\"\n free_'::nat \n\nrecord 'g list_vars' = \"'g list_vars\" +\n i_'::nat\n first_'::ref\n\n\ndefinition \"sz = (2::nat)\"\n\ntext {* Restrict locale @{text hoare} to the required type. *}\n\nlocale hoare_ex =\n hoare \\ for \\ :: \"'c ~=> (('a globals_list_alloc_scheme, 'b) list_vars'_scheme, 'c, 'd) com\"\n\nlemma (in hoare_ex)\n \"\\\\ \\\\i = 0 \\ \\first = Null \\ n*sz \\ \\free\\\n WHILE \\i < n \n INV \\\\Ps. List \\first \\next Ps \\ length Ps = \\i \\ \\i \\ n \\ \n set Ps \\ set \\alloc \\ (n - \\i)*sz \\ \\free\\\n DO\n \\p :== NEW sz [\\cont:==0,\\next:== Null];;\n \\p\\\\next :== \\first;;\n \\first :== \\p;;\n \\i :== \\i+ 1 \n OD\n \\\\Ps. List \\first \\next Ps \\ length Ps = n \\ set Ps \\ set \\alloc\\\"\n\napply (vcg)\napply simp\napply clarsimp\napply (rule conjI)\napply clarsimp\napply (rule_tac x=\"new (set alloc)#Ps\" in exI)\napply clarsimp\napply (rule conjI)\napply fastforce\napply (simp add: sz_def)\napply (simp add: sz_def)\napply fastforce\ndone\n\n\nlemma (in hoare_ex)\n \"\\\\ \\\\i = 0 \\ \\first = Null \\ n*sz \\ \\free\\\n WHILE \\i < n \n INV \\\\Ps. List \\first \\next Ps \\ length Ps = \\i \\ \\i \\ n \\ \n set Ps \\ set \\alloc \\ (n - \\i)*sz \\ \\free\\\n DO\n \\p :== NNEW sz [\\cont:==0,\\next:== Null];;\n \\p\\\\next :== \\first;;\n \\first :== \\p;;\n \\i :== \\i+ 1 \n OD\n \\\\Ps. List \\first \\next Ps \\ length Ps = n \\ set Ps \\ set \\alloc\\\"\n\napply (vcg)\napply simp\napply clarsimp\napply (rule conjI)\napply clarsimp\napply (rule_tac x=\"new (set alloc)#Ps\" in exI)\napply clarsimp\napply (rule conjI)\napply fastforce\napply (simp add: sz_def)\napply (simp add: sz_def)\napply fastforce\ndone\n\nsubsection {* Fault Avoiding Semantics *}\n\ntext {*\nIf we want to ensure that no runtime errors occur we can insert guards into\nthe code. We will not be able to prove any nontrivial Hoare triple \nabout code with guards, if we cannot show that the guards will never fail.\nA trivial hoare triple is one with an empty precondition. \n*}\n\n\nlemma \"\\\\ \\True\\ \\\\p\\Null\\\\ \\p\\\\next :== \\p \\True\\\"\napply vcg\noops\n\nlemma \"\\\\ {} \\\\p\\Null\\\\ \\p\\\\next :== \\p \\True\\\"\napply vcg\ndone\n\ntext {* Let us consider this small program that reverts a list. At\nfirst without guards. \n*}\nlemma (in hoare_ex) rev_strip:\n \"\\\\ \\List \\p \\next Ps \\ List \\q \\next Qs \\ set Ps \\ set Qs = {} \\\n set Ps \\ set \\alloc \\ set Qs \\ set \\alloc\\\n WHILE \\p \\ Null\n INV \\\\ps qs. List \\p \\next ps \\ List \\q \\next qs \\ set ps \\ set qs = {} \\\n rev ps @ qs = rev Ps @ Qs \\ \n set ps \\ set \\alloc \\ set qs \\ set \\alloc\\\n DO \\r :== \\p;; \n \\p :== \\p\\ \\next;; \n \\r\\\\next :== \\q;; \n \\q :== \\r OD\n \\List \\q \\next (rev Ps @ Qs) \\ set Ps\\ set \\alloc \\ set Qs \\ set \\alloc\\\"\napply (vcg)\napply fastforce+\ndone\n\ntext {* If we want to ensure that we do not dereference @{term \"Null\"} or\naccess unallocated memory, we have to add some guards.\n*}\n\nlocale hoare_ex_guard =\n hoare \\ for \\ :: \"'c ~=> (('a globals_list_alloc_scheme, 'b) list_vars'_scheme, 'c, bool) com\"\n\nlemma \n (in hoare_ex_guard)\n \"\\\\ \\List \\p \\next Ps \\ List \\q \\next Qs \\ set Ps \\ set Qs = {} \\\n set Ps \\ set \\alloc \\ set Qs \\ set \\alloc\\\n WHILE \\p \\ Null\n INV \\\\ps qs. List \\p \\next ps \\ List \\q \\next qs \\ set ps \\ set qs = {} \\\n rev ps @ qs = rev Ps @ Qs \\ \n set ps \\ set \\alloc \\ set qs \\ set \\alloc\\\n DO \\r :== \\p;; \n \\\\p\\Null \\ \\p\\set \\alloc\\\\ \\p :== \\p\\ \\next;; \n \\\\r\\Null \\ \\r\\set \\alloc\\\\ \\r\\\\next :== \\q;; \n \\q :== \\r OD\n \\List \\q \\next (rev Ps @ Qs) \\ set Ps \\ set \\alloc \\ set Qs \\ set \\alloc\\\"\napply (vcg)\napply fastforce+\ndone\n\n\ntext {* We can also just prove that no faults will occur, by giving the\ntrivial postcondition.\n*}\nlemma (in hoare_ex_guard) rev_noFault: \n \"\\\\ \\List \\p \\next Ps \\ List \\q \\next Qs \\ set Ps \\ set Qs = {} \\\n set Ps \\ set \\alloc \\ set Qs \\ set \\alloc\\\n WHILE \\p \\ Null\n INV \\\\ps qs. List \\p \\next ps \\ List \\q \\next qs \\ set ps \\ set qs = {} \\\n rev ps @ qs = rev Ps @ Qs \\ \n set ps \\ set \\alloc \\ set qs \\ set \\alloc\\\n DO \\r :== \\p;; \n \\\\p\\Null \\ \\p\\set \\alloc\\\\ \\p :== \\p\\ \\next;; \n \\\\r\\Null \\ \\r\\set \\alloc\\\\ \\r\\\\next :== \\q;; \n \\q :== \\r OD\n UNIV,UNIV\"\napply (vcg)\napply fastforce+\ndone\n\nlemma (in hoare_ex_guard) rev_moduloGuards: \n \"\\\\\\<^bsub>\/{True}\\<^esub> \\List \\p \\next Ps \\ List \\q \\next Qs \\ set Ps \\ set Qs = {} \\\n set Ps \\ set \\alloc \\ set Qs \\ set \\alloc\\\n WHILE \\p \\ Null\n INV \\\\ps qs. List \\p \\next ps \\ List \\q \\next qs \\ set ps \\ set qs = {} \\\n rev ps @ qs = rev Ps @ Qs \\ \n set ps \\ set \\alloc \\ set qs \\ set \\alloc\\\n DO \\r :== \\p;; \n \\\\p\\Null \\ \\p\\set \\alloc\\\\ \\ \\p :== \\p\\ \\next;; \n \\\\r\\Null \\ \\r\\set \\alloc\\\\ \\ \\r\\\\next :== \\q;; \n \\q :== \\r OD\n \\List \\q \\next (rev Ps @ Qs) \\ set Ps \\ set \\alloc \\ set Qs \\ set \\alloc\\\"\napply vcg\napply fastforce+\ndone\n\n\n\n\nlemma CombineStrip': \n assumes deriv: \"\\,\\\\\\<^bsub>\/F\\<^esub> P c' Q,A\"\n assumes deriv_strip: \"\\,\\\\\\<^bsub>\/{}\\<^esub> P c'' UNIV,UNIV\"\n assumes c'': \"c''= mark_guards False (strip_guards (-F) c')\"\n assumes c: \"c = mark_guards False c'\"\n shows \"\\,\\\\\\<^bsub>\/{}\\<^esub> P c Q,A\"\nproof -\n from deriv_strip [simplified c'']\n have \"\\,\\\\ P (strip_guards (- F) c') UNIV,UNIV\"\n by (rule HoarePartialProps.MarkGuardsD)\n with deriv \n have \"\\,\\\\ P c' Q,A\"\n by (rule HoarePartialProps.CombineStrip)\n hence \"\\,\\\\ P mark_guards False c' Q,A\"\n by (rule HoarePartialProps.MarkGuardsI)\n thus ?thesis\n by (simp add: c)\nqed\n\n\ntext {* We can then combine the prove that no fault will occur with the\nfunctional proof of the programme without guards to get the full prove by\nthe rule @{thm HoarePartialProps.CombineStrip}\n*}\n\n\nlemma \n (in hoare_ex_guard)\n \"\\\\ \\List \\p \\next Ps \\ List \\q \\next Qs \\ set Ps \\ set Qs = {} \\\n set Ps \\ set \\alloc \\ set Qs \\ set \\alloc\\\n WHILE \\p \\ Null\n INV \\\\ps qs. List \\p \\next ps \\ List \\q \\next qs \\ set ps \\ set qs = {} \\\n rev ps @ qs = rev Ps @ Qs \\ \n set ps \\ set \\alloc \\ set qs \\ set \\alloc\\\n DO \\r :== \\p;; \n \\\\p\\Null \\ \\p\\set \\alloc\\\\ \\p :== \\p\\ \\next;; \n \\\\r\\Null \\ \\r\\set \\alloc\\\\ \\r\\\\next :== \\q;; \n \\q :== \\r OD\n \\List \\q \\next (rev Ps @ Qs) \\ set Ps \\ set \\alloc \\ set Qs \\ set \\alloc\\\"\n\napply (rule CombineStrip' [OF rev_moduloGuards rev_noFault])\napply simp\napply simp\ndone\n\n\ntext {* In the previous example the effort to split up the prove did not\nreally pay off. But when we think of programs with a lot of guards and\ncomplicated specifications it may be better to first focus on a prove without\nthe messy guards. Maybe it is possible to automate the no fault proofs so\nthat it suffices to focus on the stripped program. \n*}\n\n\ntext {*\nThe purpose of guards is to watch for faults that can occur during \nevaluation of expressions. In the example before we watched for null pointer\ndereferencing or memory faults. We can also look for array index bounds or\ndivision by zero. As the condition of a while loop is evaluated in each\niteration we cannot just add a guard before the while loop. Instead we need\na special guard for the condition.\nExample: @{term \"WHILE \\\\p\\Null\\\\ \\p\\\\next\\Null DO SKIP OD\"}\n*}\n\nsubsection {* Circular Lists *}\ndefinition\n distPath :: \"ref \\ (ref \\ ref) \\ ref \\ ref list \\ bool\" where\n \"distPath x next y as = (Path x next y as \\ distinct as)\"\n\nlemma neq_dP: \"\\p \\ q; Path p h q Ps; distinct Ps\\ \\\n \\Qs. p\\Null \\ Ps = p#Qs \\ p \\ set Qs\"\nby (cases Ps, auto)\n\nlemma circular_list_rev_I:\n \"\\\\ \\\\root = r \\ distPath \\root \\next \\root (r#Ps)\\\n \\p :== \\root;; \\q :== \\root\\\\next;;\n WHILE \\q \\ \\root\n INV \\\\ ps qs. distPath \\p \\next \\root ps \\ distPath \\q \\next \\root qs \\ \n \\root = r \\ r\\Null \\ r \\ set Ps \\ set ps \\ set qs = {} \\ \n Ps = (rev ps) @ qs \\\n DO \\tmp :== \\q;; \\q :== \\q\\\\next;; \\tmp\\\\next :== \\p;; \\p:==\\tmp OD;;\n \\root\\\\next :== \\p\n \\\\root = r \\ distPath \\root \\next \\root (r#rev Ps)\\\"\napply (simp only:distPath_def)\napply vcg\napply (rule_tac x=\"[]\" in exI)\napply fastforce\napply clarsimp\napply (drule (2) neq_dP)\napply (rule_tac x=\"q # ps\" in exI)\napply clarsimp\napply fastforce\ndone\n\n\n\nlemma path_is_list:\"\\a next b. \\Path b next a Ps ; a \\ set Ps; a\\Null\\ \n\\ List b (next(a := Null)) (Ps @ [a])\"\napply (induct Ps)\napply (auto simp add:fun_upd_apply)\ndone\n\ntext {*\nThe simple algorithm for acyclic list reversal, with modified\nannotations, works for cyclic lists as well.: \n*}\n\nlemma circular_list_rev_II:\n \"\\\\\n \\\\p = r \\ distPath \\p \\next \\p (r#Ps)\\\n\\q:==Null;;\nWHILE \\p \\ Null\nINV\n \\ ((\\q = Null) \\ (\\ps. distPath \\p \\next r ps \\ ps = r#Ps)) \\\n ((\\q \\ Null) \\ (\\ps qs. distPath \\q \\next r qs \\ List \\p \\next ps \\\n set ps \\ set qs = {} \\ rev qs @ ps = Ps@[r])) \\\n \\ (\\p = Null \\ \\q = Null \\ r = Null )\n \\\nDO\n \\tmp :== \\p;; \\p :== \\p\\\\next;; \\tmp\\\\next :== \\q;; \\q:==\\tmp\nOD\n \\\\q = r \\ distPath \\q \\next \\q (r # rev Ps)\\\"\n\napply (simp only:distPath_def)\napply vcg\napply clarsimp\napply clarsimp\napply (case_tac \"(q = Null)\")\napply (fastforce intro: path_is_list)\napply clarify\napply (rule_tac x=\"psa\" in exI)\napply (rule_tac x=\" p # qs\" in exI) \napply force\napply fastforce\ndone\n\ntext{* Although the above algorithm is more succinct, its invariant\nlooks more involved. The reason for the case distinction on @{term q}\nis due to the fact that during execution, the pointer variables can\npoint to either cyclic or acyclic structures.\n*}\n\ntext {*\nWhen working on lists, its sometimes better to remove\n@{thm[source] fun_upd_apply} from the simpset, and instead include @{thm[source] fun_upd_same} and @{thm[source] fun_upd_other} to\nthe simpset\n*}\n\n(*\ndeclare fun_upd_apply[simp del]fun_upd_same[simp] fun_upd_other[simp]\n*)\n\n\nlemma \"\\\\ {\\}\n \\I :== \\M;; \n ANNO \\. \\\\. \\I = \\<^bsup>\\\\<^esup>M\\\n \\M :== \\N;; \\N :== \\I \n \\\\M = \\<^bsup>\\\\<^esup>N \\ \\N = \\<^bsup>\\\\<^esup>I\\\n \\\\M = \\<^bsup>\\\\<^esup>N \\ \\N = \\<^bsup>\\\\<^esup>M\\\"\napply vcg\napply auto\ndone\n\n\nlemma \"\\\\ ({\\} \\ \\\\M = 0 \\ \\S = 0\\)\n (ANNO \\. ({\\} \\ \\\\A=\\<^bsup>\\\\<^esup>A \\ \\I=\\<^bsup>\\\\<^esup>I \\ \\M=0 \\ \\S=0\\)\n WHILE \\M \\ \\A\n INV \\\\S = \\M * \\I \\ \\A=\\<^bsup>\\\\<^esup>A \\ \\I=\\<^bsup>\\\\<^esup>I\\\n DO \\S :== \\S + \\I;; \\M :== \\M + 1 OD\n \\\\S = \\<^bsup>\\\\<^esup>A * \\<^bsup>\\\\<^esup>I\\)\n \\\\S = \\<^bsup>\\\\<^esup>A * \\<^bsup>\\\\<^esup>I\\\"\napply vcg_step\napply vcg_step\napply simp\napply vcg_step\napply vcg_step\napply simp\napply vcg\napply simp\napply simp\napply vcg_step\napply auto\ndone\n\ntext {* Instead of annotations one can also directly use previously proven lemmas.*}\nlemma foo_lemma: \"\\n m. \\\\ \\\\N = n \\ \\M = m\\ \\N :== \\N + 1;; \\M :== \\M + 1 \n \\\\N = n + 1 \\ \\M = m + 1\\\"\n by vcg\n\n\nlemma \"\\\\ \\\\N = n \\ \\M = m\\ LEMMA foo_lemma \n \\N :== \\N + 1;; \\M :== \\M + 1\n END;; \n \\N :== \\N + 1 \n \\\\N = n + 2 \\ \\M = m + 1\\\"\n apply vcg\n apply simp\n done\n\nlemma \"\\\\ \\\\N = n \\ \\M = m\\ \n LEMMA foo_lemma \n \\N :== \\N + 1;; \\M :== \\M + 1\n END;;\n LEMMA foo_lemma \n \\N :== \\N + 1;; \\M :== \\M + 1\n END\n \\\\N = n + 2 \\ \\M = m + 2\\\"\n apply vcg\n apply simp\n done\n\nlemma \"\\\\ \\\\N = n \\ \\M = m\\ \n \\N :== \\N + 1;; \\M :== \\M + 1;;\n \\N :== \\N + 1;; \\M :== \\M + 1\n \\\\N = n + 2 \\ \\M = m + 2\\\"\n apply (hoare_rule anno= \n \"LEMMA foo_lemma \n \\N :== \\N + 1;; \\M :== \\M + 1\n END;;\n LEMMA foo_lemma \n \\N :== \\N + 1;; \\M :== \\M + 1\n END\"\n in HoarePartial.annotate_normI)\n apply vcg\n apply simp\n done\n\ntext {* Just some test on marked, guards *}\nlemma \"\\\\\\True\\ WHILE \\P \\N \\\\, \\Q \\M\\#, \\R \\N\\\\ \\N < \\M \n INV \\\\N < 2\\ DO\n \\N :== \\M\n OD \n \\hard\\\"\napply vcg\noops\n\nlemma \"\\\\\\<^bsub>\/{True}\\<^esub> \\True\\ WHILE \\P \\N \\\\, \\Q \\M\\#, \\R \\N\\\\ \\N < \\M \n INV \\\\N < 2\\ DO\n \\N :== \\M\n OD \n \\hard\\\"\napply vcg\noops\n\n\n\nterm \"\\\\\\<^bsub>\/{True}\\<^esub> \\True\\ WHILE\\<^sub>g \\N < \\Arr!i\n FIX Z.\n INV \\\\N < 2\\ \n \n DO\n \\N :== \\M\n OD \n \\hard\\\"\n\nlemma \"\\\\\\<^bsub>\/{True}\\<^esub> \\True\\ WHILE\\<^sub>g \\N < \\Arr!i\n FIX Z.\n INV \\\\N < 2\\ \n VAR arbitrary\n DO\n \\N :== \\M\n OD \n \\hard\\\"\napply vcg\noops\n\nlemma \"\\\\\\<^bsub>\/{True}\\<^esub> \\True\\ WHILE \\P \\N \\\\, \\Q \\M\\#, \\R \\N\\\\ \\N < \\M \n FIX Z.\n INV \\\\N < 2\\ \n VAR arbitrary\n DO\n \\N :== \\M\n OD \n \\hard\\\"\napply vcg\noops\n\nend ","avg_line_length":39.9894249835,"max_line_length":216,"alphanum_fraction":0.6227026312} {"size":28730,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"theory Automation\nimports ProofSearchPredicates \"HOL-Eisbach.Eisbach_Tools\"\nbegin\n\nmethod iIntro = \n (match conclusion in \"upred_holds _\" \\ \\rule upred_wand_holdsI | subst upred_holds_entails\\)?,((rule upred_wandI)+)?\n\nmethod remove_emp = (simp_all only: upred_sep_assoc_eq emp_rule)?\n\nnamed_theorems iris_simp\nnamed_theorems inG_axioms\n\ndeclare upred_sep_assoc_eq[iris_simp]\ndeclare emp_rule[iris_simp]\n\nmethod iris_simp declares iris_simp = \n (simp_all add: iris_simp)?\n\nmethod log_prog_solver declares log_prog_rule =\n fast intro: log_prog_rule inG_axioms\n(* | slow intro: log_prog_rule *)\n(* | best intro: log_prog_rule *)\n(*| force intro: log_prog_rule\n| blast 5 intro: log_prog_rule*)\n\nmethod is_entailment = match conclusion in \"_\\_\" \\ succeed\n\ntext \\A simple attribute to convert \\<^const>\\upred_holds\\ predicates into entailments.\\\nML \\ val to_entailment: attribute context_parser = let \n fun is_upred_holds (Const(\\<^const_name>\\Trueprop\\,_)$(Const(\\<^const_name>\\upred_holds\\,_)$_)) = true\n | is_upred_holds _ = false\n fun match_upred_holds thm = is_upred_holds (Thm.concl_of thm)\n\n fun is_wand_term (Const(\\<^const_name>\\upred_wand\\,_)$_$_) = true\n | is_wand_term _ = false\n\n fun contains_wand thm = Thm.concl_of thm\n |> dest_comb |> snd (* Strip Trueprop*)\n |> strip_comb |> snd |> tl |> hd (* Strip entails*)\n |> is_wand_term\n\n fun contains_emp (Const(\\<^const_name>\\upred_pure\\,_)$Const(\\<^const_name>\\True\\,_)) = true\n | contains_emp (f$x) = contains_emp f orelse contains_emp x\n | contains_emp _ = false\n\n fun remove_emp thm = if contains_emp (Thm.concl_of thm\n |> dest_comb |> snd (* Strip Trueprop*)\n |> strip_comb |> snd |> hd (* Strip entails*))\n then Conv.fconv_rule (Conv.rewr_conv @{thm eq_reflection[OF upred_sep_comm]}\n then_conv (Conv.rewr_conv @{thm eq_reflection[OF upred_true_sep]})\n |> Conv.arg_conv (* Only transform the antecedent *)\n |> Conv.fun_conv (* Go below the \"\\\" *) \n |> HOLogic.Trueprop_conv\n |> Conv.concl_conv ~1)\n thm\n else thm\n\n fun to_entail thm = (if match_upred_holds thm \n then Conv.fconv_rule (Conv.rewr_conv @{thm eq_reflection[OF upred_holds_entails]}\n |> HOLogic.Trueprop_conv\n |> Conv.concl_conv ~1)\n thm\n else thm)\n\n fun move_wands thm = (if contains_wand thm then (@{thm upred_wandE} OF [thm]) |> remove_emp |> move_wands\n else thm)\n in\n (fn whatevs => ((fn (ctxt, thm) => let val thm' = try (move_wands o to_entail) thm in\n (SOME ctxt, thm')end), whatevs)) end\n\\\nattribute_setup to_entailment = \\to_entailment\\\n\ntext \\Find a subgoal on which the given method is applicable, prefer that subgoal and apply the method.\n This will result in new subgoals to be at the head. Requires to evaluate the method for all subgoals\n up to the applicable goal and another time for that goal.\\\nmethod_setup apply_prefer =\n \\Method.text_closure >> (fn m => fn ctxt => fn facts => \n let fun prefer_first i thm = \n let val applicable = case Seq.pull (SELECT_GOAL (method_evaluate m ctxt facts) i thm) \n of SOME _ => true\n | NONE => false\n in (if applicable then prefer_tac i thm else no_tac thm) end\n in SIMPLE_METHOD ((FIRSTGOAL prefer_first) THEN (method_evaluate m ctxt facts)) facts end)\\\n \"Find a subgoal that the method can work on and move it to the top.\"\n\ntext \\Find a subgoal on which the given method is applicable and apply the method there.\n This will not move any subgoals around and resulting subgoals will not be at the head. \n Requires the method to be evaluated for all subgoals at most once.\\\nmethod_setup apply_first =\n \\Method.text_closure >> (fn m => fn ctxt => fn facts => \n let fun eval_method i = \n SELECT_GOAL (method_evaluate m ctxt facts) i\n in SIMPLE_METHOD (FIRSTGOAL eval_method) facts end)\\\n \"Find the first subgoal that the method can work on.\"\n\nmethod_setup get_concl = \\ let \n fun get_concl m ctxt facts (ctxt',thm) = let\n fun free_to_var (Free (x, ty)) = (if Variable.is_declared ctxt' x then Free (x,ty) else Var ((x,0),ty))\n | free_to_var t = t\n val frees_to_vars = Term.map_aterms free_to_var\n val trm = Thm.prop_of thm\n val concl = (case try (HOLogic.dest_Trueprop o Logic.concl_of_goal trm) 1 of SOME trm' => trm'\n | NONE => trm) |> frees_to_vars\n in\n case concl of Const (\\<^const_name>\\Pure.prop\\,_)$(Const (\\<^const_name>\\Pure.term\\, _ )$_) \n => CONTEXT_TACTIC all_tac (ctxt',thm)\n | Const (\\<^const_name>\\Pure.prop\\,_)$_ => CONTEXT_TACTIC no_tac (ctxt',thm)\n | _ => (case try (Method_Closure.apply_method ctxt m [concl] [] [] ctxt facts) (ctxt',thm) of\n SOME res => res | NONE => Seq.empty)\n end\nin \n (Scan.lift Parse.name >> (fn m => fn ctxt => get_concl m ctxt))\nend \\ \"Allows to match against conclusions with schematic variables.\"\n \nmethod entails_substL uses rule =\n match rule[uncurry] in \"_ = _\" \\ \\rule upred_entails_trans[OF upred_entails_eq[OF rule]]\\\n \\ \"_ \\ (_=_)\" \\ \\rule upred_entails_trans[OF upred_entails_eq[OF rule]]\\\n \\ \"_\\_\" \\ \\rule rule\n | rule upred_entails_substE[OF rule, unfolded upred_sep_assoc_eq]\n | rule upred_entails_trans[OF rule] | rule upred_entails_substE'[OF rule, unfolded upred_conj_assoc]\\\n \\ \"_ \\ (_ \\ _)\" \\ \\rule rule\n | rule upred_entails_substE[OF rule, unfolded upred_sep_assoc_eq]\n | rule upred_entails_trans[OF rule] | rule upred_entails_substE'[OF rule, unfolded upred_conj_assoc]\\\n \\ R[curry]: \"upred_holds _\" \\ \\entails_substL rule: R[to_entailment]\\\n \\ R[curry]: \"_ \\ upred_holds _\" \\ \\entails_substL rule: R[to_entailment]\\\n \nmethod entails_substR uses rule = \n match rule[uncurry] in \"_ = _\" \\ \\rule upred_entails_trans[OF _ upred_entails_eq[OF rule]]\\\n \\ \"_ \\ (_=_)\" \\ \\rule upred_entails_trans[OF _ upred_entails_eq[OF rule]]\\\n \\ \"_\\_\" \\ \\rule rule\n | (rule upred_entails_trans[OF _ rule])\n | rule upred_entails_substI[OF rule, unfolded upred_sep_assoc_eq]\\\n \\ \"_ \\ (_ \\ _)\" \\ \\rule rule\n | rule upred_entails_substI[OF rule, unfolded upred_sep_assoc_eq]\n | rule upred_entails_trans[OF _ rule]\\\n \\ R[curry]: \"upred_holds _\" \\ \\entails_substR rule: R[to_entailment]\\\n \\ R[curry]: \"_ \\ upred_holds _\" \\ \\entails_substR rule: R[to_entailment]\\\n \nmethod dupl_pers = (entails_substL rule: upred_entail_eqR[OF persistent_dupl], log_prog_solver)?\n \nmethod subst_pers_keepL uses rule =\n (entails_substL rule: persistent_keep[OF _ rule], log_prog_solver)\n| entails_substL rule: rule\n\ntext \\Unchecked move methods, might not terminate if pattern is not found.\\ \nmethod move_sepL for pat :: \"'a::ucamera upred_f\" =\n match conclusion in \\hyps \\ _\\ for hyps :: \"'a upred_f\" \\\n \\ match (hyps) in \"pat\" \\ succeed\n \\ \"_\\<^emph>pat\" \\ succeed\n \\ \"pat\\<^emph>_\" \\ \\entails_substL rule: upred_sep_comm\\\n \\ \"_\\<^emph>pat\\<^emph>_\" \\ \\entails_substL rule: upred_sep_comm2R\\\n \\ \"pat\\<^emph>_\\<^emph>_\" \\ \\entails_substL rule: upred_sep_comm2L; move_sepL pat\\\n \\ \"_\\<^emph>pat\\<^emph>_\\<^emph>_\" \\ \\entails_substL rule: upred_sep_comm3M; move_sepL pat\\\n \\ \"pat\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substL rule: upred_sep_comm3L; move_sepL pat\\\n \\ \"_\\<^emph>pat\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substL rule: upred_sep_comm4_2; move_sepL pat\\\n \\ \"pat\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substL rule: upred_sep_comm4_1; move_sepL pat\\\n \\ \"_\\<^emph>pat\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substL rule: upred_sep_comm5_2; move_sepL pat\\\n \\ \"pat\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substL rule: upred_sep_comm5_1; move_sepL pat\\\n \\ \"_\\<^emph>pat\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substL rule: upred_sep_comm6_2; move_sepL pat\\\n \\ \"pat\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substL rule: upred_sep_comm6_1; move_sepL pat\\\n \\ \"_\\<^emph>pat\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substL rule: upred_sep_comm7_2; move_sepL pat\\\n \\ \"pat\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substL rule: upred_sep_comm7_1; move_sepL pat\\\n \\ \"_\\<^emph>pat\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substL rule: upred_sep_comm8_2; move_sepL pat\\\n \\ \"pat\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substL rule: upred_sep_comm8_1; move_sepL pat\\\n \\ \"_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substL rule: upred_sep_comm8_1; move_sepL pat\\\n \\\n \nmethod move_sepR for pat :: \"'a::ucamera upred_f\" =\n match conclusion in \\_ \\ goal\\ for goal :: \"'a upred_f\" \\\n \\ match (goal) in \"pat\" \\ succeed\n \\ \"_\\<^emph>pat\" \\ succeed\n \\ \"pat\\<^emph>_\" \\ \\entails_substR rule: upred_sep_comm\\\n \\ \"_\\<^emph>pat\\<^emph>_\" \\ \\entails_substR rule: upred_sep_comm2R\\\n \\ \"pat\\<^emph>_\\<^emph>_\" \\ \\entails_substR rule: upred_sep_comm2L; move_sepR pat\\\n \\ \"_\\<^emph>pat\\<^emph>_\\<^emph>_\" \\ \\entails_substR rule: upred_sep_comm3M; move_sepR pat\\\n \\ \"pat\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substR rule: upred_sep_comm3L; move_sepR pat\\\n \\ \"_\\<^emph>pat\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substR rule: upred_sep_comm4_2; move_sepR pat\\\n \\ \"pat\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substR rule: upred_sep_comm4_1; move_sepR pat\\\n \\ \"_\\<^emph>pat\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substR rule: upred_sep_comm5_2; move_sepR pat\\\n \\ \"pat\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substR rule: upred_sep_comm5_1; move_sepR pat\\\n \\ \"_\\<^emph>pat\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substR rule: upred_sep_comm6_2; move_sepR pat\\\n \\ \"pat\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substR rule: upred_sep_comm6_1; move_sepR pat\\\n \\ \"_\\<^emph>pat\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substR rule: upred_sep_comm7_2; move_sepR pat\\\n \\ \"pat\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substR rule: upred_sep_comm7_1; move_sepR pat\\\n \\ \"_\\<^emph>pat\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substR rule: upred_sep_comm8_2; move_sepR pat\\\n \\ \"pat\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substR rule: upred_sep_comm8_1; move_sepR pat\\\n \\ \"_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\\<^emph>_\" \\ \\entails_substR rule: upred_sep_comm8_1; move_sepR pat\\\n \\\n\nmethod move_sep for left :: bool and pat :: \"'a::ucamera upred_f\" = \n match (left) in True \\ \\move_sepL pat\\\n \\ False \\ \\move_sepR pat\\\n \nmethod move_sep_all for left :: bool and trm :: \"'a::ucamera upred_f\" =\n match (trm) in \"rest\\<^emph>head\" for rest head :: \"'a upred_f\" \\ \\move_sep_all left rest; move_sep left head\\\n \\ \"P\" for P :: \"'a upred_f\" \\ \\move_sep left P\\\n\nmethod move_sep_both for trm :: \"'a::ucamera upred_f\" =\n move_sepL trm, move_sepR trm\n\nmethod move_sep_all_both for pat :: \"'a::ucamera upred_f\" =\n move_sep_all True pat, move_sep_all False pat\n \nmethod find_pat_sep for pat trm :: \"'a::ucamera upred_f\" = \n match (trm) in \"pat\" \\ succeed\n \\ \"_\\<^emph>pat\" \\ succeed\n \\ \"pat\\<^emph>_\" \\ succeed\n \\ \"rest\\<^emph>_\" for rest :: \"'a upred_f\" \\ \\find_pat_sep pat rest\\ \n\nmethod find_in_pat_sep for pat trm :: \"'a::ucamera upred_f\" = \n match (pat) in \"rest\\<^emph>head\" for rest head :: \"'a upred_f\" \\\n \\ match (trm) in head \\ succeed | find_in_pat_sep rest trm \\\n \\ \"single_pat\" for single_pat \\ \\ match (trm) in single_pat \\ succeed \\\n\nmethod find_other_than_pat_sep for pat trm :: \"'a::ucamera upred_f\" =\n match (trm) in pat \\ fail\n \\ \"\\rest\" for rest :: \"'a upred_f\" \\ \\find_other_than_pat_sep pat rest\\\n \\ \"\\rest\" for rest :: \"'a upred_f\" \\ \\find_other_than_pat_sep pat rest\\\n \\ \"rest\\<^emph>head\" for rest head :: \"'a upred_f\" \\ \n \\find_other_than_pat_sep pat rest | find_other_than_pat_sep pat head\\\n \\ \"_\" \\ succeed \n \nmethod check_not_headL for pat :: \"'a::ucamera upred_f\" =\n match conclusion in \"_\\<^emph>head\\_\" for head :: \"'a upred_f\" \\ \\find_other_than_pat_sep pat head\\\n \nmethod check_head for pat trm :: \"'a::ucamera upred_f\" =\n match (pat) in \"rest_pat\\<^emph>head_pat\" for rest_pat head_pat :: \"'a upred_f\" \\ \n \\match (trm) in \"rest\\<^emph>head_pat\" for rest :: \"'a upred_f\" \\ \\check_head rest_pat rest\\\\\n \\ _ \\ \\match (trm) in pat \\ succeed \\ \"_\\<^emph>pat\" \\ succeed\\\n\ntext \\Checked move methods, guaranteed to terminate.\\\nmethod check_headL for pat :: \"'a::ucamera upred_f\" =\n match conclusion in \"hyps\\_\" for hyps :: \"'a upred_f\" \\ \\check_head pat hyps\\\n\nmethod check_moveL for pat :: \"'a::ucamera upred_f\" =\n match conclusion in \"hyps\\_\" for hyps :: \"'a upred_f\" \\\n \\find_pat_sep pat hyps; move_sepL pat\\\n \nmethod check_moveR for pat :: \"'a::ucamera upred_f\" =\n match conclusion in \\_ \\ goal\\ for goal :: \"'a upred_f\" \\\n \\ find_pat_sep pat goal; move_sepR pat\\\n \nmethod check_move for left :: bool and pat :: \"'a::ucamera upred_f\" = \n match (left) in True \\ \\check_moveL pat\\\n \\ False \\ \\check_moveR pat\\ \n\nmethod check_move_all for left :: bool and trm :: \"'a::ucamera upred_f\" =\n match (trm) in \"rest\\<^emph>head\" for rest head :: \"'a upred_f\" \\ \n \\check_move_all left rest; check_move left head\\\n \\ \"P\" for P :: \"'a upred_f\" \\ \\check_move left P\\\n\nmethod check_move_both for trm :: \"'a::ucamera upred_f\" =\n (check_moveL trm, dupl_pers), check_moveR trm\n \nmethod check_move_dupl_all for left acc_pure :: bool and trm :: \"'a::ucamera upred_f\" =\n match (trm) in \"rest\\<^emph>\\head\" for rest :: \"'a upred_f\" and head \\ \\match (acc_pure) in True \\ succeed \n \\ False \\ \\check_move left \"\\head\", dupl_pers, check_move_dupl_all left acc_pure rest\\\\\n \\ \"rest\\<^emph>head\" for rest head :: \"'a upred_f\" \\\n \\check_move left head, dupl_pers, check_move_dupl_all left acc_pure rest\\\n \\ \"P\" for P :: \"'a upred_f\" \\ \\check_move left P, dupl_pers\\\n\nmethod check_move_all_both for pat :: \"'a::ucamera upred_f\" =\n (check_move_dupl_all True False pat, move_sep_all True pat), check_move_all False pat\n \ntext \\Moves all hypotheses while duplicating all persistent, then moves again but unchecked to get \n correct order of hypotheses. Then applies given rule.\\\nmethod iApply uses rule = iris_simp,\n match rule[uncurry] in \"hyps \\ _\" for hyps \\ \\check_move_dupl_all True True hyps, move_sep_all True hyps, \n subst_pers_keepL rule: rule\\\n \\ \"_ \\ hyps \\ _\" for hyps \\ \\check_move_dupl_all True True hyps, move_sep_all True hyps,\n subst_pers_keepL rule: rule\\\n \\ R[curry]: \"upred_holds _\" \\ \\iApply rule: R[to_entailment] | rule add_holds[OF rule]\\\n \\ R[curry]: \"_ \\ upred_holds _\" \\ \\iApply rule: R[to_entailment]\\, iris_simp\n\ntext \\Looks for the head term in the given pattern and separates matches to the right.\\\nmethod split_pat for pat :: \"'a::ucamera upred_f\" = repeat_new\n \\((match conclusion in \"can_be_split (_\\<^emph>_) _ _\" \\ succeed),\n (((match conclusion in \"can_be_split (_\\<^emph>head) _ _\" for head :: \"'a upred_f\" \\\n \\find_in_pat_sep pat head\\), rule can_be_split_sepR)\n | rule can_be_split_sepL))\n| ((match conclusion in \"can_be_split (_\\\\<^sub>u_) _ _\" \\ succeed),rule can_be_split_disj)\n| (((match conclusion in \"can_be_split head _ _\" for head :: \"'a upred_f\" \\\n \\find_in_pat_sep pat head\\), rule can_be_split_baseR)\n | rule can_be_split_baseL)\\\n\ntext \\Separates the top terms (the same number as the patterns) to the right and the rest to the left.\n If it should separate the terms in the pattern, they first need to be moved to the top level.\\\nmethod ord_split_pat for pat :: \"'a::ucamera upred_f\" =\n (match conclusion in \"can_be_split (_\\<^emph>_) _ _\" \\ succeed),\n match (pat) in \"rest\\<^emph>_\" for rest :: \"'a upred_f\" \\ \n \\((rule persistent_dupl_split', log_prog_solver) \n | rule can_be_split_sepR), ord_split_pat rest\\\n \\ \"_\" \\ \\(rule can_be_split_rev, rule can_be_split_refl) \n | (rule persistent_dupl_split', log_prog_solver)\n | rule can_be_split_baseR\\\n| (match conclusion in \"frame (_\\\\<^sub>u_) _ _\" \\ succeed),rule frame_disj; \n ord_split_pat pat\n\nmethod split_log_prog for pat :: \"'a::ucamera upred_f\" = repeat_new \n \\(rule split_rule | (((match conclusion in \"can_be_split head _ _\" for head :: \"'a upred_f\" \\\n \\find_in_pat_sep pat head\\), rule can_be_split_baseR) | rule can_be_split_baseL))\\\n\ntext \\Linear-time moving that doesn't guarantee the order of the moved parts \n or that all parts of the pattern where found. Takes an I-pattern.\\\nmethod split_move for pat :: \"'a::ucamera upred_f\" =\n rule upred_entails_trans[OF upred_entail_eqL[OF can_be_splitE]], split_log_prog pat,\n check_not_headL upred_emp, remove_emp \n \nmethod split_move_ord for pat :: \"'a::ucamera upred_f\" =\n split_move pat, check_move_all True pat\n\ntext \\O-pattern based splitting. Can only support a single (possible nested) pattern term at a time.\\\nmethod splitO for pat :: \"'a::ucamera upred_f\" and goal :: \"bool\" = remove_emp,\n (match (goal) in \"can_be_split head _ _\" for head \\\n \\match (head) in pat \\ \\rule can_be_split_baseR\\\\) (* Pattern found *)\n| match (goal) in \"can_be_split (\\head) _ _\" for head \\\n \\match (pat) in \"\\rest\" for rest :: \"'a upred_f\" \\ \\rule can_be_split_later, \n splitO rest \"can_be_split head ?l ?r\"\\ \\ _ \\ \\rule can_be_split_baseL\\\\\n \\ \"can_be_split (\\head) _ _\" for head \\\n \\match (pat) in \"\\rest\" for rest :: \"'a upred_f\" \\ \\rule can_be_split_except_zero,\n splitO rest \"can_be_split head ?l ?r\"\\ \\ _ \\ \\rule can_be_split_baseL\\\\\n \\ \"can_be_split (tail\\<^emph>head) _ _\" for head tail \\ \n \\rule can_be_split_mono, splitO pat \"can_be_split tail ?l ?r\", splitO pat \"can_be_split head ?l ?r\"\\\n \\ \"can_be_split (l\\\\<^sub>ur) _ _\" for l r \\ \n \\rule can_be_split_disj, splitO pat \"can_be_split l ?l ?r\", splitO pat \"can_be_split r ?l ?r\"\\ \n \\ _ \\ \\rule can_be_split_baseL\\\n \nmethod split_moveO for pat :: \"'a::ucamera upred_f\" =\n match conclusion in \"hyps\\_\" for hyps \\ \n \\rule upred_entails_trans[OF upred_entail_eqL[OF can_be_splitE]],\n splitO pat \"can_be_split hyps ?l ?r\", remove_emp\\\n\nmethod split_move_allO for pat :: \"'a::ucamera upred_f\" =\n match (pat) in \"tail_pat\\<^emph>head_pat\" for tail_pat head_pat :: \"'a upred_f\" \\\n \\split_move_allO tail_pat, check_headL tail_pat, split_moveO head_pat\\\n \\ _ \\ \\split_moveO pat, check_headL pat\\\n\nlemma \"(\\((\\P)\\<^emph>Q)) \\\\<^sub>u (\\\\P) \\ \\P\" apply (split_moveO \"\\\\P\") oops\nlemma \"\\(R\\<^emph>\\(P\\<^emph>Q)) \\ R\" apply (split_moveO \"\\\\(P\\<^emph>Q)\") oops\nlemma \"\\(R\\<^emph>\\(P\\<^emph>S\\<^emph>Q)) \\ R\" apply (split_moveO \"\\\\(P\\<^emph>Q)\") oops (*Strange*)\nlemma \"\\(R\\<^emph>\\(P\\<^emph>S\\<^emph>Q)) \\ R\" apply (split_moveO \"\\P\") oops (*Strange*)\nlemma \"\\(R\\<^emph>\\(P\\<^emph>Q)) \\ R\" apply (split_move_allO \"(\\\\P)\\<^emph>\\R\") oops\n\ntext \\Uses the \\<^term>\\rule\\ to do a step and separates arguments based on the \\<^term>\\pat\\.\\\nmethod iApply_step' for pat :: \"'a::ucamera upred_f\" uses rule = iris_simp,\n check_move_all True pat, rule split_trans_rule[OF rule[to_entailment]], rule can_be_split_rev,\n ord_split_pat pat; iris_simp\n\nmethod iApply_step for pat :: \"'a::ucamera upred_f\" uses rule = iris_simp,\n rule split_trans_rule[OF rule[to_entailment]], rule can_be_split_rev, (* The rule has the order of things reversed. *)\n split_pat pat; iris_simp\n \ntext \\Does a transitive step with the given \\<^term>\\step\\ and separates arguments based on \\<^term>\\pat\\.\\\nmethod iApply_step2' for step pat :: \"'a::ucamera upred_f\" = iris_simp,\n check_move_all True pat, rule split_trans[where ?Q = step], rule can_be_split_rev,\n ord_split_pat pat; iris_simp\n\nmethod iApply_step2 for step pat :: \"'a::ucamera upred_f\" = iris_simp,\n rule split_trans[where ?Q = step], rule can_be_split_rev, (* The rule has the order of things reversed. *)\n split_pat pat; iris_simp\n\ntext \\Search for a wand with left hand side \\<^term>\\lhs_pat\\, obtain the lhs term from other hypotheses\n matching \\<^term>\\pat\\ and apply the wand to the newly obtained lhs term.\\\nmethod iApply_wand_as_rule for lhs_pat pat :: \"'a::ucamera upred_f\" = iris_simp, \n check_moveL \"lhs_pat-\\<^emph>?a_schematic_variable_name_that_noone_would_use_in_setp_pat\";\n match conclusion in \"_\\<^emph>(step_trm-\\<^emph>P)\\_\" for step_trm P :: \"'a upred_f\" \\\n \\iApply_step2 step_trm pat,\n prefer_last,\n move_sepL step_trm, move_sepL \"step_trm-\\<^emph>P\", subst_pers_keepL rule: upred_wand_apply,\n defer_tac\\, iris_simp\n \nmethod iExistsL = iris_simp,\n check_moveL \"upred_exists ?P\", ((rule pull_exists_antecedentR)+)?; rule upred_existsE',\n iris_simp\n\nmethod iExistsR for inst = iris_simp,\n check_moveR \"upred_exists ?P\"; (unfold pull_exists_eq pull_exists_eq')?; \n rule upred_existsI[of _ _ inst], iris_simp\n\nmethod iForallL for inst = iris_simp,\n check_moveL \"upred_forall ?P\";\n rule upred_entails_trans[OF upred_forall_inst[of _ inst]] upred_entails_substE[OF upred_forall_inst[of _ inst]], \n iris_simp\n \nmethod iForallR = iris_simp, check_moveR \"upred_forall ?P\"; rule upred_forallI, iris_simp\n \nmethod iPureL =\n iris_simp, check_moveL \"upred_pure ?b\", rule upred_pure_impl, iris_simp\n\nmethod iPureR = \n iris_simp, check_moveR \"upred_pure ?b\", rule upred_pureI' upred_pureI, assumption?, iris_simp\n \nmethod find_applicable_wand for trm :: \"'a::ucamera upred_f\" =\n match (trm) in \"P-\\<^emph>Q\" for P Q :: \"'a upred_f\" \\\n \\check_moveL P, dupl_pers, move_sepL \"P-\\<^emph>Q\"\\\n \\ \"rest\\<^emph>(P-\\<^emph>Q)\" for P Q rest :: \"'a upred_f\" \\\n \\(check_moveL P, dupl_pers, move_sepL \"P-\\<^emph>Q\") | find_applicable_wand rest\\\n \\ \"rest\\<^emph>_\" for rest :: \"'a upred_f\" \\ \\find_applicable_wand rest\\\n\nmethod iApply_wand = iris_simp,\n match conclusion in \\hyps \\ _\\ for hyps \\\n \\find_applicable_wand hyps, subst_pers_keepL rule: upred_wand_apply, iris_simp\\\n\nmethod iFrame_single_safe for trm :: bool = iris_simp,\n match (trm) in \\_ \\ goal\\ for goal \\\n \\ match (goal) in \"_\\<^emph>P\" for P \\ \n \\(check_moveL P; dupl_pers; rule upred_frame upred_emp_left) | iPureR\\\n \\ _ \\\n \\(check_moveL goal; (rule upred_entails_refl | rule upred_weakeningR)) | iPureR\\ \\,\n iris_simp\n \ntext \\Tries to remove the head goal term by either framing or reasoning with iPure and assumptions.\\\nmethod iFrame_single = iris_simp, get_concl \"Automation.iFrame_single_safe\", iris_simp\n\nmethod iExistsR2 = iris_simp,\n (check_moveR \"upred_exists ?P\"; (unfold pull_exists_eq pull_exists_eq')?; \n rule upred_exists_lift, rule exI)+, iris_simp\n\nmethod later_elim = iris_simp,\n check_moveL \"\\ ?P\", \n (rule elim_modal_entails'[OF elim_modal_timeless']\n | rule elim_modal_entails[OF elim_modal_timeless']),\n (* Once for the timeless goal, once for the is_except_zero goal. *) \n log_prog_solver, log_prog_solver\n\nmethod iMod_raw methods fupd uses rule =\n iris_simp, iApply rule: rule, \n (prefer_last, (later_elim| fupd)+, defer_tac)?, iris_simp\n\nmethod iMod_raw_wand for lhs_pat pat :: \"'a::ucamera upred_f\" methods later fupd =\n iris_simp, iApply_wand_as_rule lhs_pat pat, (prefer_last, (later | fupd)+, defer_tac)?, iris_simp\n\nmethod iMod_raw_step for pat :: \"'a::ucamera upred_f\" methods later fupd uses rule = \n iris_simp, iApply_step pat rule: rule; all \\((later | fupd)+)?\\; iris_simp\n \nmethod iDestruct_raw = iris_simp,\n ((check_moveL \"\\ (?c::'a::dcamera)\", entails_substL rule: upred_entail_eqL[OF discrete_valid])\n| iPureL\n| iExistsL), iris_simp\n\ntext \\Applies the given rule and destructs the resulting term.\\\nmethod iDestruct uses rule =\n iris_simp, iApply rule: rule, (prefer_last, iDestruct_raw+, defer_tac)?, iris_simp\n\nmethod iDrop for pat :: \"'a::ucamera upred_f\" =\n iris_simp, check_moveL pat; rule upred_entails_trans[OF upred_weakeningL], iris_simp\n \nlemma test_lemma: \"S \\<^emph> (\\P) \\<^emph> Q \\<^emph> ((\\P)-\\<^emph>\\R) \\<^emph> (\\R) -\\<^emph> (\\R) \\<^emph> (\\R) \\<^emph> Q\"\napply iIntro\napply iApply_wand\napply (split_move \"Q\\<^emph>S\\<^emph>\\P\")\nby iFrame_single+\nend","avg_line_length":63.4216335541,"max_line_length":186,"alphanum_fraction":0.6980856248} {"size":4388,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/n_german_lemma_inv__38_on_rules.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_german Protocol Case Study*} \n\ntheory n_german_lemma_inv__38_on_rules imports n_german_lemma_on_inv__38\nbegin\nsection{*All lemmas on causal relation between inv__38*}\nlemma lemma_inv__38_on_rules:\n assumes b1: \"r \\ rules N\" and b2: \"(\\ p__Inv2. p__Inv2\\N\\f=inv__38 p__Inv2)\"\n shows \"invHoldForRule s f r (invariants N)\"\n proof -\n have c1: \"(\\ i d. i\\N\\d\\N\\r=n_Store i d)\\\n (\\ i. i\\N\\r=n_SendReqS i)\\\n (\\ i. i\\N\\r=n_SendReqE__part__0 i)\\\n (\\ i. i\\N\\r=n_SendReqE__part__1 i)\\\n (\\ i. i\\N\\r=n_RecvReqS N i)\\\n (\\ i. i\\N\\r=n_RecvReqE N i)\\\n (\\ i. i\\N\\r=n_SendInv__part__0 i)\\\n (\\ i. i\\N\\r=n_SendInv__part__1 i)\\\n (\\ i. i\\N\\r=n_SendInvAck i)\\\n (\\ i. i\\N\\r=n_RecvInvAck i)\\\n (\\ i. i\\N\\r=n_SendGntS i)\\\n (\\ i. i\\N\\r=n_SendGntE N i)\\\n (\\ i. i\\N\\r=n_RecvGntS i)\\\n (\\ i. i\\N\\r=n_RecvGntE i)\"\n apply (cut_tac b1, auto) done\n moreover {\n assume d1: \"(\\ i d. i\\N\\d\\N\\r=n_Store i d)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_StoreVsinv__38) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendReqS i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendReqSVsinv__38) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendReqE__part__0 i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendReqE__part__0Vsinv__38) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendReqE__part__1 i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendReqE__part__1Vsinv__38) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvReqS N i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvReqSVsinv__38) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvReqE N i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvReqEVsinv__38) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendInv__part__0 i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendInv__part__0Vsinv__38) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendInv__part__1 i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendInv__part__1Vsinv__38) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendInvAck i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendInvAckVsinv__38) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvInvAck i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvInvAckVsinv__38) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendGntS i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendGntSVsinv__38) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendGntE N i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendGntEVsinv__38) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvGntS i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvGntSVsinv__38) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvGntE i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvGntEVsinv__38) done\n }\n\n ultimately show \"invHoldForRule s f r (invariants N)\"\n by satx\nqed\n\nend\n","avg_line_length":36.8739495798,"max_line_length":132,"alphanum_fraction":0.6308113036} {"size":744,"ext":"thy","lang":"Isabelle","max_stars_count":2.0,"content":"theory auto_proofs\nimports Main IsaP\nbegin\n-- \"This line sets the tests to use the simple theory of Peano\n arithmetic without any lemmas proved.\"\n\nuse_thy \"src\/examples\/N\"\nML {* val thry = theory \"N\"; *}\n\n-- \"ML function to automatically prove goals in Peano arithematic using\n with Rippling and Lemma Calculation \"\nML {*\nfun a_rippling goals = \n PPInterface.init_rst_of_strings thry goals\n |> RState.set_rtechn (SOME (RTechnEnv.map_then RippleLemCalc.induct_ripple_lemcalc))\n |> GSearch.depth_fs (fn rst => is_none (RState.get_rtechn rst)) RState.unfold\n |> Seq.pull;\n*}\n\n-- \"Regression tests to make sure we can still prove things we should be able to\"\nML {* val SOME (myrst, more) = a_rippling [\"a + b = b + (a::N)\"]; *}\n\n\n\nend;","avg_line_length":29.76,"max_line_length":87,"alphanum_fraction":0.7163978495} {"size":6755,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/n_g2kAbsAfter_lemma_inv__61_on_rules.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_g2kAbsAfter Protocol Case Study*} \n\ntheory n_g2kAbsAfter_lemma_inv__61_on_rules imports n_g2kAbsAfter_lemma_on_inv__61\nbegin\nsection{*All lemmas on causal relation between inv__61*}\nlemma lemma_inv__61_on_rules:\n assumes b1: \"r \\ rules N\" and b2: \"(f=inv__61 )\"\n shows \"invHoldForRule s f r (invariants N)\"\n proof -\n have c1: \"(\\ d. d\\N\\r=n_n_Store_i1 d)\\\n (\\ d. d\\N\\r=n_n_AStore_i1 d)\\\n (r=n_n_SendReqS_j1 )\\\n (r=n_n_SendReqEI_i1 )\\\n (r=n_n_SendReqES_i1 )\\\n (r=n_n_RecvReq_i1 )\\\n (r=n_n_SendInvE_i1 )\\\n (r=n_n_SendInvS_i1 )\\\n (r=n_n_SendInvAck_i1 )\\\n (r=n_n_RecvInvAck_i1 )\\\n (r=n_n_SendGntS_i1 )\\\n (r=n_n_SendGntE_i1 )\\\n (r=n_n_RecvGntS_i1 )\\\n (r=n_n_RecvGntE_i1 )\\\n (r=n_n_ASendReqIS_j1 )\\\n (r=n_n_ASendReqSE_j1 )\\\n (r=n_n_ASendReqEI_i1 )\\\n (r=n_n_ASendReqES_i1 )\\\n (r=n_n_SendReqEE_i1 )\\\n (r=n_n_ARecvReq_i1 )\\\n (r=n_n_ASendInvE_i1 )\\\n (r=n_n_ASendInvS_i1 )\\\n (r=n_n_ASendInvAck_i1 )\\\n (r=n_n_ARecvInvAck_i1 )\\\n (r=n_n_ASendGntS_i1 )\\\n (r=n_n_ASendGntE_i1 )\\\n (r=n_n_ARecvGntS_i1 )\\\n (r=n_n_ARecvGntE_i1 )\"\n apply (cut_tac b1, auto) done\n moreover {\n assume d1: \"(\\ d. d\\N\\r=n_n_Store_i1 d)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_Store_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(\\ d. d\\N\\r=n_n_AStore_i1 d)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_AStore_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_SendReqS_j1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_SendReqS_j1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_SendReqEI_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_SendReqEI_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_SendReqES_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_SendReqES_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_RecvReq_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_RecvReq_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_SendInvE_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_SendInvE_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_SendInvS_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_SendInvS_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_SendInvAck_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_SendInvAck_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_RecvInvAck_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_RecvInvAck_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_SendGntS_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_SendGntS_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_SendGntE_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_SendGntE_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_RecvGntS_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_RecvGntS_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_RecvGntE_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_RecvGntE_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_ASendReqIS_j1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_ASendReqIS_j1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_ASendReqSE_j1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_ASendReqSE_j1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_ASendReqEI_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_ASendReqEI_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_ASendReqES_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_ASendReqES_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_SendReqEE_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_SendReqEE_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_ARecvReq_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_ARecvReq_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_ASendInvE_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_ASendInvE_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_ASendInvS_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_ASendInvS_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_ASendInvAck_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_ASendInvAck_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_ARecvInvAck_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_ARecvInvAck_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_ASendGntS_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_ASendGntS_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_ASendGntE_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_ASendGntE_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_ARecvGntS_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_ARecvGntS_i1Vsinv__61) done\n }\n\n moreover {\n assume d1: \"(r=n_n_ARecvGntE_i1 )\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_n_ARecvGntE_i1Vsinv__61) done\n }\n\n ultimately show \"invHoldForRule s f r (invariants N)\"\n by satx\nqed\n\nend\n","avg_line_length":31.1290322581,"max_line_length":132,"alphanum_fraction":0.6473723168} {"size":291,"ext":"thy","lang":"Isabelle","max_stars_count":30.0,"content":"theory lscmnbignum_Lsc__bignum__word_of_boolean__subprogram_def_WP_parameter_def_1\nimports \"..\/LibSPARKcrypto\"\nbegin\n\nwhy3_open \"lscmnbignum_Lsc__bignum__word_of_boolean__subprogram_def_WP_parameter_def_1.xml\"\n\nwhy3_vc WP_parameter_def\n using\n `b \\ True`\n by simp\n\nwhy3_end\n\nend\n","avg_line_length":19.4,"max_line_length":91,"alphanum_fraction":0.8556701031} {"size":1905,"ext":"thy","lang":"Isabelle","max_stars_count":1.0,"content":"theory T181\nimports Main\nbegin\nlemma \"(\n(\\ x::nat. \\ y::nat. meet(x, y) = meet(y, x)) &\n(\\ x::nat. \\ y::nat. join(x, y) = join(y, x)) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(x, meet(y, z)) = meet(meet(x, y), z)) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(x, join(y, z)) = join(join(x, y), z)) &\n(\\ x::nat. \\ y::nat. meet(x, join(x, y)) = x) &\n(\\ x::nat. \\ y::nat. join(x, meet(x, y)) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(x, join(y, z)) = join(mult(x, y), mult(x, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(join(x, y), z) = join(mult(x, z), mult(y, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(x, over(join(mult(x, y), z), y)) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(y, undr(x, join(mult(x, y), z))) = y) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(mult(over(x, y), y), x) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(mult(y, undr(y, x)), x) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(x, meet(y, z)) = meet(mult(x, y), mult(x, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(meet(x, y), z) = meet(mult(x, z), mult(y, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. undr(x, join(y, z)) = join(undr(x, y), undr(x, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. over(x, meet(y, z)) = join(over(x, y), over(x, z))) &\n(\\ x::nat. \\ y::nat. invo(join(x, y)) = meet(invo(x), invo(y))) &\n(\\ x::nat. \\ y::nat. invo(meet(x, y)) = join(invo(x), invo(y))) &\n(\\ x::nat. invo(invo(x)) = x)\n) \\\n(\\ x::nat. \\ y::nat. \\ z::nat. undr(meet(x, y), z) = join(undr(x, z), undr(y, z)))\n\"\nnitpick[card nat=7,timeout=86400]\noops\nend","avg_line_length":65.6896551724,"max_line_length":108,"alphanum_fraction":0.5333333333} {"size":53435,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"(*\n File: dLambda.thy\n Time-stamp: <2016-01-05T12:38:20Z>\n Author: JRF\n Web: http:\/\/jrf.cocolog-nifty.com\/software\/2016\/01\/post.html\n Logic Image: ZF (of Isabelle2015)\n*)\n\ntheory dLambda imports dTermDef OCons FinCard Arith begin\n\ndefinition dAbst :: \"[i, i, i]=>i\" where\n\"dAbst(M, x, n) == dTerm_rec(\n %y. lam i: nat. if(x=y, dBound(i), dVar(y)), \n %j. lam i: nat. dBound(j),\n %N r. lam i: nat. dLam(r`succ(i)),\n %A B ra rb. lam i: nat. dApp(ra`i, rb`i), M) ` n\"\n\ndefinition dLift :: \"[i, i]=>i\" where\n\"dLift(M, n) == dTerm_rec(\n %x. lam i: nat. dVar(x),\n %j. lam i: nat. if (j < i, dBound(j), dBound(succ(j))),\n %N r. lam i: nat. dLam(r`succ(i)),\n %A B ra rb. lam i: nat. dApp(ra`i, rb`i), M) ` n\"\n\ndefinition dSubst :: \"[i, i, i]=>i\" where\n\"dSubst(M, n, N) == dTerm_rec(\n %x. lam i: nat. lam m: dTerm. dVar(x),\n %j. lam i: nat. lam m: dTerm. if (i < j, dBound(j #- 1),\n if (i=j, m, dBound(j))),\n %N r. lam i: nat. lam m: dTerm. dLam(r`succ(i)`dLift(m, 0)),\n %A B ra rb. lam i: nat. lam m: dTerm. dApp(ra`i`m, rb`i`m), M)`n`N\"\n\n\ndefinition dDeg :: \"i=>i\" where\n\"dDeg(M) == dTerm_rec(%x. 0, %n. succ(n), %N r. r #- 1,\n %A B rm rn. rm Un rn, M)\"\n\ndefinition dFV :: \"i=>i\" where\n\"dFV(M) == {x: LVariable. EX l. : dOcc(M)}\"\n\ndefinition dProp :: i where\n\"dProp == {M: dTerm. dDeg(M) = 0}\"\n\n\ndefinition dLamDegBase :: \"[i, i]=>i\" where\n\"dLamDegBase(l, M) == {v: dOcc(M). EX m. v = & m ~= l &\n initseg(nat, m, l)}\"\n\ndefinition dLamDeg :: \"[i, i]=>i\" where\n\"dLamDeg(l, M) == |dLamDegBase(l, M)|\"\n\ndefinition dBoundBy :: \"[i, i, i]=>o\" where\n\"dBoundBy(u, v, M) == M: dTerm & u: dOcc(M) & v: dOcc(M) &\n (EX n l m x. u = & v = &\n m = l @ x & dLamDeg(x, dsubterm(M, l)) = succ(n))\"\n\n\nlemmas dOcc_domain = Occ_ind_cond_Occ_domain [OF\n dTerm_Occ_ind_cond]\n\nlemmas dOcc_in_Occ_range = Occ_ind_cond_Occ_in_Occ_range [OF\n dTerm_Occ_ind_cond]\n\nlemma dOcc_typeD1:\n assumes major: \": dOcc(M)\"\n and prem: \"M: dTerm\"\n shows \"l: list(nat)\"\napply (rule major [THEN prem [THEN dOcc_domain, THEN subsetD, THEN SigmaD1]])\ndone\n\nlemma dOcc_typeD2:\n assumes major: \": dOcc(M)\"\n and prem: \"M: dTerm\"\n shows \"T: dTag\"\napply (rule major [THEN prem [THEN dOcc_domain, THEN subsetD, THEN SigmaD2]])\ndone\n\nlemma dTerm_typeEs:\n \"[| dVar(x): dTerm; x: LVariable ==> R |] ==> R\"\n \"[| dBound(n): dTerm; n: nat ==> R |] ==> R\"\n \"[| dLam(M): dTerm; M: dTerm ==> R |] ==> R\"\n \"[| dApp(M, N): dTerm; [| M: dTerm; N: dTerm |] ==> R |] ==> R\"\napply (erule dTerm.cases, (blast elim!: dTerm.free_elims)+)+\ndone\n\nlemma dTag_typeEs:\n \"[| TdVar(x): dTag; x: LVariable ==> R |] ==> R\"\n \"[| TdBound(n): dTag; n: nat ==> R |] ==> R\"\napply (erule dTag.cases, (blast elim!: dTag.free_elims)+)+\ndone\n\nlemma dOcc_dVarE:\n assumes major: \"u: dOcc(dVar(x))\"\n and prem: \"u = <[], TdVar(x)> ==> R\"\n shows \"R\"\napply (insert major)\napply (simp add: dOcc_eqns)\napply (erule Occ_consE)\napply (erule prem)\napply simp\ndone\n\nlemma dOcc_dBoundE:\n assumes major: \"u: dOcc(dBound(n))\"\n and prem: \"u = <[], TdBound(n)> ==> R\"\n shows \"R\"\napply (insert major)\napply (simp only: dOcc_eqns)\napply (erule Occ_consE)\napply (erule prem)\napply simp\ndone\n\nlemma dOcc_dLamE:\n assumes major: \"u: dOcc(dLam(M))\"\n and prem1: \"u = <[], TdLam> ==> R\"\n and prem2:\n \"!! l T. [| u = ; : dOcc(M) |] ==> R\"\n shows \"R\"\napply (insert major)\napply (simp only: dOcc_eqns)\napply (erule Occ_consE)\napply (erule prem1)\napply simp\napply (erule succE)\napply (erule_tac [2] emptyE)\napply hypsubst\napply (rule prem2)\nprefer 2 apply simp\napply assumption\ndone\n\nlemma dOcc_dAppE:\n assumes major: \"u: dOcc(dApp(M, N))\"\n and prem1: \"u = <[], TdApp> ==> R\"\n and prem2:\n \"!! l T. [| u = ; : dOcc(M) |] ==> R\"\n and prem3:\n \"!! l T. [| u = ; : dOcc(N) |] ==> R\"\n shows \"R\"\napply (insert major)\napply (simp only: dOcc_eqns)\napply (erule Occ_consE)\napply (erule prem1)\napply simp\napply (erule succE)\napply (erule_tac [2] succE)\napply (erule_tac [3] emptyE)\napply hypsubst\napply (rule prem3)\nprefer 2 apply simp\napply assumption\napply hypsubst\napply (rule prem2)\nprefer 2 apply simp\napply assumption\ndone\n\nlemmas dOcc_dTermEs = dOcc_dVarE dOcc_dBoundE dOcc_dLamE dOcc_dAppE\n\nlemma dOcc_dTermIs:\n \"<[], TdVar(x)>: dOcc(dVar(x))\"\n \"<[], TdBound(n)>: dOcc(dBound(n))\"\n \"<[], TdLam>: dOcc(dLam(M))\"\n \": dOcc(M) ==> : dOcc(dLam(M))\"\n \"<[], TdApp>: dOcc(dApp(M, N))\"\n \": dOcc(M) ==> : dOcc(dApp(M, N))\"\n \": dOcc(N) ==> : dOcc(dApp(M, N))\"\napply (simp_all add: dOcc_eqns)\napply (rule Occ_consI2 Occ_consI1 | simp\n | (assumption | rule succI1 succI2)+)+\ndone\n\nlemmas dTerm_def_subterm_Nil = def_subterm_Nil [OF\n dTerm_Occ_cons_cond dTerm_Occ_ind_cond dOccinv_def\n dSub_def dTerm_Term_cons_inj_cond dsubterm_def]\n\nlemmas dTerm_def_subterm_Cons = def_subterm_Cons [OF\n dTerm_Occ_cons_cond dTerm_Occ_ind_cond dOccinv_def\n dSub_def dTerm_Term_cons_inj_cond dsubterm_def]\n\nlemma dsubterm_eqns_0:\n \"[| M: dTerm; l: list(nat) |] ==>\n dsubterm(dLam(M), Cons(0, l)) = dsubterm(M, l)\"\n \"[| A: dTerm; B: dTerm; l: list(nat) |] ==>\n dsubterm(dApp(A, B), Cons(0, l)) = dsubterm(A, l)\"\n \"[| A: dTerm; B: dTerm; l: list(nat) |] ==>\n dsubterm(dApp(A, B), Cons(1, l)) = dsubterm(B, l)\"\napply (simp_all add: dTerm_cons_eqns_sym dTerm_def_subterm_Cons)\ndone\n\nlemmas dsubterm_eqns = dTerm_def_subterm_Nil dsubterm_eqns_0\n\nlemma dAbst_eqns:\n \"n: nat ==> dAbst(dVar(y), x, n) = if(x = y, dBound(n), dVar(y))\"\n \"n: nat ==> dAbst(dBound(i), x, n) = dBound(i)\"\n \"n: nat ==> dAbst(dLam(M), x, n) = dLam(dAbst(M, x, succ(n)))\"\n \"n: nat ==> dAbst(dApp(A, B), x, n) =\n dApp(dAbst(A, x, n), dAbst(B, x, n))\"\napply (unfold dAbst_def)\napply simp_all\ndone\n\nlemma dAbst_type:\n assumes major: \"M: dTerm\"\n and sub: \"n: nat\"\n shows \"dAbst(M, x, n): dTerm\"\napply (rule sub [THEN [2] bspec])\napply (rule major [THEN dTerm.induct])\napply (simp_all add: dAbst_eqns)\napply (rule_tac [3] ballI)\napply (drule_tac [3] bspec)\napply (erule_tac [3] nat_succI)\napply blast+\ndone\n\nlemma dLift_eqns:\n \"n: nat ==> dLift(dVar(x), n) = dVar(x)\"\n \"n: nat ==> dLift(dBound(i), n) = if (i < n, dBound(i), dBound(succ(i)))\"\n \"n: nat ==> dLift(dLam(M), n) = dLam(dLift(M, succ(n)))\"\n \"n: nat ==> dLift(dApp(A, B), n) =\n dApp(dLift(A, n), dLift(B, n))\"\napply (unfold dLift_def)\napply simp_all\ndone\n\nlemma dLift_type:\n assumes major: \"M: dTerm\"\n and sub: \"n: nat\"\n shows \"dLift(M, n): dTerm\"\napply (rule sub [THEN [2] bspec])\napply (rule major [THEN dTerm.induct])\napply (simp_all add: dLift_eqns)\napply (rule_tac [3] ballI)\napply (drule_tac [3] bspec)\napply (erule_tac [3] nat_succI)\napply blast+\ndone\n\nlemma dSubst_eqns:\n \"[| n: nat; N: dTerm |] ==> dSubst(dVar(x), n, N) = dVar(x)\"\n \"[| n: nat; N: dTerm |] ==> dSubst(dBound(i), n, N) =\n if (n < i, dBound(i #- 1), if (n = i, N, dBound(i)))\"\n \"[| n: nat; N: dTerm |] ==> dSubst(dLam(M), n, N)\n = dLam(dSubst(M, succ(n), dLift(N, 0)))\"\n \"[| n: nat; N: dTerm |] ==> dSubst(dApp(A, B), n, N) =\n dApp(dSubst(A, n, N), dSubst(B, n, N))\"\napply (unfold dSubst_def)\napply simp_all\ndone\n\nlemma dSubst_type:\n assumes major: \"M: dTerm\"\n and sub: \"n: nat\"\n and prem: \"N: dTerm\"\n shows \"dSubst(M, n, N): dTerm\"\napply (rule sub [THEN [2] bspec])\napply (rule prem [THEN [2] bspec])\napply (rule major [THEN dTerm.induct])\napply (simp_all add: dSubst_eqns)\napply safe\napply (erule_tac [3] bspec [THEN bspec])\napply (erule_tac [2] bspec [THEN bspec])\napply (erule_tac [1] bspec [THEN bspec])\napply (assumption | rule dLift_type nat_succI nat_0I)+\ndone\n\nlemma dDeg_eqns:\n \"dDeg(dVar(x)) = 0\"\n \"dDeg(dBound(i)) = succ(i)\"\n \"dDeg(dLam(M)) = dDeg(M) #- 1\"\n \"dDeg(dApp(A, B)) = dDeg(A) Un dDeg(B)\"\napply (unfold dDeg_def)\napply simp_all\ndone\n\nlemma dDeg_type:\n \"M: dTerm ==> dDeg(M): nat\"\napply (unfold dDeg_def)\napply (rule dTerm_rec_type)\napply (assumption | rule diff_type nat_UnI nat_succI nat_0I)+\ndone\n\n\n(** dLamDeg **)\nlemma dLamDegBase_Nil:\n \"M: dTerm ==> dLamDegBase([], M) = 0\"\napply (unfold dLamDegBase_def)\napply (rule equalityI)\napply (safe elim!: initseg_NilE)\ndone\n\nlemma dLamDegBase_Cons_dLam:\n \"l: list(nat) ==> dLamDegBase(Cons(0, l), dLam(M))\n = cons(<[], TdLam>, Occ_shift(0, dLamDegBase(l, M)))\"\napply (unfold dLamDegBase_def)\napply (rule equalityI)\napply (safe elim!: list.free_elims Occ_shiftE initseg_ConsE dOcc_dTermEs)\napply (erule swap, rule Occ_shiftI)\napply blast\napply (rule dOcc_dTermIs)\napply (erule_tac [2] dOcc_dTermIs)\napply (erule_tac [2] asm_rl | rule_tac [2] conjI refl exI)+\napply (assumption | rule conjI refl exI)+\napply (blast elim!: list.free_elims)\nprefer 2 apply (blast elim!: list.free_elims)\napply (assumption | rule list.intros initseg_NilI initseg_ConsI\n nat_0I)+\ndone\n\nlemma dLamDegBase_Cons_dApp1:\n \"l: list(nat) ==> dLamDegBase(Cons(0, l), dApp(M, N))\n = Occ_shift(0, dLamDegBase(l, M))\"\napply (unfold dLamDegBase_def)\napply (rule equalityI)\napply (safe elim!: list.free_elims dTag.free_elims Occ_shiftE\n initseg_ConsE dOcc_dTermEs)\napply (rule Occ_shiftI)\napply blast\napply (erule dOcc_dTermIs)\napply (assumption | rule conjI refl exI)+\napply (blast elim!: list.free_elims)\napply (assumption | rule list.intros initseg_ConsI nat_0I)+\ndone\n\nlemma dLamDegBase_Cons_dApp2:\n \"l: list(nat) ==> dLamDegBase(Cons(1, l), dApp(M, N))\n = Occ_shift(1, dLamDegBase(l, N))\"\napply (unfold dLamDegBase_def)\napply (rule equalityI)\napply (safe elim!: list.free_elims dTag.free_elims Occ_shiftE\n initseg_ConsE dOcc_dTermEs)\napply (rule Occ_shiftI)\napply blast\napply (erule dOcc_dTermIs)\napply (assumption | rule conjI refl exI)+\napply (blast elim!: list.free_elims)\napply (assumption | rule list.intros initseg_ConsI nat_1I)+\ndone\n\nlemmas dTerm_Occ_ind_cond_Occ_FinI = Occ_ind_cond_Occ_FinI [OF\n dTerm_Occ_ind_cond]\n\nlemma dLamDeg_type:\n \"M: dTerm ==> dLamDeg(l, M): nat\"\napply (unfold dLamDeg_def dLamDegBase_def)\napply (assumption | rule Finite_imp_card_nat Fin_into_Finite\n dTerm_Occ_ind_cond_Occ_FinI Collect_subset Fin_subset)+\ndone\n\nlemma dLamDeg_Nil:\n \"M: dTerm ==> dLamDeg([], M) = 0\"\napply (unfold dLamDeg_def)\napply (simp only: dLamDegBase_Nil)\napply (rule Card_0 [THEN Card_cardinal_eq])\ndone\n\nlemma dLamDeg_Cons_dLam:\n assumes major: \"M: dTerm\"\n and prem: \"l: list(nat)\"\n shows \"dLamDeg(Cons(0, l), dLam(M)) = succ(dLamDeg(l, M))\"\napply (unfold dLamDeg_def)\napply (simp only: prem [THEN dLamDegBase_Cons_dLam])\napply (rule trans)\napply (rule Finite_cardinal_cons)\napply (rule_tac [3] f=\"succ\" in function_apply_eq)\napply (rule_tac [3] Occ_shift_cardinal)\napply (unfold dLamDegBase_def)\napply (assumption | rule Fin_into_Finite Occ_shift_FinI\n Collect_subset major nat_0I\n dTerm_Occ_ind_cond_Occ_FinI Fin_subset)+\napply (blast elim!: list.free_elims Occ_shiftE)\napply (rule subset_trans)\napply (assumption | rule major dOcc_domain Collect_subset)+\ndone\n\nlemma dLamDeg_Cons_dApp1:\n \"[| M: dTerm; l: list(nat) |] ==>\n dLamDeg(Cons(0, l), dApp(M, N)) = dLamDeg(l, M)\"\napply (unfold dLamDeg_def)\napply (simp only: dLamDegBase_Cons_dApp1)\napply (rule Occ_shift_cardinal)\napply (unfold dLamDegBase_def)\napply (rule subset_trans)\napply (assumption | rule dOcc_domain Collect_subset)+\ndone\n\nlemma dLamDeg_Cons_dApp2:\n \"[| N: dTerm; l: list(nat) |] ==>\n dLamDeg(Cons(1, l), dApp(M, N)) = dLamDeg(l, N)\"\napply (unfold dLamDeg_def)\napply (simp only: dLamDegBase_Cons_dApp2)\napply (rule Occ_shift_cardinal)\napply (unfold dLamDegBase_def)\napply (rule subset_trans)\napply (assumption | rule dOcc_domain Collect_subset)+\ndone\n\nlemmas dLamDeg_eqns = dLamDeg_Nil dLamDeg_Cons_dLam dLamDeg_Cons_dApp1\n dLamDeg_Cons_dApp2\n\n\n(** dFV **)\nlemma dFV_I:\n \"[| : dOcc(M); M: dTerm |] ==> x: dFV(M)\"\napply (unfold dFV_def)\napply (frule dOcc_typeD2)\napply assumption\napply (erule dTag_typeEs)\napply (assumption | rule exI CollectI)+\ndone\n\nlemma dFV_I2:\n \"[| : dOcc(M); x: LVariable |] ==> x: dFV(M)\"\napply (unfold dFV_def)\napply (assumption | rule exI CollectI)+\ndone\n\nlemma dFV_E:\n \"[| x: dFV(M); !!l. [| x: LVariable; : dOcc(M) |] ==> R |]\n ==> R\"\napply (unfold dFV_def)\napply blast\ndone\n\nlemma dFV_Fin:\n \"M: dTerm ==> dFV(M): Fin(LVariable)\"\napply (unfold dFV_def)\napply (erule dTerm_Occ_ind_cond_Occ_FinI [THEN Fin_induct])\napply simp\napply (erule SigmaE)\napply (erule dTag.cases)\napply safe\napply (rule_tac P=\"%x. x: Fin(LVariable)\" in ssubst)\napply (erule_tac [2] Fin.intros)\nprefer 2 apply assumption\napply (rule_tac [2] P=\"%x. x: Fin(LVariable)\" in ssubst)\nprefer 3 apply assumption\napply (rule_tac [3] P=\"%x. x: Fin(LVariable)\" in ssubst)\nprefer 4 apply assumption\napply (rule_tac [4] P=\"%x. x: Fin(LVariable)\" in ssubst)\nprefer 5 apply assumption\napply (rule equalityI, blast elim!: dTag.free_elims,\n blast elim!: dTag.free_elims)+\ndone\n\nlemma dFV_not_in_lemma:\n \"[| x ~: dFV(M); M: dTerm |] ==> ~(EX l. : dOcc(M))\"\napply (blast intro!: dFV_I)\ndone\n\nlemma dFV_dVar:\n \"x: LVariable ==> dFV(dVar(x)) = {x}\"\napply (rule equalityI)\napply (safe elim!: dOcc_dTermEs dFV_E dTag.free_elims)\napply (assumption | rule dFV_I dTerm.intros dOcc_dTermIs)+\ndone\n\nlemma dFV_dBound:\n \"dFV(dBound(x)) = 0\"\napply (rule equalityI)\napply (safe elim!: dOcc_dTermEs dFV_E dTag.free_elims)\ndone\n\nlemma dFV_dLam:\n \"M: dTerm ==> dFV(dLam(M)) = dFV(M)\"\napply (rule equalityI)\napply (safe elim!: dOcc_dTermEs dFV_E dTag.free_elims)\napply (assumption | rule dFV_I dTerm.intros dOcc_dTermIs)+\ndone\n\nlemma dFV_dApp:\n \"[| M: dTerm; N: dTerm |] ==> dFV(dApp(M, N)) = dFV(M) Un dFV(N)\"\napply (rule equalityI)\napply (safe elim!: dOcc_dTermEs dFV_E dTag.free_elims)\napply (erule_tac [2] swap)\napply (assumption | rule dFV_I dTerm.intros\n | erule dOcc_dTermIs)+\ndone\n\nlemmas dFV_eqns = dFV_dVar dFV_dBound dFV_dApp dFV_dLam\n\ndeclare nat_ltI [simp del]\nlemmas dTerm_ss_simps = nat_succ_Un Un_diff (* dArity_eqns *)\n (* add_0_right add_succ_right *) gt_not_eq lt_asym_if\n le_asym_if not_lt_iff_le lt_irrefl_if\n diff_le_iff lt_diff_iff diff_diff_eq_diff_add\n Un_least_lt_iff [OF nat_into_Ord nat_into_Ord]\n dLift_eqns dSubst_eqns dsubterm_eqns dDeg_eqns\n dAbst_eqns dLamDeg_eqns dFV_eqns\nlemmas dTerm_ss_typechecks = dDeg_type dAbst_type\n dSubst_type dLift_type dLamDeg_type dTerm.intros\n nat_UnI\n\ndeclare dTerm_ss_simps [simp]\ndeclare dTerm_ss_typechecks [TC]\n(* declare split_if [split del] *)\n\n\n(** dProp **)\nlemma dPropI:\n \"[| M: dTerm; dDeg(M) = 0 |] ==> M: dProp\"\napply (unfold dProp_def)\napply blast\ndone\n\nlemma dPropE:\n \"[| M: dProp; [| M: dTerm; dDeg(M) = 0 |] ==> R |] ==> R\"\napply (unfold dProp_def)\napply blast\ndone\n\nlemma dPropD1:\n \"M: dProp ==> M: dTerm\"\napply (unfold dProp_def)\napply (erule CollectD1)\ndone\n\nlemma dPropD2:\n \"M: dProp ==> dDeg(M) = 0\"\napply (unfold dProp_def)\napply (erule CollectD2)\ndone\n\nlemma dProp_dVarI:\n \"x: LVariable ==> dVar(x): dProp\"\napply (blast intro: dPropI dDeg_eqns)\ndone\n\nlemma dProp_dLamI1:\n \"M: dProp ==> dLam(M): dProp\"\napply (erule dPropE)\napply (rule dPropI)\nprefer 2 apply simp\napply (assumption | rule dTerm.intros)+\ndone\n\nlemma dProp_dLamI2:\n \"[| M: dTerm; dDeg(M) = 1 |] ==> dLam(M): dProp\"\napply (rule dPropI)\nprefer 2 apply simp\napply (assumption | rule dTerm.intros)+\ndone\n\nlemma dProp_dAppI:\n \"[| A: dProp; B: dProp |] ==> dApp(A, B): dProp\"\napply (erule dPropE)+\napply (rule dPropI)\nprefer 2 apply simp\napply (assumption | rule dTerm.intros)+\ndone\n\nlemmas dProp_dTermIs = dProp_dVarI dProp_dLamI1 dProp_dLamI2 dProp_dAppI\n\nlemma dProp_dVarE:\n \"[| dVar(x): dProp; x: LVariable ==> R |] ==> R\"\napply (blast elim!: dPropE dTerm_typeEs)\ndone\n\nlemma dProp_dBoundE:\n \"dBound(n): dProp ==> R\"\napply (erule dPropE)\napply (simp only: dDeg_eqns)\napply (erule succ_neq_0)\ndone\n\nlemma dProp_dLamE:\n assumes major: \"dLam(M): dProp\"\n and \"M: dProp ==> R\"\n and \"[| M: dTerm; dDeg(M) = 1 |] ==> R\"\n shows \"R\"\napply (rule major [THEN dPropE])\napply (simp only: dDeg_eqns)\napply (erule dTerm_typeEs)\napply (rule dDeg_type [THEN natE])\napply assumption\napply (rotate_tac [2] 1)\nprefer 2 apply simp\napply (blast intro: dPropI assms)+\ndone\n\nlemma dProp_dAppE:\n assumes major: \"dApp(A, B): dProp\"\n and prem: \"[| A: dProp; B: dProp |] ==> R\"\n shows \"R\"\napply (rule major [THEN dPropE])\napply (simp only: dDeg_eqns)\napply (erule dTerm_typeEs)\napply (rule prem)\napply (rule_tac [2] dPropI)\napply (rule dPropI)\nprefer 3\napply assumption+\napply (rule_tac [2] equals0I, drule_tac [2] equals0D)\napply (rule_tac [1] equals0I, drule_tac [1] equals0D)\napply (erule notE, erule UnI1)\napply (erule notE, erule UnI2)\ndone\n\nlemmas dProp_dTermEs = dProp_dVarE dProp_dBoundE dProp_dLamE dProp_dAppE\n\nlemma dProp_induct:\n assumes major: \"M: dProp\"\n and prem1:\n \"!! x. x: LVariable ==> P(dVar(x))\"\n and prem2:\n \"!! M. [| M: dProp; P(M) |] ==> P(dLam(M))\"\n and prem3:\n \"!! M. [| M: dTerm; dDeg(M) = 1 |] ==> P(dLam(M))\"\n and prem4:\n \"!! A B. [| A: dProp; P(A); B: dProp; P(B) |] ==> P(dApp(A, B))\"\n shows \"P(M)\"\napply (rule major [THEN dPropD2, THEN rev_mp])\napply (rule major [THEN dPropD1, THEN dTerm.induct])\nprefer 4\napply (rule impI)\napply simp\napply (erule conjE)\nprefer 4\napply (rule impI)\napply simp\nprefer 4\napply (rule impI)\napply simp\nprefer 3\napply (rule impI)\napply simp\napply (erule prem1)\napply (drule diff_eq_0D)\napply (assumption | rule dDeg_type nat_1I)+\napply (drule le_succ_iff [THEN iffD1])\napply (erule disjE)\napply (drule le0_iff [THEN iffD1])\napply (rule_tac [3] prem4)\napply (rule_tac [2] prem3)\napply (rule prem2)\napply (safe intro!: dPropI)\ndone\n\n\n(** dBoundBy **)\nlemma dBoundByI:\n \"[| M: dTerm; : dOcc(M); : dOcc(M);\n m = l @ x; dLamDeg(x, dsubterm(M, l)) = succ(n)\n |] ==> dBoundBy(, , M)\"\napply (unfold dBoundBy_def)\napply blast\ndone\n\nlemma dBoundByE:\n assumes major: \"dBoundBy(u, v, M)\"\n and prem:\n \"!! l n x. [| u = ; v = ;\n M: dTerm; l: list(nat); x: list(nat);\n : dOcc(M); : dOcc(M);\n dLamDeg(x, dsubterm(M, l)) = succ(n)\n |] ==> R\"\n shows \"R\"\napply (rule major [unfolded dBoundBy_def, THEN conjE])\napply (erule conjE exE)+\napply (rule prem)\napply safe\napply (assumption | rule refl)+\napply (drule_tac [2] dOcc_typeD1, erule_tac [3] app_typeD)\napply (assumption | rule refl | erule dOcc_typeD1)+\ndone\n\nlemma dBoundByD1:\n \"dBoundBy(u, v, M) ==> M: dTerm\"\napply (unfold dBoundBy_def)\napply (erule conjunct1)\ndone\n\nlemma dBoundBy_dLamI1:\n \"[| M: dTerm; dLamDeg(m, M) = n; : dOcc(M) |] ==>\n dBoundBy(, <[], TdLam>, dLam(M))\"\napply (rule dBoundByI)\napply (rule_tac [4] app_Nil [THEN sym])\napply (drule_tac [4] dOcc_typeD1)\nprefer 5 apply simp\napply (assumption | rule nat_succI nat_0I dOcc_dTermIs\n dTerm.intros list.intros)+\ndone\n\nlemma dBoundBy_dLamI2:\n \"dBoundBy(, , M) ==>\n dBoundBy(, , dLam(M))\"\napply (erule dBoundByE)\napply safe\napply (rule dBoundByI)\napply (rule_tac [4] app_Cons [THEN sym])\nprefer 4 apply simp\napply (assumption | rule nat_succI nat_0I initseg_ConsI\n dOcc_dTermIs dTerm.intros)+\ndone\n\nlemma dBoundBy_dAppI1:\n \"[| dBoundBy(, , A); B: dTerm |] ==>\n dBoundBy(, , dApp(A, B))\"\napply (erule dBoundByE)\napply safe\napply (rule dBoundByI)\napply (rule_tac [4] app_Cons [THEN sym])\nprefer 4 apply simp\napply (assumption | rule nat_succI nat_0I initseg_ConsI\n dOcc_dTermIs dTerm.intros)+\ndone\n\nlemma dBoundBy_dAppI2:\n \"[| dBoundBy(, , B); A: dTerm |] ==>\n dBoundBy(, , dApp(A, B))\"\napply (erule dBoundByE)\napply safe\napply (rule dBoundByI)\napply (rule_tac [4] app_Cons [THEN sym])\nprefer 4 apply simp\napply (assumption | rule nat_succI nat_0I initseg_ConsI\n dOcc_dTermIs dTerm.intros)+\ndone\n\nlemmas dBoundBy_dTermIs = dBoundBy_dLamI1 dBoundBy_dLamI2\n dBoundBy_dAppI1 dBoundBy_dAppI2\n\nlemma dBoundBy_dBoundE:\n \"dBoundBy(u, v, dBound(n)) ==> R\"\napply (erule dBoundByE)\napply (erule dOcc_dTermEs)+\napply (blast elim!: dTag.free_elims)\ndone\n\nlemma dBoundBy_dVarE:\n \"dBoundBy(u, v, dVar(x)) ==> R\"\napply (erule dBoundByE)\napply (erule dOcc_dTermEs)+\napply (blast elim!: dTag.free_elims)\ndone\n\nlemma dBoundBy_dLamE:\n assumes major: \"dBoundBy(u, v, dLam(M))\"\n and prem1:\n \"!! m. [| u = ; v = <[], TdLam>;\n M: dTerm; : dOcc(M)\n |] ==> R\"\n and prem2:\n \"!! l m n. [| u = ; v = ;\n dBoundBy(, , M)\n |] ==> R\"\n shows \"R\"\napply (rule major [THEN dBoundByE])\napply (erule dTerm_typeEs)\napply (rotate_tac 7)\napply (erule dOcc_dTermEs)\napply (erule_tac [2] dOcc_dTermEs)\napply (rule_tac [3] prem2)\napply (rule_tac [2] prem1)\napply (safe elim!: dTag.free_elims dTerm_typeEs list.free_elims)\napply (rotate_tac [1] 3)\napply (rotate_tac [2] 3)\napply (rotate_tac [3] 3)\napply simp_all\napply hypsubst\nprefer 2 apply hypsubst\nprefer 3 apply hypsubst\napply (assumption | rule refl dBoundByI conjI)+\ndone\n\nlemma dBoundBy_dAppE:\n assumes major: \"dBoundBy(u, v, dApp(A, B))\"\n and prem1:\n \"!! l m n. [| u = ; v = ;\n dBoundBy(, , A); B: dTerm\n |] ==> R\"\n and prem2:\n \"!! l m n. [| u = ; v = ;\n dBoundBy(, , B); A: dTerm\n |] ==> R\"\n shows \"R\"\napply (rule major [THEN dBoundByE])\napply (erule dTerm_typeEs)\napply (erule dOcc_dTermEs)\napply (erule_tac [3] dOcc_dTermEs)\napply (erule_tac [2] dOcc_dTermEs)\napply (rule_tac [7] prem2)\napply (rule_tac [3] prem1)\napply (safe elim!: ConsE dTag.free_elims dOcc_dTermEs\n dTerm_typeEs list.free_elims)\napply (simp_all only: app_Nil app_Cons)\napply (safe elim!: list.free_elims)\napply (rotate_tac [2] 2)\napply (rotate_tac [1] 2)\napply simp_all\napply (assumption | rule dBoundByI refl)+\ndone\n\nlemmas dBoundBy_dTermEs = dBoundBy_dVarE dBoundBy_dBoundE\n dBoundBy_dLamE dBoundBy_dAppE\n\n\n(** Some Lemmas **)\nlemma dDeg_dAbst_lemma1:\n assumes major: \"M: dTerm\"\n and prem1: \"x ~: dFV(M)\"\n and prem2: \"n: nat\"\n shows \"dAbst(M, x, n) = M\"\napply (rule prem1 [THEN rev_mp])\napply (rule prem2 [THEN [2] bspec])\napply (rule major [THEN dTerm.induct])\napply simp_all\ndone\n\nlemma dDeg_dAbst_lemma2:\n assumes major: \"M: dTerm\"\n and prem1: \"x: dFV(M)\"\n and prem2: \"n: nat\"\n shows \"dDeg(dAbst(M, x, n)) = succ(n) Un dDeg(M)\"\napply (rule prem1 [THEN rev_mp])\napply (rule prem2 [THEN [2] bspec])\napply (rule major [THEN dTerm.induct])\napply (safe elim!: dProp_dTermEs dOcc_dTermEs dTag.free_elims)\napply simp_all\napply (erule disjE)\napply (case_tac [2] \"x: dFV(M)\")\napply (case_tac [1] \"x: dFV(N)\")\napply (simp_all add: dDeg_dAbst_lemma1)\napply blast+\ndone\n\nlemma dDeg_dLift_lemma1:\n assumes major: \"dDeg(M) le n\"\n and prem1: \"M: dTerm\"\n and prem2: \"n: nat\"\n shows \"dLift(M, n) = M\"\napply (rule major [THEN rev_mp])\napply (rule prem2 [THEN [2] bspec])\napply (rule prem1 [THEN dTerm.induct])\napply simp_all\ndone\n\nlemma dDeg_dLift_lemma2:\n assumes major: \"n < dDeg(M)\"\n and prem1: \"M: dTerm\"\n and prem2: \"n: nat\"\n shows \"dDeg(dLift(M, n)) = succ(dDeg(M))\"\napply (rule major [THEN rev_mp])\napply (rule prem2 [THEN [2] bspec])\napply (rule prem1 [THEN dTerm.induct])\napply safe\napply simp_all\napply (rule dDeg_type [THEN natE])\napply assumption\napply (rotate_tac [2] 4)\napply (rotate_tac [1] 4)\napply simp_all\napply (rule_tac i=\"dDeg(N)\" and j=\"dDeg(M)\" in Ord_linear_lt)\napply (rule_tac [5] i=\"x\" and j=\"dDeg(M)\" in Ord_linear2)\napply (rule_tac [3] i=\"x\" and j=\"dDeg(N)\" in Ord_linear2)\nprefer 8\nprefer 9\napply (assumption | rule nat_into_Ord dDeg_type)+\napply (simp_all add: dDeg_dLift_lemma1 lt_Un_eq_lemma\n trans [OF Un_commute lt_Un_eq_lemma])\napply (rule_tac [2] lt_Un_eq_lemma)\napply (erule_tac [2] leI)\napply (rule trans [OF Un_commute lt_Un_eq_lemma])\napply (erule leI)\ndone\n\nlemma dDeg_dSubst_lemma1:\n assumes major: \"M: dTerm\"\n and prem1: \"dDeg(M) le n\"\n and prem2: \"n: nat\"\n and prem3: \"N: dTerm\"\n shows \"dSubst(M, n, N) = M\"\napply (rule prem1 [THEN rev_mp])\napply (rule prem2 [THEN [2] bspec])\napply (rule prem3 [THEN [2] bspec])\napply (rule major [THEN dTerm.induct])\napply safe\napply simp_all\ndone\n\nlemma dDeg_dSubst_lemma2:\n assumes major: \"M: dTerm\"\n and prem1: \"n < dDeg(M)\"\n and prem2: \"n: nat\"\n and prem3: \"N: dTerm\"\n shows \"dDeg(dSubst(M, n, N)) le (dDeg(M) #- 1) Un dDeg(N)\"\napply (rule prem1 [THEN rev_mp])\napply (rule prem3 [THEN [2] bspec])\napply (rule prem2 [THEN [2] bspec])\napply (rule major [THEN dTerm.induct])\napply safe\napply (case_tac [2] \"x = n\")\napply (simp_all split del: split_if)\napply (rule Un_upper2_le)\napply (assumption | rule nat_into_Ord dDeg_type)+\napply (subgoal_tac \"x < n\")\napply (erule_tac [2] swap, rule_tac [2] le_anti_sym)\napply (simp_all add: not_lt_imp_le\n [OF asm_rl nat_into_Ord nat_into_Ord]\n split del: split_if)\napply (rule_tac lt_trans2)\napply (rule_tac [2] Un_upper1_le)\napply (rule gt_pred)\napply (assumption | rule le_refl nat_into_Ord dDeg_type)+\n\napply (rule_tac M1=\"M\" in dDeg_type [THEN natE])\napply assumption\napply (rotate_tac [1] 5)\napply (rotate_tac [2] 5)\napply (rule_tac [3] i=\"dDeg(M)\" and j=\"dDeg(N)\" in Ord_linear_lt)\napply (erule_tac [3] asm_rl | rule_tac [3] nat_into_Ord dDeg_type)+\napply (frule_tac [5] c=\"dDeg(M)\" in trans [OF Un_commute lt_Un_eq_lemma])\napply (frule_tac [3] B=\"dDeg(N)\" in lt_Un_eq_lemma)\napply (rotate_tac [3] 8)\napply (rotate_tac [4] 7)\napply (rotate_tac [5] 8)\napply simp_all\napply (rule nat_succ_Un [THEN subst])\napply (rule_tac [3] succ_pred [THEN mp, THEN ssubst])\nprefer 5 apply assumption\napply (assumption | rule diff_type nat_succI nat_0I dDeg_type)+\n\napply (rule_tac i=\"0\" and j=\"dDeg(dSubst(M, succ(x), dLift(xa, 0)))\"\n in Ord_linear2)\napply (assumption | rule nat_into_Ord nat_0I nat_succI dDeg_type\n dSubst_type dLift_type)+\nprefer 2\napply simp\napply (rule lt_imp_0_lt)\napply (erule Un_upper1_lt)\napply (assumption | rule nat_into_Ord dDeg_type nat_succI)+\napply (rule gt_pred)\nprefer 2 apply assumption\napply (drule_tac x2=\"succ(x)\" and x=\"dLift(xa, 0)\" in bspec [THEN mp, THEN bspec])\nprefer 4\napply (erule le_trans)\napply (rule_tac M1=\"xa\" in dDeg_type [THEN natE])\napply assumption\napply (simp add: dDeg_dLift_lemma1)\napply (rule Un_upper1_le)\nprefer 3\napply (rule dDeg_dLift_lemma2 [THEN ssubst])\napply simp\napply (assumption | rule nat_succI nat_into_Ord dDeg_type\n nat_0I dLift_type le_refl nat_UnI succ_leI dSubst_type)+\n\napply (rule_tac [2] i=\"x\" and j=\"dDeg(N)\" in Ord_linear2)\napply (rule_tac [1] i=\"x\" and j=\"dDeg(M)\" in Ord_linear2)\nprefer 5\nprefer 6\napply (assumption | rule nat_into_Ord dDeg_type)+\napply (simp_all add: dDeg_dSubst_lemma1)\napply (drule_tac [1] x=\"xa\" in bspec [THEN mp, THEN bspec],\n erule_tac [1] asm_rl, erule_tac [1] asm_rl,\n erule_tac [1] asm_rl)+\napply (drule_tac [2] x=\"xa\" in bspec [THEN mp, THEN bspec],\n erule_tac [2] asm_rl, erule_tac [2] asm_rl,\n erule_tac [2] asm_rl)+\napply (drule_tac [3] x=\"xa\" in bspec [THEN mp, THEN bspec],\n erule_tac [3] asm_rl, erule_tac [3] asm_rl,\n erule_tac [3] asm_rl)+\napply (drule_tac [4] x=\"xa\" in bspec [THEN mp, THEN bspec],\n erule_tac [4] asm_rl, erule_tac [4] asm_rl,\n erule_tac [4] asm_rl)+\napply safe\nprefer 8 apply (erule le_trans)\nprefer 8 apply (erule le_trans)\nprefer 8 apply (erule le_trans)\nprefer 8 apply (erule le_trans)\nprefer 8 apply (erule le_trans)\nprefer 8 apply (erule le_trans)\nprefer 8 apply (erule le_trans)\nprefer 8 apply (erule le_trans)\napply simp_all\nprefer 4\nprefer 5\nprefer 6\nprefer 7\napply (rule conjI)\napply (rule_tac [2] Un_upper2_le)\napply (rule Un_upper1_le [THEN le_trans])\napply (rule_tac [3] Un_upper1_le)\napply (assumption | rule nat_into_Ord dDeg_type diff_type\n nat_0I nat_succI nat_UnI)+\n\napply (rule conjI)\napply (rule_tac [2] Un_upper2_le)\napply (rule Un_upper2_le [THEN le_trans])\napply (rule_tac [3] Un_upper1_le)\napply (assumption | rule nat_into_Ord dDeg_type diff_type\n nat_0I nat_succI nat_UnI)+\n\napply (rule conjI)\napply (rule_tac [2] Un_upper2_le)\napply (rule Un_upper1_le [THEN le_trans])\napply (rule_tac [3] Un_upper1_le)\napply (assumption | rule nat_into_Ord dDeg_type diff_type\n nat_0I nat_succI nat_UnI)+\n\napply (rule conjI)\napply (rule_tac [2] Un_upper2_le)\napply (rule Un_upper2_le [THEN le_trans])\napply (rule_tac [3] Un_upper1_le)\napply (assumption | rule nat_into_Ord dDeg_type diff_type\n nat_0I nat_succI nat_UnI)+\n\napply (rule conjI)\napply (rule_tac [2] Un_upper2_le)\napply (rule Un_upper1_le [THEN le_trans])\napply (rule_tac [3] Un_upper1_le)\napply (assumption | rule nat_into_Ord dDeg_type diff_type\n nat_0I nat_succI nat_UnI)+\n\napply (rule conjI)\napply (rule_tac [2] Un_upper2_le)\napply (rule Un_upper2_le [THEN le_trans])\napply (rule_tac [3] Un_upper1_le)\napply (assumption | rule nat_into_Ord dDeg_type diff_type\n nat_0I nat_succI nat_UnI)+\n\napply (rule_tac j=\"dDeg(N) #- 1\" in le_trans)\napply (erule lt_imp_le_pred)\nprefer 2\napply (rule Un_upper2_le [THEN le_trans])\napply (rule_tac [3] Un_upper1_le)\napply (assumption | rule nat_into_Ord dDeg_type diff_type\n nat_0I nat_succI nat_UnI)+\n\napply (rule_tac j=\"dDeg(M) #- 1\" in le_trans)\napply (erule lt_imp_le_pred)\nprefer 2\napply (rule Un_upper1_le [THEN le_trans])\napply (rule_tac [3] Un_upper1_le)\napply (assumption | rule nat_into_Ord dDeg_type diff_type\n nat_0I nat_succI nat_UnI)+\n\ndone\n\nlemma dDeg_dSubst_lemma3:\n assumes prem1: \"M: dTerm\"\n and prem2: \"dDeg(M) = 1\"\n and prem3: \"N: dProp\"\n shows \"dSubst(M, 0, N): dProp\"\napply (insert prem1 prem2 prem3 [THEN dPropD1] prem3 [THEN dPropD2])\napply (rule_tac M1=\"M\" and n1=\"0\" and N1=\"N\" in\n dDeg_dSubst_lemma2 [THEN revcut_rl])\napply (rule_tac [2] prem2 [THEN ssubst])\napply (assumption | rule le_refl nat_0I nat_into_Ord)+\napply simp\napply (assumption | rule dPropI dSubst_type nat_0I)+\ndone\n\nlemma dSubst_dAbst_lemma:\n assumes prem1: \"M: dTerm\"\n and prem2: \"x: LVariable\"\n and prem3: \"n: nat\"\n and prem4: \"dDeg(M) le n\"\n shows \"dSubst(dAbst(M, x, n), n, dVar(x)) = M\"\napply (insert prem2)\napply (rule prem4 [THEN rev_mp])\napply (rule prem3 [THEN [2] bspec])\napply (rule prem1 [THEN dTerm.induct])\napply safe\napply (case_tac \"x = xa\")\napply simp_all\ndone\n\nlemma dSubst_dAbst_lemma2:\n assumes major: \"M: dProp\"\n and prem: \"x: LVariable\"\n shows \"dSubst(dAbst(M, x, 0), 0, dVar(x)) = M\"\napply (rule dSubst_dAbst_lemma)\napply (rule_tac [4] major [THEN dPropD2, THEN ssubst])\napply (assumption | rule major [THEN dPropD1] prem nat_0I\n Ord_0 le_refl)+\ndone\n\nlemma dSubst_dAbst_lemma3:\n assumes prem1: \"dDeg(M) le n\"\n and prem2: \"M: dTerm\"\n and prem3: \"N: dTerm\"\n and prem4: \"n: nat\"\n shows \"dSubst(dAbst(M, x, succ(n)), succ(n), N) =\n dSubst(dAbst(M, x, n), n, N)\"\napply (rule prem1 [THEN rev_mp])\napply (rule prem3 [THEN [2] bspec])\napply (rule prem4 [THEN [2] bspec])\napply (rule prem2 [THEN dTerm.induct])\napply (rule_tac [2] ballI)\napply (case_tac [2] \"xa = n\")\napply (case_tac \"x = xa\")\napply simp_all\napply safe\napply (subgoal_tac \"succ(x) ~= n\" \"~ succ(x) < n\")\napply simp\napply safe\napply (drule_tac [2] leI [THEN succ_le_iff [THEN iffD1]])\napply (erule_tac [2] lt_irrefl)\napply (drule lt_trans, assumption)\napply (drule leI [THEN succ_le_iff [THEN iffD1]],\n erule lt_irrefl)\ndone\n\nlemma dAbst_dSubst_lemma:\n assumes prem1: \"M: dTerm\"\n and prem2: \"x: LVariable\"\n and prem3: \"x ~: dFV(M)\"\n and prem4: \"n: nat\"\n and prem5: \"dDeg(M) le succ(n)\"\n shows \"dAbst(dSubst(M, n, dVar(x)), x, n) = M\"\napply (insert prem2)\napply (rule prem3 [THEN rev_mp])\napply (rule prem5 [THEN rev_mp])\napply (rule prem4 [THEN [2] bspec])\napply (rule prem1 [THEN dTerm.induct])\napply safe\napply (case_tac [2] \"xa = n\")\napply (case_tac [3] \"xa < n\")\napply simp_all\napply (drule lt_trans2, assumption)\napply (erule lt_irrefl)\ndone\n\nlemma dAbst_dLift_lemma:\n assumes prem1: \"m le n\"\n and prem2: \"M: dTerm\"\n and prem3: \"n: nat\"\n and prem4: \"m: nat\"\n shows \"dAbst(dLift(M, m), x, succ(n))\n = dLift(dAbst(M, x, n), m)\"\napply (rule prem1 [THEN rev_mp])\napply (rule prem3 [THEN [2] bspec])\napply (rule prem4 [THEN [2] bspec])\napply (rule prem2 [THEN dTerm.induct])\napply safe\napply (case_tac [2] \"xa = n\")\napply (case_tac [3] \"n < xa\")\napply (case_tac [1] \"x = xa\")\napply simp_all\ndone\n\nlemma dAbst_dSubst_lemma2:\n assumes prem1: \"m le n\"\n and prem3: \"M: dTerm\"\n and prem4: \"N: dTerm\"\n and prem5: \"n: nat\"\n and prem6: \"m: nat\"\n shows \"dAbst(dSubst(M, m, N), x, n)\n = dSubst(dAbst(M, x, succ(n)), m, dAbst(N, x, n))\"\napply (rule prem1 [THEN rev_mp])\napply (rule prem4 [THEN [2] bspec])\napply (rule prem5 [THEN [2] bspec])\napply (rule prem6 [THEN [2] bspec])\napply (rule prem3 [THEN dTerm.induct])\napply safe\napply (case_tac [2] \"xa = n\")\napply (case_tac [3] \"xa < n\")\napply (case_tac \"x = xa\")\napply (simp_all add: dAbst_dLift_lemma)\ndone\n\nlemma dLift_dLift_lemma:\n assumes prem1: \"m le n\"\n and prem2: \"M: dTerm\"\n and prem4: \"n: nat\"\n and prem5: \"m: nat\"\n shows \"dLift(dLift(M, m), succ(n)) = dLift(dLift(M, n), m)\"\napply (rule prem1 [THEN rev_mp])\napply (rule prem4 [THEN [2] bspec])\napply (rule prem5 [THEN [2] bspec])\napply (rule prem2 [THEN dTerm.induct])\napply simp_all\napply safe\napply (frule le_anti_sym, assumption)\napply hypsubst\napply assumption\napply (erule lt_trans, assumption)\napply (erule lt_trans1, assumption)\napply (erule lt_trans, assumption)\ndone\n\nlemma dLift_dSubst_lemma:\n assumes prem1: \"m le n\"\n and prem2: \"M: dTerm\"\n and prem3: \"N: dTerm\"\n and prem4: \"n: nat\"\n and prem5: \"m: nat\"\n shows \"dLift(dSubst(M, n, N), m) = dSubst(dLift(M, m), succ(n),\n dLift(N, m))\"\napply (rule prem1 [THEN rev_mp])\napply (rule prem3 [THEN [2] bspec])\napply (rule prem4 [THEN [2] bspec])\napply (rule prem5 [THEN [2] bspec])\napply (rule prem2 [THEN dTerm.induct])\napply (simp_all add: dLift_dLift_lemma)\napply safe\napply (drule_tac i=\"n\" in lt_trans2, assumption)\napply (erule lt_irrefl)\napply (drule_tac i=\"succ(xa)\" in lt_trans2, assumption)\napply simp\napply (drule_tac i=\"n\" in lt_trans2, assumption)\napply (drule_tac i=\"xa\" and j=\"n\" and k=\"xa\" in lt_trans, assumption)\napply (erule lt_irrefl)\napply (drule_tac i=\"succ(xa)\" in lt_trans2, assumption)\napply simp\napply (drule_tac i=\"x\" and k=\"n\" in lt_trans1, assumption)\napply (erule_tac n=\"n\" in natE)\napply hypsubst\napply (erule lt0E)\napply hypsubst\napply simp\napply (drule_tac i=\"xb\" and k=\"xb\" in lt_trans2, assumption)\napply (erule lt_irrefl)\napply (drule_tac i=\"n\" and k=\"n\" in lt_trans2, assumption)\napply (erule lt_irrefl)\napply (drule_tac i=\"succ(xa)\" and k=\"xa\" in lt_trans2, assumption)\napply simp\napply (drule_tac i=\"n\" and k=\"xa\" in lt_trans2, assumption)\napply (drule_tac i=\"n\" and k=\"n\" in lt_trans, assumption)\napply (erule lt_irrefl)\napply (drule_tac i=\"n\" and k=\"xa\" in lt_trans2, assumption)\napply (drule_tac i=\"n\" and k=\"n\" in lt_trans, assumption)\napply (erule lt_irrefl)\napply (drule_tac i=\"n\" and k=\"n #- 1\" in lt_trans2, assumption)\napply simp\napply (erule_tac n=\"n\" in natE)\napply hypsubst\napply simp\napply hypsubst\napply simp\ndone\n\nlemma dSubst_dSubst_lemma1:\n assumes prema: \"dDeg(M) le succ(m)\"\n and prem0: \"dDeg(A) = 0\"\n and prem1: \"m le n\"\n and prem2: \"M: dTerm\"\n and prem3: \"A: dTerm\"\n and prem4: \"B: dTerm\"\n and prem5: \"n: nat\"\n and prem6: \"m: nat\"\n shows \"dSubst(dSubst(M, m, A), n, B) =\n dSubst(dSubst(M, succ(n), dLift(B, 0)), m, A)\"\napply (rule prema [THEN rev_mp])\napply (rule prem0 [THEN rev_mp])\napply (rule prem1 [THEN rev_mp])\napply (rule prem3 [THEN [2] bspec])\napply (rule prem4 [THEN [2] bspec])\napply (rule prem5 [THEN [2] bspec])\napply (rule prem6 [THEN [2] bspec])\napply (rule prem2 [THEN dTerm.induct])\napply (simp_all add: dDeg_dLift_lemma1 split del: split_if)\napply safe\napply (case_tac \"x = n\")\napply (subgoal_tac [2] \"n < x\" \"n < xa\")\napply (erule_tac [4] swap, rule_tac [4] le_anti_sym)\napply (erule_tac [3] lt_trans2, erule_tac [3] asm_rl)\napply hypsubst\napply (simp_all split del: split_if add: leI dDeg_dSubst_lemma1)\ndone\n\nlemma dSubst_dSubst_lemma2:\n assumes prem0: \"dDeg(B) = 0\"\n and prem1: \"m le n\"\n and prem2: \"M: dTerm\"\n and prem3: \"A: dTerm\"\n and prem4: \"B: dTerm\"\n and prem5: \"n: nat\"\n and prem6: \"m: nat\"\n shows \"dSubst(dSubst(M, m, A), n, B) =\n dSubst(dSubst(M, succ(n), B), m, dSubst(A, n, B))\"\napply (rule prem0 [THEN rev_mp])\napply (rule prem1 [THEN rev_mp])\napply (rule prem3 [THEN [2] bspec])\napply (rule prem4 [THEN [2] bspec])\napply (rule prem5 [THEN [2] bspec])\napply (rule prem6 [THEN [2] bspec])\napply (rule prem2 [THEN dTerm.induct])\napply (simp_all split del: split_if\n add: dDeg_dLift_lemma1 dLift_dSubst_lemma)\napply safe\napply (rule_tac i=\"n\" and j=\"x\" in Ord_linear_lt)\napply (assumption | rule nat_into_Ord)+\napply (subgoal_tac \"n < xa\")\napply (erule_tac [2] lt_trans2, erule_tac [2] asm_rl)\napply (rule_tac [3] i=\"n\" and j=\"succ(xa)\" in Ord_linear_lt)\napply (erule_tac [3] asm_rl | rule_tac [3] nat_into_Ord nat_succI)+\napply (subgoal_tac [5] \"succ(x) < n\")\napply (subgoal_tac [3] \"xa ~= n #- 1\")\napply (simp_all split del: split_if\n add: leI dDeg_dSubst_lemma1 not_lt_iff_le [OF nat_into_Ord nat_into_Ord])\napply (rule_tac [2] j=\"succ(xa)\" in lt_trans1)\nprefer 3 apply assumption\napply (erule_tac n=\"n\" in natE)\napply safe\napply simp\napply (erule lt_irrefl)\ndone\n\nlemma dFV_dAbst:\n assumes major: \"M: dTerm\"\n and prem: \"n:nat\"\n shows \"dFV(dAbst(M, x, n)) = dFV(M) - {x}\"\napply (rule prem [THEN rev_bspec])\napply (rule major [THEN dTerm.induct])\napply (case_tac \"x = xa\")\napply simp_all\napply blast+\ndone\n\nlemma dDeg_dLamDeg_lemma1:\n assumes prem1: \"M: dTerm\"\n and prem2: \": dOcc(M)\"\n shows \"n < dDeg(M) #+ dLamDeg(l, M)\"\napply (rule prem2 [THEN rev_mp])\napply (rule_tac x=\"l\" in spec)\napply (rule prem1 [THEN dTerm.induct])\napply (safe elim!: dOcc_dTermEs dTag.free_elims)\napply (frule_tac [4] dOcc_typeD1, erule_tac [4] asm_rl)\napply (frule_tac [3] dOcc_typeD1, erule_tac [3] asm_rl)\napply (frule_tac [2] dOcc_typeD1, erule_tac [2] asm_rl)\napply (simp_all split del: split_if)\napply (rule dDeg_type [THEN natE])\napply assumption\napply (rotate_tac [1] 4)\napply (rotate_tac [2] 4)\napply simp\nprefer 2\napply simp\napply (drule_tac [3] spec [THEN mp], erule_tac [3] asm_rl)\napply (drule_tac [2] spec [THEN mp], erule_tac [2] asm_rl)\napply (drule_tac [1] spec [THEN mp], erule_tac [1] asm_rl)\napply (erule leI)\napply (erule_tac [2] lt_trans2)\napply (rule_tac [2] add_le_mono1)\napply (erule_tac [1] lt_trans2)\napply (rule_tac [1] add_le_mono1)\napply (assumption | rule dLamDeg_type dDeg_type nat_UnI\n Un_upper1_le Un_upper2_le nat_into_Ord)+\ndone\n\nlemma dDeg_0_lemma:\n assumes prem1: \"M: dTerm\"\n and prem2: \"~(EX l n. : dOcc(M))\"\n shows \"dDeg(M) = 0\"\napply (rule prem2 [THEN rev_mp])\napply (rule prem1 [THEN dTerm.induct])\napply (simp_all split del: split_if)\napply (assumption | rule exI dOcc_dTermIs)+\napply (safe elim!: dOcc_dTermEs dTag.free_elims)\nprefer 2 apply simp\nprefer 5 apply simp\napply (blast intro: dOcc_dTermIs)+\ndone\n\nlemma dDeg_dLamDeg_lemma2:\n assumes prem1: \"M: dTerm\"\n and prem2: \"EX l n. : dOcc(M)\"\n shows \"EX l n. : dOcc(M) &\n dDeg(M) = succ(n) #- dLamDeg(l, M)\"\napply (rule prem2 [THEN rev_mp])\napply (rule prem1 [THEN dTerm.induct])\napply (safe elim!: dOcc_dTermEs dTag.free_elims)\nprefer 2 apply (erule swap, rule exI [THEN exI], assumption)\nprefer 3 apply (erule swap, rule exI [THEN exI], assumption)\nprefer 3 apply (erule swap, rule exI [THEN exI], assumption)\nprefer 3 apply (erule swap, rule exI [THEN exI], assumption)\nprefer 5 apply (erule swap, rule exI [THEN exI], assumption)\napply (rule exI [THEN exI])\napply (rule conjI)\napply (rule dOcc_dTermIs)\napply simp\napply (rule_tac x=\"Cons(0, lb)\" in exI)\napply (frule_tac l=\"lb\" in dOcc_typeD1, assumption)\napply (frule_tac T=\"TdBound(na)\" in dOcc_typeD2, assumption)\napply (erule dTag_typeEs)\napply (rule_tac [2] x=\"Cons(1, la)\" in exI)\napply (frule_tac [2] l=\"la\" in dOcc_typeD1, erule_tac [2] asm_rl)\napply (rule_tac [3] x=\"Cons(0, la)\" in exI)\napply (frule_tac [3] l=\"la\" in dOcc_typeD1, erule_tac [3] asm_rl)\napply (rule_tac [5] i=\"dDeg(M)\" and j=\"dDeg(N)\" in Ord_linear2)\napply (erule_tac [5] asm_rl | rule_tac [5] nat_into_Ord dDeg_type)+\napply (rule_tac [4] i=\"dDeg(M)\" and j=\"dDeg(N)\" in Ord_linear2)\napply (erule_tac [4] asm_rl | rule_tac [4] nat_into_Ord dDeg_type)+\napply (rule_tac [4] x=\"Cons(1, lb)\" in exI)\napply (frule_tac [4] l=\"lb\" in dOcc_typeD1, erule_tac [4] asm_rl)\napply (rule_tac [5] x=\"Cons(0, la)\" in exI)\napply (frule_tac [5] l=\"la\" in dOcc_typeD1, erule_tac [5] asm_rl)\napply (rule_tac [6] x=\"Cons(1, lb)\" in exI)\napply (frule_tac [6] l=\"lb\" in dOcc_typeD1, erule_tac [6] asm_rl)\napply (rule_tac [7] x=\"Cons(0, la)\" in exI)\napply (frule_tac [7] l=\"la\" in dOcc_typeD1, erule_tac [7] asm_rl)\napply (rule_tac [1] exI, rule_tac [1] conjI, erule_tac [1] dOcc_dTermIs)\napply (rule_tac [2] exI, rule_tac [2] conjI, erule_tac [2] dOcc_dTermIs)\napply (rule_tac [3] exI, rule_tac [3] conjI, erule_tac [3] dOcc_dTermIs)\napply (rule_tac [4] exI, rule_tac [4] conjI, erule_tac [4] dOcc_dTermIs)\napply (rule_tac [5] exI, rule_tac [5] conjI, erule_tac [5] dOcc_dTermIs)\napply (rule_tac [6] exI, rule_tac [6] conjI, erule_tac [6] dOcc_dTermIs)\napply (rule_tac [7] exI, rule_tac [7] conjI, erule_tac [7] dOcc_dTermIs)\napply (simp_all add: dDeg_0_lemma le_Un_eq_lemma lt_Un_eq_lemma del: not_ex)\napply (rule_tac [1] Un_commute [THEN subst])\napply (rule_tac [2] Un_commute [THEN subst])\napply (simp_all add: le_Un_eq_lemma)\ndone\n\nlemma dBoundBy_dLamDeg_lemma1:\n assumes major: \"dBoundBy(, v, M)\"\n shows \"succ(n) #- dLamDeg(l, M) = 0\"\napply (rule major [THEN rev_mp])\napply (rule_tac x=\"v\" in spec)\napply (rule_tac x=\"l\" and A=\"list(nat)\" in bspec)\napply (rule_tac x=\"n\" and A=\"nat\" in bspec)\napply (rule_tac [2] major [THEN dBoundByE])\napply (rule_tac [3] major [THEN dBoundByE])\napply (rule major [THEN dBoundByD1, THEN dTerm.induct])\napply (safe elim!: dBoundBy_dTermEs dTag.free_elims ConsE)\napply (erule_tac [6] asm_rl | rule_tac [6] app_type)+\napply (drule_tac [5] dOcc_typeD2)\napply (erule_tac [6] dTag_typeEs)\napply (erule_tac [5] asm_rl)+\napply (simp_all del: all_simps) \napply (drule bspec [THEN bspec, THEN spec, THEN mp])\nprefer 3 apply assumption\nprefer 3\napply (simp only: le0_iff [THEN iff_sym])\napply (rule le_trans)\nprefer 2 apply assumption\napply (assumption | rule diff_le_mono1 dLamDeg_type le_refl\n nat_into_Ord nat_succI leI)+\ndone\n\nlemma dBoundBy_dLamDeg_lemma2:\n assumes major: \"M: dTerm\"\n and prem1: \": dOcc(M)\"\n and prem2: \"n < dLamDeg(l, M)\"\n shows \"EX m. dBoundBy(, , M)\"\napply (rule prem1 [THEN rev_mp])\napply (rule prem2 [THEN rev_mp])\napply (rule_tac x=\"l\" and A=\"list(nat)\" in bspec)\napply (rule_tac x=\"n\" and A=\"nat\" in bspec)\napply (rule_tac [2] dOcc_typeD2 [OF prem1 major, THEN revcut_rl])\napply (rule_tac [3] dOcc_typeD1 [OF prem1 major])\napply (rule major [THEN dTerm.induct])\napply (safe elim!: dTag_typeEs dOcc_dTermEs ConsE dTag.free_elims)\napply (rotate_tac [2] 4)\napply (rotate_tac [3] 6)\napply (rotate_tac [4] 6)\napply simp_all\napply (erule leE)\nprefer 2\napply hypsubst\napply (rule exI)\napply (assumption | rule refl dBoundBy_dLamI1)+\napply (drule_tac [3] bspec [THEN bspec, THEN mp, THEN mp],\n erule_tac [5] asm_rl)\napply (drule_tac [2] bspec [THEN bspec, THEN mp, THEN mp],\n erule_tac [4] asm_rl)\napply (drule_tac [1] bspec [THEN bspec, THEN mp, THEN mp],\n erule_tac [3] asm_rl)\napply safe\napply (assumption | rule exI dBoundBy_dLamI2 dBoundBy_dAppI1\n dBoundBy_dAppI2)+\ndone\n\nlemma dProp_dBoundBy_lemma1:\n assumes major: \"M: dProp\"\n and prem: \": dOcc(M)\"\n shows \"EX l. dBoundBy(, , M)\"\napply (rule major [THEN dPropE])\napply (insert dDeg_dLamDeg_lemma1 [OF major [THEN dPropD1] prem])\napply (rule dBoundBy_dLamDeg_lemma2)\nprefer 3 apply simp\napply (assumption | rule prem)+\ndone\n\nlemma dProp_dBoundBy_lemma2:\n assumes major: \"M: dTerm\"\n and prem:\n \"ALL m n. : dOcc(M) -->\n (EX l. dBoundBy(, , M))\"\n shows \"M: dProp\"\napply (case_tac \"EX l n. : dOcc(M)\")\nprefer 2\napply (drule major [THEN dDeg_0_lemma])\napply (drule_tac [2] major [THEN dDeg_dLamDeg_lemma2])\napply (erule_tac [2] exE conjE)+\napply (rule_tac [2] prem [THEN spec, THEN spec, THEN mp, THEN exE])\nprefer 2 apply assumption\napply (drule_tac [2] dBoundBy_dLamDeg_lemma1)\napply (rotate_tac [2] 2)\nprefer 2 apply simp\napply (assumption | rule dPropI major)+\ndone\n\nlemma dOcc_dAbstI1:\n assumes prem1: \": dOcc(M)\"\n and prem2: \"M: dTerm\"\n and prem3: \"n: nat\"\n shows \": dOcc(dAbst(M, x, n))\"\napply (rule prem1 [THEN rev_mp])\napply (rule_tac x=\"l\" and A=\"list(nat)\" in bspec)\napply (rule_tac [2] dOcc_typeD1 [OF prem1 prem2])\napply (rule prem3 [THEN [2] bspec])\napply (rule prem2 [THEN dTerm.induct])\napply (safe elim!: dOcc_dTermEs dTag.free_elims ConsE)\napply simp_all\napply (rule_tac [4] dOcc_dTermIs)\napply (rule_tac [3] dOcc_dTermIs)\napply (rule_tac [2] dOcc_dTermIs)\napply (rule_tac [1] dOcc_dTermIs)\napply (drule bspec [THEN bspec, THEN mp])\nprefer 3 apply assumption\napply (erule nat_succI)\nprefer 2 apply simp\napply assumption\napply (erule_tac [2] bspec [THEN bspec, THEN mp])\napply (erule_tac [1] bspec [THEN bspec, THEN mp])\napply assumption+\ndone\n\nlemma dOcc_dAbstI2:\n assumes prem1: \": dOcc(M)\"\n and major: \"T ~= TdVar(x)\"\n and prem2: \"M: dTerm\"\n and prem3: \"n: nat\"\n shows \": dOcc(dAbst(M, x, n))\"\napply (insert major)\napply (rule prem1 [THEN rev_mp])\napply (rule_tac x=\"l\" and A=\"list(nat)\" in bspec)\napply (rule_tac [2] dOcc_typeD1 [OF prem1 prem2])\napply (rule prem3 [THEN [2] bspec])\napply (rule prem2 [THEN dTerm.induct])\napply (safe elim!: dOcc_dTermEs dTag.free_elims ConsE)\napply (subgoal_tac \"x ~= xa\")\nprefer 2 apply blast\napply simp_all\napply (safe intro!: dOcc_dTermIs)\napply (erule_tac [3] bspec [THEN bspec, THEN mp])\napply (erule_tac [2] bspec [THEN bspec, THEN mp])\napply (erule_tac [1] bspec [THEN bspec, THEN mp])\napply (assumption | rule nat_succI)+\ndone\n\nlemma dOcc_dAbstE_lemma:\n assumes major: \": dOcc(dAbst(M, x, n))\"\n and prem1: \"M: dTerm\"\n and prem2: \"n: nat\"\n and prem3:\n \"T = TdBound(n #+ dLamDeg(l, M)) & : dOcc(M) --> R\"\n and prem4: \": dOcc(M) --> R\"\n shows \"R\"\napply (rule prem4 [THEN rev_mp])\napply (rule prem3 [THEN rev_mp])\napply (rule major [THEN rev_mp])\napply (rule_tac x=\"l\" and A=\"list(nat)\" in bspec)\nprefer 2\napply (rule major [THEN dOcc_typeD1])\napply (assumption | rule dAbst_type prem1 prem2)+\napply (rule prem2 [THEN [2] bspec])\napply (rule prem1 [THEN dTerm.induct])\napply (case_tac \"x = xa\")\napply simp_all\napply (safe elim!: dOcc_dTermEs dTag.free_elims ConsE\n intro!: dOcc_dTermIs)\napply simp_all\napply (drule_tac [2] bspec [THEN bspec])\napply (erule_tac [2] nat_succI)\napply (drule_tac [1] bspec [THEN bspec])\napply (erule_tac [1] nat_succI)\napply assumption\nprefer 2 apply assumption\napply simp\napply simp\napply blast\napply blast\ndone\n\nlemma dOcc_dAbstE:\n assumes major: \": dOcc(dAbst(M, x, n))\"\n and prem1: \"M: dTerm\"\n and prem2: \"n: nat\"\n and prem3:\n \"[| T = TdBound(n #+ dLamDeg(l, M)); : dOcc(M) |] ==> R\"\n and prem4: \": dOcc(M) ==> R\"\n shows \"R\"\napply (rule dOcc_dAbstE_lemma [OF major prem1 prem2])\napply (rule_tac [2] impI)\napply (rule impI)\napply (erule conjE)\napply (erule_tac [2] prem4)\napply (erule prem3)\napply assumption\ndone\n\nlemma dOcc_dAbst_lemma1:\n assumes major: \": dOcc(dAbst(M, x, n))\"\n and prem1: \"M: dTerm\"\n and prem2: \"n: nat\"\n shows \"T ~= TdVar(x)\"\napply (rule major [THEN rev_mp])\napply (rule_tac x=\"l\" in spec)\napply (rule_tac prem2 [THEN [2] bspec])\napply (rule prem1 [THEN dTerm.induct])\napply (case_tac \"x = xa\")\nprefer 2\napply (simp_all del: all_simps)\napply (safe elim!: dOcc_dTermEs dTag.free_elims)\napply (drule_tac [3] bspec [THEN spec, THEN mp],\n erule_tac [4] asm_rl) \napply (drule_tac [2] bspec [THEN spec, THEN mp],\n erule_tac [3] asm_rl) \napply (drule_tac [1] bspec [THEN spec, THEN mp],\n erule_tac [2] asm_rl)\nprefer 3\nprefer 5\napply (assumption | rule nat_succI)+\napply (erule notE, rule refl)+\ndone\n\nlemma dOcc_dAbst_lemma2:\n assumes major: \": dOcc(dAbst(M, x, n))\"\n and prem1: \"M: dTerm\"\n and prem2: \"n: nat\"\n and prem3: \"dDeg(M) le n\"\n shows \": dOcc(M)\"\napply (rule major [THEN rev_mp])\napply (rule prem3 [THEN rev_mp])\napply (rule_tac x=\"l\" and A=\"list(nat)\" in bspec)\nprefer 2\napply (rule major [THEN dOcc_typeD1])\napply (assumption | rule dAbst_type prem1 prem2)+\napply (rule prem2 [THEN [2] bspec])\napply (rule prem1 [THEN dTerm.induct])\napply (case_tac \"x = xa\")\nprefer 2\napply simp_all\napply (safe elim!: dOcc_dTermEs dTag.free_elims ConsE\n intro!: dOcc_dTermIs)\napply simp_all\napply (erule bspec [THEN mp, THEN bspec, THEN mp])\napply (erule nat_succI)\nprefer 3 apply simp\napply assumption+\ndone\n\nlemma dOcc_dAbst_lemma3:\n assumes major: \": dOcc(dAbst(M, x, 0))\"\n and prem: \"M: dProp\"\n shows \": dOcc(M)\"\napply (rule prem [THEN dPropE])\napply (rule dOcc_dAbst_lemma2)\nprefer 4\napply simp\napply (rule le_refl)\nprefer 2\napply simp\napply (assumption | rule major nat_0I Ord_0)+\ndone\n\nlemma dLamDeg_dAbst_lemma:\n assumes major: \"M: dTerm\"\n and prem1: \": dOcc(M)\"\n and prem2: \"n: nat\"\n shows \"dLamDeg(l, dAbst(M, x, n)) = dLamDeg(l, M)\"\napply (rule prem1 [THEN rev_mp])\napply (rule prem2 [THEN [2] bspec])\napply (rule_tac x=\"l\" and A=\"list(nat)\" in bspec)\nprefer 2\napply (rule dOcc_typeD1 [OF prem1 major])\napply (rule major [THEN dTerm.induct])\napply (safe elim!: dOcc_dTermEs ConsE dTag.free_elims)\napply (case_tac \"x = xa\")\napply simp_all\ndone\n\nlemma dBoundBy_dAbstI:\n assumes major: \"dBoundBy(u, v, M)\"\n and prem: \"n: nat\"\n shows \"dBoundBy(u, v, dAbst(M, x, n))\"\napply (rule major [THEN rev_mp])\napply (rule prem [THEN [2] bspec])\napply (rule_tac x=\"v\" in spec)\napply (rule_tac x=\"u\" in spec)\napply (rule major [THEN dBoundByD1, THEN dTerm.induct])\napply (safe elim!: dBoundBy_dTermEs dTag.free_elims)\napply simp_all\napply (safe intro!: dBoundBy_dTermIs dAbst_type)\napply (rule dLamDeg_dAbst_lemma)\napply (assumption | rule nat_succI)+\napply (erule dOcc_dAbstI2)\napply (blast elim!: dTag.free_elims)\napply (assumption | rule nat_succI)+\napply (erule_tac [3] spec [THEN spec, THEN mp, THEN bspec])\napply (erule_tac [2] spec [THEN spec, THEN mp, THEN bspec])\napply (erule_tac [1] spec [THEN spec, THEN mp, THEN bspec])\napply (assumption | rule nat_succI)+\ndone\n\nlemma dBoundBy_dAbstD:\n assumes major: \"dBoundBy(u, v, dAbst(M, x, n))\"\n and prem1: \"M: dTerm\"\n and prem2: \"n: nat\"\n shows \"dBoundBy(u, v, M)\"\napply (rule major [THEN rev_mp])\napply (rule prem2 [THEN [2] bspec])\napply (rule_tac x=\"v\" in spec)\napply (rule_tac x=\"u\" in spec)\napply (rule prem1 [THEN dTerm.induct])\napply (case_tac \"x = xa\")\nprefer 2\napply (simp_all del: all_simps ball_simps)\napply (safe elim!: dBoundBy_dTermEs dOcc_dAbstE dTag.free_elims\n intro!: dBoundBy_dTermIs)\napply (assumption | rule dLamDeg_dAbst_lemma [THEN sym] nat_succI)+\napply (drule_tac f=\"%x. x #- dLamDeg(m, M)\" in function_apply_eq)\napply (simp del: all_simps ball_simps add: dLamDeg_dAbst_lemma)\napply (erule_tac [3] spec [THEN spec, THEN bspec, THEN mp],\n erule_tac [4] asm_rl) \napply (erule_tac [2] spec [THEN spec, THEN bspec, THEN mp],\n erule_tac [3] asm_rl) \napply (erule_tac [1] spec [THEN spec, THEN bspec, THEN mp],\n erule_tac [2] asm_rl) \napply (assumption | rule nat_succI)+\ndone\n\nlemma dFV_dLift_iff:\n assumes prem1: \"M: dTerm\"\n and prem2: \"n: nat\"\n shows \"x : dFV(dLift(M, n)) <-> x: dFV(M)\"\napply (rule prem2 [THEN [2] bspec])\napply (rule prem1 [THEN dTerm.induct])\napply (rule_tac [2] ballI)\napply (case_tac [2] \"n < xa\")\napply simp_all\ndone\n\nlemma dFV_dSubst_lemma:\n assumes major: \"x: dFV(dSubst(M, n, N))\"\n and prem1: \"M: dTerm\"\n and prem2: \"n: nat\"\n and prem3: \"N: dTerm\"\n shows \"x: dFV(M) | x: dFV(N)\"\napply (rule major [THEN rev_mp])\napply (rule prem3 [THEN [2] bspec])\napply (rule prem2 [THEN [2] bspec])\napply (rule prem1 [THEN dTerm.induct])\napply (rule_tac [2] ballI)\napply (case_tac [2] \"xa = n\")\napply (case_tac [3] \"xa < n\")\napply (simp_all del: ball_simps all_simps)\napply safe\napply (drule_tac [3] bspec [THEN bspec, THEN mp],\n erule_tac [5] asm_rl)\napply (drule_tac [2] bspec [THEN bspec, THEN mp],\n erule_tac [4] asm_rl)\napply (drule_tac [1] bspec [THEN bspec, THEN mp],\n erule_tac [3] asm_rl)\nprefer 4\nprefer 5\nprefer 7\nprefer 8\napply (assumption | rule dLift_type nat_succI nat_0I)+\napply (simp add: dFV_dLift_iff)\napply safe\ndone\n\nend\n","avg_line_length":30.2063312606,"max_line_length":82,"alphanum_fraction":0.6805651726} {"size":4097,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/n_german_lemma_inv__17_on_rules.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_german Protocol Case Study*} \n\ntheory n_german_lemma_inv__17_on_rules imports n_german_lemma_on_inv__17\nbegin\nsection{*All lemmas on causal relation between inv__17*}\nlemma lemma_inv__17_on_rules:\n assumes b1: \"r \\ rules N\" and b2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__17 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n proof -\n have c1: \"(\\ j. j\\N\\r=n_SendReqS j)\\\n (\\ i. i\\N\\r=n_SendReqEI i)\\\n (\\ i. i\\N\\r=n_SendReqES i)\\\n (\\ i. i\\N\\r=n_RecvReq N i)\\\n (\\ i. i\\N\\r=n_SendInvE i)\\\n (\\ i. i\\N\\r=n_SendInvS i)\\\n (\\ i. i\\N\\r=n_SendInvAck i)\\\n (\\ i. i\\N\\r=n_RecvInvAck i)\\\n (\\ i. i\\N\\r=n_SendGntS i)\\\n (\\ i. i\\N\\r=n_SendGntE N i)\\\n (\\ i. i\\N\\r=n_RecvGntS i)\\\n (\\ i. i\\N\\r=n_RecvGntE i)\\\n (\\ i d. i\\N\\d\\N\\r=n_Store i d)\"\n apply (cut_tac b1, auto) done\n moreover {\n assume d1: \"(\\ j. j\\N\\r=n_SendReqS j)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendReqSVsinv__17) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendReqEI i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendReqEIVsinv__17) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendReqES i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendReqESVsinv__17) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvReq N i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvReqVsinv__17) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendInvE i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendInvEVsinv__17) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendInvS i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendInvSVsinv__17) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendInvAck i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendInvAckVsinv__17) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvInvAck i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvInvAckVsinv__17) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendGntS i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendGntSVsinv__17) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_SendGntE N i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_SendGntEVsinv__17) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvGntS i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvGntSVsinv__17) done\n }\n\n moreover {\n assume d1: \"(\\ i. i\\N\\r=n_RecvGntE i)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_RecvGntEVsinv__17) done\n }\n\n moreover {\n assume d1: \"(\\ i d. i\\N\\d\\N\\r=n_Store i d)\"\n have \"invHoldForRule s f r (invariants N)\"\n apply (cut_tac b2 d1, metis n_StoreVsinv__17) done\n }\n\n ultimately show \"invHoldForRule s f r (invariants N)\"\n by satx\nqed\n\nend\n","avg_line_length":36.5803571429,"max_line_length":157,"alphanum_fraction":0.6260678545} {"size":218,"ext":"thy","lang":"Isabelle","max_stars_count":102.0,"content":"(*\n Authors: Wenda Li\n*)\ntheory amc12_2000_p5 imports Complex_Main\nbegin\n\ntheorem amc12_2000_p5:\n fixes x p ::real\n assumes \"x<2\"\n and \"\\x -2\\ = p\"\n shows \"x - p = 2 - 2 * p\"\n using assms by auto\n\nend","avg_line_length":15.5714285714,"max_line_length":41,"alphanum_fraction":0.6330275229} {"size":431,"ext":"thy","lang":"Isabelle","max_stars_count":30.0,"content":"theory lscmnec_Lsc__ec__point_add__subprogram_def_WP_parameter_def_5\nimports \"..\/LibSPARKcrypto\"\nbegin\n\nwhy3_open \"lscmnec_Lsc__ec__point_add__subprogram_def_WP_parameter_def_5.xml\"\n\nwhy3_vc WP_parameter_def\n using\n `(num_of_big_int' (Array lsc__bignum__mont_mult__a5 _) _ _ = _) = _`\n `(math_int_from_word (of_int 1) < num_of_big_int' m _ _) = _`\n by (simp add: mk_bounds_eqs integer_in_range_def slide_eq)\n\nwhy3_end\n\nend\n","avg_line_length":26.9375,"max_line_length":77,"alphanum_fraction":0.807424594} {"size":16433,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"section {* Standalone Verification Component Based on KAT *}\n\ntheory VC_KAT_scratch\n imports Main GCD (*\"$ISABELLE_HOME\/src\/HOL\/Eisbach\/Eisbach\"*)\n\nbegin\n\nsubsection {* KAT: Definition and Basic Properties *}\n\ntext {* Most proofs are fully automated when using SMT solvers. We have added proofs without these tools for the AFP,\n but SMT proofs can be commented in if wanted. *}\n\nnotation times (infixl \"\\\" 70)\n\nclass plus_ord = plus + ord +\n assumes less_eq_def: \"x \\ y \\ x + y = y\"\n and less_def: \"x < y \\ x \\ y \\ x \\ y\"\n\nclass dioid = semiring + one + zero + plus_ord +\n assumes add_idem [simp]: \"x + x = x\"\n and mult_onel [simp]: \"1 \\ x = x\"\n and mult_oner [simp]: \"x \\ 1 = x\"\n and add_zerol [simp]: \"0 + x = x\"\n and annil [simp]: \"0 \\ x = 0\"\n and annir [simp]: \"x \\ 0 = 0\"\n\nbegin\n\nsubclass monoid_mult \n by (standard, simp_all)\n\nsubclass order\n apply (standard, simp_all add: less_def less_eq_def add_commute)\n apply auto[1]\n by (metis add_assoc)\n\nlemma mult_isol: \"x \\ y \\ z \\ x \\ z \\ y\"\n by (metis distrib_left less_eq_def)\n\nlemma mult_isor: \"x \\ y \\ x \\ z \\ y \\ z\"\n by (metis distrib_right less_eq_def)\n \nlemma add_iso: \"x \\ y \\ x + z \\ y + z\"\n by (metis (no_types, lifting) abel_semigroup.commute add.abel_semigroup_axioms add.semigroup_axioms add_idem less_eq_def semigroup.assoc)\n\nlemma add_lub: \"x + y \\ z \\ x \\ z \\ y \\ z\"\n by (metis add_assoc add_commute less_eq_def order.ordering_axioms ordering.refl)\n\nend\n\nclass kleene_algebra = dioid + \n fixes star :: \"'a \\ 'a\" (\"_\\<^sup>\\\" [101] 100)\n assumes star_unfoldl: \"1 + x \\ x\\<^sup>\\ \\ x\\<^sup>\\\" \n and star_unfoldr: \"1 + x\\<^sup>\\ \\ x \\ x\\<^sup>\\\"\n and star_inductl: \"z + x \\ y \\ y \\ x\\<^sup>\\ \\ z \\ y\"\n and star_inductr: \"z + y \\ x \\ y \\ z \\ x\\<^sup>\\ \\ y\"\n\nbegin\n\nlemma star_sim: \"x \\ y \\ z \\ x \\ x \\ y\\<^sup>\\ \\ z\\<^sup>\\ \\ x\"\n(* by (sm add_commute add_assoc add_idem distrib_left distrib_right less_eq_def mult_onel star_inductr star_unfoldr mult_assoc) *)\nproof - \n assume \"x \\ y \\ z \\ x\"\n hence \"x + z\\<^sup>\\ \\ x \\ y \\ x + z\\<^sup>\\ \\ z \\ x\"\n by (metis add_lub distrib_left eq_refl less_eq_def mult_assoc)\n also have \"... \\ z\\<^sup>\\ \\ x\"\n using add_lub mult_isor star_unfoldr by fastforce\n finally show ?thesis\n by (simp add: star_inductr) \nqed\n\nend\n\nclass kat = kleene_algebra +\n fixes at :: \"'a \\ 'a\" \n assumes test_one [simp]: \"at (at 1) = 1\"\n and test_mult [simp]: \"at (at (at (at x) \\ at (at y))) = at (at y) \\ at (at x)\" \n and test_mult_comp [simp]: \"at x \\ at (at x) = 0\"\n and test_de_morgan: \"at x + at y = at (at (at x) \\ at (at y))\"\n\nbegin\n\ndefinition t_op :: \"'a \\ 'a\" (\"t_\" [100] 101) where\n \"t x = at (at x)\"\n\nlemma t_n [simp]: \"t (at x) = at x\"\n by (metis add_idem test_de_morgan test_mult t_op_def)\n\nlemma t_comm: \"t x \\ t y = t y \\ t x\"\n by (metis add_commute test_de_morgan test_mult t_op_def)\n\nlemma t_idem [simp]: \"t x \\ t x = t x\"\n by (metis add_idem test_de_morgan test_mult t_op_def)\n\nlemma t_mult_closed [simp]: \"t (t x \\ t y) = t x \\ t y\"\n using t_comm t_op_def by auto\n\nsubsection{* Propositional Hoare Logic *}\n\ndefinition H :: \"'a \\ 'a \\ 'a \\ bool\" where\n \"H p x q \\ t p \\ x \\ x \\ t q\"\n\ndefinition if_then_else :: \"'a \\ 'a \\ 'a \\ 'a\" (\"if _ then _ else _ fi\" [64,64,64] 63) where\n \"if p then x else y fi = t p \\ x + at p \\ y\"\n\ndefinition while :: \"'a \\ 'a \\ 'a\" (\"while _ do _ od\" [64,64] 63) where\n \"while p do x od = (t p \\ x)\\<^sup>\\ \\ at p\"\n\ndefinition while_inv :: \"'a \\ 'a \\ 'a \\ 'a\" (\"while _ inv _ do _ od\" [64,64,64] 63) where\n \"while p inv i do x od = while p do x od\"\n\nlemma H_skip: \"H p 1 p\"\n by (simp add: H_def)\n\nlemma H_cons: \"t p \\ t p' \\ t q' \\ t q \\ H p' x q' \\ H p x q\"\n by (meson H_def mult_isol mult_isor order.trans)\n\nlemma H_seq: \"H r y q \\ H p x r \\ H p (x \\ y) q\"\n(* by (smt H_def add.semigroup_axioms distrib_left distrib_right less_eq_def mult.semigroup_axioms semigroup.assoc)*)\nproof -\n assume h1: \"H p x r\" and h2: \"H r y q\" \n hence h3: \"t p \\ x \\ x \\ t r\" and h4: \"t r \\ y \\ y \\ t q\"\n using H_def apply blast using H_def h2 by blast\n hence \"t p \\ x \\ y \\ x \\ t r \\ y\"\n using mult_isor by blast\n also have \"... \\ x \\ y \\ t q\"\n by (simp add: h4 mult_isol mult_assoc)\n finally show ?thesis\n by (simp add: H_def mult_assoc)\nqed\n\nlemma H_cond: \"H (t p \\ t r) x q \\ H (t p \\ at r) y q \\ H p (if r then x else y fi) q\"\n(* by (smt H_def abel_semigroup.commute abel_semigroup.left_commute if_then_else_def add.abel_semigroup_axioms distrib_left distrib_right less_eq_def mult.semigroup_axioms t_comm t_idem t_mult_closed t_n semigroup.assoc)*)\nproof -\n assume h1: \"H (t p \\ t r) x q\" and h2: \"H (t p \\ at r) y q\"\n hence h3: \"t r \\ t p \\ t r \\ x \\ t r \\ x \\ t q\" and h4: \"at r \\ t p \\ at r \\ y \\ at r \\ y \\ t q\"\n by (simp add: H_def mult_isol mult_assoc, metis H_def h2 mult_isol mult_assoc t_mult_closed t_n)\n hence h5: \"t p \\ t r \\ x \\ t r \\ x \\ t q\" and h6: \"t p \\ at r \\ y \\ at r \\ y \\ t q\"\n by (simp add: mult_assoc t_comm, metis h4 mult_assoc t_comm t_idem t_n)\n have \"t p \\ (t r \\ x + at r \\ y) = t p \\ t r \\ x + t p \\ at r \\ y\"\n by (simp add: distrib_left mult_assoc)\n also have \"... \\ t r \\ x \\ t q + t p \\ at r \\ y\"\n using h5 add_iso by blast\n also have \"... \\ t r \\ x \\ t q + at r \\ y \\ t q\"\n by (simp add: add_commute h6 add_iso)\n finally show ?thesis\n by (simp add: H_def if_then_else_def distrib_right)\nqed\n\nlemma H_loop: \"H (t p \\ t r) x p \\ H p (while r do x od) (t p \\ at r)\"\n(* by (smt while_def H_def distrib_left less_eq_def mult.semigroup_axioms semigroup.assoc star_sim t_comm t_idem t_mult_closed mult_isor test_mult t_n t_op_def)*)\nproof - \n assume \"H (t p \\ t r) x p\"\n hence \"t r \\ t p \\ t r \\ x \\ t r \\ x \\ t p\"\n by (metis H_def distrib_left less_eq_def mult_assoc t_mult_closed)\n hence \"t p \\ t r \\ x \\ t r \\ x \\ t p\"\n by (simp add: mult_assoc t_comm)\n hence \"t p \\ (t r \\ x)\\<^sup>\\ \\ at r \\ (t r \\ x)\\<^sup>\\ \\ t p \\ at r\"\n by (metis mult_isor star_sim mult_assoc)\n hence \"t p \\ (t r \\ x)\\<^sup>\\ \\ at r \\ (t r \\ x)\\<^sup>\\ \\ at r \\ t p \\ at r\"\n by (metis mult_assoc t_comm t_idem t_n)\n thus ?thesis\n by (metis H_def mult_assoc t_mult_closed t_n while_def)\nqed\n\nlemma H_while_inv: \"t p \\ t i \\ t i \\ at r \\ t q \\ H (t i \\ t r) x i \\ H p (while r inv i do x od) q\"\n by (metis H_cons H_loop t_mult_closed t_n while_inv_def)\n\nend\n\nsubsection{* Soundness *}\n\nnotation relcomp (infixl \";\" 70)\n\ninterpretation rel_d: dioid Id \"{}\" \"op \\\" \"op ;\" \"op \\\" \"op \\\" \n by (standard, auto)\n\nlemma (in dioid) power_inductl: \"z + x \\ y \\ y \\ x ^ i \\ z \\ y\"\n by (induct i, simp add: add_lub, smt add_lub distrib_left less_eq_def power.power_Suc mult_assoc)\n\nlemma (in dioid) power_inductr: \"z + y \\ x \\ y \\ z \\ x ^ i \\ y\"\n by (induct i, simp add: add_lub, smt add_lub combine_common_factor less_eq_def power_Suc2 mult_assoc)\n\nlemma power_is_relpow: \"rel_d.power X i = X ^^ i\"\n by (induct i, simp_all add: relpow_commute)\n\nlemma rel_star_def: \"X^* = (\\i. rel_d.power X i)\"\n by (simp add: power_is_relpow rtrancl_is_UN_relpow)\n\nlemma rel_star_contl: \"X ; Y^* = (\\i. X ; rel_d.power Y i)\"\n by (simp add: rel_star_def relcomp_UNION_distrib)\n\nlemma rel_star_contr: \"X^* ; Y = (\\i. (rel_d.power X i) ; Y)\"\n by (simp add: rel_star_def relcomp_UNION_distrib2)\n\ndefinition rel_at :: \"'a rel \\ 'a rel\" where \n \"rel_at X = Id \\ - X\" \n\ninterpretation rel_kat: kat Id \"{}\" \"op \\\" \"op ;\" \"op \\\" \"op \\\" rtrancl rel_at\n apply standard \n apply auto[2]\n by (auto simp: rel_star_contr rel_d.power_inductl rel_star_contl SUP_least rel_d.power_inductr rel_at_def)\n\nsubsection{* Embedding Predicates in Relations *}\n\ntype_synonym 'a pred = \"'a \\ bool\"\n\nabbreviation p2r :: \"'a pred \\ 'a rel\" (\"\\_\\\") where\n \"\\P\\ \\ {(s,s) |s. P s}\"\n\nlemma t_p2r [simp]: \"rel_kat.t_op \\P\\ = \\P\\\"\n by (auto simp add: rel_kat.t_op_def rel_at_def)\n \nlemma p2r_neg_hom [simp]: \"rel_at \\P\\ = \\\\s. \\ P s\\\" \n by (auto simp: rel_at_def)\n\nlemma p2r_conj_hom [simp]: \"\\P\\ \\ \\Q\\ = \\\\s. P s \\ Q s\\\"\n by auto \n\nlemma p2r_conj_hom_var [simp]: \"\\P\\ ; \\Q\\ = \\\\s. P s \\ Q s\\\" \n by auto \n\nlemma p2r_disj_hom [simp]: \"\\P\\ \\ \\Q\\ = \\\\s. P s \\ Q s\\\"\n by auto \n\nlemma impl_prop [simp]: \"\\P\\ \\ \\Q\\ \\ (\\s. P s \\ Q s)\"\n by auto \n\nsubsection {* Store and Assignment *}\n\ntype_synonym 'a store = \"string \\ 'a\"\n\ndefinition gets :: \"string \\ ('a store \\ 'a) \\ 'a store rel\" (\"_ ::= _\" [70, 65] 61) where \n \"v ::= e = {(s,s (v := e s)) |s. True}\"\n\nlemma H_assign: \"rel_kat.H \\\\s. P (s (v := e s))\\ (v ::= e) \\P\\\"\n by (auto simp: gets_def rel_kat.H_def rel_kat.t_op_def rel_at_def)\n\nlemma H_assign_var: \"(\\s. P s \\ Q (s (v := e s))) \\ rel_kat.H \\P\\ (v ::= e) \\Q\\\"\n by (auto simp: gets_def rel_kat.H_def rel_kat.t_op_def rel_at_def)\n\nsubsection {* Simplifications *}\n\nabbreviation H_sugar :: \"'a pred \\ 'a rel \\ 'a pred \\ bool\" (\"PRE _ _ POST _\" [64,64,64] 63) where\n \"PRE P X POST Q \\ rel_kat.H \\P\\ X \\Q\\\"\n\nabbreviation if_then_else_sugar :: \"'a pred \\ 'a rel \\ 'a rel \\ 'a rel\" (\"IF _ THEN _ ELSE _ FI\" [64,64,64] 63) where\n \"IF P THEN X ELSE Y FI \\ rel_kat.if_then_else \\P\\ X Y\"\n\nabbreviation while_inv_sugar :: \"'a pred \\ 'a pred \\ 'a rel \\ 'a rel\" (\"WHILE _ INV _ DO _ OD\" [64,64,64] 63) where\n \"WHILE P INV I DO X OD \\ rel_kat.while_inv \\P\\ \\I\\ X\"\n\nsubsection {* Examples *}\n\nlemma euclid:\n \"PRE (\\s::nat store. s ''x'' = x \\ s ''y'' = y)\n (WHILE (\\s. s ''y'' \\ 0) INV (\\s. gcd (s ''x'') (s ''y'') = gcd x y) \n DO\n (''z'' ::= (\\s. s ''y''));\n (''y'' ::= (\\s. s ''x'' mod s ''y''));\n (''x'' ::= (\\s. s ''z''))\n OD)\n POST (\\s. s ''x'' = gcd x y)\"\n apply (rule rel_kat.H_while_inv, simp_all, clarsimp)\n apply (intro rel_kat.H_seq)\n apply (subst H_assign, simp)+\n apply (rule H_assign_var)\n using gcd_red_nat by auto\n\nsection {* Refinement Component Based on KAT *}\n\nsubsection {* Definition of RKAT *}\n\nclass rkat = kat +\n fixes R :: \"'a \\ 'a \\ 'a\"\n assumes R1: \"H p (R p q) q\"\n and R2: \"H p x q \\ x \\ R p q\"\n\nbegin\n\nsubsection {* Refinement Laws *}\n\nlemma R_skip: \"1 \\ R p p\"\n by (simp add: H_skip R2)\n\nlemma R_cons: \"t p \\ t p' \\ t q' \\ t q \\ R p' q' \\ R p q\"\n by (simp add: H_cons R2 R1)\n\nlemma R_seq: \"(R p r) \\ (R r q) \\ R p q\"\n using H_seq R2 R1 by blast\n\nlemma R_cond: \"if v then (R (t v \\ t p) q) else (R (at v \\ t p) q) fi \\ R p q\"\n by (metis H_cond R1 R2 t_comm t_n)\n\nlemma R_loop: \"while q do (R (t p \\ t q) p) od \\ R p (t p \\ at q)\"\n by (simp add: H_loop R2 R1)\n\nend\n\nsubsection {* Soundness *}\n\ndefinition rel_R :: \"'a rel \\ 'a rel \\ 'a rel\" where \n \"rel_R P Q = \\{X. rel_kat.H P X Q}\"\n\ninterpretation rel_rkat: rkat Id \"{}\" \"op \\\" \"op ;\" \"op \\\" \"op \\\" rtrancl rel_at rel_R\n by (standard, auto simp: rel_R_def rel_kat.H_def rel_kat.t_op_def rel_at_def)\n\nsubsection {* Assignment Laws *}\n\nlemma R_assign: \"(\\s. P s \\ Q (s (v := e s))) \\ (v ::= e) \\ rel_R \\P\\ \\Q\\\"\n by (simp add: H_assign_var rel_rkat.R2)\n\nlemma R_assignr: \"(\\s. Q' s \\ Q (s (v := e s))) \\ (rel_R \\P\\ \\Q'\\) ; (v ::= e) \\ rel_R \\P\\ \\Q\\\"\nproof -\n assume a1: \"\\s. Q' s \\ Q (s(v := e s))\"\n have \"\\p pa cs f. \\fa. (p fa \\ cs ::= f \\ rel_R \\p\\ \\pa\\) \\ (\\ pa (fa(cs := f fa::'a)) \\ cs ::= f \\ rel_R \\p\\ \\pa\\)\"\n using R_assign by blast\n hence \"v ::= e \\ rel_R \\Q'\\ \\Q\\\" \n using a1 by blast\n thus ?thesis \n by (meson dual_order.trans rel_d.mult_isol rel_rkat.R_seq)\nqed\n\nlemma R_assignl: \"(\\s. P s \\ P' (s (v := e s))) \\ (v ::= e) ; (rel_R \\P'\\ \\Q\\) \\ rel_R \\P\\ \\Q\\\"\nproof -\n assume a1: \"\\s. P s \\ P' (s(v := e s))\"\n have \"\\p pa cs f. \\fa. (p fa \\ cs ::= f \\ rel_R \\p\\ \\pa\\) \\ (\\ pa (fa(cs := f fa::'a)) \\ cs ::= f \\ rel_R \\p\\ \\pa\\)\"\n using R_assign by blast\n then have \"v ::= e \\ rel_R \\P\\ \\P'\\\"\n using a1 by blast\n then show ?thesis\n by (meson dual_order.trans rel_d.mult_isor rel_rkat.R_seq)\nqed \n\nsubsection {* Example *}\n\nlemma var_swap_ref1: \n \"rel_R \\\\s. s ''x'' = a \\ s ''y'' = b\\ \\\\s. s ''x'' = b \\ s ''y'' = a\\ \n \\ (''z'' ::= (\\s. s ''x'')); rel_R \\\\s. s ''z'' = a \\ s ''y'' = b\\ \\\\s. s ''x'' = b \\ s ''y'' = a\\\"\n by (rule R_assignl, auto) \n\nlemma var_swap_ref2: \n \"rel_R \\\\s. s ''z'' = a \\ s ''y'' = b\\ \\\\s. s ''x'' = b \\ s ''y'' = a\\ \n \\ (''x'' ::= (\\s. s ''y'')); rel_R \\\\s. s ''z'' = a \\ s ''x'' = b\\ \\\\s. s ''x'' = b \\ s ''y'' = a\\\"\n by (rule R_assignl, auto)\n\nlemma var_swap_ref3: \n \"rel_R \\\\s. s ''z'' = a \\ s ''x'' = b\\ \\\\s. s ''x'' = b \\ s ''y'' = a\\ \n \\ (''y'' ::= (\\s. s ''z'')); rel_R \\\\s. s ''x'' = b \\ s ''y'' = a\\ \\\\s. s ''x'' = b \\ s ''y'' = a\\\" \n by (rule R_assignl, auto)\n\nlemma var_swap_ref_var: \n \"rel_R \\\\s. s ''x'' = a \\ s ''y'' = b\\ \\\\s. s ''x'' = b \\ s ''y'' = a\\ \n \\ (''z'' ::= (\\s. s ''x'')); (''x'' ::= (\\s. s ''y'')); (''y'' ::= (\\s. s ''z''))\"\n using var_swap_ref1 var_swap_ref2 var_swap_ref3 rel_rkat.R_skip by fastforce\n\nend\n\n\n","avg_line_length":45.6472222222,"max_line_length":228,"alphanum_fraction":0.6179030001} {"size":9131,"ext":"thy","lang":"Isabelle","max_stars_count":1.0,"content":"(* Example in linked lists *)\n\ntheory IHT_Linked_List\nimports \"..\/SepLogicTime\/SLTC_Main\" \"..\/Asymptotics\/Asymptotics_Recurrences\"\nbegin\n\nsection \\List assertion\\\n\ndatatype 'a node = Node (val: \"'a\") (nxt: \"'a node ref option\")\nsetup \\fold add_rewrite_rule @{thms node.sel}\\\nsetup \\add_forward_prfstep (equiv_forward_th @{thm node.simps(1)})\\\n\nfun node_encode :: \"'a::heap node \\ nat\" where\n \"node_encode (Node x r) = to_nat (x, r)\"\n\ninstance node :: (heap) heap\n apply (rule heap_class.intro)\n apply (rule countable_classI [of \"node_encode\"])\n apply (case_tac x, simp_all, case_tac y, simp_all)\n ..\n\nfun os_list :: \"'a::heap list \\ 'a node ref option \\ assn\" where\n \"os_list [] p = \\(p = None)\"\n| \"os_list (x # l) (Some p) = (\\\\<^sub>Aq. p \\\\<^sub>r Node x q * os_list l q)\"\n| \"os_list (x # l) None = false\"\nsetup \\fold add_rewrite_ent_rule @{thms os_list.simps}\\\n\nlemma os_list_empty [forward_ent]:\n \"os_list [] p \\\\<^sub>A \\(p = None)\" by auto2\n\nlemma os_list_Cons [forward_ent]:\n \"os_list (x # l) p \\\\<^sub>A (\\\\<^sub>Aq. the p \\\\<^sub>r Node x q * os_list l q * \\(p \\ None))\" \n@proof @case \"p = None\" @qed\n\nlemma os_list_none: \"emp \\\\<^sub>A os_list [] None\" by auto2\n\nlemma os_list_constr_ent:\n \"p \\\\<^sub>r Node x q * os_list l q \\\\<^sub>A os_list (x # l) (Some p)\" by auto2\n\nsetup \\fold add_entail_matcher [@{thm os_list_none}, @{thm os_list_constr_ent}]\\\nsetup \\fold del_prfstep_thm @{thms os_list.simps}\\\n\ntype_synonym 'a os_list = \"'a node ref option\"\n\nsection \\Basic operations\\\n\ndefinition os_empty :: \"'a::heap os_list Heap\" where\n \"os_empty = return None\"\n\nlemma os_empty_rule [hoare_triple]:\n \"<$1> os_empty \" by auto2\n\ndefinition os_is_empty :: \"'a::heap os_list \\ bool Heap\" where\n \"os_is_empty b = return (b = None)\"\n\nlemma os_is_empty_rule [hoare_triple]:\n \" os_is_empty b <\\r. os_list xs b * \\(r \\ xs = [])>\"\n@proof @case \"xs = []\" @have \"xs = hd xs # tl xs\" @qed\n\ndefinition os_prepend :: \"'a \\ 'a::heap os_list \\ 'a os_list Heap\" where\n \"os_prepend a n = do { p \\ ref (Node a n); return (Some p) }\"\n\nlemma os_prepend_rule [hoare_triple]:\n \" os_prepend x n \" by auto2\n\ndefinition os_pop :: \"'a::heap os_list \\ ('a \\ 'a os_list) Heap\" where\n \"os_pop r = (case r of\n None \\ raise ''Empty Os_list'' |\n Some p \\ do {m \\ !p; return (val m, nxt m)})\"\n\nlemma os_pop_rule [hoare_triple]:\n \"\n os_pop (Some p)\n <\\(x,r'). os_list (tl xs) r' * p \\\\<^sub>r (Node x r') * \\(x = hd xs)>\"\n@proof @case \"xs = []\" @have \"xs = hd xs # tl xs\" @qed\n\nsection \\Reverse\\\n\npartial_function (heap_time) os_reverse_aux :: \"'a::heap os_list \\ 'a os_list \\ 'a os_list Heap\" where\n \"os_reverse_aux q p = (case p of\n None \\ return q |\n Some r \\ do {\n v \\ !r;\n r := Node (val v) q;\n os_reverse_aux p (nxt v) })\"\n\nlemma os_reverse_aux_rule [hoare_triple]:\n \"\n os_reverse_aux q p \n \"\n@proof @induct xs arbitrary p q ys @qed\n\ndefinition os_reverse :: \"'a::heap os_list \\ 'a os_list Heap\" where\n \"os_reverse p = os_reverse_aux None p\"\n\nlemma os_reverse_rule:\n \"\n os_reverse p\n \" by auto2\n\nsection \\Remove\\\n\nsetup \\fold add_rewrite_rule @{thms removeAll.simps}\\\n\npartial_function (heap_time) os_rem :: \"'a::heap \\ 'a node ref option \\ 'a node ref option Heap\" where\n \"os_rem x b = (case b of \n None \\ return None |\n Some p \\ do { \n n \\ !p;\n q \\ os_rem x (nxt n);\n (if val n = x then\n return q\n else do {\n p := Node (val n) q; \n return (Some p) }) })\"\n\nlemma os_rem_rule [hoare_triple]:\n \"\n os_rem x b\n <\\r. os_list (removeAll x xs) r>\\<^sub>t\"\n@proof @induct xs arbitrary b @qed\n\nsection \\Extract list\\\n\npartial_function (heap_time) extract_list :: \"'a::heap os_list \\ 'a list Heap\" where\n \"extract_list p = (case p of\n None \\ return []\n | Some pp \\ do {\n v \\ !pp;\n ls \\ extract_list (nxt v);\n return (val v # ls)\n })\"\n\nlemma extract_list_rule [hoare_triple]:\n \"\n extract_list p\n <\\r. os_list l p * \\(r = l)>\"\n@proof @induct l arbitrary p @qed\n \nsection \\Ordered insert\\\n\nfun list_insert :: \"'a::ord \\ 'a list \\ 'a list\" where\n \"list_insert x [] = [x]\"\n| \"list_insert x (y # ys) = (\n if x \\ y then x # (y # ys) else y # list_insert x ys)\"\nsetup \\fold add_rewrite_rule @{thms list_insert.simps}\\\n\nlemma list_insert_length [rewrite_arg]:\n \"length (list_insert x xs) = length xs + 1\"\n@proof @induct xs @qed\n\nlemma list_insert_mset [rewrite]:\n \"mset (list_insert x xs) = {#x#} + mset xs\"\n@proof @induct xs @qed\n\nlemma list_insert_set [rewrite]:\n \"set (list_insert x xs) = {x} \\ set xs\"\n@proof @induct xs @qed\n\nlemma list_insert_sorted [forward]:\n \"sorted xs \\ sorted (list_insert x xs)\"\n@proof @induct xs @qed\n\npartial_function (heap_time) os_insert :: \"'a::{ord,heap} \\ 'a os_list \\ 'a os_list Heap\" where\n \"os_insert x b = (case b of\n None \\ os_prepend x None\n | Some p \\ do {\n v \\ !p;\n (if x \\ val v then os_prepend x b\n else do {\n q \\ os_insert x (nxt v);\n p := Node (val v) q;\n return (Some p) }) })\"\n\nlemma os_insert_to_fun [hoare_triple]:\n \"\n os_insert x b\n \\<^sub>t\"\n@proof @induct xs arbitrary b @qed\n\nsection \\Insertion sort\\\n\nfun insert_sort :: \"'a::ord list \\ 'a list\" where\n \"insert_sort [] = []\"\n| \"insert_sort (x # xs) = list_insert x (insert_sort xs)\"\nsetup \\fold add_rewrite_rule @{thms insert_sort.simps}\\\n\nlemma insert_sort_length [rewrite_arg]:\n \"length (insert_sort xs) = length xs\"\n@proof @induct xs @qed\n\nlemma insert_sort_mset [rewrite]:\n \"mset (insert_sort xs) = mset xs\"\n@proof @induct xs @qed\n\nlemma insert_sort_sorted [forward]:\n \"sorted (insert_sort xs)\"\n@proof @induct xs @qed\n\nlemma insert_sort_is_sort [rewrite]:\n \"insert_sort xs = sort xs\" by auto2\n\nfun os_insert_sort_aux :: \"'a::{heap,ord} list \\ 'a os_list Heap\" where\n \"os_insert_sort_aux [] = (return None)\"\n| \"os_insert_sort_aux (x # xs) = do {\n b \\ os_insert_sort_aux xs;\n b' \\ os_insert x b;\n return b'\n }\"\n\nlemma os_insert_sort_aux_correct [hoare_triple]:\n \"<$(2 * length xs * length xs + length xs + 1)>\n os_insert_sort_aux xs\n \\<^sub>t\"\n@proof @induct xs @qed\n\ndefinition os_insert_sort :: \"'a::{ord,heap} list \\ 'a list Heap\" where\n \"os_insert_sort xs = do {\n p \\ os_insert_sort_aux xs;\n l \\ extract_list p;\n return l\n }\"\n\ndefinition os_insert_sort_time :: \"nat \\ nat\" where [rewrite]:\n \"os_insert_sort_time n = 2 * n * n + 3 * n + 3\"\n\nlemma os_insert_sort_rule [hoare_triple]:\n \"<$(os_insert_sort_time (length xs))>\n os_insert_sort xs\n <\\ys. \\(ys = sort xs)>\\<^sub>t\" by auto2\n\nlemma os_insert_sort_time_monotonic [backward]:\n \"n \\ m \\ os_insert_sort_time n \\ os_insert_sort_time m\"\n@proof @have \"3 * n \\ 3 * m\" @qed\n\nsetup \\del_prfstep_thm @{thm os_insert_sort_time_def}\\\n\n(* Alternative proof using bigO *)\n\nfun os_insert_sort_aux' :: \"'a::{heap,ord} list \\ 'a os_list Heap\" where\n \"os_insert_sort_aux' [] = (return None)\"\n| \"os_insert_sort_aux' (x # xs) = do {\n b \\ os_insert_sort_aux' xs;\n b' \\ os_insert x b;\n return b'\n }\"\n\nfun os_insert_sort_aux_time :: \"nat \\ nat\" where \n \"os_insert_sort_aux_time 0 = 1\"\n| \"os_insert_sort_aux_time (Suc n) = os_insert_sort_aux_time n + 3 * n + 2 + 1\" \nsetup \\add_rewrite_rule @{thm os_insert_sort_aux_time.simps(1)}\\\n\nlemma os_insert_sort_aux_time_simps [rewrite]:\n \"os_insert_sort_aux_time (n + 1) = os_insert_sort_aux_time n + 3 * n + 2 + 1\" by simp\n\nlemma os_insert_sort_aux_correct':\n \"<$(os_insert_sort_aux_time (length xs))>\n os_insert_sort_aux' xs\n \\<^sub>t\"\n@proof @induct xs @qed\n\nlemma os_insert_sort_aux_time_asym': \"os_insert_sort_aux_time \\ \\(\\n. n * n)\"\n by (rule bigTheta_linear_recurrence[where N=0]) auto\n\nend\n","avg_line_length":34.3270676692,"max_line_length":142,"alphanum_fraction":0.6598401051} {"size":37638,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"theory Datatype_Bindings\n imports Common_Data_Codata_Bindings\nbegin \n\n(* The type T of pre-terms: In ('a, 'a, 'a T, 'a T) F:\n-- the first component 'a represents the free variables\n-- the second component 'a represents the binding variables\n-- the third (recursive) component of 'a T is free, i.e., not bound by the second component\n-- the fourth (recursive) component 'a T is bound by the second component\n*)\n\ndatatype 'a::var_TT T = ctor \"('a, 'a, 'a T, 'a T) F\"\n\n(* T acts like a BNF on bijections; but the BNF package did not infer this,\nsince P is not a BNF; so we need to do the constructions ourselves: *)\n\nprimrec map_T :: \"('a::var_TT \\ 'a) \\ 'a T \\ 'a T\" where\n \"map_T u (ctor x) = ctor (map_F u u id id (map_F id id (map_T u) (map_T u) x))\"\n\nlemma map_T_simps:\n fixes u::\"'a::var_TT\\'a\" assumes u: \"bij u\" \"|supp u| 'a\" and v::\"'a::var_TT\\'a\"\n assumes u: \"bij u\" \"|supp u| 'a T \\ bool\" where\n set1: \"a \\ set1_F x \\ free a (ctor x)\"\n| set2_free: \"t \\ set3_F x \\ free a t \\ free a (ctor x)\"\n| set2_rec: \"t \\ set4_F x \\ a \\ set2_F x \\ free a t \\ free a (ctor x)\"\n\n(* Note: free was just an auxiliary -- we will only use FVars *)\ndefinition FVars :: \"'a::var_TT T \\ 'a set\" where\n FVars_def: \"FVars t = {a . free a t}\"\n\nlemma free_FVars: \"free a t \\ a \\ FVars t\"\n unfolding FVars_def by simp\n\n\n(* BEGIN emancipation of FVars *)\nlemmas FVars_intros = free.intros[unfolded free_FVars]\n\nlemmas FVars_induct[consumes 1, case_names set1 set2_free set2_rec, induct set: FVars] =\n free.induct[unfolded free_FVars]\n\nlemmas FVars_cases[consumes 1, case_names set1 set2_free set2_rec, cases set: FVars] =\n free.cases[unfolded free_FVars]\n\nlemma FVars_ctor:\n \"FVars (ctor x) = set1_F x \\ (\\tt \\ set3_F x. FVars tt) \\ ((\\tt \\ set4_F x. FVars tt) - set2_F x)\"\n by (auto elim: FVars_cases intro: FVars_intros)\n\n(* DONE with emancipation of FVars *)\n\nlemma FVars_map_T_le:\n fixes u::\"'a::var_TT\\'a\" assumes u: \"bij u\" \"|supp u| FVars t \\ u a \\ FVars (map_T u t)\"\n apply (induct a t rule: FVars_induct)\n subgoal by (auto simp: assms map_T_simps F_set_map intro!: FVars_intros(1))\n subgoal by (auto simp: assms map_T_simps F_set_map intro!: FVars_intros(2))\n subgoal by (auto simp: assms map_T_simps F_set_map intro!: FVars_intros(3))\n done\n\nlemma FVars_map_T:\n fixes u::\"'a::var_TT\\'a\" assumes u: \"bij u\" \"|supp u| UNION (set4_F x) FVars - set2_F x\"\n\n\ncoinductive alpha:: \"'a::var_TT T \\ 'a T \\ bool\"\n where alpha: \"|supp f| bij f \\ id_on (FVarsB x) f \\\n rel_F id f alpha (\\s s'. alpha (map_T f s) s') x y \\ alpha (ctor x) (ctor y)\"\n monos F_rel_mono[OF supp_id_bound] conj_context_mono\n \nlemmas alpha_def_from_paper = alpha.intros[unfolded rel_F_def]\n \n(* rrel_F alpha (\\s s'. alpha (map_T f s) s') (map_F id f id id x) y *)\n\nlemma alpha_refl:\n \"alpha t t\"\n apply (coinduction arbitrary: t rule: alpha.coinduct)\n subgoal for t\n apply (cases t)\n apply (auto simp only: supp_id_bound T_map_id T.inject ex_simps simp_thms\n intro!: F.rel_refl_strong alpha exI[of _ id])\n done\n done\n\nlemma alpha_bij:\n fixes u :: \"'a::var_TT\\ 'a\" and v :: \"'a::var_TT\\ 'a\"\n assumes \"alpha t t'\" \"\\x \\ FVars t. u x = v x\" \"bij u\" \"|supp u| 'a\"\n assumes \"bij u\" \"|supp u| 'a\"\n assumes u: \"bij u\" \"|supp u| FVars t \\ alpha t t' \\ x \\ FVars t'\"\n apply (induct x t arbitrary: t' rule: FVars_induct; elim alpha.cases)\n apply (simp_all only: T.inject FVars_ctor)\n apply (rule UnI1, rule UnI1)\n apply (drule rel_funD[OF F_set_transfer(1)[OF supp_id_bound], rotated -1];\n auto simp only: Grp_UNIV_id image_id)\n apply (rule UnI1, rule UnI2)\n apply (drule rel_funD[OF F_set_transfer(3)[OF supp_id_bound], rotated -1];\n auto 0 3 simp only: rel_set_def)\n apply (rule UnI2)\n apply (frule rel_funD[OF F_set_transfer(2)[OF supp_id_bound], rotated -1]; (simp only: Grp_def)?)\n apply (drule conjunct1)\n apply (drule rel_funD[OF F_set_transfer(4)[OF supp_id_bound], rotated -1]; (simp only: rel_set_def)?)\n apply (erule conjE)\n apply (drule bspec, assumption, erule bexE)\n apply (drule alpha_bij_eq_inv[THEN iffD1, rotated -1]; (simp only: )?)\n apply (drule meta_spec, drule meta_mp, assumption)\n apply (simp only: FVars_map_T bij_imp_bij_inv supp_inv_bound)\n apply (rule DiffI)\n apply (erule UN_I)\n apply (auto simp only: id_on_def Diff_iff Union_iff bex_simps\n inv_simp2 bij_implies_inject)\n done\n\nlemma alpha_FVars_le':\n \"x \\ FVars t' \\ alpha t t' \\ x \\ FVars t\"\n apply (induct x t' arbitrary: t rule: FVars_induct; elim alpha.cases)\n apply (simp_all only: T.inject FVars_ctor)\n apply (rule UnI1, rule UnI1)\n apply (drule rel_funD[OF F_set_transfer(1)[OF supp_id_bound], rotated -1];\n auto simp only: Grp_UNIV_id image_id)\n apply (rule UnI1, rule UnI2)\n apply (drule rel_funD[OF F_set_transfer(3)[OF supp_id_bound], rotated -1];\n auto 0 3 simp only: rel_set_def)\n apply (rule UnI2)\n apply (frule rel_funD[OF F_set_transfer(2)[OF supp_id_bound], rotated -1]; (simp only: Grp_def)?)\n apply (drule conjunct1)\n apply (drule rel_funD[OF F_set_transfer(4)[OF supp_id_bound], rotated -1]; (simp only: rel_set_def)?)\n apply (erule conjE)\n apply (drule bspec, assumption, erule bexE)\n apply (drule meta_spec, drule meta_mp, assumption)\n apply (simp only: FVars_map_T bij_imp_bij_inv supp_inv_bound image_iff bex_simps)\n apply (erule bexE)\n apply hypsubst\n apply (simp only: id_on_def)\n apply (frule spec, drule mp, rule DiffI, rule UN_I, assumption, assumption)\n apply (auto simp only: )\n done\n\nlemma alpha_FVars:\n \"alpha t t' \\ FVars t = FVars t'\"\n apply (rule set_eqI iffI)+\n apply (erule alpha_FVars_le, assumption)\n apply (erule alpha_FVars_le', assumption)\n done\n\n\nlemma alpha_sym:\n \"alpha t t' \\ alpha t' t\"\n apply (coinduction arbitrary: t t' rule: alpha.coinduct)\n apply (elim alpha.cases; hypsubst)\n subgoal for _ _ f x y\n apply (rule exI[of _ \"inv f\"] exI conjI refl)+\n apply (rule supp_inv_bound; assumption)\n apply (rule conjI)\n apply (erule bij_imp_bij_inv)\n apply (rule conjI[rotated])\n apply (rule F_rel_flip[THEN iffD1])\n apply (auto simp only: supp_inv_bound bij_imp_bij_inv id_on_inv alpha_bij_eq_inv\n inv_id supp_id_bound inv_inv_eq elim!: F_rel_mono_strong0[rotated 6]) [5]\n apply (frule rel_funD[OF F_set_transfer(2)[OF supp_id_bound], rotated -1]; (simp only: Grp_def)?)\n apply (drule conjunct1)\n apply (drule rel_funD[OF F_set_transfer(4)[OF supp_id_bound], rotated -1]; (simp only: FVars_map_T)?)\n apply (drule rel_set_mono[OF predicate2I, THEN predicate2D, rotated -1])\n apply (erule alpha_FVars)\n apply (drule rel_set_UN_D[symmetric])\n apply (simp only: image_UN[symmetric] FVars_map_T image_set_diff[symmetric] bij_is_inj\n id_on_image id_on_inv)\n done\n done\n\nlemma alpha_trans:\n \"alpha t s \\ alpha s r \\ alpha t r\"\n apply (coinduction arbitrary: t s r rule: alpha.coinduct)\n apply (elim alpha.cases; hypsubst_thin, unfold T.inject)\n subgoal for _ _ _ f x _ g y z\n apply (rule exI[of _ \"g o f\"])\n apply (rule exI[of _ \"x\"])\n apply (rule exI[of _ \"z\"])\n apply (auto simp only: supp_comp_bound bij_comp id_on_comp\n supp_id_bound T_map_comp alpha_bij_eq_inv[of g] ex_simps simp_thms\n elim!: F_rel_mono[THEN predicate2D, rotated -1, OF F_rel_comp_leq[THEN predicate2D],\n of id id, unfolded id_o, rotated 6, OF relcomppI])\n apply (frule rel_funD[OF F_set_transfer(2)[OF supp_id_bound], rotated -1]; (simp only: Grp_def)?)\n apply (drule conjunct1)\n apply (drule rel_funD[OF F_set_transfer(4)[OF supp_id_bound], rotated -1]; (simp only: FVars_map_T)?)\n apply (drule rel_set_mono[OF predicate2I, THEN predicate2D, rotated -1])\n apply (erule alpha_FVars)\n apply (drule rel_set_UN_D[THEN sym])\n apply (simp only: image_UN[symmetric] FVars_map_T image_set_diff[symmetric] bij_is_inj)\n subgoal for xx yy zz\n apply (rule exI[of _ \"map_T g zz\"])\n apply (auto simp only: inv_o_simp1 T_map_id T_map_comp[symmetric] bij_imp_bij_inv supp_inv_bound alpha_bij_eq_inv[of g])\n done\n done\n done\n\n(* Some refreshments... *)\n\nlemmas card_of_FVarsB_bound =\n ordLeq_ordLess_trans[OF card_of_diff UNION_bound[OF set4_F_bound card_of_FVars_bound]]\n\nlemma refresh_set2_F:\n fixes t :: \"('a::var_TT) T\" and x :: \"('a, 'a, 'a T, 'a T) F\" assumes A: \"|A::'a set| f. |supp f| bij f \\ id_on (FVarsB x) f \\ set2_F (map_F id f id (map_T f) x) \\ A = {}\"\n apply (insert card_of_ordLeq[THEN iffD2, OF ordLess_imp_ordLeq, of \"set2_F x \\ A\" \"UNIV - (set2_F x \\ FVarsB x \\ A)\"])\n apply (drule meta_mp)\n apply (rule ordLess_ordIso_trans)\n apply (rule ordLeq_ordLess_trans[OF card_of_mono1[OF Int_lower1]])\n apply (rule set2_F_bound)\n apply (rule ordIso_symmetric)\n apply (rule infinite_UNIV_card_of_minus[OF var_TT_infinite])\n apply (rule Un_bound[OF Un_bound[OF set2_F_bound card_of_FVarsB_bound] A])\n apply (erule exE conjE)+\n subgoal for u\n apply (insert extU[of u \"set2_F x \\ A\" \"u ` (set2_F x \\ A)\"])\n apply (rule exI[of _ \"extU (set2_F x \\ A) (u ` (set2_F x \\ A)) u\"])\n apply (drule meta_mp)\n apply (erule inj_on_imp_bij_betw)\n apply (drule meta_mp)\n apply auto []\n apply (erule conjE)+\n apply (rule context_conjI)\n apply (erule ordLeq_ordLess_trans[OF card_of_mono1])\n apply (rule Un_bound)\n apply (rule ordLeq_ordLess_trans[OF card_of_mono1[OF Int_lower1]])\n apply (rule set2_F_bound)\n apply (rule ordLeq_ordLess_trans[OF card_of_image])\n apply (rule ordLeq_ordLess_trans[OF card_of_mono1[OF Int_lower1]])\n apply (rule set2_F_bound)\n apply (rule conjI)\n apply assumption\n apply (rule conjI)\n apply (erule id_on_antimono)\n apply blast\n apply (auto simp only: F_set_map supp_id_bound)\n subgoal\n apply (auto simp only: extU_def split: if_splits)\n done\n done\n done\n\ninductive subshape :: \"'a::var_TT T \\ 'a T \\ bool\" where\n \"bij u \\ |supp u| alpha (map_T u tt) uu \\ uu \\ set3_F x \\ set4_F x \\\n subshape tt (ctor x)\"\n\nlemma subshape_induct_raw:\n assumes IH: \"\\ t::'a::var_TT T. (\\ tt. subshape tt t \\ P tt) \\ P t\"\n shows \"bij g \\ |supp g| alpha (map_T g t) u \\ P u\"\n apply (induction t arbitrary: u g rule: T.induct)\n apply (rule IH)\n apply (auto simp only: map_T_simps True_implies_equals F_rel_map supp_comp_bound bij_comp\n supp_id_bound bij_id id_o\n elim!: alpha.cases)\n apply (elim subshape.cases UnE; simp only: T.inject; hypsubst_thin)\n subgoal premises prems for x g _ f _ h t a y\n apply (insert prems(3-12))\n apply (drule F_set3_transfer[THEN rel_funD, rotated -1];\n (simp only: bij_comp supp_comp_bound)?)\n apply (drule rel_setD2, assumption)\n apply (erule bexE relcomppE GrpE)+\n apply hypsubst_thin\n apply (erule prems(1)[of _ \"inv h o g\"])\n apply (auto simp only: bij_comp bij_imp_bij_inv supp_comp_bound supp_inv_bound T_map_comp\n alpha_bij_eq_inv[of \"inv _\"] inv_inv_eq elim!: alpha_trans alpha_sym)\n done\n subgoal premises prems for x g _ f _ h t a y\n apply (insert prems(3-12))\n apply (drule F_set4_transfer[THEN rel_funD, rotated -1];\n (simp only: bij_comp supp_comp_bound)?)\n apply (drule rel_setD2, assumption)\n apply (erule bexE relcomppE GrpE)+\n apply hypsubst_thin\n apply (erule prems(2)[of _ \"inv h o f o g\"])\n apply (auto simp only: bij_comp bij_imp_bij_inv supp_comp_bound supp_inv_bound T_map_comp\n alpha_bij_eq_inv[of \"inv _\"] inv_inv_eq elim!: alpha_trans alpha_sym)\n done\n done\n\nlemmas subshape_induct[case_names subsh] =\n subshape_induct_raw[OF _ bij_id supp_id_bound, unfolded T_map_id, OF _ alpha_refl]\n\nlemma refresh:\n fixes x :: \"('a::var_TT, 'a, 'a T, 'a T) F\" assumes A: \"|A::'a set| x'. set2_F x' \\ A = {} \\ alpha (ctor x) (ctor x')\"\n apply (insert refresh_set2_F[OF A, of x])\n apply (erule exE conjE)+\n subgoal for f\n apply (rule exI[of _ \"map_F id f id (map_T f) x\"])\n apply (erule conjI)\n apply (rule alpha[of f]; assumption?)\n apply (simp only: F_rel_map_right_bij bij_id supp_id_bound relcompp_conversep_Grp id_apply\n inv_o_simp1 alpha_refl F.rel_refl)\n done\n done\n\nlemma alpha_fresh_cases:\n \"alpha (ctor x) (ctor y) \\ set2_F x \\ A = {} \\ set2_F y \\ A = {} \\\n |A| \n (\\f :: 'a \\ 'a. |supp f| bij f \\ id_on (FVarsB x) f \\\n imsupp f \\ A = {} \\\n rel_F id f alpha (\\s. alpha (map_T f s)) x y \\ P) \\\n P\"\n apply (erule alpha.cases)\n subgoal for f x y\n apply (unfold T.inject)\n apply (hypsubst_thin)\n apply (frule avoiding_bij(1)[of f \"FVarsB x\" \"set2_F x\" \"A\"];\n (auto simp only: var_TT_infinite simp_thms Un_bound UNION_bound card_of_FVarsB_bound set2_F_bound)?)\n apply (frule avoiding_bij(2)[of f \"FVarsB x\" \"set2_F x\" \"A\"];\n (auto simp only: var_TT_infinite simp_thms Un_bound UNION_bound card_of_FVarsB_bound set2_F_bound)?)\n apply (frule avoiding_bij(3)[of f \"FVarsB x\" \"set2_F x\" \"A\"];\n (auto simp only: var_TT_infinite simp_thms Un_bound UNION_bound card_of_FVarsB_bound set2_F_bound)?)\n apply (frule avoiding_bij(4)[of f \"FVarsB x\" \"set2_F x\" \"A\"];\n (auto simp only: var_TT_infinite simp_thms Un_bound UNION_bound card_of_FVarsB_bound set2_F_bound)?)\n apply (frule avoiding_bij(5)[of f \"FVarsB x\" \"set2_F x\" \"A\"];\n (auto simp only: var_TT_infinite simp_thms Un_bound UNION_bound card_of_FVarsB_bound set2_F_bound)?)\n apply (drule meta_spec[of _ \"avoiding_bij f (FVarsB x) (set2_F x) (A)\"])\n apply (drule meta_mp, assumption)\n apply (drule meta_mp, assumption)\n apply (drule meta_mp, assumption)\n apply (drule meta_mp) apply blast\n apply (erule meta_mp)\n apply (frule F_set2_transfer[THEN rel_funD, rotated -1];\n (simp only: supp_id_bound)?)\n apply (erule F_rel_mono_strong0[rotated 6];\n auto simp only: supp_id_bound Grp_def)\n apply (rule sym)\n apply (drule spec, erule mp, auto) []\n apply (erule alpha_trans[rotated])\n apply (rule alpha_bij[OF alpha_refl]; assumption?)\n apply (rule ballI)\n subgoal for _ _ z\n apply (cases \"z \\ set2_F x\")\n apply (auto simp only: id_on_def dest!: spec[of _ z])\n done\n done\n done\n\n(* destruct avoiding a set: *)\ndefinition avoid :: \"('a::var_TT, 'a, 'a T, 'a T) F \\ 'a set \\ ('a::var_TT, 'a, 'a T, 'a T) F\" where\n \"avoid x A \\ \n (if set2_F x \\ A = {} then x else (SOME x'. set2_F x' \\ A = {} \\ alpha (ctor x) (ctor x')))\"\n\nlemma avoid:\n fixes x :: \"('a::var_TT, 'a, 'a T, 'a T) F\"\n assumes A: \"|A| A = {}\" and alpha_avoid: \"alpha (ctor x) (ctor (avoid x A))\"\n using someI_ex[OF refresh[OF A, of x]] unfolding avoid_def\n by (auto simp only: alpha_refl split: if_splits)\n\nlemma avoid_triv:\n fixes x :: \"('a::var_TT, 'a, 'a T, 'a T) F\"\n shows \"set2_F x \\ A = {} \\ avoid x A = x\"\n by (auto simp only: avoid_def split: if_splits)\n\nlemma supp_asSS_bound:\n \"|supp (asSS f::'a::var_TT\\'a)| subshape tt x \\ subshape tt y\"\n apply (erule alpha.cases subshape.cases)+\n apply hypsubst_thin\n apply (unfold T.inject)\n apply hypsubst_thin\n subgoal for f _ y u _ _ x g a b\n apply (erule UnE)\n apply (drule F_set3_transfer[THEN rel_funD, rotated -1]; (simp only: supp_id_bound)?)\n apply (drule rel_setD1, assumption)\n apply (erule bexE conjE)+\n apply (rule subshape.intros[of \"u\", OF _ _ _ UnI1]; simp)\n apply (erule alpha_trans[rotated])\n apply (rule alpha[of g]; assumption)\n apply (drule F_set4_transfer[THEN rel_funD, rotated -1]; (simp only: supp_id_bound)?)\n apply (drule rel_setD1, assumption)\n apply (erule bexE conjE)+\n apply (rule subshape.intros[of \"f o u\", OF _ _ _ UnI2]; simp add: supp_comp_bound T_map_comp)\n apply (erule alpha_trans[rotated])\n apply (rule alpha_bij; simp?)\n apply (rule alpha[of \"g\"]; simp?)\n done\n done\n\nlemma subshape_avoid:\n fixes x :: \"('a::var_TT, 'a, 'a T, 'a T)F\"\n assumes \"|A| subshape tt (ctor x)\"\n apply (rule iffI)\n apply (erule alpha_subshape[OF alpha_sym[OF alpha_avoid[OF assms]]])\n apply (erule alpha_subshape[OF alpha_avoid[OF assms]])\n done\n\nabbreviation cl :: \"('a::var_TT T \\ 'a T \\ bool) \\ 'a T \\ 'a T \\ bool\" where\n \"cl X x y \\\n (\\g. |supp g| bij g \\ X (map_T g x) (map_T g y)) \\ alpha x y\"\n\nlemma alpha_coinduct_upto[case_names C]:\n \"X x1 x2 \\\n (\\x1 x2. X x1 x2 \\\n \\(f :: 'a::var_TT \\ 'a) x y. x1 = ctor x \\\n x2 = ctor y \\\n |supp f| \n bij f \\\n id_on (FVarsB x) f \\\n rel_F id f (cl X) (\\s s'. cl X (map_T f s) s') x y) \\\n alpha x1 x2\"\n apply (rule alpha.coinduct[of \"cl X\"])\n apply (rule disjI1)\n apply (rule exI[of _ id])\n apply (simp only: bij_id supp_id_bound simp_thms T_map_id)\n apply (erule thin_rl)\n apply (erule disjE exE conjE)+\n apply (drule meta_spec2, drule meta_mp, assumption)\n apply (erule exE conjE)+\n subgoal for l r g f x y\n apply (cases l; cases r)\n apply (auto simp only: map_T_simps T.inject ex_simps simp_thms F_rel_map bij_id supp_id_bound\n o_id bij_comp supp_comp_bound bij_imp_bij_inv supp_inv_bound inv_o_simp1 id_on_def o_apply\n F_set_map UN_simps FVars_map_T inv_simp1\n intro!: exI[of _ \"inv g \\ f \\ g\"])\n subgoal for _ _ a\n apply (drule spec[of _ \"g a\"])\n apply (auto simp only: inv_simp1 bij_implies_inject)\n done\n subgoal\n apply (erule F_rel_mono_strong0[rotated 6]; (auto simp only: supp_id_bound\n alpha_bij_eq alpha_bij_eq_inv[of \"inv g\"] inv_inv_eq\n bij_comp supp_comp_bound bij_imp_bij_inv supp_inv_bound Grp_def T_map_comp)?)\n subgoal for _ _ h\n apply (auto simp only: bij_comp supp_comp_bound T_map_comp intro!: exI[of _ \"h o g\"])\n done\n subgoal for _ _ h\n apply (auto simp only: bij_comp supp_comp_bound bij_imp_bij_inv supp_inv_bound\n T_map_comp[symmetric] o_assoc rewriteR_comp_comp[OF inv_o_simp2] o_id intro!: exI[of _ \"h o g\"])\n done\n done\n done\n apply (erule thin_rl)\n apply (erule alpha.cases)\n subgoal for _ _ f x y\n apply (rule exI[of _ f])\n apply (auto simp only: supp_id_bound T.inject ex_simps simp_thms\n elim!: F_rel_mono_strong0[rotated 6])\n done\n done\n\n\n(*********************************)\n(* Quotienting *)\n(*********************************)\n\nquotient_type 'a TT = \"'a::var_TT T\" \/ alpha\n unfolding equivp_def fun_eq_iff using alpha_sym alpha_trans alpha_refl by blast\n\nlemma Quotient_F[quot_map]:\n \"Quotient R Abs Rep T \\ Quotient R' Abs' Rep' T' \\\n Quotient (rel_F_id R R') (map_F id id Abs Abs') (map_F id id Rep Rep') (rel_F_id T T')\"\n unfolding Quotient_alt_def5 unfolding rel_F_id_def\n unfolding F.rel_conversep[symmetric]\n unfolding F_rel_Grp[OF supp_id_bound bij_id supp_id_bound, symmetric]\n unfolding F.rel_compp[symmetric]\n by (auto elim!: F.rel_mono_strong)\n\n(* Lifted concepts, from terms to tterms: *)\n\nlift_definition cctor :: \"('a::var_TT, 'a, 'a TT,'a TT) F \\ 'a TT\" is ctor\n apply (rule alpha[of id])\n apply (unfold rel_F_id_def)\n apply (simp_all only: supp_id_bound bij_id id_on_id T_map_id)\n done\n\nlemma abs_TT_ctor: \"abs_TT (ctor x) = cctor (map_F id id abs_TT abs_TT x)\"\n unfolding cctor_def map_fun_def o_apply unfolding F.map_comp\n unfolding TT.abs_eq_iff\n apply (rule alpha[of id])\n apply (auto simp only: F.rel_map Grp_def supp_id_bound T_map_id o_apply\n alpha_sym[OF Quotient3_rep_abs[OF Quotient3_TT alpha_refl]]\n intro!: F.rel_refl)\n done\n\nlift_definition map_TT :: \"('a::var_TT \\ 'a) \\ 'a TT \\ 'a TT\"\n is \"map_T o asSS o asBij\"\n by (auto simp: alpha_bij_eq asBij_def asSS_def supp_id_bound)\n\ndeclare F.map_transfer[folded rel_F_id_def, transfer_rule]\ndeclare map_F_transfer[folded rel_F_id_def, transfer_rule]\n\nlemma map_TT_cctor:\n fixes f :: \"'a::var_TT \\ 'a\"\n assumes \"bij f\" and \"|supp f| f. bij f \\ |supp f| f. |supp f| 'a set\" is FVars\n by (simp add: alpha_FVars)\n\nlemma abs_rep_TT: \"abs_TT \\ rep_TT = id\" \n apply(rule ext) \n by simp (meson Quotient3_TT Quotient3_def)\n\nlemma abs_rep_TT2: \"abs_TT (rep_TT t) = t\" \n by (simp add: abs_rep_TT comp_eq_dest_lhs)\n\nlemma alpha_rep_abs_TT: \"alpha (rep_TT (abs_TT t)) t\" \n using TT.abs_eq_iff abs_rep_TT2 by blast\n\nlemma alpha_ctor_rep_TT_abs_TT: \n\"alpha (ctor (map_F id id (rep_TT \\ abs_TT) (rep_TT \\ abs_TT) x)) (ctor x)\"\nby (auto intro!: alpha.intros[of id] F.rel_refl_strong \n simp: supp_id_bound F_rel_map Grp_def OO_def T_map_id alpha_rep_abs_TT)\n\nlemma card_of_FFVars_bound: \"|FFVars t| TT. \\x. TT = cctor x\"\n apply transfer\n apply (rule allI)\n subgoal for t by (cases t) (auto simp only: intro: alpha_refl)\n done\n\nlemma FFVars_simps:\n \"FFVars (cctor x) =\n set1_F x \\ (\\t'\\set3_F x. FFVars t') \\ ((\\t'\\set4_F x. FFVars t') - set2_F x)\"\n apply transfer\n apply (rule FVars_ctor)\n done\n\nlemma FFVars_intros[rule_format]:\n \"\\a \\ set1_F t. a \\ FFVars (cctor t)\"\n \"\\t' \\ set3_F t. \\a \\ FFVars t'. a \\ FFVars (cctor t)\"\n \"\\t' \\ set4_F t. \\a \\ FFVars t' - set2_F t. a \\ FFVars (cctor t)\"\n apply (transfer; auto intro: FVars_intros)+\n done\n\nlemma FFVars_cases:\n \"a \\ FFVars (cctor t) \\\n (\\a \\ set1_F t. P) \\\n (\\t' \\ set3_F t. \\a \\ FFVars t'. P) \\\n (\\t' \\ set4_F t. \\a \\ FFVars t' - set2_F t. P) \\\n P\"\n by transfer (auto elim: FVars_cases)\n\nlemma FFVars_induct:\n \"a \\ FFVars (cctor t) \\\n (\\t. \\a \\ set1_F t. P a (cctor t)) \\\n (\\t. \\t' \\ set3_F t. \\a \\ FFVars t'. P a t' \\ P a (cctor t)) \\\n (\\t. \\t' \\ set4_F t. \\a \\ FFVars t'. a \\ set2_F t \\ P a t' \\ P a (cctor t)) \\\n P a (cctor t)\"\n apply transfer\n apply (erule FVars_induct)\n apply simp_all\n done\n\n(* Nonstandard transfer (sensitive to bindings) *)\n\n(* Useful for fresh structural induction and fresh cases: *)\ntheorem fresh_nchotomy:\n fixes t :: \"('a::var_TT) TT\" assumes A: \"|A::'a set| x. t = cctor x \\ set2_F x \\ A = {}\"\n using assms apply transfer\n subgoal for A t by (cases t; auto dest: alpha_avoid avoid_fresh)\n done\n\ntheorem fresh_cases:\n fixes t :: \"('a::var_TT) TT\" assumes A: \"|A::'a set| A = {}\"\n using fresh_nchotomy[OF assms, of t] by auto\n\n(* This should _not_ be declared as a simp rule, since, thanks\nto fresh induction, we will often use plain equality for x and x'\nto deduce ctor x = ctor x' *)\ntheorem TT_inject0:\n fixes x x' :: \"('a::var_TT, 'a, 'a TT,'a TT) F\"\n shows \"cctor x = cctor x' \\\n (\\f. bij f \\ |supp f| id_on ((\\t \\ set4_F x. FFVars t)- set2_F x) f \\\n map_F id f id (map_TT f) x = x')\"\n apply (simp only: F.rel_eq[symmetric] F_rel_map bij_id supp_id_bound id_o o_id o_apply\n Grp_def id_apply UNIV_I simp_thms OO_eq id_on_def cctor_def map_fun_def TT.abs_eq_iff\n cong: conj_cong)\n apply (safe elim!: alpha.cases)\n subgoal for f\n apply (rule exI[of _ f])\n apply (auto 3 0 simp only: F_rel_map F_set_map id_on_def FFVars_def supp_id_bound bij_id\n Quotient3_rel_rep[OF Quotient3_TT] map_TT_def asBij_def asSS_def Grp_def alpha_refl\n map_fun_def o_id inv_id id_o o_apply id_apply if_True image_id Diff_iff UN_iff\n elim!: F_rel_mono_strong0[rotated 6] alpha_sym[OF alpha_trans[rotated]]\n intro!: trans[OF Quotient3_abs_rep[OF Quotient3_TT, symmetric], OF TT.abs_eq_iff[THEN iffD2]])\n done\n subgoal for f\n apply (rule alpha[of f])\n apply (auto 3 0 simp only: F_rel_map F_set_map id_on_def FFVars_def supp_id_bound bij_id\n map_fun_def o_id inv_id id_o o_apply id_apply if_True image_id Diff_iff UN_iff asBij_def asSS_def\n relcompp_apply conversep_iff UNIV_I simp_thms Grp_def conj_commute[of _ \"_ = _\"]\n Quotient3_rel_rep[OF Quotient3_TT] map_TT_def alpha_refl\n elim!: F_rel_mono_strong0[rotated 6]\n intro!: Quotient.rep_abs_rsp[OF Quotient3_TT])\n done\n done\n \ntheorem TT_existential_induct[case_names cctor, consumes 1]:\n fixes t:: \"'a::var_TT TT\"\n assumes i:\n \"\\ (x::('a, 'a, 'a TT, 'a TT)F).\n \\ x'. cctor x' = cctor x \\ \n ((\\ t \\. t \\ set3_F x' \\ \\ t) \\ (\\ t \\. t \\ set4_F x' \\ \\ t) \n \\ \n \\ (cctor x'))\"\n shows \"\\ t\"\nproof-\n define tt where \"tt = rep_TT t\"\n {have \"\\ (abs_TT tt)\"\n proof(induct tt rule: subshape_induct)\n case (subsh t)\n obtain x0 where t: \"t = ctor x0\" by (cases t)\n define xx0 where \"xx0 = map_F id id abs_TT abs_TT x0\"\n obtain xx where c_xx: \"cctor xx = cctor xx0\" and \n imp: \"(\\t. t \\ set3_F xx \\ \\ t) \\ (\\t. t \\ set4_F xx \\ \\ t) \\ \\ (cctor xx)\" \n using i[of xx0] by blast \n define x where \"x \\ map_F id id rep_TT rep_TT xx\" \n have al: \"alpha t (ctor x)\" unfolding t using c_xx[symmetric]\n unfolding cctor_def apply auto unfolding xx0_def x_def \n apply(auto simp: F_map_comp[symmetric] supp_id_bound TT.abs_eq_iff)\n using alpha_ctor_rep_TT_abs_TT[of x0] alpha_trans alpha_sym by blast\n have sht: \"\\ tt. subshape tt t = subshape tt (ctor x)\"\n using al alpha_subshape alpha_sym by blast\n have xx: \"xx = map_F id id abs_TT abs_TT x\" unfolding x_def \n by (simp add: F_map_comp[symmetric] F_map_id supp_id_bound abs_rep_TT)\n have 0: \"abs_TT t = abs_TT (ctor x)\" using al by (simp add: TT.abs_eq_iff )\n show ?case unfolding 0 abs_TT_ctor apply(rule imp[unfolded xx])\n by (auto simp: F_set_map supp_id_bound T_map_id sht\n intro!: subsh subshape.intros[OF bij_id supp_id_bound alpha_refl]) \n qed\n }\n thus ?thesis unfolding tt_def abs_rep_TT2 .\nqed\n\ntheorem TT_fresh_induct_param[case_names cctor, consumes 1]:\n fixes t:: \"'a::var_TT TT\"\n and Param :: \"'param set\" and varsOf :: \"'param \\ 'a set\"\n assumes param: \"\\ \\. \\ \\ Param \\ |varsOf \\ ::'a set| (x::('a, 'a, 'a TT, 'a TT)F) \\.\n (* induction hypothesis: *)\n \\\\t \\. \\t \\ set3_F x; \\ \\ Param\\ \\ \\ t \\;\n \\t \\. \\t \\ set4_F x; \\ \\ Param\\ \\ \\ t \\;\n (* freshness assumption for the parameters: *)\n \\a. \\a \\ set2_F x\\ \\ a \\ varsOf \\;\n (* the next two are the option: *)\n \\a. \\a \\ set2_F x\\ \\ a \\ set1_F x;\n \\a t. \\a \\ set2_F x; t \\ set3_F x\\ \\ a \\ FFVars t;\n \\ \\ Param\\\n \\\n \\ (cctor x) \\\"\n shows \"\\ \\ \\ Param. \\ t \\\" \nproof-\n define tt where \"tt = rep_TT t\"\n {fix \\ have \"\\ \\ Param \\ \\ (abs_TT tt) \\\"\n proof(induct tt arbitrary: \\ rule: subshape_induct)\n case (subsh t)\n obtain x0 where x0: \"t = ctor x0\" by (cases t)\n define x where x: \"x \\ avoid x0 (varsOf \\ \\ set1_F x0 \\ UNION (set3_F x0) FVars)\"\n define xx where xx: \"xx = map_F id id abs_TT abs_TT x\"\n have al: \"alpha t (ctor x)\"\n unfolding x x0\n by (rule alpha_avoid) (simp only: Un_bound UNION_bound param[OF `\\\\Param`] set1_F_bound set3_F_bound card_of_FVars_bound)\n have sht: \"\\ tt. subshape tt t = subshape tt (ctor x)\"\n unfolding x x0\n by (rule subshape_avoid[symmetric])\n (simp only: Un_bound UNION_bound param[OF `\\\\Param`] set1_F_bound set3_F_bound card_of_FVars_bound)\n have 0: \"abs_TT t = abs_TT (ctor x)\" using al by (simp add: TT.abs_eq_iff)\n show ?case unfolding 0 abs_TT_ctor using avoid_fresh[of \"varsOf \\ \\ set1_F x0 \\ UNION (set3_F x0) FVars\" x0]\n apply (auto 0 3 simp only: F_set_map bij_id supp_id_bound id_apply x sht T_map_id\n Un_bound UNION_bound param[OF `\\\\Param`] set1_F_bound set3_F_bound card_of_FVars_bound\n True_implies_equals\n intro!: i subsh subshape.intros[OF bij_id supp_id_bound alpha_refl])\n subgoal for a\n using al\n apply (rule alpha.cases)\n apply (drule rel_funD[OF F_set_transfer(1), rotated -1])\n apply (auto simp only: image_id eq_alt[symmetric] supp_id_bound x0 x)\n done\n subgoal for a\n using al\n apply (rule alpha.cases)\n apply (drule rel_funD[OF F_set_transfer(3), rotated -1])\n apply (auto 0 3 simp only: image_id eq_alt[symmetric] supp_id_bound x0 x FFVars_def map_fun_def o_apply id_apply\n alpha_FVars[OF Quotient3_rep_abs[OF Quotient3_TT alpha_refl]]\n dest!: alpha_FVars rel_setD2)\n done\n done\n qed\n }\n thus ?thesis unfolding tt_def\n by (metis Quotient3_TT Quotient3_def)\nqed\n\n(* The most useful version of fresh induction: lighter one,\nfor fixed parameters: *)\n\nlemmas TT_fresh_induct = TT_fresh_induct_param[of UNIV \"\\\\. A\" \"\\x \\. P x\" for A P, \n simplified, case_names cctor, consumes 1, induct type]\n\n\nlemmas TT_plain_induct = TT_fresh_induct[OF emp_bound, simplified, case_names cctor]\n\n\ntheorem map_TT_id: \"map_TT id = id\"\n apply (rule ext)\n apply transfer\n apply (auto simp only: o_apply asBij_def asSS_def bij_id supp_id_bound if_True T_map_id id_apply alpha_refl)\n done\n\n(* A particular case of vvsubst_cong (for identity) with map_TT instead pf vvsubst *)\nlemma map_TT_cong_id: \n fixes f::\"'a::var_TT \\ 'a\" \n assumes \"bij f\" and \"|supp f| a. a \\ FFVars t \\ f a = a\" \n shows \"map_TT f t = t\"\n using assms(3)\n apply (induct t rule: TT_fresh_induct[consumes 0, of \"supp f\"])\n apply (simp only: imsupp_supp_bound assms)\n apply (fastforce simp only: map_TT_cctor assms(1,2) TT_inject0 F_map_comp[symmetric] supp_id_bound bij_id\n id_o map_TT_id id_apply FFVars_simps Un_iff UN_iff Diff_iff not_in_supp_alt\n intro!: exI[of _ id] trans[OF F_map_cong F.map_id])\n done\n\n(* One direction of TT_inject with map_TT instead pf vvsubst *)\nlemma cctor_eq_intro_map_TT: \n fixes f :: \"'a::var_TT\\'a\"\n assumes \"bij f\" \"|supp f| t\\set4_F x. FFVars t) - set2_F x) f\" and \"map_F id f id (map_TT f) x = x'\"\n shows \"cctor x = cctor x'\"\n unfolding TT_inject0\n by (rule exI[of _ f] conjI assms)+\n\nend\n","avg_line_length":44.8605482718,"max_line_length":186,"alphanum_fraction":0.676789415} {"size":465,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"name: hol-floating-point\nversion: 1.1\ndescription: HOL floating point theories\nauthor: HOL OpenTheory Packager \nlicense: MIT\nrequires: base\nrequires: hol-base\nrequires: hol-words\nrequires: hol-integer\nrequires: hol-real\nshow: \"HOL4\"\nshow: \"Data.Bool\"\nshow: \"Data.Pair\"\nshow: \"Function\"\nshow: \"Number.Natural\"\nshow: \"Relation\"\nmain {\n article: \"hol4-floating-point-unint.art\"\n interpretation: \"..\/opentheory\/hol4.int\"\n}\n","avg_line_length":22.1428571429,"max_line_length":76,"alphanum_fraction":0.7612903226} {"size":185,"ext":"thy","lang":"Isabelle","max_stars_count":102.0,"content":"(*\n Authors: Wenda Li\n*)\n\ntheory amc12b_2004_p3 imports\n Complex_Main\nbegin\n\ntheorem amc12b_2004_p3:\n fixes x y :: nat\n assumes \"2^x * 3^y = 1296\"\n shows \"x + y = 8\" \n sorry\n\nend\n","avg_line_length":11.5625,"max_line_length":29,"alphanum_fraction":0.6486486486} {"size":1671,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/n_german.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_german Protocol Case Study*} \n\ntheory n_german imports n_german_lemma_invs_on_rules n_german_on_inis\nbegin\nlemma main:\nassumes a1: \"s \\ reachableSet {andList (allInitSpecs N)} (rules N)\"\nand a2: \"0 < N\"\nshows \"\\ f. f \\ (invariants N) --> formEval f s\"\nproof (rule consistentLemma)\nshow \"consistent (invariants N) {andList (allInitSpecs N)} (rules N)\"\nproof (cut_tac a1, unfold consistent_def, rule conjI)\nshow \"\\ f ini s. f \\ (invariants N) --> ini \\ {andList (allInitSpecs N)} --> formEval ini s --> formEval f s\"\nproof ((rule allI)+, (rule impI)+)\n fix f ini s\n assume b1: \"f \\ (invariants N)\" and b2: \"ini \\ {andList (allInitSpecs N)}\" and b3: \"formEval ini s\"\n have b4: \"formEval (andList (allInitSpecs N)) s\"\n apply (cut_tac b2 b3, simp) done\n show \"formEval f s\"\n apply (rule on_inis, cut_tac b1, assumption, cut_tac b2, assumption, cut_tac b3, assumption) done\nqed\nnext show \"\\ f r s. f \\ invariants N --> r \\ rules N --> invHoldForRule s f r (invariants N)\"\nproof ((rule allI)+, (rule impI)+)\n fix f r s\n assume b1: \"f \\ invariants N\" and b2: \"r \\ rules N\"\n show \"invHoldForRule s f r (invariants N)\"\n apply (rule invs_on_rules, cut_tac b1, assumption, cut_tac b2, assumption) done\nqed\nqed\nnext show \"s \\ reachableSet {andList (allInitSpecs N)} (rules N)\"\n apply (metis a1) done\nqed\nend\n","avg_line_length":43.9736842105,"max_line_length":132,"alphanum_fraction":0.6965888689} {"size":8293,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"theory \"Transition_Systems-Mutation_Systems\"\nimports\n \"Transition_Systems-Simulation_Systems\"\nbegin\n\nprimrec with_shortcut :: \"('a \\ 'p relation) \\ ('a option \\ 'p relation)\" where\n \"with_shortcut \\ None = (=)\" |\n \"with_shortcut \\ (Some \\) = \\ \\\"\n\nlocale mutation_system =\n simulation_system \\original_transition\\ \\simulating_transition\\\n for\n original_transition :: \"'a \\ 'p relation\" (\\'(\\\\_\\')\\)\n and\n simulating_transition :: \"'a \\ 'p relation\" (\\'(\\\\_\\')\\)\n +\n fixes\n original_shortcut_transition :: \"'a option \\ 'p relation\" (\\'(\\\\<^sup>?\\_\\')\\)\n fixes\n simulating_shortcut_transition :: \"'a option \\ 'p relation\" (\\'(\\\\<^sup>?\\_\\')\\)\n fixes\n universe :: \"'p relation set\" (\\\\\\)\n fixes\n mutation_transition_std :: \"'p relation \\ 'a \\ 'a option \\ 'p relation \\ bool\"\n (\\(_ \\\\_ \\ _\\\/ _)\\ [51, 0, 0, 51] 50)\n defines original_shortcut_transition_def [simp]:\n \"original_shortcut_transition \\ with_shortcut original_transition\"\n defines simulating_shortcut_transition_def [simp]:\n \"simulating_shortcut_transition \\ with_shortcut simulating_transition\"\n assumes mutation_transition_std_is_type_correct:\n \"\\\\ \\ I J. I \\\\\\ \\ \\\\ J \\ I \\ \\ \\ J \\ \\\"\n assumes dissection:\n \"\\\\. \\I \\ \\. I OO (\\\\\\\\) \\ \\ {(\\\\<^sup>?\\\\\\) OO J | \\ J. I \\\\\\ \\ \\\\ J}\"\n assumes connection:\n \"\\\\. \\J \\ \\. \\ {I\\\\ OO (\\\\<^sup>?\\\\\\) | \\ I. I \\\\\\ \\ \\\\ J} \\ (\\\\\\\\) OO J\\\\\"\nbegin\n\ntext \\\n The introduction of an explicit \\<^term>\\mutation_transition_std\\ relation has the following\n advantages:\n\n \\<^item> We can replace Sangiorgi's seemingly \\<^emph>\\ad hoc\\ condition by a pair of conditions that are in\n perfect duality.\n\n \\<^item> We can refer from the outside to the data that is only guaranteed to exist in the case of\n Sangiorgi's condition. This is crucial for the specification of weak mutation systems.\n\\\n\ndefinition mutant_lifting :: \"'p relation \\ 'p relation\" (\\\\\\) where\n [simp]: \"\\ = (\\K. (\\I \\ \\. I\\\\ OO K OO I))\"\n\ncontext begin\n\ntext \\\n This is the place where we finally need the extra condition \\<^term>\\K \\ L\\ that sets apart\n \\<^term>\\K \\ L\\ from \\<^term>\\K \\ L\\.\n\\\n\nprivate lemma unilateral_shortcut_progression:\n assumes \"K \\ L\" and \"K \\ L\"\n shows \"K\\\\ OO (\\\\<^sup>?\\\\\\) \\ (\\\\<^sup>?\\\\\\) OO L\\\\\"\n using assms by (cases \\) auto\n\nprivate lemma unilateral_mutant_progression:\n assumes \"K \\ L\" and \"K \\ L\"\n shows \"\\ K \\ \\ L\"\nproof -\n have \"(\\I \\ \\. I\\\\ OO K OO I)\\\\ OO (\\\\\\\\) \\ (\\\\\\\\) OO (\\J \\ \\. J\\\\ OO L OO J)\\\\\" for \\\n proof -\n have \"(\\I \\ \\. I\\\\ OO K OO I)\\\\ OO (\\\\\\\\) = (\\I \\ \\. I\\\\ OO K\\\\ OO I) OO (\\\\\\\\)\"\n by blast\n also have \"\\ = (\\I \\ \\. I\\\\ OO K\\\\ OO I OO (\\\\\\\\))\"\n by blast\n also have \"\\ \\ (\\I \\ \\. I\\\\ OO K\\\\ OO \\ {(\\\\<^sup>?\\\\\\) OO J | \\ J. I \\\\\\ \\ \\\\ J})\"\n using dissection\n by simp fast\n also have \"\\ = (\\I \\ \\. \\ {I\\\\ OO K\\\\ OO (\\\\<^sup>?\\\\\\) OO J | \\ J. I \\\\\\ \\ \\\\ J})\"\n by blast\n also have \"\\ = \\ {I\\\\ OO K\\\\ OO (\\\\<^sup>?\\\\\\) OO J | \\ I J. I \\\\\\ \\ \\\\ J}\"\n using mutation_transition_std_is_type_correct\n by blast\n also have \"\\ \\ \\ {I\\\\ OO (\\\\<^sup>?\\\\\\) OO L\\\\ OO J | \\ I J. I \\\\\\ \\ \\\\ J}\"\n using unilateral_shortcut_progression [OF \\K \\ L\\ \\K \\ L\\]\n by blast\n also have \"\\ = (\\J \\ \\. \\ {I\\\\ OO (\\\\<^sup>?\\\\\\) OO L\\\\ OO J | \\ I. I \\\\\\ \\ \\\\ J})\"\n using mutation_transition_std_is_type_correct\n by blast\n also have \"\\ = (\\J \\ \\. \\ {I\\\\ OO (\\\\<^sup>?\\\\\\) | \\ I. I \\\\\\ \\ \\\\ J} OO L\\\\ OO J)\"\n by blast\n also have \"\\ \\ (\\J \\ \\. (\\\\\\\\) OO J\\\\ OO L\\\\ OO J)\"\n using connection\n by simp fast\n also have \"\\ = (\\\\\\\\) OO (\\J \\ \\. J\\\\ OO L\\\\ OO J)\"\n by blast\n also have \"\\ = (\\\\\\\\) OO (\\J \\ \\. J\\\\ OO L OO J)\\\\\"\n by blast\n finally show ?thesis .\n qed\n then show ?thesis\n by simp\nqed\n\nlemma mutant_lifting_is_respectful [respectful]:\n shows \"respectful \\\"\nproof -\n have \"\\ K \\ \\ L\" if \"K \\ L\" for K and L\n proof -\n from \\K \\ L\\ have \"K \\ L\" and \"K\\\\ \\ L\\\\\" and \"K \\ L\" and \"K\\\\ \\ L\\\\\"\n by simp_all\n from \\K \\ L\\ have \"\\ K \\ \\ L\"\n by auto\n moreover\n from \\K \\ L\\ and \\K \\ L\\ have \"\\ K \\ \\ L\"\n by (fact unilateral_mutant_progression)\n moreover\n from \\K\\\\ \\ L\\\\\\ and \\K\\\\ \\ L\\\\\\ have \"\\ K\\\\ \\ \\ L\\\\\"\n by (fact unilateral_mutant_progression)\n then have \"(\\ K)\\\\ \\ (\\ L)\\\\\"\n unfolding mutant_lifting_def by blast\n ultimately show ?thesis\n by simp\n qed\n then show ?thesis\n by simp\nqed\n\nend\n\nlemma mutation_is_compatible_with_bisimilarity:\n assumes \"I \\ \\\" and \"I s\\<^sub>1 t\\<^sub>1\" and \"I s\\<^sub>2 t\\<^sub>2\" and \"s\\<^sub>1 \\ s\\<^sub>2\"\n shows \"t\\<^sub>1 \\ t\\<^sub>2\"\n using\n respectfully_transformed_bisimilarity_in_bisimilarity [OF mutant_lifting_is_respectful]\n and\n assms\n by auto\n\nend\n\nend\n","avg_line_length":58.8156028369,"max_line_length":289,"alphanum_fraction":0.6377667913} {"size":337089,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"theory ContainedClassSetFieldValue\n imports\n Main\n \"Ecore-GROOVE-Mapping.Instance_Model_Graph_Mapping\"\n ContainedClassSetField\nbegin\n\nsection \"Definition of an instance model which introduces values for a field typed by a class that can be nullable\"\n\ninductive_set sets_to_set :: \"'a set set \\ 'a set\"\n for A :: \"'a set set\"\n where\n rule_member: \"\\x y. x \\ A \\ y \\ x \\ y \\ sets_to_set A\"\n\ndefinition imod_contained_class_set_field :: \"'t Id \\ 't \\ 't Id \\ multiplicity \\ 'o set \\ ('o \\ 't) \\ ('o \\ 'o list) \\ ('o, 't) instance_model\" where\n \"imod_contained_class_set_field classtype name containedtype mul objects obids values = \\\n Tm = tmod_contained_class_set_field classtype name containedtype mul,\n Object = objects \\ sets_to_set (set ` values ` objects),\n ObjectClass = (\\x. if x \\ objects then classtype else if x \\ sets_to_set (set ` values ` objects) then containedtype else undefined),\n ObjectId = (\\x. if x \\ objects \\ sets_to_set (set ` values ` objects) then obids x else undefined),\n FieldValue = (\\x. if fst x \\ objects \\ snd x = (classtype, name) then setof (map obj (values (fst x))) else\n if fst x \\ sets_to_set (set ` values ` objects) \\ snd x = (classtype, name) then unspecified else undefined),\n DefaultValue = (\\x. undefined)\n \\\"\n\nlemma imod_contained_class_set_field_correct:\n assumes valid_ns: \"\\id_in_ns containedtype (Identifier classtype) \\ \\id_in_ns classtype (Identifier containedtype)\"\n assumes valid_mul: \"multiplicity mul\"\n assumes classtype_containedtype_neq: \"classtype \\ containedtype\"\n assumes objects_unique: \"objects \\ sets_to_set (set ` values ` objects) = {}\"\n assumes unique_ids: \"\\o1 o2. o1 \\ objects \\ sets_to_set (set ` values ` objects) \\ \n o2 \\ objects \\ sets_to_set (set ` values ` objects) \\ obids o1 = obids o2 \\ o1 = o2\"\n assumes unique_sets: \"\\ob. ob \\ objects \\ distinct (values ob)\"\n assumes unique_across_sets: \"\\o1 o2. o1 \\ objects \\ o2 \\ objects \\ o1 \\ o2 \\ set (values o1) \\ set (values o2) = {}\"\n assumes valid_sets: \"\\ob. ob \\ objects \\ length (values ob) in mul\"\n shows \"instance_model (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\nproof (intro instance_model.intro)\n fix ob\n assume \"ob \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n then have \"ob \\ objects \\ sets_to_set (set ` values ` objects)\"\n unfolding imod_contained_class_set_field_def\n by simp\n then have \"ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob = classtype \\\n ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob = containedtype\"\n unfolding imod_contained_class_set_field_def\n by fastforce\n then show \"ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob \\ \n Class (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by simp\nnext\n show \"type_model (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_contained_class_set_field_def\n using tmod_contained_class_set_field_correct valid_ns valid_mul\n by simp\nnext\n fix ob f\n assume \"ob \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values) \\ \n f \\ type_model.Field (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n then have \"ob \\ objects \\ sets_to_set (set ` values ` objects) \\ f \\ (classtype, name)\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by simp\n then show \"FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f) = undefined\"\n unfolding imod_contained_class_set_field_def\n by auto\nnext\n fix ob f\n assume \"ob \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n then have ob_def: \"ob \\ objects \\ sets_to_set (set ` values ` objects)\"\n unfolding imod_contained_class_set_field_def\n by simp\n assume \"f \\ type_model.Field (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n then have f_def: \"f = (classtype, name)\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by simp\n assume no_inh: \"\\\\(ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob) \n \\[Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)] \n \\(class (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) f)\"\n show \"FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f) = unspecified\"\n using ob_def\n proof (elim UnE)\n assume \"ob \\ objects\"\n then have ob_class_def: \"ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob = classtype\"\n unfolding imod_contained_class_set_field_def\n by simp\n then have \"\\(ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob) \\ \n ProperClassType (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n by (simp add: ProperClassType.rule_proper_classes imod_contained_class_set_field_def tmod_contained_class_set_field_def)\n then have ob_type_def: \"\\(ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob) \\ \n Type (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding Type_def NonContainerType_def ClassType_def\n by blast\n have \"ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob = \n class (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) f\"\n unfolding class_def\n by (simp add: f_def ob_class_def)\n then have \"\\(ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob) \n \\[Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)] \n \\(class (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) f)\"\n unfolding subtype_def\n using ob_type_def subtype_rel.reflexivity\n by simp\n then show ?thesis\n using no_inh\n by blast\n next\n assume \"ob \\ sets_to_set (set ` values ` objects)\"\n then show ?thesis\n unfolding imod_contained_class_set_field_def\n using objects_unique f_def\n by fastforce\n qed\nnext\n have type_model_correct: \"type_model (tmod_contained_class_set_field classtype name containedtype mul)\"\n using tmod_contained_class_set_field_correct valid_ns valid_mul\n by metis\n fix ob f\n assume \"ob \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n then have ob_cases: \"ob \\ objects \\ sets_to_set (set ` values ` objects)\"\n unfolding imod_contained_class_set_field_def\n by simp\n assume \"f \\ type_model.Field (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n then have f_def: \"f = (classtype, name)\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by simp\n then have f_type: \"Type_Model.type (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) f = TypeDef.setof \\containedtype\"\n unfolding Type_Model.type_def imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by simp\n have f_lower: \"lower (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) f = Multiplicity.lower mul\"\n unfolding lower_def imod_contained_class_set_field_def tmod_contained_class_set_field_def\n using f_def\n by simp\n have f_upper: \"upper (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) f = Multiplicity.upper mul\"\n unfolding upper_def imod_contained_class_set_field_def tmod_contained_class_set_field_def\n using f_def\n by simp\n assume \"\\(ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob)\n \\[Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)]\n \\(class (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) f)\"\n then have \"\\(ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob)\n \\[tmod_contained_class_set_field classtype name containedtype mul] \\(fst f)\"\n unfolding imod_contained_class_set_field_def class_def\n by simp\n then have \"(\\(ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob), \\(fst f)) \\ \n subtype_rel_altdef (tmod_contained_class_set_field classtype name containedtype mul)\"\n using subtype_def subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_correct\n by blast\n then have ob_def: \"ob \\ objects\"\n unfolding subtype_rel_altdef_def\n proof (elim UnE)\n assume \"(\\(ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob), \\(fst f)) \\ \n subtype_tuple ` Type (tmod_contained_class_set_field classtype name containedtype mul)\"\n then have eq: \"ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob = fst f\"\n by (simp add: image_iff subtype_tuple_def)\n show ?thesis\n using ob_cases\n proof (elim UnE)\n assume \"ob \\ objects\"\n then show ?thesis\n by simp\n next\n assume \"ob \\ sets_to_set (set ` values ` objects)\"\n then have ob_class_def: \"ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob = containedtype\"\n unfolding imod_contained_class_set_field_def\n using objects_unique\n by auto\n then show ?thesis\n using eq classtype_containedtype_neq f_def\n by simp\n qed\n next\n assume \"(\\(ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob), \\(fst f)) \\ \n subtype_conv nullable nullable ` (Inh (tmod_contained_class_set_field classtype name containedtype mul))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob), \\(fst f)) \\ \n subtype_conv proper proper ` (Inh (tmod_contained_class_set_field classtype name containedtype mul))\\<^sup>+\"\n then show ?thesis\n unfolding tmod_contained_class_set_field_def\n by auto\n next\n assume \"(\\(ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob), \\(fst f)) \\ \n subtype_conv proper nullable ` subtype_tuple ` Class (tmod_contained_class_set_field classtype name containedtype mul)\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob), \\(fst f)) \\\n subtype_conv proper nullable ` (Inh (tmod_contained_class_set_field classtype name containedtype mul))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n then have value_def: \"FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f) = setof (map obj (values (ob)))\"\n unfolding imod_contained_class_set_field_def\n using f_def\n by fastforce\n have value_valid: \"FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f) \n :[imod_contained_class_set_field classtype name containedtype mul objects obids values] TypeDef.setof \\containedtype\"\n unfolding Valid_def\n proof (rule Valid_rel.valid_rule_sets)\n show \"TypeDef.setof \\containedtype \\ SetContainerType (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n proof (intro SetContainerType.rule_setof_all_type)\n show \"\\containedtype \\ Type (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding Type_def NonContainerType_def ClassType_def\n by (simp add: ProperClassType.rule_proper_classes imod_contained_class_set_field_def tmod_contained_class_set_field_def)\n qed\n next\n have \"setof (map obj (values ob)) \\ SetContainerValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof (induct \"values ob = []\")\n case True\n show ?case\n proof (rule SetContainerValue.rule_setof_container_values)\n show \"map obj (values ob) \\ ContainerValueList (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using ContainerValueList.rule_empty_list True.hyps\n by simp\n qed\n next\n case False\n show ?case\n proof (rule SetContainerValue.rule_setof_atom_values)\n have \"set (map obj (values ob)) \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof\n fix x :: \"('b, 'a) ValueDef\"\n assume assump: \"x \\ set (map obj (values ob))\"\n have \"set (values ob) \\ sets_to_set (set ` values ` objects)\"\n proof\n fix x\n assume \"x \\ set (values ob)\"\n then show \"x \\ sets_to_set (set ` values ` objects)\"\n using ob_def imageI sets_to_set.rule_member\n by metis\n qed\n then have \"x \\ obj ` sets_to_set (set ` values ` objects)\"\n using assump\n by fastforce\n then show \"x \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof\n fix y\n assume x_def: \"x = obj y\"\n assume y_def: \"y \\ sets_to_set (set ` values ` objects)\"\n then have \"obj y \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof (intro ProperClassValue.rule_proper_objects)\n assume \"y \\ sets_to_set (set ` values ` objects)\"\n then show \"y \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n unfolding imod_contained_class_set_field_def\n by simp\n qed\n then show \"x \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using x_def\n by blast\n qed\n qed\n then have \"set (map obj (values ob)) \\ AtomValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using proper_class_values_are_atom_values\n by blast\n then show \"map obj (values ob) \\ AtomValueList (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using False.hyps list.map_disc_iff list_of_atom_values_in_atom_value_list_alt\n by metis\n qed\n qed\n then show \"FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f) \\ \n SetContainerValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using distinct_map\n by (simp add: value_def)\n next\n have \"inj_on obj (set (values ob))\"\n unfolding inj_on_def\n by blast\n then have distinct_map_def: \"distinct (map obj (values ob))\"\n using unique_sets ob_def\n by (simp add: distinct_map)\n have \"\\x1 x2. x1 \\ set (map obj (values ob)) \\ x2 \\ set (map obj (values ob)) \\ \n x1 \\[imod_contained_class_set_field classtype name containedtype mul objects obids values] x2 \\ x1 = x2\"\n proof-\n fix x1 x2\n have set_in_sets: \"set (values ob) \\ sets_to_set (set ` values ` objects)\"\n proof\n fix x\n assume \"x \\ set (values ob)\"\n then show \"x \\ sets_to_set (set ` values ` objects)\"\n using ob_def imageI sets_to_set.rule_member\n by metis\n qed\n assume equiv: \"x1 \\[imod_contained_class_set_field classtype name containedtype mul objects obids values] x2\"\n assume \"x1 \\ set (map obj (values ob))\"\n then have \"x1 \\ obj ` sets_to_set (set ` values ` objects)\"\n using set_in_sets\n by fastforce\n then have x1_def: \"x1 \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof\n fix y\n assume x_def: \"x1 = obj y\"\n assume y_def: \"y \\ sets_to_set (set ` values ` objects)\"\n then have \"obj y \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof (intro ProperClassValue.rule_proper_objects)\n assume \"y \\ sets_to_set (set ` values ` objects)\"\n then show \"y \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n unfolding imod_contained_class_set_field_def\n by simp\n qed\n then show \"x1 \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using x_def\n by blast\n qed\n assume \"x2 \\ set (map obj (values ob))\"\n then have \"x2 \\ obj ` sets_to_set (set ` values ` objects)\"\n using set_in_sets\n by fastforce\n then have x2_def: \"x2 \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof\n fix y\n assume x_def: \"x2 = obj y\"\n assume y_def: \"y \\ sets_to_set (set ` values ` objects)\"\n then have \"obj y \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof (intro ProperClassValue.rule_proper_objects)\n assume \"y \\ sets_to_set (set ` values ` objects)\"\n then show \"y \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n unfolding imod_contained_class_set_field_def\n by simp\n qed\n then show \"x2 \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using x_def\n by blast\n qed\n show \"x1 = x2\"\n using equiv x1_def x2_def\n proof (induct)\n case (rule_atom_equiv v1 v2)\n then show ?case\n unfolding Value_def AtomValue_def ClassValue_def\n by blast\n qed (simp_all)\n qed\n then have \"distinct_values (imod_contained_class_set_field classtype name containedtype mul objects obids values) (map obj (values ob))\"\n using distinct_values_impl_distinct_rev distinct_map_def\n by blast\n then show \"distinct_values (imod_contained_class_set_field classtype name containedtype mul objects obids values) \n (contained_list (FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f)))\"\n by (simp add: value_def)\n next\n have set_in_sets: \"set (values ob) \\ sets_to_set (set ` values ` objects)\"\n proof\n fix x\n assume \"x \\ set (values ob)\"\n then show \"x \\ sets_to_set (set ` values ` objects)\"\n using ob_def imageI sets_to_set.rule_member\n by metis\n qed\n fix x\n assume \"x \\ set (contained_list (FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f)))\"\n then have \"x \\ set (map obj (values ob))\"\n by (simp add: value_def)\n then have x_def: \"x \\ obj ` sets_to_set (set ` values ` objects)\"\n using set_in_sets\n by fastforce\n then have x_class_value: \"x \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof\n fix y\n assume x_def: \"x = obj y\"\n assume y_def: \"y \\ sets_to_set (set ` values ` objects)\"\n then have \"obj y \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof (intro ProperClassValue.rule_proper_objects)\n assume \"y \\ sets_to_set (set ` values ` objects)\"\n then show \"y \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n unfolding imod_contained_class_set_field_def\n by simp\n qed\n then show \"x \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using x_def\n by blast\n qed\n have \"(\\containedtype, x) \\ Valid_rel (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using x_def\n proof (elim imageE)\n fix y\n assume x_def: \"x = obj y\"\n assume \"y \\ sets_to_set (set ` values ` objects)\"\n then have \"(\\containedtype, obj y) \\ Valid_rel (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof (intro Valid_rel.valid_rule_proper_classes)\n assume \"y \\ sets_to_set (set ` values ` objects)\"\n then show \"y \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n by (simp add: imod_contained_class_set_field_def)\n next\n show \"\\containedtype \\ ClassType (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def ClassType_def\n by (simp add: ProperClassType.rule_proper_classes)\n then have containedtype_def: \"\\containedtype \\ Type (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding Type_def NonContainerType_def\n by blast\n assume \"y \\ sets_to_set (set ` values ` objects)\"\n then have \"ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) y = containedtype\"\n unfolding imod_contained_class_set_field_def\n using objects_unique\n by fastforce\n then show \"\\(ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) y) \n \\[Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)]\n \\containedtype\"\n using containedtype_def\n by (simp add: subtype_def subtype_rel.reflexivity)\n qed\n then show \"(\\containedtype, x) \\ Valid_rel (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using x_def\n by simp\n qed\n then show \"(contained_type (TypeDef.setof \\containedtype), x) \\ Valid_rel (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n by simp\n qed\n then show \"FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f) \n :[imod_contained_class_set_field classtype name containedtype mul objects obids values] \n Type_Model.type (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) f\"\n using value_def f_type\n by simp\n have values_are_class_values: \"FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f) \\ \n SetContainerValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using value_valid\n unfolding Valid_def\n by (cases) (simp_all add: value_def)\n then show \"FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f) \\\n Value (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n unfolding Value_def\n using set_container_values_are_container_values\n by blast\n have \"validMul (imod_contained_class_set_field classtype name containedtype mul objects obids values) ((ob, f), \n FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f))\"\n unfolding validMul_def\n proof (intro conjI)\n show \"snd ((ob, f), FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f)) \\ \n ContainerValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) \\\n lower (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (snd (fst ((ob, f), FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f)))) \\ \n \\<^bold>(length (contained_list (snd ((ob, f), FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f))))) \\\n \\<^bold>(length (contained_list (snd ((ob, f), FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f))))) \\ \n upper (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (snd (fst ((ob, f), FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f))))\"\n proof\n assume \"snd ((ob, f), FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f)) \\ \n ContainerValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n then have \"Multiplicity.lower mul \\ \\<^bold>(length (map obj (values ob))) \\\n \\<^bold>(length (map obj (values ob))) \\ Multiplicity.upper mul\"\n using valid_sets ob_def\n unfolding within_multiplicity_def\n by simp\n then show \"lower (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (snd (fst ((ob, f), FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f)))) \\ \n \\<^bold>(length (contained_list (snd ((ob, f), FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f))))) \\\n \\<^bold>(length (contained_list (snd ((ob, f), FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f))))) \\ \n upper (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (snd (fst ((ob, f), FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f))))\"\n using f_lower f_upper value_def\n by simp\n qed\n qed (simp_all add: value_valid f_type)\n then show \"validMul (imod_contained_class_set_field classtype name containedtype mul objects obids values) ((ob, f), FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ob, f))\"\n by (simp add: value_def)\nnext\n have type_model_correct: \"type_model (tmod_contained_class_set_field classtype name containedtype mul)\"\n using tmod_contained_class_set_field_correct valid_ns valid_mul\n by metis\n have no_attr_type: \"TypeDef.setof \\containedtype \\ AttrType (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n proof\n assume \"TypeDef.setof \\containedtype \\ AttrType (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n then show \"False\"\n by (cases) (simp_all)\n qed\n have no_attr: \"(classtype, name) \\ Attr (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n proof\n have containedtype_def: \"Type_Model.type (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (classtype, name) = TypeDef.setof \\containedtype\"\n unfolding Type_Model.type_def imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by simp\n assume \"(classtype, name) \\ Attr (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n then show \"False\"\n unfolding Attr_def\n using containedtype_def no_attr_type\n by simp\n qed\n have rel_def: \"Rel (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) = {(classtype, name)}\"\n proof\n show \"Rel (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) \\ {(classtype, name)}\"\n proof\n fix x\n assume \"x \\ Rel (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n then show \"x \\ {(classtype, name)}\"\n unfolding Rel_def imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by simp\n qed\n next\n show \"{(classtype, name)} \\ Rel (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n proof\n fix x\n assume \"x \\ {(classtype, name)}\"\n then have \"x = (classtype, name)\"\n by simp\n then show \"x \\ Rel (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n using no_attr\n unfolding Rel_def imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by simp\n qed\n qed\n have cr_def: \"CR (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) = {(classtype, name)}\"\n proof\n show \"CR (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) \\ {(classtype, name)}\"\n proof\n fix x\n assume \"x \\ CR (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n then show \"x \\ {(classtype, name)}\"\n proof (induct)\n case (rule_containment_relations r)\n then show ?case\n using rel_def\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by blast\n qed\n qed\n next\n show \"{(classtype, name)} \\ CR (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n proof\n fix x\n assume \"x \\ {(classtype, name)}\"\n then have x_def: \"x = (classtype, name)\"\n by simp\n show \"x \\ CR (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n proof (rule CR.rule_containment_relations)\n show \"x \\ Rel (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n using x_def rel_def\n by simp\n next\n show \"containment x \\ Prop (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n using x_def\n by simp\n qed\n qed\n qed\n fix p\n assume \"p \\ Prop (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n then have p_def: \"p = containment (classtype, name)\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by simp\n have \"imod_contained_class_set_field classtype name containedtype mul objects obids values \\ containment (classtype, name)\"\n proof (rule property_satisfaction.rule_property_containment)\n fix ob\n assume \"ob \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n then have ob_cases: \"ob \\ objects \\ sets_to_set (set ` values ` objects)\"\n unfolding imod_contained_class_set_field_def\n by simp\n then show \"card (object_containments (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob) \\ 1\"\n proof (elim UnE)\n assume ob_def: \"ob \\ objects\"\n have \"object_containments (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob = {}\"\n proof\n show \"object_containments (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob \\ {}\"\n proof\n fix x\n assume \"x \\ object_containments (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob\"\n then show \"x \\ {}\"\n proof (induct x)\n case (Pair a d)\n then show ?case\n proof (induct a)\n case (fields a b c)\n then show ?case\n proof (induct)\n case (rule_object_containment o1 r)\n then have r_def: \"r = (classtype, name)\"\n using cr_def\n by simp\n then have o1_cases: \"o1 \\ objects \\ sets_to_set (set ` values ` objects)\"\n using rule_object_containment.hyps(1)\n unfolding imod_contained_class_set_field_def\n by simp\n then show ?case\n proof (elim UnE)\n assume o1_def: \"o1 \\ objects\"\n then have o1_class_def: \"ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1 = classtype\"\n unfolding imod_contained_class_set_field_def\n by simp\n have value_def: \"FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (o1, r) = setof (map obj (values o1))\"\n unfolding imod_contained_class_set_field_def\n using o1_def r_def\n by simp\n have set_in_sets: \"set (values o1) \\ sets_to_set (set ` values ` objects)\"\n proof\n fix x\n assume \"x \\ set (values o1)\"\n then show \"x \\ sets_to_set (set ` values ` objects)\"\n using o1_def imageI sets_to_set.rule_member\n by metis\n qed\n have \"set (map obj (values o1)) \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof\n fix x :: \"('b, 'a) ValueDef\"\n assume \"x \\ set (map obj (values o1))\"\n then have \"x \\ obj ` sets_to_set (set ` values ` objects)\"\n using set_in_sets\n by fastforce\n then show \"x \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof\n fix y\n assume x_def: \"x = obj y\"\n assume y_def: \"y \\ sets_to_set (set ` values ` objects)\"\n then have \"obj y \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof (intro ProperClassValue.rule_proper_objects)\n assume \"y \\ sets_to_set (set ` values ` objects)\"\n then show \"y \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n unfolding imod_contained_class_set_field_def\n by simp\n qed\n then show \"x \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using x_def\n by blast\n qed\n qed\n then have \"set (map obj (values o1)) \\ AtomValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using proper_class_values_are_atom_values\n by blast\n then have \"map obj (values o1) = [] \\ map obj (values o1) \\ AtomValueList (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using list.map_disc_iff list_of_atom_values_in_atom_value_list_alt\n by metis\n then have contained_values_def: \"contained_values (FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (o1, r)) = map obj (values o1)\"\n using value_def atom_value_list_contained_values_setof_identity\n by fastforce\n have \"obj ob \\ set (map obj (values o1))\"\n proof\n have ob_not_in_sets: \"ob \\ sets_to_set (set ` values ` objects)\"\n using ob_def objects_unique\n by blast\n assume \"obj ob \\ set (map obj (values o1))\"\n then have \"ob \\ set (values o1)\"\n by fastforce\n then have \"ob \\ sets_to_set (set ` values ` objects)\"\n using set_in_sets\n by blast\n then show \"False\"\n using ob_not_in_sets\n by simp\n qed\n then show ?thesis\n using contained_values_def rule_object_containment.hyps(4)\n by metis\n next\n assume o1_def: \"o1 \\ sets_to_set (set ` values ` objects)\"\n then have o1_class_def: \"ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1 = containedtype\"\n unfolding imod_contained_class_set_field_def\n using objects_unique\n by fastforce\n have \"\\\\containedtype \\[Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)] \\classtype\"\n proof\n assume \"\\containedtype \\[Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)] \\classtype\"\n then have \"\\containedtype \\[tmod_contained_class_set_field classtype name containedtype mul] \\classtype\"\n unfolding imod_contained_class_set_field_def class_def\n by simp\n then have \"(\\containedtype, \\classtype) \\ subtype_rel_altdef (tmod_contained_class_set_field classtype name containedtype mul)\"\n using subtype_def subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_correct\n by blast\n then show \"False\"\n unfolding subtype_rel_altdef_def\n proof (elim UnE)\n assume \"(\\containedtype, \\classtype) \\ subtype_tuple ` Type (tmod_contained_class_set_field classtype name containedtype mul)\"\n then have \"classtype = containedtype\"\n by (simp add: image_iff subtype_tuple_def)\n then show ?thesis\n using classtype_containedtype_neq\n by blast\n next\n assume \"(\\containedtype, \\classtype) \\ subtype_conv nullable nullable ` (Inh (tmod_contained_class_set_field classtype name containedtype mul))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\containedtype, \\classtype) \\ subtype_conv proper proper ` (Inh (tmod_contained_class_set_field classtype name containedtype mul))\\<^sup>+\"\n then show ?thesis\n unfolding tmod_contained_class_set_field_def\n by auto\n next\n assume \"(\\containedtype, \\classtype) \\ subtype_conv proper nullable ` subtype_tuple ` Class (tmod_contained_class_set_field classtype name containedtype mul)\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\containedtype, \\classtype) \\ subtype_conv proper nullable ` (Inh (tmod_contained_class_set_field classtype name containedtype mul))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n qed\n then have \"r \\ Type_Model.fields (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) containedtype\"\n unfolding Type_Model.fields_def\n using r_def\n by simp\n then show ?thesis\n using o1_class_def rule_object_containment.hyps(3)\n by simp\n qed\n qed\n qed\n qed\n qed\n next\n show \"{} \\ object_containments (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob\"\n by simp\n qed\n then show ?thesis\n using card_empty\n by simp\n next\n assume ob_def: \"ob \\ sets_to_set (set ` values ` objects)\"\n then show ?thesis\n proof\n fix x y\n assume x_def: \"x \\ set ` values ` objects\"\n assume y_def: \"y \\ x\"\n assume \"ob = y\"\n then have \"ob \\ x\"\n using y_def\n by simp\n then show ?thesis\n using x_def\n proof (elim imageE)\n fix i j\n assume j_def: \"j \\ objects\"\n assume i_def: \"i = values j\"\n assume \"x = set i\"\n then have x_def: \"x = set (values j)\"\n by (simp add: i_def)\n assume \"ob \\ x\"\n then have ob_def: \"ob \\ set (values j)\"\n by (simp add: x_def)\n have \"object_containments (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob \\ {((j, (classtype, name)), ob)}\"\n proof\n fix x\n assume \"x \\ object_containments (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob\"\n then show \"x \\ {((j, (classtype, name)), ob)}\"\n proof (induct x)\n case (Pair a d)\n then show ?case\n proof (induct a)\n case (fields a b c)\n then show ?case\n proof (induct)\n case (rule_object_containment o1 r)\n then have r_def: \"r = (classtype, name)\"\n using cr_def\n by simp\n then have o1_cases: \"o1 \\ objects \\ sets_to_set (set ` values ` objects)\"\n using rule_object_containment.hyps(1)\n unfolding imod_contained_class_set_field_def\n by simp\n then show ?case\n proof (elim UnE)\n assume o1_def: \"o1 \\ objects\"\n then have o1_class_def: \"ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1 = classtype\"\n unfolding imod_contained_class_set_field_def\n by simp\n have value_def: \"FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (o1, r) = setof (map obj (values o1))\"\n unfolding imod_contained_class_set_field_def\n using o1_def r_def\n by simp\n have set_in_sets: \"set (values o1) \\ sets_to_set (set ` values ` objects)\"\n proof\n fix x\n assume \"x \\ set (values o1)\"\n then show \"x \\ sets_to_set (set ` values ` objects)\"\n using o1_def imageI sets_to_set.rule_member\n by metis\n qed\n have \"set (map obj (values o1)) \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof\n fix x :: \"('b, 'a) ValueDef\"\n assume \"x \\ set (map obj (values o1))\"\n then have \"x \\ obj ` sets_to_set (set ` values ` objects)\"\n using set_in_sets\n by fastforce\n then show \"x \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof\n fix y\n assume x_def: \"x = obj y\"\n assume y_def: \"y \\ sets_to_set (set ` values ` objects)\"\n then have \"obj y \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof (intro ProperClassValue.rule_proper_objects)\n assume \"y \\ sets_to_set (set ` values ` objects)\"\n then show \"y \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n unfolding imod_contained_class_set_field_def\n by simp\n qed\n then show \"x \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using x_def\n by blast\n qed\n qed\n then have \"set (map obj (values o1)) \\ AtomValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using proper_class_values_are_atom_values\n by blast\n then have \"map obj (values o1) = [] \\ map obj (values o1) \\ AtomValueList (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using list.map_disc_iff list_of_atom_values_in_atom_value_list_alt\n by metis\n then have contained_values_def: \"contained_values (FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (o1, r)) = map obj (values o1)\"\n using value_def atom_value_list_contained_values_setof_identity\n by fastforce\n then have \"obj ob \\ set (map obj (values o1))\"\n using rule_object_containment.hyps(4)\n by fastforce\n then have ob_in_set_def: \"ob \\ set (values o1)\"\n using rule_object_containment.hyps(4)\n by fastforce\n show ?thesis\n proof (induct \"o1 = j\")\n case True\n then show ?case\n using r_def\n by blast\n next\n case False\n then show ?case\n using j_def o1_def ob_in_set_def ob_def unique_across_sets\n by blast\n qed\n next\n assume o1_def: \"o1 \\ sets_to_set (set ` values ` objects)\"\n then have o1_class_def: \"ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1 = containedtype\"\n unfolding imod_contained_class_set_field_def\n using objects_unique\n by fastforce\n have \"\\\\containedtype \\[Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)] \\classtype\"\n proof\n assume \"\\containedtype \\[Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)] \\classtype\"\n then have \"\\containedtype \\[tmod_contained_class_set_field classtype name containedtype mul] \\classtype\"\n unfolding imod_contained_class_set_field_def class_def\n by simp\n then have \"(\\containedtype, \\classtype) \\ subtype_rel_altdef (tmod_contained_class_set_field classtype name containedtype mul)\"\n using subtype_def subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_correct\n by blast\n then show \"False\"\n unfolding subtype_rel_altdef_def\n proof (elim UnE)\n assume \"(\\containedtype, \\classtype) \\ subtype_tuple ` Type (tmod_contained_class_set_field classtype name containedtype mul)\"\n then have \"classtype = containedtype\"\n by (simp add: image_iff subtype_tuple_def)\n then show ?thesis\n using classtype_containedtype_neq\n by blast\n next\n assume \"(\\containedtype, \\classtype) \\ subtype_conv nullable nullable ` (Inh (tmod_contained_class_set_field classtype name containedtype mul))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\containedtype, \\classtype) \\ subtype_conv proper proper ` (Inh (tmod_contained_class_set_field classtype name containedtype mul))\\<^sup>+\"\n then show ?thesis\n unfolding tmod_contained_class_set_field_def\n by auto\n next\n assume \"(\\containedtype, \\classtype) \\ subtype_conv proper nullable ` subtype_tuple ` Class (tmod_contained_class_set_field classtype name containedtype mul)\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\containedtype, \\classtype) \\ subtype_conv proper nullable ` (Inh (tmod_contained_class_set_field classtype name containedtype mul))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n qed\n then have \"r \\ Type_Model.fields (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) containedtype\"\n unfolding Type_Model.fields_def\n using r_def\n by simp\n then show ?thesis\n using o1_class_def rule_object_containment.hyps(3)\n by simp\n qed\n qed\n qed\n qed\n qed\n then have \"object_containments (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob = {((j, classtype, name), ob)} \\\n object_containments (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob = {}\"\n by blast\n then show ?thesis\n using card_empty\n by fastforce\n qed\n qed\n qed\n next\n have containment_relation_def: \"\\x y. (x, y) \\ object_containments_relation (imod_contained_class_set_field classtype name containedtype mul objects obids values) \\ \n x \\ objects \\ y \\ sets_to_set (set ` values ` objects)\"\n proof-\n fix x y\n assume \"(x, y) \\ object_containments_relation (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n then show \"x \\ objects \\ y \\ sets_to_set (set ` values ` objects)\"\n proof (induct)\n case (rule_object_containment o1 o2 r)\n then have r_def: \"r = (classtype, name)\"\n using cr_def\n by simp\n then have o1_cases: \"o1 \\ objects \\ sets_to_set (set ` values ` objects)\"\n using rule_object_containment.hyps(1)\n unfolding imod_contained_class_set_field_def\n by simp\n then show ?case\n proof (elim UnE)\n assume o1_def: \"o1 \\ objects\"\n then have o1_class_def: \"ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1 = classtype\"\n unfolding imod_contained_class_set_field_def\n by simp\n have value_def: \"FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (o1, r) = setof (map obj (values o1))\"\n unfolding imod_contained_class_set_field_def\n using o1_def r_def\n by simp\n have set_in_sets: \"set (values o1) \\ sets_to_set (set ` values ` objects)\"\n proof\n fix x\n assume \"x \\ set (values o1)\"\n then show \"x \\ sets_to_set (set ` values ` objects)\"\n using o1_def imageI sets_to_set.rule_member\n by metis\n qed\n have \"set (map obj (values o1)) \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof\n fix x :: \"('b, 'a) ValueDef\"\n assume \"x \\ set (map obj (values o1))\"\n then have \"x \\ obj ` sets_to_set (set ` values ` objects)\"\n using set_in_sets\n by fastforce\n then show \"x \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof\n fix y\n assume x_def: \"x = obj y\"\n assume y_def: \"y \\ sets_to_set (set ` values ` objects)\"\n then have \"obj y \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof (intro ProperClassValue.rule_proper_objects)\n assume \"y \\ sets_to_set (set ` values ` objects)\"\n then show \"y \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n unfolding imod_contained_class_set_field_def\n by simp\n qed\n then show \"x \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using x_def\n by blast\n qed\n qed\n then have \"set (map obj (values o1)) \\ AtomValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using proper_class_values_are_atom_values\n by blast\n then have \"map obj (values o1) = [] \\ map obj (values o1) \\ AtomValueList (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using list.map_disc_iff list_of_atom_values_in_atom_value_list_alt\n by metis\n then have contained_values_def: \"contained_values (FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (o1, r)) = map obj (values o1)\"\n using value_def atom_value_list_contained_values_setof_identity\n by fastforce\n then have \"obj o2 \\ set (map obj (values o1))\"\n using rule_object_containment.hyps(4)\n by fastforce\n then have ob_in_set_def: \"o2 \\ set (values o1)\"\n using rule_object_containment.hyps(4)\n by fastforce\n then have \"o2 \\ sets_to_set (set ` values ` objects)\"\n using set_in_sets\n by blast\n then show ?thesis\n using o1_def\n by blast\n next\n assume o1_def: \"o1 \\ sets_to_set (set ` values ` objects)\"\n then have o1_class_def: \"ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1 = containedtype\"\n unfolding imod_contained_class_set_field_def\n using objects_unique\n by fastforce\n have \"\\\\containedtype \\[Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)] \\classtype\"\n proof\n assume \"\\containedtype \\[Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)] \\classtype\"\n then have \"\\containedtype \\[tmod_contained_class_set_field classtype name containedtype mul] \\classtype\"\n unfolding imod_contained_class_set_field_def class_def\n by simp\n then have \"(\\containedtype, \\classtype) \\ subtype_rel_altdef (tmod_contained_class_set_field classtype name containedtype mul)\"\n using subtype_def subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_correct\n by blast\n then show \"False\"\n unfolding subtype_rel_altdef_def\n proof (elim UnE)\n assume \"(\\containedtype, \\classtype) \\ subtype_tuple ` Type (tmod_contained_class_set_field classtype name containedtype mul)\"\n then have \"classtype = containedtype\"\n by (simp add: image_iff subtype_tuple_def)\n then show ?thesis\n using classtype_containedtype_neq\n by blast\n next\n assume \"(\\containedtype, \\classtype) \\ subtype_conv nullable nullable ` (Inh (tmod_contained_class_set_field classtype name containedtype mul))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\containedtype, \\classtype) \\ subtype_conv proper proper ` (Inh (tmod_contained_class_set_field classtype name containedtype mul))\\<^sup>+\"\n then show ?thesis\n unfolding tmod_contained_class_set_field_def\n by auto\n next\n assume \"(\\containedtype, \\classtype) \\ subtype_conv proper nullable ` subtype_tuple ` Class (tmod_contained_class_set_field classtype name containedtype mul)\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\containedtype, \\classtype) \\ subtype_conv proper nullable ` (Inh (tmod_contained_class_set_field classtype name containedtype mul))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n qed\n then have \"r \\ Type_Model.fields (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) containedtype\"\n unfolding Type_Model.fields_def\n using r_def\n by simp\n then show ?thesis\n using o1_class_def rule_object_containment.hyps(3)\n by simp\n qed\n qed\n qed\n have \"\\x. (x, x) \\ (object_containments_relation (imod_contained_class_set_field classtype name containedtype mul objects obids values))\\<^sup>+\"\n proof\n fix x\n assume \"(x, x) \\ (object_containments_relation (imod_contained_class_set_field classtype name containedtype mul objects obids values))\\<^sup>+\"\n then show \"False\"\n proof (cases)\n case base\n then show ?thesis\n using containment_relation_def objects_unique\n by blast\n next\n case (step c)\n then show ?thesis\n using disjoint_iff_not_equal tranclE containment_relation_def objects_unique\n by metis\n qed\n qed\n then show \"irrefl ((object_containments_relation (imod_contained_class_set_field classtype name containedtype mul objects obids values))\\<^sup>+)\"\n unfolding irrefl_def\n by simp\n qed\n then show \"imod_contained_class_set_field classtype name containedtype mul objects obids values \\ p\"\n using p_def\n by simp\nqed (simp_all add: assms imod_contained_class_set_field_def tmod_contained_class_set_field_def)\n\nlemma imod_contained_class_set_field_combine_correct:\n assumes \"instance_model Imod\"\n assumes existing_classes: \"{classtype, containedtype} \\ Class (Tm Imod)\"\n assumes new_field: \"(classtype, name) \\ Field (Tm Imod)\"\n assumes valid_ns: \"\\id_in_ns containedtype (Identifier classtype) \\ \\id_in_ns classtype (Identifier containedtype)\"\n assumes valid_mul: \"multiplicity mul\"\n assumes no_inh_classtype: \"\\x. (x, classtype) \\ Inh (Tm Imod)\"\n assumes classtype_containedtype_neq: \"classtype \\ containedtype\"\n assumes no_fields_containedtype: \"Type_Model.fields (Tm Imod) containedtype = {}\"\n assumes objects_unique: \"objects \\ sets_to_set (set ` values ` objects) = {}\"\n assumes invalid_ids: \"\\o1 o2. o1 \\ Object Imod \\ \n o2 \\ sets_to_set (set ` values ` objects) \\ ObjectId Imod o1 \\ obids o2\"\n assumes unique_ids: \"\\o1 o2. o1 \\ sets_to_set (set ` values ` objects) \\ \n o2 \\ sets_to_set (set ` values ` objects) \\ obids o1 = obids o2 \\ o1 = o2\"\n assumes unique_sets: \"\\ob. ob \\ objects \\ distinct (values ob)\"\n assumes unique_across_sets: \"\\o1 o2. o1 \\ objects \\ o2 \\ objects \\ o1 \\ o2 \\ set (values o1) \\ set (values o2) = {}\"\n assumes valid_sets: \"\\ob. ob \\ objects \\ length (values ob) in mul\"\n assumes existing_objects: \"(objects \\ sets_to_set (set ` values ` objects)) \\ Object Imod = objects\"\n assumes all_objects: \"\\ob. ob \\ Object Imod \\ ObjectClass Imod ob = classtype \\ ob \\ objects\"\n assumes classes_valid: \"\\ob. ob \\ objects \\ \n ObjectClass Imod ob = ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob\"\n assumes ids_valid: \"\\ob. ob \\ objects \\ ObjectId Imod ob = obids ob\"\n shows \"instance_model (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\nproof (intro imod_combine_merge_correct)\n fix ob\n assume ob_in_imod: \"ob \\ Object Imod\"\n assume \"ob \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n then have \"ob \\ objects \\ sets_to_set (set ` values ` objects)\"\n unfolding imod_contained_class_set_field_def\n by simp\n then have ob_in_objects: \"ob \\ objects\"\n using existing_objects ob_in_imod\n by blast\n then show \"ObjectClass Imod ob = ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob\"\n using classes_valid ob_in_objects\n by simp\nnext\n fix ob\n assume ob_in_imod: \"ob \\ Object Imod\"\n assume \"ob \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n then have \"ob \\ objects \\ sets_to_set (set ` values ` objects)\"\n unfolding imod_contained_class_set_field_def\n by simp\n then have ob_in_objects: \"ob \\ objects\"\n using existing_objects ob_in_imod\n by blast\n then have \"ObjectId (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob = obids ob\"\n unfolding imod_contained_class_set_field_def\n by simp\n then show \"ObjectId Imod ob = ObjectId (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob\"\n using ids_valid ob_in_objects\n by simp\nnext\n fix o1 o2\n assume \"o1 \\ Object Imod - Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n then have \"o1 \\ Object Imod - (objects \\ sets_to_set (set ` values ` objects))\"\n unfolding imod_contained_class_set_field_def\n by simp\n then have o1_def: \"o1 \\ Object Imod - objects\"\n using existing_objects\n by blast\n assume \"o2 \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values) - Object Imod\"\n then have \"o2 \\ objects \\ sets_to_set (set ` values ` objects) - Object Imod\"\n unfolding imod_contained_class_set_field_def\n by simp\n then have \"o2 \\ sets_to_set (set ` values ` objects)\"\n using existing_objects\n by blast\n then have not_eq: \"ObjectId Imod o1 \\ ObjectId (imod_contained_class_set_field classtype name containedtype mul objects obids values) o2\"\n unfolding imod_contained_class_set_field_def\n using invalid_ids o1_def\n by simp\n assume \"ObjectId Imod o1 = ObjectId (imod_contained_class_set_field classtype name containedtype mul objects obids values) o2\"\n then show \"o1 = o2\"\n using not_eq\n by simp\nnext\n have type_model_valid: \"type_model (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n using assms(1) instance_model.validity_type_model_consistent existing_classes new_field valid_ns valid_mul\n by (intro tmod_contained_class_set_field_combine_correct) (simp_all)\n fix ob f\n assume ob_def: \"ob \\ Object Imod\"\n then have \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob = \n imod_combine_object_class Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob\"\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n then have ob_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob = ObjectClass Imod ob\"\n unfolding imod_combine_object_class_def\n using existing_objects classes_valid\n by (simp add: imod_contained_class_set_field_def inf.commute ob_def)\n assume \"f \\ Field (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n then have f_def: \"f = (classtype, name)\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by simp\n assume \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob)\n \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))]\n \\(class (Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))) f)\"\n then have \"\\(ObjectClass Imod ob) \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))] \\classtype\"\n unfolding class_def\n using ob_class_def f_def\n by simp\n then have \"(\\(ObjectClass Imod ob), \\classtype) \\ subtype_rel_altdef (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n unfolding subtype_def imod_contained_class_set_field_def imod_combine_def\n by (simp add: subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_valid)\n then have ob_class_is_classtype: \"\\(ObjectClass Imod ob) = \\classtype\"\n unfolding subtype_rel_altdef_def\n proof (elim UnE)\n assume \"(\\(ObjectClass Imod ob), \\classtype) \\ subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_tuple_def\n by blast\n next\n assume \"(\\(ObjectClass Imod ob), \\classtype) \\ subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass Imod ob), \\classtype) \\ subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then have ob_extends_classtype: \"(ObjectClass Imod ob, classtype) \\ (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n unfolding subtype_conv_def\n by fastforce\n have \"(ObjectClass Imod ob, classtype) \\ (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n proof\n assume \"(ObjectClass Imod ob, classtype) \\ (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show \"False\"\n proof (cases)\n case base\n then show ?thesis\n unfolding tmod_contained_class_set_field_def tmod_combine_def\n using no_inh_classtype\n by simp\n next\n case (step c)\n then show ?thesis\n unfolding tmod_contained_class_set_field_def tmod_combine_def\n using no_inh_classtype\n by simp\n qed\n qed\n then show ?thesis\n using ob_extends_classtype\n by blast\n next\n assume \"(\\(ObjectClass Imod ob), \\classtype) \\ subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass Imod ob), \\classtype) \\ subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n then have ob_in_objects: \"ob \\ objects\"\n using all_objects ob_def\n by blast\n have \"\\classtype \\ ProperClassType (tmod_contained_class_set_field classtype name containedtype mul)\"\n unfolding tmod_contained_class_set_field_def\n by (simp add: ProperClassType.rule_proper_classes)\n then have \"\\classtype \\ Type (tmod_contained_class_set_field classtype name containedtype mul)\"\n unfolding Type_def NonContainerType_def ClassType_def\n by blast\n then show \"ob \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values) \\\n \\(ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob) \n \\[Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)]\n \\(class (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) f)\"\n unfolding imod_contained_class_set_field_def class_def subtype_def\n using ob_in_objects f_def\n by (simp add: subtype_rel.reflexivity)\nnext\n have type_model_valid: \"type_model (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n using assms(1) instance_model.validity_type_model_consistent existing_classes new_field valid_ns valid_mul\n by (intro tmod_contained_class_set_field_combine_correct) (simp_all)\n fix ob f\n assume \"ob \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n then have ob_def: \"ob \\ objects \\ sets_to_set (set ` values ` objects)\"\n unfolding imod_contained_class_set_field_def\n by simp\n then have ob_cases: \"ob \\ Object Imod \\ sets_to_set (set ` values ` objects)\"\n using existing_objects\n by blast\n assume f_def: \"f \\ Field (Tm Imod)\"\n assume extend_def: \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob)\n \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))]\n \\(class (Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))) f)\"\n show \"ob \\ Object Imod \\ \\(ObjectClass Imod ob) \\[Tm Imod] \\(class (Tm Imod) f)\"\n using ob_cases\n proof (elim UnE)\n assume ob_in_imod: \"ob \\ Object Imod\"\n then have \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob = \n imod_combine_object_class Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob\"\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n then have ob_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob = ObjectClass Imod ob\"\n unfolding imod_combine_object_class_def\n using existing_objects classes_valid\n by (simp add: imod_contained_class_set_field_def inf.commute ob_in_imod)\n have \"ObjectClass Imod ob \\ Class (Tm Imod)\"\n by (simp add: assms(1) instance_model.structure_object_class_wellformed ob_in_imod)\n then have \"\\(ObjectClass Imod ob) \\ ProperClassType (Tm Imod)\"\n by (simp add: ProperClassType.rule_proper_classes)\n then have object_class_is_type: \"\\(ObjectClass Imod ob) \\ Type (Tm Imod)\"\n unfolding Type_def NonContainerType_def ClassType_def\n by blast\n have \"\\(ObjectClass Imod ob) \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))] \\(fst f)\"\n using extend_def ob_class_def\n unfolding class_def\n by simp\n then have \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_rel_altdef (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n unfolding subtype_def imod_contained_class_set_field_def imod_combine_def\n by (simp add: subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_valid)\n then have \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)) \\ \n subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+ \\\n subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+ \\\n subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)) \\\n subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n unfolding subtype_rel_altdef_def\n by simp\n then have \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_rel_altdef (Tm Imod)\"\n proof (elim UnE)\n assume \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then have \"ObjectClass Imod ob = fst f\"\n unfolding subtype_tuple_def\n by fastforce\n then have \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_tuple ` Type (Tm Imod)\"\n unfolding subtype_tuple_def\n using object_class_is_type\n by fastforce\n then show ?thesis\n unfolding subtype_rel_altdef_def\n by simp\n next\n assume \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then have \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_conv proper proper ` (Inh (Tm Imod))\\<^sup>+\"\n unfolding subtype_conv_def tmod_combine_def tmod_contained_class_set_field_def\n by simp\n then show ?thesis\n unfolding subtype_rel_altdef_def\n by simp\n next\n assume \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n then have \"\\(ObjectClass Imod ob) \\[Tm (Imod)] \\(fst f)\"\n unfolding subtype_def\n by (simp add: assms(1) instance_model.validity_type_model_consistent subtype_rel_alt type_model.structure_inh_wellformed_classes)\n then show ?thesis\n unfolding class_def\n using ob_in_imod\n by blast\n next\n assume ob_def: \"ob \\ sets_to_set (set ` values ` objects)\"\n then have \"ob \\ Object Imod\"\n using existing_objects objects_unique\n by auto\n then have ob_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob = containedtype\"\n unfolding imod_combine_def imod_contained_class_set_field_def imod_combine_object_class_def\n using ob_def existing_objects\n by auto\n have \"containedtype \\ Class (Tm Imod)\"\n using existing_classes\n by blast\n then have \"\\containedtype \\ ProperClassType (Tm Imod)\"\n by (simp add: ProperClassType.rule_proper_classes)\n then have object_class_is_type: \"\\containedtype \\ Type (Tm Imod)\"\n unfolding Type_def NonContainerType_def ClassType_def\n by blast\n have no_extend_imod: \"\\\\containedtype \\[Tm Imod] \\(fst f)\"\n proof\n assume \"\\containedtype \\[Tm Imod] \\(fst f)\"\n then have \"f \\ Type_Model.fields (Tm Imod) containedtype\"\n unfolding Type_Model.fields_def\n using f_def\n by fastforce\n then show \"False\"\n by (simp add: no_fields_containedtype)\n qed\n have \"\\\\containedtype \\[tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)] \\(fst f)\"\n proof\n assume \"\\containedtype \\[tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)] \\(fst f)\"\n then have \"(\\containedtype, \\(fst f)) \\ subtype_rel_altdef (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n unfolding subtype_def imod_contained_class_set_field_def imod_combine_def\n by (simp add: subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_valid)\n then show \"False\"\n unfolding subtype_rel_altdef_def\n proof (elim UnE)\n assume \"(\\containedtype, \\(fst f)) \\ subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then have \"\\containedtype = \\(fst f)\"\n by (simp add: image_iff subtype_tuple_def)\n then have \"\\containedtype \\[Tm Imod] \\(fst f)\"\n using object_class_is_type subtype_def subtype_rel.reflexivity\n by blast\n then show ?thesis\n using no_extend_imod\n by blast\n next\n assume \"(\\containedtype, \\(fst f)) \\ subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\containedtype, \\(fst f)) \\ subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then have \"(\\containedtype, \\(fst f)) \\ subtype_conv proper proper ` (Inh (Tm Imod))\\<^sup>+\"\n unfolding tmod_combine_def tmod_contained_class_set_field_def\n by simp\n then have \"(\\containedtype, \\(fst f)) \\ subtype_rel_altdef (Tm Imod)\"\n unfolding subtype_rel_altdef_def\n by blast\n then have \"\\containedtype \\[Tm Imod] \\(fst f)\"\n by (simp add: assms(1) instance_model.validity_type_model_consistent subtype_def subtype_rel_alt type_model.structure_inh_wellformed_classes)\n then show ?thesis\n using no_extend_imod\n by blast\n next\n assume \"(\\containedtype, \\(fst f)) \\ subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\containedtype, \\(fst f)) \\ subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n qed\n then have \"\\\\containedtype \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))] \\(fst f)\"\n unfolding imod_contained_class_set_field_def imod_combine_def\n by simp\n then show ?thesis\n using extend_def ob_class_def\n unfolding class_def\n by simp\n qed\nnext\n have type_model_valid: \"type_model (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n using assms(1) instance_model.validity_type_model_consistent existing_classes new_field valid_ns valid_mul\n by (intro tmod_contained_class_set_field_combine_correct) (simp_all)\n fix ob f\n assume ob_def: \"ob \\ Object Imod\"\n then have \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob = \n imod_combine_object_class Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob\"\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n then have ob_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob = ObjectClass Imod ob\"\n unfolding imod_combine_object_class_def\n using existing_objects classes_valid\n by (simp add: imod_contained_class_set_field_def inf.commute ob_def)\n then have \"ObjectClass Imod ob \\ Class (Tm Imod)\"\n by (simp add: assms(1) instance_model.structure_object_class_wellformed ob_def)\n then have \"\\(ObjectClass Imod ob) \\ ProperClassType (Tm Imod)\"\n by (fact ProperClassType.rule_proper_classes)\n then have ob_class_is_type: \"\\(ObjectClass Imod ob) \\ Type (Tm Imod)\"\n unfolding Type_def NonContainerType_def ClassType_def\n by blast\n assume f_def: \"f \\ Field (Tm Imod)\"\n assume \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob)\n \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))]\n \\(class (Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))) f)\"\n then have \"\\(ObjectClass Imod ob) \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))] \\(fst f)\"\n unfolding class_def\n using ob_class_def\n by simp\n then have \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_rel_altdef (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n unfolding subtype_def imod_contained_class_set_field_def imod_combine_def\n by (simp add: subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_valid)\n then have \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)) \\ \n subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+ \\\n subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+ \\\n subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)) \\\n subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n unfolding subtype_rel_altdef_def\n by simp\n then have \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_rel_altdef (Tm Imod)\"\n proof (elim UnE)\n assume \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then have \"ObjectClass Imod ob = fst f\"\n unfolding subtype_tuple_def\n by fastforce\n then have \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_tuple ` Type (Tm Imod)\"\n unfolding subtype_tuple_def\n using ob_class_is_type\n by simp\n then show ?thesis\n unfolding subtype_rel_altdef_def\n by simp\n next\n assume \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then have \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_conv proper proper ` (Inh (Tm Imod))\\<^sup>+\"\n unfolding subtype_conv_def tmod_combine_def tmod_contained_class_set_field_def\n by simp\n then show ?thesis\n unfolding subtype_rel_altdef_def\n by simp\n next\n assume \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass Imod ob), \\(fst f)) \\ subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n then show \"\\(ObjectClass Imod ob) \\[Tm (Imod)] \\(class (Tm Imod) f)\"\n unfolding subtype_def class_def\n by (simp add: assms(1) instance_model.validity_type_model_consistent subtype_rel_alt type_model.structure_inh_wellformed_classes)\nnext\n have type_model_valid: \"type_model (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n using assms(1) instance_model.validity_type_model_consistent existing_classes new_field valid_ns valid_mul\n by (intro tmod_contained_class_set_field_combine_correct) (simp_all)\n fix ob f\n assume \"ob \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n then have ob_def: \"ob \\ objects \\ sets_to_set (set ` values ` objects)\"\n unfolding imod_contained_class_set_field_def\n by simp\n assume \"f \\ Field (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n then have f_def: \"f = (classtype, name)\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by simp\n have \"\\classtype \\ ProperClassType (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by (simp add: ProperClassType.rule_proper_classes)\n then have \"\\classtype \\ Type (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding Type_def NonContainerType_def ClassType_def\n by blast\n then have classtype_extend: \"\\classtype \\[Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)] \\classtype\"\n unfolding subtype_def\n by (simp add: subtype_rel.reflexivity)\n assume \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob)\n \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))]\n \\(class (Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))) f)\"\n then have \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob)\n \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))] \\classtype\"\n unfolding class_def\n using f_def\n by simp\n then have \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob), \\classtype) \\ \n subtype_rel_altdef (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n unfolding subtype_def imod_contained_class_set_field_def imod_combine_def\n by (simp add: subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_valid)\n then have object_class_def: \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob) = \\classtype\"\n unfolding subtype_rel_altdef_def\n proof (elim UnE)\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob), \\classtype) \\ \n subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_tuple_def\n by fastforce\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob), \\classtype) \\ \n subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob), \\classtype) \\ \n subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then have ob_extends_classtype: \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n unfolding subtype_conv_def\n by fastforce\n have \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n proof\n assume \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show \"False\"\n proof (cases)\n case base\n then show ?thesis\n unfolding tmod_contained_class_set_field_def tmod_combine_def\n using no_inh_classtype\n by simp\n next\n case (step c)\n then show ?thesis\n unfolding tmod_contained_class_set_field_def tmod_combine_def\n using no_inh_classtype\n by simp\n qed\n qed\n then show ?thesis\n using ob_extends_classtype\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob), \\classtype) \\ \n subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob), \\classtype) \\ \n subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n show \"\\(ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob)\n \\[Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)]\n \\(class (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) f)\"\n using ob_def\n proof (elim UnE)\n assume ob_def: \"ob \\ objects\"\n then have \"\\(ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob) = \\classtype\"\n using existing_objects classes_valid\n unfolding imod_contained_class_set_field_def imod_combine_def imod_combine_object_class_def\n by fastforce\n then show ?thesis\n unfolding class_def\n using f_def classtype_extend\n by simp\n next\n assume ob_def: \"ob \\ sets_to_set (set ` values ` objects)\"\n then have \"ob \\ Object Imod\"\n using existing_objects objects_unique\n by auto\n then have ob_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob = containedtype\"\n unfolding imod_combine_def imod_contained_class_set_field_def imod_combine_object_class_def\n using ob_def existing_objects\n by auto\n then show ?thesis\n using classtype_containedtype_neq object_class_def\n by simp\n qed\nnext\n have \"type_model (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n using assms(1) instance_model.validity_type_model_consistent existing_classes new_field valid_ns valid_mul\n by (intro tmod_contained_class_set_field_combine_correct) (simp_all)\n then show \"type_model (tmod_combine (Tm Imod) (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)))\"\n unfolding imod_contained_class_set_field_def\n by simp\nnext\n show instance_model_correct: \"instance_model (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof (intro imod_contained_class_set_field_correct)\n fix o1 o2\n assume o1_cases: \"o1 \\ objects \\ sets_to_set (set ` values ` objects)\"\n assume o2_cases: \"o2 \\ objects \\ sets_to_set (set ` values ` objects)\"\n assume ids_eq: \"obids o1 = obids o2\"\n then show \"o1 = o2\"\n using o1_cases o2_cases\n proof (elim UnE)\n assume o1_def: \"o1 \\ objects\"\n then have o1_object: \"o1 \\ Object Imod\"\n using existing_objects\n by blast\n have o1_id: \"ObjectId Imod o1 = obids o1\"\n using o1_def ids_valid\n by simp\n assume o2_def: \"o2 \\ objects\"\n then have o2_object: \"o2 \\ Object Imod\"\n using existing_objects\n by blast\n have o2_id: \"ObjectId Imod o2 = obids o2\"\n using o2_def ids_valid\n by simp\n show ?thesis\n using assms(1) instance_model.property_object_id_uniqueness o2_object o1_object o2_id o1_id ids_eq\n by metis\n next\n assume o1_def: \"o1 \\ objects\"\n then have o1_object: \"o1 \\ Object Imod\"\n using existing_objects\n by blast\n have o1_id: \"ObjectId Imod o1 = obids o1\"\n using o1_def ids_valid\n by simp\n assume o2_def: \"o2 \\ sets_to_set (set ` values ` objects)\"\n then show ?thesis\n using o1_object o1_id ids_eq invalid_ids\n by metis\n next\n assume o2_def: \"o2 \\ objects\"\n then have o2_object: \"o2 \\ Object Imod\"\n using existing_objects\n by blast\n have o2_id: \"ObjectId Imod o2 = obids o2\"\n using o2_def ids_valid\n by simp\n assume o1_def: \"o1 \\ sets_to_set (set ` values ` objects)\"\n then show ?thesis\n using o2_object o2_id ids_eq invalid_ids\n by metis\n next\n assume o1_def: \"o1 \\ sets_to_set (set ` values ` objects)\"\n assume o2_def: \"o2 \\ sets_to_set (set ` values ` objects)\"\n show ?thesis\n using o1_def o2_def ids_eq unique_ids\n by blast\n qed\n qed (simp_all add: assms)\n have type_model_correct: \"type_model (tmod_contained_class_set_field classtype name containedtype mul)\"\n using tmod_contained_class_set_field_correct valid_ns valid_mul\n by metis\n have no_attr_type: \"TypeDef.setof \\containedtype \\ AttrType (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n proof\n assume \"TypeDef.setof \\containedtype \\ AttrType (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n then show \"False\"\n by (cases) (simp_all)\n qed\n have no_attr: \"(classtype, name) \\ Attr (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n proof\n have containedtype_def: \"Type_Model.type (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (classtype, name) = TypeDef.setof \\containedtype\"\n unfolding Type_Model.type_def imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by simp\n assume \"(classtype, name) \\ Attr (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n then show \"False\"\n unfolding Attr_def\n using containedtype_def no_attr_type\n by simp\n qed\n have rel_def: \"Rel (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) = {(classtype, name)}\"\n proof\n show \"Rel (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) \\ {(classtype, name)}\"\n proof\n fix x\n assume \"x \\ Rel (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n then show \"x \\ {(classtype, name)}\"\n unfolding Rel_def imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by simp\n qed\n next\n show \"{(classtype, name)} \\ Rel (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n proof\n fix x\n assume \"x \\ {(classtype, name)}\"\n then have \"x = (classtype, name)\"\n by simp\n then show \"x \\ Rel (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n using no_attr\n unfolding Rel_def imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by simp\n qed\n qed\n have cr_def_part: \"CR (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) = {(classtype, name)}\"\n proof\n show \"CR (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) \\ {(classtype, name)}\"\n proof\n fix x\n assume \"x \\ CR (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n then show \"x \\ {(classtype, name)}\"\n proof (induct)\n case (rule_containment_relations r)\n then show ?case\n using rel_def\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by blast\n qed\n qed\n next\n show \"{(classtype, name)} \\ CR (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n proof\n fix x\n assume \"x \\ {(classtype, name)}\"\n then have x_def: \"x = (classtype, name)\"\n by simp\n show \"x \\ CR (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n proof (rule CR.rule_containment_relations)\n show \"x \\ Rel (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n using x_def rel_def\n by simp\n next\n show \"containment x \\ Prop (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n using x_def\n by simp\n qed\n qed\n qed\n have type_model_valid: \"type_model (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n using assms(1) instance_model.validity_type_model_consistent existing_classes new_field valid_ns valid_mul\n by (intro tmod_contained_class_set_field_combine_correct) (simp_all)\n have structure_fieldsig_wellformed_type: \"\\f. f \\ Field (Tm Imod) \\ Field (tmod_contained_class_set_field classtype name containedtype mul) \\ \n fst (FieldSig (Tm Imod) f) = fst (FieldSig (tmod_contained_class_set_field classtype name containedtype mul) f)\"\n proof-\n fix f\n assume f_in_both: \"f \\ Field (Tm Imod) \\ Field (tmod_contained_class_set_field classtype name containedtype mul)\"\n then have \"f \\ Field (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n unfolding tmod_combine_def\n by simp\n then have \"fst (FieldSig (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)) f) \\ \n Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n using type_model_valid type_model.structure_fieldsig_wellformed_type\n by blast\n then have fst_in_type: \"fst (tmod_combine_fieldsig (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul) f) \\ \n Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n by (simp add: tmod_combine_def)\n then show \"fst (FieldSig (Tm Imod) f) = fst (FieldSig (tmod_contained_class_set_field classtype name containedtype mul) f)\"\n proof (induct \"fst (FieldSig (Tm Imod) f) = fst (FieldSig (tmod_contained_class_set_field classtype name containedtype mul) f)\")\n case True\n then show ?case\n by simp\n next\n case False\n then have \"fst (tmod_combine_fieldsig (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul) f) = TypeDef.invalid\"\n unfolding tmod_combine_fieldsig_def\n using f_in_both \n by simp\n then have \"fst (tmod_combine_fieldsig (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul) f) \\ \n Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n by simp\n then show ?case\n using fst_in_type\n by simp\n qed\n qed\n have \"CR (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)) = \n CR (Tm Imod) \\ CR (tmod_contained_class_set_field classtype name containedtype mul)\"\n using assms(1) instance_model.validity_type_model_consistent tmod_combine_containment_relation type_model_correct \n using structure_fieldsig_wellformed_type type_model.structure_fieldsig_wellformed_type type_model.structure_properties_wellfomed\n by blast\n then have \"CR (Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))) = \n CR (Tm Imod) \\ CR (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n then have cr_def: \"CR (Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))) = \n CR (Tm Imod) \\ {(classtype, name)}\"\n using cr_def_part\n by simp\n have containments_relation_def: \"object_containments_relation (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) = \n object_containments_relation Imod \\ object_containments_relation (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof\n show \"object_containments_relation (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) \\ \n object_containments_relation Imod \\ object_containments_relation (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof\n fix x\n assume \"x \\ object_containments_relation (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n then show \"x \\ object_containments_relation Imod \\ object_containments_relation (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof (induct x)\n case (Pair a b)\n then show ?case\n proof (induct)\n case (rule_object_containment o1 o2 r)\n then have r_cases: \"r \\ CR (Tm Imod) \\ {(classtype, name)}\"\n using cr_def\n by blast\n have \"o1 \\ Object Imod \\ objects \\ sets_to_set (set ` values ` objects)\"\n using rule_object_containment.hyps(1)\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n then have \"o1 \\ Object Imod \\ sets_to_set (set ` values ` objects)\"\n using existing_objects\n by blast\n then show ?case\n using r_cases\n proof (elim UnE)\n assume o1_def: \"o1 \\ Object Imod\"\n then have \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = \n imod_combine_object_class Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1\"\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n then have ob_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = ObjectClass Imod o1\"\n unfolding imod_combine_object_class_def\n using existing_objects classes_valid\n by (simp add: imod_contained_class_set_field_def inf.commute o1_def)\n then have \"ObjectClass Imod o1 \\ Class (Tm Imod)\"\n by (simp add: assms(1) instance_model.structure_object_class_wellformed o1_def)\n then have \"\\(ObjectClass Imod o1) \\ ProperClassType (Tm Imod)\"\n by (fact ProperClassType.rule_proper_classes)\n then have o1_class_is_type: \"\\(ObjectClass Imod o1) \\ Type (Tm Imod)\"\n unfolding Type_def NonContainerType_def ClassType_def\n by blast\n assume r_def: \"r \\ CR (Tm Imod)\"\n then have r_field: \"r \\ Field (Tm Imod)\"\n using containment_relations_are_fields\n by blast\n then have r_not_field: \"r \\ Field (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n using new_field\n by fastforce\n have \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1) \n \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))] \\(fst r)\"\n using rule_object_containment.hyps(3)\n unfolding Type_Model.fields_def\n by fastforce\n then have \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_rel_altdef (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n using ob_class_def\n unfolding subtype_def imod_contained_class_set_field_def imod_combine_def\n by (simp add: subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_valid)\n then have \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)) \\ \n subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+ \\\n subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+ \\\n subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)) \\\n subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n unfolding subtype_rel_altdef_def\n by simp\n then have \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_rel_altdef (Tm Imod)\"\n proof (elim UnE)\n assume \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then have \"ObjectClass Imod o1 = fst r\"\n unfolding subtype_tuple_def\n by fastforce\n then have \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_tuple ` Type (Tm Imod)\"\n unfolding subtype_tuple_def\n using o1_class_is_type\n by simp\n then show ?thesis\n unfolding subtype_rel_altdef_def\n by simp\n next\n assume \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then have \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_conv proper proper ` (Inh (Tm Imod))\\<^sup>+\"\n unfolding subtype_conv_def tmod_combine_def tmod_contained_class_set_field_def\n by simp\n then show ?thesis\n unfolding subtype_rel_altdef_def\n by simp\n next\n assume \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n then have \"\\(ObjectClass Imod o1) \\[Tm Imod] \\(fst r)\"\n by (simp add: assms(1) instance_model.validity_type_model_consistent subtype_def subtype_rel_alt type_model.structure_inh_wellformed_classes)\n then have r_in_fields: \"r \\ Type_Model.fields (Tm Imod) (ObjectClass Imod o1)\"\n unfolding Type_Model.fields_def\n using r_field\n by fastforce\n have \"FieldValue (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (o1, r) = FieldValue Imod (o1, r)\"\n unfolding imod_combine_def imod_combine_field_value_def\n using r_not_field r_field o1_def\n by simp\n then have \"obj o2 \\ set (contained_values (FieldValue Imod (o1, r)))\"\n using rule_object_containment.hyps(4)\n by simp\n then show ?thesis\n using o1_def object_containments_relation.rule_object_containment r_def r_in_fields\n by fastforce\n next\n assume o1_def: \"o1 \\ Object Imod\"\n then have \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = \n imod_combine_object_class Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1\"\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n then have ob_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = ObjectClass Imod o1\"\n unfolding imod_combine_object_class_def\n using existing_objects classes_valid\n by (simp add: imod_contained_class_set_field_def inf.commute o1_def)\n assume \"r \\ {(classtype, name)}\"\n then have r_def: \"r = (classtype, name)\"\n by simp\n then have r_cr: \"r \\ CR (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n using cr_def_part\n by simp\n have r_field: \"r \\ Field (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by (simp add: r_def)\n have r_not_field: \"r \\ Field (Tm Imod)\"\n using r_def new_field\n by simp\n have \"\\classtype \\ ProperClassType (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by (simp add: ProperClassType.rule_proper_classes)\n then have \"\\classtype \\ Type (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding Type_def NonContainerType_def ClassType_def\n by blast\n then have classtype_extend: \"\\classtype \\[Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)] \\classtype\"\n unfolding subtype_def\n by (simp add: subtype_rel.reflexivity)\n have \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1)\n \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))] \\classtype\"\n using rule_object_containment.hyps(3) r_def\n unfolding Type_Model.fields_def\n by blast\n then have \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_rel_altdef (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n unfolding subtype_def imod_contained_class_set_field_def imod_combine_def\n by (simp add: subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_valid)\n then have object_class_def: \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1) = \\classtype\"\n unfolding subtype_rel_altdef_def\n proof (elim UnE)\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_tuple_def\n by fastforce\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then have ob_extends_classtype: \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n unfolding subtype_conv_def\n by fastforce\n have \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n proof\n assume \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show \"False\"\n proof (cases)\n case base\n then show ?thesis\n unfolding tmod_contained_class_set_field_def tmod_combine_def\n using no_inh_classtype\n by simp\n next\n case (step c)\n then show ?thesis\n unfolding tmod_contained_class_set_field_def tmod_combine_def\n using no_inh_classtype\n by simp\n qed\n qed\n then show ?thesis\n using ob_extends_classtype\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n then have o1_class_def: \"ObjectClass Imod o1 = classtype\"\n by (simp add: ob_class_def)\n then have o1_in_objects: \"o1 \\ objects\"\n using all_objects o1_def\n by blast\n then have o1_def: \"o1 \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n unfolding imod_contained_class_set_field_def\n by simp\n then have \"ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1 = ObjectClass Imod o1\"\n unfolding imod_contained_class_set_field_def\n by (simp add: o1_class_def o1_in_objects)\n then have r_in_fields: \"r \\ Type_Model.fields (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) \n (ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1)\"\n unfolding Type_Model.fields_def\n using classtype_extend o1_class_def r_def r_field\n by fastforce\n have \"FieldValue (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (o1, r) =\n FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (o1, r)\"\n unfolding imod_combine_def imod_combine_field_value_def\n using r_not_field r_field o1_def\n by simp\n then have \"obj o2 \\ set (contained_values (FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (o1, r)))\"\n using rule_object_containment.hyps(4)\n by metis\n then show ?thesis\n using o1_def object_containments_relation.rule_object_containment r_cr r_in_fields\n by fastforce\n next\n assume o1_def: \"o1 \\ sets_to_set (set ` values ` objects)\"\n then have \"o1 \\ Object Imod\"\n using existing_objects objects_unique\n by auto\n then have ob_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = containedtype\"\n unfolding imod_combine_def imod_contained_class_set_field_def imod_combine_object_class_def\n using o1_def existing_objects\n by auto\n assume r_def: \"r \\ CR (Tm Imod)\"\n then have r_field: \"r \\ Field (Tm Imod)\"\n using containment_relations_are_fields\n by blast\n have \"containedtype \\ Class (Tm Imod)\"\n using existing_classes\n by blast\n then have \"\\containedtype \\ ProperClassType (Tm Imod)\"\n by (simp add: ProperClassType.rule_proper_classes)\n then have object_class_is_type: \"\\containedtype \\ Type (Tm Imod)\"\n unfolding Type_def NonContainerType_def ClassType_def\n by blast\n have no_extend_imod: \"\\\\containedtype \\[Tm Imod] \\(fst r)\"\n proof\n assume \"\\containedtype \\[Tm Imod] \\(fst r)\"\n then have \"r \\ Type_Model.fields (Tm Imod) containedtype\"\n unfolding Type_Model.fields_def\n using r_field\n by fastforce\n then show \"False\"\n by (simp add: no_fields_containedtype)\n qed\n have \"\\\\containedtype \\[tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)] \\(fst r)\"\n proof\n assume \"\\containedtype \\[tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)] \\(fst r)\"\n then have \"(\\containedtype, \\(fst r)) \\ subtype_rel_altdef (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n unfolding subtype_def imod_contained_class_set_field_def imod_combine_def\n by (simp add: subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_valid)\n then show \"False\"\n unfolding subtype_rel_altdef_def\n proof (elim UnE)\n assume \"(\\containedtype, \\(fst r)) \\ subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then have \"\\containedtype = \\(fst r)\"\n by (simp add: image_iff subtype_tuple_def)\n then have \"\\containedtype \\[Tm Imod] \\(fst r)\"\n using object_class_is_type subtype_def subtype_rel.reflexivity\n by blast\n then show ?thesis\n using no_extend_imod\n by blast\n next\n assume \"(\\containedtype, \\(fst r)) \\ subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\containedtype, \\(fst r)) \\ subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then have \"(\\containedtype, \\(fst r)) \\ subtype_conv proper proper ` (Inh (Tm Imod))\\<^sup>+\"\n unfolding tmod_combine_def tmod_contained_class_set_field_def\n by simp\n then have \"(\\containedtype, \\(fst r)) \\ subtype_rel_altdef (Tm Imod)\"\n unfolding subtype_rel_altdef_def\n by blast\n then have \"\\containedtype \\[Tm Imod] \\(fst r)\"\n by (simp add: assms(1) instance_model.validity_type_model_consistent subtype_def subtype_rel_alt type_model.structure_inh_wellformed_classes)\n then show ?thesis\n using no_extend_imod\n by blast\n next\n assume \"(\\containedtype, \\(fst r)) \\ subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\containedtype, \\(fst r)) \\ subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n qed\n then have \"\\\\containedtype \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))] \\(fst r)\"\n unfolding imod_contained_class_set_field_def imod_combine_def\n by simp\n then have \"r \\ Type_Model.fields (Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))) containedtype\"\n unfolding Type_Model.fields_def\n by fastforce\n then show ?thesis\n using rule_object_containment.hyps(3) ob_class_def\n by simp\n next\n assume o1_def: \"o1 \\ sets_to_set (set ` values ` objects)\"\n then have \"o1 \\ Object Imod\"\n using existing_objects objects_unique\n by auto\n then have ob_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = containedtype\"\n unfolding imod_combine_def imod_contained_class_set_field_def imod_combine_object_class_def\n using o1_def existing_objects\n by auto\n assume \"r \\ {(classtype, name)}\"\n then have r_def: \"r = (classtype, name)\"\n by simp\n then have \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1)\n \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))] \\classtype\"\n using rule_object_containment.hyps(3)\n unfolding Type_Model.fields_def\n by blast\n then have \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_rel_altdef (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n unfolding subtype_def imod_contained_class_set_field_def imod_combine_def\n by (simp add: subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_valid)\n then have object_class_def: \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1) = \\classtype\"\n unfolding subtype_rel_altdef_def\n proof (elim UnE)\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_tuple_def\n by fastforce\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then have ob_extends_classtype: \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n unfolding subtype_conv_def\n by fastforce\n have \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n proof\n assume \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show \"False\"\n proof (cases)\n case base\n then show ?thesis\n unfolding tmod_contained_class_set_field_def tmod_combine_def\n using no_inh_classtype\n by simp\n next\n case (step c)\n then show ?thesis\n unfolding tmod_contained_class_set_field_def tmod_combine_def\n using no_inh_classtype\n by simp\n qed\n qed\n then show ?thesis\n using ob_extends_classtype\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n then show ?thesis\n using ob_class_def classtype_containedtype_neq\n by simp\n qed\n qed\n qed\n qed\n next\n show \"object_containments_relation Imod \\ object_containments_relation (imod_contained_class_set_field classtype name containedtype mul objects obids values) \\ \n object_containments_relation (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n proof\n fix x\n assume \"x \\ object_containments_relation Imod \\ object_containments_relation (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n then show \"x \\ object_containments_relation (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n proof (elim UnE)\n assume \"x \\ object_containments_relation Imod\"\n then show \"x \\ object_containments_relation (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n proof (induct x)\n case (Pair a b)\n then show ?case\n proof (induct)\n case (rule_object_containment o1 o2 r)\n then have \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = \n imod_combine_object_class Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1\"\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n then have o1_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = ObjectClass Imod o1\"\n unfolding imod_combine_object_class_def\n using existing_objects classes_valid\n by (simp add: imod_contained_class_set_field_def inf.commute rule_object_containment.hyps(1))\n have r_field: \"r \\ Field (Tm Imod)\"\n using rule_object_containment.hyps(2) containment_relations_are_fields\n by blast\n then have r_not_field: \"r \\ Field (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n using new_field\n by fastforce\n have \"o1 \\ Object Imod \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using rule_object_containment.hyps(1)\n by blast\n then have o1_def: \"o1 \\ Object (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_combine_def\n by simp\n have \"r \\ CR (Tm Imod) \\ {(classtype, name)}\"\n by (simp add: rule_object_containment.hyps(2))\n then have r_def: \"r \\ CR (Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)))\"\n by (simp add: cr_def)\n have \"r \\ Type_Model.fields (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)) (ObjectClass Imod o1)\"\n using rule_object_containment.hyps(3) tmod_combine_subtype_subset_tmod1\n unfolding Type_Model.fields_def tmod_combine_def\n by fastforce\n then have \"r \\ Type_Model.fields (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\n (ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1)\"\n by (simp add: o1_class_def)\n then have r_in_fields: \"r \\ Type_Model.fields (Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)))\n (ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1)\"\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n have \"FieldValue (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (o1, r) = FieldValue Imod (o1, r)\"\n unfolding imod_combine_def imod_combine_field_value_def\n using r_not_field r_field rule_object_containment.hyps(1)\n by simp\n then have \"obj o2 \\ set (contained_values (FieldValue (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (o1, r)))\"\n using rule_object_containment.hyps(4)\n by simp\n then show ?case\n using o1_def object_containments_relation.rule_object_containment r_def r_in_fields\n by fastforce\n qed\n qed\n next\n assume \"x \\ object_containments_relation (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n then show \"x \\ object_containments_relation (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n proof (induct x)\n case (Pair a b)\n then show ?case\n proof (induct)\n case (rule_object_containment o1 o2 r)\n then have \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = \n imod_combine_object_class Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1\"\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n then have o1_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = \n ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1\"\n using objects_unique existing_objects classes_valid rule_object_containment.hyps(1)\n unfolding imod_combine_object_class_def imod_contained_class_set_field_def\n by fastforce\n have r_field: \"r \\ Field (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n using rule_object_containment.hyps(2) containment_relations_are_fields\n by blast\n then have r_not_field: \"r \\ Field (Tm Imod)\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n using new_field\n by fastforce\n have \"o1 \\ Object Imod \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using rule_object_containment.hyps(1)\n by blast\n then have o1_def: \"o1 \\ Object (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_combine_def\n by simp\n have \"r = (classtype, name)\"\n using cr_def_part rule_object_containment.hyps(2)\n by simp\n then have \"r \\ CR (Tm Imod) \\ {(classtype, name)}\"\n by simp\n then have r_def: \"r \\ CR (Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)))\"\n by (simp add: cr_def)\n have \"r \\ Type_Model.fields (tmod_combine (Tm Imod) (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))) \n (ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1)\"\n using rule_object_containment.hyps(3) tmod_combine_subtype_subset_tmod2\n unfolding Type_Model.fields_def tmod_combine_def\n by fastforce\n then have \"r \\ Type_Model.fields (tmod_combine (Tm Imod) (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)))\n (ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1)\"\n by (simp add: o1_class_def)\n then have r_in_fields: \"r \\ Type_Model.fields (Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)))\n (ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1)\"\n unfolding imod_combine_def\n by simp\n have \"FieldValue (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (o1, r) = \n FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (o1, r)\"\n unfolding imod_combine_def imod_combine_field_value_def\n using r_not_field r_field rule_object_containment.hyps(1)\n by simp\n then have \"obj o2 \\ set (contained_values (FieldValue (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (o1, r)))\"\n using rule_object_containment.hyps(4)\n by simp\n then show ?case\n using o1_def object_containments_relation.rule_object_containment r_def r_in_fields\n by fastforce\n qed\n qed\n qed\n qed\n qed\n have containments_imod_def: \"\\x y. (x, y) \\ object_containments_relation Imod \\ x \\ Object Imod \\ y \\ Object Imod\"\n proof-\n fix x y\n assume \"(x, y) \\ object_containments_relation Imod\"\n then show \"x \\ Object Imod \\ y \\ Object Imod\"\n proof (induct)\n case (rule_object_containment o1 o2 r)\n then have \"r \\ Field (Tm Imod)\"\n by simp\n then have value_def: \"FieldValue Imod (o1, r) \\ Value Imod\"\n by (simp add: assms(1) instance_model.property_field_values_inside_domain rule_object_containment.hyps(1) rule_object_containment.hyps(3))\n then have \"set (contained_values (FieldValue Imod (o1, r))) \\ Value Imod\"\n unfolding Value_def\n using container_value_contained_values atom_values_contained_values_singleton\n by fastforce\n then have \"obj o2 \\ Value Imod\"\n using value_def rule_object_containment.hyps(4)\n by blast\n then have \"obj o2 \\ ProperClassValue Imod\"\n unfolding Value_def AtomValue_def ClassValue_def\n by simp\n then have \"o2 \\ Object Imod\"\n using ProperClassValue.cases\n by blast\n then show ?case\n by (simp add: rule_object_containment.hyps(1))\n qed\n qed\n have containments_imod_irrefl: \"irrefl ((object_containments_relation Imod)\\<^sup>+)\"\n proof (induct \"\\r. containment r \\ Prop (Tm Imod)\")\n case True\n then show ?case\n using assms(1) instance_model.validity_properties_satisfied property_satisfaction_containment_rev\n by metis\n next\n case False\n have \"object_containments_relation Imod = {}\"\n proof\n show \"object_containments_relation Imod \\ {}\"\n proof\n fix x\n assume \"x \\ object_containments_relation Imod\"\n then show \"x \\ {}\"\n proof (induct x)\n case (Pair a b)\n then show ?case\n proof (induct)\n case (rule_object_containment o1 o2 r)\n have \"\\r. containment r \\ Prop (Tm Imod)\"\n using rule_object_containment.hyps(2)\n proof (induct)\n case (rule_containment_relations r)\n then show ?case\n by blast\n qed\n then show ?case\n using False.hyps\n by simp\n qed\n qed\n qed\n next\n show \"{} \\ object_containments_relation Imod\"\n by simp\n qed\n then show ?case\n unfolding irrefl_def\n by simp\n qed\n have containments_block_def: \"\\x y. (x, y) \\ object_containments_relation (imod_contained_class_set_field classtype name containedtype mul objects obids values) \\ \n x \\ objects \\ y \\ sets_to_set (set ` values ` objects)\"\n proof-\n fix x y\n assume \"(x, y) \\ object_containments_relation (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n then show \"x \\ objects \\ y \\ sets_to_set (set ` values ` objects)\"\n proof (induct)\n case (rule_object_containment o1 o2 r)\n then have r_def: \"r = (classtype, name)\"\n using cr_def_part\n by simp\n then have o1_cases: \"o1 \\ objects \\ sets_to_set (set ` values ` objects)\"\n using rule_object_containment.hyps(1)\n unfolding imod_contained_class_set_field_def\n by simp\n then show ?case\n proof (elim UnE)\n assume o1_def: \"o1 \\ objects\"\n then have o1_class_def: \"ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1 = classtype\"\n unfolding imod_contained_class_set_field_def\n by simp\n have value_def: \"FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (o1, r) = setof (map obj (values o1))\"\n unfolding imod_contained_class_set_field_def\n using o1_def r_def\n by simp\n have set_in_sets: \"set (values o1) \\ sets_to_set (set ` values ` objects)\"\n proof\n fix x\n assume \"x \\ set (values o1)\"\n then show \"x \\ sets_to_set (set ` values ` objects)\"\n using o1_def imageI sets_to_set.rule_member\n by metis\n qed\n have \"set (map obj (values o1)) \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof\n fix x :: \"('a, 'b) ValueDef\"\n assume \"x \\ set (map obj (values o1))\"\n then have \"x \\ obj ` sets_to_set (set ` values ` objects)\"\n using set_in_sets\n by fastforce\n then show \"x \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof\n fix y\n assume x_def: \"x = obj y\"\n assume y_def: \"y \\ sets_to_set (set ` values ` objects)\"\n then have \"obj y \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof (intro ProperClassValue.rule_proper_objects)\n assume \"y \\ sets_to_set (set ` values ` objects)\"\n then show \"y \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n unfolding imod_contained_class_set_field_def\n by simp\n qed\n then show \"x \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using x_def\n by blast\n qed\n qed\n then have \"set (map obj (values o1)) \\ AtomValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using proper_class_values_are_atom_values\n by blast\n then have \"map obj (values o1) = [] \\ map obj (values o1) \\ AtomValueList (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using list.map_disc_iff list_of_atom_values_in_atom_value_list_alt\n by metis\n then have contained_values_def: \"contained_values (FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (o1, r)) = map obj (values o1)\"\n using value_def atom_value_list_contained_values_setof_identity\n by fastforce\n then have \"obj o2 \\ set (map obj (values o1))\"\n using rule_object_containment.hyps(4)\n by fastforce\n then have ob_in_set_def: \"o2 \\ set (values o1)\"\n using rule_object_containment.hyps(4)\n by fastforce\n then have \"o2 \\ sets_to_set (set ` values ` objects)\"\n using set_in_sets\n by blast\n then show ?thesis\n using o1_def\n by blast\n next\n assume o1_def: \"o1 \\ sets_to_set (set ` values ` objects)\"\n then have o1_class_def: \"ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1 = containedtype\"\n unfolding imod_contained_class_set_field_def\n using objects_unique\n by fastforce\n have \"\\\\containedtype \\[Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)] \\classtype\"\n proof\n assume \"\\containedtype \\[Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)] \\classtype\"\n then have \"\\containedtype \\[tmod_contained_class_set_field classtype name containedtype mul] \\classtype\"\n unfolding imod_contained_class_set_field_def class_def\n by simp\n then have \"(\\containedtype, \\classtype) \\ subtype_rel_altdef (tmod_contained_class_set_field classtype name containedtype mul)\"\n using subtype_def subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_correct\n by blast\n then show \"False\"\n unfolding subtype_rel_altdef_def\n proof (elim UnE)\n assume \"(\\containedtype, \\classtype) \\ subtype_tuple ` Type (tmod_contained_class_set_field classtype name containedtype mul)\"\n then have \"classtype = containedtype\"\n by (simp add: image_iff subtype_tuple_def)\n then show ?thesis\n using classtype_containedtype_neq\n by blast\n next\n assume \"(\\containedtype, \\classtype) \\ subtype_conv nullable nullable ` (Inh (tmod_contained_class_set_field classtype name containedtype mul))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\containedtype, \\classtype) \\ subtype_conv proper proper ` (Inh (tmod_contained_class_set_field classtype name containedtype mul))\\<^sup>+\"\n then show ?thesis\n unfolding tmod_contained_class_set_field_def\n by auto\n next\n assume \"(\\containedtype, \\classtype) \\ subtype_conv proper nullable ` subtype_tuple ` Class (tmod_contained_class_set_field classtype name containedtype mul)\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\containedtype, \\classtype) \\ subtype_conv proper nullable ` (Inh (tmod_contained_class_set_field classtype name containedtype mul))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n qed\n then have \"r \\ Type_Model.fields (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) containedtype\"\n unfolding Type_Model.fields_def\n using r_def\n by simp\n then show ?thesis\n using o1_class_def rule_object_containment.hyps(3)\n by simp\n qed\n qed\n qed\n have \"imod_contained_class_set_field classtype name containedtype mul objects obids values \\ containment (classtype, name)\"\n using instance_model_correct instance_model.validity_properties_satisfied\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by fastforce\n then have containments_block_irrefl: \"irrefl ((object_containments_relation (imod_contained_class_set_field classtype name containedtype mul objects obids values))\\<^sup>+)\"\n using instance_model_correct property_satisfaction_containment_rev\n by metis\n have \"\\x. (x, x) \\ (object_containments_relation Imod \\ object_containments_relation (imod_contained_class_set_field classtype name containedtype mul objects obids values))\\<^sup>+\"\n proof\n fix x\n assume \"(x, x) \\ (object_containments_relation Imod \\ object_containments_relation (imod_contained_class_set_field classtype name containedtype mul objects obids values))\\<^sup>+\"\n then show \"False\"\n proof (cases)\n case base\n then show ?thesis\n using containments_imod_irrefl containments_block_irrefl\n unfolding irrefl_def\n by blast\n next\n case (step c)\n then show ?thesis\n proof (elim UnE)\n assume c_x_def: \"(c, x) \\ object_containments_relation Imod\"\n then have c_def: \"c \\ Object Imod\"\n using containments_imod_def\n by simp\n have \"(x, c) \\ (object_containments_relation Imod)\\<^sup>+\"\n using step(1) c_def\n proof (induct)\n case (base y)\n then show ?case\n using containments_block_def existing_objects objects_unique\n by blast\n next\n case (step y z)\n then show ?case\n using containments_imod_def containments_block_def existing_objects objects_unique\n by fastforce\n qed\n then show ?thesis\n using c_x_def containments_imod_irrefl irrefl_def trancl_into_trancl2\n by metis\n next\n assume c_x_def: \"(c, x) \\ object_containments_relation (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n then have x_def: \"x \\ sets_to_set (set ` values ` objects)\"\n using containments_block_def\n by blast\n have c_def: \"c \\ objects\"\n using c_x_def containments_block_def\n by simp\n then have c_def: \"c \\ Object Imod\"\n using existing_objects\n by blast\n have \"(x, c) \\ (object_containments_relation Imod)\\<^sup>+\"\n using step(1) c_def\n proof (induct)\n case (base y)\n then show ?case\n using containments_block_def existing_objects objects_unique\n by blast\n next\n case (step y z)\n then show ?case\n using containments_imod_def containments_block_def existing_objects objects_unique\n by fastforce\n qed\n then have \"x \\ Object Imod\"\n using containments_imod_def converse_tranclE\n by metis\n then show ?thesis\n using x_def objects_unique existing_objects\n by blast\n qed\n qed\n qed\n then show \"irrefl ((object_containments_relation (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)))\\<^sup>+)\"\n unfolding irrefl_def\n using containments_relation_def\n by simp\n fix ob\n assume \"ob \\ Object Imod \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n then have \"ob \\ Object Imod \\ objects \\ sets_to_set (set ` values ` objects)\"\n unfolding imod_contained_class_set_field_def\n by simp\n then have \"ob \\ Object Imod \\ sets_to_set (set ` values ` objects)\"\n using existing_objects\n by blast\n then show \"card (object_containments (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob) \\ 1\"\n proof (elim UnE)\n assume ob_def: \"ob \\ Object Imod\"\n have \"object_containments (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob = object_containments Imod ob\"\n proof\n show \"object_containments (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob \\ object_containments Imod ob\"\n proof\n fix x\n assume \"x \\ object_containments (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob\"\n then show \"x \\ object_containments Imod ob\"\n proof (induct x)\n case (Pair a d)\n then show ?case\n proof (induct a)\n case (fields a b c)\n then show ?case\n proof (induct)\n case (rule_object_containment o1 r)\n then have r_cases: \"r \\ CR (Tm Imod) \\ {(classtype, name)}\"\n using cr_def\n by blast\n have \"o1 \\ Object Imod \\ objects \\ sets_to_set (set ` values ` objects)\"\n using rule_object_containment.hyps(1)\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n then have \"o1 \\ Object Imod \\ sets_to_set (set ` values ` objects)\"\n using existing_objects\n by blast\n then show ?case\n using r_cases\n proof (elim UnE)\n assume o1_def: \"o1 \\ Object Imod\"\n then have \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = \n imod_combine_object_class Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1\"\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n then have ob_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = ObjectClass Imod o1\"\n unfolding imod_combine_object_class_def\n using existing_objects classes_valid\n by (simp add: imod_contained_class_set_field_def inf.commute o1_def)\n then have \"ObjectClass Imod o1 \\ Class (Tm Imod)\"\n by (simp add: assms(1) instance_model.structure_object_class_wellformed o1_def)\n then have \"\\(ObjectClass Imod o1) \\ ProperClassType (Tm Imod)\"\n by (fact ProperClassType.rule_proper_classes)\n then have o1_class_is_type: \"\\(ObjectClass Imod o1) \\ Type (Tm Imod)\"\n unfolding Type_def NonContainerType_def ClassType_def\n by blast\n assume r_def: \"r \\ CR (Tm Imod)\"\n then have r_field: \"r \\ Field (Tm Imod)\"\n using containment_relations_are_fields\n by blast\n then have r_not_field: \"r \\ Field (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n using new_field\n by fastforce\n have \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1) \n \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))] \\(fst r)\"\n using rule_object_containment.hyps(3)\n unfolding Type_Model.fields_def\n by fastforce\n then have \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_rel_altdef (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n using ob_class_def\n unfolding subtype_def imod_contained_class_set_field_def imod_combine_def\n by (simp add: subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_valid)\n then have \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)) \\ \n subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+ \\\n subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+ \\\n subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)) \\\n subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n unfolding subtype_rel_altdef_def\n by simp\n then have \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_rel_altdef (Tm Imod)\"\n proof (elim UnE)\n assume \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then have \"ObjectClass Imod o1 = fst r\"\n unfolding subtype_tuple_def\n by fastforce\n then have \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_tuple ` Type (Tm Imod)\"\n unfolding subtype_tuple_def\n using o1_class_is_type\n by simp\n then show ?thesis\n unfolding subtype_rel_altdef_def\n by simp\n next\n assume \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then have \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_conv proper proper ` (Inh (Tm Imod))\\<^sup>+\"\n unfolding subtype_conv_def tmod_combine_def tmod_contained_class_set_field_def\n by simp\n then show ?thesis\n unfolding subtype_rel_altdef_def\n by simp\n next\n assume \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n then have \"\\(ObjectClass Imod o1) \\[Tm Imod] \\(fst r)\"\n by (simp add: assms(1) instance_model.validity_type_model_consistent subtype_def subtype_rel_alt type_model.structure_inh_wellformed_classes)\n then have r_in_fields: \"r \\ Type_Model.fields (Tm Imod) (ObjectClass Imod o1)\"\n unfolding Type_Model.fields_def\n using r_field\n by fastforce\n have \"FieldValue (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (o1, r) = FieldValue Imod (o1, r)\"\n unfolding imod_combine_def imod_combine_field_value_def\n using r_not_field r_field o1_def\n by simp\n then have \"obj ob \\ set (contained_values (FieldValue Imod (o1, r)))\"\n using rule_object_containment.hyps(4)\n by simp\n then show ?thesis\n by (simp add: o1_def object_containments.rule_object_containment r_def r_in_fields)\n next\n assume o1_def: \"o1 \\ Object Imod\"\n then have \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = \n imod_combine_object_class Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1\"\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n then have ob_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = ObjectClass Imod o1\"\n unfolding imod_combine_object_class_def\n using existing_objects classes_valid\n by (simp add: imod_contained_class_set_field_def inf.commute o1_def)\n assume r_def: \"r \\ {(classtype, name)}\"\n then have r_def: \"r = (classtype, name)\"\n by simp\n have r_field: \"r \\ Field (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by (simp add: r_def)\n have r_not_field: \"r \\ Field (Tm Imod)\"\n using r_def new_field\n by simp\n have \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1)\n \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))] \\classtype\"\n using rule_object_containment.hyps(3) r_def\n unfolding Type_Model.fields_def\n by blast\n then have \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_rel_altdef (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n unfolding subtype_def imod_contained_class_set_field_def imod_combine_def\n by (simp add: subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_valid)\n then have object_class_def: \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1) = \\classtype\"\n unfolding subtype_rel_altdef_def\n proof (elim UnE)\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_tuple_def\n by fastforce\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then have ob_extends_classtype: \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n unfolding subtype_conv_def\n by fastforce\n have \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n proof\n assume \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show \"False\"\n proof (cases)\n case base\n then show ?thesis\n unfolding tmod_contained_class_set_field_def tmod_combine_def\n using no_inh_classtype\n by simp\n next\n case (step c)\n then show ?thesis\n unfolding tmod_contained_class_set_field_def tmod_combine_def\n using no_inh_classtype\n by simp\n qed\n qed\n then show ?thesis\n using ob_extends_classtype\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n then have \"ObjectClass Imod o1 = classtype\"\n by (simp add: ob_class_def)\n then have o1_def: \"o1 \\ objects\"\n using all_objects o1_def\n by blast\n then have \"o1 \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n unfolding imod_contained_class_set_field_def\n by simp\n then have \"FieldValue (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (o1, r) = \n FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (o1, r)\"\n unfolding imod_combine_def imod_combine_field_value_def\n using r_not_field r_field\n by simp\n then have value_def: \"FieldValue (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (o1, r) = \n setof (map obj (values o1))\"\n unfolding imod_contained_class_set_field_def\n using o1_def r_def\n by simp\n have set_in_sets: \"set (values o1) \\ sets_to_set (set ` values ` objects)\"\n proof\n fix x\n assume \"x \\ set (values o1)\"\n then show \"x \\ sets_to_set (set ` values ` objects)\"\n using o1_def imageI sets_to_set.rule_member\n by metis\n qed\n have \"set (map obj (values o1)) \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof\n fix x :: \"('a, 'b) ValueDef\"\n assume \"x \\ set (map obj (values o1))\"\n then have \"x \\ obj ` sets_to_set (set ` values ` objects)\"\n using set_in_sets\n by fastforce\n then show \"x \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof\n fix y\n assume x_def: \"x = obj y\"\n assume y_def: \"y \\ sets_to_set (set ` values ` objects)\"\n then have \"obj y \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n proof (intro ProperClassValue.rule_proper_objects)\n assume \"y \\ sets_to_set (set ` values ` objects)\"\n then show \"y \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n unfolding imod_contained_class_set_field_def\n by simp\n qed\n then show \"x \\ ProperClassValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using x_def\n by blast\n qed\n qed\n then have \"set (map obj (values o1)) \\ AtomValue (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using proper_class_values_are_atom_values\n by blast\n then have \"map obj (values o1) = [] \\ map obj (values o1) \\ AtomValueList (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using list.map_disc_iff list_of_atom_values_in_atom_value_list_alt\n by metis\n then have contained_values_def: \"contained_values (FieldValue (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (o1, r)) = map obj (values o1)\"\n using value_def atom_value_list_contained_values_setof_identity\n by fastforce\n have \"obj ob \\ set (map obj (values o1))\"\n proof\n have ob_not_in_sets: \"ob \\ sets_to_set (set ` values ` objects)\"\n using ob_def existing_objects objects_unique\n by blast\n assume \"obj ob \\ set (map obj (values o1))\"\n then have \"ob \\ set (values o1)\"\n by fastforce\n then have \"ob \\ sets_to_set (set ` values ` objects)\"\n using set_in_sets\n by blast\n then show \"False\"\n using ob_not_in_sets\n by simp\n qed\n then show ?thesis\n using contained_values_def rule_object_containment.hyps(4)\n by metis\n next\n assume o1_def: \"o1 \\ sets_to_set (set ` values ` objects)\"\n then have \"o1 \\ Object Imod\"\n using existing_objects objects_unique\n by auto\n then have ob_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = containedtype\"\n unfolding imod_combine_def imod_contained_class_set_field_def imod_combine_object_class_def\n using o1_def existing_objects\n by auto\n assume r_def: \"r \\ CR (Tm Imod)\"\n then have r_field: \"r \\ Field (Tm Imod)\"\n using containment_relations_are_fields\n by blast\n have \"containedtype \\ Class (Tm Imod)\"\n using existing_classes\n by blast\n then have \"\\containedtype \\ ProperClassType (Tm Imod)\"\n by (simp add: ProperClassType.rule_proper_classes)\n then have object_class_is_type: \"\\containedtype \\ Type (Tm Imod)\"\n unfolding Type_def NonContainerType_def ClassType_def\n by blast\n have no_extend_imod: \"\\\\containedtype \\[Tm Imod] \\(fst r)\"\n proof\n assume \"\\containedtype \\[Tm Imod] \\(fst r)\"\n then have \"r \\ Type_Model.fields (Tm Imod) containedtype\"\n unfolding Type_Model.fields_def\n using r_field\n by fastforce\n then show \"False\"\n by (simp add: no_fields_containedtype)\n qed\n have \"\\\\containedtype \\[tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)] \\(fst r)\"\n proof\n assume \"\\containedtype \\[tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)] \\(fst r)\"\n then have \"(\\containedtype, \\(fst r)) \\ subtype_rel_altdef (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n unfolding subtype_def imod_contained_class_set_field_def imod_combine_def\n by (simp add: subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_valid)\n then show \"False\"\n unfolding subtype_rel_altdef_def\n proof (elim UnE)\n assume \"(\\containedtype, \\(fst r)) \\ subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then have \"\\containedtype = \\(fst r)\"\n by (simp add: image_iff subtype_tuple_def)\n then have \"\\containedtype \\[Tm Imod] \\(fst r)\"\n using object_class_is_type subtype_def subtype_rel.reflexivity\n by blast\n then show ?thesis\n using no_extend_imod\n by blast\n next\n assume \"(\\containedtype, \\(fst r)) \\ subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\containedtype, \\(fst r)) \\ subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then have \"(\\containedtype, \\(fst r)) \\ subtype_conv proper proper ` (Inh (Tm Imod))\\<^sup>+\"\n unfolding tmod_combine_def tmod_contained_class_set_field_def\n by simp\n then have \"(\\containedtype, \\(fst r)) \\ subtype_rel_altdef (Tm Imod)\"\n unfolding subtype_rel_altdef_def\n by blast\n then have \"\\containedtype \\[Tm Imod] \\(fst r)\"\n by (simp add: assms(1) instance_model.validity_type_model_consistent subtype_def subtype_rel_alt type_model.structure_inh_wellformed_classes)\n then show ?thesis\n using no_extend_imod\n by blast\n next\n assume \"(\\containedtype, \\(fst r)) \\ subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\containedtype, \\(fst r)) \\ subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n qed\n then have \"\\\\containedtype \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))] \\(fst r)\"\n unfolding imod_contained_class_set_field_def imod_combine_def\n by simp\n then have \"r \\ Type_Model.fields (Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))) containedtype\"\n unfolding Type_Model.fields_def\n by fastforce\n then show ?thesis\n using rule_object_containment.hyps(3) ob_class_def\n by simp\n next\n assume o1_def: \"o1 \\ sets_to_set (set ` values ` objects)\"\n then have \"o1 \\ Object Imod\"\n using existing_objects objects_unique\n by auto\n then have ob_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = containedtype\"\n unfolding imod_combine_def imod_contained_class_set_field_def imod_combine_object_class_def\n using o1_def existing_objects\n by auto\n assume \"r \\ {(classtype, name)}\"\n then have r_def: \"r = (classtype, name)\"\n by simp\n then have \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1)\n \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))] \\classtype\"\n using rule_object_containment.hyps(3)\n unfolding Type_Model.fields_def\n by blast\n then have \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_rel_altdef (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n unfolding subtype_def imod_contained_class_set_field_def imod_combine_def\n by (simp add: subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_valid)\n then have object_class_def: \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1) = \\classtype\"\n unfolding subtype_rel_altdef_def\n proof (elim UnE)\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_tuple_def\n by fastforce\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then have ob_extends_classtype: \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n unfolding subtype_conv_def\n by fastforce\n have \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n proof\n assume \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show \"False\"\n proof (cases)\n case base\n then show ?thesis\n unfolding tmod_contained_class_set_field_def tmod_combine_def\n using no_inh_classtype\n by simp\n next\n case (step c)\n then show ?thesis\n unfolding tmod_contained_class_set_field_def tmod_combine_def\n using no_inh_classtype\n by simp\n qed\n qed\n then show ?thesis\n using ob_extends_classtype\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n then show ?thesis\n using ob_class_def classtype_containedtype_neq\n by simp\n qed\n qed\n qed\n qed\n qed\n next\n show \"object_containments Imod ob \\ object_containments (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob\"\n proof\n fix x\n assume \"x \\ object_containments Imod ob\"\n then show \"x \\ object_containments (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob\"\n proof (induct x)\n case (Pair a d)\n then show ?case\n proof (induct a)\n case (fields a b c)\n then show ?case\n proof (induct)\n case (rule_object_containment o1 r)\n then have \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = \n imod_combine_object_class Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1\"\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n then have o1_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = ObjectClass Imod o1\"\n unfolding imod_combine_object_class_def\n using existing_objects classes_valid\n by (simp add: imod_contained_class_set_field_def inf.commute rule_object_containment.hyps(1))\n have r_field: \"r \\ Field (Tm Imod)\"\n using rule_object_containment.hyps(2) containment_relations_are_fields\n by blast\n then have r_not_field: \"r \\ Field (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n using new_field\n by fastforce\n have \"o1 \\ Object Imod \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using rule_object_containment.hyps(1)\n by blast\n then have o1_def: \"o1 \\ Object (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_combine_def\n by simp\n have \"r \\ CR (Tm Imod) \\ {(classtype, name)}\"\n by (simp add: rule_object_containment.hyps(2))\n then have r_def: \"r \\ CR (Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)))\"\n by (simp add: cr_def)\n have \"r \\ Type_Model.fields (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)) (ObjectClass Imod o1)\"\n using rule_object_containment.hyps(3) tmod_combine_subtype_subset_tmod1\n unfolding Type_Model.fields_def tmod_combine_def\n by fastforce\n then have \"r \\ Type_Model.fields (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\n (ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1)\"\n by (simp add: o1_class_def)\n then have r_in_fields: \"r \\ Type_Model.fields (Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)))\n (ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1)\"\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n have \"FieldValue (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (o1, r) = FieldValue Imod (o1, r)\"\n unfolding imod_combine_def imod_combine_field_value_def\n using r_not_field r_field rule_object_containment.hyps(1)\n by simp\n then have \"obj ob \\ set (contained_values (FieldValue (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (o1, r)))\"\n using rule_object_containment.hyps(4)\n by simp\n then show ?case\n by (simp add: o1_def object_containments.rule_object_containment r_def r_in_fields)\n qed\n qed\n qed\n qed\n qed\n then show ?thesis\n proof (induct \"\\r. containment r \\ Prop (Tm Imod)\")\n case True\n then show ?case\n using ob_def assms(1) instance_model.validity_properties_satisfied property_satisfaction_containment_rev\n by metis\n next\n case False\n have \"object_containments Imod ob = {}\"\n proof\n show \"object_containments Imod ob \\ {}\"\n proof\n fix x\n assume \"x \\ object_containments Imod ob\"\n then show \"x \\ {}\"\n proof (induct x)\n case (Pair a d)\n then show ?case\n proof (induct a)\n case (fields a b c)\n then show ?case\n proof (induct)\n case (rule_object_containment o1 r)\n have \"\\r. containment r \\ Prop (Tm Imod)\"\n using rule_object_containment.hyps(2)\n proof (induct)\n case (rule_containment_relations r)\n then show ?case\n by blast\n qed\n then show ?case\n using False.hyps\n by simp\n qed\n qed\n qed\n qed\n next\n show \"{} \\ object_containments Imod ob\"\n by simp\n qed\n then show ?case\n using False.prems card_empty\n by simp\n qed\n next\n assume ob_def: \"ob \\ sets_to_set (set ` values ` objects)\"\n then have ob_altdef: \"ob \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n unfolding imod_contained_class_set_field_def\n by simp\n have containments_eq: \"object_containments (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob = \n object_containments (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob\"\n proof\n show \"object_containments (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob \\ \n object_containments (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob\"\n proof\n fix x\n assume \"x \\ object_containments (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob\"\n then show \"x \\ object_containments (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob\"\n proof (induct x)\n case (Pair a d)\n then show ?case\n proof (induct a)\n case (fields a b c)\n then show ?case\n proof (induct)\n case (rule_object_containment o1 r)\n then have r_cases: \"r \\ CR (Tm Imod) \\ {(classtype, name)}\"\n using cr_def\n by blast\n have \"o1 \\ Object Imod \\ objects \\ sets_to_set (set ` values ` objects)\"\n using rule_object_containment.hyps(1)\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n then have \"o1 \\ Object Imod \\ sets_to_set (set ` values ` objects)\"\n using existing_objects\n by blast\n then show ?case\n using r_cases\n proof (elim UnE)\n assume o1_def: \"o1 \\ Object Imod\"\n then have \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = \n imod_combine_object_class Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1\"\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n then have ob_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = ObjectClass Imod o1\"\n unfolding imod_combine_object_class_def\n using existing_objects classes_valid\n by (simp add: imod_contained_class_set_field_def inf.commute o1_def)\n then have \"ObjectClass Imod o1 \\ Class (Tm Imod)\"\n by (simp add: assms(1) instance_model.structure_object_class_wellformed o1_def)\n then have \"\\(ObjectClass Imod o1) \\ ProperClassType (Tm Imod)\"\n by (fact ProperClassType.rule_proper_classes)\n then have o1_class_is_type: \"\\(ObjectClass Imod o1) \\ Type (Tm Imod)\"\n unfolding Type_def NonContainerType_def ClassType_def\n by blast\n assume r_def: \"r \\ CR (Tm Imod)\"\n then have r_field: \"r \\ Field (Tm Imod)\"\n using containment_relations_are_fields\n by blast\n then have r_not_field: \"r \\ Field (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n using new_field\n by fastforce\n have \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1) \n \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))] \\(fst r)\"\n using rule_object_containment.hyps(3)\n unfolding Type_Model.fields_def\n by fastforce\n then have \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_rel_altdef (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n using ob_class_def\n unfolding subtype_def imod_contained_class_set_field_def imod_combine_def\n by (simp add: subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_valid)\n then have \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)) \\ \n subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+ \\\n subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+ \\\n subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)) \\\n subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n unfolding subtype_rel_altdef_def\n by simp\n then have \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_rel_altdef (Tm Imod)\"\n proof (elim UnE)\n assume \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then have \"ObjectClass Imod o1 = fst r\"\n unfolding subtype_tuple_def\n by fastforce\n then have \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_tuple ` Type (Tm Imod)\"\n unfolding subtype_tuple_def\n using o1_class_is_type\n by simp\n then show ?thesis\n unfolding subtype_rel_altdef_def\n by simp\n next\n assume \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then have \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_conv proper proper ` (Inh (Tm Imod))\\<^sup>+\"\n unfolding subtype_conv_def tmod_combine_def tmod_contained_class_set_field_def\n by simp\n then show ?thesis\n unfolding subtype_rel_altdef_def\n by simp\n next\n assume \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass Imod o1), \\(fst r)) \\ subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n then have \"\\(ObjectClass Imod o1) \\[Tm Imod] \\(fst r)\"\n by (simp add: assms(1) instance_model.validity_type_model_consistent subtype_def subtype_rel_alt type_model.structure_inh_wellformed_classes)\n then have r_in_fields: \"r \\ Type_Model.fields (Tm Imod) (ObjectClass Imod o1)\"\n unfolding Type_Model.fields_def\n using r_field\n by fastforce\n have \"FieldValue (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (o1, r) = FieldValue Imod (o1, r)\"\n unfolding imod_combine_def imod_combine_field_value_def\n using r_not_field r_field o1_def\n by simp\n then have value_def: \"obj ob \\ set (contained_values (FieldValue Imod (o1, r)))\"\n using rule_object_containment.hyps(4)\n by simp\n have \"FieldValue Imod (o1, r) \\ Value Imod\"\n by (simp add: assms(1) instance_model.property_field_values_inside_domain o1_def r_field r_in_fields)\n then have \"set (contained_values (FieldValue Imod (o1, r))) \\ Value Imod\"\n unfolding Value_def\n using container_value_contained_values atom_values_contained_values_singleton\n by fastforce\n then have \"obj ob \\ Value Imod\"\n using value_def\n by blast\n then have \"obj ob \\ ProperClassValue Imod\"\n unfolding Value_def AtomValue_def ClassValue_def\n by simp\n then have \"ob \\ Object Imod\"\n using ProperClassValue.cases\n by blast\n then show ?thesis\n using ob_def existing_objects objects_unique\n by blast\n next\n assume o1_def: \"o1 \\ Object Imod\"\n then have \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = \n imod_combine_object_class Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1\"\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n then have ob_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = ObjectClass Imod o1\"\n unfolding imod_combine_object_class_def\n using existing_objects classes_valid\n by (simp add: imod_contained_class_set_field_def inf.commute o1_def)\n assume \"r \\ {(classtype, name)}\"\n then have r_def: \"r = (classtype, name)\"\n by simp\n then have r_cr: \"r \\ CR (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n using cr_def_part\n by simp\n have r_field: \"r \\ Field (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by (simp add: r_def)\n have r_not_field: \"r \\ Field (Tm Imod)\"\n using r_def new_field\n by simp\n have \"\\classtype \\ ProperClassType (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by (simp add: ProperClassType.rule_proper_classes)\n then have \"\\classtype \\ Type (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding Type_def NonContainerType_def ClassType_def\n by blast\n then have classtype_extend: \"\\classtype \\[Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)] \\classtype\"\n unfolding subtype_def\n by (simp add: subtype_rel.reflexivity)\n have \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1)\n \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))] \\classtype\"\n using rule_object_containment.hyps(3) r_def\n unfolding Type_Model.fields_def\n by blast\n then have \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_rel_altdef (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n unfolding subtype_def imod_contained_class_set_field_def imod_combine_def\n by (simp add: subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_valid)\n then have object_class_def: \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1) = \\classtype\"\n unfolding subtype_rel_altdef_def\n proof (elim UnE)\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_tuple_def\n by fastforce\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then have ob_extends_classtype: \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n unfolding subtype_conv_def\n by fastforce\n have \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n proof\n assume \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show \"False\"\n proof (cases)\n case base\n then show ?thesis\n unfolding tmod_contained_class_set_field_def tmod_combine_def\n using no_inh_classtype\n by simp\n next\n case (step c)\n then show ?thesis\n unfolding tmod_contained_class_set_field_def tmod_combine_def\n using no_inh_classtype\n by simp\n qed\n qed\n then show ?thesis\n using ob_extends_classtype\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n then have o1_class_def: \"ObjectClass Imod o1 = classtype\"\n by (simp add: ob_class_def)\n then have o1_in_objects: \"o1 \\ objects\"\n using all_objects o1_def\n by blast\n then have o1_def: \"o1 \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n unfolding imod_contained_class_set_field_def\n by simp\n then have \"ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1 = ObjectClass Imod o1\"\n unfolding imod_contained_class_set_field_def\n by (simp add: o1_class_def o1_in_objects)\n then have r_in_fields: \"r \\ Type_Model.fields (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)) \n (ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1)\"\n unfolding Type_Model.fields_def\n using classtype_extend o1_class_def r_def r_field\n by fastforce\n have \"FieldValue (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (o1, r) =\n FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (o1, r)\"\n unfolding imod_combine_def imod_combine_field_value_def\n using r_not_field r_field o1_def\n by simp\n then have \"obj ob \\ set (contained_values (FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (o1, r)))\"\n using rule_object_containment.hyps(4)\n by metis\n then show ?thesis\n by (simp add: o1_def object_containments.rule_object_containment r_cr r_in_fields)\n next\n assume o1_def: \"o1 \\ sets_to_set (set ` values ` objects)\"\n then have \"o1 \\ Object Imod\"\n using existing_objects objects_unique\n by auto\n then have ob_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = containedtype\"\n unfolding imod_combine_def imod_contained_class_set_field_def imod_combine_object_class_def\n using o1_def existing_objects\n by auto\n assume r_def: \"r \\ CR (Tm Imod)\"\n then have r_field: \"r \\ Field (Tm Imod)\"\n using containment_relations_are_fields\n by blast\n have \"containedtype \\ Class (Tm Imod)\"\n using existing_classes\n by blast\n then have \"\\containedtype \\ ProperClassType (Tm Imod)\"\n by (simp add: ProperClassType.rule_proper_classes)\n then have object_class_is_type: \"\\containedtype \\ Type (Tm Imod)\"\n unfolding Type_def NonContainerType_def ClassType_def\n by blast\n have no_extend_imod: \"\\\\containedtype \\[Tm Imod] \\(fst r)\"\n proof\n assume \"\\containedtype \\[Tm Imod] \\(fst r)\"\n then have \"r \\ Type_Model.fields (Tm Imod) containedtype\"\n unfolding Type_Model.fields_def\n using r_field\n by fastforce\n then show \"False\"\n by (simp add: no_fields_containedtype)\n qed\n have \"\\\\containedtype \\[tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)] \\(fst r)\"\n proof\n assume \"\\containedtype \\[tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)] \\(fst r)\"\n then have \"(\\containedtype, \\(fst r)) \\ subtype_rel_altdef (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n unfolding subtype_def imod_contained_class_set_field_def imod_combine_def\n by (simp add: subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_valid)\n then show \"False\"\n unfolding subtype_rel_altdef_def\n proof (elim UnE)\n assume \"(\\containedtype, \\(fst r)) \\ subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then have \"\\containedtype = \\(fst r)\"\n by (simp add: image_iff subtype_tuple_def)\n then have \"\\containedtype \\[Tm Imod] \\(fst r)\"\n using object_class_is_type subtype_def subtype_rel.reflexivity\n by blast\n then show ?thesis\n using no_extend_imod\n by blast\n next\n assume \"(\\containedtype, \\(fst r)) \\ subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\containedtype, \\(fst r)) \\ subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then have \"(\\containedtype, \\(fst r)) \\ subtype_conv proper proper ` (Inh (Tm Imod))\\<^sup>+\"\n unfolding tmod_combine_def tmod_contained_class_set_field_def\n by simp\n then have \"(\\containedtype, \\(fst r)) \\ subtype_rel_altdef (Tm Imod)\"\n unfolding subtype_rel_altdef_def\n by blast\n then have \"\\containedtype \\[Tm Imod] \\(fst r)\"\n by (simp add: assms(1) instance_model.validity_type_model_consistent subtype_def subtype_rel_alt type_model.structure_inh_wellformed_classes)\n then show ?thesis\n using no_extend_imod\n by blast\n next\n assume \"(\\containedtype, \\(fst r)) \\ subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\containedtype, \\(fst r)) \\ subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n qed\n then have \"\\\\containedtype \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))] \\(fst r)\"\n unfolding imod_contained_class_set_field_def imod_combine_def\n by simp\n then have \"r \\ Type_Model.fields (Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))) containedtype\"\n unfolding Type_Model.fields_def\n by fastforce\n then show ?thesis\n using rule_object_containment.hyps(3) ob_class_def\n by simp\n next\n assume o1_def: \"o1 \\ sets_to_set (set ` values ` objects)\"\n then have \"o1 \\ Object Imod\"\n using existing_objects objects_unique\n by auto\n then have ob_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = containedtype\"\n unfolding imod_combine_def imod_contained_class_set_field_def imod_combine_object_class_def\n using o1_def existing_objects\n by auto\n assume \"r \\ {(classtype, name)}\"\n then have r_def: \"r = (classtype, name)\"\n by simp\n then have \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1)\n \\[Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))] \\classtype\"\n using rule_object_containment.hyps(3)\n unfolding Type_Model.fields_def\n by blast\n then have \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_rel_altdef (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n unfolding subtype_def imod_contained_class_set_field_def imod_combine_def\n by (simp add: subtype_rel_alt type_model.structure_inh_wellformed_classes type_model_valid)\n then have object_class_def: \"\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1) = \\classtype\"\n unfolding subtype_rel_altdef_def\n proof (elim UnE)\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_tuple ` Type (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_tuple_def\n by fastforce\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv nullable nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv proper proper ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then have ob_extends_classtype: \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n unfolding subtype_conv_def\n by fastforce\n have \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n proof\n assume \"(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1, classtype) \\ \n (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show \"False\"\n proof (cases)\n case base\n then show ?thesis\n unfolding tmod_contained_class_set_field_def tmod_combine_def\n using no_inh_classtype\n by simp\n next\n case (step c)\n then show ?thesis\n unfolding tmod_contained_class_set_field_def tmod_combine_def\n using no_inh_classtype\n by simp\n qed\n qed\n then show ?thesis\n using ob_extends_classtype\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv proper nullable ` subtype_tuple ` Class (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul))\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n next\n assume \"(\\(ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1), \\classtype) \\ \n subtype_conv proper nullable ` (Inh (tmod_combine (Tm Imod) (tmod_contained_class_set_field classtype name containedtype mul)))\\<^sup>+\"\n then show ?thesis\n unfolding subtype_conv_def\n by blast\n qed\n then show ?thesis\n using ob_class_def classtype_containedtype_neq\n by simp\n qed\n qed\n qed\n qed\n qed\n next\n show \"object_containments (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob \\ \n object_containments (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob\"\n proof\n fix x\n assume \"x \\ object_containments (imod_contained_class_set_field classtype name containedtype mul objects obids values) ob\"\n then show \"x \\ object_containments (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) ob\"\n proof (induct x)\n case (Pair a d)\n then show ?case\n proof (induct a)\n case (fields a b c)\n then show ?case\n proof (induct)\n case (rule_object_containment o1 r)\n then have \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = \n imod_combine_object_class Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1\"\n unfolding imod_combine_def imod_contained_class_set_field_def\n by simp\n then have o1_class_def: \"ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1 = \n ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1\"\n using objects_unique existing_objects classes_valid rule_object_containment.hyps(1)\n unfolding imod_combine_object_class_def imod_contained_class_set_field_def\n by fastforce\n have r_field: \"r \\ Field (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n using rule_object_containment.hyps(2) containment_relations_are_fields\n by blast\n then have r_not_field: \"r \\ Field (Tm Imod)\"\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n using new_field\n by fastforce\n have \"o1 \\ Object Imod \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\n using rule_object_containment.hyps(1)\n by blast\n then have o1_def: \"o1 \\ Object (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n unfolding imod_combine_def\n by simp\n have \"r = (classtype, name)\"\n using cr_def_part rule_object_containment.hyps(2)\n by simp\n then have \"r \\ CR (Tm Imod) \\ {(classtype, name)}\"\n by simp\n then have r_def: \"r \\ CR (Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)))\"\n by (simp add: cr_def)\n have \"r \\ Type_Model.fields (tmod_combine (Tm Imod) (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values))) \n (ObjectClass (imod_contained_class_set_field classtype name containedtype mul objects obids values) o1)\"\n using rule_object_containment.hyps(3) tmod_combine_subtype_subset_tmod2\n unfolding Type_Model.fields_def tmod_combine_def\n by fastforce\n then have \"r \\ Type_Model.fields (tmod_combine (Tm Imod) (Tm (imod_contained_class_set_field classtype name containedtype mul objects obids values)))\n (ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1)\"\n by (simp add: o1_class_def)\n then have r_in_fields: \"r \\ Type_Model.fields (Tm (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)))\n (ObjectClass (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) o1)\"\n unfolding imod_combine_def\n by simp\n have \"FieldValue (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (o1, r) = \n FieldValue (imod_contained_class_set_field classtype name containedtype mul objects obids values) (o1, r)\"\n unfolding imod_combine_def imod_combine_field_value_def\n using r_not_field r_field rule_object_containment.hyps(1)\n by simp\n then have \"obj ob \\ set (contained_values (FieldValue (imod_combine Imod (imod_contained_class_set_field classtype name containedtype mul objects obids values)) (o1, r)))\"\n using rule_object_containment.hyps(4)\n by simp\n then show ?case\n by (simp add: o1_def object_containments.rule_object_containment r_def r_in_fields)\n qed\n qed\n qed\n qed\n qed\n have \"imod_contained_class_set_field classtype name containedtype mul objects obids values \\ containment (classtype, name)\"\n using instance_model_correct instance_model.validity_properties_satisfied\n unfolding imod_contained_class_set_field_def tmod_contained_class_set_field_def\n by fastforce\n then show ?thesis\n using property_satisfaction_containment_rev ob_altdef containments_eq\n by metis\n qed\nqed (simp_all add: assms imod_contained_class_set_field_def tmod_contained_class_set_field_def)\n\n\n\nsection \"Encoding of a class-typed field as edge type in GROOVE\"\n\ninductive_set values_to_pairs :: \"'a set \\ ('a \\ 'a list) \\ ('a \\ 'a) set\"\n for A :: \"'a set\" and f :: \"'a \\ 'a list\"\n where\n rule_member: \"\\x y. x \\ A \\ y \\ set (f x) \\ (x, y) \\ values_to_pairs A f\"\n\nlemma values_to_pairs_prod: \"(x, y) \\ values_to_pairs A f \\ x \\ A \\ y \\ set (f x)\"\n using values_to_pairs.cases\n by metis\n\nlemma values_to_pairs_fst: \"x \\ values_to_pairs A f \\ fst x \\ A\"\n using prod.collapse values_to_pairs.cases\n by metis\n\nlemma values_to_pairs_snd: \"x \\ values_to_pairs A f \\ snd x \\ sets_to_set (set ` f ` A)\"\nproof-\n fix x\n assume \"x \\ values_to_pairs A f\"\n then show \"snd x \\ sets_to_set (set ` f ` A)\"\n proof (induct x)\n case (Pair a b)\n then show ?case\n proof (induct)\n case (rule_member x y)\n then show ?case\n using sets_to_set.simps\n by fastforce\n qed\n qed\nqed\n\nlemma values_to_pairs_select: \"x \\ A \\ snd ` {z \\ values_to_pairs A f. fst z = x} = set (f x)\"\nproof\n show \"snd ` {z \\ values_to_pairs A f. fst z = x} \\ set (f x)\"\n proof\n fix y\n assume \"y \\ snd ` {z \\ values_to_pairs A f. fst z = x}\"\n then show \"y \\ set (f x)\"\n proof (elim imageE)\n fix z\n assume z_def: \"z \\ {z \\ values_to_pairs A f. fst z = x}\"\n assume y_def: \"y = snd z\"\n show \"y \\ set (f x)\"\n using z_def\n proof\n assume z_def: \"z \\ values_to_pairs A f \\ fst z = x\"\n then have snd_z_def: \"fst z = x\"\n by simp\n have \"z \\ values_to_pairs A f\"\n using z_def\n by simp\n then show \"y \\ set (f x)\"\n using y_def snd_z_def\n proof (induct z)\n case (Pair a b)\n then show ?case\n proof (induct)\n case (rule_member a b)\n then show ?case\n by simp\n qed\n qed\n qed\n qed\n qed\nnext\n assume x_in_A: \"x \\ A\"\n show \"set (f x) \\ snd ` {z \\ values_to_pairs A f. fst z = x}\"\n proof\n fix y\n assume \"y \\ set (f x)\"\n then show \"y \\ snd ` {z \\ values_to_pairs A f. fst z = x}\"\n using x_in_A\n by (simp add: image_iff values_to_pairs.simps)\n qed\nqed\n\ndefinition ig_contained_class_set_field_as_edge_type :: \"'t Id \\ 't \\ 't Id \\ multiplicity \\ 'o set \\ ('o \\ 't) \\ ('o \\ 'o list) \\ ('o, 't list, 't) instance_graph\" where\n \"ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values = \\\n TG = tg_contained_class_set_field_as_edge_type classtype name containedtype mul,\n Id = obids ` objects \\ obids ` sets_to_set (set ` values ` objects),\n N = typed (type (id_to_list classtype)) ` objects \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects),\n E = (\\x. (typed (type (id_to_list classtype)) (fst x), (type (id_to_list classtype), LabDef.edge [name], type (id_to_list containedtype)), typed (type (id_to_list containedtype)) (snd x))) ` values_to_pairs objects values,\n ident = (\\x. if x \\ obids ` objects then typed (type (id_to_list classtype)) (THE y. obids y = x) else \n if x \\ obids ` sets_to_set (set ` values ` objects) then typed (type (id_to_list containedtype)) (THE y. obids y = x) else undefined)\n \\\"\n\nlemma ig_contained_class_set_field_as_edge_type_correct:\n assumes valid_mul: \"multiplicity mul\"\n assumes classtype_containedtype_neq: \"classtype \\ containedtype\"\n assumes objects_unique: \"objects \\ sets_to_set (set ` values ` objects) = {}\"\n assumes unique_ids: \"\\o1 o2. o1 \\ objects \\ sets_to_set (set ` values ` objects) \\ obids o1 = obids o2 \\ o1 = o2\"\n assumes unique_sets: \"\\ob. ob \\ objects \\ distinct (values ob)\"\n assumes unique_across_sets: \"\\o1 o2. o1 \\ objects \\ o2 \\ objects \\ o1 \\ o2 \\ set (values o1) \\ set (values o2) = {}\"\n assumes valid_sets: \"\\ob. ob \\ objects \\ length (values ob) in mul\"\n shows \"instance_graph (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\nproof (intro instance_graph.intro)\n fix n\n assume \"n \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n then have \"n \\ typed (type (id_to_list classtype)) ` objects \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n then have type_and_node_def: \"type\\<^sub>n n \\ NT (tg_contained_class_set_field_as_edge_type classtype name containedtype mul) \\ n \\ Node\"\n proof (elim UnE)\n assume \"n \\ typed (type (id_to_list classtype)) ` objects\"\n then show \"type\\<^sub>n n \\ NT (tg_contained_class_set_field_as_edge_type classtype name containedtype mul) \\ n \\ Node\"\n proof (intro conjI)\n assume \"n \\ typed (type (id_to_list classtype)) ` objects\"\n then show \"type\\<^sub>n n \\ NT (tg_contained_class_set_field_as_edge_type classtype name containedtype mul)\"\n unfolding tg_contained_class_set_field_as_edge_type_def\n by fastforce\n next\n assume \"n \\ typed (type (id_to_list classtype)) ` objects\"\n then show \"n \\ Node\"\n unfolding Node_def\n using Lab\\<^sub>t.rule_type_labels Node\\<^sub>t.rule_typed_nodes\n by fastforce\n qed\n next\n assume \"n \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n then show \"type\\<^sub>n n \\ NT (tg_contained_class_set_field_as_edge_type classtype name containedtype mul) \\ n \\ Node\"\n proof (intro conjI)\n assume \"n \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n then show \"type\\<^sub>n n \\ NT (tg_contained_class_set_field_as_edge_type classtype name containedtype mul)\"\n unfolding tg_contained_class_set_field_as_edge_type_def\n by fastforce\n next\n assume \"n \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n then show \"n \\ Node\"\n unfolding Node_def\n using Lab\\<^sub>t.rule_type_labels Node\\<^sub>t.rule_typed_nodes\n by fastforce\n qed\n qed\n then show \"type\\<^sub>n n \\ NT (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n show \"n \\ Node\"\n by (simp add: type_and_node_def)\nnext\n fix s l t\n assume \"(s, l, t) \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n then have edge_def: \"(s, l, t) \\ (\\x. (typed (type (id_to_list classtype)) (fst x), \n (type (id_to_list classtype), LabDef.edge [name], type (id_to_list containedtype)), \n typed (type (id_to_list containedtype)) (snd x))) ` values_to_pairs objects values\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n show \"s \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) \\ \n l \\ ET (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)) \\ \n t \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n proof (intro conjI)\n have \"s \\ typed (type (id_to_list classtype)) ` fst ` values_to_pairs objects values\"\n using edge_def\n by blast\n then have \"s \\ typed (type (id_to_list classtype)) ` objects\"\n using values_to_pairs_fst\n by blast\n then show \"s \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n using edge_def\n by simp\n next\n have \"l = (type (id_to_list classtype), LabDef.edge [name], type (id_to_list containedtype))\"\n using edge_def\n by blast\n then show \"l \\ ET (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n by simp\n next\n have \"t \\ typed (type (id_to_list containedtype)) ` snd ` values_to_pairs objects values\"\n using edge_def\n by blast\n then have \"t \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n using values_to_pairs_snd\n by blast\n then show \"t \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n using edge_def\n by simp\n qed\nnext\n fix i\n assume \"i \\ Id (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n then have i_in_id: \"i \\ obids ` objects \\ obids ` sets_to_set (set ` values ` objects)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n then show \"ident (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) i \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) \\ \n type\\<^sub>n (ident (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) i) \\ Lab\\<^sub>t\"\n proof (elim UnE)\n assume i_in_id: \"i \\ obids ` objects\"\n then show ?thesis\n proof (intro conjI)\n assume \"i \\ obids ` objects\"\n then have \"(THE y. obids y = i) \\ objects\"\n proof\n fix x\n assume i_def: \"i = obids x\"\n assume x_is_object: \"x \\ objects\"\n have \"(THE y. obids y = obids x) \\ objects\"\n proof (rule the1I2)\n show \"\\!y. obids y = obids x\"\n using Un_iff unique_ids x_is_object\n by metis\n next\n fix y\n assume \"obids y = obids x\"\n then show \"y \\ objects\"\n using Un_iff unique_ids x_is_object\n by metis\n qed\n then show \"(THE y. obids y = i) \\ objects\"\n by (simp add: i_def)\n qed\n then have \"typed (type (id_to_list classtype)) (THE y. obids y = i) \\ typed (type (id_to_list classtype)) ` objects\"\n by simp\n then show \"ident (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) i \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n using i_in_id\n by simp\n next\n have \"type\\<^sub>n (typed (type (id_to_list classtype)) (THE y. obids y = i)) \\ Lab\\<^sub>t\"\n by (simp add: Lab\\<^sub>t.rule_type_labels)\n then show \"type\\<^sub>n (ident (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) i) \\ Lab\\<^sub>t\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n using i_in_id\n by simp\n qed\n next\n assume i_in_id: \"i \\ obids ` sets_to_set (set ` values ` objects)\"\n then show ?thesis\n proof (intro conjI)\n assume \"i \\ obids ` sets_to_set (set ` values ` objects)\"\n then have \"(THE y. obids y = i) \\ sets_to_set (set ` values ` objects)\"\n proof\n fix x\n assume i_def: \"i = obids x\"\n assume x_is_object: \"x \\ sets_to_set (set ` values ` objects)\"\n have \"(THE y. obids y = obids x) \\ sets_to_set (set ` values ` objects)\"\n proof (rule the1I2)\n show \"\\!y. obids y = obids x\"\n using Un_iff unique_ids x_is_object\n by metis\n next\n fix y\n assume \"obids y = obids x\"\n then show \"y \\ sets_to_set (set ` values ` objects)\"\n using Un_iff unique_ids x_is_object\n by metis\n qed\n then show \"(THE y. obids y = i) \\ sets_to_set (set ` values ` objects)\"\n by (simp add: i_def)\n qed\n then have \"typed (type (id_to_list containedtype)) (THE y. obids y = i) \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n by simp\n then show \"ident (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) i \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n using i_in_id objects_unique unique_ids\n by auto\n next\n have \"type\\<^sub>n (typed (type (id_to_list classtype)) (THE y. obids y = i)) \\ Lab\\<^sub>t \\ type\\<^sub>n (typed (type (id_to_list containedtype)) (THE y. obids y = i)) \\ Lab\\<^sub>t\"\n by (simp add: Lab\\<^sub>t.rule_type_labels)\n then show \"type\\<^sub>n (ident (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) i) \\ Lab\\<^sub>t\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n using i_in_id\n by simp\n qed\n qed\nnext\n show \"type_graph (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n using tg_contained_class_set_field_as_edge_type_correct valid_mul\n by simp\nnext\n fix e\n assume \"e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n then have e_def: \"e \\ (\\x. (typed (type (id_to_list classtype)) (fst x), \n (type (id_to_list classtype), LabDef.edge [name], type (id_to_list containedtype)), \n typed (type (id_to_list containedtype)) (snd x))) ` values_to_pairs objects values\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n have type_n_def: \"type\\<^sub>n (src e) = type (id_to_list classtype)\"\n using e_def\n by fastforce\n have type_e_def: \"src (type\\<^sub>e e) = type (id_to_list classtype)\"\n using e_def\n by fastforce\n have \"(type\\<^sub>n (src e), src (type\\<^sub>e e)) \\ {(type (id_to_list classtype), type (id_to_list classtype)), (type (id_to_list containedtype), type (id_to_list containedtype))}\"\n using type_n_def type_e_def\n by blast\n then show \"(type\\<^sub>n (src e), src (type\\<^sub>e e)) \\ inh (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n by simp\nnext\n fix e\n assume \"e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n then have e_def: \"e \\ (\\x. (typed (type (id_to_list classtype)) (fst x), \n (type (id_to_list classtype), LabDef.edge [name], type (id_to_list containedtype)), \n typed (type (id_to_list containedtype)) (snd x))) ` values_to_pairs objects values\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n have type_n_def: \"type\\<^sub>n (tgt e) = type (id_to_list containedtype)\"\n using e_def\n by fastforce\n have type_e_def: \"tgt (type\\<^sub>e e) = type (id_to_list containedtype)\"\n using e_def\n by fastforce\n have \"(type\\<^sub>n (tgt e), tgt (type\\<^sub>e e)) \\ {(type (id_to_list classtype), type (id_to_list classtype)), (type (id_to_list containedtype), type (id_to_list containedtype))}\"\n using type_n_def type_e_def\n by blast\n then show \"(type\\<^sub>n (tgt e), tgt (type\\<^sub>e e)) \\ inh (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n by simp\nnext\n have type_neq: \"type (id_to_list classtype) \\ type (id_to_list containedtype)\"\n using classtype_containedtype_neq LabDef.inject(1) id_to_list_inverse\n by metis\n fix et n\n assume \"et \\ ET (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n then have et_def: \"et = (type (id_to_list classtype), LabDef.edge [name], type (id_to_list containedtype))\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n by simp\n then have src_et_def: \"src et = type (id_to_list classtype)\"\n by simp\n have mult_et_def: \"m_out (mult (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)) et) = mul\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n by (simp add: et_def)\n assume \"n \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n then have n_def: \"n \\ typed (type (id_to_list classtype)) ` objects \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n assume \"(type\\<^sub>n n, src et) \\ inh (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n then have \"(type\\<^sub>n n, src et) \\ {(type (id_to_list classtype), type (id_to_list classtype)), (type (id_to_list containedtype), type (id_to_list containedtype))}\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n by simp\n then have type_n_def: \"type\\<^sub>n n = type (id_to_list classtype)\"\n using src_et_def\n by fastforce\n then have n_def: \"n \\ typed (type (id_to_list classtype)) ` objects\"\n using n_def type_neq\n by fastforce\n then have edges_def: \"{e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). src e = n \\ type\\<^sub>e e = et} = \n (\\x. (typed (type (id_to_list classtype)) (nodeId n), (type (id_to_list classtype), LabDef.edge [name], type (id_to_list containedtype)), typed (type (id_to_list containedtype)) x)) ` set (values (nodeId n))\"\n proof (elim imageE)\n fix x\n assume x_def: \"x \\ objects\"\n assume n_def: \"n = typed (LabDef.type (id_to_list classtype)) x\"\n then have nodeId_n: \"nodeId n = x\"\n by simp\n show ?thesis\n proof\n show \"{e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). src e = n \\ type\\<^sub>e e = et}\n \\ (\\x. (typed (LabDef.type (id_to_list classtype)) (nodeId n), \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) x)) ` set (values (nodeId n))\"\n proof\n fix y\n assume \"y \\ {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). src e = n \\ type\\<^sub>e e = et}\"\n then show \"y \\ (\\x. (typed (LabDef.type (id_to_list classtype)) (nodeId n), \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) x)) ` set (values (nodeId n))\"\n proof\n assume \"y \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) \\ src y = n \\ type\\<^sub>e y = et\"\n then have \"y \\ (\\z. (typed (LabDef.type (id_to_list classtype)) (fst z), \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) (snd z))) ` {z \\ values_to_pairs objects values. fst z = x}\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n using n_def\n by fastforce\n then have \"y \\ (\\z. (typed (LabDef.type (id_to_list classtype)) x, \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) z)) ` snd ` {z \\ values_to_pairs objects values. fst z = x}\"\n by fastforce\n then have \"y \\ (\\z. (typed (LabDef.type (id_to_list classtype)) x, \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) z)) ` set (values x)\"\n by (simp add: values_to_pairs_select x_def)\n then show \"y \\ (\\x. (typed (LabDef.type (id_to_list classtype)) (nodeId n), \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) x)) ` set (values (nodeId n))\"\n by (simp add: nodeId_n)\n qed\n qed\n next\n show \"(\\x. (typed (LabDef.type (id_to_list classtype)) (nodeId n), \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) x)) ` set (values (nodeId n))\n \\ {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). src e = n \\ type\\<^sub>e e = et}\"\n proof\n fix y\n assume \"y \\ (\\x. (typed (LabDef.type (id_to_list classtype)) (nodeId n), \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) x)) ` set (values (nodeId n))\"\n then show \"y \\ {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). src e = n \\ type\\<^sub>e e = et}\"\n proof (elim imageE)\n fix z\n assume \"y = (typed (LabDef.type (id_to_list classtype)) (nodeId n), \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) z)\"\n then have y_def: \"y = (typed (LabDef.type (id_to_list classtype)) x, \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) z)\"\n using nodeId_n\n by blast\n assume \"z \\ set (values (nodeId n))\"\n then have \"z \\ set (values x)\"\n by (simp add: nodeId_n)\n then have z_def: \"z \\ snd ` {z \\ values_to_pairs objects values. fst z = x}\"\n by (simp add: values_to_pairs_select x_def)\n show ?thesis\n proof\n show \"y \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) \\ src y = n \\ type\\<^sub>e y = et\"\n proof (intro conjI)\n have \"y \\ (\\z. (typed (LabDef.type (id_to_list classtype)) (fst z), \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) (snd z))) ` {z \\ values_to_pairs objects values. fst z = x}\"\n using y_def z_def\n by blast\n then show \"y \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by auto\n next\n show \"src y = n\"\n using y_def n_def\n by simp\n next\n show \"type\\<^sub>e y = et\"\n using y_def et_def\n by simp\n qed\n qed\n qed\n qed\n qed\n qed\n have \"length (values (nodeId n)) in mul\"\n using n_def valid_sets\n by fastforce\n then have card_values_def: \"card (set (values (nodeId n))) in mul\"\n using unique_sets n_def distinct_card\n by fastforce\n have \"inj_on (\\x. (typed (LabDef.type (id_to_list classtype)) (nodeId n), \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) x)) (set (values (nodeId n)))\"\n unfolding inj_on_def\n by blast\n then have \"card ((\\x. (typed (LabDef.type (id_to_list classtype)) (nodeId n), \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) x)) ` set (values (nodeId n))) in mul\"\n using card_image card_values_def\n by fastforce\n then show \"card {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). src e = n \\ type\\<^sub>e e = et} in \n m_out (mult (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)) et)\"\n using edges_def mult_et_def\n by simp\nnext\n have type_neq: \"type (id_to_list classtype) \\ type (id_to_list containedtype)\"\n using classtype_containedtype_neq LabDef.inject(1) id_to_list_inverse\n by metis\n fix et n\n assume \"et \\ ET (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n then have et_def: \"et = (type (id_to_list classtype), LabDef.edge [name], type (id_to_list containedtype))\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n by simp\n then have tgt_et_def: \"tgt et = type (id_to_list containedtype)\"\n by simp\n have mult_et_def: \"m_in (mult (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)) et) = \\<^bold>0..\\<^bold>1\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n by (simp add: et_def)\n assume \"n \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n then have n_def: \"n \\ typed (type (id_to_list classtype)) ` objects \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n assume \"(type\\<^sub>n n, tgt et) \\ inh (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n then have \"(type\\<^sub>n n, tgt et) \\ {(type (id_to_list classtype), type (id_to_list classtype)), (type (id_to_list containedtype), type (id_to_list containedtype))}\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n by simp\n then have type_n_def: \"type\\<^sub>n n = type (id_to_list containedtype)\"\n using tgt_et_def\n by fastforce\n then have n_def: \"n \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n using n_def type_neq\n by fastforce\n then have \"card {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et} \\ 1\"\n proof (elim imageE)\n fix x\n assume n_def: \"n = typed (LabDef.type (id_to_list containedtype)) x\"\n assume x_def: \"x \\ sets_to_set (set ` values ` objects)\"\n then show ?thesis\n using n_def\n proof (induct)\n case (rule_member y z)\n then show ?case\n proof (elim imageE)\n fix i j\n assume n_def: \"n = typed (LabDef.type (id_to_list containedtype)) z\"\n assume j_def: \"j \\ objects\"\n assume i_def: \"i = values j\"\n assume \"y = set i\"\n then have y_def: \"y = set (values j)\"\n by (simp add: i_def)\n assume \"z \\ y\"\n then have z_def: \"z \\ set (values j)\"\n by (simp add: y_def)\n have \"{e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et} \\ \n {(typed (LabDef.type (id_to_list classtype)) j, \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) z)}\"\n proof\n fix k\n assume \"k \\ {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et}\"\n then show \"k \\ {(typed (LabDef.type (id_to_list classtype)) j, \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) z)}\"\n proof\n assume \"k \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) \\ tgt k = n \\ type\\<^sub>e k = et\"\n then have \"k = (\\x. (typed (LabDef.type (id_to_list classtype)) (fst x), \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) (snd x))) (j, z)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n using unique_across_sets j_def z_def n_def values_to_pairs_prod\n by fastforce\n then have \"k = (typed (LabDef.type (id_to_list classtype)) j, \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) z)\"\n by simp\n then show \"k \\ {(typed (LabDef.type (id_to_list classtype)) j, \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) z)}\"\n by blast\n qed\n qed\n then have \"{e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et} = {} \\\n {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et} =\n {(typed (LabDef.type (id_to_list classtype)) j, \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) z)}\"\n by blast\n then show ?thesis\n proof (elim disjE)\n assume \"{e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et} = {}\"\n then have \"card {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et} = 0\"\n using card_empty\n by metis\n then show ?thesis\n by simp\n next\n assume \"{e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et} =\n {(typed (LabDef.type (id_to_list classtype)) j, \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) z)}\"\n then show ?thesis\n by simp\n qed\n qed\n qed\n qed\n then show \"card {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et} in \n m_in (mult (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)) et)\"\n using mult_et_def\n unfolding within_multiplicity_def\n by simp\nnext\n have type_neq: \"type (id_to_list classtype) \\ type (id_to_list containedtype)\"\n using classtype_containedtype_neq LabDef.inject(1) id_to_list_inverse\n by metis\n fix n\n assume \"n \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n then have n_def: \"n \\ typed (type (id_to_list classtype)) ` objects \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n then show \"card {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))} \\ 1\"\n proof (elim UnE)\n assume n_def: \"n \\ typed (LabDef.type (id_to_list classtype)) ` objects\"\n then show ?thesis\n proof\n fix x\n assume n_def: \"n = typed (LabDef.type (id_to_list classtype)) x\"\n assume x_def: \"x \\ objects\"\n have \"{e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))} = {}\"\n proof\n show \"{e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))} \\ {}\"\n proof\n fix y\n assume \"y \\ {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))}\"\n then show \"y \\ {}\"\n proof\n assume \"y \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) \\ tgt y = n \\ \n type\\<^sub>e y \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n then show \"y \\ {}\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n using n_def type_neq\n by fastforce\n qed\n qed\n next\n show \"{} \\ {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))}\"\n by simp\n qed\n then have \"card {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))} = 0\"\n using card_empty\n by metis\n then show ?thesis\n by simp\n qed\n next\n assume n_def: \"n \\ typed (LabDef.type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n then show ?thesis\n proof (elim imageE)\n fix x\n assume n_def: \"n = typed (LabDef.type (id_to_list containedtype)) x\"\n assume x_def: \"x \\ sets_to_set (set ` values ` objects)\"\n then show ?thesis\n using n_def\n proof (induct)\n case (rule_member y z)\n then show ?case\n proof (elim imageE)\n fix i j\n assume n_def: \"n = typed (LabDef.type (id_to_list containedtype)) z\"\n assume j_def: \"j \\ objects\"\n assume i_def: \"i = values j\"\n assume \"y = set i\"\n then have y_def: \"y = set (values j)\"\n by (simp add: i_def)\n assume \"z \\ y\"\n then have z_def: \"z \\ set (values j)\"\n by (simp add: y_def)\n have \"{e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))} \\ \n {(typed (LabDef.type (id_to_list classtype)) j, \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) z)}\"\n proof\n fix k\n assume \"k \\ {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))}\"\n then show \"k \\ {(typed (LabDef.type (id_to_list classtype)) j, \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) z)}\"\n proof\n assume \"k \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) \\ tgt k = n \\ \n type\\<^sub>e k \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n then have \"k = (\\x. (typed (LabDef.type (id_to_list classtype)) (fst x), \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) (snd x))) (j, z)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n using unique_across_sets j_def z_def n_def values_to_pairs_prod\n by fastforce\n then have \"k = (typed (LabDef.type (id_to_list classtype)) j, \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) z)\"\n by simp\n then show \"k \\ {(typed (LabDef.type (id_to_list classtype)) j, \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) z)}\"\n by blast\n qed\n qed\n then have \"{e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))} = {} \\\n {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))} =\n {(typed (LabDef.type (id_to_list classtype)) j, \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) z)}\"\n by blast\n then show ?thesis\n proof (elim disjE)\n assume \"{e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))} = {}\"\n then have \"card {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))} = 0\"\n using card_empty\n by metis\n then show ?thesis\n by simp\n next\n assume \"{e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))} =\n {(typed (LabDef.type (id_to_list classtype)) j, \n (LabDef.type (id_to_list classtype), LabDef.edge [name], LabDef.type (id_to_list containedtype)), \n typed (LabDef.type (id_to_list containedtype)) z)}\"\n then show ?thesis\n by simp\n qed\n qed\n qed\n qed\n qed\nnext\n fix p\n show \"\\pre_digraph.cycle (instance_graph_containment_proj (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)) p\"\n proof (intro validity_containmentI)\n fix e\n assume \"e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n then have edge_def: \"e \\ (\\x. (typed (type (id_to_list classtype)) (fst x), \n (type (id_to_list classtype), LabDef.edge [name], type (id_to_list containedtype)), \n typed (type (id_to_list containedtype)) (snd x))) ` values_to_pairs objects values\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n show \"src e \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) \\ \n tgt e \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n proof (intro conjI)\n have \"src e \\ typed (type (id_to_list classtype)) ` fst ` values_to_pairs objects values\"\n using edge_def\n by force\n then have \"src e \\ typed (type (id_to_list classtype)) ` objects\"\n using values_to_pairs_fst\n by blast\n then show \"src e \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n using edge_def\n by simp\n next\n have \"tgt e \\ typed (type (id_to_list containedtype)) ` snd ` values_to_pairs objects values\"\n using edge_def\n by force\n then have \"tgt e \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n using values_to_pairs_snd\n by blast\n then show \"tgt e \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n using edge_def\n by simp\n qed\n next\n have type_neq: \"type (id_to_list classtype) \\ type (id_to_list containedtype)\"\n using classtype_containedtype_neq LabDef.inject(1) id_to_list_inverse\n by metis\n then have nodes_neq: \"typed (type (id_to_list classtype)) ` objects \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects) = {}\"\n by blast\n have containments_rel_def: \"\\s t. (s, t) \\ edge_to_tuple ` {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))} \\\n s \\ typed (type (id_to_list classtype)) ` objects \\ t \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n proof (elim imageE)\n fix s t e\n assume e_def: \"e \\ {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))}\"\n assume s_t_def: \"(s, t) = edge_to_tuple e\"\n show \"s \\ typed (LabDef.type (id_to_list classtype)) ` objects \\ t \\ typed (LabDef.type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n using e_def\n proof\n assume \"e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) \\ \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n then have edge_def: \"e \\ (\\x. (typed (type (id_to_list classtype)) (fst x), \n (type (id_to_list classtype), LabDef.edge [name], type (id_to_list containedtype)), \n typed (type (id_to_list containedtype)) (snd x))) ` values_to_pairs objects values\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n have \"src e \\ typed (type (id_to_list classtype)) ` fst ` values_to_pairs objects values\"\n using edge_def\n by force\n then have \"src e \\ typed (type (id_to_list classtype)) ` objects\"\n using values_to_pairs_fst\n by blast\n then have s_def: \"s \\ typed (type (id_to_list classtype)) ` objects\"\n using s_t_def\n unfolding edge_to_tuple_def\n by blast\n have \"tgt e \\ typed (type (id_to_list containedtype)) ` snd ` values_to_pairs objects values\"\n using edge_def\n by force\n then have tgt_e_def: \"tgt e \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n using values_to_pairs_snd\n by blast\n then have t_def: \"t \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n using s_t_def\n unfolding edge_to_tuple_def\n by blast\n show \"s \\ typed (LabDef.type (id_to_list classtype)) ` objects \\ t \\ typed (LabDef.type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n using s_def t_def\n by blast\n qed\n qed\n have \"\\x. (x, x) \\ (edge_to_tuple ` {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))})\\<^sup>+\"\n proof\n fix x\n assume \"(x, x) \\ (edge_to_tuple ` {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))})\\<^sup>+\"\n then show \"False\"\n proof (cases)\n case base\n then show ?thesis\n using containments_rel_def nodes_neq\n by blast\n next\n case (step c)\n have c_def: \"c \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n using step(1)\n proof (induct)\n case (base y)\n then show ?case\n using containments_rel_def\n by blast\n next\n case (step y z)\n then show ?case\n using containments_rel_def\n by blast\n qed\n have \"c \\ typed (type (id_to_list classtype)) ` objects\"\n using step(2) containments_rel_def\n by blast\n then show ?thesis\n using c_def nodes_neq\n by blast\n qed\n qed\n then show \"irrefl ((edge_to_tuple ` {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))})\\<^sup>+)\"\n unfolding irrefl_def\n by blast\n qed\nqed (simp_all add: assms ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def)\n\nlemma ig_contained_class_set_field_as_edge_type_combine_correct:\n assumes \"instance_graph IG\"\n assumes existing_node_types: \"{type (id_to_list classtype), type (id_to_list containedtype)} \\ NT (TG IG)\"\n assumes new_edge_type: \"\\s l t. (type (id_to_list classtype), s) \\ inh (TG IG) \\ l = LabDef.edge [name] \\ (s, l, t) \\ ET (TG IG)\"\n assumes no_inh_classtype: \"\\x. (x, type (id_to_list classtype)) \\ inh (TG IG) \\ x = type (id_to_list classtype)\"\n assumes valid_mul: \"multiplicity mul\"\n assumes classtype_containedtype_neq: \"classtype \\ containedtype\"\n assumes no_src_edges_containedtype: \"\\s l t. (type (id_to_list containedtype), s) \\ inh (TG IG) \\ (s, l, t) \\ ET (TG IG)\"\n assumes no_tgt_edges_containedtype: \"\\s l t. (type (id_to_list containedtype), t) \\ inh (TG IG) \\ (s, l, t) \\ ET (TG IG)\"\n assumes objects_unique: \"objects \\ sets_to_set (set ` values ` objects) = {}\"\n assumes unique_ids: \"\\o1 o2. o1 \\ objects \\ sets_to_set (set ` values ` objects) \\ obids o1 = obids o2 \\ o1 = o2\"\n assumes unique_sets: \"\\ob. ob \\ objects \\ distinct (values ob)\"\n assumes unique_across_sets: \"\\o1 o2. o1 \\ objects \\ o2 \\ objects \\ o1 \\ o2 \\ set (values o1) \\ set (values o2) = {}\"\n assumes valid_sets: \"\\ob. ob \\ objects \\ length (values ob) in mul\"\n assumes existing_objects: \"(typed (type (id_to_list classtype)) ` objects \\ \n typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)) \\ N IG = \n typed (type (id_to_list classtype)) ` objects\"\n assumes all_objects: \"\\n. n \\ N IG \\ type\\<^sub>n n = type (id_to_list classtype) \\ \n n \\ typed (type (id_to_list classtype)) ` objects\"\n assumes valid_ids: \"\\i. i \\ obids ` objects \\ obids ` sets_to_set (set ` values ` objects) \\ \n ident IG i = ident (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) i\"\n assumes existing_ids: \"(obids ` objects \\ obids ` sets_to_set (set ` values ` objects)) \\ Id IG = obids ` objects\"\n shows \"instance_graph (ig_combine IG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\nproof (intro ig_combine_merge_correct)\n show \"instance_graph (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n by (intro ig_contained_class_set_field_as_edge_type_correct) (simp_all add: assms)\nnext\n have \"type_graph (tg_combine (TG IG) (tg_contained_class_set_field_as_edge_type classtype name containedtype mul))\"\n using existing_node_types \n proof (intro tg_contained_class_set_field_as_edge_type_combine_correct)\n fix s l t\n assume \"(s, LabDef.type (id_to_list classtype)) \\ inh (TG IG) \\ (LabDef.type (id_to_list classtype), s) \\ inh (TG IG)\"\n then have s_def: \"(LabDef.type (id_to_list classtype), s) \\ inh (TG IG)\"\n using no_inh_classtype\n by blast\n assume \"l = LabDef.edge [name]\"\n then show \"(s, l, t) \\ ET (TG IG)\"\n by (simp add: new_edge_type s_def)\n qed (simp_all add: assms(1) instance_graph.validity_type_graph new_edge_type valid_mul)\n then show \"type_graph (tg_combine (TG IG) (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)))\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\nnext\n show \"ET (TG IG) \\ ET (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)) = {}\"\n using existing_node_types\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n by (simp add: assms(1) instance_graph.validity_type_graph new_edge_type type_graph.validity_inh_node)\nnext\n fix et n\n assume et_def: \"et \\ ET (TG IG)\"\n assume \"n \\ N IG \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n then have \"n \\ N IG \\ typed (type (id_to_list classtype)) ` objects \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n then have n_def: \"n \\ N IG \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n using existing_objects\n by blast\n assume \"(type\\<^sub>n n, src et) \\ (inh (TG IG) \\ inh (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)))\\<^sup>+\"\n then have \"(type\\<^sub>n n, src et) \\ (inh (TG IG) \\ inh (tg_contained_class_set_field_as_edge_type classtype name containedtype mul))\\<^sup>+\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n then have \"(type\\<^sub>n n, src et) \\ (inh (TG IG))\\<^sup>+\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n using Un_absorb2 existing_node_types assms(1) insert_subset instance_graph.validity_type_graph sup.orderI sup_bot.right_neutral type_graph.select_convs(3) type_graph.validity_inh_node\n by metis\n then have extend_def: \"(type\\<^sub>n n, src et) \\ inh (TG IG)\"\n by (simp add: assms(1) instance_graph.validity_type_graph type_graph.validity_inh_trans)\n show \"card {e \\ E IG. src e = n \\ type\\<^sub>e e = et} in m_out (mult (TG IG) et)\"\n using n_def\n proof (elim UnE)\n assume \"n \\ N IG\"\n then show ?thesis\n using et_def extend_def assms(1) instance_graph.validity_outgoing_mult\n by blast\n next\n assume \"n \\ typed (LabDef.type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n then have \"(LabDef.type (id_to_list containedtype), src et) \\ inh (TG IG)\"\n using extend_def\n by fastforce\n then have \"et \\ ET (TG IG)\"\n using no_src_edges_containedtype fst_conv prod_cases3 src_def\n by metis\n then show ?thesis\n using et_def\n by simp\n qed \nnext\n have instance_graph_valid: \"instance_graph (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n by (intro ig_contained_class_set_field_as_edge_type_correct) (simp_all add: assms)\n have type_neq: \"type (id_to_list classtype) \\ type (id_to_list containedtype)\"\n using classtype_containedtype_neq LabDef.inject(1) id_to_list_inverse\n by metis\n fix et n\n assume et_in_ig: \"et \\ ET (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n then have et_def: \"et = (type (id_to_list classtype), LabDef.edge [name], type (id_to_list containedtype))\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n by simp\n assume \"n \\ N IG \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n then have n_def: \"n \\ N IG \\ typed (type (id_to_list classtype)) ` objects \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n assume \"(type\\<^sub>n n, src et) \\ (inh (TG IG) \\ inh (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)))\\<^sup>+\"\n then have \"(type\\<^sub>n n, src et) \\ (inh (TG IG) \\ inh (tg_contained_class_set_field_as_edge_type classtype name containedtype mul))\\<^sup>+\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n then have \"(type\\<^sub>n n, src et) \\ (inh (TG IG))\\<^sup>+\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n using Un_absorb2 existing_node_types assms(1) insert_subset instance_graph.validity_type_graph sup.orderI sup_bot.right_neutral type_graph.select_convs(3) type_graph.validity_inh_node\n by metis\n then have \"(type\\<^sub>n n, src et) \\ inh (TG IG)\"\n by (simp add: assms(1) instance_graph.validity_type_graph type_graph.validity_inh_trans)\n then have \"(type\\<^sub>n n, type (id_to_list classtype)) \\ inh (TG IG)\"\n using et_def\n by simp\n then have type_n_def: \"type\\<^sub>n n = type (id_to_list classtype)\"\n using no_inh_classtype\n by simp\n then have edge_extend_def: \"(type\\<^sub>n n, type (id_to_list classtype)) \\ inh (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n by simp\n have \"n \\ N IG \\ typed (type (id_to_list classtype)) ` objects\"\n using n_def type_n_def type_neq\n by fastforce\n then have \"n \\ typed (type (id_to_list classtype)) ` objects\"\n using all_objects existing_objects type_n_def\n by blast\n then have \"n \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n then show \"card {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). src e = n \\ type\\<^sub>e e = et} in \n m_out (mult (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)) et)\"\n using edge_extend_def et_def et_in_ig instance_graph_valid instance_graph.validity_outgoing_mult\n by fastforce\nnext\n fix et n\n assume et_def: \"et \\ ET (TG IG)\"\n assume \"n \\ N IG \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n then have \"n \\ N IG \\ typed (type (id_to_list classtype)) ` objects \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n then have n_def: \"n \\ N IG \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n using existing_objects\n by blast\n assume \"(type\\<^sub>n n, tgt et) \\ (inh (TG IG) \\ inh (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)))\\<^sup>+\"\n then have \"(type\\<^sub>n n, tgt et) \\ (inh (TG IG) \\ inh (tg_contained_class_set_field_as_edge_type classtype name containedtype mul))\\<^sup>+\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n then have \"(type\\<^sub>n n, tgt et) \\ (inh (TG IG))\\<^sup>+\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n using Un_absorb2 existing_node_types assms(1) insert_subset instance_graph.validity_type_graph sup.orderI sup_bot.right_neutral type_graph.select_convs(3) type_graph.validity_inh_node\n by metis\n then have extend_def: \"(type\\<^sub>n n, tgt et) \\ inh (TG IG)\"\n by (simp add: assms(1) instance_graph.validity_type_graph type_graph.validity_inh_trans)\n show \"card {e \\ E IG. tgt e = n \\ type\\<^sub>e e = et} in m_in (mult (TG IG) et)\"\n using n_def\n proof (elim UnE)\n assume \"n \\ N IG\"\n then show ?thesis\n using et_def extend_def assms(1) instance_graph.validity_ingoing_mult\n by blast\n next\n assume \"n \\ typed (LabDef.type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n then have \"(LabDef.type (id_to_list containedtype), tgt et) \\ inh (TG IG)\"\n using extend_def\n by fastforce\n then have \"et \\ ET (TG IG)\"\n using no_tgt_edges_containedtype snd_conv prod_cases3 tgt_def\n by metis\n then show ?thesis\n using et_def\n by simp\n qed\nnext\n have instance_graph_valid: \"instance_graph (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n by (intro ig_contained_class_set_field_as_edge_type_correct) (simp_all add: assms)\n have type_neq: \"type (id_to_list classtype) \\ type (id_to_list containedtype)\"\n using classtype_containedtype_neq LabDef.inject(1) id_to_list_inverse\n by metis\n fix et n\n assume et_in_ig: \"et \\ ET (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n then have et_def: \"et = (type (id_to_list classtype), LabDef.edge [name], type (id_to_list containedtype))\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n by simp\n assume \"n \\ N IG \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n then have n_def: \"n \\ N IG \\ typed (type (id_to_list classtype)) ` objects \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n assume \"(type\\<^sub>n n, tgt et) \\ (inh (TG IG) \\ inh (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)))\\<^sup>+\"\n then have \"(type\\<^sub>n n, tgt et) \\ (inh (TG IG) \\ inh (tg_contained_class_set_field_as_edge_type classtype name containedtype mul))\\<^sup>+\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n then have \"(type\\<^sub>n n, tgt et) \\ (inh (TG IG))\\<^sup>+\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n using Un_absorb2 existing_node_types assms(1) insert_subset instance_graph.validity_type_graph sup.orderI sup_bot.right_neutral type_graph.select_convs(3) type_graph.validity_inh_node\n by metis\n then have \"(type\\<^sub>n n, tgt et) \\ inh (TG IG)\"\n by (simp add: assms(1) instance_graph.validity_type_graph type_graph.validity_inh_trans)\n then have extend_def: \"(type\\<^sub>n n, type (id_to_list containedtype)) \\ inh (TG IG)\"\n using et_def\n by simp\n show \"card {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et} in \n m_in (mult (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)) et)\"\n using n_def\n proof (elim UnE)\n assume n_def: \"n \\ N IG\"\n have \"{e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et} = {}\"\n proof\n show \"{e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et} \\ {}\"\n proof\n fix x\n assume \"x \\ {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et}\"\n then show \"x \\ {}\"\n proof\n assume assump: \"x \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) \\ tgt x = n \\ type\\<^sub>e x = et\"\n then have \"tgt x \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n using instance_graph.structure_edges_wellformed_alt instance_graph_valid\n by blast\n then have \"n \\ typed (LabDef.type (id_to_list classtype)) ` objects\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n using existing_objects n_def assump\n by auto\n then have type_n_def: \"type\\<^sub>n n = LabDef.type (id_to_list classtype)\"\n by fastforce\n have \"type\\<^sub>n (tgt x) = LabDef.type (id_to_list containedtype)\"\n using assump\n unfolding ig_contained_class_set_field_as_edge_type_def\n by fastforce\n then show \"x \\ {}\"\n using assump type_n_def type_neq\n by simp\n qed\n qed\n next\n show \"{} \\ {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et}\"\n by simp\n qed\n then have \"card {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et} = 0\"\n using card_empty\n by metis\n then show ?thesis\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def within_multiplicity_def\n using et_def\n by simp\n next\n assume n_def: \"n \\ typed (LabDef.type (id_to_list classtype)) ` objects\"\n then have type_n_def: \"type\\<^sub>n n = LabDef.type (id_to_list classtype)\"\n by fastforce\n have \"{e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et} = {}\"\n proof\n show \"{e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et} \\ {}\"\n proof\n fix x\n assume \"x \\ {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et}\"\n then show \"x \\ {}\"\n proof\n assume assump: \"x \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) \\ tgt x = n \\ type\\<^sub>e x = et\"\n then have \"type\\<^sub>n (tgt x) = LabDef.type (id_to_list containedtype)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by fastforce\n then show \"x \\ {}\"\n using assump type_n_def type_neq\n by simp\n qed\n qed\n next\n show \"{} \\ {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et}\"\n by simp\n qed\n then have \"card {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ type\\<^sub>e e = et} = 0\"\n using card_empty\n by metis\n then show ?thesis\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def within_multiplicity_def\n using et_def\n by simp\n next\n assume n_def: \"n \\ typed (LabDef.type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n then have n_in_ig: \"n \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n have \"(type (id_to_list containedtype), type (id_to_list containedtype)) \\ inh (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n by simp\n then have \"(type\\<^sub>n n, tgt et) \\ inh (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n using n_def et_def\n by fastforce\n then show ?thesis\n using et_in_ig n_in_ig instance_graph_valid instance_graph.validity_ingoing_mult\n by blast\n qed\nnext\n have instance_graph_valid: \"instance_graph (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n by (intro ig_contained_class_set_field_as_edge_type_correct) (simp_all add: assms)\n have type_neq: \"type (id_to_list classtype) \\ type (id_to_list containedtype)\"\n using classtype_containedtype_neq LabDef.inject(1) id_to_list_inverse\n by metis\n fix n\n assume n_both: \"n \\ N IG \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n then have n_def: \"n \\ typed (type (id_to_list classtype)) ` objects\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n using existing_objects\n by auto\n have set_eq: \"{e \\ E IG \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ \n type\\<^sub>e e \\ contains (TG IG) \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))} =\n {e \\ E IG. tgt e = n \\ type\\<^sub>e e \\ contains (TG IG)}\"\n proof\n show \"{e \\ E IG \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ \n type\\<^sub>e e \\ contains (TG IG) \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))}\n \\ {e \\ E IG. tgt e = n \\ type\\<^sub>e e \\ contains (TG IG)}\"\n proof\n fix x\n assume \"x \\ {e \\ E IG \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ \n type\\<^sub>e e \\ contains (TG IG) \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))}\"\n then show \"x \\ {e \\ E IG. tgt e = n \\ type\\<^sub>e e \\ contains (TG IG)}\"\n proof\n assume assump: \"x \\ E IG \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) \\ tgt x = n \\ \n type\\<^sub>e x \\ contains (TG IG) \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n then have \"x \\ E IG \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n by simp\n then show \"x \\ {e \\ E IG. tgt e = n \\ type\\<^sub>e e \\ contains (TG IG)}\"\n proof (elim UnE)\n assume x_def: \"x \\ E IG\"\n then have \"type\\<^sub>e x \\ ET (TG IG)\"\n using assms(1) instance_graph.structure_edges_wellformed_edge_type_alt\n by blast\n then have \"type\\<^sub>e x \\ ET (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n using new_edge_type assms(1) instance_graph.validity_type_graph type_graph.structure_edges_wellformed_src_node type_graph.validity_inh_node\n by fastforce\n then have \"type\\<^sub>e x \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n using instance_graph.validity_type_graph instance_graph_valid type_graph.structure_contains_wellformed\n by blast\n then show ?thesis\n using assump x_def\n by blast\n next\n assume \"x \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n then have \"x \\ (\\x. (typed (type (id_to_list classtype)) (fst x), \n (type (id_to_list classtype), LabDef.edge [name], type (id_to_list containedtype)), \n typed (type (id_to_list containedtype)) (snd x))) ` values_to_pairs objects values\"\n unfolding ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def\n by simp\n then have tgt_type_def: \"type\\<^sub>n (tgt x) = type (id_to_list containedtype)\"\n by fastforce\n have \"type\\<^sub>n n = type (id_to_list classtype)\"\n using n_def\n by fastforce\n then show ?thesis\n using tgt_type_def type_neq assump\n by simp\n qed\n qed\n qed\n next\n show \"{e \\ E IG. tgt e = n \\ type\\<^sub>e e \\ contains (TG IG)} \\\n {e \\ E IG \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ \n type\\<^sub>e e \\ contains (TG IG) \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))}\"\n by blast\n qed\n have \"card {e \\ E IG. tgt e = n \\ type\\<^sub>e e \\ contains (TG IG)} \\ 1\"\n using assms(1) n_both instance_graph.validity_contained_node\n by blast\n then show \"card {e \\ E IG \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). tgt e = n \\ \n type\\<^sub>e e \\ contains (TG IG) \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))} \\ 1\"\n using set_eq\n by simp\nnext\n have instance_graph_valid: \"instance_graph (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n by (intro ig_contained_class_set_field_as_edge_type_correct) (simp_all add: assms)\n have type_neq: \"type (id_to_list classtype) \\ type (id_to_list containedtype)\"\n using classtype_containedtype_neq LabDef.inject(1) id_to_list_inverse\n by metis\n then have nodes_neq: \"typed (type (id_to_list classtype)) ` objects \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects) = {}\"\n by blast\n then have nodes_ig_neq: \"N IG \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects) = {}\"\n using existing_objects\n by blast\n have containments_block_irrefl: \"irrefl ((edge_to_tuple ` {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))})\\<^sup>+)\"\n proof (intro validity_containment_alt)\n fix e\n assume \"e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n then show \"src e \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) \\ \n tgt e \\ N (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\n using instance_graph_valid instance_graph.structure_edges_wellformed_src_node_alt instance_graph.structure_edges_wellformed_tgt_node_alt\n by blast\n next\n show \"\\p. \\pre_digraph.cycle (instance_graph_containment_proj (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)) p\"\n using instance_graph_valid instance_graph.validity_containment\n by blast\n qed\n have containments_block_def: \"\\s t. (s, t) \\ edge_to_tuple ` {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))} \\\n s \\ typed (type (id_to_list classtype)) ` objects \\ t \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n proof (elim imageE)\n fix s t e\n assume e_def: \"e \\ {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))}\"\n assume s_t_def: \"(s, t) = edge_to_tuple e\"\n show \"s \\ typed (LabDef.type (id_to_list classtype)) ` objects \\ t \\ typed (LabDef.type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n using e_def\n proof\n assume \"e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) \\ \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))\"\n then have edge_def: \"e \\ (\\x. (typed (type (id_to_list classtype)) (fst x), \n (type (id_to_list classtype), LabDef.edge [name], type (id_to_list containedtype)), \n typed (type (id_to_list containedtype)) (snd x))) ` values_to_pairs objects values\"\n unfolding ig_contained_class_set_field_as_edge_type_def\n by simp\n have \"src e \\ typed (type (id_to_list classtype)) ` fst ` values_to_pairs objects values\"\n using edge_def\n by force\n then have \"src e \\ typed (type (id_to_list classtype)) ` objects\"\n using values_to_pairs_fst\n by blast\n then have s_def: \"s \\ typed (type (id_to_list classtype)) ` objects\"\n using s_t_def\n unfolding edge_to_tuple_def\n by blast\n have \"tgt e \\ typed (type (id_to_list containedtype)) ` snd ` values_to_pairs objects values\"\n using edge_def\n by force\n then have tgt_e_def: \"tgt e \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n using values_to_pairs_snd\n by blast\n then have t_def: \"t \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n using s_t_def\n unfolding edge_to_tuple_def\n by blast\n show \"s \\ typed (LabDef.type (id_to_list classtype)) ` objects \\ t \\ typed (LabDef.type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n using s_def t_def\n by blast\n qed\n qed\n have containments_ig_irrefl: \"irrefl ((edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)})\\<^sup>+)\"\n proof (intro validity_containment_alt)\n fix e\n assume \"e \\ E IG\"\n then show \"src e \\ N IG \\ tgt e \\ N IG\"\n using assms(1) instance_graph.structure_edges_wellformed_src_node_alt instance_graph.structure_edges_wellformed_tgt_node_alt\n by blast\n next\n show \"\\p. \\pre_digraph.cycle (instance_graph_containment_proj IG) p\"\n using assms(1) instance_graph.validity_containment\n by blast\n qed\n have containments_ig_def: \"\\s t. (s, t) \\ edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)} \\ s \\ N IG \\ t \\ N IG\"\n proof (elim imageE)\n fix s t e\n assume e_def: \"e \\ {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)}\"\n assume s_t_def: \"(s, t) = edge_to_tuple e\"\n show \"s \\ N IG \\ t \\ N IG\"\n using e_def\n proof\n assume assump: \"e \\ E IG \\ type\\<^sub>e e \\ contains (TG IG)\"\n then have \"src e \\ N IG\"\n using assms(1) instance_graph.structure_edges_wellformed_src_node_alt\n by blast\n then have s_def: \"s \\ N IG\"\n using s_t_def\n unfolding edge_to_tuple_def\n by blast\n have \"tgt e \\ N IG\"\n using assump assms(1) instance_graph.structure_edges_wellformed_tgt_node_alt\n by blast\n then have t_def: \"t \\ N IG\"\n using s_t_def\n unfolding edge_to_tuple_def\n by blast\n show \"s \\ N IG \\ t \\ N IG\"\n using s_def t_def\n by blast\n qed\n qed\n have \"\\x. (x, x) \\ (edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)} \\\n edge_to_tuple ` {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))})\\<^sup>+\"\n proof\n fix x\n assume \"(x, x) \\ (edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)} \\\n edge_to_tuple ` {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))})\\<^sup>+\"\n then show \"False\"\n proof (cases)\n case base\n then show ?thesis\n proof (elim UnE)\n assume \"(x, x) \\ edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)}\"\n then show ?thesis\n using containments_ig_irrefl\n unfolding irrefl_def\n by blast\n next\n assume \"(x, x) \\ edge_to_tuple ` {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))}\"\n then show ?thesis\n using containments_block_irrefl\n unfolding irrefl_def\n by blast\n qed\n next\n case (step c)\n then show ?thesis\n proof (elim UnE)\n assume c_x_def: \"(c, x) \\ edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)}\"\n then have c_def: \"c \\ N IG\"\n using containments_ig_def\n by blast\n have \"(x, c) \\ (edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)})\\<^sup>+\"\n using step(1) c_def\n proof (induct)\n case (base y)\n then show ?case\n using containments_block_def nodes_ig_neq\n by blast\n next\n case (step y z)\n then have y_z_def: \"(y, z) \\ edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)}\"\n using containments_block_def nodes_ig_neq\n by blast\n then have \"(x, y) \\ (edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)})\\<^sup>+\"\n using containments_ig_def step(3)\n by blast\n then show ?case\n using y_z_def\n by simp\n qed\n then have \"(x, x) \\ (edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)})\\<^sup>+\"\n using c_x_def\n by simp\n then show ?thesis\n using containments_ig_irrefl irrefl_def\n by fastforce\n next\n assume assump: \"(c, x) \\ edge_to_tuple ` {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))}\"\n then have x_def: \"x \\ typed (type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)\"\n using containments_block_def\n by blast\n have \"c \\ typed (type (id_to_list classtype)) ` objects\"\n using assump containments_block_def\n by blast\n then have c_def: \"c \\ N IG\"\n using existing_objects\n by blast\n have \"(x, c) \\ (edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)})\\<^sup>+\"\n using step(1) c_def\n proof (induct)\n case (base y)\n then show ?case\n using containments_block_def nodes_ig_neq\n by blast\n next\n case (step y z)\n then have y_z_def: \"(y, z) \\ edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)}\"\n using containments_block_def nodes_ig_neq\n by blast\n then have \"(x, y) \\ (edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)})\\<^sup>+\"\n using containments_ig_def step(3)\n by blast\n then show ?case\n using y_z_def\n by simp\n qed\n then have \"x \\ N IG\"\n using containments_ig_def\n proof (induct)\n case (base y)\n then show ?case\n by blast\n next\n case (step y z)\n then show ?case\n by blast\n qed\n then show ?thesis\n using x_def objects_unique existing_objects\n by blast\n qed\n qed\n qed\n then show \"irrefl ((edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)} \\\n edge_to_tuple ` {e \\ E (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values). \n type\\<^sub>e e \\ contains (TG (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values))})\\<^sup>+)\"\n unfolding irrefl_def\n by simp\nqed (simp_all add: ig_contained_class_set_field_as_edge_type_def tg_contained_class_set_field_as_edge_type_def assms)\n\n\n\nsubsection \"Transformation functions\"\n\ndefinition imod_contained_class_set_field_to_ig_contained_class_set_field_as_edge_type :: \"'t Id \\ 't \\ 't Id \\ multiplicity \\ 'o set \\ ('o \\ 't) \\ ('o \\ 'o list) \\ ('o, 't) instance_model \\ ('o, 't list, 't) instance_graph\" where\n \"imod_contained_class_set_field_to_ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values Imod = \\\n TG = tg_contained_class_set_field_as_edge_type classtype name containedtype mul,\n Id = obids ` Object Imod,\n N = typed (type (id_to_list classtype)) ` {ob \\ Object Imod. ob \\ objects} \\ typed (type (id_to_list containedtype)) ` {ob \\ Object Imod. ob \\ sets_to_set (set ` values ` objects)},\n E = (\\x. (typed (type (id_to_list classtype)) (fst x), (type (id_to_list classtype), LabDef.edge [name], type (id_to_list containedtype)), typed (type (id_to_list containedtype)) (snd x))) ` values_to_pairs {ob \\ Object Imod. ob \\ objects} values,\n ident = (\\x. if x \\ obids ` objects then typed (type (id_to_list classtype)) (THE y. obids y = x) else \n if x \\ obids ` sets_to_set (set ` values ` objects) then typed (type (id_to_list containedtype)) (THE y. obids y = x) else undefined)\n \\\"\n\nlemma imod_contained_class_set_field_to_ig_contained_class_set_field_as_edge_type_proj:\n shows \"imod_contained_class_set_field_to_ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values (imod_contained_class_set_field classtype name containedtype mul objects obids values) = \n ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values\"\nproof-\n have \"values_to_pairs {ob \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values). ob \\ objects} values = values_to_pairs objects values\"\n proof-\n have \"{ob \\ Object (imod_contained_class_set_field classtype name containedtype mul objects obids values). ob \\ objects} = objects\"\n unfolding imod_contained_class_set_field_def\n by auto\n then show ?thesis\n by simp\n qed\n then show \"imod_contained_class_set_field_to_ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values (imod_contained_class_set_field classtype name containedtype mul objects obids values) = \n ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values\"\n unfolding imod_contained_class_set_field_to_ig_contained_class_set_field_as_edge_type_def ig_contained_class_set_field_as_edge_type_def imod_contained_class_set_field_def\n by auto\nqed\n \n\nlemma imod_contained_class_set_field_to_ig_contained_class_set_field_as_edge_type_func:\n shows \"ig_combine_mapping_function (imod_contained_class_set_field_to_ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\n (imod_contained_class_set_field classtype name containedtype mul objects obids values) (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values)\"\nproof (intro ig_combine_mapping_function.intro)\n show \"imod_contained_class_set_field_to_ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values (imod_contained_class_set_field classtype name containedtype mul objects obids values) = \n ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values\"\n by (fact imod_contained_class_set_field_to_ig_contained_class_set_field_as_edge_type_proj)\nnext\n fix ImodX\n show \"E (imod_contained_class_set_field_to_ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values (imod_contained_class_set_field classtype name containedtype mul objects obids values))\n \\ E (imod_contained_class_set_field_to_ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values (imod_combine (imod_contained_class_set_field classtype name containedtype mul objects obids values) ImodX))\"\n proof\n fix x\n have value_to_pairs_def: \"values_to_pairs {ob. (ob \\ objects \\ ob \\ sets_to_set (set ` values ` objects)) \\ ob \\ objects} values \\ \n values_to_pairs {ob. (ob \\ objects \\ ob \\ sets_to_set (set ` values ` objects) \\ ob \\ Object ImodX) \\ ob \\ objects} values\"\n proof\n fix x\n assume \"x \\ values_to_pairs {ob. (ob \\ objects \\ ob \\ sets_to_set (set ` values ` objects)) \\ ob \\ objects} values\"\n then show \"x \\ values_to_pairs {ob. (ob \\ objects \\ ob \\ sets_to_set (set ` values ` objects) \\ ob \\ Object ImodX) \\ ob \\ objects} values\"\n proof (induct x)\n case (Pair a b)\n then show ?case\n proof (induct)\n case (rule_member x y)\n then have \"x \\ {ob. (ob \\ objects \\ ob \\ sets_to_set (set ` values ` objects) \\ ob \\ Object ImodX) \\ ob \\ objects}\"\n by simp\n then show ?case\n by (simp add: rule_member.hyps(2) values_to_pairs.rule_member)\n qed\n qed\n qed\n assume \"x \\ E (imod_contained_class_set_field_to_ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values (imod_contained_class_set_field classtype name containedtype mul objects obids values))\"\n then show \"x \\ E (imod_contained_class_set_field_to_ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values (imod_combine (imod_contained_class_set_field classtype name containedtype mul objects obids values) ImodX))\"\n unfolding imod_contained_class_set_field_to_ig_contained_class_set_field_as_edge_type_def imod_contained_class_set_field_def ig_contained_class_set_field_as_edge_type_def imod_combine_def\n using value_to_pairs_def\n by auto\n qed\nqed (auto simp add: imod_contained_class_set_field_to_ig_contained_class_set_field_as_edge_type_def imod_contained_class_set_field_def ig_contained_class_set_field_as_edge_type_def imod_combine_def)\n\ndefinition ig_contained_class_set_field_as_edge_type_to_imod_contained_class_set_field :: \"'t Id \\ 't \\ 't Id \\ multiplicity \\ 'o set \\ ('o \\ 't) \\ ('o \\ 'o list) \\ ('o, 't list, 't) instance_graph \\ ('o, 't) instance_model\" where\n \"ig_contained_class_set_field_as_edge_type_to_imod_contained_class_set_field classtype name containedtype mul objects obids values IG = \\\n Tm = tmod_contained_class_set_field classtype name containedtype mul,\n Object = nodeId ` N IG,\n ObjectClass = (\\x. if x \\ objects then classtype else if x \\ sets_to_set (set ` values ` objects) then containedtype else undefined),\n ObjectId = (\\x. if x \\ objects \\ sets_to_set (set ` values ` objects) then obids x else undefined),\n FieldValue = (\\x. if fst x \\ objects \\ snd x = (classtype, name) then setof (map obj (values (fst x))) else\n if fst x \\ sets_to_set (set ` values ` objects) \\ snd x = (classtype, name) then unspecified else undefined),\n DefaultValue = (\\x. undefined)\n \\\"\n\nlemma ig_contained_class_set_field_as_edge_type_to_imod_contained_class_set_field_proj:\n shows \"ig_contained_class_set_field_as_edge_type_to_imod_contained_class_set_field classtype name containedtype mul objects obids values (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) = \n imod_contained_class_set_field classtype name containedtype mul objects obids values\"\nproof-\n have \"nodeId ` (typed (LabDef.type (id_to_list classtype)) ` objects) = objects\"\n by force\n then have objects_def: \"\\x. x \\ objects \\ \n x \\ nodeId ` (typed (LabDef.type (id_to_list classtype)) ` objects \\ typed (LabDef.type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects))\"\n by blast\n have \"nodeId ` (typed (LabDef.type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects)) = sets_to_set (set ` values ` objects)\"\n by force\n then have values_def: \"\\x. x \\ sets_to_set (set ` values ` objects) \\ \n x \\ nodeId ` (typed (LabDef.type (id_to_list classtype)) ` objects \\ typed (LabDef.type (id_to_list containedtype)) ` sets_to_set (set ` values ` objects))\"\n by blast\n show ?thesis\n unfolding ig_contained_class_set_field_as_edge_type_to_imod_contained_class_set_field_def imod_contained_class_set_field_def ig_contained_class_set_field_as_edge_type_def\n using objects_def values_def\n by auto\nqed\n\nlemma ig_contained_class_set_field_as_edge_type_to_imod_contained_class_set_field_func:\n shows \"imod_combine_mapping_function (ig_contained_class_set_field_as_edge_type_to_imod_contained_class_set_field classtype name containedtype mul objects obids values)\n (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) (imod_contained_class_set_field classtype name containedtype mul objects obids values)\"\nproof (intro imod_combine_mapping_function.intro)\n show \"ig_contained_class_set_field_as_edge_type_to_imod_contained_class_set_field classtype name containedtype mul objects obids values (ig_contained_class_set_field_as_edge_type classtype name containedtype mul objects obids values) =\n imod_contained_class_set_field classtype name containedtype mul objects obids values\"\n by (fact ig_contained_class_set_field_as_edge_type_to_imod_contained_class_set_field_proj)\nqed (auto simp add: ig_contained_class_set_field_as_edge_type_to_imod_contained_class_set_field_def imod_contained_class_set_field_def ig_contained_class_set_field_as_edge_type_def ig_combine_def)\n\nend","avg_line_length":64.4652897303,"max_line_length":350,"alphanum_fraction":0.6772217426} {"size":1905,"ext":"thy","lang":"Isabelle","max_stars_count":1.0,"content":"theory T57\nimports Main\nbegin\nlemma \"(\n(\\ x::nat. \\ y::nat. meet(x, y) = meet(y, x)) &\n(\\ x::nat. \\ y::nat. join(x, y) = join(y, x)) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(x, meet(y, z)) = meet(meet(x, y), z)) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(x, join(y, z)) = join(join(x, y), z)) &\n(\\ x::nat. \\ y::nat. meet(x, join(x, y)) = x) &\n(\\ x::nat. \\ y::nat. join(x, meet(x, y)) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(x, join(y, z)) = join(mult(x, y), mult(x, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(join(x, y), z) = join(mult(x, z), mult(y, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(x, over(join(mult(x, y), z), y)) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(y, undr(x, join(mult(x, y), z))) = y) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(mult(over(x, y), y), x) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(mult(y, undr(y, x)), x) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(x, meet(y, z)) = meet(mult(x, y), mult(x, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. undr(x, join(y, z)) = join(undr(x, y), undr(x, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. over(join(x, y), z) = join(over(x, z), over(y, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. undr(meet(x, y), z) = join(undr(x, z), undr(y, z))) &\n(\\ x::nat. \\ y::nat. invo(join(x, y)) = meet(invo(x), invo(y))) &\n(\\ x::nat. \\ y::nat. invo(meet(x, y)) = join(invo(x), invo(y))) &\n(\\ x::nat. invo(invo(x)) = x)\n) \\\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(meet(x, y), z) = meet(mult(x, z), mult(y, z)))\n\"\nnitpick[card nat=10,timeout=86400]\noops\nend","avg_line_length":65.6896551724,"max_line_length":108,"alphanum_fraction":0.5333333333} {"size":4676,"ext":"thy","lang":"Isabelle","max_stars_count":8.0,"content":"theory Statements extends \\root\n\n\n# do\n -------------------------------\n\nassert (do 42) == 42 <> [42] == (do* 42)\n\ndo\n # we are surrounding the following statements with do\n to avoid polluting the namespace of the theory with the\n definition of x and y, which are rather arbitrary names\n val x = 10\n val y = \n do*\n x\n x\n + 1\n x + 2\n assert y == [10, 11, 12]\n\ndo\n val result1 = \n do*\n val (x, y, z) = (1, 2, 3)\n x\n -y\n z\n\n val result2 = \n do*\n val (x, y, z) = (1, 2, 3)\n x\n -y\n z\n \n assert result1 == (1, -2, 3) \n assert result2 == (-1, 3)\n\ndo\n val result = \n do*\n val x = 10\n def f x = \n do* \n x + 1\n x = x * x\n x * x\n f x\n assert result == [(11, 10000)]\n\ndo\n val result = \n do*\n val x = 10\n def f x = \n do* \n x + 1\n x = x * x\n x * x\n f x\n assert result == (10000, [101])\n\n\n\n\n# if\n -------------------------------\n\nassert (if true then 1 else 2) == 1\nassert (if false then 1 else 2) == 2\nfailure (if nil then 1 else 2)\n\n\n# match\n -------------------------------\n\nval wordOf = x => \n match x\n case 0 => \"none\"\n case 1 => \"one\"\n case 2 => \"two\"\n case z if z > 0 => \"many\"\n\nassert wordOf 0 == \"none\" and wordOf 1 == \"one\" and wordOf 2 == \"two\"\nassert wordOf 5 == \"many\"\nfailure wordOf (-1)\n\n\n# while\n -------------------------------\n\ndef gcd (a, b) = \n if a < 0 then a = -a\n if b < 0 then b = -b\n while b > 0 do\n (a, b) = (b, a mod b)\n a\n\nassert gcd (54, 24) == 6\nassert gcd (-54, -24) == 6\nassert gcd (54, 25) == 1\n\ndef ggt (a, b) =\n if a < 0 then ggt (-a, b)\n else \n if b < 0 then ggt (a, -b)\n else \n if b == 0 then a\n else ggt (b, a mod b)\n\nassert ggt (54, 24) == 6\nassert ggt (-54, -24) == 6\nassert ggt (54, 25) == 1\nassert ggt (0, 0) == 0\n\n# for\n -------------------------------\n\n# This function sums up all the elements of a vector which are non-negative integers\ndef sum v =\n val s = 0\n for x if x >= 0 in v do\n s = s + x\n s\n\nassert sum (1, 2, 3, 4, 5, -10, \"hello\", 7) == 22\nassert sum () == 0\n\n# the function also works for sets\nassert sum {1, 2, 3, 4, 5, -10, \"hello\", 7} == 22\nassert sum {} == sum {->} == 0\nassert sum {4, 3, 3} == 7\n\n# This implements the map functional for vectors\ndef map (f, v) = for x in v do f x\n\nassert map (x => x * x, [1, 9, 5]) == [1, 81, 25]\n\n# You can apply map also to sets, but you still get a vector\nassert map (x => x * x, {1, 9, 5}) == [1, 81, 25]\n\n# Here is how you can swap keys and values in a Map\ndef swap (m : Map) : Map = \n val result = {->}\n for (k, v) in m do\n result = result ++ {v -> k}\n result\n\nassert swap {2 -> 3, 3 -> 5, 5 -> 7, 7 -> 11} == {3 -> 2, 5 -> 3, 7 -> 5, 11 -> 7}\n\n# And this implements the fold functional\ndef fold (f, x, v) =\n for y in v do\n x = f (x, y)\n x\n\nassert fold ((x, y) => x + y, 8, [1, 2, 3, 4, 5, 7]) == 30\n\n# Finally, foldmap\ndef foldmap (f, x, v) =\n for y in v do\n x = f (x, y)\n x\n\nassert foldmap ((x, y) => x + y, 8, [1, 2, 3, 4, 5, 7]) == [9, 11, 14, 18, 23, 30]\n\n\n# val, def and rebinding\n -------------------------------\n\ndo\n val x = 3\n val y if x == 3 =\n x + x\n assert y == 6\n\ndo\n val x = 3\n val y if x == 3 =\n val x = 2\n x + x\n assert y == 4\n\nfailure\n val x = 3\n val y if x == 3 =\n x = 2\n x + x\n\ndef \n fac 0 = 1\n fac 1 = 1\n fac n = n * fac (n - 1)\n\nassert fac 10 == 3628800\n\ndef \n even 0 = true\n odd 0 = false\n even n if n > 0 = odd (n - 1)\n odd n if n > 0 = even (n - 1)\n even n if n < 0 = odd (n + 1)\n odd n if n < 0 = even (n + 1)\n\nassert even 24 == even (-24) == true\nassert odd 24 == odd (-24) == false\nfailure even \"24\"\nfailure odd \"24\"\n\neven = \"even\"\n\nassert even == \"even\" and odd 24 == false\n\n# return\n -------------------------------\n\n# look up element in association list\ndef lookup (x, v) = \n for (key, value) in v do \n if x == key then return value\n return\n\nval proofpeers = [(\"Steven\", \"Obua\"), (\"Jacques\", \"Fleuriot\"), \n (\"Phil\", \"Scott\"), (\"David\", \"Aspinall\")]\n\nassert lookup (\"Jacques\", proofpeers) == \"Fleuriot\"\nassert lookup (\"Marilyn\", proofpeers) == nil\n\n# fail\n -------------------------------\n\n# This function computes the integer square root of an integer if it\n actually exists. Otherwise it fails.\ndef sqrt x =\n if x < 0 then fail\n for i in 0 to x do\n if i * i == x then return i\n fail\n\nassert sqrt 1024 == 32\nfailure sqrt (-1)\nassert sqrt 9 == 3\nassert sqrt 0 == 0\nassert sqrt 1 == 1\nassert sqrt 4 == 2\nfailure sqrt 10\n\n# timeit\n -------------------------------\n\nval _ = timeit 100\n\nassert (timeit \n \"A\"\n \"B\"\n \"C\") == \"C\"\n\ntimeit\n \"A\"\n \"B\"\n \"C\"\n\n\n\n\n\n\n","avg_line_length":17.3828996283,"max_line_length":84,"alphanum_fraction":0.4835329341} {"size":2172,"ext":"thy","lang":"Isabelle","max_stars_count":18.0,"content":"theory Tracing\n imports Main Refine_Imperative_HOL.Sepref\nbegin\n\ndatatype message = ExploredState\n\ndefinition write_msg :: \"message \\ unit\" where\n \"write_msg m = ()\"\n\ncode_printing code_module \"Tracing\" \\ (SML)\n\\\nstructure Tracing : sig\n val count_up : unit -> unit\n val get_count : unit -> int\nend = struct\n val counter = Unsynchronized.ref 0;\n fun count_up () = (counter := !counter + 1);\n fun get_count () = !counter;\nend\n\\ and (OCaml)\n\\\nmodule Tracing : sig\n val count_up : unit -> unit\n val get_count : unit -> int\nend = struct\n let counter = ref 0\n let count_up () = (counter := !counter + 1)\n let get_count () = !counter\nend\n\\\n\ncode_reserved SML Tracing\n\ncode_reserved OCaml Tracing\n\ncode_printing\n constant write_msg \\ (SML) \"(fn x => Tracing.count'_up ()) _\"\n and (OCaml) \"(fun x -> Tracing.count'_up ()) _\"\n\ndefinition trace where\n \"trace m x = (let a = write_msg m in x)\"\n\nlemma trace_alt_def[simp]:\n \"trace m x = (\\ _. x) (write_msg x)\"\n unfolding trace_def by simp\n\ndefinition\n \"test m = trace ExploredState ((3 :: int) + 1)\"\n\ndefinition \"TRACE m = RETURN (trace m ())\"\n\nlemma TRACE_bind[simp]:\n \"do {TRACE m; c} = c\"\n unfolding TRACE_def by simp\n\nlemma [sepref_import_param]:\n \"(trace, trace) \\ \\Id,\\Id,Id\\fun_rel\\fun_rel\"\n by simp\n\nsepref_definition TRACE_impl is\n \"TRACE\" :: \"id_assn\\<^sup>k \\\\<^sub>a unit_assn\"\n unfolding TRACE_def by sepref\n\nlemmas [sepref_fr_rules] = TRACE_impl.refine\n\n\ntext \\Somehow Sepref does not want to pick up TRACE as it is, so we use the following workaround:\\\n\ndefinition \"TRACE' = TRACE ExploredState\"\n\ndefinition \"trace' = trace ExploredState\"\n\nlemma TRACE'_alt_def:\n \"TRACE' = RETURN (trace' ())\"\n unfolding TRACE_def TRACE'_def trace'_def ..\n\nlemma [sepref_import_param]:\n \"(trace', trace') \\ \\Id,Id\\fun_rel\"\n by simp\n\nsepref_definition TRACE'_impl is\n \"uncurry0 TRACE'\" :: \"unit_assn\\<^sup>k \\\\<^sub>a unit_assn\"\n unfolding TRACE'_alt_def\n by sepref\n\nlemmas [sepref_fr_rules] = TRACE'_impl.refine\n\nend\n","avg_line_length":24.404494382,"max_line_length":111,"alphanum_fraction":0.6938305709} {"size":2254,"ext":"thy","lang":"Isabelle","max_stars_count":30.0,"content":"theory lscmnbignum_Lsc__bignum__mont_mult__subprogram_def_WP_parameter_def_5\nimports \"..\/LibSPARKcrypto\"\nbegin\n\nlemma mod_cong: \"a = b \\ a mod m = b mod m\"\n by simp\n\nwhy3_open \"lscmnbignum_Lsc__bignum__mont_mult__subprogram_def_WP_parameter_def_5.xml\"\n\nabbreviation F where\n \"F x \\ map__content (mk_map__ref x)\"\n\nabbreviation G where\n \"G x \\ t__content (mk_t__ref x)\"\n\nlemma [simp]: \"F x = x\"\n by (simp add: map__content_def)\n\nlemma [simp]: \"G x = x\"\n by (simp add: t__content_def)\n\nwhy3_vc WP_parameter_def\nproof -\n let ?a = \"num_of_big_int (word32_to_int \\ a1) a_first (a_last - a_first + 1)\"\n let ?a' = \"num_of_big_int (word32_to_int \\ a2) a_first (a_last - a_first + 1)\"\n let ?m = \"num_of_big_int (word32_to_int \\ elts m) m_first (a_last - a_first + 1)\"\n let ?R = \"Base ^ nat (a_last - a_first + 1)\"\n note sub = `(num_of_big_int' (Array (F a1) _) _ _ - num_of_big_int' m _ _ = _) = _`\n [simplified base_eq, simplified]\n note invariant1 = `((num_of_big_int' (Array a1 _) _ _ + _) mod _ = _) = _`\n note invariant2 = `(num_of_big_int' (Array a1 _) _ _ + _ < _ * _ - _) = _`\n\n have \"?m < ?R\" by (simp add: num_of_lint_upper word32_to_int_upper')\n have \"0 \\ ?m\" \"0 \\ ?a\" by (simp_all add: num_of_lint_lower word32_to_int_lower)\n\n from sub [THEN mod_cong, of ?R]\n have \"?a' = (?a + ?R * \\a_msw1\\\\<^sub>s - ?m) mod ?R\"\n by (simp add: mod_pos_pos_trivial num_of_lint_lower word32_to_int_lower\n num_of_lint_upper word32_to_int_upper')\n also from `G a_msw1 \\ of_int 0` [simplified word_uint_eq_iff, simplified, folded word32_to_int_def]\n word32_to_int_lower [of a_msw1]\n have \"1 \\ \\a_msw1\\\\<^sub>s\" by simp\n with `?m < ?R` have \"?m * 1 < ?R * \\a_msw1\\\\<^sub>s\" using `0 \\ ?m`\n by (rule mult_less_le_imp_less) simp_all\n with invariant2 `0 \\ ?a` `0 \\ ?m` `?m < ?R`\n have \"(?a + ?R * \\a_msw1\\\\<^sub>s - ?m) mod ?R = (?a + ?R * \\a_msw1\\\\<^sub>s - ?m) mod ?m\"\n by (simp add: mod_pos_pos_trivial base_eq word32_to_int_def del: minus_mod_self2)\n finally show ?thesis using invariant1\n by (simp add: diff_add_eq base_eq word32_to_int_def)\nqed\n\nwhy3_end\n\nend\n","avg_line_length":40.9818181818,"max_line_length":124,"alphanum_fraction":0.6787932564} {"size":4847,"ext":"thy","lang":"Isabelle","max_stars_count":11.0,"content":"theory Sshiftr\n imports \"Word_Lib.Reversed_Bit_Lists\"\nbegin\n\ntext\\\nAdded to the afp: https:\/\/foss.heptapod.net\/isa-afp\/afp-devel\/-\/commit\/6b53a6d8121ef1088de9668d98061fb500e915e5\nSo this theory can be removed once it's in a release.\n\\\n\ntext\\Some auxiliaries for shifting by the entire word length or more\\\n\nlemma sshiftr_clamp_pos:\n assumes\n \"LENGTH('a) \\ n\"\n \"0 \\ sint x\"\n shows \"(x::'a::len word) >>> n = 0\"\n apply (rule word_sint.Rep_eqD)\n apply (unfold sshiftr_div_2n Word.sint_0)\n apply (rule div_pos_pos_trivial)\n subgoal using assms(2) .\n apply (rule order.strict_trans[where b=\"2 ^ (LENGTH('a) - 1)\"])\n using sint_lt assms(1) by auto\n\nlemma sshiftr_clamp_neg:\n assumes\n \"LENGTH('a) \\ n\"\n \"sint x < 0\"\n shows \"(x::'a::len word) >>> n = -1\"\nproof -\n have *: \"- (2 ^ n) < sint x\"\n apply (rule order.strict_trans2[where b=\"- (2 ^ (LENGTH('a) - 1))\"])\n using assms(1) sint_ge by auto\n show ?thesis\n apply (rule word_sint.Rep_eqD)\n apply (unfold sshiftr_div_2n Word.sint_n1)\n apply (subst div_minus_minus[symmetric])\n apply (rule div_pos_neg_trivial)\n subgoal using assms(2) by linarith\n using * by simp\nqed\n\nlemma sshiftr_clamp:\n assumes \"LENGTH('a) \\ n\"\n shows \"(x::'a::len word) >>> n = x >>> LENGTH('a)\"\n apply (cases \"0 \\ sint x\")\n subgoal\n apply (subst sshiftr_clamp_pos[OF assms])\n defer apply (subst sshiftr_clamp_pos)\n by auto\n apply (subst sshiftr_clamp_neg[OF assms])\n defer apply (subst sshiftr_clamp_neg)\n by auto\n\ntext\\\nLike @{thm shiftr1_bl_of}, but the precondition is stronger because we need to pick the msb out of\nthe list.\n\\\nlemma sshiftr1_bl_of:\n \"length bl = LENGTH('a) \\\n sshiftr1 (of_bl bl::'a::len word) = of_bl (hd bl # butlast bl)\"\n apply (rule word_bl.Rep_eqD)\n apply (subst bl_sshiftr1[of \"of_bl bl :: 'a word\"])\n by (simp add: word_bl.Abs_inverse)\n\ntext\\\nLike @{thm sshiftr1_bl_of}, with a weaker precondition.\nWe still get a direct equation for @{term \\sshiftr1 (of_bl bl)\\}, it's just uglier.\n\\\nlemma sshiftr1_bl_of':\n \"LENGTH('a) \\ length bl \\\n sshiftr1 (of_bl bl::'a::len word) =\n of_bl (hd (drop (length bl - LENGTH('a)) bl) # butlast (drop (length bl - LENGTH('a)) bl))\"\n apply (subst of_bl_drop'[symmetric, of \"length bl - LENGTH('a)\"])\n using sshiftr1_bl_of[of \"drop (length bl - LENGTH('a)) bl\"]\n by auto\n\ntext\\\nLike @{thm shiftr_bl_of}.\n\\\nlemma sshiftr_bl_of:\n assumes \"length bl = LENGTH('a)\"\n shows \"(of_bl bl::'a::len word) >>> n = of_bl (replicate n (hd bl) @ take (length bl - n) bl)\"\nproof -\n {\n fix n\n assume \"n \\ LENGTH('a)\"\n hence \"(of_bl bl::'a::len word) >>> n = of_bl (replicate n (hd bl) @ take (length bl - n) bl)\"\n proof (induction n)\n case (Suc n)\n hence \"n < length bl\" by (simp add: assms)\n hence ne: \"\\take (length bl - n) bl = []\" by auto\n have left: \"hd (replicate n (hd bl) @ take (length bl - n) bl) = (hd bl)\"\n by (cases \"0 < n\") auto\n have right: \"butlast (take (length bl - n) bl) = take (length bl - Suc n) bl\"\n by (subst butlast_take) auto\n have \"(of_bl bl::'a::len word) >>> Suc n = sshiftr1 ((of_bl bl::'a::len word) >>> n)\"\n unfolding sshiftr_eq_funpow_sshiftr1 by simp\n also have \"\\ = of_bl (replicate (Suc n) (hd bl) @ take (length bl - Suc n) bl)\"\n apply (subst Suc.IH[OF Suc_leD[OF Suc.prems]])\n apply (subst sshiftr1_bl_of)\n subgoal using assms Suc.prems by simp\n apply (rule arg_cong[where f=of_bl])\n apply (subst butlast_append)\n unfolding left right using ne by simp\n finally show ?case .\n qed (transfer, simp)\n }\n note pos = this\n {\n assume n: \"LENGTH('a) \\ n\"\n have \"(of_bl bl::'a::len word) >>> n = (of_bl bl::'a::len word) >>> LENGTH('a)\"\n by (rule sshiftr_clamp[OF n])\n also have \"\\ = of_bl (replicate LENGTH('a) (hd bl) @ take (length bl - LENGTH('a)) bl)\"\n apply (rule pos) ..\n also have \"\\ = of_bl (replicate n (hd bl) @ take (length bl - n) bl)\"\n proof -\n have \"(of_bl (replicate LENGTH('a) (hd bl)) :: 'a word) = of_bl (replicate n (hd bl))\"\n apply (subst of_bl_drop'[symmetric, of \"n - LENGTH('a)\" \"replicate n (hd bl)\"])\n unfolding length_replicate by (auto simp: n)\n thus ?thesis by (simp add: assms n)\n qed\n finally have \"(of_bl bl::'a::len word) >>> n\n = of_bl (replicate n (hd bl) @ take (length bl - n) bl)\" .\n }\n thus ?thesis using pos by fastforce\nqed\n\ntext\\Like @{thm shiftr_bl}\\\nlemma sshiftr_bl: \"x >>> n \\ of_bl (replicate n (msb x) @ take (LENGTH('a) - n) (to_bl x))\"\n for x :: \"'a::len word\"\n unfolding word_msb_alt\n by (smt (z3) length_to_bl_eq sshiftr_bl_of word_bl.Rep_inverse)\n\nend","avg_line_length":36.171641791,"max_line_length":111,"alphanum_fraction":0.6346193522} {"size":437,"ext":"thy","lang":"Isabelle","max_stars_count":13.0,"content":"name: list-set-thm\nversion: 1.52\ndescription: Properties of list to set conversions\nauthor: Joe Leslie-Hurd \nlicense: HOLLight\nprovenance: HOL Light theory exported on 2019-05-03\nrequires: bool\nrequires: list-def\nrequires: list-dest\nrequires: list-length\nrequires: list-set-def\nrequires: natural\nrequires: set\nshow: \"Data.Bool\"\nshow: \"Data.List\"\nshow: \"Number.Natural\"\nshow: \"Set\"\n\nmain {\n article: \"list-set-thm.art\"\n}\n","avg_line_length":19.8636363636,"max_line_length":51,"alphanum_fraction":0.7597254005} {"size":719,"ext":"thy","lang":"Isabelle","max_stars_count":252.0,"content":"(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory Sep_Cancel_Set\nimports Separation_Algebra Sep_Tactic_Helpers\nbegin\n\nML {*\n structure SepCancel_Rules = Named_Thms (\n val name = @{binding \"sep_cancel\"}\n val description = \"sep_cancel rules\"\n )\n*}\n\nsetup SepCancel_Rules.setup\n\nlemma refl_imp: \"P \\ P\" by assumption\n\ndeclare refl_imp[sep_cancel]\n\ndeclare sep_conj_empty[sep_cancel]\nlemmas sep_conj_empty' = sep_conj_empty[simplified sep_conj_commute[symmetric]]\ndeclare sep_conj_empty'[sep_cancel]\n\n\nend\n","avg_line_length":21.1470588235,"max_line_length":79,"alphanum_fraction":0.7621696801} {"size":38004,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"(* Title: HOL\/Auth\/flash_data_cub_lemma_on_inv__1.thy\n Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The flash_data_cub Protocol Case Study*} \n\ntheory flash_data_cub_lemma_on_inv__1 imports flash_data_cub_base\nbegin\nsection{*All lemmas on causal relation between inv__1 and some rule r*}\nlemma n_PI_Remote_PutXVsinv__1:\nassumes a1: \"(\\ dst. dst\\N\\r=n_PI_Remote_PutX dst)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain dst where a1:\"dst\\N\\r=n_PI_Remote_PutX dst\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(dst=p__Inv4)\\(dst=p__Inv3)\\(dst~=p__Inv3\\dst~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(dst=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(dst=p__Inv3)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(dst~=p__Inv3\\dst~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_PI_Remote_ReplaceVsinv__1:\nassumes a1: \"(\\ src. src\\N\\r=n_PI_Remote_Replace src)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src where a1:\"src\\N\\r=n_PI_Remote_Replace src\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(src=p__Inv4)\\(src=p__Inv3)\\(src~=p__Inv3\\src~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(src=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(src=p__Inv3)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(src~=p__Inv3\\src~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_NI_Remote_Get_PutVsinv__1:\nassumes a1: \"(\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Put src dst)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src dst where a1:\"src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Put src dst\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(src=p__Inv4\\dst=p__Inv3)\\(src=p__Inv3\\dst=p__Inv4)\\(src=p__Inv4\\dst~=p__Inv3\\dst~=p__Inv4)\\(src~=p__Inv3\\src~=p__Inv4\\dst=p__Inv4)\\(src=p__Inv3\\dst~=p__Inv3\\dst~=p__Inv4)\\(src~=p__Inv3\\src~=p__Inv4\\dst=p__Inv3)\\(src~=p__Inv3\\src~=p__Inv4\\dst~=p__Inv3\\dst~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(src=p__Inv4\\dst=p__Inv3)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(src=p__Inv3\\dst=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(src=p__Inv4\\dst~=p__Inv3\\dst~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(src~=p__Inv3\\src~=p__Inv4\\dst=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(src=p__Inv3\\dst~=p__Inv3\\dst~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(src~=p__Inv3\\src~=p__Inv4\\dst=p__Inv3)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(src~=p__Inv3\\src~=p__Inv4\\dst~=p__Inv3\\dst~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_NI_Remote_Get_Put_HomeVsinv__1:\nassumes a1: \"(\\ dst. dst\\N\\r=n_NI_Remote_Get_Put_Home dst)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain dst where a1:\"dst\\N\\r=n_NI_Remote_Get_Put_Home dst\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(dst=p__Inv4)\\(dst=p__Inv3)\\(dst~=p__Inv3\\dst~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(dst=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(dst=p__Inv3)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(dst~=p__Inv3\\dst~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_NI_Remote_GetX_PutXVsinv__1:\nassumes a1: \"(\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_PutX src dst)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain src dst where a1:\"src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_PutX src dst\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(src=p__Inv4\\dst=p__Inv3)\\(src=p__Inv3\\dst=p__Inv4)\\(src=p__Inv4\\dst~=p__Inv3\\dst~=p__Inv4)\\(src~=p__Inv3\\src~=p__Inv4\\dst=p__Inv4)\\(src=p__Inv3\\dst~=p__Inv3\\dst~=p__Inv4)\\(src~=p__Inv3\\src~=p__Inv4\\dst=p__Inv3)\\(src~=p__Inv3\\src~=p__Inv4\\dst~=p__Inv3\\dst~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(src=p__Inv4\\dst=p__Inv3)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(src=p__Inv3\\dst=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(src=p__Inv4\\dst~=p__Inv3\\dst~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(src~=p__Inv3\\src~=p__Inv4\\dst=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(src=p__Inv3\\dst~=p__Inv3\\dst~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(src~=p__Inv3\\src~=p__Inv4\\dst=p__Inv3)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(src~=p__Inv3\\src~=p__Inv4\\dst~=p__Inv3\\dst~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_NI_Remote_GetX_PutX_HomeVsinv__1:\nassumes a1: \"(\\ dst. dst\\N\\r=n_NI_Remote_GetX_PutX_Home dst)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain dst where a1:\"dst\\N\\r=n_NI_Remote_GetX_PutX_Home dst\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(dst=p__Inv4)\\(dst=p__Inv3)\\(dst~=p__Inv3\\dst~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(dst=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(dst=p__Inv3)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(dst~=p__Inv3\\dst~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_NI_Remote_PutVsinv__1:\nassumes a1: \"(\\ dst. dst\\N\\r=n_NI_Remote_Put dst)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain dst where a1:\"dst\\N\\r=n_NI_Remote_Put dst\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(dst=p__Inv4)\\(dst=p__Inv3)\\(dst~=p__Inv3\\dst~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(dst=p__Inv4)\"\n have \"((formEval (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''InvMarked'')) (Const true)) s))\\((formEval (neg (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''InvMarked'')) (Const true))) s))\" by auto\n moreover {\n assume c1: \"((formEval (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''InvMarked'')) (Const true)) s))\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1 c1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n }\n moreover {\n assume c1: \"((formEval (neg (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''InvMarked'')) (Const true))) s))\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1 c1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n }\n ultimately have \"invHoldForRule s f r (invariants N)\" by satx\n}\nmoreover {\n assume b1: \"(dst=p__Inv3)\"\n have \"((formEval (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv3) ''InvMarked'')) (Const true)) s))\\((formEval (neg (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv3) ''InvMarked'')) (Const true))) s))\" by auto\n moreover {\n assume c1: \"((formEval (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv3) ''InvMarked'')) (Const true)) s))\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1 c1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n }\n moreover {\n assume c1: \"((formEval (neg (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv3) ''InvMarked'')) (Const true))) s))\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1 c1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n }\n ultimately have \"invHoldForRule s f r (invariants N)\" by satx\n}\nmoreover {\n assume b1: \"(dst~=p__Inv3\\dst~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_NI_Remote_PutXVsinv__1:\nassumes a1: \"(\\ dst. dst\\N\\r=n_NI_Remote_PutX dst)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain dst where a1:\"dst\\N\\r=n_NI_Remote_PutX dst\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(dst=p__Inv4)\\(dst=p__Inv3)\\(dst~=p__Inv3\\dst~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(dst=p__Inv4)\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv3) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(dst=p__Inv3)\"\n have \"?P3 s\"\n apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv3) ''Cmd'')) (Const UNI_PutX))))\" in exI, auto) done\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(dst~=p__Inv3\\dst~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_NI_InvVsinv__1:\nassumes a1: \"(\\ dst. dst\\N\\r=n_NI_Inv dst)\" and\na2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\ ?P2 s \\ ?P3 s\")\nproof -\nfrom a1 obtain dst where a1:\"dst\\N\\r=n_NI_Inv dst\" apply fastforce done\nfrom a2 obtain p__Inv3 p__Inv4 where a2:\"p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4\" apply fastforce done\nhave \"(dst=p__Inv4)\\(dst=p__Inv3)\\(dst~=p__Inv3\\dst~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n assume b1: \"(dst=p__Inv4)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(dst=p__Inv3)\"\n have \"?P1 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n assume b1: \"(dst~=p__Inv3\\dst~=p__Inv4)\"\n have \"?P2 s\"\n proof(cut_tac a1 a2 b1, auto) qed\n then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_NI_Local_Get_Get__part__1Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Get__part__1 src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Remote_GetVsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_PI_Remote_Get src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_9__part__0Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__0 N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_GetX_PutX__part__0Vsinv__1:\n assumes a1: \"r=n_PI_Local_GetX_PutX__part__0 \" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_WbVsinv__1:\n assumes a1: \"r=n_NI_Wb \" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_StoreVsinv__1:\n assumes a1: \"\\ src data. src\\N\\data\\N\\r=n_Store src data\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_5Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_PutX_5 N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_GetX__part__1Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__1 src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_InvAck_3Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_InvAck_3 N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_8_Home_NODE_GetVsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_7_NODE_Get__part__1Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_InvAck_1Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_InvAck_1 N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_GetX_GetX__part__1Vsinv__1:\n assumes a1: \"r=n_PI_Local_GetX_GetX__part__1 \" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_GetX_GetX__part__0Vsinv__1:\n assumes a1: \"r=n_PI_Local_GetX_GetX__part__0 \" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_Store_HomeVsinv__1:\n assumes a1: \"\\ data. data\\N\\r=n_Store_Home data\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_3Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_PutX_3 N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_ReplaceVsinv__1:\n assumes a1: \"r=n_PI_Local_Replace \" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_Nak__part__1Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__1 src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_Get_Nak__part__1Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__1 src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_Get_Get__part__0Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Get__part__0 src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_InvAck_existsVsinv__1:\n assumes a1: \"\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_InvAck_exists src pp\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_Nak__part__2Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__2 src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_Get_Put_HeadVsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Put_Head N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_PutXVsinv__1:\n assumes a1: \"r=n_PI_Local_PutX \" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_Get_Nak__part__2Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__2 src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_GetX__part__0Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_GetX__part__0 src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_6Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_PutX_6 N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_Get_PutVsinv__1:\n assumes a1: \"r=n_PI_Local_Get_Put \" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_ShWbVsinv__1:\n assumes a1: \"r=n_NI_ShWb N \" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_GetX_PutX_HeadVld__part__0Vsinv__1:\n assumes a1: \"r=n_PI_Local_GetX_PutX_HeadVld__part__0 N \" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_11Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_PutX_11 N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_ReplaceVsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Replace src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_1Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_PutX_1 N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_8_HomeVsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_PutX_8_Home N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_GetX_Nak_HomeVsinv__1:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Remote_GetX_Nak_Home dst\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_7__part__0Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__0 N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_PutXAcksDoneVsinv__1:\n assumes a1: \"r=n_NI_Local_PutXAcksDone \" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_GetX_NakVsinv__1:\n assumes a1: \"\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_GetX_Nak src dst\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_NakVsinv__1:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Nak dst\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_9__part__1Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_PutX_9__part__1 N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Remote_GetXVsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_PI_Remote_GetX src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_GetX_PutX__part__1Vsinv__1:\n assumes a1: \"r=n_PI_Local_GetX_PutX__part__1 \" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_Get_Nak_HomeVsinv__1:\n assumes a1: \"\\ dst. dst\\N\\r=n_NI_Remote_Get_Nak_Home dst\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_10Vsinv__1:\n assumes a1: \"\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_10 N src pp\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_8Vsinv__1:\n assumes a1: \"\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8 N src pp\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_Get_PutVsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Put src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_8_NODE_GetVsinv__1:\n assumes a1: \"\\ src pp. src\\N\\pp\\N\\src~=pp\\r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_2Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_PutX_2 N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_Nak__part__0Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_Nak__part__0 src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_InvAck_exists_HomeVsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_InvAck_exists_Home src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Replace_HomeVsinv__1:\n assumes a1: \"r=n_NI_Replace_Home \" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_PutVsinv__1:\n assumes a1: \"r=n_NI_Local_Put \" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_7__part__1Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7__part__1 N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Remote_Get_NakVsinv__1:\n assumes a1: \"\\ src dst. src\\N\\dst\\N\\src~=dst\\r=n_NI_Remote_Get_Nak src dst\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Nak_ClearVsinv__1:\n assumes a1: \"r=n_NI_Nak_Clear \" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_Get_Put_DirtyVsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Put_Dirty src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_Get_Nak__part__0Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_Get_Nak__part__0 src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_Get_GetVsinv__1:\n assumes a1: \"r=n_PI_Local_Get_Get \" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Nak_HomeVsinv__1:\n assumes a1: \"r=n_NI_Nak_Home \" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_10_HomeVsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_PutX_10_Home N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_InvAck_2Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_InvAck_2 N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_PI_Local_GetX_PutX_HeadVld__part__1Vsinv__1:\n assumes a1: \"r=n_PI_Local_GetX_PutX_HeadVld__part__1 N \" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_FAckVsinv__1:\n assumes a1: \"r=n_NI_FAck \" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_4Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_PutX_4 N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \n\nlemma n_NI_Local_GetX_PutX_7_NODE_Get__part__0Vsinv__1:\n assumes a1: \"\\ src. src\\N\\r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src\" and\n a2: \"(\\ p__Inv3 p__Inv4. p__Inv3\\N\\p__Inv4\\N\\p__Inv3~=p__Inv4\\f=inv__1 p__Inv3 p__Inv4)\"\n shows \"invHoldForRule s f r (invariants N)\"\n apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n \nend\n","avg_line_length":47.6838143036,"max_line_length":394,"alphanum_fraction":0.7127670771} {"size":2104,"ext":"thy","lang":"Isabelle","max_stars_count":62.0,"content":"(* Victor B. F. Gomes, University of Cambridge\n Martin Kleppmann, University of Cambridge\n Dominic P. Mulligan, University of Cambridge\n*)\n\nsection\\Increment-Decrement Counter\\\n \ntext\\The Increment-Decrement Counter is perhaps the simplest CRDT, and a paradigmatic example of a\n replicated data structure with commutative operations.\\\n\ntheory\n Counter\nimports\n Network\n \"~~\/src\/HOL\/Library\/Code_Target_Numeral\"\nbegin\n\ndatatype operation = Increment | Decrement\n\nfun counter_op :: \"operation \\ int \\ int\" where\n \"counter_op Increment x = Some (x + 1)\" |\n \"counter_op Decrement x = Some (x - 1)\"\n \nexport_code Increment counter_op in OCaml file \"ocaml\/counter.ml\"\n\nlocale counter = network_with_ops _ counter_op 0\n\nlemma (in counter) \"counter_op x \\ counter_op y = counter_op y \\ counter_op x\"\n by(case_tac x; case_tac y; auto simp add: kleisli_def)\n\nlemma (in counter) concurrent_operations_commute:\n assumes \"xs prefix of i\"\n shows \"hb.concurrent_ops_commute (node_deliver_messages xs)\"\n using assms\n apply(clarsimp simp: hb.concurrent_ops_commute_def)\n apply(unfold interp_msg_def, simp)\n apply(case_tac \"b\"; case_tac \"ba\")\n apply(auto simp add: kleisli_def)\ndone\n \ncorollary (in counter) counter_convergence:\n assumes \"set (node_deliver_messages xs) = set (node_deliver_messages ys)\"\n and \"xs prefix of i\"\n and \"ys prefix of j\"\n shows \"apply_operations xs = apply_operations ys\"\nusing assms by(auto simp add: apply_operations_def intro: hb.convergence_ext concurrent_operations_commute\n node_deliver_messages_distinct hb_consistent_prefix)\n\ncontext counter begin\n\nsublocale sec: strong_eventual_consistency weak_hb hb interp_msg\n \"\\ops. \\xs i. xs prefix of i \\ node_deliver_messages xs = ops\" 0\n apply(standard; clarsimp)\n apply(auto simp add: hb_consistent_prefix drop_last_message node_deliver_messages_distinct concurrent_operations_commute)\n apply(metis (full_types) interp_msg_def counter_op.elims)\n using drop_last_message apply blast\ndone\n\nend\nend","avg_line_length":35.0666666667,"max_line_length":127,"alphanum_fraction":0.7690114068} {"size":1686,"ext":"thy","lang":"Isabelle","max_stars_count":1.0,"content":"theory T74\nimports Main\nbegin\nlemma \"(\n(\\ x::nat. \\ y::nat. meet(x, y) = meet(y, x)) &\n(\\ x::nat. \\ y::nat. join(x, y) = join(y, x)) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(x, meet(y, z)) = meet(meet(x, y), z)) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(x, join(y, z)) = join(join(x, y), z)) &\n(\\ x::nat. \\ y::nat. meet(x, join(x, y)) = x) &\n(\\ x::nat. \\ y::nat. join(x, meet(x, y)) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(x, join(y, z)) = join(mult(x, y), mult(x, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. mult(join(x, y), z) = join(mult(x, z), mult(y, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(x, over(join(mult(x, y), z), y)) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. meet(y, undr(x, join(mult(x, y), z))) = y) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(mult(over(x, y), y), x) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. join(mult(y, undr(y, x)), x) = x) &\n(\\ x::nat. \\ y::nat. \\ z::nat. over(join(x, y), z) = join(over(x, z), over(y, z))) &\n(\\ x::nat. \\ y::nat. \\ z::nat. over(x, meet(y, z)) = join(over(x, y), over(x, z))) &\n(\\ x::nat. \\ y::nat. invo(join(x, y)) = meet(invo(x), invo(y))) &\n(\\ x::nat. \\ y::nat. invo(meet(x, y)) = join(invo(x), invo(y))) &\n(\\ x::nat. invo(invo(x)) = x)\n) \\\n(\\ x::nat. \\ y::nat. \\ z::nat. undr(x, join(y, z)) = join(undr(x, y), undr(x, z)))\n\"\nnitpick[card nat=4,timeout=86400]\noops\nend","avg_line_length":62.4444444444,"max_line_length":108,"alphanum_fraction":0.534400949} {"size":77949,"ext":"thy","lang":"Isabelle","max_stars_count":2.0,"content":"(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory HeapLift\nimports\n TypHeapSimple\n CorresXF\n L2Defs\n ExecConcrete\n AbstractArrays\n \"..\/lib\/LemmaBucket_C\"\nbegin\n\ndefinition \"L2Tcorres st A C = corresXF st (\\r _. r) (\\r _. r) \\ A C\"\n\nlemma L2Tcorres_id:\n \"L2Tcorres id C C\"\n by (metis L2Tcorres_def corresXF_id)\n\nlemma L2Tcorres_fail:\n \"L2Tcorres st L2_fail X\"\n apply (clarsimp simp: L2Tcorres_def L2_defs)\n apply (rule corresXF_fail)\n done\n\n(* Abstraction predicates for inner expressions. *)\ndefinition \"abs_guard st A C \\ \\s. A (st s) \\ C s\"\ndefinition \"abs_expr st P A C \\ \\s. P (st s) \\ C s = A (st s)\"\ndefinition \"abs_modifies st P A C \\ \\s. P (st s) \\ st (C s) = A (st s)\"\n\n(* Predicates to enable some transformations on the input expressions\n (namely, rewriting uses of field_lvalue) that are best done\n as a preprocessing stage (st = id).\n The corresTA rules should ensure that these are used to rewrite\n any inner expressions before handing off to the predicates above. *)\ndefinition \"struct_rewrite_guard A C \\ \\s. A s \\ C s\"\ndefinition \"struct_rewrite_expr P A C \\ \\s. P s \\ C s = A s\"\ndefinition \"struct_rewrite_modifies P A C \\ \\s. P s \\ C s = A s\"\n\n\n(* fun_app2 is like fun_app, but it skips an abstraction.\n * We use this for terms like \"\\s a. Array.update a k (f s)\".\n * FIXME: ideally, the first order conversion code can skip abstractions. *)\nlemma abs_expr_fun_app2 [heap_abs_fo]:\n \"\\ abs_expr st P f' f;\n abs_expr st Q g' g \\ \\\n abs_expr st (\\s. P s \\ Q s) (\\s a. f' s a (g' s a)) (\\s a. f s a $ g s a)\"\n by (simp add: abs_expr_def)\n\nlemma abs_expr_fun_app [heap_abs_fo]:\n \"\\ abs_expr st Y b' b; abs_expr st X a' a \\ \\\n abs_expr st (\\s. X s \\ Y s) (\\s. a' s (b' s)) (\\s. a s $ b s)\"\n apply (clarsimp simp: abs_expr_def)\n done\n\nlemma abs_expr_constant [heap_abs]:\n \"abs_expr st \\ (\\s. a) (\\s. a)\"\n apply (clarsimp simp: abs_expr_def)\n done\n\nlemma abs_guard_expr [heap_abs]:\n \"abs_expr st P a' a \\ abs_guard st (\\s. P s \\ a' s) a\"\n by (simp add: abs_expr_def abs_guard_def)\n\nlemma abs_guard_constant [heap_abs]:\n \"abs_guard st (\\_. P) (\\_. P)\"\n by (clarsimp simp: abs_guard_def)\n\nlemma abs_guard_conj [heap_abs]:\n \"\\ abs_guard st G G'; abs_guard st H H' \\\n \\ abs_guard st (\\s. G s \\ H s) (\\s. G' s \\ H' s)\"\n by (clarsimp simp: abs_guard_def)\n\n\nlemma L2Tcorres_modify [heap_abs]:\n \"\\ struct_rewrite_modifies P b c; abs_guard st P' P;\n abs_modifies st Q a b \\ \\\n L2Tcorres st (L2_seq (L2_guard (\\s. P' s \\ Q s)) (\\_. (L2_modify a))) (L2_modify c)\"\n apply (monad_eq simp: corresXF_def L2Tcorres_def L2_defs abs_modifies_def abs_guard_def struct_rewrite_modifies_def struct_rewrite_guard_def)\n done\n\nlemma L2Tcorres_gets [heap_abs]:\n \"\\ struct_rewrite_expr P b c; abs_guard st P' P;\n abs_expr st Q a b \\ \\\n L2Tcorres st (L2_seq (L2_guard (\\s. P' s \\ Q s)) (\\_. L2_gets a n)) (L2_gets c n)\"\n apply (monad_eq simp: corresXF_def L2Tcorres_def L2_defs abs_expr_def abs_guard_def struct_rewrite_expr_def struct_rewrite_guard_def)\n done\n\nlemma L2Tcorres_gets_const [heap_abs]:\n \"L2Tcorres st (L2_gets (\\_. a) n) (L2_gets (\\_. a) n)\"\n apply (monad_eq simp: corresXF_def L2Tcorres_def L2_defs)\n done\n\nlemma L2Tcorres_guard [heap_abs]:\n \"\\ struct_rewrite_guard b c; abs_guard st a b \\ \\\n L2Tcorres st (L2_guard a) (L2_guard c)\"\n apply (monad_eq simp: corresXF_def L2Tcorres_def L2_defs abs_guard_def struct_rewrite_guard_def)\n done\n\nlemma L2Tcorres_recguard [heap_abs]:\n \"\\ L2Tcorres st A C \\ \\ L2Tcorres st (L2_recguard n A) (L2_recguard n C)\"\n apply (monad_eq simp: corresXF_def L2Tcorres_def L2_defs Ball_def Bex_def split: sum.splits)\n done\n\nlemma L2Tcorres_while [heap_abs]:\n assumes body_corres: \"\\x. L2Tcorres st (B' x) (B x)\"\n and cond_rewrite: \"\\r. struct_rewrite_expr (G r) (C' r) (C r)\"\n and guard_abs: \"\\r. abs_guard st (G' r) (G r)\"\n and guard_impl_cond: \"\\r. abs_expr st (H r) (C'' r) (C' r)\"\n shows \"L2Tcorres st (L2_guarded_while (\\i s. G' i s \\ H i s) C'' B' i n) (L2_while C B i n)\"\nproof -\n have cond_match: \"\\r s. G' r (st s) \\ H r (st s) \\ C'' r (st s) = C r s\"\n using cond_rewrite guard_abs guard_impl_cond\n by (clarsimp simp: abs_expr_def abs_guard_def struct_rewrite_expr_def)\n\n have \"corresXF st (\\r _. r) (\\r _. r) (\\_. True)\n (doE _ \\ guardE (\\s. G' i s \\ H i s);\n whileLoopE C''\n (\\i. doE r \\ B' i;\n _ \\ guardE (\\s. G' r s \\ H r s);\n returnOk r\n odE) i\n odE)\n (whileLoopE C B i)\"\n apply (rule corresXF_guard_imp)\n apply (rule corresXF_guarded_while [where P=\"\\_ _. True\" and P'=\"\\_ _. True\"])\n apply (clarsimp cong: corresXF_cong)\n apply (rule corresXF_guard_imp)\n apply (rule body_corres [unfolded L2Tcorres_def])\n apply simp\n apply (clarsimp simp: cond_match)\n apply clarsimp\n apply (rule hoareE_TrueI)\n apply simp\n apply simp\n apply simp\n done\n\n thus ?thesis\n by (clarsimp simp: L2Tcorres_def L2_defs\n guardE_def returnOk_liftE)\nqed\n\ndefinition \"abs_spec st P (A :: ('a \\ 'a) set) (C :: ('c \\ 'c) set)\n \\ (\\s t. P (st s) \\ (((s, t) \\ C) \\ ((st s, st t) \\ A)))\n \\ (\\s. P (st s) \\ (\\x. (st s, x) \\ A) \\ (\\x. (s, x) \\ C))\"\n\nlemma L2Tcorres_spec [heap_abs]:\n \"\\ abs_spec st P A C \\\n \\ L2Tcorres st (L2_seq (L2_guard P) (\\_. (L2_spec A))) (L2_spec C)\"\n apply (monad_eq simp: corresXF_def L2Tcorres_def L2_defs image_def set_eq_UNIV\n split_def Ball_def state_select_def abs_spec_def split: sum.splits)\n done\n\nlemma abs_spec_constant [heap_abs]:\n \"abs_spec st \\ {(a, b). C} {(a, b). C}\"\n apply (clarsimp simp: abs_spec_def)\n done\n\nlemma L2Tcorres_condition [heap_abs]:\n \"\\ L2Tcorres st L L';\n L2Tcorres st R R';\n struct_rewrite_expr P C' C;\n abs_guard st P' P;\n abs_expr st Q C'' C' \\ \\\n L2Tcorres st (L2_seq (L2_guard (\\s. P' s \\ Q s)) (\\_. L2_condition C'' L R)) (L2_condition C L' R')\"\n apply (clarsimp simp: L2_defs L2Tcorres_def abs_expr_def abs_guard_def struct_rewrite_expr_def struct_rewrite_guard_def)\n apply (rule corresXF_exec_abs_guard [unfolded guardE_def])\n apply (rule corresXF_cond)\n apply (metis corresXF_guard_imp)\n apply (metis corresXF_guard_imp)\n apply simp\n done\n\nlemma L2Tcorres_seq [heap_abs]:\n \"\\ L2Tcorres st L' L; \\r. L2Tcorres st (\\s. R' r s) (\\s. R r s) \\\n \\ L2Tcorres st (L2_seq L' (\\r s. R' r s)) (L2_seq L (\\r s. R r s))\"\n apply (clarsimp simp: L2Tcorres_def L2_defs)\n apply (rule corresXF_guard_imp)\n apply (erule corresXF_join [where P'=\"\\x y s. x = y\" and Q=\"\\_. True\"])\n apply (metis (full_types) corresXF_assume_pre)\n apply simp\n apply (rule hoareE_TrueI)\n apply simp\n apply simp\n done\n\nlemma L2Tcorres_catch [heap_abs]:\n \"\\ L2Tcorres st L L';\n \\r. L2Tcorres st (\\s. R r s) (\\s. R' r s)\n \\ \\ L2Tcorres st (L2_catch L (\\r s. R r s)) (L2_catch L' (\\r s. R' r s))\"\n apply (clarsimp simp: L2Tcorres_def L2_defs)\n apply (rule corresXF_guard_imp)\n apply (erule corresXF_except [where P'=\"\\x y s. x = y\" and Q=\"\\_. True\"])\n apply (metis (full_types) corresXF_assume_pre)\n apply simp\n apply (rule hoareE_TrueI)\n apply simp\n apply simp\n done\n\nlemma L2Tcorres_unknown [heap_abs]:\n \"L2Tcorres st (L2_unknown name) (L2_unknown name)\"\n apply (clarsimp simp: L2_unknown_def selectE_def[symmetric])\n apply (clarsimp simp: L2Tcorres_def)\n apply (auto intro!: corresXF_select_select)\n done\n\nlemma L2Tcorres_throw [heap_abs]:\n \"L2Tcorres st (L2_throw x n) (L2_throw x n)\"\n apply (clarsimp simp: L2Tcorres_def L2_defs)\n apply (rule corresXF_throw)\n apply simp\n done\n\nlemma L2Tcorres_split [heap_abs]:\n \"\\ \\x y. L2Tcorres st (P x y) (P' x y) \\ \\\n L2Tcorres st (case a of (x, y) \\ P x y) (case a of (x, y) \\ P' x y)\"\n apply (clarsimp simp: split_def)\n done\n\nlemma L2Tcorres_seq_unused_result [heap_abs]:\n \"\\ L2Tcorres st L L'; L2Tcorres st R R' \\ \\ L2Tcorres st (L2_seq L (\\_. R)) (L2_seq L' (\\_. R'))\"\n apply (rule L2Tcorres_seq, auto)\n done\n\nlemma abs_expr_split [heap_abs]:\n \"\\ \\a b. abs_expr st (P a b) (A a b) (C a b) \\\n \\ abs_expr st (case r of (a, b) \\ P a b)\n (case r of (a, b) \\ A a b) (case r of (a, b) \\ C a b)\"\n apply (auto simp: split_def)\n done\n\nlemma abs_guard_split [heap_abs]:\n \"\\ \\a b. abs_guard st (A a b) (C a b) \\\n \\ abs_guard st (case r of (a, b) \\ A a b) (case r of (a, b) \\ C a b)\"\n apply (auto simp: split_def)\n done\n\nlemma L2Tcorres_recguard_0:\n \"L2Tcorres st (L2_recguard 0 A) C\"\n apply (monad_eq simp: corresXF_def L2Tcorres_def L2_defs)\n done\n\nlemma L2Tcorres_abstract_fail [heap_abs]:\n \"L2Tcorres st L2_fail L2_fail\"\n apply (clarsimp simp: L2Tcorres_def L2_defs)\n apply (rule corresXF_fail)\n done\n\nlemma abs_expr_id [heap_abs]:\n \"abs_expr id \\ A A\"\n apply (clarsimp simp: abs_expr_def)\n done\n\nlemma abs_expr_lambda_null [heap_abs]:\n \"abs_expr st P A C \\ abs_expr st P (\\s r. A s) (\\s r. C s)\"\n apply (clarsimp simp: abs_expr_def)\n done\n\nlemma abs_modify_id [heap_abs]:\n \"abs_modifies id \\ A A\"\n apply (clarsimp simp: abs_modifies_def)\n done\n\nlemma L2Tcorres_exec_concrete [heap_abs]:\n \"L2Tcorres id A C \\ L2Tcorres st (exec_concrete st (L2_call A)) (L2_call C)\"\n apply (clarsimp simp: L2Tcorres_def L2_call_def)\n apply (rule corresXF_exec_concrete)\n apply (rule corresXF_except)\n apply assumption\n apply (rule corresXF_fail)\n apply wp[1]\n apply simp\n done\n\nlemma L2Tcorres_exec_abstract [heap_abs]:\n \"L2Tcorres st A C \\ L2Tcorres id (exec_abstract st (L2_call A)) (L2_call C)\"\n apply (clarsimp simp: L2_call_def L2Tcorres_def)\n apply (rule corresXF_exec_abstract)\n apply (rule corresXF_except)\n apply assumption\n apply (rule corresXF_fail)\n apply wp[1]\n apply simp\n done\n\nlemma L2Tcorres_call [heap_abs]:\n \"L2Tcorres st A C \\ L2Tcorres st (L2_call A) (L2_call C)\"\n unfolding L2Tcorres_def L2_call_def\n apply (rule corresXF_except)\n apply simp\n apply (rule corresXF_fail)\n apply (rule hoareE_TrueI)\n apply simp\n done\n\nlemma L2Tcorres_measure_call [heap_abs]:\n \"\\ monad_mono C; \\m. L2Tcorres st (A m) (C m) \\\n \\ L2Tcorres st (measure_call A) (measure_call C)\"\n apply (unfold L2Tcorres_def)\n apply (erule corresXF_measure_call)\n apply assumption\n done\n\n(*\n * Assert the given abstracted heap (accessed using \"getter\" and \"setter\") for type\n * \"'a\" is a valid abstraction w.r.t. the given state translation functions.\n *)\n\ndefinition\n \"read_write_valid r w \\\n (\\f s. r (w f s) = f (r s))\n \\ (\\s f. f (r s) = (r s) \\ w f s = s)\n \\ (\\f f' s. (f (r s) = f' (r s)) \\ w f s = w f' s)\n \\ (\\f g s. w f (w g s) = w (\\x. f (g x)) s)\"\n\nlemma read_write_validI:\n \"\\ \\f s. r (w f s) = f (r s);\n \\f s. f (r s) = r s \\ w f s = s;\n \\f f' s. f (r s) = f' (r s) \\ w f s = w f' s;\n \\f g s. w f (w g s) = w (\\x. f (g x)) s\n \\ \\ read_write_valid r w\"\n unfolding read_write_valid_def by metis\n\nlemma read_write_write_id: \"read_write_valid r w \\ w (\\x. x) s = s\"\n by (simp add: read_write_valid_def)\n\nlemma read_write_valid_def1:\n \"read_write_valid r w \\ r (w f s) = f (r s)\"\n by (metis read_write_valid_def)\n\nlemma read_write_valid_def2:\n \"\\ read_write_valid r w; f (r s) = r s \\ \\ w f s = s\"\n by (metis read_write_valid_def)\n\nlemma read_write_valid_def3:\n \"\\ read_write_valid r w; f (r s) = f' (r s) \\ \\ w f s = w f' s\"\n by (metis read_write_valid_def)\n\nlemma read_write_o:\n \"\\ read_write_valid r w; \\x. h x = f (g x) \\ \\ w f (w g s) = w h s\"\n apply (subst (asm) read_write_valid_def)\n apply metis\n done\n\n\ndefinition [simp]:\n \"valid_implies_cguard st v\\<^sub>r \\ \\s p. v\\<^sub>r (st s) p \\ c_guard p\"\n\ndefinition [simp]:\n \"heap_decode_bytes st v\\<^sub>r h\\<^sub>r t_hrs\\<^sub>r \\ \\s p. v\\<^sub>r (st s) p \\\n h\\<^sub>r (st s) p = h_val (hrs_mem (t_hrs\\<^sub>r s)) p\"\n\ndefinition [simp]:\n \"heap_encode_bytes st v\\<^sub>r h\\<^sub>w t_hrs\\<^sub>w \\\n \\s p x. v\\<^sub>r (st s) p \\\n st (t_hrs\\<^sub>w (hrs_mem_update (heap_update p x)) s) =\n h\\<^sub>w (\\f. f(p := x)) (st s)\"\n\ndefinition [simp]:\n \"write_preserves_valid v\\<^sub>r h\\<^sub>w \\\n (\\p f s. v\\<^sub>r s p \\ v\\<^sub>r (h\\<^sub>w f s) p)\"\n\ndefinition\n valid_typ_heap ::\n \"('s \\ 't) \\\n ('t \\ ('a::c_type) ptr \\ 'a) \\\n ((('a ptr \\ 'a) \\ ('a ptr \\ 'a)) \\ 't \\ 't) \\\n ('t \\ ('a::c_type) ptr \\ bool) \\\n ((('a ptr \\ bool) \\ ('a ptr \\ bool)) \\ 't \\ 't) \\\n ('s \\ heap_raw_state) \\\n ((heap_raw_state \\ heap_raw_state) \\ 's \\ 's) \\\n bool\"\nwhere\n \"valid_typ_heap st getter setter vgetter vsetter t_hrs t_hrs_update \\\n (read_write_valid getter setter)\n \\ (read_write_valid vgetter vsetter)\n \\ (read_write_valid t_hrs t_hrs_update)\n \\ (valid_implies_cguard st vgetter)\n \\ (heap_decode_bytes st vgetter getter t_hrs)\n \\ (heap_encode_bytes st vgetter setter t_hrs_update)\n \\ (write_preserves_valid vgetter setter)\"\n\nlemma valid_typ_heapI [intro!]:\n assumes getter_setter_idem: \"\\s x. getter (setter x s) = x (getter s)\"\n and setter_getter_idem: \"\\s f. f (getter s) = (getter s) \\ setter f s = s\"\n and setter_static: \"\\s f f'. f (getter s) = f' (getter s) \\ setter f s = setter f' s\"\n and setter_chain: \"\\s f g. setter f (setter g s) = setter (\\x. f (g x)) s\"\n and vgetter_setter_idem: \"\\s x. vgetter (vsetter x s) = x (vgetter s)\"\n and vsetter_getter_idem: \"\\s f. f (vgetter s) = (vgetter s) \\ vsetter f s = s\"\n and vsetter_static: \"\\s f f'. f (vgetter s) = f' (vgetter s) \\ vsetter f s = vsetter f' s\"\n and vsetter_chain: \"\\s f g. vsetter f (vsetter g s) = vsetter (\\x. f (g x)) s\"\n and getter_implies_safe: \"\\s p. vgetter (st s) p \\ c_guard p\"\n and getter_data_correct: \"\\s p. vgetter (st s) p \\\n getter (st s) p = h_val (hrs_mem (t_hrs s)) p\"\n and setter_keeps_vgetter: \"\\s f p. vgetter s p \\ vgetter (setter f s) p\"\n and abs_update_matches_conc_update:\n \"\\s p v. vgetter (st s) p \\\n st (t_hrs_update (hrs_mem_update (heap_update p v)) s) =\n setter (\\x. x(p := v)) (st s)\"\n and t_hrs_set_get: \"\\s x. t_hrs (t_hrs_update x s) = x (t_hrs s)\"\n and t_hrs_get_set: \"\\s f. f (t_hrs s) = t_hrs s \\ t_hrs_update f s = s\"\n and t_hrs_set_static: \"\\s f f'. f (t_hrs s) = f' (t_hrs s) \\ t_hrs_update f s = t_hrs_update f' s\"\n and t_hrs_set_chain: \"\\s f g. t_hrs_update f (t_hrs_update g s) = t_hrs_update (\\x. f (g x)) s\"\n shows \"valid_typ_heap st getter setter vgetter vsetter t_hrs t_hrs_update\"\n apply (clarsimp simp: valid_typ_heap_def read_write_valid_def)\n apply (safe | fact | rule ext)+\n done\n\nlemma read_write_valid_fg_cons:\n \"read_write_valid r w \\ fg_cons r (w \\ (\\x _. x))\"\n unfolding read_write_valid_def fg_cons_def o_def\n by metis\n\n(*\n * Assert the given field (\"field_getter\", \"field_setter\") of the given structure\n * can be abstracted into the heap, and then accessed as a HOL object.\n *)\n\n(*\n * This can deal with nested structures, but they must be packed_types.\n * FIXME: generalise this framework to mem_types\n *)\ndefinition\n valid_struct_field\n :: \"('s \\ 't)\n \\ string list\n \\ (('p::packed_type) \\ ('f::packed_type))\n \\ (('f \\ 'f) \\ ('p \\ 'p))\n \\ ('s \\ heap_raw_state)\n \\ ((heap_raw_state \\ heap_raw_state) \\ 's \\ 's)\n \\ bool\"\n where\n \"valid_struct_field st field_name field_getter field_setter t_hrs t_hrs_update \\\n (read_write_valid field_getter field_setter\n \\ field_ti TYPE('p) field_name =\n Some (adjust_ti (typ_info_t TYPE('f)) field_getter (field_setter \\ (\\x _. x)))\n \\ (\\p :: 'p ptr. c_guard p \\ c_guard (Ptr &(p\\field_name) :: 'f ptr))\n \\ read_write_valid t_hrs t_hrs_update)\"\n\nlemma valid_struct_fieldI [intro]:\n fixes st :: \"'s \\ 't\"\n fixes field_getter :: \"('a::packed_type) \\ ('f::packed_type)\"\n shows \"\\\n \\s f. f (field_getter s) = (field_getter s) \\ field_setter f s = s;\n \\s f f'. f (field_getter s) = f' (field_getter s) \\ field_setter f s = field_setter f' s;\n \\s f. field_getter (field_setter f s) = f (field_getter s);\n \\s f g. field_setter f (field_setter g s) = field_setter (f \\ g) s;\n field_ti TYPE('a) field_name =\n Some (adjust_ti (typ_info_t TYPE('f)) field_getter (field_setter \\ (\\x _. x)));\n \\(p::'a ptr). c_guard p \\ c_guard (Ptr &(p\\field_name) :: 'f ptr);\n \\s x. t_hrs (t_hrs_update x s) = x (t_hrs s);\n \\s f. f (t_hrs s) = t_hrs s \\ t_hrs_update f s = s;\n \\s f f'. f (t_hrs s) = f' (t_hrs s) \\ t_hrs_update f s = t_hrs_update f' s;\n \\s f g. t_hrs_update f (t_hrs_update g s) = t_hrs_update (\\x. f (g x)) s\n \\ \\\n valid_struct_field st field_name field_getter field_setter t_hrs t_hrs_update\"\n apply (unfold valid_struct_field_def read_write_valid_def o_def)\n apply (safe | assumption | rule ext)+\n done\n\n(*\n * This cannot deal with struct nesting, but works for general mem_types.\n *)\ndefinition\n valid_struct_field_legacy\n :: \"('s \\ 't)\n \\ string list\n \\ ('p \\ ('f::c_type))\n \\ ('f \\ 'p \\ 'p)\n \\ ('t \\ (('p::c_type) ptr \\ 'p))\n \\ ((('p ptr \\ 'p) \\ ('p ptr \\ 'p)) \\ 't \\ 't)\n \\ ('t \\ (('p::c_type) ptr \\ bool))\n \\ ((('p ptr \\ bool) \\ ('p ptr \\ bool)) \\ 't \\ 't)\n \\ ('s \\ heap_raw_state)\n \\ ((heap_raw_state \\ heap_raw_state) \\ 's \\ 's)\n \\ bool\"\nwhere\n \"valid_struct_field_legacy st field_name field_getter field_setter\n getter setter vgetter vsetter t_hrs t_hrs_update \\\n (\\s p. vgetter (st s) p \\\n h_val (hrs_mem (t_hrs s)) (Ptr &(p\\field_name))\n = field_getter (getter (st s) p))\n \\ (\\s p val. vgetter (st s) p \\\n st (t_hrs_update (hrs_mem_update (heap_update (Ptr &(p\\field_name)) val)) s) =\n setter (\\old. old(p := (field_setter val (old p)))) (st s))\n \\ (\\s p. vgetter (st s) p \\ c_guard p)\n \\ (\\p. c_guard (p :: 'p ptr) \\ c_guard (Ptr &(p\\field_name) :: 'f ptr))\"\n\nlemma valid_struct_field_legacyI [intro]:\n fixes st :: \"'s \\ 't\"\n fixes field_getter :: \"('a::c_type) \\ ('f::c_type)\"\n shows \"\\ \\s p. vgetter (st s) p \\\n h_val (hrs_mem (t_hrs s)) (Ptr &(p\\field_name)) = field_getter (getter (st s) p);\n \\s p val. vgetter (st s) p \\\n st (t_hrs_update (hrs_mem_update (heap_update (Ptr &(p\\field_name)) val)) s) =\n setter (\\old. old(p := (field_setter val (old p)))) (st s);\n \\s p. vgetter (st s) p \\ c_guard p;\n \\(p::'a ptr). c_guard p \\ c_guard (Ptr &(p\\field_name) :: 'f ptr) \\ \\\n valid_struct_field_legacy st field_name field_getter field_setter getter setter vgetter vsetter t_hrs t_hrs_update\"\n apply (fastforce simp: valid_struct_field_legacy_def)\n done\n\n\n\nlemma valid_typ_heap_get_hvalD:\n \"\\ valid_typ_heap st getter setter vgetter vsetter\n t_hrs t_hrs_update; vgetter (st s) p \\ \\\n h_val (hrs_mem (t_hrs s)) p = getter (st s) p\"\n apply (clarsimp simp: valid_typ_heap_def)\n done\n\nlemma valid_typ_heap_t_hrs_updateD:\n \"\\ valid_typ_heap st getter setter vgetter vsetter\n t_hrs t_hrs_update; vgetter (st s) p \\ \\\n st (t_hrs_update (hrs_mem_update (heap_update p v')) s) =\n setter (\\x. x(p := v')) (st s)\"\n apply (clarsimp simp: valid_typ_heap_def)\n done\n\n\nlemma heap_abs_expr_guard [heap_abs]:\n \"\\ valid_typ_heap st getter setter vgetter vsetter t_hrs t_hrs_update;\n abs_expr st P x' x \\ \\\n abs_guard st (\\s. P s \\ vgetter s (x' s)) (\\s. (c_guard (x s :: ('a::c_type) ptr)))\"\n apply (clarsimp simp: abs_expr_def abs_guard_def\n simple_lift_def heap_ptr_valid_def valid_typ_heap_def)\n done\n\nlemma heap_abs_expr_h_val [heap_abs]:\n \"\\ valid_typ_heap st getter setter vgetter vsetter t_hrs t_hrs_update;\n abs_expr st P x' x \\ \\\n abs_expr st\n (\\s. P s \\ vgetter s (x' s))\n (\\s. (getter s (x' s)))\n (\\s. (h_val (hrs_mem (t_hrs s))) (x s))\"\n apply (clarsimp simp: abs_expr_def simple_lift_def)\n apply (metis valid_typ_heap_get_hvalD)\n done\n\nlemma heap_abs_modifies_heap_update__unused:\n \"\\ valid_typ_heap st getter setter vgetter vsetter t_hrs t_hrs_update;\n abs_expr st Pb b' b;\n abs_expr st Pc c' c \\ \\\n abs_modifies st (\\s. Pb s \\ Pc s \\ vgetter s (b' s))\n (\\s. setter (\\x. x(b' s := (c' s))) s)\n (\\s. t_hrs_update (hrs_mem_update (heap_update (b s :: ('a::c_type) ptr) (c s))) s)\"\n apply (clarsimp simp: typ_simple_heap_simps abs_expr_def abs_modifies_def)\n apply (metis valid_typ_heap_t_hrs_updateD)\n done\n\n(* See comment for heap_lift__wrap_h_val. *)\ndefinition \"heap_lift__h_val \\ h_val\"\n\n(* See the comment for struct_rewrite_modifies_field.\n * In this case we rely on nice unification for ?c.\n * The heap_abs_syntax generator also relies on this rule\n * and would need to be modified if the previous rule was used instead. *)\nlemma heap_abs_modifies_heap_update [heap_abs]:\n \"\\ valid_typ_heap st getter setter vgetter vsetter t_hrs t_hrs_update;\n abs_expr st Pb b' b;\n \\v. abs_expr st Pc (c' v) (c v) \\ \\\n abs_modifies st (\\s. Pb s \\ Pc s \\ vgetter s (b' s))\n (\\s. setter (\\x. x(b' s := c' (x (b' s)) s)) s)\n (\\s. t_hrs_update (hrs_mem_update\n (heap_update (b s :: ('a::c_type) ptr)\n (c (heap_lift__h_val (hrs_mem (t_hrs s)) (b s)) s))) s)\"\n apply (clarsimp simp: typ_simple_heap_simps abs_expr_def abs_modifies_def heap_lift__h_val_def)\n apply (rule_tac t = \"h_val (hrs_mem (t_hrs s)) (b' (st s))\"\n and s = \"getter (st s) (b' (st s))\" in subst)\n apply (clarsimp simp: valid_typ_heap_def)\n apply (rule_tac f1 = \"(\\x. x(b' (st s) := c' (getter (st s) (b' (st s))) (st s)))\"\n in subst[OF read_write_valid_def3[where r = getter and w = setter]])\n apply (clarsimp simp: valid_typ_heap_def)\n apply (rule refl)\n apply (metis valid_typ_heap_t_hrs_updateD)\n done\n\n\n(* Legacy rules for non-packed types. *)\nlemma abs_expr_field_getter_legacy [heap_abs]:\n \"\\ valid_struct_field_legacy st field_name field_getter field_setter\n getter setter vgetter vsetter t_hrs t_hrs_setter;\n abs_expr st P a c \\ \\\n abs_expr st (\\s. P s \\ vgetter s (a s))\n (\\s. field_getter (getter s (a s)))\n (\\s. h_val (hrs_mem (t_hrs s)) (Ptr &((c s)\\field_name)))\"\n apply (clarsimp simp: abs_expr_def valid_struct_field_legacy_def valid_typ_heap_def)\n done\n\nlemma abs_expr_field_setter_legacy [heap_abs]:\n \"\\ valid_struct_field_legacy st field_name\n field_getter field_setter getter setter vgetter vsetter t_hrs t_hrs_update;\n abs_expr st P p p'; abs_expr st Q val val' \\ \\\n abs_modifies st (\\s. P s \\ Q s \\ vgetter s (p s))\n (\\s. setter (\\old. old((p s) := field_setter (val s) (old (p s)))) s)\n (\\s. t_hrs_update (hrs_mem_update (heap_update (Ptr &((p' s)\\field_name)) (val' s))) s)\"\n apply (clarsimp simp: abs_expr_def valid_struct_field_legacy_def valid_typ_heap_def abs_modifies_def)\n done\n\nlemma abs_expr_field_guard_legacy [heap_abs]:\n \"\\ valid_struct_field_legacy st field_name\n (field_getter :: 'p \\ 'f) field_setter getter setter vgetter vsetter t_hrs t_hrs_update;\n abs_expr st P p p' \\ \\\n abs_guard st (P and (\\s. vgetter s (p s :: 'p :: {c_type} ptr )))\n (\\s. c_guard (Ptr &((p' s)\\field_name) :: 'f::{c_type} ptr))\"\n apply (clarsimp simp: abs_guard_def abs_expr_def valid_struct_field_legacy_def valid_typ_heap_def)\n done\n\n\n\n(*\n * struct_rewrite: remove uses of field_lvalue. (field_lvalue p a = &(p\\a))\n * We do three transformations:\n * c_guard (p\\a) \\ c_guard p\n * h_val s (p\\a) = p_C.a_C (h_val s p)\n * heap_update (p\\a) v s = heap_update p (p_C.a_C_update (\\_. v) (h_val s p)) s\n * However, an inner expression may nest h_vals arbitrarily.\n *\n * Any output of a struct_rewrite rule should be fully rewritten.\n * By doing this, each rule only needs to rewrite the parts of a term that it\n * introduces by itself.\n *)\n\n(* struct_rewrite_guard rules *)\n\nlemma struct_rewrite_guard_expr [heap_abs]:\n \"struct_rewrite_expr P a' a \\ struct_rewrite_guard (\\s. P s \\ a' s) a\"\n by (simp add: struct_rewrite_expr_def struct_rewrite_guard_def)\n\nlemma struct_rewrite_guard_constant [heap_abs]:\n \"struct_rewrite_guard (\\_. P) (\\_. P)\"\n by (simp add: struct_rewrite_guard_def)\n\nlemma struct_rewrite_guard_conj [heap_abs]:\n \"\\ struct_rewrite_guard b' b; struct_rewrite_guard a' a \\ \\\n struct_rewrite_guard (\\s. a' s \\ b' s) (\\s. a s \\ b s)\"\n by (clarsimp simp: struct_rewrite_guard_def)\n\nlemma struct_rewrite_guard_split [heap_abs]:\n \"\\ \\a b. struct_rewrite_guard (A a b) (C a b) \\\n \\ struct_rewrite_guard (case r of (a, b) \\ A a b) (case r of (a, b) \\ C a b)\"\n apply (auto simp: split_def)\n done\n\nlemma struct_rewrite_guard_c_guard_field [heap_abs]:\n \"\\ valid_struct_field st field_name (field_getter :: ('a :: packed_type) \\ ('f :: packed_type)) field_setter t_hrs t_hrs_update;\n struct_rewrite_expr P p' p;\n struct_rewrite_guard Q (\\s. c_guard (p' s)) \\ \\\n struct_rewrite_guard (\\s. P s \\ Q s)\n (\\s. c_guard (Ptr (field_lvalue (p s :: 'a ptr) field_name) :: 'f ptr))\"\n by (simp add: valid_struct_field_def struct_rewrite_expr_def struct_rewrite_guard_def)\n\nlemma align_of_array: \"align_of TYPE(('a :: oneMB_size)['b' :: fourthousand_count]) = align_of TYPE('a)\"\n by (simp add: align_of_def align_td_array)\n\nlemma c_guard_array:\n \"\\ 0 \\ k; nat k < CARD('b); c_guard (p :: (('a::oneMB_size)['b::fourthousand_count]) ptr) \\\n \\ c_guard (ptr_coerce p +\\<^sub>p k :: 'a ptr)\"\n apply (clarsimp simp: ptr_add_def c_guard_def c_null_guard_def)\n apply (rule conjI[rotated])\n apply (erule contrapos_nn)\n apply (clarsimp simp: intvl_def)\n apply (rename_tac i, rule_tac x = \"nat k * size_of TYPE('a) + i\" in exI)\n apply clarsimp\n apply (rule conjI)\n apply (simp add: field_simps of_nat_nat)\n apply (rule_tac y = \"Suc (nat k) * size_of TYPE('a)\" in less_le_trans)\n apply simp\n apply (metis less_eq_Suc_le mult_le_mono2 mult.commute)\n apply (subgoal_tac \"ptr_aligned (ptr_coerce p :: 'a ptr)\")\n apply (frule_tac p = \"ptr_coerce p\" and i = \"k\" in ptr_aligned_plus)\n apply (clarsimp simp: ptr_add_def)\n apply (clarsimp simp: ptr_aligned_def align_of_array)\n done\n\nlemma struct_rewrite_guard_c_guard_Array_field [heap_abs]:\n \"\\ valid_struct_field st field_name (field_getter :: ('a :: packed_type) \\ ('f::oneMB_packed ['n::fourthousand_count])) field_setter t_hrs t_hrs_update;\n struct_rewrite_expr P p' p;\n struct_rewrite_guard Q (\\s. c_guard (p' s)) \\ \\\n struct_rewrite_guard (\\s. P s \\ Q s \\ 0 \\ k \\ nat k < CARD('n))\n (\\s. c_guard (ptr_coerce (Ptr (field_lvalue (p s :: 'a ptr) field_name) :: (('f['n]) ptr)) +\\<^sub>p k :: 'f ptr))\"\n by (simp del: ptr_coerce.simps add: valid_struct_field_def struct_rewrite_expr_def struct_rewrite_guard_def c_guard_array)\n\n\n(* struct_rewrite_expr rules *)\n\n(* This is only used when heap lifting is turned off,\n * where we expect no rewriting to happen anyway.\n * TODO: it might be safe to enable this unconditionally,\n * as long as it happens after heap_abs_fo. *)\nlemma struct_rewrite_expr_id:\n \"struct_rewrite_expr \\ A A\"\n by (simp add: struct_rewrite_expr_def)\n\nlemma struct_rewrite_expr_fun_app2 [heap_abs_fo]:\n \"\\ struct_rewrite_expr P f' f;\n struct_rewrite_expr Q g' g \\ \\\n struct_rewrite_expr (\\s. P s \\ Q s) (\\s a. f' s a (g' s a)) (\\s a. f s a $ g s a)\"\n by (simp add: struct_rewrite_expr_def)\n\nlemma struct_rewrite_expr_fun_app [heap_abs_fo]:\n \"\\ struct_rewrite_expr Y b' b; struct_rewrite_expr X a' a \\ \\\n struct_rewrite_expr (\\s. X s \\ Y s) (\\s. a' s (b' s)) (\\s. a s $ b s)\"\n by (clarsimp simp: struct_rewrite_expr_def)\n\nlemma struct_rewrite_expr_constant [heap_abs]:\n \"struct_rewrite_expr \\ (\\_. a) (\\_. a)\"\n by (clarsimp simp: struct_rewrite_expr_def)\n\nlemma struct_rewrite_expr_lambda_null [heap_abs]:\n \"struct_rewrite_expr P A C \\ struct_rewrite_expr P (\\s _. A s) (\\s _. C s)\"\n by (clarsimp simp: struct_rewrite_expr_def)\n\nlemma struct_rewrite_expr_split [heap_abs]:\n \"\\ \\a b. struct_rewrite_expr (P a b) (A a b) (C a b) \\\n \\ struct_rewrite_expr (case r of (a, b) \\ P a b)\n (case r of (a, b) \\ A a b) (case r of (a, b) \\ C a b)\"\n apply (auto simp: split_def)\n done\n\nlemma struct_rewrite_expr_basecase_h_val [heap_abs]:\n \"struct_rewrite_expr \\ (\\s. h_val (h s) (p s)) (\\s. h_val (h s) (p s))\"\n by (simp add: struct_rewrite_expr_def)\n\nlemma struct_rewrite_expr_field [heap_abs]:\n \"\\ valid_struct_field st field_name (field_getter :: ('a :: packed_type) \\ ('f :: packed_type)) field_setter t_hrs t_hrs_update;\n struct_rewrite_expr P p' p;\n struct_rewrite_expr Q a (\\s. h_val (hrs_mem (t_hrs s)) (p' s)) \\\n \\ struct_rewrite_expr (\\s. P s \\ Q s) (\\s. field_getter (a s))\n (\\s. h_val (hrs_mem (t_hrs s)) (Ptr (field_lvalue (p s) field_name)))\"\n apply (clarsimp simp: valid_struct_field_def struct_rewrite_expr_def)\n apply (subst h_val_field_from_bytes')\n apply assumption\n apply (rule export_tag_adjust_ti(1)[rule_format])\n apply (simp add: read_write_valid_fg_cons)\n apply simp\n apply simp\n done\n\nlemma struct_rewrite_expr_Array_field [heap_abs]:\n \"\\ valid_struct_field st field_name\n (field_getter :: ('a :: packed_type) \\ 'f::oneMB_packed ['n::fourthousand_count])\n field_setter t_hrs t_hrs_update;\n struct_rewrite_expr P p' p;\n struct_rewrite_expr Q a (\\s. h_val (hrs_mem (t_hrs s)) (p' s)) \\\n \\ struct_rewrite_expr (\\s. P s \\ Q s \\ k \\ 0 \\ nat k < CARD('n))\n (\\s. index (field_getter (a s)) (nat k))\n (\\s. h_val (hrs_mem (t_hrs s))\n (ptr_coerce (Ptr (field_lvalue (p s) field_name) :: ('f['n]) ptr) +\\<^sub>p k))\"\n apply (case_tac k)\n apply (clarsimp simp: struct_rewrite_expr_def simp del: ptr_coerce.simps)\n apply (subst struct_rewrite_expr_field\n [unfolded struct_rewrite_expr_def, simplified, rule_format, symmetric,\n where field_getter = field_getter and P = P and Q = Q and p = p and p' = p'])\n apply assumption\n apply simp\n apply simp\n apply simp\n apply (rule_tac s = \"p s\" and t = \"p' s\" in subst)\n apply simp\n apply (rule heap_access_Array_element[symmetric])\n apply simp\n apply (simp add: struct_rewrite_expr_def)\n done\ndeclare struct_rewrite_expr_Array_field [unfolded ptr_coerce.simps, heap_abs]\n\n(* struct_rewrite_modifies rules *)\n\nlemma struct_rewrite_modifies_id [heap_abs]:\n \"struct_rewrite_modifies \\ A A\"\n by (simp add: struct_rewrite_modifies_def)\n\n(* We need some valid_typ_heap, but we're really only after t_hrs_update.\n * We artificially constrain the type of v to limit backtracking. *)\nlemma struct_rewrite_modifies_basecase [heap_abs]:\n \"\\ valid_typ_heap st (getter :: 's \\ 'a ptr \\ ('a::c_type)) setter vgetter vsetter t_hrs t_hrs_update;\n struct_rewrite_expr P p' p;\n struct_rewrite_expr Q v' v \\ \\\n struct_rewrite_modifies (\\s. P s \\ Q s)\n (\\s. t_hrs_update (hrs_mem_update (heap_update (p' s) (v' s :: 'a))) s)\n (\\s. t_hrs_update (hrs_mem_update (heap_update (p s) (v s :: 'a))) s)\"\n by (simp add: struct_rewrite_expr_def struct_rewrite_modifies_def)\n\n(* \\ heap_update_field *)\nlemma heap_update_field_unpacked:\n \"\\ field_ti TYPE('a::mem_type) f = Some (t :: 'a field_desc typ_desc);\n c_guard (p :: 'a::mem_type ptr);\n export_uinfo t = export_uinfo (typ_info_t TYPE('b::mem_type)) \\ \\\n heap_update (Ptr &(p\\f) :: 'b ptr) v hp =\n heap_update p (update_ti t (to_bytes_p v) (h_val hp p)) hp\"\n oops\n\n(* \\ heap_update_Array_element *)\nlemma heap_update_Array_element_unpacked:\n \"n < CARD('b::fourthousand_count) \\\n heap_update (ptr_coerce p' +\\<^sub>p int n) w hp =\n heap_update (p'::('a::oneMB_size['b::fourthousand_count]) ptr)\n (Arrays.update (h_val hp p') n w) hp\"\n oops\n\n(* helper *)\nlemma read_write_valid_hrs_mem:\n \"read_write_valid hrs_mem hrs_mem_update\"\n by (clarsimp simp: hrs_mem_def hrs_mem_update_def read_write_valid_def)\n\n\n(*\n * heap_update is a bit harder.\n * Recall that we want to rewrite\n * \"heap_update (ptr\\a\\b\\c) val s\" to\n * \"heap_update ptr (c_update (b_update (a_update (\\_. val))) (h_val s ptr)) s\".\n * In the second term, c_update is the outer update even though\n * c is the innermost field.\n *\n * We introduce a schematic update function ?u that would eventually be\n * instantiated to be the chain \"\\f. c_update (b_update (a_update f))\".\n * Observe that when we find another field \"\\d\", we can instantiate\n * ?u' = \\f. ?u (d_update f)\n * so that u' is the correct update function for \"ptr\\a\\b\\c\\d\".\n *\n * This is a big hack because:\n * - We rely on a particular behaviour of the unifier (see below).\n * - We will have a chain of flex-flex pairs\n * ?u1 =?= \\f. ?u0 (a_update f)\n * ?u2 =?= \\f. ?u1 (b_update f)\n * etc.\n * - Because we are doing this transformation in steps, moving\n * one component of \"ptr\\a\\...\" at a time, we end up invoking\n * struct_rewrite_expr on the same subterms over and over again.\n * In case we find out this hack doesn't scale, we can avoid the schematic ?u\n * by traversing the chain and constructing ?u in a separate step.\n *)\n\n(*\n * There's more. heap_update rewrites for \"ptr\\a\\b := RHS\" cause a\n * \"h_val s ptr\" to appear in the RHS.\n * When we lift to the typed heap, we want this h_val to be treated\n * differently to other \"h_val s ptr\" terms that were already in the RHS.\n * Thus we define heap_lift__h_val \\ h_val to carry this information around.\n *)\ndefinition \"heap_lift__wrap_h_val \\ op =\"\n\nlemma heap_lift_wrap_h_val [heap_abs]:\n \"heap_lift__wrap_h_val (heap_lift__h_val s p) (h_val s p)\"\n by (simp add: heap_lift__h_val_def heap_lift__wrap_h_val_def)\n\nlemma heap_lift_wrap_h_val_skip [heap_abs]:\n \"heap_lift__wrap_h_val (h_val s (Ptr (field_lvalue p f))) (h_val s (Ptr (field_lvalue p f)))\"\n by (simp add: heap_lift__wrap_h_val_def)\n\nlemma heap_lift_wrap_h_val_skip_array [heap_abs]:\n \"heap_lift__wrap_h_val (h_val s (ptr_coerce p +\\<^sub>p k))\n (h_val s (ptr_coerce p +\\<^sub>p k))\"\n by (simp add: heap_lift__wrap_h_val_def)\n\n(* These are valid rules, but produce redundant output. *)\nlemma struct_rewrite_modifies_field__unused:\n \"\\ valid_struct_field (st :: 's \\ 't) field_name (field_getter :: ('a::packed_type) \\ ('f::packed_type)) field_setter t_hrs t_hrs_update;\n struct_rewrite_expr P p' p;\n struct_rewrite_expr Q f' f;\n struct_rewrite_modifies R\n (\\s. t_hrs_update (hrs_mem_update (heap_update (p'' s)\n (u s (field_setter (\\_. f' s))))) s)\n (\\s. t_hrs_update (hrs_mem_update (heap_update (p' s)\n (field_setter (\\_. f' s) (h_val (hrs_mem (t_hrs s)) (p' s))))) s);\n struct_rewrite_guard S (\\s. c_guard (p' s)) \\ \\\n struct_rewrite_modifies (\\s. P s \\ Q s \\ R s \\ S s)\n (\\s. t_hrs_update (hrs_mem_update (heap_update (p'' s)\n (u s (field_setter (\\_. f' s))))) s)\n (\\s. t_hrs_update (hrs_mem_update (heap_update (Ptr (field_lvalue (p s) field_name))\n (f s))) s)\"\n apply (clarsimp simp: struct_rewrite_expr_def struct_rewrite_guard_def struct_rewrite_modifies_def valid_struct_field_def)\n apply (erule_tac x = s in allE)+\n apply (erule impE, assumption)+\n apply (erule_tac t = \"t_hrs_update (hrs_mem_update (heap_update (p'' s)\n (u s (field_setter (\\_. f' s))))) s\"\n and s = \"t_hrs_update (hrs_mem_update (heap_update (p' s)\n (field_setter (\\_. f' s) (h_val (hrs_mem (t_hrs s)) (p' s))))) s\"\n in subst)\n apply (rule read_write_valid_def3[where r = t_hrs and w = t_hrs_update])\n apply assumption\n apply (rule read_write_valid_def3[OF read_write_valid_hrs_mem])\n apply (subst heap_update_field)\n apply assumption+\n apply (simp add: export_tag_adjust_ti(1)[rule_format] read_write_valid_fg_cons)\n apply (subst update_ti_update_ti_t)\n apply (simp add: size_of_def)\n apply (subst update_ti_s_adjust_ti_to_bytes_p)\n apply (erule read_write_valid_fg_cons)\n apply simp\n done\n\nlemma struct_rewrite_modifies_Array_field__unused:\n \"\\ valid_struct_field (st :: 's \\ 't) field_name (field_getter :: ('a::packed_type) \\ (('f::oneMB_packed)['n::fourthousand_count])) field_setter t_hrs t_hrs_update;\n struct_rewrite_expr P p' p;\n struct_rewrite_expr Q f' f;\n struct_rewrite_modifies R\n (\\s. t_hrs_update (hrs_mem_update (heap_update (p'' s)\n (u s (field_setter (\\a. Arrays.update a (nat k) (f' s)))))) s)\n (\\s. t_hrs_update (hrs_mem_update (heap_update (p' s)\n (field_setter (\\a. Arrays.update a (nat k) (f' s))\n (h_val (hrs_mem (t_hrs s)) (p' s))))) s);\n struct_rewrite_guard S (\\s. c_guard (p' s)) \\ \\\n struct_rewrite_modifies (\\s. P s \\ Q s \\ R s \\ S s \\ 0 \\ k \\ nat k < CARD('n))\n (\\s. t_hrs_update (hrs_mem_update (heap_update (p'' s)\n (u s (field_setter (\\a. Arrays.update a (nat k) (f' s)))))) s)\n (\\s. t_hrs_update (hrs_mem_update (heap_update\n (ptr_coerce (Ptr (field_lvalue (p s) field_name) :: ('f['n]) ptr) +\\<^sub>p k) (f s))) s)\"\n using ptr_coerce.simps [simp del]\n apply (clarsimp simp: struct_rewrite_expr_def struct_rewrite_guard_def struct_rewrite_modifies_def valid_struct_field_def)\n apply (erule_tac x = s in allE)+\n apply (erule impE, assumption)+\n apply (erule_tac t = \"t_hrs_update (hrs_mem_update (heap_update (p'' s)\n (u s(field_setter (\\a. Arrays.update a (nat k) (f' s)))))) s\"\n and s = \"t_hrs_update (hrs_mem_update (heap_update (p' s)\n (field_setter (\\a. Arrays.update a (nat k) (f' s))\n (h_val (hrs_mem (t_hrs s)) (p' s))))) s\"\n in subst)\n apply (rule read_write_valid_def3[where r = t_hrs and w = t_hrs_update])\n apply assumption\n apply (rule read_write_valid_def3[OF read_write_valid_hrs_mem])\n apply (case_tac k, clarsimp)\n apply (subst heap_update_Array_element[symmetric])\n apply assumption\n apply (subst heap_update_field)\n apply assumption+\n apply (simp add: export_tag_adjust_ti(1)[rule_format] read_write_valid_fg_cons)\n apply (subst h_val_field_from_bytes')\n apply assumption+\n apply (simp add: export_tag_adjust_ti(1)[rule_format] read_write_valid_fg_cons)\n apply clarsimp\n apply (subst update_ti_update_ti_t)\n apply (simp add: size_of_def)\n apply (subst update_ti_s_adjust_ti_to_bytes_p)\n apply (erule read_write_valid_fg_cons)\n apply clarsimp\n apply (subst read_write_valid_def3[of field_getter field_setter])\n apply auto\n done\n\n\n(*\n * These produce less redundant output (we avoid \"t_update (\\_. foo (t x)) x\"\n * where x is some huge term).\n * The catch: we rely on the unifier to produce a \"greedy\" instantiation for ?f.\n * Namely, if we are matching \"?f s (h_val s p)\" on\n * \"b_update (a_update (\\_. foo (h_val s p))) (h_val s p)\",\n * we expect ?f to be instantiated to\n * \"\\s v. b_update (a_update (\\_. foo v)) v\"\n * even though there are other valid ones.\n * It just so happens that isabelle's unifier produces such an instantiation.\n * Are we lucky, or presumptuous?\n *)\nlemma struct_rewrite_modifies_field [heap_abs]:\n \"\\ valid_struct_field (st :: 's \\ 't) field_name (field_getter :: ('a::packed_type) \\ ('f::packed_type)) field_setter t_hrs t_hrs_update;\n struct_rewrite_expr P p' p;\n struct_rewrite_expr Q f' f;\n \\s. heap_lift__wrap_h_val (h_val_p' s) (h_val (hrs_mem (t_hrs s)) (p' s));\n struct_rewrite_modifies R\n (\\s. t_hrs_update (hrs_mem_update (heap_update (p'' s)\n (u s (field_setter (f' s))))) s)\n (\\s. t_hrs_update (hrs_mem_update (heap_update (p' s)\n (field_setter (f' s) (h_val_p' s)))) s);\n struct_rewrite_guard S (\\s. c_guard (p' s)) \\ \\\n struct_rewrite_modifies (\\s. P s \\ Q s \\ R s \\ S s)\n (\\s. t_hrs_update (hrs_mem_update (heap_update (p'' s)\n (u s (field_setter (f' s))))) s)\n (\\s. t_hrs_update (hrs_mem_update (heap_update (Ptr (field_lvalue (p s) field_name))\n (f s (h_val (hrs_mem (t_hrs s)) (Ptr (field_lvalue (p s) field_name)))))) s)\"\n apply (clarsimp simp: struct_rewrite_expr_def struct_rewrite_guard_def struct_rewrite_modifies_def valid_struct_field_def heap_lift__wrap_h_val_def)\n apply (erule_tac x = s in allE)+\n apply (erule impE, assumption)+\n apply (erule_tac t = \"t_hrs_update (hrs_mem_update (heap_update (p'' s)\n (u s (field_setter (f' s))))) s\"\n and s = \"t_hrs_update (hrs_mem_update (heap_update (p' s)\n (field_setter (f' s) (h_val (hrs_mem (t_hrs s)) (p' s))))) s\"\n in subst)\n apply (rule read_write_valid_def3[where r = t_hrs and w = t_hrs_update])\n apply assumption\n apply (rule read_write_valid_def3[OF read_write_valid_hrs_mem])\n apply (subst heap_update_field)\n apply assumption+\n apply (simp add: export_tag_adjust_ti(1)[rule_format] read_write_valid_fg_cons)\n apply (subst h_val_field_from_bytes')\n apply assumption+\n apply (simp add: export_tag_adjust_ti(1)[rule_format] read_write_valid_fg_cons)\n apply (subst update_ti_update_ti_t)\n apply (simp add: size_of_def)\n apply (subst update_ti_s_adjust_ti_to_bytes_p)\n apply (erule read_write_valid_fg_cons)\n apply (subst read_write_valid_def3[where r = field_getter and w = field_setter])\n apply auto\n done\n\n(* FIXME: this is nearly a duplicate. Would a standalone array rule work instead? *)\nlemma struct_rewrite_modifies_Array_field [heap_abs]:\n \"\\ valid_struct_field (st :: 's \\ 't) field_name (field_getter :: ('a::packed_type) \\ (('f::oneMB_packed)['n::fourthousand_count])) field_setter t_hrs t_hrs_update;\n struct_rewrite_expr P p' p;\n struct_rewrite_expr Q f' f;\n \\s. heap_lift__wrap_h_val (h_val_p' s) (h_val (hrs_mem (t_hrs s)) (p' s));\n struct_rewrite_modifies R\n (\\s. t_hrs_update (hrs_mem_update (heap_update (p'' s)\n (u s (field_setter (\\a. Arrays.update a (nat k) (f' s (index a (nat k)))))))) s)\n (\\s. t_hrs_update (hrs_mem_update (heap_update (p' s)\n (field_setter (\\a. Arrays.update a (nat k) (f' s (index a (nat k))))\n (h_val_p' s)))) s);\n struct_rewrite_guard S (\\s. c_guard (p' s)) \\ \\\n struct_rewrite_modifies (\\s. P s \\ Q s \\ R s \\ S s \\ 0 \\ k \\ nat k < CARD('n))\n (\\s. t_hrs_update (hrs_mem_update (heap_update (p'' s)\n (u s (field_setter (\\a. Arrays.update a (nat k) (f' s (index a (nat k)))))))) s)\n (\\s. t_hrs_update (hrs_mem_update (heap_update\n (ptr_coerce (Ptr (field_lvalue (p s) field_name) :: ('f['n]) ptr) +\\<^sub>p k)\n (f s (h_val (hrs_mem (t_hrs s)) (ptr_coerce (Ptr (field_lvalue (p s) field_name) :: ('f['n]) ptr) +\\<^sub>p k :: 'f ptr))))) s)\"\n using ptr_coerce.simps[simp del]\n apply (clarsimp simp: struct_rewrite_expr_def struct_rewrite_guard_def struct_rewrite_modifies_def valid_struct_field_def heap_lift__wrap_h_val_def)\n apply (erule_tac x = s in allE)+\n apply (erule impE, assumption)+\n apply (erule_tac t = \"t_hrs_update (hrs_mem_update (heap_update (p'' s)\n (u s(field_setter (\\a. Arrays.update a (nat k) (f' s (index a (nat k)))))))) s\"\n and s = \"t_hrs_update (hrs_mem_update (heap_update (p' s)\n (field_setter (\\a. Arrays.update a (nat k) (f' s (index a (nat k))))\n (h_val (hrs_mem (t_hrs s)) (p' s))))) s\"\n in subst)\n apply (rule read_write_valid_def3[where r = t_hrs and w = t_hrs_update])\n apply assumption\n apply (rule read_write_valid_def3[OF read_write_valid_hrs_mem])\n apply (case_tac k, clarsimp)\n apply (subst heap_update_Array_element[symmetric])\n apply assumption\n apply (subst heap_update_field)\n apply assumption+\n apply (simp add: export_tag_adjust_ti(1)[rule_format] read_write_valid_fg_cons)\n apply (subst h_val_field_from_bytes')\n apply assumption+\n apply (simp add: export_tag_adjust_ti(1)[rule_format] read_write_valid_fg_cons)\n apply (subst heap_access_Array_element[symmetric])\n apply simp\n apply (subst h_val_field_from_bytes')\n apply assumption+\n apply (simp add: export_tag_adjust_ti(1)[rule_format] read_write_valid_fg_cons)\n apply clarsimp\n apply (subst update_ti_update_ti_t)\n apply (simp add: size_of_def)\n apply (subst update_ti_s_adjust_ti_to_bytes_p)\n apply (erule read_write_valid_fg_cons)\n apply clarsimp\n apply (subst read_write_valid_def3[of field_getter field_setter])\n apply auto\n done\n\n\n(*\n * Convert gets\/sets to global variables into gets\/sets in the new globals record.\n *)\n\ndefinition\n valid_globals_field :: \"\n ('s \\ 't)\n \\ ('s \\ 'a)\n \\ (('a \\ 'a) \\ 's \\ 's)\n \\ ('t \\ 'a)\n \\ (('a \\ 'a) \\ 't \\ 't)\n \\ bool\"\nwhere\n \"valid_globals_field st old_getter old_setter new_getter new_setter \\\n (\\s. new_getter (st s) = old_getter s)\n \\ (\\s v. new_setter v (st s) = st (old_setter v s))\"\n\nlemma abs_expr_globals_getter [heap_abs]:\n \"\\ valid_globals_field st old_getter old_setter new_getter new_setter \\\n \\ abs_expr st \\ new_getter old_getter\"\n apply (clarsimp simp: valid_globals_field_def abs_expr_def)\n done\n\nlemma abs_expr_globals_setter [heap_abs]:\n \"\\ valid_globals_field st old_getter old_setter new_getter new_setter;\n \\old. abs_expr st (P old) (v old) (v' old) \\\n \\ abs_modifies st (\\s. \\old. P old s) (\\s. new_setter (\\old. v old s) s) (\\s. old_setter (\\old. v' old s) s)\"\n apply (clarsimp simp: valid_globals_field_def abs_expr_def abs_modifies_def)\n done\n\nlemma struct_rewrite_expr_globals_getter [heap_abs]:\n \"\\ valid_globals_field st old_getter old_setter new_getter new_setter \\\n \\ struct_rewrite_expr \\ old_getter old_getter\"\n apply (clarsimp simp: struct_rewrite_expr_def)\n done\n\nlemma struct_rewrite_modifies_globals_setter [heap_abs]:\n \"\\ valid_globals_field st old_getter old_setter new_getter new_setter;\n \\old. struct_rewrite_expr (P old) (v' old) (v old) \\\n \\ struct_rewrite_modifies (\\s. \\old. P old s) (\\s. old_setter (\\old. v' old s) s) (\\s. old_setter (\\old. v old s) s)\"\n apply (clarsimp simp: valid_globals_field_def struct_rewrite_expr_def struct_rewrite_modifies_def)\n done\n\n(* Signed words are stored on the heap as unsigned words. *)\n\nlemma uint_scast [simp]:\n \"uint (scast x :: 'a word) = uint (x :: 'a::len signed word)\"\n apply (subst down_cast_same [symmetric])\n apply (clarsimp simp: cast_simps)\n apply (subst uint_up_ucast)\n apply (clarsimp simp: cast_simps)\n apply simp\n done\n\nlemma to_bytes_signed_word:\n \"to_bytes (x :: 'a::len8 signed word) p = to_bytes (scast x :: 'a word) p\"\n by (clarsimp simp: to_bytes_def typ_info_word word_rsplit_def)\n\nlemma from_bytes_signed_word:\n \"length p = len_of TYPE('a) div 8 \\\n (from_bytes p :: 'a::len8 signed word) = ucast (from_bytes p :: 'a word)\"\n by (clarsimp simp: from_bytes_def word_rcat_def\n scast_def cast_simps typ_info_word)\n\nlemma hrs_mem_update_signed_word:\n \"hrs_mem_update (heap_update (ptr_coerce p :: 'a::len8 word ptr) (scast val :: 'a::len8 word))\n = hrs_mem_update (heap_update p (val :: 'a::len8 signed word))\"\n apply (rule ext)\n apply (clarsimp simp: hrs_mem_update_def split_def)\n apply (clarsimp simp: heap_update_def to_bytes_signed_word\n size_of_def typ_info_word)\n done\n\nlemma h_val_signed_word:\n \"(h_val a p :: 'a::len8 signed word) = ucast (h_val a (ptr_coerce p :: 'a word ptr))\"\n apply (clarsimp simp: h_val_def)\n apply (subst from_bytes_signed_word)\n apply (clarsimp simp: size_of_def typ_info_word)\n apply (clarsimp simp: size_of_def typ_info_word)\n done\n\n\nlemma align_of_signed_word [simp]:\n \"align_of TYPE('a::len8 signed word) = align_of TYPE('a word)\"\n by (clarsimp simp: align_of_def typ_info_word)\n\nlemma size_of_signed_word [simp]:\n \"size_of TYPE('a::len8 signed word) = size_of TYPE('a word)\"\n by (clarsimp simp: size_of_def typ_info_word)\n\nlemma c_guard_ptr_coerce:\n \"\\ align_of TYPE('a) = align_of TYPE('b);\n size_of TYPE('a) = size_of TYPE('b) \\ \\\n c_guard (ptr_coerce p :: ('b::c_type) ptr) = c_guard (p :: ('a::c_type) ptr)\"\n apply (clarsimp simp: c_guard_def ptr_aligned_def c_null_guard_def)\n done\n\nlemma word_rsplit_signed:\n \"(word_rsplit (ucast v' :: ('a::len) signed word) :: 8 word list) = word_rsplit (v' :: 'a word)\"\n apply (clarsimp simp: word_rsplit_def)\n apply (clarsimp simp: cast_simps)\n done\n\nlemma heap_update_signed_word [simp]:\n \"heap_update (ptr_coerce p :: 'a word ptr) (scast v) = heap_update (p :: ('a::len8) signed word ptr) v\"\n \"heap_update (ptr_coerce p' :: 'a signed word ptr) (ucast v') = heap_update (p' :: ('a::len8) word ptr) v'\"\n apply (auto simp: heap_update_def to_bytes_def typ_info_word word_rsplit_def cast_simps)\n done\n\nlemma valid_typ_heap_c_guard:\n \"\\ valid_typ_heap st getter setter vgetter vsetter t_hrs t_hrs_update;\n vgetter (st s) p \\ \\ c_guard p\"\n by (clarsimp simp: valid_typ_heap_def)\n\nabbreviation (input)\n scast_f :: \"(('a::len) signed word ptr \\ 'a signed word)\n \\ ('a word ptr \\ 'a word)\"\nwhere\n \"scast_f f \\ (\\p. scast (f (ptr_coerce p)))\"\n\nabbreviation (input)\n ucast_f :: \"(('a::len) word ptr \\ 'a word)\n \\ ('a signed word ptr \\ 'a signed word)\"\nwhere\n \"ucast_f f \\ (\\p. ucast (f (ptr_coerce p)))\"\n\nabbreviation (input)\n cast_f' :: \"('a ptr \\ 'x) \\ ('b ptr \\ 'x)\"\nwhere\n \"cast_f' f \\ (\\p. f (ptr_coerce p))\"\n\nlemma read_write_validE_weak:\n \"\\ read_write_valid r w;\n \\ \\f s. r (w f s) = f (r s);\n \\f s. f (r s) = (r s) \\ w f s = s \\ \\ R \\\n \\ R\"\n apply atomize_elim\n apply (unfold read_write_valid_def)\n apply blast\n done\n\nlemma read_write_valid_transcode:\n \"\\ read_write_valid r w; \\v. f' (f v) = v; \\v. f (f' v) = v \\ \\ read_write_valid (\\s. f' (r s)) (\\g s. w (\\old. f (g (f' old))) s)\"\n apply (unfold read_write_valid_def)\n apply safe\n apply atomize\n apply metis\n apply atomize\n apply (metis (full_types))\n apply atomize\n apply metis\n apply atomize\n apply (metis (lifting, mono_tags))\n done\n\nlemma valid_typ_heap_signed_word:\n \"\\ valid_typ_heap st\n (getter :: 's \\ ('a::len8) word ptr \\ 'a word) setter\n vgetter vsetter t_hrs t_hrs_update \\\n \\ valid_typ_heap st\n (\\s p. ucast (getter s (ptr_coerce p)) :: 'a signed word)\n (\\f. (setter ((\\x. scast_f (f (ucast_f x))))))\n (\\s p. vgetter s (ptr_coerce p))\n (\\f. (vsetter ((\\x. cast_f' (f (cast_f' x))))))\n t_hrs t_hrs_update\"\n apply (clarsimp simp: valid_typ_heap_def\n map.compositionality o_def c_guard_ptr_coerce)\n apply (rule read_write_validE_weak [where r=getter], assumption)\n apply (rule read_write_validE_weak [where r=vgetter], assumption)\n apply (rule read_write_validE_weak [where r=t_hrs], assumption)\n apply (intro conjI impI)\n apply (erule read_write_valid_transcode, auto)[1]\n apply (erule read_write_valid_transcode, auto)[1]\n apply clarsimp\n apply (drule spec, drule spec, erule (1) impE)+\n apply (subst (asm) c_guard_ptr_coerce, simp, simp)\n apply simp\n apply clarsimp\n apply (drule spec, drule spec, erule (1) impE)+\n apply (subst (asm) c_guard_ptr_coerce, simp, simp)\n apply (metis (hide_lams, mono_tags) h_val_signed_word scast_ucast_norm(2))\n apply clarsimp\n apply (drule_tac x=s in spec)+\n apply (drule_tac x=\"ptr_coerce p\" in spec)+\n apply clarsimp\n apply (drule_tac x=\"scast x\" in spec)+\n apply clarsimp\n apply (clarsimp simp: fun_upd_def split: option.splits)\n apply (rule arg_cong2 [where f=setter])\n apply (rule ext)\n apply (rule ext)\n apply (clarsimp simp: split: option.splits)\n apply (metis ptr_coerce_id ptr_coerce_idem)\n done\n\nlemma c_guard_ptr_ptr_coerce:\n \"\\ c_guard (a :: ('a::c_type) ptr ptr); ptr_val a = ptr_val b \\ \\\n c_guard (b :: ('b::c_type) ptr ptr)\"\n by (clarsimp simp: c_guard_def ptr_aligned_def c_null_guard_def)\n\nabbreviation (input)\n ptr_coerce_f :: \"('a ptr ptr \\ 'a ptr) \\ ('b ptr ptr \\ 'b ptr)\"\nwhere\n \"ptr_coerce_f f \\ (\\p. ptr_coerce (f (ptr_coerce p)))\"\n\nabbreviation (input)\n ptr_coerce_range_f :: \"('a ptr \\ bool) \\ ('b ptr \\ bool)\"\nwhere\n \"ptr_coerce_range_f f \\ (\\p. (f (ptr_coerce p)))\"\n\nlemma valid_typ_heap_ptr_coerce:\n \"\\ valid_typ_heap st\n (getter :: 's \\ ('a::c_type) ptr ptr \\ 'a ptr) setter\n vgetter vsetter t_hrs t_hrs_update \\\n \\ valid_typ_heap st\n (\\s p. ptr_coerce (getter s (ptr_coerce p)) :: ('b::c_type) ptr)\n (\\f. (setter ((\\x. ptr_coerce_f (f (ptr_coerce_f x))))))\n (\\s p. vgetter s (ptr_coerce p))\n (\\f. (vsetter ((\\x. ptr_coerce_range_f (f (ptr_coerce_range_f x))))))\n t_hrs t_hrs_update\"\n apply (clarsimp simp: valid_typ_heap_def fun_upd_def)\n apply (rule read_write_validE_weak [where r=getter], assumption)\n apply (rule read_write_validE_weak [where r=vgetter], assumption)\n apply (rule read_write_validE_weak [where r=t_hrs], assumption)\n apply safe\n apply (erule read_write_valid_transcode, auto)[1]\n apply (erule read_write_valid_transcode, auto)[1]\n apply (erule allE, erule allE, erule impE, assumption)+\n apply (erule c_guard_ptr_ptr_coerce, simp)\n apply (clarsimp simp: h_val_def typ_info_ptr from_bytes_def)\n apply (erule allE, erule allE, erule (1) impE)+\n apply (erule allE)\n apply (erule_tac x=\"ptr_coerce x\" in allE)\n apply (clarsimp simp: heap_update_def [abs_def] to_bytes_def typ_info_ptr)\n apply (clarsimp simp: if_distrib [where f=ptr_coerce])\n apply (metis (hide_lams, mono_tags) Ptr_ptr_val ptr_coerce.simps)\n done\n\n(*\n * Nasty hack: Convert signed word pointers-to-pointers to word\n * pointers-to-pointers.\n *\n * The idea here is that types of the form:\n *\n * int ***x;\n *\n * need to be converted to accesses of the \"unsigned int ***\" heap.\n *)\nlemmas signed_valid_typ_heaps =\n valid_typ_heap_signed_word\n valid_typ_heap_ptr_coerce [where 'a=\"('x::len8) word\" and 'b=\"('x::len8) signed word\"]\n valid_typ_heap_ptr_coerce [where 'a=\"('x::len8) word ptr\" and 'b=\"('x::len8) signed word ptr\"]\n valid_typ_heap_ptr_coerce [where 'a=\"('x::len8) word ptr ptr\" and 'b=\"('x::len8) signed word ptr ptr\"]\n valid_typ_heap_ptr_coerce [where 'a=\"('x::len8) word ptr ptr ptr\" and 'b=\"('x::len8) signed word ptr ptr ptr\"]\n\n(*\n * The above lemmas generate a mess in its output, generating things\n * like:\n *\n * (heap_w32_update\n * (\\a b. scast\n * (((\\b. ucast (a (ptr_coerce b)))(a := 3))\n * (ptr_coerce b))))\n *\n * This theorem cleans it up a little.\n *)\nlemma ptr_coerce_eq:\n \"(ptr_coerce x = ptr_coerce y) = (x = y)\"\n by (cases x, cases y, auto)\n\nlemma signed_word_heap_opt [L2opt]:\n \"(scast (((\\x. ucast (a (ptr_coerce x))) (p := v :: 'a::len signed word)) (b :: 'a signed word ptr)))\n = ((a(ptr_coerce p := (scast v :: 'a word))) ((ptr_coerce b) :: 'a word ptr))\"\n by (auto simp: fun_upd_def ptr_coerce_eq)\n\nlemma signed_word_heap_ptr_coerce_opt [L2opt]:\n \"(ptr_coerce (((\\x. ptr_coerce (a (ptr_coerce x))) (p := v :: 'a ptr)) (b :: 'a ptr ptr)))\n = ((a(ptr_coerce p := (ptr_coerce v :: 'b ptr))) ((ptr_coerce b) :: 'b ptr ptr))\"\n by (auto simp: fun_upd_def scast_id ptr_coerce_eq)\n\ndeclare ptr_coerce_idem [L2opt]\ndeclare scast_ucast_id [L2opt]\ndeclare ucast_scast_id [L2opt]\n\n(* array rules *)\nlemma heap_abs_expr_c_guard_array [heap_abs]:\n \"\\ valid_typ_heap st getter setter vgetter vsetter t_hrs t_hrs_update;\n abs_expr st P x' (\\s. ptr_coerce (x s) :: 'a ptr) \\ \\\n abs_guard st\n (\\s. P s \\ (\\a \\ set (array_addrs (x' s) CARD('b)). vgetter s a))\n (\\s. c_guard (x s :: ('a::oneMB_size, 'b::fourthousand_count) array ptr))\"\n apply (clarsimp simp: abs_expr_def abs_guard_def simple_lift_def heap_ptr_valid_def)\n apply (subgoal_tac \"\\a\\set (array_addrs (x' (st s)) CARD('b)). c_guard a\")\n apply (erule allE, erule (1) impE)\n apply (rule c_guard_array_c_guard)\n apply (subst (asm) (2) set_array_addrs)\n apply force\n apply clarsimp\n apply (erule (1) my_BallE)\n apply (drule (1) valid_typ_heap_c_guard)\n apply simp\n done\n\n(* begin machinery for heap_abs_array_update *)\nlemma fold_over_st:\n \"\\ xs = ys; P s;\n \\s x. x \\ set xs \\ P s \\ P (g x s) \\ f x (st s) = st (g x s)\n \\ \\ fold f xs (st s) = st (fold g ys s)\"\n apply (erule subst)\n apply (induct xs arbitrary: s)\n apply simp\n apply simp\n done\n\nlemma fold_lift_write:\n \"\\ xs = ys; read_write_valid r w\n \\ \\ fold (\\i. w (f i)) xs s = w (fold f ys) s\"\n apply (erule subst)\n apply (induct xs arbitrary: s)\n apply (simp add: read_write_valid_def2)\n apply (force elim!: read_write_o)\n done\n\n(* cf. heap_update_nmem_same *)\nlemma fold_heap_update_list_nmem_same:\n \"\\ n * size_of TYPE('a :: mem_type) < addr_card;\n n * size_of TYPE('a) \\ k; k < addr_card;\n \\i h. length (pad i h) = size_of TYPE('a) \\ \\\n h (ptr_val (p :: 'a ptr) + of_nat k) =\n (fold (\\i h. heap_update_list (ptr_val (p +\\<^sub>p int i))\n (to_bytes (val i h :: 'a) (pad i h)) h) [0.. n * size_of TYPE('a :: mem_type) < addr_card;\n n * size_of TYPE('a) + k < addr_card;\n \\i h. length (pad i h) = size_of TYPE('a) \\ \\\n heap_list (fold (\\i h. heap_update_list (ptr_val ((p :: 'a ptr) +\\<^sub>p int i))\n (to_bytes (val i h :: 'a) (pad i h)) h) [0..p int n))\n = heap_list h k (ptr_val (p +\\<^sub>p int n))\"\n apply (rule nth_equalityI)\n apply simp\n apply (clarsimp simp: heap_list_nth)\n apply (rule_tac t = \"ptr_val (p +\\<^sub>p int n) + of_nat i\"\n and s = \"ptr_val p + of_nat (n * size_of TYPE('a) + i)\"\n in subst)\n apply (clarsimp simp: ptr_add_def)\n apply (rule fold_heap_update_list_nmem_same[symmetric])\n apply simp_all\n done\n\n(* remove false dependency *)\nlemma fold_heap_update_list:\n \"n * size_of TYPE('a :: mem_type) < 2^32 \\\n fold (\\i h. heap_update_list (ptr_val ((p :: 'a ptr) +\\<^sub>p int i))\n (to_bytes (val i :: 'a)\n (heap_list h (size_of TYPE('a)) (ptr_val (p +\\<^sub>p int i)))) h)\n [0..i. heap_update_list (ptr_val (p +\\<^sub>p int i))\n (to_bytes (val i)\n (heap_list h (size_of TYPE('a)) (ptr_val (p +\\<^sub>p int i)))))\n [0.. \\n. size_td_pair (f n) = v3; length xs = v3 * n;\n \\m xs. length xs = v3 \\ m < n \\\n access_ti_pair (f m) (FCP g) xs = h m xs\n \\ \\\n access_ti_list (map f [0 ..< n]) (FCP g) xs\n = foldl (op @) [] (map (\\m. h m (take v3 (drop (v3 * m) xs))) [0 ..< n])\"\n apply (subgoal_tac \"\\ys. size_td_list (map f ys) = v3 * length ys\")\n prefer 2\n apply (rule allI, induct_tac ys, simp+)\n apply (induct n arbitrary: xs)\n apply simp\n apply (simp add: access_ti_append)\n apply (rule foldl_cong)\n apply simp\n apply (rule map_cong[OF refl])\n apply (subst take_drop)\n apply (subst take_take)\n apply (subst min_absorb1)\n apply clarsimp\n apply (metis Suc_leI mult_Suc_right nat_mult_le_cancel_disj)\n apply (subst take_drop[symmetric])\n apply (rule refl)\n apply simp\n done\n\nlemma concat_nth_chunk:\n \"\\ \\x \\ set xs. length (f x) = chunk; n < length xs \\\n \\ take chunk (drop (n * chunk) (concat (map f xs))) = f (xs ! n)\"\n apply (induct xs arbitrary: n)\n apply simp\n apply (case_tac n)\n apply clarsimp\n apply clarsimp\n done\n\nlemma array_update_split:\n \"\\ valid_typ_heap st (getter :: 's \\ ('a::oneMB_size) ptr \\ 'a) setter\n vgetter vsetter t_hrs t_hrs_update;\n \\x \\ set (array_addrs (ptr_coerce p) CARD('b::fourthousand_count)).\n vgetter (st s) x\n \\ \\ st (t_hrs_update (hrs_mem_update (heap_update p (arr :: 'a['b]))) s) =\n fold (\\i. setter (\\x. x(ptr_coerce p +\\<^sub>p int i := index arr i)))\n [0 ..< CARD('b)] (st s)\"\n apply (clarsimp simp: valid_typ_heap_def)\n\n (* unwrap st *)\n apply (subst fold_over_st[OF refl,\n where P = \"\\s. \\x\\set (array_addrs (ptr_coerce p) CARD('b)). vgetter (st s) x\"\n and g = \"\\i. t_hrs_update (hrs_mem_update (heap_update\n (ptr_coerce p +\\<^sub>p int i) (index arr i)))\"])\n apply simp\n apply (subgoal_tac \"vgetter (st sa) (ptr_coerce p +\\<^sub>p int x)\")\n apply clarsimp\n apply (clarsimp simp: set_array_addrs)\n apply metis\n apply (rule_tac f = st in arg_cong)\n apply (subst hrs_mem_update_def)+\n\n (* unwrap t_hrs_update *)\n apply (subst fold_lift_write[OF refl, where w = t_hrs_update])\n apply assumption\n apply (rule_tac f = \"\\f. t_hrs_update f s\" in arg_cong)\n apply (rule ext)\n apply (subst fold_lift_write[OF refl,\n where r = fst and w = \"\\f s. case s of (h, z) \\ (f h, z)\"])\n apply (simp (no_asm) add: read_write_valid_def)\n apply clarsimp\n\n (* split up array update *)\n apply (clarsimp simp: heap_update_def[abs_def])\n apply (subst coerce_heap_update_to_heap_updates[unfolded foldl_conv_fold,\n where chunk = \"size_of TYPE('a)\" and m = \"CARD('b)\"])\n apply (rule size_of_array[unfolded mult.commute])\n apply simp\n\n (* remove false dependency *)\n apply (subst fold_heap_update_list[OF fourthousand_size])\n apply (rule fold_cong[OF refl refl])\n\n apply (clarsimp simp: ptr_add_def)\n apply (rule_tac f = \"heap_update_list (ptr_val p + of_nat x * of_nat (size_of TYPE('a)))\"\n in arg_cong)\n\n apply (subst fcp_eta[where g = arr, symmetric])\n apply (clarsimp simp: to_bytes_def typ_info_array array_tag_def array_tag_n_eq simp del: fcp_eta)\n apply (subst access_ti_list_array_unpacked)\n apply clarsimp\n apply (rule refl)\n apply (simp add: size_of_def)\n apply clarsimp\n apply (rule refl)\n apply (clarsimp simp: foldl_conv_concat)\n\n (* we need this later *)\n apply (subgoal_tac\n \"\\x. x < CARD('b) \\\n size_td (typ_info_t TYPE('a))\n \\ CARD('b) * size_td (typ_info_t TYPE('a)) - size_td (typ_info_t TYPE('a)) * x\")\n prefer 2\n apply (subst le_diff_conv2)\n apply simp\n apply (subst mult.commute, subst mult_Suc[symmetric])\n apply (rule mult_le_mono1)\n apply simp\n\n apply (subst concat_nth_chunk)\n apply clarsimp\n apply (subst fd_cons_length)\n apply simp\n apply (simp add: size_of_def)\n apply (simp add: size_of_def)\n apply simp\n apply (subst drop_heap_list_le)\n apply (simp add: size_of_def)\n apply (subst take_heap_list_le)\n apply (simp add: size_of_def)\n apply (clarsimp simp: size_of_def)\n apply (subst mult.commute, rule refl)\n done\n\nlemma fold_update_id:\n \"\\ read_write_valid getter setter;\n \\i \\ set xs. \\j \\ set xs. (i = j) = (ind i = ind j);\n \\i \\ set xs. val i = getter s (ind i)\n \\ \\ fold (\\i. setter (\\x. x(ind i := val i))) xs s = s\"\n apply (induct xs)\n apply simp\n apply (rename_tac a xs)\n apply clarsimp\n apply (subgoal_tac \"setter (\\x. x(ind a := getter s (ind a))) s = s\")\n apply simp\n apply (subst (asm) read_write_valid_def)\n apply simp\n done\n\nlemma fourthousand_index:\n \"\\ i < CARD('b::fourthousand_count); j < CARD('b) \\\n \\ (i = j) =\n ((of_nat (i * size_of TYPE('a::oneMB_size)) :: word32)\n = of_nat (j * size_of TYPE('a)))\"\n apply (rule_tac t = \"i = j\" and s = \"i * size_of TYPE('a) = j * size_of TYPE('a)\" in subst)\n apply clarsimp\n apply (metis sz_nzero less_nat_zero_code)\n\n apply (rule of_nat_inj[symmetric])\n apply (rule_tac t = \"len_of TYPE(32)\" and s = 32 in subst,\n simp,\n rule less_trans,\n erule_tac b = \"CARD('b)\" in mult_strict_right_mono,\n rule sz_nzero,\n rule fourthousand_size)+\n done\n\n(* end machinery for heap_abs_array_update *)\n\ntheorem heap_abs_array_update [heap_abs]:\n \"\\ valid_typ_heap st (getter :: 's \\ 'a ptr \\ 'a) setter\n vgetter vsetter t_hrs t_hrs_update;\n abs_expr st Pb b' b;\n abs_expr st Pn n' n;\n abs_expr st Pv v' v\n \\ \\\n abs_modifies st (\\s. Pb s \\ Pn s \\ Pv s \\ n' s < CARD('b) \\\n (\\ptr \\ set (array_addrs (ptr_coerce (b' s)) CARD('b)). (vgetter s ptr)))\n (\\s. setter (\\v. v(ptr_coerce (b' s) +\\<^sub>p int (n' s) := v' s)) s)\n (\\s. t_hrs_update (hrs_mem_update (\n heap_update (b s) (Arrays.update ((h_val (hrs_mem (t_hrs s)) (b s))\n :: ('a::oneMB_size)['b::fourthousand_count]) (n s) (v s)))) s)\"\n apply (clarsimp simp: abs_modifies_def abs_expr_def)\n (* rewrite heap_update of array *)\n apply (subst array_update_split\n [where st = st and t_hrs = t_hrs and t_hrs_update = t_hrs_update])\n apply assumption\n apply assumption\n apply (clarsimp simp: valid_typ_heap_def)\n\n (* rewrite array reads to pointer reads *)\n apply (subst fold_cong[OF refl refl,\n where g = \"\\i. setter (\\x. x(ptr_coerce (b' (st s)) +\\<^sub>p int i :=\n if i = n' (st s) then v' (st s) else getter (st s) (ptr_coerce (b' (st s)) +\\<^sub>p int i)))\"])\n apply (rule_tac f = setter in arg_cong)\n apply (case_tac \"x = n' (st s)\")\n apply simp\n apply (subst index_update2)\n apply simp\n apply simp\n apply (rule_tac x = \"index (h_val (hrs_mem (t_hrs s)) (b' (st s))) x\" in arg_cong)\n apply (subst heap_access_Array_element)\n apply simp\n apply (clarsimp simp: set_array_addrs)\n apply metis\n\n (* split away the indices that don't change *)\n apply (subst split_upt_on_n[where n = \"n s\"])\n apply simp\n apply clarsimp\n\n (* [0.. of_nat (n s * size_of TYPE('a))\")\n apply force\n apply (subst fourthousand_index[symmetric])\n apply assumption\n apply simp\n apply simp\n apply simp\n done\n\n(* Array access, which is considerably simpler than updating. *)\nlemma heap_abs_array_access[heap_abs]:\n \"\\ valid_typ_heap st (getter :: 's \\ ('a::mem_type) ptr \\ 'a) setter\n vgetter vsetter t_hrs t_hrs_update;\n abs_expr st Pb b' b;\n abs_expr st Pn n' n\n \\ \\\n abs_expr st (\\s. Pb s \\ Pn s \\ n' s < CARD('b::finite) \\ vgetter s (ptr_coerce (b' s) +\\<^sub>p int (n' s)))\n (\\s. getter s (ptr_coerce (b' s) +\\<^sub>p int (n' s)))\n (\\s. index (h_val (hrs_mem (t_hrs s)) (b s :: ('a['b]) ptr)) (n s))\"\n apply (clarsimp simp: valid_typ_heap_def abs_expr_def)\n apply (subst heap_access_Array_element)\n apply simp\n apply (simp add: set_array_addrs)\n done\n\n\nlemma the_fun_upd_lemma1:\n \"(\\x. the (f x))(p := v) = (\\x. the ((f (p := Some v)) x))\"\n by auto\n\nlemma the_fun_upd_lemma2:\n \"\\z. f p = Some z \\\n (\\x. \\z. (f (p := Some v)) x = Some z) = (\\x. \\z. f x = Some z) \"\n by auto\n\nlemma the_fun_upd_lemma3:\n \"((\\x. the (f x))(p := v)) x = the ((f (p := Some v)) x)\"\n by simp\n\nlemma the_fun_upd_lemma4:\n \"\\z. f p = Some z \\\n (\\z. (f (p := Some v)) x = Some z) = (\\z. f x = Some z) \"\n by simp\n\nlemmas the_fun_upd_lemmas =\n the_fun_upd_lemma1\n the_fun_upd_lemma2\n the_fun_upd_lemma3\n the_fun_upd_lemma4\n\n\n(* Used by heap_abs_syntax to simplify signed word updates. *)\nlemma sword_update:\n\"\\ptr :: ('a :: len) signed word ptr.\n (\\(x :: 'a word ptr \\ 'a word) p :: 'a word ptr.\n if ptr_coerce p = ptr then scast (n :: 'a signed word) else x (ptr_coerce p))\n =\n (\\(old :: 'a word ptr \\ 'a word) x :: 'a word ptr.\n if x = ptr_coerce ptr then scast n else old x)\"\n by force\n\nend\n","avg_line_length":45.0311958406,"max_line_length":200,"alphanum_fraction":0.664549898} {"size":11393,"ext":"thy","lang":"Isabelle","max_stars_count":11.0,"content":"(* \nThis file is a part of IsarMathLib - \na library of formalized mathematics for Isabelle\/Isar.\n\nCopyright (C) 2005 - 2008 Slawomir Kolodynski\n\nThis program is free software; Redistribution and use in source and binary forms, \nwith or without modification, are permitted provided that the \nfollowing conditions are met:\n\n1. Redistributions of source code must retain the above copyright notice, \n this list of conditions and the following disclaimer.\n 2. Redistributions in binary form must reproduce the above copyright notice, \n this list of conditions and the following disclaimer in the documentation and\/or \n other materials provided with the distribution.\n 3. The name of the author may not be used to endorse or promote products \n derived from this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED \nWARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF \nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \nIN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, \nPROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; \nOR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \nWHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR \nOTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, \nEVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n*)\n\nsection \\Monoids\\\n\ntheory Monoid_ZF imports func_ZF Loop_ZF\n\nbegin\n\ntext\\This theory provides basic facts about monoids.\\\n\nsubsection\\Definition and basic properties\\\n\ntext\\In this section we talk about monoids. \n The notion of a monoid is similar to the notion of a semigroup \n except that we require the existence of a neutral element.\n It is also similar to the notion of group except that\n we don't require existence of the inverse.\\\n\ntext\\Monoid is a set $G$ with an associative operation and a neutral element.\n The operation is a function on $G\\times G$ with values in $G$. \n In the context of ZF set theory this means that it is a set of pairs\n $\\langle x,y \\rangle$, where $x\\in G\\times G$ and $y\\in G$. In other words \n the operation is a certain subset of $(G\\times G)\\times G$. We express\n all this by defing a predicate \\IsAmonoid(G,f)\\. Here $G$ is the \n ''carrier'' of the monoid and $f$ is the binary operation on it.\n\\\n\ndefinition\n \"IsAmonoid(G,f) \\\n f {is associative on} G \\ \n (\\e\\G. (\\ g\\G. ( (f`(\\e,g\\) = g) \\ (f`(\\g,e\\) = g))))\"\n\ntext\\The next locale called ''monoid0'' defines a context for theorems\n that concern monoids. In this contex we assume that the pair $(G,f)$\n is a monoid. We will use\n the \\\\\\ symbol to denote the monoid operation (for \n no particular reason).\\\n\nlocale monoid0 =\n fixes G f\n assumes monoidAsssum: \"IsAmonoid(G,f)\"\n \n fixes monoper (infixl \"\\\" 70)\n defines monoper_def [simp]: \"a \\ b \\ f`\\a,b\\\"\n\ntext\\The result of the monoid operation is in the monoid (carrier).\\\n\nlemma (in monoid0) group0_1_L1: \n assumes \"a\\G\" \"b\\G\" shows \"a\\b \\ G\" \n using assms monoidAsssum IsAmonoid_def IsAssociative_def apply_funtype\n by auto\n\ntext\\There is only one neutral element in a monoid.\\\n\nlemma (in monoid0) group0_1_L2: shows\n \"\\!e. e\\G \\ (\\ g\\G. ( (e\\g = g) \\ g\\e = g))\"\nproof\n fix e y\n assume \"e \\ G \\ (\\g\\G. e \\ g = g \\ g \\ e = g)\"\n and \"y \\ G \\ (\\g\\G. y \\ g = g \\ g \\ y = g)\"\n then have \"y\\e = y\" \"y\\e = e\" by auto\n thus \"e = y\" by simp\nnext from monoidAsssum show \n \"\\e. e\\ G \\ (\\ g\\G. e\\g = g \\ g\\e = g)\"\n using IsAmonoid_def by auto\nqed\n\ntext\\The neutral element is neutral.\\\n\nlemma (in monoid0) unit_is_neutral:\n assumes A1: \"e = TheNeutralElement(G,f)\"\n shows \"e \\ G \\ (\\g\\G. e \\ g = g \\ g \\ e = g)\"\nproof -\n let ?n = \"THE b. b\\ G \\ (\\ g\\G. b\\g = g \\ g\\b = g)\"\n have \"\\!b. b\\ G \\ (\\ g\\G. b\\g = g \\ g\\b = g)\"\n using group0_1_L2 by simp\n then have \"?n\\ G \\ (\\ g\\G. ?n\\g = g \\ g\\?n = g)\"\n by (rule theI)\n with A1 show ?thesis \n using TheNeutralElement_def by simp\nqed\n\ntext\\The monoid carrier is not empty.\\\n\nlemma (in monoid0) group0_1_L3A: shows \"G\\0\"\nproof -\n have \"TheNeutralElement(G,f) \\ G\" using unit_is_neutral\n by simp\n thus ?thesis by auto\nqed\n\ntext\\The range of the monoid operation is the whole monoid carrier.\\\n\nlemma (in monoid0) group0_1_L3B: shows \"range(f) = G\"\nproof\n from monoidAsssum have \"f : G\\G\\G\"\n using IsAmonoid_def IsAssociative_def by simp\n then show \"range(f) \\ G\" \n using func1_1_L5B by simp\n show \"G \\ range(f)\"\n proof\n fix g assume A1: \"g\\G\"\n let ?e = \"TheNeutralElement(G,f)\"\n from A1 have \"\\?e,g\\ \\ G\\G\" \"g = f`\\?e,g\\\"\n using unit_is_neutral by auto\n with \\f : G\\G\\G\\ show \"g \\ range(f)\"\n using func1_1_L5A by blast\n qed\nqed\n\ntext\\Another way to state that the range of the monoid operation\n is the whole monoid carrier.\\\n\nlemma (in monoid0) range_carr: shows \"f``(G\\G) = G\"\n using monoidAsssum IsAmonoid_def IsAssociative_def\n group0_1_L3B range_image_domain by auto\n \ntext\\In a monoid any neutral element is the neutral element.\\\n\nlemma (in monoid0) group0_1_L4: \n assumes A1: \"e \\ G \\ (\\g\\G. e \\ g = g \\ g \\ e = g)\"\n shows \"e = TheNeutralElement(G,f)\"\nproof -\n let ?n = \"THE b. b\\ G \\ (\\ g\\G. b\\g = g \\ g\\b = g)\"\n have \"\\!b. b\\ G \\ (\\ g\\G. b\\g = g \\ g\\b = g)\"\n using group0_1_L2 by simp\n moreover note A1\n ultimately have \"?n = e\" by (rule the_equality2)\n then show ?thesis using TheNeutralElement_def by simp\nqed\n\ntext\\The next lemma shows that if the if we restrict the monoid operation to\n a subset of $G$ that contains the neutral element, then the \n neutral element of the monoid operation is also neutral with the \n restricted operation.\n\\\n\nlemma (in monoid0) group0_1_L5:\n assumes A1: \"\\x\\H.\\y\\H. x\\y \\ H\"\n and A2: \"H\\G\"\n and A3: \"e = TheNeutralElement(G,f)\"\n and A4: \"g = restrict(f,H\\H)\"\n and A5: \"e\\H\"\n and A6: \"h\\H\"\n shows \"g`\\e,h\\ = h \\ g`\\h,e\\ = h\"\nproof -\n from A4 A6 A5 have \n \"g`\\e,h\\ = e\\h \\ g`\\h,e\\ = h\\e\"\n using restrict_if by simp\n with A3 A4 A6 A2 show \n \"g`\\e,h\\ = h \\ g`\\h,e\\ = h\"\n using unit_is_neutral by auto\nqed\n\ntext\\The next theorem shows that if the monoid operation is closed\n on a subset of $G$ then this set is a (sub)monoid (although \n we do not define this notion). This fact will be \n useful when we study subgroups.\\\n\ntheorem (in monoid0) group0_1_T1: \n assumes A1: \"H {is closed under} f\"\n and A2: \"H\\G\"\n and A3: \"TheNeutralElement(G,f) \\ H\"\n shows \"IsAmonoid(H,restrict(f,H\\H))\"\nproof -\n let ?g = \"restrict(f,H\\H)\"\n let ?e = \"TheNeutralElement(G,f)\"\n from monoidAsssum have \"f \\ G\\G\\G\" \n using IsAmonoid_def IsAssociative_def by simp\n moreover from A2 have \"H\\H \\ G\\G\" by auto\n moreover from A1 have \"\\p \\ H\\H. f`(p) \\ H\"\n using IsOpClosed_def by auto\n ultimately have \"?g \\ H\\H\\H\"\n using func1_2_L4 by simp\n moreover have \"\\x\\H.\\y\\H.\\z\\H. \n ?g`\\?g`\\x,y\\ ,z\\ = ?g`\\x,?g`\\y,z\\\\\"\n proof -\n from A1 have \"\\x\\H.\\y\\H.\\z\\H.\n ?g`\\?g`\\x,y\\,z\\ = x\\y\\z\"\n using IsOpClosed_def restrict_if by simp\n moreover have \"\\x\\H.\\y\\H.\\z\\H. x\\y\\z = x\\(y\\z)\"\n proof -\n from monoidAsssum have \n\t\"\\x\\G.\\y\\G.\\z\\G. x\\y\\z = x\\(y\\z)\"\n\tusing IsAmonoid_def IsAssociative_def \n\tby simp\n with A2 show ?thesis by auto\n qed\n moreover from A1 have \n \"\\x\\H.\\y\\H.\\z\\H. x\\(y\\z) = ?g`\\ x,?g`\\y,z\\ \\\"\n using IsOpClosed_def restrict_if by simp\n ultimately show ?thesis by simp \n qed\n moreover have \n \"\\n\\H. (\\h\\H. ?g`\\n,h\\ = h \\ ?g`\\h,n\\ = h)\"\n proof -\n from A1 have \"\\x\\H.\\y\\H. x\\y \\ H\"\n using IsOpClosed_def by simp\n with A2 A3 have \n \"\\ h\\H. ?g`\\?e,h\\ = h \\ ?g`\\h,?e\\ = h\"\n using group0_1_L5 by blast\n with A3 show ?thesis by auto\n qed\n ultimately show ?thesis using IsAmonoid_def IsAssociative_def \n by simp\nqed\n \ntext\\Under the assumptions of \\ group0_1_T1\\\n the neutral element of a \n submonoid is the same as that of the monoid.\\\n\nlemma group0_1_L6: \n assumes A1: \"IsAmonoid(G,f)\"\n and A2: \"H {is closed under} f\"\n and A3: \"H\\G\"\n and A4: \"TheNeutralElement(G,f) \\ H\"\n shows \"TheNeutralElement(H,restrict(f,H\\H)) = TheNeutralElement(G,f)\"\nproof -\n let ?e = \"TheNeutralElement(G,f)\"\n let ?g = \"restrict(f,H\\H)\"\n from assms have \"monoid0(H,?g)\"\n using monoid0_def monoid0.group0_1_T1 \n by simp\n moreover have \n \"?e \\ H \\ (\\h\\H. ?g`\\?e,h\\ = h \\ ?g`\\h,?e\\ = h)\"\n proof -\n { fix h assume \"h \\ H\"\n with assms have\n\t\"monoid0(G,f)\" \"\\x\\H.\\y\\H. f`\\x,y\\ \\ H\" \n\t\"H\\G\" \"?e = TheNeutralElement(G,f)\" \"?g = restrict(f,H\\H)\"\n\t\"?e \\ H\" \"h \\ H\" \n\tusing monoid0_def IsOpClosed_def by auto\n then have \"?g`\\?e,h\\ = h \\ ?g`\\h,?e\\ = h\"\n\tby (rule monoid0.group0_1_L5)\n } hence \"\\h\\H. ?g`\\?e,h\\ = h \\ ?g`\\h,?e\\ = h\" by simp\n with A4 show ?thesis by simp\n qed\n ultimately have \"?e = TheNeutralElement(H,?g)\"\n by (rule monoid0.group0_1_L4)\n thus ?thesis by simp\nqed\n\ntext\\If a sum of two elements is not zero, \n then at least one has to be nonzero.\\\n\nlemma (in monoid0) sum_nonzero_elmnt_nonzero: \n assumes \"a \\ b \\ TheNeutralElement(G,f)\"\n shows \"a \\ TheNeutralElement(G,f) \\ b \\ TheNeutralElement(G,f)\"\n using assms unit_is_neutral by auto\n\nend\n","avg_line_length":40.5444839858,"max_line_length":133,"alphanum_fraction":0.6644430791} {"size":443,"ext":"thy","lang":"Isabelle","max_stars_count":13.0,"content":"name: set-finite-thm\nversion: 1.68\ndescription: Properties of finite sets\nauthor: Joe Leslie-Hurd \nlicense: HOLLight\nprovenance: HOL Light theory exported on 2019-10-31\nrequires: bool\nrequires: function\nrequires: natural\nrequires: pair\nrequires: set-def\nrequires: set-finite-def\nrequires: set-thm\nshow: \"Data.Bool\"\nshow: \"Data.Pair\"\nshow: \"Function\"\nshow: \"Number.Natural\"\nshow: \"Set\"\n\nmain {\n article: \"set-finite-thm.art\"\n}\n","avg_line_length":19.2608695652,"max_line_length":51,"alphanum_fraction":0.7584650113} {"size":27887,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"theory Instance_Graph\n imports \n Main\n Multiplicity_Pair\n Type_Graph\n Extended_Graph_Theory\nbegin\n\nsection \"Node set definitions\"\n\ndatatype ('nt, 'lt) NodeDef = typed \"'lt LabDef\" \"'nt\" | bool bool | int int | real real | string string | invalid\n\nfun nodeType :: \"('nt, 'lt) NodeDef \\ ('lt) LabDef\" where\n \"nodeType (typed t n) = t\" |\n \"nodeType (bool v) = LabDef.bool\" |\n \"nodeType (int v) = LabDef.int\" |\n \"nodeType (real v) = LabDef.real\" |\n \"nodeType (string v) = LabDef.string\" |\n \"nodeType invalid = undefined\"\n\nfun nodeId :: \"('nt, 'lt) NodeDef \\ 'nt\" where\n \"nodeId (typed t n) = n\" | \n \"nodeId _ = undefined\"\n\n\nsubsection \"Typed nodes\"\n\ninductive_set Node\\<^sub>t :: \"('nt, 'lt) NodeDef set\"\n where\n rule_typed_nodes: \"\\t n. t \\ Lab\\<^sub>t \\ typed t n \\ Node\\<^sub>t\"\n\nlemma typed_nodes_member[simp]: \"x \\ Node\\<^sub>t \\ \\y z. x = typed y z\"\n using Node\\<^sub>t.cases by blast\n\nlemma typed_nodes_contains_no_bool[simp]: \"bool x \\ Node\\<^sub>t\"\n using typed_nodes_member by blast\n\nlemma typed_nodes_contains_no_int[simp]: \"int x \\ Node\\<^sub>t\"\n using typed_nodes_member by blast\n\nlemma typed_nodes_contains_no_real[simp]: \"real x \\ Node\\<^sub>t\"\n using typed_nodes_member by blast\n\nlemma typed_nodes_contains_no_string[simp]: \"string x \\ Node\\<^sub>t\"\n using typed_nodes_member by blast\n\nlemma typed_nodes_node_type: \"x \\ Node\\<^sub>t \\ nodeType x \\ Lab\\<^sub>t\"\n using Node\\<^sub>t.cases nodeType.simps(1)\n by metis\n\nlemma typed_nodes_not_invalid[simp]: \"invalid \\ Node\\<^sub>t\"\n using typed_nodes_member by blast\n\n\nsubsection \"Set of value nodes\"\n\nsubsubsection \"Boolean nodes\"\n\ndefinition BooleanNode\\<^sub>v :: \"('nt, 'lt) NodeDef set\" where\n \"BooleanNode\\<^sub>v \\ {bool True, bool False}\"\n\nfun boolValue :: \"('nt, 'lt) NodeDef \\ bool\" where\n \"boolValue (bool v) = v\" |\n \"boolValue _ = undefined\"\n\nlemma boolean_nodes_member[simp]: \"x \\ BooleanNode\\<^sub>v \\ x = bool True \\ x = bool False\"\n by (simp add: BooleanNode\\<^sub>v_def)\n\nlemma boolean_nodes_contains_no_typed_node[simp]: \"typed x y \\ BooleanNode\\<^sub>v\"\n using boolean_nodes_member by blast\n\nlemma boolean_nodes_contains_no_int[simp]: \"int x \\ BooleanNode\\<^sub>v\"\n using boolean_nodes_member by blast\n\nlemma boolean_nodes_contains_no_real[simp]: \"real x \\ BooleanNode\\<^sub>v\"\n using boolean_nodes_member by blast\n\nlemma boolean_nodes_contains_no_string[simp]: \"string x \\ BooleanNode\\<^sub>v\"\n using boolean_nodes_member by blast\n\nlemma boolean_nodes_typed_nodes_intersect[simp]: \"BooleanNode\\<^sub>v \\ Node\\<^sub>t = {}\"\n using typed_nodes_member by fastforce\n\nlemma boolean_nodes_node_type[simp]: \"x \\ BooleanNode\\<^sub>v \\ nodeType x = LabDef.bool\"\n using boolean_nodes_member nodeType.simps(2) by blast\n\nlemma boolean_nodes_not_invalid[simp]: \"invalid \\ BooleanNode\\<^sub>v\"\n using boolean_nodes_member by blast\n\nlemma boolean_nodes_value[simp]: \"x \\ BooleanNode\\<^sub>v \\ x = bool y \\ boolValue x = y\"\n by simp\n\nsubsubsection \"Integer nodes\"\n\ninductive_set IntegerNode\\<^sub>v :: \"('nt, 'lt) NodeDef set\"\n where\n rule_integer_nodes: \"\\i. int i \\ IntegerNode\\<^sub>v\"\n\nfun intValue :: \"('nt, 'lt) NodeDef \\ int\" where\n \"intValue (int v) = v\" |\n \"intValue _ = undefined\"\n\nlemma integer_nodes_member[simp]: \"x \\ IntegerNode\\<^sub>v \\ \\y. x = int y\"\n using IntegerNode\\<^sub>v.cases by blast\n\nlemma integer_nodes_contains_no_typed_node[simp]: \"typed x y \\ IntegerNode\\<^sub>v\"\n using integer_nodes_member by blast\n\nlemma integer_nodes_contains_no_bool[simp]: \"bool x \\ IntegerNode\\<^sub>v\"\n using integer_nodes_member by blast\n\nlemma integer_nodes_contains_no_real[simp]: \"real x \\ IntegerNode\\<^sub>v\"\n using integer_nodes_member by blast\n\nlemma integer_nodes_contains_no_string[simp]: \"string x \\ IntegerNode\\<^sub>v\"\n using integer_nodes_member by blast\n\nlemma integer_nodes_typed_nodes_intersect[simp]: \"IntegerNode\\<^sub>v \\ Node\\<^sub>t = {}\"\n using typed_nodes_member by fastforce\n\nlemma integer_nodes_boolean_nodes_intersect[simp]: \"IntegerNode\\<^sub>v \\ BooleanNode\\<^sub>v = {}\"\n using boolean_nodes_member by fastforce\n\nlemma integer_nodes_node_type[simp]: \"x \\ IntegerNode\\<^sub>v \\ nodeType x = LabDef.int\"\n using integer_nodes_member nodeType.simps(3) by blast\n\nlemma integer_nodes_not_invalid[simp]: \"invalid \\ IntegerNode\\<^sub>v\"\n using integer_nodes_member by blast\n\nlemma integer_nodes_value[simp]: \"x \\ IntegerNode\\<^sub>v \\ x = int y \\ intValue x = y\"\n by simp\n\nsubsubsection \"Real nodes\"\n\ninductive_set RealNode\\<^sub>v :: \"('nt, 'lt) NodeDef set\"\n where\n rule_real_nodes: \"\\r. real r \\ RealNode\\<^sub>v\"\n\nfun realValue :: \"('nt, 'lt) NodeDef \\ real\" where\n \"realValue (real v) = v\" |\n \"realValue _ = undefined\"\n\nlemma real_nodes_member[simp]: \"x \\ RealNode\\<^sub>v \\ \\y. x = real y\"\n using RealNode\\<^sub>v.cases by blast\n\nlemma real_nodes_contains_no_typed_node[simp]: \"typed x y \\ RealNode\\<^sub>v\"\n using real_nodes_member by blast\n\nlemma real_nodes_contains_no_bool[simp]: \"bool x \\ RealNode\\<^sub>v\"\n using real_nodes_member by blast\n\nlemma real_nodes_contains_no_int[simp]: \"int x \\ RealNode\\<^sub>v\"\n using real_nodes_member by blast\n\nlemma real_nodes_contains_no_string[simp]: \"string x \\ RealNode\\<^sub>v\"\n using real_nodes_member by blast\n\nlemma real_nodes_typed_nodes_intersect[simp]: \"RealNode\\<^sub>v \\ Node\\<^sub>t = {}\"\n using typed_nodes_member by fastforce\n\nlemma real_nodes_boolean_nodes_intersect[simp]: \"RealNode\\<^sub>v \\ BooleanNode\\<^sub>v = {}\"\n using boolean_nodes_member by fastforce\n\nlemma real_nodes_integer_nodes_intersect[simp]: \"RealNode\\<^sub>v \\ IntegerNode\\<^sub>v = {}\"\n using integer_nodes_member by fastforce\n\nlemma real_nodes_node_type[simp]: \"x \\ RealNode\\<^sub>v \\ nodeType x = LabDef.real\"\n using real_nodes_member nodeType.simps(4) by blast\n\nlemma real_nodes_not_invalid[simp]: \"invalid \\ RealNode\\<^sub>v\"\n using real_nodes_member by blast\n\nlemma real_nodes_value[simp]: \"x \\ RealNode\\<^sub>v \\ x = real y \\ realValue x = y\"\n by simp\n\nsubsubsection \"String nodes\"\n\ninductive_set StringNode\\<^sub>v :: \"('nt, 'lt) NodeDef set\"\n where\n rule_string_nodes: \"\\s. string s \\ StringNode\\<^sub>v\"\n\nfun stringValue :: \"('nt, 'lt) NodeDef \\ string\" where\n \"stringValue (string v) = v\" |\n \"stringValue _ = undefined\"\n\nlemma string_nodes_member[simp]: \"x \\ StringNode\\<^sub>v \\ \\y. x = string y\"\n using StringNode\\<^sub>v.cases by blast\n\nlemma string_nodes_contains_no_typed_node[simp]: \"typed x y \\ StringNode\\<^sub>v\"\n using string_nodes_member by blast\n\nlemma string_nodes_contains_no_bool[simp]: \"bool x \\ StringNode\\<^sub>v\"\n using string_nodes_member by blast\n\nlemma string_nodes_contains_no_int[simp]: \"int x \\ StringNode\\<^sub>v\"\n using string_nodes_member by blast\n\nlemma string_nodes_contains_no_real[simp]: \"real x \\ StringNode\\<^sub>v\"\n using string_nodes_member by blast\n\nlemma string_nodes_typed_nodes_intersect[simp]: \"StringNode\\<^sub>v \\ Node\\<^sub>t = {}\"\n using typed_nodes_member by fastforce\n\nlemma string_nodes_boolean_nodes_intersect[simp]: \"StringNode\\<^sub>v \\ BooleanNode\\<^sub>v = {}\"\n using boolean_nodes_member by fastforce\n\nlemma string_nodes_integer_nodes_intersect[simp]: \"StringNode\\<^sub>v \\ IntegerNode\\<^sub>v = {}\"\n using integer_nodes_member by fastforce\n\nlemma string_nodes_real_nodes_intersect[simp]: \"StringNode\\<^sub>v \\ RealNode\\<^sub>v = {}\"\n using real_nodes_member by fastforce\n\nlemma string_nodes_node_type[simp]: \"x \\ StringNode\\<^sub>v \\ nodeType x = LabDef.string\"\n using string_nodes_member nodeType.simps(5) by blast\n\nlemma string_nodes_not_invalid[simp]: \"invalid \\ StringNode\\<^sub>v\"\n using string_nodes_member by blast\n\nlemma string_nodes_value[simp]: \"x \\ StringNode\\<^sub>v \\ x = string y \\ stringValue x = y\"\n by simp\n\nsubsubsection \"Value nodes\"\n\ndefinition Node\\<^sub>v :: \"('nt, 'lt) NodeDef set\" where\n \"Node\\<^sub>v \\ BooleanNode\\<^sub>v \\ IntegerNode\\<^sub>v \\ RealNode\\<^sub>v \\ StringNode\\<^sub>v\"\n\nlemma value_nodes_member[simp]: \"x \\ Node\\<^sub>v \\ x = bool True \\ x = bool False \\ (\\y. x = int y) \\ (\\y. x = real y) \\ (\\y. x = string y)\"\n unfolding Node\\<^sub>v_def\n using boolean_nodes_member integer_nodes_member real_nodes_member string_nodes_member\n by blast\n\nlemma value_nodes_contains_no_typed_node[simp]: \"typed x y \\ Node\\<^sub>v\"\n using value_nodes_member by blast\n\nlemma value_nodes_typed_nodes_intersect[simp]: \"Node\\<^sub>v \\ Node\\<^sub>t = {}\"\n using typed_nodes_member by fastforce\n\nlemma value_nodes_boolean_nodes_intersect[simp]: \"Node\\<^sub>v \\ BooleanNode\\<^sub>v = BooleanNode\\<^sub>v\"\n using Node\\<^sub>v_def by fastforce\n\nlemma value_nodes_integer_nodes_intersect[simp]: \"Node\\<^sub>v \\ IntegerNode\\<^sub>v = IntegerNode\\<^sub>v\"\n using Node\\<^sub>v_def by fastforce\n\nlemma value_nodes_real_nodes_intersect[simp]: \"Node\\<^sub>v \\ RealNode\\<^sub>v = RealNode\\<^sub>v\"\n using Node\\<^sub>v_def by fastforce\n\nlemma value_nodes_string_nodes_intersect[simp]: \"Node\\<^sub>v \\ StringNode\\<^sub>v = StringNode\\<^sub>v\"\n using Node\\<^sub>v_def by fastforce\n\nlemma value_nodes_contain_boolean_nodes[simp]: \"BooleanNode\\<^sub>v \\ Node\\<^sub>v\"\n using value_nodes_boolean_nodes_intersect by fastforce\n\nlemma value_nodes_contain_integer_nodes[simp]: \"IntegerNode\\<^sub>v \\ Node\\<^sub>v\"\n using value_nodes_integer_nodes_intersect by fastforce\n\nlemma value_nodes_contain_real_nodes[simp]: \"RealNode\\<^sub>v \\ Node\\<^sub>v\"\n using value_nodes_real_nodes_intersect by fastforce\n\nlemma value_nodes_contain_string_nodes[simp]: \"StringNode\\<^sub>v \\ Node\\<^sub>v\"\n using value_nodes_string_nodes_intersect by fastforce\n\nlemma value_nodes_node_type: \"x \\ Node\\<^sub>v \\ nodeType x \\ Lab\\<^sub>p\"\n using Lab\\<^sub>p_def value_nodes_member by fastforce\n\nlemma value_nodes_not_invalid[simp]: \"invalid \\ Node\\<^sub>v\"\n using value_nodes_member by blast\n\n\nsubsection \"Nodes\"\n\ndefinition Node :: \"('nt, 'lt) NodeDef set\" where\n \"Node \\ Node\\<^sub>t \\ Node\\<^sub>v\"\n\nlemma nodes_typed_nodes_intersect[simp]: \"Node \\ Node\\<^sub>t = Node\\<^sub>t\"\n using Node_def by fastforce\n\nlemma nodes_value_nodes_intersect[simp]: \"Node \\ Node\\<^sub>v = Node\\<^sub>v\"\n using Node_def by fastforce\n\nlemma nodes_boolean_nodes_intersect[simp]: \"Node \\ BooleanNode\\<^sub>v = BooleanNode\\<^sub>v\"\n using nodes_value_nodes_intersect value_nodes_boolean_nodes_intersect\n by blast\n\nlemma nodes_integer_nodes_intersect[simp]: \"Node \\ IntegerNode\\<^sub>v = IntegerNode\\<^sub>v\"\n using nodes_value_nodes_intersect value_nodes_integer_nodes_intersect\n by blast\n\nlemma nodes_real_nodes_intersect[simp]: \"Node \\ RealNode\\<^sub>v = RealNode\\<^sub>v\"\n using nodes_value_nodes_intersect value_nodes_real_nodes_intersect\n by blast\n\nlemma nodes_string_nodes_intersect[simp]: \"Node \\ StringNode\\<^sub>v = StringNode\\<^sub>v\"\n using nodes_value_nodes_intersect value_nodes_string_nodes_intersect\n by blast\n\nlemma nodes_contain_typed_nodes[simp]: \"Node\\<^sub>t \\ Node\"\n using nodes_typed_nodes_intersect by fastforce\n\nlemma nodes_contain_value_nodes[simp]: \"Node\\<^sub>v \\ Node\"\n using nodes_value_nodes_intersect by fastforce\n\nlemma nodes_contain_boolean_nodes[simp]: \"BooleanNode\\<^sub>v \\ Node\"\n using nodes_boolean_nodes_intersect by fastforce\n\nlemma nodes_contain_integer_nodes[simp]: \"IntegerNode\\<^sub>v \\ Node\"\n using nodes_integer_nodes_intersect by fastforce\n\nlemma nodes_contain_real_nodes[simp]: \"RealNode\\<^sub>v \\ Node\"\n using nodes_real_nodes_intersect by fastforce\n\nlemma nodes_contain_string_nodes[simp]: \"StringNode\\<^sub>v \\ Node\"\n using nodes_string_nodes_intersect by fastforce\n\nlemma nodes_node_type: \"x \\ Node \\ nodeType x \\ Lab\\<^sub>t \\ Lab\\<^sub>p\"\n using Node_def typed_nodes_node_type value_nodes_node_type by auto\n\nlemma nodes_not_invalid[simp]: \"invalid \\ Node\"\n unfolding Node_def\n by simp\n\n\n\nsection \"Instance graph tuple definition\"\n\nrecord ('nt, 'lt, 'id) instance_graph =\n TG :: \"('lt) type_graph\"\n Id :: \"'id set\"\n N :: \"('nt, 'lt) NodeDef set\"\n E :: \"(('nt, 'lt) NodeDef \\ ('lt LabDef \\ 'lt LabDef \\ 'lt LabDef) \\ ('nt, 'lt) NodeDef) set\"\n ident :: \"'id \\ ('nt, 'lt) NodeDef\"\n\n\n\nsection \"Types\"\n\ndefinition type\\<^sub>n :: \"('nt, 'lt) NodeDef \\ 'lt LabDef\" where\n \"type\\<^sub>n \\ nodeType\"\n\ndeclare type\\<^sub>n_def[simp add]\n\ndefinition type\\<^sub>e :: \"('nt, 'lt) NodeDef \\ ('lt LabDef \\ 'lt LabDef \\ 'lt LabDef) \\ ('nt, 'lt) NodeDef \\ 'lt LabDef \\ 'lt LabDef \\ 'lt LabDef\" where\n \"type\\<^sub>e e \\ fst (snd e)\"\n\ndeclare type\\<^sub>e_def[simp add]\n\n\n\nsection \"Graph theory projection\"\n\ndefinition instance_graph_proj :: \"('nt, 'lt, 'id) instance_graph \\ (('nt, 'lt) NodeDef, ('nt, 'lt) NodeDef \\ ('lt LabDef \\ 'lt LabDef \\ 'lt LabDef) \\ ('nt, 'lt) NodeDef) pre_digraph\" where\n \"instance_graph_proj IG = \\ verts = N IG, arcs = E IG, tail = tgt, head = src \\\"\n\ndeclare [[coercion instance_graph_proj]]\n\ndefinition instance_graph_containment_proj :: \"('nt, 'lt, 'id) instance_graph \\ (('nt, 'lt) NodeDef, ('nt, 'lt) NodeDef \\ ('lt LabDef \\ 'lt LabDef \\ 'lt LabDef) \\ ('nt, 'lt) NodeDef) pre_digraph\" where\n \"instance_graph_containment_proj IG = \\ verts = N IG, arcs = { e \\ E IG. type\\<^sub>e e \\ contains (TG IG) }, tail = tgt, head = src \\\"\n\n\n\nsection \"Instance graph validity\"\n\nlocale instance_graph = fixes IG :: \"('nt, 'lt, 'id) instance_graph\"\n assumes structure_nodes_wellformed[simp]: \"\\n. n \\ N IG \\ n \\ Node\"\n assumes structure_edges_wellformed: \"\\s l t. (s, l, t) \\ E IG \\ s \\ N IG \\ l \\ ET (TG IG) \\ t \\ N IG\"\n assumes structure_ident_wellformed: \"\\i. i \\ Id IG \\ ident IG i \\ N IG \\ type\\<^sub>n (ident IG i) \\ Lab\\<^sub>t\"\n assumes structure_ident_domain[simp]: \"\\i. i \\ Id IG \\ ident IG i = undefined\"\n assumes validity_type_graph[simp]: \"type_graph (TG IG)\"\n assumes validity_node_typed[simp]: \"\\n. n \\ N IG \\ type\\<^sub>n n \\ NT (TG IG)\"\n assumes validity_edge_src_typed[simp]: \"\\e. e \\ E IG \\ (type\\<^sub>n (src e), src (type\\<^sub>e e)) \\ inh (TG IG)\"\n assumes validity_edge_tgt_typed[simp]: \"\\e. e \\ E IG \\ (type\\<^sub>n (tgt e), tgt (type\\<^sub>e e)) \\ inh (TG IG)\"\n assumes validity_abs_no_instances[simp]: \"\\n. n \\ N IG \\ type\\<^sub>n n \\ abs (TG IG)\"\n assumes validity_outgoing_mult[simp]: \"\\et n. et \\ ET (TG IG) \\ n \\ N IG \\ (type\\<^sub>n n, src et) \\ inh (TG IG) \\ card { e. e \\ E IG \\ src e = n \\ type\\<^sub>e e = et} in m_out (mult (TG IG) et)\"\n assumes validity_ingoing_mult[simp]: \"\\et n. et \\ ET (TG IG) \\ n \\ N IG \\ (type\\<^sub>n n, tgt et) \\ inh (TG IG) \\ card { e. e \\ E IG \\ tgt e = n \\ type\\<^sub>e e = et} in m_in (mult (TG IG) et)\"\n assumes validity_contained_node[simp]: \"\\n. n \\ N IG \\ card { e. e \\ E IG \\ tgt e = n \\ type\\<^sub>e e \\ contains (TG IG) } \\ 1\"\n assumes validity_containment[simp]: \"\\p. \\pre_digraph.cycle (instance_graph_containment_proj IG) p\"\n\ncontext instance_graph \nbegin\n\nlemma structure_edges_wellformed_src_node[simp]: \"\\s. (s, l, t) \\ E IG \\ s \\ N IG\"\n by (simp add: structure_edges_wellformed)\n\nlemma structure_edges_wellformed_edge_type[simp]: \"\\l. (s, l, t) \\ E IG \\ l \\ ET (TG IG)\"\n by (simp add: structure_edges_wellformed)\n\nlemma structure_edges_wellformed_tgt_node[simp]: \"\\t. (s, l, t) \\ E IG \\ t \\ N IG\"\n by (simp add: structure_edges_wellformed)\n\nlemma structure_edges_wellformed_alt: \"\\e. e \\ E IG \\ src e \\ N IG \\ type\\<^sub>e e \\ ET (TG IG) \\ tgt e \\ N IG\"\n by auto\n\nlemma structure_edges_wellformed_src_node_alt[simp]: \"\\e. e \\ E IG \\ src e \\ N IG\"\n by auto\n\nlemma structure_edges_wellformed_edge_type_alt[simp]: \"\\e. e \\ E IG \\ type\\<^sub>e e \\ ET (TG IG)\"\n by auto\n\nlemma structure_edges_wellformed_tgt_node_alt[simp]: \"\\e. e \\ E IG \\ tgt e \\ N IG\"\n by auto\n\nlemma structure_ident_wellformed_node[simp]: \"\\i. i \\ Id IG \\ ident IG i \\ N IG\"\n using structure_ident_wellformed\n by blast\n\nlemma structure_ident_wellformed_node_type[simp]: \"\\i. i \\ Id IG \\ type\\<^sub>n (ident IG i) \\ Lab\\<^sub>t\"\n using structure_ident_wellformed\n by blast\n\nlemma validity_edge_src_typed_alt[simp]: \"\\s l t. (s, l, t) \\ E IG \\ (type\\<^sub>n s, src l) \\ inh (TG IG)\"\nproof-\n fix s l t\n assume \"(s, l, t) \\ E IG\"\n then have \"(type\\<^sub>n (src (s, l, t)), src (type\\<^sub>e (s, l, t))) \\ inh (TG IG)\"\n by (fact validity_edge_src_typed)\n then show \"(type\\<^sub>n s, src l) \\ inh (TG IG)\"\n by simp\nqed\n\nlemma validity_edge_tgt_typed_alt[simp]: \"\\s l t. (s, l, t) \\ E IG \\ (type\\<^sub>n t, tgt l) \\ inh (TG IG)\"\nproof-\n fix s l t\n assume \"(s, l, t) \\ E IG\"\n then have \"(type\\<^sub>n (tgt (s, l, t)), tgt (type\\<^sub>e (s, l, t))) \\ inh (TG IG)\"\n by (fact validity_edge_tgt_typed)\n then show \"(type\\<^sub>n t, tgt l) \\ inh (TG IG)\"\n by simp\nqed\n\nlemma validity_contained_node_alt[simp]: \"\\n. n \\ N IG \\ card { (s, l, t). (s, l, t) \\ E IG \\ t = n \\ l \\ contains (TG IG) } \\ 1\"\nproof-\n fix n\n assume n_in_nodes: \"n \\ N IG\"\n have \"{ e. e \\ E IG \\ tgt e = n \\ type\\<^sub>e e \\ contains (TG IG) } = { (s, l, t). (s, l, t) \\ E IG \\ tgt (s, l, t) = n \\ type\\<^sub>e (s, l, t) \\ contains (TG IG) }\"\n by blast\n then have \"card { (s, l, t). (s, l, t) \\ E IG \\ tgt (s, l, t) = n \\ type\\<^sub>e (s, l, t) \\ contains (TG IG) } \\ 1\"\n using n_in_nodes validity_contained_node by fastforce\n then show \"card { (s, l, t). (s, l, t) \\ E IG \\ t = n \\ l \\ contains (TG IG) } \\ 1\"\n by simp\nqed\n\nend\n\n\n\nsection \"Graph theory compatibility\"\n\nsublocale instance_graph \\ pre_digraph \"instance_graph_proj IG\"\n rewrites \"verts IG = N IG\" and \"arcs IG = E IG\" and \"tail IG = tgt\" and \"head IG = src\"\n by unfold_locales (simp_all add: instance_graph_proj_def)\n\nsublocale instance_graph \\ wf_digraph IG\nproof\n have verts_are_nodes: \"verts (instance_graph_proj IG) = N IG\"\n by (simp add: instance_graph_proj_def)\n have head_is_src: \"head (instance_graph_proj IG) = src\"\n by (simp add: instance_graph_proj_def)\n have tail_is_tgt: \"tail (instance_graph_proj IG) = tgt\"\n by (simp add: instance_graph_proj_def)\n fix e\n assume \"e \\ arcs (instance_graph_proj IG)\"\n then have e_in_edges: \"e \\ E IG\"\n by (simp add: instance_graph_proj_def)\n show \"tail (instance_graph_proj IG) e \\ verts (instance_graph_proj IG)\"\n using e_in_edges verts_are_nodes tail_is_tgt structure_edges_wellformed_tgt_node_alt \n by auto\n show \"head (instance_graph_proj IG) e \\ verts (instance_graph_proj IG)\"\n using e_in_edges verts_are_nodes head_is_src structure_edges_wellformed_src_node_alt \n by auto\nqed\n\nlemma validity_containment_alt:\n assumes structure_edges_wellformed: \"\\e. e \\ E IG \\ type\\<^sub>e e \\ contains (TG IG) \\ src e \\ N IG \\ tgt e \\ N IG\"\n assumes validity_containment: \"\\p. \\pre_digraph.cycle (instance_graph_containment_proj IG) p\"\n shows \"irrefl ((edge_to_tuple ` { e \\ E IG. type\\<^sub>e e \\ contains (TG IG) })\\<^sup>+)\"\nproof-\n have \"irrefl ((pre_digraph.arc_to_tuple (instance_graph_containment_proj IG) ` arcs (instance_graph_containment_proj IG))\\<^sup>+)\"\n proof (intro wf_digraph.acyclic_impl_irrefl_trancl)\n show \"wf_digraph (instance_graph_containment_proj IG)\"\n proof (intro wf_digraph.intro)\n fix e\n assume \"e \\ arcs (instance_graph_containment_proj IG)\"\n then have \"e \\ { e \\ E IG. type\\<^sub>e e \\ contains (TG IG) }\"\n unfolding instance_graph_containment_proj_def\n by simp\n then show \"tail (instance_graph_containment_proj IG) e \\ verts (instance_graph_containment_proj IG)\"\n unfolding instance_graph_containment_proj_def\n using structure_edges_wellformed\n by simp\n next\n fix e\n assume \"e \\ arcs (instance_graph_containment_proj IG)\"\n then have \"e \\ { e \\ E IG. type\\<^sub>e e \\ contains (TG IG) }\"\n unfolding instance_graph_containment_proj_def\n by simp\n then show \"head (instance_graph_containment_proj IG) e \\ verts (instance_graph_containment_proj IG)\"\n unfolding instance_graph_containment_proj_def\n using structure_edges_wellformed\n by simp\n qed\n next\n show \"\\p. \\pre_digraph.cycle (instance_graph_containment_proj IG) p\"\n by (fact validity_containment)\n qed\n then show \"irrefl ((edge_to_tuple ` { e \\ E IG. type\\<^sub>e e \\ contains (TG IG) })\\<^sup>+)\"\n unfolding pre_digraph.arc_to_tuple_def edge_to_tuple_def instance_graph_containment_proj_def\n by simp\nqed\n\nlemma (in instance_graph) validity_containment_alt':\n shows \"irrefl ((edge_to_tuple ` { e \\ E IG. type\\<^sub>e e \\ contains (TG IG) })\\<^sup>+)\"\nproof (intro validity_containment_alt)\n show \"\\e. e \\ E IG \\ type\\<^sub>e e \\ contains (TG IG) \\ src e \\ N IG \\ tgt e \\ N IG\"\n by fastforce\nnext\n show \"\\p. \\pre_digraph.cycle (instance_graph_containment_proj IG) p\"\n by simp\nqed\n\nlemma validity_containmentI[intro]:\n assumes structure_edges_wellformed: \"\\e. e \\ E IG \\ type\\<^sub>e e \\ contains (TG IG) \\ src e \\ N IG \\ tgt e \\ N IG\"\n assumes irrefl_contains_edges: \"irrefl ((edge_to_tuple ` { e \\ E IG. type\\<^sub>e e \\ contains (TG IG) })\\<^sup>+)\"\n shows \"\\pre_digraph.cycle (instance_graph_containment_proj IG) p\"\nproof (intro wf_digraph.irrefl_trancl_impl_acyclic)\n show \"wf_digraph (instance_graph_containment_proj IG)\"\n proof (intro wf_digraph.intro)\n fix e\n assume \"e \\ arcs (instance_graph_containment_proj IG)\"\n then have \"e \\ { e \\ E IG. type\\<^sub>e e \\ contains (TG IG) }\"\n unfolding instance_graph_containment_proj_def\n by simp\n then show \"tail (instance_graph_containment_proj IG) e \\ verts (instance_graph_containment_proj IG)\"\n unfolding instance_graph_containment_proj_def\n using structure_edges_wellformed\n by simp\n next\n fix e\n assume \"e \\ arcs (instance_graph_containment_proj IG)\"\n then have \"e \\ { e \\ E IG. type\\<^sub>e e \\ contains (TG IG) }\"\n unfolding instance_graph_containment_proj_def\n by simp\n then show \"head (instance_graph_containment_proj IG) e \\ verts (instance_graph_containment_proj IG)\"\n unfolding instance_graph_containment_proj_def\n using structure_edges_wellformed\n by simp\n qed\nnext\n have \"pre_digraph.arc_to_tuple (instance_graph_containment_proj IG) ` arcs (instance_graph_containment_proj IG) =\n edge_to_tuple ` { e \\ E IG. type\\<^sub>e e \\ contains (TG IG) }\"\n proof\n show \"pre_digraph.arc_to_tuple (instance_graph_containment_proj IG) ` arcs (instance_graph_containment_proj IG)\n \\ edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)}\"\n proof\n fix x\n assume \"x \\ pre_digraph.arc_to_tuple (instance_graph_containment_proj IG) ` arcs (instance_graph_containment_proj IG)\"\n then show \"x \\ edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)}\"\n proof\n fix xa\n assume x_is_xa: \"x = pre_digraph.arc_to_tuple (instance_graph_containment_proj IG) xa\"\n assume \"xa \\ arcs (instance_graph_containment_proj IG)\"\n then have \"pre_digraph.arc_to_tuple (instance_graph_containment_proj IG) xa \n \\ edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)}\"\n unfolding instance_graph_containment_proj_def pre_digraph.arc_to_tuple_def\n by simp\n then show \"x \\ edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)}\"\n by (simp add: x_is_xa)\n qed\n qed\n next\n show \"edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)}\n \\ pre_digraph.arc_to_tuple (instance_graph_containment_proj IG) ` arcs (instance_graph_containment_proj IG)\"\n proof\n fix x\n assume \"x \\ edge_to_tuple ` {e \\ E IG. type\\<^sub>e e \\ contains (TG IG)}\"\n then show \"x \\ pre_digraph.arc_to_tuple (instance_graph_containment_proj IG) ` arcs (instance_graph_containment_proj IG)\"\n unfolding instance_graph_containment_proj_def pre_digraph.arc_to_tuple_def edge_to_tuple_def\n by simp\n qed\n qed\n then show \"irrefl ((pre_digraph.arc_to_tuple (instance_graph_containment_proj IG) ` arcs (instance_graph_containment_proj IG))\\<^sup>+)\"\n using irrefl_contains_edges\n by simp\nqed\n\n\n\nsection \"Validity of trivial instance graphs\"\n\ndefinition ig_empty :: \"('nt, 'lt, 'id) instance_graph\" where\n [simp]: \"ig_empty = \\\n TG = tg_empty,\n Id = {},\n N = {},\n E = {},\n ident = (\\x. undefined)\n \\\"\n\nlemma ig_empty_correct[simp]: \"instance_graph ig_empty\"\nproof (intro instance_graph.intro)\n show \"type_graph (TG ig_empty)\"\n unfolding ig_empty_def\n using tg_empty_correct\n by simp\nnext\n fix p :: \"(('nt, 'lt) NodeDef \\ ('lt LabDef \\ 'lt LabDef \\ 'lt LabDef) \\ ('nt, 'lt) NodeDef) awalk\"\n show \"\\pre_digraph.cycle (instance_graph_containment_proj ig_empty) p\"\n unfolding instance_graph_containment_proj_def pre_digraph.cycle_def pre_digraph.awalk_def\n by simp\nqed (simp_all)\n\nlemma ig_empty_any_type_graph_correct[simp]:\n assumes instance_graph_type_graph: \"type_graph (TG IG)\"\n assumes instance_graph_id: \"Id IG = {}\"\n assumes instance_graph_nodes: \"N IG = {}\"\n assumes instance_graph_edges: \"E IG = {}\"\n assumes instance_graph_ident: \"ident IG = (\\x. undefined)\"\n shows \"instance_graph IG\"\nproof (intro instance_graph.intro)\n fix p\n show \"\\pre_digraph.cycle (instance_graph_containment_proj IG) p\"\n unfolding instance_graph_containment_proj_def pre_digraph.cycle_def pre_digraph.awalk_def\n by (simp add: instance_graph_nodes)\nqed (simp_all add: assms)\n\nend\n","avg_line_length":44.6192,"max_line_length":278,"alphanum_fraction":0.7076056944} {"size":38745,"ext":"thy","lang":"Isabelle","max_stars_count":null,"content":"theory Reordering_Quantifiers\n imports Main \"HOL-Eisbach.Eisbach\"\nbegin\n\n(* Printing util *)\nML \\\n fun pretty_cterm ctxt ctm = Syntax.pretty_term ctxt (Thm.term_of ctm)\n val string_of_cterm = Pretty.string_of oo pretty_cterm\n val string_of_term = Pretty.string_of oo Syntax.pretty_term\n\\\n\nML_val \\tracing (Syntax.string_of_term @{context} @{term \"a < b\"})\\\n\nML_val \\tracing (ML_Syntax.print_term @{term \"a < b\"})\\\n\nML \\\n fun strip_prop (Const (@{const_name HOL.Trueprop}, _) $ t) = t\n | strip_prop t = t\n\\\n\ndeclare [[ML_print_depth = 50]]\n\nML \\\n signature QUANTIFIER1_DATA =\nsig\n (*functionality*)\n (*terms to be moved around*)\n (*arguments: preceding quantifies, term under question, preceding terms*)\n val move: (term * string * typ) list -> term -> term list -> bool\n (*always move? if false then moves appear if a non-mover was encountered before*)\n val force_move: bool\n (*rotate quantifiers after moving*)\n val rotate: bool\n (*abstract syntax*)\n val dest_eq: term -> (term * term) option\n val dest_conj: term -> (term * term) option\n val dest_imp: term -> (term * term) option\n val conj: term\n val imp: term\n (*rules*)\n val iff_reflection: thm (* P <-> Q ==> P == Q *)\n val iffI: thm\n val iff_trans: thm\n val conjI: thm\n val conjE: thm\n val impI: thm\n val mp: thm\n val exI: thm\n val exE: thm\n val uncurry: thm (* P --> Q --> R ==> P & Q --> R *)\n val iff_allI: thm (* !!x. P x <-> Q x ==> (!x. P x) = (!x. Q x) *)\n val iff_exI: thm (* !!x. P x <-> Q x ==> (? x. P x) = (? x. Q x) *)\n val all_comm: thm (* (!x y. P x y) = (!y x. P x y) *)\n val ex_comm: thm (* (? x y. P x y) = (? y x. P x y) *)\nend;\n\nsignature QUANTIFIER1 =\nsig\n val prove_one_point_all_tac: Proof.context -> tactic\n val prove_one_point_ex_tac: Proof.context -> tactic\n val rearrange_all: Proof.context -> cterm -> thm option\n (* XXX Need to export this ?*)\n val rearrange_ex': Proof.context -> term -> thm option\n val rearrange_ex: Proof.context -> cterm -> thm option\n val rotate_ex: Proof.context -> cterm -> thm option\n val miniscope_ex: Proof.context -> cterm -> thm option\n val rotate_all: Proof.context -> cterm -> thm option\n val rearrange_ball: (Proof.context -> tactic) -> Proof.context -> cterm -> thm option\n val rearrange_bex: (Proof.context -> tactic) -> Proof.context -> cterm -> thm option\n val rearrange_Collect: (Proof.context -> tactic) -> Proof.context -> cterm -> thm option\nend;\n\nfunctor Quantifier(Data: QUANTIFIER1_DATA): QUANTIFIER1 =\nstruct\n\nfun extract_conj trms fst xs t =\n (case Data.dest_conj t of\n NONE => NONE\n | SOME (P, Q) =>\n let\n val mover = Data.move xs P trms\n in\n if Data.force_move andalso mover then (if fst then NONE else SOME (xs, P, Q))\n else if Data.force_move andalso Data.move xs Q (P :: trms) then SOME (xs, Q, P)\n else if mover andalso not fst then SOME (xs, P, Q)\n else if\n not Data.force_move andalso (not mover orelse not fst) andalso Data.move xs Q (P :: trms)\n then SOME (xs, Q, P)\n else\n (case extract_conj trms (if Data.force_move then false else fst) xs P of\n SOME (xs, eq, P') => SOME (xs, eq, Data.conj $ P' $ Q)\n | NONE =>\n (case extract_conj (P :: trms)\n (if Data.force_move then false else (fst andalso mover)) xs Q\n of\n SOME (xs, eq, Q') => SOME (xs, eq, Data.conj $ P $ Q')\n | NONE => NONE))\n end);\n(* XXX This is not regularized with respect to term context *)\nfun extract_imp fst xs t =\n (case Data.dest_imp t of\n NONE => NONE\n | SOME (P, Q) =>\n if Data.move xs P [] then (if fst then NONE else SOME (xs, P, Q))\n else\n (case extract_conj [] false xs P of\n SOME (xs, eq, P') => SOME (xs, eq, Data.imp $ P' $ Q)\n | NONE =>\n (case extract_imp false xs Q of\n NONE => NONE\n | SOME (xs, eq, Q') => SOME (xs, eq, Data.imp $ P $ Q'))));\n\nfun extract_quant extract q =\n let\n fun exqu xs ((qC as Const (qa, _)) $ Abs (x, T, Q)) =\n if qa = q then exqu ((qC, x, T) :: xs) Q else NONE\n | exqu xs P = extract (if Data.force_move then null xs else true) xs P\n in exqu [] end;\n\nfun prove_conv ctxt tu tac =\n let\n val (goal, ctxt') =\n yield_singleton (Variable.import_terms true) (Logic.mk_equals tu) ctxt;\n val thm =\n Goal.prove ctxt' [] [] goal\n (fn {context = ctxt'', ...} =>\n resolve_tac ctxt'' [Data.iff_reflection] 1 THEN tac ctxt'');\n in singleton (Variable.export ctxt' ctxt) thm end;\n\nfun maybe_tac tac = if Data.rotate then tac else K all_tac;\n\nfun qcomm_tac ctxt qcomm qI i =\n REPEAT_DETERM (maybe_tac (resolve_tac ctxt [qcomm]) i THEN resolve_tac ctxt [qI] i);\n\n(* Proves (? x0..xn. ... & x0 = t & ...) = (? x1..xn x0. x0 = t & ... & ...)\n Better: instantiate exI\n*)\nlocal\n val excomm = Data.ex_comm RS Data.iff_trans;\nin\n fun prove_rotate_ex_tac ctxt i = qcomm_tac ctxt excomm Data.iff_exI i\n fun prove_one_point_ex_tac ctxt =\n prove_rotate_ex_tac ctxt 1 THEN resolve_tac ctxt [Data.iffI] 1 THEN\n ALLGOALS\n (EVERY' [maybe_tac (eresolve_tac ctxt [Data.exE]),\n REPEAT_DETERM o eresolve_tac ctxt [Data.conjE],\n maybe_tac (resolve_tac ctxt [Data.exI]),\n DEPTH_SOLVE_1 o ares_tac ctxt [Data.conjI]])\nend;\n\n(* Proves (! x0..xn. (... & x0 = t & ...) --> P x0) =\n (! x1..xn x0. x0 = t --> (... & ...) --> P x0)\n*)\nlocal\n fun tac ctxt =\n SELECT_GOAL\n (EVERY1 [REPEAT o dresolve_tac ctxt [Data.uncurry],\n REPEAT o resolve_tac ctxt [Data.impI],\n eresolve_tac ctxt [Data.mp],\n REPEAT o eresolve_tac ctxt [Data.conjE],\n REPEAT o ares_tac ctxt [Data.conjI]]);\n val allcomm = Data.all_comm RS Data.iff_trans;\nin\n fun prove_one_point_all_tac ctxt =\n EVERY1 [qcomm_tac ctxt allcomm Data.iff_allI,\n resolve_tac ctxt [Data.iff_allI],\n resolve_tac ctxt [Data.iffI], tac ctxt, tac ctxt];\nend\n\n(* Proves (! x0..xn. (... & x0 = t & ...) --> P x0) =\n (! x1..xn x0. x0 = t --> (... & ...) --> P x0)\n*)\nlocal\n val allcomm = Data.all_comm RS Data.iff_trans;\nin\n fun prove_one_point_all_tac2 ctxt =\n EVERY1 [qcomm_tac ctxt allcomm Data.iff_allI,\n resolve_tac ctxt [Data.iff_allI],\n resolve_tac ctxt [Data.iffI], blast_tac ctxt, blast_tac ctxt];\nend\n\nfun renumber l u (Bound i) =\n Bound (if i < l orelse i > u then i else if i = u then l else i + 1)\n | renumber l u (s $ t) = renumber l u s $ renumber l u t\n | renumber l u (Abs (x, T, t)) = Abs (x, T, renumber (l + 1) (u + 1) t)\n | renumber _ _ atom = atom;\n\nfun quantify qC x T xs P =\n let\n fun quant [] P = P\n | quant ((qC, x, T) :: xs) P = quant xs (qC $ Abs (x, T, P));\n val n = length xs;\n val Q = if n = 0 then P else renumber 0 n P;\n in if Data.rotate then quant xs (qC $ Abs (x, T, Q)) else qC $ Abs (x, T, quant xs P) end;\n\nfun rearrange_all ctxt ct =\n (case Thm.term_of ct of\n F as (all as Const (q, _)) $ Abs (x, T, P) =>\n (case extract_quant extract_imp q P of\n NONE => NONE\n | SOME (xs, eq, Q) =>\n let val R = quantify all x T xs (Data.imp $ eq $ Q)\n in SOME (prove_conv ctxt (F, R) prove_one_point_all_tac) end)\n | _ => NONE);\n\nfun rotate_all ctxt ct =\n let\n fun extract fst xs P =\n if fst then NONE else SOME (xs, P, P)\n in\n (case strip_prop (Thm.term_of ct) of\n F as (ex as Const (q, _)) $ Abs (x, T, P) =>\n (case extract_quant extract q P of\n NONE => NONE\n | SOME (xs, _, Q) =>\n let val R = quantify ex x T xs Q\n in SOME (prove_conv ctxt (F, R) prove_one_point_all_tac2) end)\n | _ => NONE) end;\n\nfun rearrange_ball tac ctxt ct =\n (case Thm.term_of ct of\n F as Ball $ A $ Abs (x, T, P) =>\n (case extract_imp true [] P of\n NONE => NONE\n | SOME (xs, eq, Q) =>\n if not (null xs) then NONE\n else\n let val R = Data.imp $ eq $ Q\n in SOME (prove_conv ctxt (F, Ball $ A $ Abs (x, T, R)) tac) end)\n | _ => NONE);\n\nfun rearrange_ex' ctxt trm =\n (case strip_prop trm of\n F as (ex as Const (q, _)) $ Abs (x, T, P) =>\n (case extract_quant (extract_conj []) q P of\n NONE => NONE\n | SOME (xs, eq, Q) =>\n let val R = quantify ex x T xs (Data.conj $ eq $ Q)\n in SOME (prove_conv ctxt (F, R) prove_one_point_ex_tac) end)\n | _ => NONE);\n\nfun rearrange_ex ctxt = rearrange_ex' ctxt o Thm.term_of\n\nfun rotate_ex ctxt ct =\n let\n fun extract fst xs P =\n if fst then NONE else SOME (xs, P, P)\n in\n (case strip_prop (Thm.term_of ct) of\n F as (ex as Const (q, _)) $ Abs (x, T, P) =>\n (case extract_quant extract q P of\n NONE => NONE\n | SOME (xs, _, Q) =>\n let val R = quantify ex x T xs Q\n in SOME (prove_conv ctxt (F, R) prove_one_point_ex_tac) end)\n | _ => NONE) end;\n\nfun miniscope_ex ctxt ct =\n let\n fun extract fst xs t =\n case Data.dest_conj t of\n SOME (P, _) => if Data.move xs P [] andalso not fst then SOME (xs, t, t) else NONE\n | NONE => NONE\n in\n (case strip_prop (Thm.term_of ct) of\n F as (ex as Const (q, _)) $ Abs (x, T, P) =>\n (case extract_quant extract q P of\n NONE => NONE\n | SOME (xs, _, Q) =>\n let val R = quantify ex x T xs Q\n in SOME (prove_conv ctxt (F, R) prove_one_point_ex_tac) end)\n | _ => NONE) end;\n\nfun rearrange_bex tac ctxt ct =\n (case Thm.term_of ct of\n F as Bex $ A $ Abs (x, T, P) =>\n (case extract_conj [] true [] P of\n NONE => NONE\n | SOME (xs, eq, Q) =>\n if not (null xs) then NONE\n else SOME (prove_conv ctxt (F, Bex $ A $ Abs (x, T, Data.conj $ eq $ Q)) tac))\n | _ => NONE);\n\nfun rearrange_Collect tac ctxt ct =\n (case Thm.term_of ct of\n F as Collect $ Abs (x, T, P) =>\n (case extract_conj [] true [] P of\n NONE => NONE\n | SOME (_, eq, Q) =>\n let val R = Collect $ Abs (x, T, Data.conj $ eq $ Q)\n in SOME (prove_conv ctxt (F, R) tac) end)\n | _ => NONE);\n\nend;\n\nstructure Quantifier1 = Quantifier\n(\n (*abstract syntax*)\n fun dest_eq (Const(@{const_name HOL.eq},_) $ s $ t) = SOME (s, t)\n | dest_eq _ = NONE;\n fun dest_conj (Const(@{const_name HOL.conj},_) $ s $ t) = SOME (s, t)\n | dest_conj _ = NONE;\n fun dest_imp (Const(@{const_name HOL.implies},_) $ s $ t) = SOME (s, t)\n | dest_imp _ = NONE;\n val conj = HOLogic.conj\n val imp = HOLogic.imp\n fun move xs eq _ =\n (case dest_eq eq of\n SOME (s, t) =>\n let val n = length xs in\n s = Bound n andalso not (loose_bvar1 (t, n)) orelse\n t = Bound n andalso not (loose_bvar1 (s, n))\n end\n | NONE => false);\n val force_move = true\n val rotate = true\n (*rules*)\n val iff_reflection = @{thm eq_reflection}\n val iffI = @{thm iffI}\n val iff_trans = @{thm trans}\n val conjI= @{thm conjI}\n val conjE= @{thm conjE}\n val impI = @{thm impI}\n val mp = @{thm mp}\n val uncurry = @{thm uncurry}\n val exI = @{thm exI}\n val exE = @{thm exE}\n val iff_allI = @{thm iff_allI}\n val iff_exI = @{thm iff_exI}\n val all_comm = @{thm all_comm}\n val ex_comm = @{thm ex_comm}\n);\n\n(* loose_bvar2(t,k) iff t contains a 'loose' bound variable referring to\n a level below k. *)\nfun loose_bvar2(Bound i,k) = i < k\n | loose_bvar2(f$t, k) = loose_bvar2(f,k) orelse loose_bvar2(t,k)\n | loose_bvar2(Abs(_,_,t),k) = loose_bvar2(t,k+1)\n | loose_bvar2 _ = false;\n\nstructure Quantifier2 = Quantifier\n(\n (*abstract syntax*)\n fun dest_eq (Const(@{const_name HOL.eq},_) $ s $ t) = SOME (s, t)\n | dest_eq _ = NONE;\n fun dest_conj (Const(@{const_name HOL.conj},_) $ s $ t) = SOME (s, t)\n | dest_conj _ = NONE;\n fun dest_imp (Const(@{const_name HOL.implies},_) $ s $ t) = SOME (s, t)\n | dest_imp _ = NONE;\n val conj = HOLogic.conj\n val imp = HOLogic.imp\n fun move xs t _ = \n let val n = length xs in\n loose_bvar1 (t, n) andalso not (loose_bvar2 (t, n))\n end\n val force_move = false\n val rotate = false\n (*rules*)\n val iff_reflection = @{thm eq_reflection}\n val iffI = @{thm iffI}\n val iff_trans = @{thm trans}\n val conjI= @{thm conjI}\n val conjE= @{thm conjE}\n val impI = @{thm impI}\n val mp = @{thm mp}\n val uncurry = @{thm uncurry}\n val exI = @{thm exI}\n val exE = @{thm exE}\n val iff_allI = @{thm iff_allI}\n val iff_exI = @{thm iff_exI}\n val all_comm = @{thm all_comm}\n val ex_comm = @{thm ex_comm}\n);\n\nstructure Quantifier3 = Quantifier\n(\n (*abstract syntax*)\n fun dest_eq (Const(@{const_name HOL.eq},_) $ s $ t) = SOME (s, t)\n | dest_eq _ = NONE;\n fun dest_conj (Const(@{const_name HOL.conj},_) $ s $ t) = SOME (s, t)\n | dest_conj _ = NONE;\n fun dest_imp (Const(@{const_name HOL.implies},_) $ s $ t) = SOME (s, t)\n | dest_imp _ = NONE;\n val conj = HOLogic.conj\n val imp = HOLogic.imp\n fun move xs t _ = \n let val n = length xs in\n loose_bvar1 (t, n) andalso not (loose_bvar (t, n + 1))\n end\n val force_move = false\n val rotate = false\n (*rules*)\n val iff_reflection = @{thm eq_reflection}\n val iffI = @{thm iffI}\n val iff_trans = @{thm trans}\n val conjI= @{thm conjI}\n val conjE= @{thm conjE}\n val impI = @{thm impI}\n val mp = @{thm mp}\n val uncurry = @{thm uncurry}\n val exI = @{thm exI}\n val exE = @{thm exE}\n val iff_allI = @{thm iff_allI}\n val iff_exI = @{thm iff_exI}\n val all_comm = @{thm all_comm}\n val ex_comm = @{thm ex_comm}\n);\n\nsignature Int_Param =\n sig\n val x : int\n end;\n\nfun is_conj (Const(@{const_name HOL.conj},_) $ _ $ _) = true\n | is_conj _ = false;\n\nfunctor Quantifier4 (to_move: Int_Param) = Quantifier\n(\n (*abstract syntax*)\n fun dest_eq (Const(@{const_name HOL.eq},_) $ s $ t) = SOME (s, t)\n | dest_eq _ = NONE;\n fun dest_conj (Const(@{const_name HOL.conj},_) $ s $ t) = SOME (s, t)\n | dest_conj _ = NONE;\n fun dest_imp (Const(@{const_name HOL.implies},_) $ s $ t) = SOME (s, t)\n | dest_imp _ = NONE;\n val conj = HOLogic.conj\n val imp = HOLogic.imp\n fun move _ P trms = length trms + 1 = to_move.x andalso not (is_conj P)\n val force_move = true\n val rotate = false\n (*rules*)\n val iff_reflection = @{thm eq_reflection}\n val iffI = @{thm iffI}\n val iff_trans = @{thm trans}\n val conjI= @{thm conjI}\n val conjE= @{thm conjE}\n val impI = @{thm impI}\n val mp = @{thm mp}\n val uncurry = @{thm uncurry}\n val exI = @{thm exI}\n val exE = @{thm exE}\n val iff_allI = @{thm iff_allI}\n val iff_exI = @{thm iff_exI}\n val all_comm = @{thm all_comm}\n val ex_comm = @{thm ex_comm}\n);\n\nstructure Quantifier5 = Quantifier\n(\n (*abstract syntax*)\n fun dest_eq (Const(@{const_name HOL.eq},_) $ s $ t) = SOME (s, t)\n | dest_eq _ = NONE;\n fun dest_conj (Const(@{const_name HOL.conj},_) $ s $ t) = SOME (s, t)\n | dest_conj _ = NONE;\n fun dest_imp (Const(@{const_name HOL.implies},_) $ s $ t) = SOME (s, t)\n | dest_imp _ = NONE;\n val conj = HOLogic.conj\n val imp = HOLogic.imp\n fun move _ t _ = is_conj t\n val force_move = true\n val rotate = false\n (*rules*)\n val iff_reflection = @{thm eq_reflection}\n val iffI = @{thm iffI}\n val iff_trans = @{thm trans}\n val conjI= @{thm conjI}\n val conjE= @{thm conjE}\n val impI = @{thm impI}\n val mp = @{thm mp}\n val uncurry = @{thm uncurry}\n val exI = @{thm exI}\n val exE = @{thm exE}\n val iff_allI = @{thm iff_allI}\n val iff_exI = @{thm iff_exI}\n val all_comm = @{thm all_comm}\n val ex_comm = @{thm ex_comm}\n);\n\nstructure Quantifier6 = Quantifier\n(\n (*abstract syntax*)\n fun dest_eq (Const(@{const_name HOL.eq},_) $ s $ t) = SOME (s, t)\n | dest_eq _ = NONE;\n fun dest_conj (Const(@{const_name HOL.conj},_) $ s $ t) = SOME (s, t)\n | dest_conj _ = NONE;\n fun dest_imp (Const(@{const_name HOL.implies},_) $ s $ t) = SOME (s, t)\n | dest_imp _ = NONE;\n val conj = HOLogic.conj\n val imp = HOLogic.imp\n fun move xs t _ = \n let val n = length xs in\n not (loose_bvar1 (t, n))\n end\n val force_move = true\n val rotate = true\n (*rules*)\n val iff_reflection = @{thm eq_reflection}\n val iffI = @{thm iffI}\n val iff_trans = @{thm trans}\n val conjI= @{thm conjI}\n val conjE= @{thm conjE}\n val impI = @{thm impI}\n val mp = @{thm mp}\n val uncurry = @{thm uncurry}\n val exI = @{thm exI}\n val exE = @{thm exE}\n val iff_allI = @{thm iff_allI}\n val iff_exI = @{thm iff_exI}\n val all_comm = @{thm all_comm}\n val ex_comm = @{thm ex_comm}\n);\n\nstructure Quantifier7 = Quantifier\n(\n (*abstract syntax*)\n fun dest_eq (Const(@{const_name HOL.eq},_) $ s $ t) = SOME (s, t)\n | dest_eq _ = NONE;\n fun dest_conj (Const(@{const_name HOL.conj},_) $ s $ t) = SOME (s, t)\n | dest_conj _ = NONE;\n fun dest_imp (Const(@{const_name HOL.implies},_) $ s $ t) = SOME (s, t)\n | dest_imp _ = NONE;\n val conj = HOLogic.conj\n val imp = HOLogic.imp\n fun move xs t _ = \n let val n = length xs in\n not (loose_bvar1 (t, n))\n end\n val force_move = true\n val rotate = true\n (*rules*)\n val iff_reflection = @{thm eq_reflection}\n val iffI = @{thm iffI}\n val iff_trans = @{thm trans}\n val conjI= @{thm conjI}\n val conjE= @{thm conjE}\n val impI = @{thm impI}\n val mp = @{thm mp}\n val uncurry = @{thm uncurry}\n val exI = @{thm exI}\n val exE = @{thm exE}\n val iff_allI = @{thm iff_allI}\n val iff_exI = @{thm iff_exI}\n val all_comm = @{thm all_comm}\n val ex_comm = @{thm ex_comm}\n);\n\n\\\n\nML_val \\Quantifier1.rearrange_ex @{context} @{cterm \"\\ a c. c < n \\ a \\ A\"}\\\nML_val \\Quantifier1.rearrange_ex @{context} @{cterm \"\\ a c. c < n \\ a = b\"}\\\nML_val \\Quantifier2.rearrange_ex @{context} @{cterm \"\\ a c. a = b \\ c < n\"}\\\nML_val \\Quantifier1.rearrange_ex @{context} @{cterm \"\\ a c. a = b \\ c < n\"}\\\nML_val \\Quantifier2.rearrange_ex @{context} @{cterm \"\\ a c. c < n \\ a = b\"}\\\nML_val \\Quantifier2.rearrange_ex @{context} @{cterm \"\\ a c. a < n \\ a = b\"}\\\nML_val \\Quantifier2.rearrange_ex @{context} @{cterm \"\\ a c. a < n \\ c < n \\ a = b\"}\\\nML_val \\Quantifier2.rearrange_ex @{context} @{cterm \"\\ a c. c < n \\ a > c\"}\\\nML_val \\Quantifier3.rearrange_ex @{context} @{cterm \"\\ a c. c < n \\ a > c\"}\\\nML_val \\Quantifier2.rearrange_ex @{context} @{cterm \"\\ a c. c < n \\ a > b\"}\\\nML_val \\Quantifier2.rearrange_ex @{context} @{cterm \"\\ a c. c < n \\ (P a c \\ a > b) \\ Q c\"}\\\nML_val \\Quantifier2.rearrange_ex @{context} @{cterm \"finite {(a, c) | a c. c < n \\ a \\ A}\"}\\\nML_val \\Quantifier2.rearrange_ex @{context} @{cterm \"finite {t. \\ a c. a \\ A \\ c < n \\ t = (a,c)}\"}\\\nML_val \\Quantifier1.rotate_ex @{context} @{cterm \"\\ a c. c < n \\ a > b\"}\\\nML_val \\Quantifier1.rotate_ex @{context} @{cterm \"\\ a c d. c < n \\ a > b \\ P d\"}\\\nML_val \\Quantifier1.rearrange_ex @{context} @{cterm \"\\ a c. a < n \\ c = b\"}\\\nML_val \\Quantifier1.rearrange_ex @{context} @{cterm \"\\ a. \\ c. a < n \\ c = b\"}\\\nML_val \\Quantifier1.rearrange_ex @{context} @{cterm \"\\ a c. a < n \\ c = b\"}\\\nML_val \\Quantifier6.rearrange_ex @{context} @{cterm \"\\ a b c. a < n \\ b < 3 \\ b > c\"}\\\nML_val \\Quantifier6.rearrange_ex @{context} @{cterm \"\\b c. a < n \\ b < 3 \\ b > c\"}\\\nML_val \\Quantifier7.miniscope_ex @{context} @{cterm \"\\ a b c. a < n \\ b < 3 \\ b > c\"}\\\nML_val \\Quantifier7.miniscope_ex @{context} @{cterm \"\\b c. a < n \\ b < 3 \\ b > c\"}\\\n\nsimproc_setup ex_reorder (\"\\x. P x\") = \\fn _ => Quantifier2.rearrange_ex\\\ndeclare [[simproc del: ex_reorder]]\nsimproc_setup ex_reorder2 (\"\\x. P x\") = \\fn _ => Quantifier3.rearrange_ex\\\ndeclare [[simproc del: ex_reorder2]]\nsimproc_setup ex_reorder3 (\"\\x. P x\") = \\fn _ => Quantifier6.rearrange_ex\\\ndeclare [[simproc del: ex_reorder3]]\nsimproc_setup ex_reorder4 (\"\\x. P x\") = \\fn _ => Quantifier7.miniscope_ex\\\ndeclare [[simproc del: ex_reorder4]]\n\nML_val \\@{term \"\\ a c. c < n \\ a \\ A\"}\\\n\nML_val \\@{term \"finite {(a, c). c < n \\ a \\ A}\"}\\\n\nML_val \\@{term \"finite {(a, c) | a c. c < n \\ a \\ A}\"}\\\n\nlemma\n fixes n :: nat\n assumes A: \"finite A\"\n shows \"finite {(a, c). c < n \\ a \\ A}\"\n using assms\n using [[simproc add: finite_Collect]]\n by simp\n\nlemma\n fixes n :: nat\n assumes A: \"finite A\"\n shows \"finite {(a, c) | a c. c < n \\ a \\ A}\"\n using assms\n using [[simproc add: ex_reorder]]\n by simp\n\nlemma\n fixes n :: nat\n assumes A: \"finite A\"\n shows \"finite {t. \\ a c. a \\ A \\ c < n \\ t = (a,c)}\"\n apply simp\n using assms apply simp\n oops\n\nlemma\n fixes n :: nat\n assumes A: \"finite A\"\n shows \"finite {t. \\ a c. (t = (a,c) \\ c < n) \\ a \\ A}\"\n using [[simproc add: ex_reorder]]\n using [[simp_trace]] apply simp\n using assms by simp\n\nlemma\n fixes n :: nat\n assumes A: \"finite A\"\n shows \"finite {t. \\ a c. (t = (a,c) \\ a \\ A) \\ c < n}\"\n using [[simp_trace]] apply (simp del: Product_Type.Collect_case_prod)\n using assms by simp\n \nlemma\n fixes n :: nat\n assumes A: \"finite A\"\n shows \"finite {t. \\ a c. (a \\ A \\ t = (a,c)) \\ c < n}\"\n using [[simp_trace]] apply simp\n using assms by simp\n \nlemma\n fixes n :: nat\n assumes A: \"finite A\"\n shows \"finite {t. \\ a c. a \\ A \\ c < n \\ t = (a,c)}\"\n using [[simp_trace]] apply simp\n using assms by simp\n \nlemma\n assumes A: \"finite A\"\n shows \"finite {t. \\ a c. a \\ A \\ P c \\ t = (a,c)}\"\n using [[simp_trace]] apply simp\n using assms apply simp\n oops\n\nML \\\n fun rotate_quant reorder_thm n ctxt =\n let\n fun subst j =\n if j > n then K all_tac else\n (\n EqSubst.eqsubst_tac ctxt [j] [reorder_thm]\n ) THEN' subst (j + 1)\n in subst 1 end;\n\\\n\nML_val Pretty.string_of\nML_val Syntax.pretty_term\n\nML \\\n fun rotate_ex_tac ctxt =\n let\n fun foc_tac {concl, ...} =\n case Quantifier1.rotate_ex ctxt concl of\n NONE => no_tac\n | SOME thm => rewrite_goals_tac ctxt [thm]\n in\n Subgoal.FOCUS foc_tac ctxt\n end;\n\\\n\nML \\\n fun rotate_all_tac ctxt =\n let\n fun foc_tac {concl, ...} =\n case Quantifier1.rotate_all ctxt concl of\n NONE => no_tac\n | SOME thm => rewrite_goals_tac ctxt [thm]\n in\n Subgoal.FOCUS foc_tac ctxt\n end;\n\\\n\nML \\\n fun rearrange_ex_tac ctxt =\n let\n fun foc_tac {concl, ...} =\n case Quantifier2.rearrange_ex ctxt concl of\n NONE => no_tac\n | SOME thm => rewrite_goals_tac ctxt [thm]\n in\n Subgoal.FOCUS foc_tac ctxt\n end;\n\\\n\nML \\\n fun rearrange_ex_tac2 ctxt =\n let\n fun foc_tac {concl, ...} =\n case Quantifier3.rearrange_ex ctxt concl of\n NONE => no_tac\n | SOME thm => rewrite_goals_tac ctxt [thm]\n in\n Subgoal.FOCUS foc_tac ctxt\n end;\n\\\n\n(* XXX How to do this? *)\n(*\nML \\\n fun rearrange_ex_tac2 n ctxt =\n let\n struct Quant = Quantifier4(val x = n);\n fun foc_tac {concl, ...} =\n case Quantifier4.rearrange_ex ctxt concl of\n NONE => no_tac\n | SOME thm => rewrite_goals_tac ctxt [thm]\n in\n Subgoal.FOCUS foc_tac ctxt\n end;\n\\\n*)\n\nML_val Abs\n\nML_val Conv.rewr_conv\n\nML \\\n\n fun strip_fin (Const (@{const_name \"finite\"}, _) $ (Const (@{const_name \"Collect\"}, _) $ t)) = t\n | strip_fin t = t\n\n fun wrap_fin tac ctxt = tac ctxt o strip_fin\n\n structure Quant2 = Quantifier4(val x = 2);\n structure Quant3 = Quantifier4(val x = 3);\n structure Quant4 = Quantifier4(val x = 4);\n structure Quant5 = Quantifier4(val x = 5);\n\n fun rearrange_ex_fixed_n rearrange_n ctxt =\n let\n fun foc_tac {concl, ...} =\n case rearrange_n ctxt concl of\n NONE => no_tac\n | SOME thm => rewrite_goals_tac ctxt [thm, @{thm HOL.conj_assoc} RS @{thm HOL.eq_reflection}]\n in\n Subgoal.FOCUS foc_tac ctxt\n end;\n \n val rearrange_ex_fixed_2 = rearrange_ex_fixed_n Quant2.rearrange_ex;\n val rearrange_ex_fixed_3 = rearrange_ex_fixed_n Quant3.rearrange_ex;\n val rearrange_ex_fixed_4 = rearrange_ex_fixed_n Quant4.rearrange_ex;\n val rearrange_ex_fixed_5 = rearrange_ex_fixed_n Quant5.rearrange_ex;\n\n (* val defer_ex = rearrange_ex_fixed_n (wrap_fin Quantifier5.rearrange_ex); *)\n\n fun CONV conv ctxt =\n let\n fun foc_tac {concl, ...} =\n rewrite_goals_tac ctxt [conv ctxt concl]\n in\n Subgoal.FOCUS foc_tac ctxt\n end;\n\n fun mk_conv f ctxt ct =\n case (f ctxt ct) of\n SOME thm => thm\n | _ => raise CTERM (\"no conversion\", [])\n\n fun success_conv cv ct =\n let\n val eq = cv ct\n in\n if Thm.is_reflexive eq then raise CTERM (\"no conversion\", []) else eq\n end\n\n fun mk_conv' f ctxt ct = the_default (Thm.reflexive ct) (f ctxt ct)\n val assoc_conv = Conv.rewr_conv (@{thm HOL.conj_assoc} RS @{thm HOL.eq_reflection})\n val comm_conv = Conv.rewr_conv (@{thm HOL.conj_commute} RS @{thm HOL.eq_reflection})\n fun wrap_conv f ctxt =\n success_conv (\n Conv.top_sweep_conv (fn ctxt => mk_conv f ctxt then_conv Conv.repeat_conv assoc_conv) ctxt\n )\n fun mk_tac conv ctxt = CONVERSION (Conv.concl_conv ~1 (Object_Logic.judgment_conv ctxt (conv ctxt)))\n\n val defer_conv = mk_conv Quantifier5.rearrange_ex\n val conv = wrap_conv Quantifier5.rearrange_ex\n fun defer_ex_tac ctxt = CONVERSION (Conv.params_conv ~1 (fn ctxt => Conv.concl_conv ~1 (conv ctxt)) ctxt)\n val defer_ex_tac = CONV conv\n fun defer_ex_tac ctxt i =\n CHANGED (mk_tac (fn ctxt => wrap_conv Quantifier5.rearrange_ex ctxt else_conv Conv.top_sweep_conv (K comm_conv) ctxt) ctxt i)\n val mini_ex_tac = mk_tac (wrap_conv Quantifier6.rearrange_ex)\n val mini_ex_tac2 = mk_tac (wrap_conv Quantifier7.miniscope_ex)\n\n val rearrange_ex_fixed_2 = mk_tac (wrap_conv Quant2.rearrange_ex);\n val rearrange_ex_fixed_3 = mk_tac (wrap_conv Quant3.rearrange_ex);\n val rearrange_ex_fixed_4 = mk_tac (wrap_conv Quant4.rearrange_ex);\n val rearrange_ex_fixed_5 = mk_tac (wrap_conv Quant5.rearrange_ex);\n\\\n\nML_val Object_Logic.judgment_conv\n\nML_val \\defer_conv @{context} @{cterm \"\\ a b c d. a < 1 \\ b < 2 \\ c < 3 \\ d < 4\"}\\\nML_val \\assoc_conv @{cterm \"(a < 1 \\ b < 2) \\ c < 3 \\ d < 4\"}\\\nML_val \\Conv.binder_conv (K assoc_conv) @{context} @{cterm \"\\ a. (a < 1 \\ b < 2) \\ c < 3 \\ d < 4\"}\\\nML_val \\Conv.top_sweep_conv (K assoc_conv) @{context}\n @{cterm \"\\ a b c d. (a < 1 \\ b < 2) \\ c < 3 \\ d < 4\"}\\\nML_val \\Conv.bottom_conv (K (Conv.try_conv assoc_conv)) @{context}\n @{cterm \"\\ a b c d. (a < 1 \\ b < 2) \\ c < 3 \\ d < 4\"}\\\nML_val \\Conv.every_conv [defer_conv @{context}, Conv.try_conv assoc_conv]\n @{cterm \"\\ a b c d. a < 1 \\ b < 2 \\ c < 3 \\ d < 4\"}\\\nML_val \\conv @{context} @{cterm \"\\ a b c d. a < 1 \\ b < 2 \\ c < 3 \\ d < 4\"}\\\nML_val \\conv @{context} @{cterm \"finite {t. \\ a b c d. a < 1 \\ b < 2 \\ c < 3 \\ d < 4}\"}\\\nML_val \\conv @{context} @{cterm \"\\a b c d. d = 4 \\ c = 3 \\ b < 2 \\ a < 1\"}\\\n\nML_val \\CONVERSION (Conv.concl_conv ~1 (conv @{context}))\\\nML_val Conv.concl_conv\n\nML_val \\Quantifier1.rotate_ex @{context} @{cterm \"\\ a b c d. a < 1 \\ b < 2 \\ c < 3 \\ d < 4\"}\\\n\nML_val \\Quantifier1.rotate_all @{context} @{cterm \"\\ a b c d. a < 1 \\ b < 2 \\ c < 3 \\ d < 4\"}\\\n\nlemma\n \"\\ a b c d. a < 1 \\ b < 2 \\ c < 3 \\ d < 4\"\n apply (tactic \\rotate_all_tac @{context} 1\\)\n apply (tactic \\rotate_all_tac @{context} 1\\)\n apply (tactic \\rotate_all_tac @{context} 1\\)\n apply (tactic \\rotate_all_tac @{context} 1\\)\n apply (tactic \\rotate_all_tac @{context} 1\\)\n oops\n\nlemmas a = HOL.refl[THEN eq_reflection]\nlemmas b = enum_the_def[THEN eq_reflection]\nML_val \\Thm.is_reflexive @{thm a}\\\nML_val \\Thm.is_reflexive @{thm b}\\\nlemma\n \"\\ a b c d. a < 1 \\ b < 2 \\ c = 3 \\ d = 4\"\n apply (tactic \\rearrange_ex_fixed_2 @{context} 1\\)\n apply (tactic \\rearrange_ex_fixed_3 @{context} 1\\)\n apply (tactic \\rearrange_ex_fixed_4 @{context} 1\\)\n apply (tactic \\defer_ex_tac @{context} 1\\)\n apply (subst conj_assoc)+\n oops\n\n ML_val \\@{const_name finite}\\\n ML_val \\@{const_name Collect}\\\nML_val \\strip_fin @{term \\finite {t. \\a b c d. a < 1 \\ b < 2 \\ c = 3 \\ d = 4}\\}\\\n\n\nlemma\n \"finite {t. \\ a b c d. a < 1 \\ b < 2 \\ c = 3 \\ d = 4}\"\n apply (tactic \\rearrange_ex_fixed_2 @{context} 1\\)\n apply (tactic \\rearrange_ex_fixed_3 @{context} 1\\)\n apply (tactic \\rearrange_ex_fixed_4 @{context} 1\\)\n apply (tactic \\defer_ex_tac @{context} 1\\)\n oops\n \nlemma\n \"finite S \\ finite {t. \\ a b c d. a < 1 \\ b < 2 \\ c = 3 \\ d = 4}\"\n apply (tactic \\rearrange_ex_fixed_2 @{context} 1\\)\n apply (tactic \\rearrange_ex_fixed_3 @{context} 1\\)\n apply (tactic \\rearrange_ex_fixed_4 @{context} 1\\)\n apply (tactic \\defer_ex_tac @{context} 1\\, simp only: conj_assoc)\n oops\n\nlemma\n \"finite S \\ finite {t. \\ a b c d. P a b d \\ c > 3}\"\n apply (tactic \\defer_ex_tac @{context} 1\\)\n apply (tactic \\mini_ex_tac @{context} 1\\)\n apply (simp only: ex_simps)\n oops\n\nlemma\n \"\\ a b c d. d < 4 \\ a < 1 \\ b < 2 \\ c < 3 \\ d < 4\"\n using [[simproc add: ex_reorder3]]\n apply simp\n oops\n\nlemma\n \"\\ a b c d. d < 4 \\ a < 1 \\ b < 2 \\ c < 3 \\ d < 4\"\n using [[simproc add: ex_reorder4]]\n apply simp\n oops\n\nlemma\n \"\\ a b c d. d < 4 \\ a < 1 \\ b < 2 \\ c < 3 \\ d < 4\"\n apply (tactic \\mini_ex_tac @{context} 1\\)\n apply simp\n apply (tactic \\mini_ex_tac @{context} 1\\)\n apply simp\n apply (tactic \\mini_ex_tac @{context} 1\\)\n apply simp\n apply (tactic \\mini_ex_tac @{context} 1\\)\n apply simp\n apply (tactic \\mini_ex_tac @{context} 1\\)\n apply simp\n apply (tactic \\mini_ex_tac @{context} 1\\)\n apply simp\n oops\n\nlemma\n \"\\ a b c d. d < 4 \\ a < 1 \\ b < 2 \\ c < 3 \\ d < 4\"\n apply (tactic \\mini_ex_tac2 @{context} 1\\)\n apply simp\n apply (tactic \\mini_ex_tac2 @{context} 1\\)\n apply simp\n apply (tactic \\mini_ex_tac2 @{context} 1\\)\n apply simp\n apply (tactic \\mini_ex_tac @{context} 1\\)\n apply simp\n apply (tactic \\mini_ex_tac @{context} 1\\)\n apply simp\n apply (tactic \\mini_ex_tac @{context} 1\\)\n apply simp\n oops\n \nlemma\n \"\\ a c b d. d < 4 \\ a < 1 \\ b < 2 \\ c < 3\"\n apply simp\n oops\n \nlemma\n \"\\ a b c d. a < 1 \\ b < 2 \\ c < 3 \\ d < 4\"\n apply (tactic \\rotate_ex_tac @{context} 1\\)\n apply (tactic \\rotate_ex_tac @{context} 1\\)\n apply (tactic \\rotate_ex_tac @{context} 1\\)\n apply (tactic \\rotate_ex_tac @{context} 1\\)\n apply (tactic \\rotate_ex_tac @{context} 1\\)\n oops\n\nlemma\n \"\\ a b c d. b < 2 \\ c < 3 \\ d < 4 \\ a < 1\"\n apply (tactic \\rearrange_ex_tac @{context} 1\\)\n oops\n\nlemma\n \"\\ a b c d. b < 2 \\ c < 3 \\ d < 4 \\ a < c\"\n apply (tactic \\rearrange_ex_tac2 @{context} 1\\; simp only: conj_assoc)+\n oops\n\nlemma\n \"\\ a b c d. b < 2 \\ c < 3 \\ d < 4 \\ a < c\"\n apply (tactic \\rearrange_ex_tac2 @{context} 1\\; simp del: ex_simps)+\n oops\n\nlemma\n \"\\ a b c d. b < 2 \\ c < 3 \\ d < 4 \\ a < c\"\n apply (tactic \\rearrange_ex_tac2 @{context} 1\\)\n apply (simp del: ex_simps)\n apply (tactic \\rearrange_ex_tac2 @{context} 1\\)\n apply (simp del: ex_simps)\n apply (tactic \\rearrange_ex_tac2 @{context} 1\\)\n using [[simp_trace]]\n apply (simp del: ex_simps)\n oops\n\nlemma finite_Collect_bounded_ex_4:\n assumes \"finite {(a,b,c,d) . P a b c d}\"\n shows\n \"finite {x. \\a b c d. P a b c d \\ Q x a b c d}\n \\ (\\ a b c d. P a b c d \\ finite {x. Q x a b c d})\"\nproof -\n have *:\n \"{x. \\a b c d. P a b c d \\ Q x a b c d}\n = {x. \\ t. t \\ {(a,b,c,d). P a b c d} \\ (\\a b c d. t = (a, b, c, d) \\ Q x a b c d)}\"\n by simp\n show ?thesis apply (subst *)\n apply (subst finite_Collect_bounded_ex)\n using assms by simp+\noops\n \nlemma finite_Collect_bounded_ex_4':\n assumes \"finite {(a,b,c,d) | a b c d. P a b c d}\"\n shows\n \"finite {x. \\a b c d. P a b c d \\ Q x a b c d}\n \\ (\\ a b c d. P a b c d \\ finite {x. Q x a b c d})\"\nproof -\n have *:\n \"{x. \\a b c d. P a b c d \\ Q x a b c d}\n = {x. \\ t. t \\ {(a,b,c,d) | a b c d. P a b c d} \\ (\\a b c d. t = (a, b, c, d) \\ Q x a b c d)}\"\n by simp\n show ?thesis apply (subst *)\n apply (subst finite_Collect_bounded_ex)\n using assms by simp+\nqed\n\nlemma finite_Collect_bounded_ex_2 [simp]:\n assumes \"finite {(a,b). P a b}\"\n shows\n \"finite {x. \\a b. P a b \\ Q x a b}\n \\ (\\ a b. P a b \\ finite {x. Q x a b})\"\n using assms finite_Collect_bounded_ex[OF assms, where Q = \"\\ x. \\ (a, b). Q x a b\"]\n by clarsimp (* force, simp *)\n\nlemma finite_Collect_bounded_ex_3 [simp]:\n assumes \"finite {(a,b,c) . P a b c}\"\n shows\n \"finite {x. \\a b c. P a b c \\ Q x a b c}\n \\ (\\ a b c. P a b c \\ finite {x. Q x a b c})\"\n using assms finite_Collect_bounded_ex\n [OF assms, where Q = \"\\ x. \\ (a, b, c). Q x a b c\"]\n by clarsimp\n\nlemma finite_Collect_bounded_ex_4 [simp]:\n assumes \"finite {(a,b,c,d) . P a b c d}\"\n shows\n \"finite {x. \\a b c d. P a b c d \\ Q x a b c d}\n \\ (\\ a b c d. P a b c d \\ finite {x. Q x a b c d})\"\n using assms finite_Collect_bounded_ex[OF assms, where Q = \"\\ x. \\ (a, b, c, d). Q x a b c d\"]\n by clarsimp (* force, simp *)\n\nlemma finite_Collect_bounded_ex_5 [simp]:\n assumes \"finite {(a,b,c,d,e) . P a b c d e}\"\n shows\n \"finite {x. \\a b c d e. P a b c d e \\ Q x a b c d e}\n \\ (\\ a b c d e. P a b c d e \\ finite {x. Q x a b c d e})\"\n using assms finite_Collect_bounded_ex\n [OF assms, where Q = \"\\ x. \\ (a, b, c, d, e). Q x a b c d e\"]\n by clarsimp (* force, simp *)\n\nlemma finite_Collect_bounded_ex_6 [simp]:\n assumes \"finite {(a,b,c,d,e,f) . P a b c d e f}\"\n shows\n \"finite {x. \\a b c d e f. P a b c d e f \\ Q x a b c d e f}\n \\ (\\ a b c d e f. P a b c d e f \\ finite {x. Q x a b c d e f})\"\n using assms finite_Collect_bounded_ex\n [OF assms, where Q = \"\\ x. \\ (a, b, c, d, e, f). Q x a b c d e f\"]\n by clarsimp (* force, simp *)\n\nlemma finite_Collect_bounded_ex_7 [simp]:\n assumes \"finite {(a,b,c,d,e,f,g) . P a b c d e f g}\"\n shows\n \"finite {x. \\a b c d e f g. P a b c d e f g \\ Q x a b c d e f g}\n \\ (\\ a b c d e f g. P a b c d e f g \\ finite {x. Q x a b c d e f g})\"\n using assms finite_Collect_bounded_ex\n [OF assms, where Q = \"\\ x. \\ (a, b, c, d, e, f, g). Q x a b c d e f g\"]\n by clarsimp (* force, simp *)\n\nlemma finite_Collect_bounded_ex_8 [simp]:\n assumes \"finite {(a,b,c,d,e,f,g,h) . P a b c d e f g h}\"\n shows\n \"finite {x. \\a b c d e f g h. P a b c d e f g h \\ Q x a b c d e f g h}\n \\ (\\ a b c d e f g h. P a b c d e f g h \\ finite {x. Q x a b c d e f g h})\"\n using assms finite_Collect_bounded_ex\n [OF assms, where Q = \"\\ x. \\ (a, b, c, d, e, f, g, h). Q x a b c d e f g h\"]\n by clarsimp (* force, simp *)\n\nlemma finite_Collect_bounded_ex_9 [simp]:\n assumes \"finite {(a,b,c,d,e,f,g,h,i) . P a b c d e f g h i}\"\n shows\n \"finite {x. \\a b c d e f g h i. P a b c d e f g h i \\ Q x a b c d e f g h i}\n \\ (\\ a b c d e f g h i. P a b c d e f g h i \\ finite {x. Q x a b c d e f g h i})\"\n using assms finite_Collect_bounded_ex\n [OF assms, where Q = \"\\ x. \\ (a, b, c, d, e, f, g, h, i). Q x a b c d e f g h i\"]\n by clarsimp (* force, simp *)\n\nlemma finite_Collect_bounded_ex_10 [simp]:\n assumes \"finite {(a,b,c,d,e,f,g,h,i,j) . P a b c d e f g h i j}\"\n shows\n \"finite {x. \\a b c d e f g h i j. P a b c d e f g h i j \\ Q x a b c d e f g h i j}\n \\ (\\ a b c d e f g h i j. P a b c d e f g h i j \\ finite {x. Q x a b c d e f g h i j})\"\n using assms finite_Collect_bounded_ex\n [OF assms, where Q = \"\\ x. \\ (a, b, c, d, e, f, g, h, i, j). Q x a b c d e f g h i j\"]\n by clarsimp (* force, simp *)\n\n\nML \\fun mini_ex ctxt = SIMPLE_METHOD (mini_ex_tac ctxt 1)\\\nML \\fun defer_ex ctxt = SIMPLE_METHOD (defer_ex_tac ctxt 1)\\\n\nmethod_setup mini_existential =\n \\Scan.succeed mini_ex\\ \\Miniscope existential quantifiers\\\nmethod_setup defer_existential =\n \\Scan.succeed defer_ex\\ \\Rotate first conjunct under existential quantifiers to last position\\\n\nmethod mini_ex = ((simp only: ex_simps[symmetric])?, mini_existential, (simp)?)\nmethod defer_ex = ((simp only: ex_simps[symmetric])?, defer_existential, (simp)?)\nmethod defer_ex' = (defer_existential, (simp)?)\n\nend","avg_line_length":35.875,"max_line_length":135,"alphanum_fraction":0.6096786682} {"size":68046,"ext":"thy","lang":"Isabelle","max_stars_count":3.0,"content":"theory DerivedConstructions\nimports CoreStructures\nbegin\nsubsection \\ Basic camera constructions \\\n\nsubsubsection \\ Tuple\/Product type \\\ninstantiation prod :: (camera,camera) camera begin\n definition valid_raw_prod :: \"'a \\ 'b \\ sprop\" where\n \"valid_raw_prod \\ \\(x::'a,y::'b). valid_raw x \\\\<^sub>s valid_raw y\"\n definition pcore_prod :: \"'a\\'b \\ ('a\\'b) option\" where\n \"pcore_prod \\ \\(x,y). case pcore x of Some x' \\ (case pcore y of Some y' \\ Some (x',y') \n | None \\ None) | None \\ None\"\n definition op_prod :: \"'a\\'b \\ 'a\\'b \\ 'a\\'b\" where \n \"op_prod \\ \\(x,y) (a,b). (x \\ a,y \\ b)\"\ninstance proof\nshow \"non_expansive (valid_raw::'a \\ 'b \\ sprop)\"\n by (rule non_expansiveI;auto simp: valid_raw_prod_def sprop_conj.rep_eq n_equiv_sprop_def ) \n (metis ofe_mono ofe_sym n_valid_ne)+\nnext \nshow \"non_expansive (pcore::'a\\'b \\ ('a\\'b) option)\"\n by (rule non_expansiveI; auto simp: pcore_prod_def n_equiv_option_def split: option.splits)\n (metis n_equiv_option_def pcore_ne option.distinct(1) option.sel)+\nnext\nshow \"non_expansive2 (op::'a\\'b \\ 'a\\'b \\ 'a\\'b)\"\n by (rule non_expansive2I) (auto simp: op_prod_def)\nnext\nfix a b c :: \"'a\\'b\"\nshow \"a \\ b \\ c = a \\ (b \\ c)\"\n by (auto simp: op_prod_def camera_assoc split: prod.splits)\nnext\nfix a b :: \"'a\\'b\"\nshow \"a \\ b = b \\ a\"\n by (auto simp: op_prod_def camera_comm split: prod.splits)\nnext\nfix a a' :: \"'a\\'b\"\nshow \"pcore a = Some a' \\ a' \\ a = a\"\n by (auto simp: pcore_prod_def op_prod_def camera_pcore_id split: prod.splits option.splits)\nnext\nfix a a' :: \"'a\\'b\"\nshow \"pcore a = Some a' \\ pcore a' = pcore a\"\n by (auto simp: pcore_prod_def camera_pcore_idem split: option.splits prod.splits)\nnext\nfix a a' b :: \"'a\\'b\"\nshow \"pcore a = Some a' \\ \\c. b = a \\ c \\ \\b'. pcore b = Some b' \\ (\\c. b' = a' \\ c)\"\n by (auto simp: pcore_prod_def op_prod_def split: prod.splits option.splits)\n (metis camera_pcore_mono option.simps(1,3))+\nnext\nfix a b :: \"'a\\'b\"\nfix n\nshow \"Rep_sprop (valid_raw (a \\ b)) n \\ Rep_sprop (valid_raw a) n\"\n by (transfer; auto simp: valid_raw_prod_def sprop_conj.rep_eq op_prod_def camera_valid_op \n split: prod.splits)\nnext\nfix a b c :: \"'a\\'b\"\nfix n\nshow \"Rep_sprop (valid_raw a) n \\ n_equiv n a (b \\ c) \\ \n \\c1 c2. a = c1 \\ c2 \\ n_equiv n c1 b \\ n_equiv n c2 c\"\n by (transfer; auto simp: valid_raw_prod_def sprop_conj.rep_eq op_prod_def split: prod.splits)\n (metis camera_extend)\nqed\nend\nlemma n_incl_prod[simp]: \"n_incl n (a,b) (x,y) = (n_incl n a x \\ n_incl n b y)\"\n by (auto simp: n_incl_def op_prod_def)\n\nlemma prod_valid_def: \"valid (x,y) \\ valid x \\ valid y\"\n by (auto simp: valid_raw_prod_def valid_def sprop_conj.rep_eq)\n\nlemma prod_validI: \"\\valid x; valid y\\ \\ valid (x,y)\"\n by (auto simp: valid_raw_prod_def valid_def sprop_conj.rep_eq)\n\nlemma prod_n_valid_def: \"n_valid (x,y) n \\ n_valid x n \\ n_valid y n\"\n by (auto simp: valid_raw_prod_def valid_def sprop_conj.rep_eq)\n\nlemma prod_n_valid_fun_def: \"n_valid (x,y) = (\\n. n_valid x n \\ n_valid y n)\"\n using prod_n_valid_def by auto\n\nlemma prod_n_valid_snd: \"n_valid (x,y) n \\ n_valid y n\"\n using prod_n_valid_fun_def by metis\n \ninstance prod :: (core_id,core_id) core_id by standard (auto simp: pcore_prod_def pcore_id)\n\ninstance prod :: (dcamera,dcamera) dcamera \n apply (standard; auto simp: valid_raw_prod_def valid_def sprop_conj.rep_eq)\n using d_valid[simplified valid_def] by blast+\n\nlemma prod_dcamera_val [intro!]: \"\\dcamera_val x; dcamera_val y\\ \\ dcamera_val (x,y)\"\n apply (auto simp: dcamera_val_def discrete_val_def valid_def)\n using prod_n_valid_def by blast+\n\ninstantiation prod :: (ucamera,ucamera) ucamera begin\ndefinition \\_prod :: \"'a \\ 'b\" where [simp]: \"\\_prod = (\\,\\)\"\ninstance by standard \n (auto simp: valid_raw_prod_def sprop_conj.rep_eq pcore_prod_def op_prod_def valid_def \n \\_left_id \\_pcore \\_valid[unfolded valid_def]) \nend\n\nlemma prod_pcore_id_pred: \n \"pcore_id_pred (a::'a::ucamera,b::'b::ucamera) \\ pcore_id_pred a \\ pcore_id_pred b\"\n by (auto simp: pcore_id_pred_def pcore_prod_def split: option.splits)\n\ninstance prod :: (ducamera,ducamera) ducamera ..\n\nsubsubsection \\ Extended sum type \\\nfun sum_pcore :: \"'a::camera+\\<^sub>e'b::camera \\ ('a+\\<^sub>e'b) option\" where\n \"sum_pcore (Inl x) = (case pcore x of Some x' \\ Some (Inl x') | None \\ None)\"\n| \"sum_pcore (Inr x) = (case pcore x of Some x' \\ Some (Inr x') | None \\ None)\"\n| \"sum_pcore sum_ext.Inv = Some sum_ext.Inv\" \n\nlemma sum_pcore_ne: \"non_expansive sum_pcore\"\nproof (rule non_expansiveI)\nfix n x y\nassume \"n_equiv n x (y::('a,'b) sum_ext)\"\nthen show \"n_equiv n (sum_pcore x) (sum_pcore y)\" \n by (cases x y rule: sum_ex2; auto simp: ofe_refl ofe_sym n_equiv_option_def split: option.splits)\n (metis option.distinct(1) option.sel pcore_ne n_equiv_option_def)+\nqed\n\ninstantiation sum_ext :: (camera,camera) camera begin\n definition valid_raw_sum_ext :: \"('a,'b) sum_ext \\ sprop\" where\n \"valid_raw_sum_ext s \\ case s of (Inl a) \\ valid_raw a | Inr b \\ valid_raw b | sum_ext.Inv \\ sFalse\"\n definition \"pcore_sum_ext \\ sum_pcore\"\n definition op_sum_ext :: \"('a,'b) sum_ext \\ ('a,'b) sum_ext \\ ('a,'b) sum_ext\" where\n \"op_sum_ext x y = (case (x,y) of (Inl x', Inl y') \\ Inl (x' \\ y') \n | (Inr x', Inr y') \\ Inr (x' \\ y') | _ \\ sum_ext.Inv)\"\ninstance proof\nshow \"non_expansive (valid_raw::('a,'b) sum_ext \\ sprop)\"\n by (rule non_expansiveI;auto simp: valid_raw_sum_ext_def split: sum_ext.splits)\n (auto simp: n_equiv_sprop_def)\nnext\nshow \"non_expansive (pcore::('a,'b) sum_ext \\ ('a,'b) sum_ext option)\"\n by (simp add: sum_pcore_ne pcore_sum_ext_def)\nnext\nshow \"non_expansive2 (op::('a,'b) sum_ext \\ ('a,'b) sum_ext \\ ('a,'b) sum_ext)\"\nproof (rule non_expansive2I)\nfix x y a b :: \"('a,'b) sum_ext\"\nfix n\nassume \" n_equiv n x y\" \"n_equiv n a b\"\nthen show \"n_equiv n (x \\ a) (y \\ b)\"\n by (cases x y a b rule: sum_ex4) (auto simp: ofe_refl ofe_sym op_sum_ext_def)\nqed\nnext\nfix a b c :: \"('a,'b) sum_ext\"\nshow \"a \\ b \\ c = a \\ (b \\ c)\" \n by (cases a b c rule: sum_ex3) (auto simp: op_sum_ext_def camera_assoc)\nnext\nfix a b :: \"('a,'b) sum_ext\"\nshow \"a \\ b = b \\ a\" by (cases a b rule: sum_ex2) (auto simp: op_sum_ext_def camera_comm)\nnext\nfix a a' :: \"('a,'b) sum_ext\"\nshow \"pcore a = Some a' \\ a' \\ a = a\" by (cases a a' rule: sum_ex2) \n (auto simp: pcore_sum_ext_def op_sum_ext_def camera_pcore_id split: option.splits)\nnext\nfix a a' :: \"('a,'b) sum_ext\"\nshow \"pcore a = Some a' \\ pcore a' = pcore a\" by (cases a a' rule: sum_ex2)\n (auto simp: pcore_sum_ext_def camera_pcore_idem split: option.splits)\nnext\nfix a a' b :: \"('a,'b) sum_ext\"\nshow \"pcore a = Some a' \\ \\c. b = a \\ c \\ \\b'. pcore b = Some b' \\ (\\c. b' = a' \\ c)\"\n apply (cases a a' b rule: sum_ex3) \n apply (simp_all add: pcore_sum_ext_def op_sum_ext_def split: option.splits sum_ext.splits)\n apply (metis camera_pcore_mono option.inject sum_ext.inject(1) sum_ext.simps(4) sum_ext.simps(6))\n apply blast+\n apply (metis camera_pcore_mono option.inject sum_ext.distinct(5) sum_ext.inject(2) sum_ext.simps(4))\n by blast+\nnext\nfix a b :: \"('a,'b) sum_ext\"\nfix n\nshow \"Rep_sprop (valid_raw (a \\ b)) n \\ Rep_sprop (valid_raw a) n\" by (cases a; cases b) \n (auto simp: valid_raw_sum_ext_def op_sum_ext_def camera_valid_op split: sum_ext.splits)\nnext\nfix a b c :: \"('a,'b) sum_ext\"\nfix n\nshow \"Rep_sprop (valid_raw a) n \\ n_equiv n a (b \\ c) \\ \n \\c1 c2. a = c1 \\ c2 \\ n_equiv n c1 b \\ n_equiv n c2 c\" apply (cases a b c rule: sum_ex3) \n apply (simp_all add: valid_raw_sum_ext_def op_sum_ext_def split: sum_ext.splits)\n using camera_extend by fast+\nqed\nend\n\ninstance sum_ext :: (dcamera,dcamera) dcamera\n apply (standard; auto simp: valid_raw_sum_ext_def valid_def split: sum_ext.splits)\n using d_valid[simplified valid_def] by blast+\n\ninstance sum_ext :: (core_id,core_id) core_id \nproof\nfix a :: \"('a,'b) sum_ext\"\nshow \"pcore a = Some a\" by (cases a) (auto simp: pcore_sum_ext_def pcore_id)\nqed\n\nlemma sum_update_l: \"a\\B \\ (Inl a) \\ {Inl b |b. b\\B}\"\nby (auto simp: camera_upd_def op_sum_ext_def valid_def valid_raw_sum_ext_def split: sum_ext.splits)\n blast\n\nlemma sum_update_r: \"a\\B \\ (Inr a) \\ {Inr b |b. b\\B}\"\nby (auto simp: camera_upd_def op_sum_ext_def valid_def valid_raw_sum_ext_def split: sum_ext.splits)\n\nlemma sum_swap_l: \"\\\\c n. \\ n_valid (op a c) n; valid b\\ \\ (Inl a) \\ {Inr b}\"\nby (auto simp: valid_def camera_upd_def valid_raw_sum_ext_def op_sum_ext_def split: sum_ext.splits)\n\nlemma sum_swap_r: \"\\\\c n. \\ Rep_sprop (valid_raw (op a c)) n; valid b\\ \\ (Inr a) \\ {Inl b}\"\nby (auto simp: valid_def camera_upd_def valid_raw_sum_ext_def op_sum_ext_def split: sum_ext.splits)\n\nsubsubsection \\ Option type \\\nfun option_op :: \"('a::camera) option \\ 'a option \\ 'a option\" where\n \"option_op (Some a) (Some b) = Some (op a b)\"\n| \"option_op (Some a) (None) = Some a\"\n| \"option_op (None) (Some a) = Some a\" \n| \"option_op None None = None\"\n\nlemma option_opE: \"option_op x y = None \\ x=None \\ y=None\"\n by (induction x y rule: option_op.induct) auto\n\nlemma option_op_none_unit [simp]: \"option_op None x = x\" \"option_op x None = x\"\n apply (cases x) apply auto apply (cases x) by auto\n\nlemmas op_ex2 = option.exhaust[case_product option.exhaust]\nlemmas op_ex3 = option.exhaust[case_product op_ex2]\nlemmas op_ex4 = op_ex3[case_product option.exhaust]\n\nlemma option_op_ne: \"non_expansive2 option_op\"\nproof (rule non_expansive2I)\nfix x y a b :: \"'a option\"\nfix n\nshow \"n_equiv n x y \\ n_equiv n a b \\ n_equiv n (option_op x a) (option_op y b)\"\n by (cases x y a b rule: op_ex4) (auto simp: n_equiv_option_def split: option.splits)\nqed\n\ninstantiation option :: (camera) camera begin\n definition valid_raw_option :: \"'a option \\ sprop\" where\n \"valid_raw_option x = (case x of Some a \\ valid_raw a | None \\ sTrue)\"\n definition pcore_option :: \"'a option \\ 'a option option\" where\n \"pcore_option x = (case x of Some a \\ Some (pcore a) | None \\ Some None)\"\n definition \"op_option \\ option_op\"\ninstance proof\nshow \"non_expansive (valid_raw::'a option \\ sprop)\" by (rule non_expansiveI) \n (auto simp: valid_raw_option_def ofe_refl n_equiv_option_def valid_raw_ne split: option.splits)\nnext\nshow \"non_expansive (pcore::'a option \\ 'a option option)\" \n by (rule non_expansiveI;auto simp: pcore_option_def ofe_refl pcore_ne n_equiv_option_def split: option.split)\n (meson n_equiv_option_def pcore_ne)+\nnext\nshow \"non_expansive2 (op::'a option \\ 'a option \\ 'a option)\"\n by (simp add: op_option_def option_op_ne)\nnext\nfix a b c :: \"'a option\"\nshow \"a \\ b \\ c = a \\ (b \\ c)\" by (cases a; cases b; cases c) (auto simp: op_option_def camera_assoc)\nnext\nfix a b :: \"'a option\"\nshow \"a \\ b = b \\ a\" by (cases a; cases b) (auto simp: op_option_def camera_comm)\nnext\nfix a a' :: \"'a option\"\nshow \"pcore a = Some a' \\ a' \\ a = a\"\n by (cases a; cases a') (auto simp: op_option_def pcore_option_def camera_pcore_id)\nnext\nfix a a' :: \"'a option\"\nshow \"pcore a = Some a' \\ pcore a' = pcore a\"\n by (cases a; cases a') (auto simp: pcore_option_def camera_pcore_idem)\nnext\nfix a a' b :: \"'a option\"\nshow \"pcore a = Some a' \\ \\c. b = a \\ c \\ \\b'. pcore b = Some b' \\ (\\c. b' = a' \\ c)\"\n apply (cases a; cases a'; cases b)\n apply (simp_all add: pcore_option_def op_option_def del: option_op_none_unit)\n apply (metis option.exhaust option_op.simps(3) option_op.simps(4))\n apply (metis option_op.simps(4))\n apply (metis option.exhaust option_op.simps(3) option_op.simps(4))\n apply (metis option.distinct(1) option_op.elims)\n by (metis camera_pcore_mono not_Some_eq option.inject option_op.simps(1) option_op.simps(2))\nnext\nfix a b :: \"'a option\"\nfix n\nshow \"Rep_sprop (valid_raw (a \\ b)) n \\ Rep_sprop (valid_raw a) n\"\n by (cases a; cases b) (auto simp: valid_raw_option_def op_option_def camera_valid_op)\nnext\nfix a b c :: \"'a option\"\nfix n\nshow \"Rep_sprop (valid_raw a) n \\ n_equiv n a (b \\ c) \\ \n \\c1 c2. a = c1 \\ c2 \\ n_equiv n c1 b \\ n_equiv n c2 c\"\n apply (cases a b c rule: op_ex3; auto simp: valid_raw_option_def op_option_def n_equiv_option_def)\n using camera_extend by force+\nqed\nend\n\nlemma option_n_equiv_Some_op: \"n_equiv n z (Some x \\ y) \\ \\z'. z = Some z'\"\n apply (cases y)\n by (auto simp: n_equiv_option_def op_option_def)\n\nlemma option_n_incl: \"n_incl n o1 o2 \\ \n (o1 = None \\ (\\x y. o1 = Some x \\ o2 = Some y \\ (n_equiv n x y \\ n_incl n x y)))\"\n apply (cases o1; cases o2)\n apply (simp_all add: n_incl_def n_equiv_option_def op_option_def)\n apply (meson ofe_eq_limit option_op.simps(3))\n using option_op.elims apply blast \n apply (rule iffI)\n apply (metis (no_types, lifting) ofe_sym option.discI option.sel option_op.elims)\n using ofe_sym option_op.simps(1) option_op.simps(2) by blast\n\nlemma unital_option_n_incl: \"n_incl n (Some (x::'a::ucamera)) (Some y) \\ n_incl n x y\"\nproof\n assume \"n_incl n (Some x) (Some y)\"\n then obtain z where z: \"n_equiv n (Some y) (Some x \\ z)\" by (auto simp: n_incl_def)\n then have \"z=Some c \\ n_equiv n y (x \\ c)\" for c by (auto simp: n_equiv_option_def op_option_def)\n moreover from z have \"z=None \\ n_equiv n y (x\\\\)\" by (auto simp: n_equiv_option_def op_option_def \\_right_id)\n ultimately show \"n_incl n x y\" unfolding n_incl_def using z apply (cases z) by auto\nnext\n assume \"n_incl n x y\"\n then obtain z where \"n_equiv n y (x\\z)\" by (auto simp: n_incl_def)\n then have \"n_equiv n (Some y) (Some x \\ Some z)\" by (auto simp: n_equiv_option_def op_option_def)\n then show \"n_incl n (Some x) (Some y)\" by (auto simp: n_incl_def)\nqed\n \ninstance option :: (dcamera) dcamera\n apply (standard; auto simp: valid_raw_option_def valid_def split: option.splits)\n using d_valid[simplified valid_def] by blast\n\ninstance option :: (core_id) core_id \n by standard(auto simp: pcore_option_def pcore_id split: option.splits)\n\ninstantiation option :: (camera) ucamera begin\ndefinition \"\\_option \\ None\"\ninstance \n by (standard; auto simp: valid_def valid_raw_option_def op_option_def pcore_option_def \\_option_def)\nend\n\ninstance option :: (dcamera) ducamera ..\n\nsubsubsection \\ Agreement camera combinator\\\ninstantiation ag :: (ofe) camera begin\nlift_definition valid_raw_ag :: \"'a ag \\ sprop\" is\n \"\\a n. \\b. a={b} \\ (\\x y. (x\\a\\y\\a) \\ n_equiv n x y)\" by (metis ofe_mono)\ndefinition \"pcore_ag (a::'a ag) \\ Some a\"\nlift_definition op_ag :: \"'a ag \\ 'a ag \\ 'a ag\" is \"(\\)\" by simp\ninstance proof\nshow \"non_expansive (valid_raw::'a ag \\ sprop)\"\n apply (rule non_expansiveI; auto simp: valid_raw_ag.rep_eq n_equiv_ag.rep_eq n_equiv_sprop_def)\n by (metis ofe_mono ofe_sym ofe_trans)+\nnext\nshow \"non_expansive (pcore::'a ag \\ 'a ag option)\"\n by (rule non_expansiveI) (auto simp: pcore_ag_def n_equiv_option_def)\nnext\nshow \"non_expansive2 (op::'a ag \\ 'a ag \\ 'a ag)\"\n by (rule non_expansive2I) (auto simp: op_ag.rep_eq n_equiv_ag_def)\nnext\nfix a b c :: \"'a ag\"\nshow \"a \\ b \\ c = a \\ (b \\ c)\" by transfer auto\nnext\nfix a b :: \"'a ag\"\nshow \"a \\ b = b \\ a\" by transfer auto\nnext\nfix a a' :: \"'a ag\"\nshow \"pcore a = Some a' \\ a' \\ a = a\" by (auto simp: pcore_ag_def; transfer; simp)\nnext\nfix a a' :: \"'a ag\"\nshow \"pcore a = Some a' \\ pcore a' = pcore a\" by (simp add: pcore_ag_def)\nnext\nfix a a' b :: \"'a ag\"\nshow \"pcore a = Some a' \\ \\c. b = a \\ c \\ \\b'. pcore b = Some b' \\ (\\c. b' = a' \\ c)\"\n by (auto simp: pcore_ag_def)\nnext\nfix a b :: \"'a ag\"\nfix n\nshow \"Rep_sprop (valid_raw (a \\ b)) n \\ Rep_sprop (valid_raw a) n\"\n by transfer (auto simp: Un_singleton_iff)\nnext\nfix a b c :: \"'a ag\"\nfix n\nassume assms: \"n_equiv n a (b \\ c)\" \"Rep_sprop (valid_raw a) n\"\nhave valid_equiv: \"Rep_sprop (valid_raw (x\\y)) n \\ n_equiv n x (y::'a ag)\" for x y\n apply transfer\n apply simp_all\n by (metis equals0I ofe_refl singleton_Un_iff)\nfrom assms have \"Rep_sprop (valid_raw (b\\c)) n\"\n by transfer (metis empty_iff insert_iff ofe_sym ofe_trans)\nfrom assms have \"n_equiv n a b\" by (transfer;auto;meson UnI1 ofe_trans)\nmoreover from assms have \"n_equiv n a c\" by (transfer;auto;meson UnI2 ofe_trans)\nmoreover have \"a=a\\a\" by (auto simp: op_ag_def Rep_ag_inverse)\nultimately show \"\\c1 c2. a = c1 \\ c2 \\ n_equiv n c1 b \\ n_equiv n c2 c\"\n by blast\nqed\nend\n\ninstance ag :: (discrete) dcamera\n by standard (auto simp: valid_raw_ag.rep_eq valid_def d_equiv split: option.splits)\n \ninstance ag :: (ofe) core_id by standard (auto simp: pcore_ag_def)\n\nlemma to_ag_valid: \"valid (to_ag a)\"\n by (auto simp: to_ag.rep_eq valid_def valid_raw_ag.rep_eq)\nlemma to_ag_n_valid: \"n_valid (to_ag a) n\" using to_ag_valid valid_def by auto\n \nlemma to_ag_op: \"(to_ag a) = b\\c \\ (b=to_ag a) \\ (c=to_ag a)\"\nproof -\n assume assm: \"to_ag a = b\\c\"\n then have \"{a} = Rep_ag b \\ Rep_ag c\" by (metis assm op_ag.rep_eq to_ag.rep_eq)\n then have \"Rep_ag b = {a}\" \"Rep_ag c = {a}\" using Rep_ag by fast+\n then show \"(b=to_ag a) \\ (c=to_ag a)\" by (metis Rep_ag_inverse to_ag.abs_eq)\nqed\n\nlemma ag_idem: \"((a::'a::ofe ag) \\ a) = a\"\n by (simp add: Rep_ag_inverse op_ag_def)\n\nlemma ag_incl: \"incl (a::'a::ofe ag) b \\ b = (a\\b)\"\n apply (simp add: incl_def op_ag_def)\n by (metis Rep_ag_inverse op_ag.rep_eq sup.left_idem)\n\nlemma to_ag_uninj: \"n_valid a n \\ \\b. n_equiv n (to_ag b) a\"\n apply (auto simp: valid_def valid_raw_ag.rep_eq n_equiv_ag.rep_eq to_ag.rep_eq)\n using ofe_refl apply blast\n by (metis (no_types, opaque_lifting) Rep_ag_inverse equals0I op_ag.rep_eq singletonI \n sup_bot.left_neutral to_ag.rep_eq to_ag_op)\n \nlemma d_valid_ag: \"valid (a::('a::discrete) ag) \\ \\b. a = to_ag b\"\n apply (simp add: valid_def valid_raw_ag.rep_eq to_ag_def d_equiv )\n by (metis (mono_tags, lifting) Rep_ag_inverse image_ag image_empty is_singletonE is_singletonI' \n mem_Collect_eq)\n\nlemma ag_agree: \"n_valid ((a::('a::ofe) ag) \\ b) n \\ n_equiv n a b\"\n apply (simp add: valid_raw_ag.rep_eq op_ag.rep_eq n_equiv_ag.rep_eq)\n apply (rule conjI)\n apply (smt (verit, del_insts) Rep_ag Rep_ag_inverse all_not_in_conv mem_Collect_eq ofe_eq_limit op_ag.rep_eq to_ag.abs_eq to_ag_op)\n by (smt (verit, del_insts) Rep_ag Rep_ag_inject ex_in_conv mem_Collect_eq ofe_eq_limit op_ag.rep_eq to_ag.rep_eq to_ag_op)\n\nlemma ag_valid_n_incl: \"\\n_valid b n; n_incl n a b\\ \\ n_equiv n a (b::'a::ofe ag)\"\nproof -\n assume assms: \"n_valid b n\" \"n_incl n a b\"\n then obtain c where \"n_equiv n b (a\\c)\" using n_incl_def by blast\n with ag_agree[OF n_valid_ne[OF this assms(1)]] \n show ?thesis using ag_idem by (metis ofe_sym ofe_trans op_ne)\nqed\n \nlemma d_ag_agree: \"valid ((a::('a::discrete) ag) \\ b) \\ a=b\"\n by (auto simp: n_equiv_ag.rep_eq valid_def d_equiv) (metis ag_agree d_equiv)\n\nlemma ag_incl_equiv: \"n_equiv n a b \\ n_incl n a (b::'a::ofe ag)\"\n by (metis ag_idem n_incl_def ofe_sym)\n\nlemma to_ag_n_incl: \"\\n_equiv n a b; n_incl n (to_ag a) c\\ \\ n_incl n (to_ag b) c\"\n apply (simp add: n_incl_def to_ag.rep_eq n_equiv_ag.rep_eq op_ag.rep_eq)\n using ofe_trans by blast\n\nsubsubsection \\ Exclusive camera functor\\\ninstantiation ex :: (ofe) camera begin\ndefinition valid_raw_ex :: \"'a ex \\ sprop\" where \n \"valid_raw_ex x = (case x of Ex _ \\ sTrue | ex.Inv \\ sFalse)\" \ndefinition pcore_ex :: \"'a ex \\ 'a ex option\" where\n \"pcore_ex x = (case x of Ex _ \\ None | ex.Inv \\ Some ex.Inv)\"\ndefinition op_ex :: \"'a ex \\ 'a ex \\ 'a ex\" where [simp]: \"op_ex _ _ = ex.Inv\"\ninstance proof\nshow \"non_expansive (valid_raw::'a ex \\ sprop)\"\n by (rule non_expansiveI) (auto simp: valid_raw_ex_def n_equiv_sprop_def split: ex.splits)\nnext\nshow \"non_expansive (pcore::'a ex \\ 'a ex option)\"\n by (rule non_expansiveI) (auto simp: pcore_ex_def n_equiv_option_def split: ex.splits)\nnext\nshow \"non_expansive2 (op::'a ex \\ 'a ex \\ 'a ex)\" by (rule non_expansive2I) simp\nqed (auto simp: valid_raw_ex_def pcore_ex_def split: ex.splits)\nend\n\ninstance ex :: (discrete) dcamera by (standard; auto simp: valid_raw_ex_def valid_def split: ex.splits)\n\nsubsubsection \\ Authoritative camera functor \\\nlemma valid_raw_auth_aux: \"(\\n. \\c. x = ex.Ex c \\ n_incl n (y::'a::ucamera) c \\ n_valid c n) \\ \n {s. \\n m. m \\ n \\ s n \\ s m}\" apply (simp add: n_incl_def) using ofe_mono by fastforce\n\nlemma valid_raw_auth_aux2: \"(\\n. a = None \\ n_valid b n \\ (\\c. a = Some (ex.Ex c) \\ n_incl n b c \\ n_valid c n))\n \\ {s. \\n m. m \\ n \\ s n \\ s m}\"\n by (cases a;auto simp: n_valid_ne) (metis camera_n_incl_le)\n \ninstantiation auth :: (ucamera) camera begin\ndefinition valid_raw_auth :: \"'a auth \\ sprop\" where\n \"valid_raw_auth a = (case a of Auth (x,b) \\ Abs_sprop (\\n. (x=None\\Rep_sprop (valid_raw b) n) \\ \n (\\c. x=Some(Ex c) \\ n_incl n b c \\ Rep_sprop (valid_raw c) n)))\"\ndefinition pcore_auth :: \"'a auth \\ 'a auth option\" where\n \"pcore_auth a = (case a of Auth (_,b) \\ Some (Auth (None,core b)))\"\ndefinition op_auth :: \"'a auth \\ 'a auth \\ 'a auth\" where\n \"op_auth a b = (case a of Auth (x1,b1) \\ case b of Auth (x2,b2) \\ Auth (op (x1,b1) (x2,b2)))\"\ninstance proof \nshow \"non_expansive (valid_raw::'a auth \\ sprop)\"\napply (rule non_expansiveI)\napply (auto simp: valid_raw_auth_def n_equiv_sprop_def n_equiv_option_def split: auth.splits)\nsubgoal for n b b' m a a' proof -\nassume assms: \"m\\n\" \"Rep_sprop (Abs_sprop (\\n. \\c. a = ex.Ex c \\ n_incl n b c \\ n_valid c n)) m\"\n \"n_equiv n b b'\" \"n_equiv n a a'\"\nfrom Abs_sprop_inverse[OF valid_raw_auth_aux, of a b] assms(2) have \"\\c. a = ex.Ex c \\ n_incl m b c \\ n_valid c m\" by simp\nwith assms (1,3,4) have \"\\c. a' = ex.Ex c \\ n_incl m b' c \\ n_valid c m\" \napply (simp add: n_incl_def)\nby (smt (verit, ccfv_threshold) dual_order.eq_iff n_equiv_ex.elims(1) n_equiv_ex.simps(1) ne_sprop_weaken ofe_mono ofe_sym ofe_trans op_equiv_subst valid_raw_non_expansive)\nthen show \"Rep_sprop (Abs_sprop (\\n. \\c. a' = ex.Ex c \\ n_incl n b' c \\ n_valid c n)) m\"\nusing Abs_sprop_inverse[OF valid_raw_auth_aux, of a' b'] by simp qed\napply (meson n_valid_ne ofe_mono)\napply (simp add: \\\\n m b' b a' a. \\m \\ n; Rep_sprop (Abs_sprop (\\n. \\c. a = ex.Ex c \\ n_incl n b c \\ n_valid c n)) m; n_equiv n b b'; n_equiv n a a'\\ \\ Rep_sprop (Abs_sprop (\\n. \\c. a' = ex.Ex c \\ n_incl n b' c \\ n_valid c n)) m\\ ofe_sym)\nby (meson n_equiv_sprop_def non_expansiveE valid_raw_non_expansive)\nnext\nshow \"non_expansive (pcore::'a auth \\ 'a auth option)\" by (rule non_expansiveI)\n (auto simp: pcore_auth_def n_equiv_option_def core_ne[unfolded non_expansive_def] split: auth.splits)\nnext\nshow \"non_expansive2 (op::'a auth \\ 'a auth \\ 'a auth)\"\n by (rule non_expansive2I) (auto simp: op_auth_def op_prod_def split: auth.splits)\nnext\nfix a b c :: \"'a auth\"\nshow \"a \\ b \\ c = a \\ (b \\ c)\" by (auto simp: op_auth_def camera_assoc split: auth.splits)\nnext\nfix a b :: \"'a auth\"\nshow \"a \\ b = b \\ a\" by (auto simp: op_auth_def camera_comm split: auth.splits)\nnext\nfix a a' :: \"'a auth\"\nshow \"pcore a = Some a' \\ a' \\ a = a\" \n apply (simp add: pcore_auth_def op_auth_def op_prod_def split: auth.splits prod.splits)\n by (metis Pair_inject \\_left_id \\_option_def auth.inject camera_core_id)\nnext\nfix a a' :: \"'a auth\"\nshow \"pcore a = Some a' \\ pcore a' = pcore a\"\n by (auto simp: pcore_auth_def camera_pcore_idem core_def total_pcore split: auth.splits)\nnext\nfix a a' b :: \"'a auth\"\nassume assms: \"pcore a = Some a'\" \"\\c. b = a \\ c\"\nobtain c d where a:\"a = Auth (c,d)\" using auth.exhaust by auto\nthen have a': \"a' = Auth (None, core d)\" using assms(1) pcore_auth_def by force\nfrom assms(2) a obtain x y where c: \"b = Auth ((c,d)\\(x,y))\" apply (simp add: op_auth_def split: auth.splits)\n by (metis auth.exhaust surj_pair)\nthen have b': \"pcore b = Some (Auth (None, core (d\\y)))\"\n by (auto simp: pcore_auth_def core_def op_prod_def split: prod.splits)\nobtain z where z:\"core(d\\y) = core d \\ z\" using camera_pcore_mono[of d _ \"d\\y\"] total_pcore\n by (meson camera_core_mono incl_def)\nwith a' b' have \"Auth (None, core (d\\y)) = a' \\ Auth (None, z)\" \n by (auto simp: op_auth_def op_prod_def op_option_def)\nwith b' show \"\\b'. pcore b = Some b' \\ (\\c. b' = a' \\ c)\" by auto\nnext\nfix a b :: \"'a auth\"\nfix n\nshow \"Rep_sprop (valid_raw (a \\ b)) n \\ Rep_sprop (valid_raw a) n\"\n apply (auto simp: valid_raw_auth_def op_auth_def op_prod_def op_option_def Abs_sprop_inverse[OF valid_raw_auth_aux2] split: auth.splits)\n using option_op.elims apply force\n apply (smt (verit, best) camera_assoc ex.distinct(1) n_incl_def op_ex_def option.sel option_op.elims)\n using camera_valid_op apply blast\n by (meson camera_valid_op n_incl_def n_valid_ne)\nnext\nfix a b c :: \"'a auth\"\nfix n\nassume assms: \"Rep_sprop (valid_raw a) n\" \"n_equiv n a (b \\ c)\"\nobtain a1 a2 where a: \"a=Auth (a1,a2)\" using auth.exhaust by auto\nobtain b1 b2 where b: \"b=Auth (b1,b2)\" using auth.exhaust by auto\nobtain c1 c2 where c: \"c=Auth (c1,c2)\" using auth.exhaust by auto\nfrom assms(2) a b c have n: \"n_equiv n a1 (b1\\c1)\" \"n_equiv n a2 (b2\\c2)\" \n by (auto simp: op_auth_def op_prod_def)\nfrom assms(1) a have a_val: \"(a1=None\\Rep_sprop (valid_raw a2) n) \\ \n (\\c. a1=Some(Ex c) \\ n_incl n a2 c \\ Rep_sprop (valid_raw c) n)\"\n by (auto simp: valid_raw_auth_def Abs_sprop_inverse[OF valid_raw_auth_aux2] split: auth.splits) \n{\n then have \"a1=None \\ \\d2 e2. (a2=d2\\e2 \\ n_equiv n d2 b2 \\ n_equiv n e2 c2)\"\n using camera_extend n(2) by blast\n then obtain d2 e2 where \"a1=None \\ (a2=d2\\e2 \\ n_equiv n d2 b2 \\ n_equiv n e2 c2)\" by blast\n then have \"a1=None \\ a=Auth(a1,d2)\\Auth(a1,e2) \\ n_equiv n (Auth(a1,d2)) b \\ n_equiv n (Auth(a1,e2)) c\"\n using a b c n apply (simp add: op_auth_def op_prod_def op_option_def)\n by (metis n_equiv_option_def not_Some_eq option_op.elims)\n then have \"a1=None \\ \\c1 c2. a = c1 \\ c2 \\ n_equiv n c1 b \\ n_equiv n c2 c\" by blast\n}\nmoreover {\n fix x\n from a_val have x: \"a1=Some(Ex x) \\ n_incl n a2 x \\ Rep_sprop (valid_raw x) n\" by simp\n then have \"a1=Some(Ex x) \\ Rep_sprop (valid_raw a1) n\" \n by (auto simp: valid_raw_option_def valid_raw_ex_def split: option.splits ex.splits)\n then have \"a1=Some(Ex x) \\ \\d1 e1. (a1=d1\\e1 \\ n_equiv n d1 b1 \\ n_equiv n e1 c1)\"\n using n(1) camera_extend by blast\n then obtain d1 e1 where a1: \"a1=Some(Ex x) \\ (a1=d1\\e1 \\ n_equiv n d1 b1 \\ n_equiv n e1 c1)\" \n by blast\n from x have \"a1=Some(Ex x) \\ Rep_sprop (valid_raw a2) n\" using n_valid_incl_subst[of n a2 x \\ n]\n by (metis \\_left_id camera_comm order_refl)\n then have \"a1=Some(Ex x) \\ \\d2 e2. (a2=d2\\e2 \\ n_equiv n d2 b2 \\ n_equiv n e2 c2)\"\n using camera_extend n(2) by blast \n then obtain d2 e2 where \"a1=Some(Ex x) \\ (a2=d2\\e2 \\ n_equiv n d2 b2 \\ n_equiv n e2 c2)\" by blast\n with a1 a b c have \"a1=Some(Ex x) \\ a=Auth(d1,d2)\\Auth(e1,e2)\\ n_equiv n (Auth(d1,d2)) b \\ n_equiv n (Auth(e1,e2)) c\"\n by (auto simp: op_auth_def op_prod_def)\n then have \"a1=Some(Ex x) \\ \\c1 c2. a = c1 \\ c2 \\ n_equiv n c1 b \\ n_equiv n c2 c\" by blast\n}\nultimately show \"\\c1 c2. a = c1 \\ c2 \\ n_equiv n c1 b \\ n_equiv n c2 c\"\n using a apply (cases a1) apply blast using a_val by blast\nqed\nend\n\ninstance auth :: (ducamera) dcamera \n apply standard \n apply (simp add: valid_raw_auth_def Abs_sprop_inverse[OF valid_raw_auth_aux2] valid_def n_incl_def \n split: auth.splits)\n by (auto simp: d_equiv dcamera_valid_iff[symmetric])\n\ninstantiation auth :: (ucamera) ucamera begin\ndefinition \"\\_auth \\ Auth (None, \\)\"\ninstance proof (standard)\nhave \"valid (\\::'a auth) = valid (Auth (None, \\::'a))\" by (simp add: \\_auth_def)\nalso have \"... = (\\n. Rep_sprop (valid_raw (Auth (None, \\::'a))) n)\" by (simp add: valid_def)\nalso have \"... = (\\n. Rep_sprop (Abs_sprop (\\n. Rep_sprop (valid_raw (\\::'a)) n)) n)\"\n by (auto simp: valid_raw_auth_def)\nalso have \"... = (\\n. Rep_sprop (valid_raw (\\::'a)) n)\" using Rep_sprop_inverse by simp\nalso have \"... = valid (\\::'a)\" using valid_def by metis\nalso have \"... = True\" using \\_valid by simp\nfinally show \"valid (\\::'a auth)\" by simp\nnext\nfix a :: \"'a auth\"\nshow \"op \\ a = a\" apply (simp add: op_auth_def \\_auth_def op_prod_def split: auth.splits)\n using \\_left_id[simplified ] \\_option_def by metis+\nnext\nshow \"pcore (\\::'a auth) = Some \\\" by (auto simp: \\_auth_def pcore_auth_def \\_core split: auth.splits)\nqed\nend\n\ninstance auth :: (ducamera) ducamera ..\n\nabbreviation full :: \"'m::ucamera \\ 'm auth\" where \"full \\ \\a::'m. Auth (Some (Ex a), \\)\"\n\nlemma fragm_core_id: \"pcore_id_pred (fragm (a::'a::{ucamera,core_id}))\"\n by (auto simp: core_id_pred core_def pcore_auth_def core_id[unfolded core_def, simplified] \n split: auth.splits)\n\nlemma auth_frag_op: \"fragm (a\\b) = fragm a \\ fragm b\"\n by (auto simp: op_auth_def op_prod_def op_option_def)\n\nlemma auth_comb_opL:\"(comb a b) \\ (fragm c) = comb a (b\\c)\"\n by (auto simp: op_auth_def op_prod_def op_option_def)\n\nlemma auth_comb_opR:\"(fragm c) \\ (comb a b) = comb a (b\\c)\"\n by (auto simp: op_auth_def op_prod_def op_option_def camera_comm) \n \nlemma auth_valid_def [simp]: \n \"n_valid (Auth (a,b)::('m::ucamera) auth) n \\ (a = None \\ n_valid b n \\ (\\c. a = Some (ex.Ex c) \n \\ n_incl n b c \\ n_valid c n))\"\n by (auto simp: valid_raw_auth_def Abs_sprop_inverse[OF valid_raw_auth_aux2])\n\nlemma n_incl_fragm[simp]: \"n_incl n (fragm a) (Auth (b,c)) = n_incl n a c\"\nproof (standard; unfold n_incl_def)\n assume \"\\ca. n_equiv n (Auth (b, c)) (fragm a \\ ca)\"\n then obtain d e where \"n_equiv n (Auth (b, c)) (fragm a \\ (Auth (d,e)))\"\n by (metis auth.exhaust old.prod.exhaust)\n then have \"n_equiv n (Auth (b, c)) (Auth (None\\d,a\\e))\"\n by (auto simp: op_auth_def op_prod_def)\n then have \"n_equiv n c (a\\e)\" by auto\n then show \"\\ca. n_equiv n c (a \\ ca)\" by auto\nnext\n assume \"\\ca. n_equiv n c (a \\ ca)\"\n then obtain d where \"n_equiv n c (a \\ d)\" by blast\n moreover have \"n_equiv n b (None\\b)\" by (metis \\_left_id \\_option_def ofe_refl)\n ultimately have \"n_equiv n (Auth (b,c)) (Auth ((None\\b),(a\\d)))\"\n by (auto simp: op_auth_def)\n then have \"n_equiv n (Auth (b,c)) (fragm a \\ (Auth (b,d)))\"\n by (auto simp: op_auth_def op_prod_def) \n then show \"\\ca. n_equiv n (Auth (b, c)) (fragm a \\ ca)\" by blast\nqed\n\ndefinition lup :: \"('a::ucamera)\\'a \\ 'a\\'a \\ bool\" (infix \"\\\\<^sub>L\" 60) where\n \"lup \\ \\(a,f) (a',f'). \\n c. (n_valid a n \\ n_equiv n a (f \\ c)) \\ (n_valid a' n \\ n_equiv n a' (f' \\ c))\"\n\n(* Axiomatized for now. *)\nlemma auth_update_alloc: \"(a,f)\\\\<^sub>L(a',f') \\ (comb a f) \\ {comb a' f'}\"\napply (auto simp: lup_def camera_upd_def valid_def op_auth_def op_prod_def split: auth.splits)\napply (metis n_incl_op_extend option.distinct(1) option_n_incl)\napply (metis op_option_def option.distinct(1) option_op.elims)\nsorry\n\nsubsubsection \\ Map functors, based on a simple wrapper type \\\n\ntext \\\n As maps are only functions to options and thus can't directly be declared as class instances, \n we need a bit of class magic. Based on ideas from the AFP entry Separation Logic Algebra.\n\\\nclass opt = ucamera + fixes none assumes none_\\: \"\\ = none\"\ninstantiation option :: (camera) opt begin definition [simp]: \"none \\ None\" instance \n by standard (auto simp: ofe_eq_option_def \\_option_def)\nend\n\nlemma pcore_op_opt[simp]: \"(case pcore x of None \\ none | Some a \\ a) \\ (x::'b::opt) = x\"\n apply (cases \"pcore x\")\n apply (simp_all add: camera_pcore_id)\n using \\_left_id none_\\ by metis\n \ninstantiation \"fun\" :: (type, opt) camera begin\nlift_definition valid_raw_fun :: \"('a\\'b) \\ sprop\" is\n \"\\m n. \\i. n_valid (m i) n\" by simp\ndefinition pcore_fun :: \"('a\\'b) \\ ('a\\'b) option\" where\n \"pcore_fun m = Some ((\\b. case pcore b of Some a \\ a | None \\ none) \\ m)\"\ndefinition op_fun :: \"('a\\'b) \\ ('a\\'b) \\ ('a\\'b)\" where\n \"op_fun m1 m2 = (\\i. (m1 i) \\ (m2 i))\"\ninstance proof\nshow \"non_expansive (valid_raw::('a\\'b) \\ sprop)\"\n by (rule non_expansiveI; auto simp: valid_raw_fun_def n_equiv_sprop_def Abs_sprop_inverse)\n (meson n_equiv_fun_def n_valid_ne ofe_mono ofe_sym)+\nnext\nshow \"non_expansive (pcore::('a\\'b) \\ ('a\\'b) option)\"\n apply (rule non_expansiveI)\n apply (simp add: pcore_fun_def n_equiv_fun_def split: option.splits)\n using valid_raw_ne\n by (smt (verit, del_insts) comp_def n_equiv_fun_def n_equiv_option_def non_expansive_def ofe_eq_limit option.sel option.simps(5) pcore_ne)\nnext\nshow \"non_expansive2 (op::('a\\'b) \\ ('a\\'b) \\ ('a\\'b))\"\n apply (rule non_expansive2I; auto simp: op_fun_def n_equiv_fun_def)\n using op_ne by blast\nnext\nfix a b c :: \"'a\\'b\"\nshow \"a \\ b \\ c = a \\ (b \\ c)\" by (auto simp: op_fun_def camera_assoc)\nnext\nfix a b :: \"'a\\'b\"\nshow \"a \\ b = b \\ a\" by (auto simp: op_fun_def camera_comm)\nnext\nfix a a' :: \"'a\\'b\"\nshow \"pcore a = Some a' \\ a' \\ a = a\" by (auto simp: pcore_fun_def op_fun_def)\nnext\nfix a a' :: \"'a\\'b\"\nshow \"pcore a = Some a' \\ pcore a' = pcore a\" by (auto simp: pcore_fun_def)\n (smt (z3) \\_pcore camera_pcore_idem comp_apply comp_assoc fun.map_cong0 none_\\ option.case_eq_if option.collapse option.simps(5))\nnext\nfix a a' b :: \"'a\\'b\"\nassume assms: \"\\c. b = a \\ c\"\nthen obtain c where c: \"b = a \\ c\" by blast\nthen have \"\\i. b i = a i \\ c i\" by (auto simp: op_fun_def)\nthen have i: \"\\i. \\j. (case pcore (a i \\ c i) of None \\ none | Some a \\ a) = (case pcore (a i) of None \\ none | Some a \\ a) \\ j\"\n by (metis option.simps(5) camera_pcore_mono total_pcore)\ndefine cs where cs: \"cs \\ {(i,j) | i j. (case pcore (a i \\ c i) of None \\ none | Some a \\ a) = (case pcore (a i) of None \\ none | Some a \\ a) \\ j}\"\nwith i have \"\\i. \\j. (i,j) \\ cs\" by simp\nthen obtain cf where \"\\i. (i, cf i) \\ cs\" by metis\nwith i cs have \"\\i. (case pcore (a i \\ c i) of None \\ none | Some a \\ a) = (case pcore (a i) of None \\ none | Some a \\ a) \\ cf i\"\n by simp\nthen have \"(\\b. case pcore b of None \\ none | Some a \\ a) \\ (\\i. a i \\ c i) = (\\i. (case pcore (a i) of None \\ none | Some a \\ a) \\ cf i)\"\n by auto \nthen show \"pcore a = Some a' \\ \\b'. pcore b = Some b' \\ (\\c. b' = a' \\ c)\"\n by (auto simp: pcore_fun_def op_fun_def c)\nnext\nfix a b :: \"'a\\'b\"\nfix n\nshow \"Rep_sprop (valid_raw (a \\ b)) n \\ Rep_sprop (valid_raw a) n\"\n apply (simp add: valid_raw_fun_def op_fun_def)\n using Abs_sprop_inverse camera_valid_op by fastforce\nnext\nfix a b c :: \"'a\\'b\"\nfix n\nassume assms: \"Rep_sprop (valid_raw a) n\" \"n_equiv n a (b \\ c)\"\nthen have i_valid: \"\\i. n_valid (a i) n\" by (auto simp: Abs_sprop_inverse valid_raw_fun_def)\nfrom assms have i_equiv: \"\\i. n_equiv n (a i) (b i \\ c i)\" by (auto simp: n_equiv_fun_def op_fun_def)\nfrom camera_extend i_valid i_equiv \n have i12: \"\\i. \\i1 i2. a i = i1 \\ i2 \\ n_equiv n i1 (b i) \\ n_equiv n i2 (c i)\" by blast\nthen obtain c1 c2 where \"\\i. a i = (c1 i) \\ (c2 i) \\ n_equiv n (c1 i) (b i) \\ n_equiv n (c2 i) (c i)\"\n by metis\nthen show \"\\c1 c2. a = c1 \\ c2 \\ n_equiv n c1 b \\ n_equiv n c2 c\"\n by (auto simp: op_fun_def n_equiv_fun_def)\nqed\nend\n\nlemma singleton_map_n_valid [simp]: \"n_valid [k\\v] n \\ n_valid v n\"\n by (simp add: valid_raw_fun.rep_eq valid_raw_option_def)\n\nlemma singleton_map_valid [simp]: \"valid [k\\v] \\ valid v\"\n by (simp add: valid_def)\n\nlemma singleton_map_op [simp]: \"[k\\v] \\ [k\\v'] = [k\\(v\\v')]\"\n by (auto simp: op_fun_def op_option_def)\n\nlemma singleton_map_n_equiv [simp]: \"n_equiv n [k\\x] [k\\y] \\ n_equiv n x y\"\n by (auto simp: n_equiv_fun_def n_equiv_option_def)\n\nlemma singleton_map_only_n_equiv: \"n_equiv n [k\\x] y \\ \\y'. y=[k\\y'] \\ n_equiv n x y'\" \nproof -\nassume assms: \"n_equiv n [k\\x] y\"\nthen have i: \"n_equiv n ([k\\x] i) (y i)\" for i by (simp add: n_equiv_fun_def)\nfrom this[of k] have k: \"n_equiv n (Some x) (y k)\" by simp\nfrom i have not_k: \"n_equiv n None (y j) \\ j\\k\" for j\n by (metis fun_upd_apply n_equiv_option_def option.distinct(1))\nfrom k obtain y' where y': \"y k = Some y'\" \"n_equiv n x y'\"\n by (metis n_equiv_option_def option.distinct(1) option.sel)\nmoreover from not_k have \"y j = None \\ j\\k\" for j by (simp add: n_equiv_option_def)\nultimately have \"y = (\\i. if i=k then Some y' else None)\" by metis\nwith y' show ?thesis by fastforce\nqed\n \nlemma singleton_map_n_incl: \"n_incl n [k\\v] m \\ (\\ v'. m k = Some v' \\ n_incl n (Some v) (Some v'))\"\nproof \n assume \"n_incl n [k\\v] m\"\n then obtain m' where \"n_equiv n m ([k\\v]\\m')\" unfolding n_incl_def by blast\n then have \"\\i. n_equiv n (m i) (([k\\v]\\m') i)\" unfolding n_equiv_fun_def .\n then have \"n_equiv n (m k) (Some v \\ (m' k))\" unfolding op_fun_def by (metis fun_upd_same)\n moreover from option_n_equiv_Some_op[OF this] obtain v' where \"m k = Some v'\" by auto\n ultimately show \"\\ v'. m k = Some v' \\ n_incl n (Some v) (Some v')\" by (auto simp: n_incl_def)\nnext\n assume \"\\ v'. m k = Some v' \\ n_incl n (Some v) (Some v')\"\n then obtain v' c where \"m k = Some v'\" \"n_equiv n (m k) (Some v \\ c)\" by (auto simp: n_incl_def)\n then have \"n_equiv n (m k) (([k\\v]\\ (m(k:=c))) k)\" unfolding op_fun_def by simp\n then have \"n_equiv n m ([k\\v]\\ (m(k:=c)))\" \n apply (auto simp: n_equiv_fun_def op_fun_def op_option_def)\n subgoal for i apply (cases \"m i\") by (auto simp: ofe_refl) done\n then show \"n_incl n [k\\v] m\" by (auto simp: n_incl_def)\nqed\n\nlemma pcore_fun_alt: \"pcore (f::'a\\'b::camera) = Some (\\i. Option.bind (f i) pcore)\"\nproof -\nhave \"pcore f = Some (\\i. case pcore (f i) of Some a \\ a | None \\ None)\"\n by (auto simp: pcore_fun_def comp_def) (metis \\_option_def none_\\)\nmoreover have \"(case pcore (f x) of Some a \\ a | None \\ None) = Option.bind (f x) pcore\" for x\n by (cases \"f x\") (auto simp: pcore_option_def)\nultimately show ?thesis by simp\nqed\n\ndefinition merge :: \"('a\\'a\\'a) \\ ('b\\'a) \\ ('b\\'a) \\ ('b\\'a)\" where\n \"merge f m1 m2 = (\\i. (case m1 i of Some x1 \\ (case m2 i of Some x2 \\ Some (f x1 x2) \n | None \\ Some x1) | None \\ m2 i))\"\n\nlemma merge_op: \"merge op m1 m2 = m1 \\ m2\"\n by (auto simp: merge_def op_fun_def op_option_def split: option.splits) \n\nlemma merge_dom: \"dom (merge f m1 m2) = dom m1 \\ dom m2\"\n by (auto simp: merge_def split: option.splits)\n\nlemma merge_ne: \"non_expansive2 f \\ non_expansive2 (merge f)\"\n apply (rule non_expansive2I)\n apply (auto simp: non_expansive2_def merge_def n_equiv_fun_def n_equiv_option_def split: option.splits)\n apply (metis option.distinct(1))+\n by (metis option.discI option.inject)+\n\nclass d_opt = opt + dcamera\ninstance option :: (dcamera) d_opt ..\n\ninstance \"fun\" :: (type,d_opt) dcamera \n apply (standard; auto simp: valid_raw_fun.rep_eq valid_def)\n using d_valid[simplified valid_def] by blast\n \nclass opt_core_id = opt + core_id\ninstance option :: (core_id) opt_core_id ..\n\ninstance \"fun\" :: (type,opt_core_id) core_id by standard (auto simp: pcore_fun_def pcore_id)\n\ninstantiation \"fun\" :: (type, opt) ucamera begin\ndefinition \\_fun :: \"'a\\'b\" where \"\\_fun \\ (\\_. \\)\"\ninstance apply (standard)\napply (simp_all add: valid_def valid_raw_fun_def Abs_sprop_inverse valid_raw_option_def)\nsubgoal using Rep_sprop_inverse \\_valid valid_def by (auto simp: \\_fun_def)\nsubgoal by (auto simp: op_fun_def \\_left_id \\_fun_def)\nby (auto simp: pcore_fun_def \\_pcore \\_fun_def split: option.splits )\nend\n\nlemma \\_map_equiv [simp]: \"n_equiv n (\\::('a\\'b::camera)) x \\ x=\\\"\n by (auto simp: n_equiv_fun_def \\_fun_def n_equiv_option_def \\_option_def) \n\nlemma dcamera_val_\\_map [simp]: \"dcamera_val (\\::('a\\'b::camera))\"\n by (simp add: dcamera_val_def discrete_val_def ofe_limit valid_def valid_raw_fun.rep_eq)\n (auto simp: \\_fun_def \\_option_def valid_raw_option_def)\n\nlemma map_empty_left_id: \"Map.empty \\ f = (f:: 'a\\'b::camera)\"\nunfolding op_fun_def op_option_def HOL.fun_eq_iff\nproof\nfix x show \"option_op None (f x) = f x\" by (cases \"f x\") auto\nqed\n\nlemma ran_pcore_id_pred: \"(\\x \\ ran m. pcore_id_pred x) \\ pcore_id_pred m\"\nproof -\n assume assm: \"\\x \\ ran m. pcore_id_pred x\"\n then have \"\\y. pcore (m y) = Some (m y)\" \n by (auto simp: pcore_id_pred_def ran_def pcore_option_def split: option.splits)\n then show ?thesis unfolding pcore_id_pred_def pcore_fun_def comp_def by simp\nqed\n \ninstance \"fun\" :: (type,d_opt) ducamera ..\n\nlemma fun_n_incl:\n \"n_incl n (f::'a\\'b::{camera} option) g \\ dom f \\ dom g \\ (\\k. n_incl n (f k) (g k))\"\napply (auto simp: n_incl_def incl_def n_equiv_fun_def n_equiv_option_def op_fun_def op_option_def)\nsubgoal by (metis option_op.elims)\nby meson\n\nsubsubsection \\ Set type camera \\\ninstantiation set :: (type) camera begin\ndefinition valid_raw_set :: \"'a set \\ sprop\" where \"valid_raw_set _ = sTrue\"\ndefinition pcore_set :: \"'a set \\ 'a set option\" where \"pcore_set \\ Some\"\ndefinition op_set :: \"'a set \\ 'a set \\ 'a set\" where \"op_set \\ (\\)\"\ninstance proof\nshow \"non_expansive (valid_raw::'a set \\ sprop)\"\n by (rule non_expansiveI) (auto simp: valid_raw_set_def n_equiv_sprop_def)\nnext\nshow \"non_expansive (pcore::'a set \\ 'a set option)\"\n by (rule non_expansiveI) (auto simp: pcore_set_def n_equiv_option_def)\nnext\nshow \"non_expansive2 (op::'a set \\ 'a set \\ 'a set)\"\n by (rule non_expansive2I) (auto simp: op_set_def n_equiv_set_def)\nqed (auto simp: valid_raw_set_def pcore_set_def op_set_def n_equiv_set_def)\nend\n\ninstance set :: (type) dcamera by (standard; auto simp: valid_raw_set_def valid_def)\n\ninstance set :: (type) core_id by (standard) (auto simp: pcore_set_def)\n\nlemma n_incl_set[simp]: \"n_incl n a (b::'a set) = (a\\b)\"\n by (auto simp: n_incl_def op_set_def n_equiv_set_def)\nlemma n_incl_single[simp]: \"n_incl n {x} a = (x\\a)\"\n by auto\n \ninstantiation set :: (type) ucamera begin\ndefinition \\_set :: \"'a set\" where \"\\_set = {}\"\ninstance by (standard) (auto simp: op_set_def valid_def valid_raw_set_def pcore_set_def \\_set_def)\nend\n\ninstance set :: (type) ducamera ..\n\nsubsubsection \\ Disjoint set camera \\\ninstantiation dset :: (type) camera begin\ndefinition valid_raw_dset :: \"'a dset \\ sprop\" where \n \"valid_raw_dset d \\ case d of DSet _ \\ sTrue | DBot \\ sFalse\"\ndefinition pcore_dset :: \"'a dset \\ 'a dset option\" where \"pcore_dset d = Some (DSet {})\"\ndefinition op_dset :: \"'a dset \\ 'a dset \\ 'a dset\" where \n \"op_dset x y \\ case (x,y) of (DSet x', DSet y') \\ if x' \\ y' = {} then DSet (x'\\y') else DBot\n | _ \\ DBot\"\ninstance proof\nshow \"non_expansive (valid_raw::'a dset \\ sprop)\"\n by (rule non_expansiveI) (auto simp: d_equiv ofe_refl)\nnext\nshow \"non_expansive (pcore::'a dset \\ 'a dset option)\"\n by (rule non_expansiveI) (auto simp: d_equiv)\nnext\nshow \"non_expansive2 (op::'a dset \\ 'a dset \\ 'a dset)\"\n by (rule non_expansive2I) (auto simp: d_equiv)\nqed (auto simp: pcore_dset_def op_dset_def valid_raw_dset_def d_equiv split: dset.splits)\nend\n\nlemma dsubs_op_minus: \"d1 \\\\<^sub>d d2 \\ d2 = d1 \\ (d2 - d1)\"\n unfolding op_dset_def using dsubs_dset by fastforce\n\nlemma dsubs_disj_opL: \"\\disj d1 d2; d1 \\ d2 \\\\<^sub>d d3\\ \\ d1 \\\\<^sub>d d3\"\n unfolding disj_def apply (cases d1; cases d2; cases d3) apply auto\n by (smt (verit, ccfv_threshold) Un_iff dset.simps(4) op_dset_def prod.simps(2) subdset_eq.simps(1) subsetD)\n\nlemma dsubs_disj_opR: \"\\disj d1 d2; d1 \\ d2 \\\\<^sub>d d3\\ \\ d2 \\\\<^sub>d d3\"\n unfolding disj_def apply (cases d1; cases d2; cases d3) apply auto\n by (metis camera_comm disj_def disjoint_iff dsubs_disj_opL subdset_eq.simps(1) subsetD)\n\ninstance dset :: (type) dcamera \n by standard (auto simp: valid_def valid_raw_dset_def split: dset.splits)\n\ninstantiation dset :: (type) ucamera begin\ndefinition \\_dset :: \"'a dset\" where \"\\_dset = DSet {}\"\ninstance \n by standard (auto simp: valid_def valid_raw_dset_def op_dset_def pcore_dset_def \\_dset_def split:dset.splits)\nend\n\ninstance dset :: (type) ducamera ..\n\nsubsubsection \\ Unit type camera \\\ninstantiation unit :: camera begin\ndefinition valid_raw_unit :: \"unit \\ sprop\" where [simp]: \"valid_raw_unit _ = sTrue\"\ndefinition pcore_unit :: \"unit \\ unit option\" where [simp]: \"pcore_unit = Some\"\ndefinition op_unit :: \"unit \\ unit \\ unit\" where [simp]: \"op_unit _ _ = ()\"\ninstance by standard (auto simp: non_expansive_def non_expansive2_def n_equiv_option_def n_equiv_sprop_def)\nend\n\ninstance unit :: dcamera by standard (auto simp: valid_def)\n\ninstantiation unit :: ucamera begin\ndefinition \\_unit :: unit where [simp]: \"\\_unit = ()\"\ninstance by standard (auto simp: valid_def)\nend\n\ninstance unit :: ducamera ..\n\nsubsubsection \\Finite set camera\\\ninstantiation fset :: (type) camera begin\ndefinition valid_raw_fset :: \"'a fset \\ sprop\" where \"valid_raw_fset _ = sTrue\"\ndefinition pcore_fset :: \"'a fset \\ 'a fset option\" where \"pcore_fset \\ Some\"\ndefinition op_fset :: \"'a fset \\ 'a fset \\ 'a fset\" where \"op_fset \\ (|\\|)\"\ninstance proof\nshow \"non_expansive (valid_raw::'a fset \\ sprop)\"\n by (rule non_expansiveI) (auto simp: valid_raw_fset_def n_equiv_sprop_def)\nnext\nshow \"non_expansive (pcore::'a fset \\ 'a fset option)\"\n by (rule non_expansiveI) (auto simp: pcore_fset_def n_equiv_option_def)\nnext\nshow \"non_expansive2 (op::'a fset \\ 'a fset \\ 'a fset)\"\n by (rule non_expansive2I) (auto simp: op_fset_def)\nqed (auto simp: valid_raw_fset_def pcore_fset_def op_fset_def)\nend\n\ninstance fset :: (type) dcamera by (standard; auto simp: valid_raw_fset_def valid_def)\n\ninstance fset :: (type) core_id by (standard) (auto simp: pcore_fset_def)\n\nlemma n_incl_fset[simp]: \"n_incl n a (b::'a fset) = (a|\\|b)\"\n by (auto simp: n_incl_def op_fset_def)\nlemma n_incl_fsingle[simp]: \"n_incl n {|x|} a = (x|\\|a)\"\n by auto\n \ninstantiation fset :: (type) ucamera begin\ndefinition \\_fset :: \"'a fset\" where \"\\_fset = {||}\"\ninstance by (standard) (auto simp: op_fset_def valid_def valid_raw_fset_def pcore_fset_def \\_fset_def)\nend\n\nsubsubsection \\ Disjoint fset camera \\\ninstantiation dfset :: (type) camera begin\ndefinition valid_raw_dfset :: \"'a dfset \\ sprop\" where \n \"valid_raw_dfset d \\ case d of DFSet _ \\ sTrue | DFBot \\ sFalse\"\ndefinition pcore_dfset :: \"'a dfset \\ 'a dfset option\" where \"pcore_dfset d = Some (DFSet {||})\"\ndefinition op_dfset :: \"'a dfset \\ 'a dfset \\ 'a dfset\" where \n \"op_dfset x y \\ case (x,y) of (DFSet x', DFSet y') \\ if x' |\\| y' = {||} then DFSet (x'|\\|y') \n else DFBot | _ \\ DFBot\"\ninstance proof\nshow \"non_expansive (valid_raw::'a dfset \\ sprop)\"\n by (rule non_expansiveI) (auto simp: d_equiv ofe_refl)\nnext\nshow \"non_expansive (pcore::'a dfset \\ 'a dfset option)\"\n by (rule non_expansiveI) (auto simp: d_equiv)\nnext\nshow \"non_expansive2 (op::'a dfset \\ 'a dfset \\ 'a dfset)\"\n by (rule non_expansive2I) (auto simp: d_equiv)\nqed (auto simp: pcore_dfset_def op_dfset_def valid_raw_dfset_def d_equiv split: dfset.splits)\nend\n\ninstance dfset :: (type) dcamera \n by standard (auto simp: valid_def valid_raw_dfset_def split: dfset.splits)\n\ninstantiation dfset :: (type) ucamera begin\ndefinition \\_dfset :: \"'a dfset\" where \"\\_dfset = DFSet {||}\"\ninstance \n by standard (auto simp: valid_def \\_dfset_def valid_raw_dfset_def op_dfset_def pcore_dfset_def \n split:dfset.splits)\nend\n\ninstance dfset :: (type) ducamera ..\nsubsubsection \\ Finite map camera \\\ncontext includes fmap.lifting begin\nlift_definition fmpcore :: \"('a,'b::camera) fmap \\ ('a,'b) fmap option\" is\n \"\\m. Some (\\i. Option.bind (m i) pcore)\"\n by (metis (mono_tags, lifting) bind_eq_None_conv domIff option.pred_inject(2) rev_finite_subset subsetI)\nend\n\nlemma option_op_dom:\"dom (\\i. option_op (f i) (g i)) = dom f \\ dom g\"\n apply auto using option_opE by auto\n\nlemma option_op_finite: \"\\finite (dom f); finite (dom g)\\ \\ (\\i. option_op (f i) (g i)) \\ {m. finite (dom m)}\"\n using option_op_dom by (metis finite_Un mem_Collect_eq)\nlemmas option_op_fmlookup = option_op_finite[OF dom_fmlookup_finite dom_fmlookup_finite]\nlemma upd_dom: \"dom (\\i. if x = i then Some y else fmlookup m2 i) = fmdom' m2 \\ {x}\"\n apply (auto simp: fmlookup_dom'_iff) by (metis domI domIff)\nlemma upd_fin: \"finite (dom (\\i. if x = i then Some y else fmlookup m2 i))\"\n unfolding upd_dom by simp\nlemma drop_dom: \"dom (\\i. if i \\ x then fmlookup m2 i else None) = fmdom' m2 - {x}\"\n apply (auto simp: fmlookup_dom'_iff) apply (meson option.distinct(1)) by (meson domI domIff)\nlemma drop_fin: \"finite (dom (\\i. if i \\ x then fmlookup m2 i else None))\"\n unfolding drop_dom by simp\n\nlemma map_upd_fin: \"m \\ {m. finite (dom m)} \\ (map_upd a b m) \\ {m. finite (dom m)}\"\n by (simp add: map_upd_def)\n\ninstantiation fmap :: (type,camera) camera begin\ncontext includes fmap.lifting begin\nlift_definition valid_raw_fmap :: \"('a, 'b) fmap \\ sprop\" is valid_raw .\nlift_definition pcore_fmap :: \"('a, 'b) fmap \\ ('a, 'b) fmap option\" is pcore\n apply (auto simp: pcore_fun_def comp_def)\n by (metis (mono_tags, lifting) domIff finite_subset option.case(1) option.case(2) pcore_option_def subsetI)\nlift_definition op_fmap :: \"('a, 'b) fmap \\ ('a, 'b) fmap \\ ('a, 'b) fmap\" is \"merge op\"\n using merge_dom by (metis infinite_Un)\nend \ninstance proof \nshow \"non_expansive (valid_raw::('a, 'b) fmap \\ sprop)\"\n apply (rule non_expansiveI)\n by (auto simp: valid_raw_fmap.rep_eq) (simp add: n_equiv_fmap.rep_eq valid_raw_ne)\nnext\nshow \"non_expansive (pcore::('a, 'b) fmap \\ ('a, 'b) fmap option)\"\n apply (rule non_expansiveI)\n apply (auto simp: pcore_fmap_def n_equiv_fmap_def)\n by (smt (verit, ccfv_threshold) camera_props(9) dom_fmlookup_finite eq_onp_same_args \n map_option_eq_Some n_equiv_fmap.abs_eq n_equiv_option_def option.map_disc_iff pcore_fmap.rep_eq)\nnext\nshow \"non_expansive2 (op::('a, 'b) fmap \\ ('a, 'b) fmap \\ ('a, 'b) fmap)\"\n apply (auto simp: op_fmap.rep_eq n_equiv_fmap_def non_expansive2_def)\n using non_expansive2E[OF merge_ne[OF op_non_expansive]] by blast\nnext\nfix a b c :: \"('a,'b) fmap\"\nshow \"a \\ b \\ c = a \\ (b \\ c)\" apply (auto simp: op_fmap_def merge_op)\n by (metis (mono_tags, lifting) Abs_fmap_inverse camera_assoc fmlookup merge_op op_fmap.rep_eq)\nnext\nfix a b :: \"('a,'b) fmap\"\nshow \"a \\ b = b \\ a\"\n by (metis (mono_tags) camera_comm fmlookup_inject merge_op op_fmap.rep_eq)\nnext\nfix a a' :: \"('a,'b) fmap\"\nshow \"pcore a = Some a' \\ a' \\ a = a\"\n by (metis (mono_tags, lifting) DerivedConstructions.op_fmap.rep_eq camera_pcore_id fmlookup_inject \n merge_op option.simps(9) pcore_fmap.rep_eq)\nnext\nfix a a' :: \"('a,'b) fmap\"\nshow \"pcore a = Some a' \\ pcore a' = pcore a\"\n by (smt (verit, del_insts) DerivedConstructions.pcore_fmap.abs_eq camera_pcore_idem \n dom_fmlookup_finite eq_onp_same_args fmlookup_inverse option.simps(9) pcore_fmap.rep_eq)\nnext\nfix a a' b :: \"('a,'b) fmap\"\nassume assms: \"pcore a = Some a'\" \"\\c. b = a \\ c\"\nlet ?b' = \"Abs_fmap (\\x. case pcore (fmlookup b x) of None \\ none | Some x' \\ x')\"\nhave b': \"pcore b = Some ?b'\" by (auto simp: pcore_fmap_def pcore_fun_def comp_def)\nhave fmlookup_op: \"fmlookup (x\\y) i = fmlookup x i \\ fmlookup y i\" for x y i\n by (auto simp: op_fmap.rep_eq merge_op op_fun_def)\nhave \"dom (\\x. case case fmlookup m x of None \\ Some None | Some a \\ Some (pcore a) of None \\ none | Some a \\ a)\n \\ fmdom' m\" for m :: \"('a,'b) fmap\"\n by (auto simp: fmdom'I split: option.splits) \nthen have fin: \"(\\x. case case fmlookup m x of None \\ Some None | Some a \\ Some (pcore a) of None \\ none | Some a \\ a)\n \\ {m. finite (dom m)}\" for m :: \"('a,'b) fmap\"\n by (metis finite_fmdom' mem_Collect_eq rev_finite_subset)\nhave lookup_pcore: \"pcore m = Some m' \\ Some (fmlookup m' i) = pcore (fmlookup m i)\" for m m' i\n apply (cases \"fmlookup m i\"; cases \"fmlookup m' i\")\n by (auto simp: pcore_fmap_def pcore_option_def pcore_fun_def comp_def Abs_fmap_inverse[OF fin] split: option.splits)\nhave fmlookup_pcore: \"fmlookup (the (pcore m)) i = the (pcore (fmlookup m i))\" for m i\n by (metis lookup_pcore option.distinct(1) option.exhaust_sel option.sel option.simps(8) pcore_fmap.rep_eq total_pcore)\nhave lookup_incl:\"(\\m3. m1 = (m2\\m3)) \\ (\\i. incl (fmlookup m2 i) (fmlookup m1 i))\" for m1 m2\napply auto\nusing fmlookup_op incl_def apply blast\nproof (induction m2)\n case fmempty\n then show ?case by (auto simp: op_fmap_def merge_op op_fun_def op_option_def incl_def fmlookup_inverse)\nnext\n case (fmupd x y m2)\n then have \"\\i. \\j. fmlookup m1 i = fmlookup (fmupd x y m2) i \\ j\"\n by (simp add: incl_def)\n then have \"\\i. \\j. fmlookup m1 i = fmlookup m2 i \\ (if i=x then Some y \\ j else j)\"\n using fmupd(2) apply (auto simp: op_option_def) by (metis (full_types))\n then have \"\\i. \\j. fmlookup m1 i = fmlookup m2 i \\ j\" by auto\n with fmupd(1) obtain m3 where m3: \"m1 = (m2 \\ m3)\" by (auto simp: incl_def)\n from fmupd(2,3) have \"\\y. fmlookup m1 x = Some y\"\n apply (auto simp: incl_def) by (metis (mono_tags) ofe_eq_limit option_n_equiv_Some_op)\n then obtain y2 where y2: \"fmlookup m1 x = Some y2\" by blast\n with m3 fmupd(2) have y2': \"fmlookup m3 x = Some y2\" by (simp add: fmlookup_op op_option_def) \n from y2 fmupd(3) have \"\\y3. Some y2 = (Some y\\y3)\"\n apply (auto simp: incl_def) by (metis (full_types))\n then obtain y3 where y3: \"Some y2 = (Some y\\y3)\" by auto\n define m3' where \"m3' = (case y3 of Some y3' \\ fmupd x y3' m3 | None \\ fmdrop x m3)\"\n with y2 y2' y3 m3 fmupd(2) have \"m1 = ((fmupd x y m2)\\ m3')\" \n apply (cases y3) apply (auto simp: op_option_def op_fmap_def merge_op op_fun_def split: option.splits)\n unfolding Abs_fmap_inverse[OF option_op_fmlookup] \n Abs_fmap_inject[OF option_op_fmlookup option_op_finite[OF upd_fin drop_fin]]\n apply auto\n unfolding Abs_fmap_inject[OF option_op_fmlookup option_op_finite[OF upd_fin upd_fin]]\n by force\n then show ?case by auto \n qed\nhave core_mono: \"(\\m3. (the (pcore m1)) = (the (pcore m2) \\ m3))\" if wo_pcore: \"(\\m3. m1 = (m2\\m3))\"\nfor m1 m2 :: \"('a,'b) fmap\"\n apply (auto simp: lookup_incl fmlookup_pcore) using camera_core_mono wo_pcore[unfolded lookup_incl]\n core_def by (simp add: pcore_mono total_pcore)\nfrom this[OF assms(2)] assms(1) show \"\\b'. pcore b = Some b' \\ (\\c. b' = a' \\ c)\" by (simp add: b')\nnext\nfix a b :: \"('a,'b) fmap\" and n\nshow \"Rep_sprop (valid_raw (a \\ b)) n \\ Rep_sprop (valid_raw a) n\"\n including fmap.lifting apply transfer unfolding merge_op using camera_valid_op by blast\nnext\nfix a b1 b2 :: \"('a,'b) fmap\" and n\nassume assms: \"Rep_sprop (valid_raw a) n\" \"n_equiv n a (b1 \\ b2)\" \nthen show \"\\c1 c2. a = c1 \\ c2 \\ n_equiv n c1 b1 \\ n_equiv n c2 b2\"\nproof (induction a arbitrary: b1 b2)\n case fmempty\n then have \"\\i. n_equiv n None (fmlookup b1 i \\ fmlookup b2 i)\"\n by (auto simp: n_equiv_fmap_def op_fmap.rep_eq merge_op n_equiv_fun_def op_fun_def)\n then have \"b1 = fmempty \\ b2 = fmempty\" apply (auto simp: n_equiv_option_def op_option_def)\n using option_opE by (metis fmap_ext fmempty_lookup)+\n then have \"fmempty = b1 \\ b2 \\ n_equiv n b1 b1 \\ n_equiv n b2 b2\"\n apply (auto simp: ofe_refl op_fmap_def merge_op op_fun_def op_option_def) \n by (simp add: fmempty_def)\n then show ?case by auto\nnext\n case (fmupd x y a)\n from fmupd(2,3) have valid_a: \"Rep_sprop (valid_raw a) n\"\n apply (auto simp: valid_raw_fmap.rep_eq valid_raw_fun.rep_eq valid_raw_option_def split: option.splits)\n by (metis option.distinct(1))\n from fmupd(3) have valid_y: \"n_valid y n\"\n apply (auto simp: valid_raw_fmap.rep_eq valid_raw_fun.rep_eq valid_raw_option_def split: option.splits)\n by presburger \n let ?b1x = \"fmlookup b1 x\" let ?b2x = \"fmlookup b2 x\"\n from fmupd(4) have y:\"n_equiv n (Some y) (?b1x \\ ?b2x)\"\n apply (auto simp: n_equiv_fmap_def op_fmap.rep_eq merge_op n_equiv_fun_def op_fun_def) by presburger\n from fmupd(2,4) have equiv_a: \"n_equiv n a (fmdrop x b1 \\ fmdrop x b2)\"\n apply (auto simp: n_equiv_fmap_def op_fmap.rep_eq merge_op n_equiv_fun_def op_fun_def op_option_def ofe_refl)\n by presburger\n from fmupd(1)[OF valid_a this] obtain c1 c2 where c12: \n \"a = c1 \\ c2 \\ n_equiv n c1 (fmdrop x b1) \\ n_equiv n c2 (fmdrop x b2)\" by blast\n { fix i\n from fmupd(3) have validi: \"n_valid (fmlookup (fmupd x y a) i) n\" \n by (auto simp: valid_raw_fmap.rep_eq valid_raw_fun.rep_eq)\n from fmupd(4) have equivi: \"n_equiv n (fmlookup (fmupd x y a) i) (fmlookup b1 i \\ fmlookup b2 i)\"\n by (auto simp: n_equiv_fmap_def op_fmap.rep_eq merge_op n_equiv_fun_def op_fun_def)\n from camera_extend[OF validi equivi] have \"\\c1 c2. fmlookup (fmupd x y a) i = c1 \\ c2 \n \\ n_equiv n c1 (fmlookup b1 i) \\ n_equiv n c2 (fmlookup b2 i)\" .}\n then have \"\\i. \\c1 c2. fmlookup (fmupd x y a) i = c1 \\ c2 \\ n_equiv n c1 (fmlookup b1 i) \n \\ n_equiv n c2 (fmlookup b2 i)\" by blast\n then have \"\\c1 c2. Some y = c1 \\ c2 \\ n_equiv n c1 ?b1x \\ n_equiv n c2 ?b2x\"\n by (metis fmupd_lookup)\n then obtain c1x c2x where c12x: \"Some y = c1x \\ c2x \\ n_equiv n c1x ?b1x \\ n_equiv n c2x?b2x\"\n by auto\n then have cx_none: \"c1x \\ None \\ c2x \\ None\" by (auto simp: op_option_def)\n have eq_onp_op:\n \"eq_onp (\\m. finite (dom m)) (\\i. option_op (fmlookup c1 i) (fmlookup c2 i)) (\\i. option_op (fmlookup c1 i) (fmlookup c2 i))\"\n using option_op_finite by (auto simp: eq_onp_def)\n define c1' where c1': \"c1' \\ (case c1x of Some y' \\ fmupd x y' c1 | None \\ c1)\"\n define c2' where c2': \"c2' \\ (case c2x of Some y' \\ fmupd x y' c2 | None \\ c2)\" \n with c1' c12 cx_none y c12x have \"fmupd x y a = c1' \\ c2' \\ n_equiv n c1' b1 \\ n_equiv n c2' b2\"\n apply (cases c1x; cases c2x) \n apply (auto simp: op_option_def op_fmap_def merge_op op_fun_def split: option.splits)\n unfolding fmupd.abs_eq[OF eq_onp_op] Abs_fmap_inject[OF map_upd_fin[OF option_op_fmlookup] option_op_finite[OF dom_fmlookup_finite upd_fin]]\n subgoal apply (rule ext) by (smt (verit) Abs_fmap_inverse camera_comm eq_onp_def eq_onp_op fmupd(2) fmupd.rep_eq fmupd_lookup mem_Collect_eq op_option_def option_op.simps(2) option_opE)\n subgoal by (metis c12 fmap_ext fmlookup_drop is_none_code(2) is_none_simps(1) n_equiv_option_def)\n subgoal apply (auto simp: n_equiv_fmap_def n_equiv_fun_def) by presburger\n subgoal unfolding Abs_fmap_inject[OF map_upd_fin[OF option_op_fmlookup] option_op_finite[OF upd_fin dom_fmlookup_finite]]\n proof -\n assume \"c1x = Some y\"\n assume \"a = Abs_fmap (\\i. option_op (fmlookup c1 i) (fmlookup c2 i))\"\n then have \"\\a. option_op (if x = a then Some y else fmlookup c1 a) (fmlookup c2 a) = map_upd x y (\\a. option_op (fmlookup c1 a) (fmlookup c2 a)) a\"\n by (smt (z3) Abs_fmap_inverse camera_comm eq_onp_def eq_onp_op fmupd.hyps fmupd.rep_eq fmupd_lookup mem_Collect_eq op_option_def option_opE option_op_none_unit(1))\n then show \"map_upd x y (\\a. option_op (fmlookup c1 a) (fmlookup c2 a)) = (\\a. option_op (if x = a then Some y else fmlookup c1 a) (fmlookup c2 a))\"\n by presburger qed\n subgoal by (smt (verit, del_insts) fmlookup_drop fmupd_lookup n_equiv_fmap.rep_eq n_equiv_fun_def)\n subgoal by (metis (mono_tags, lifting) fmfilter_alt_defs(1) fmfilter_true n_equiv_option_def option.distinct(1)) \n subgoal unfolding Abs_fmap_inject[OF map_upd_fin[OF option_op_fmlookup] option_op_finite[OF upd_fin upd_fin]]\n apply (rule ext) by (smt (verit) Abs_fmap_inverse c12x eq_onp_def eq_onp_op fmupd.rep_eq fmupd_lookup mem_Collect_eq op_option_def)\n subgoal apply (auto simp: n_equiv_fmap_def n_equiv_fun_def) by presburger\n apply (auto simp: n_equiv_fmap_def n_equiv_fun_def) by presburger \n then show ?case by auto\n qed\nqed\nend\n\ninstance fmap :: (type,dcamera) dcamera apply standard\n apply (auto simp: valid_def valid_raw_fmap_def)\n using dcamera_valid_iff by blast\n\nlemma empty_finite: \" \\ \\ {m. finite (dom m)} \"\n by (auto simp: \\_fun_def \\_option_def)\n\ninstantiation fmap :: (type, camera) ucamera begin\ncontext includes fmap.lifting begin\nlift_definition \\_fmap :: \"('a, 'b) fmap\" is \"\\::'a\\'b\" by (auto simp: \\_fun_def \\_option_def)\nend\ninstance apply standard\nby (auto simp: \\_fmap_def valid_def valid_raw_fmap_def op_fmap_def pcore_fmap_def Abs_fmap_inverse[OF empty_finite]\n \\_valid[unfolded valid_def] \\_left_id fmlookup_inverse \\_pcore merge_op)\nend\n\ninstance fmap :: (type, dcamera) ducamera ..\nend","avg_line_length":55.1426256078,"max_line_length":344,"alphanum_fraction":0.7073303354}