src/HOL/Bali/Basis.thy
author nipkow
Mon Mar 17 18:38:50 2003 +0100 (2003-03-17)
changeset 13867 1fdecd15437f
parent 13688 a0b16d42d489
child 14981 e73f8140af78
permissions -rw-r--r--
just a few mods to a few thms
     1 (*  Title:      HOL/Bali/Basis.thy
     2     ID:         $Id$
     3     Author:     David von Oheimb
     4     License:    GPL (GNU GENERAL PUBLIC LICENSE)
     5 
     6 *)
     7 header {* Definitions extending HOL as logical basis of Bali *}
     8 
     9 theory Basis = Main:
    10 
    11 ML_setup {*
    12 Unify.search_bound := 40;
    13 Unify.trace_bound  := 40;
    14 *}
    15 (*print_depth 100;*)
    16 (*Syntax.ambiguity_level := 1;*)
    17 
    18 section "misc"
    19 
    20 declare same_fstI [intro!] (*### TO HOL/Wellfounded_Relations *)
    21 
    22 ML {*
    23 fun cond_simproc name pat pred thm = Simplifier.simproc (Thm.sign_of_thm thm) name [pat]
    24   (fn _ => fn _ => fn t => if pred t then None else Some (mk_meta_eq thm));
    25 *}
    26 
    27 declare split_if_asm  [split] option.split [split] option.split_asm [split]
    28 ML {*
    29 simpset_ref() := simpset() addloop ("split_all_tac", split_all_tac)
    30 *}
    31 declare if_weak_cong [cong del] option.weak_case_cong [cong del]
    32 declare length_Suc_conv [iff];
    33 
    34 (*###to be phased out *)
    35 ML {*
    36 bind_thm ("make_imp", rearrange_prems [1,0] mp)
    37 *}
    38 
    39 lemma Collect_split_eq: "{p. P (split f p)} = {(a,b). P (f a b)}"
    40 apply auto
    41 done
    42 
    43 lemma subset_insertD: 
    44   "A <= insert x B ==> A <= B & x ~: A | (EX B'. A = insert x B' & B' <= B)"
    45 apply (case_tac "x:A")
    46 apply (rule disjI2)
    47 apply (rule_tac x = "A-{x}" in exI)
    48 apply fast+
    49 done
    50 
    51 syntax
    52   "3" :: nat   ("3") 
    53   "4" :: nat   ("4")
    54 translations
    55  "3" == "Suc 2"
    56  "4" == "Suc 3"
    57 
    58 (*unused*)
    59 lemma range_bool_domain: "range f = {f True, f False}"
    60 apply auto
    61 apply (case_tac "xa")
    62 apply auto
    63 done
    64 
    65 (* irrefl_tranclI in Transitive_Closure.thy is more general *)
    66 lemma irrefl_tranclI': "r^-1 Int r^+ = {} ==> !x. (x, x) ~: r^+"
    67 by(blast elim: tranclE dest: trancl_into_rtrancl)
    68 
    69 
    70 lemma trancl_rtrancl_trancl:
    71 "\<lbrakk>(x,y)\<in>r^+; (y,z)\<in>r^*\<rbrakk> \<Longrightarrow> (x,z)\<in>r^+"
    72 by (auto dest: tranclD rtrancl_trans rtrancl_into_trancl2)
    73 
    74 lemma rtrancl_into_trancl3:
    75 "\<lbrakk>(a,b)\<in>r^*; a\<noteq>b\<rbrakk> \<Longrightarrow> (a,b)\<in>r^+" 
    76 apply (drule rtranclD)
    77 apply auto
    78 done
    79 
    80 lemma rtrancl_into_rtrancl2: 
    81   "\<lbrakk> (a, b) \<in>  r; (b, c) \<in> r^* \<rbrakk> \<Longrightarrow> (a, c) \<in>  r^*"
    82 by (auto intro: r_into_rtrancl rtrancl_trans)
    83 
    84 lemma triangle_lemma:
    85  "\<lbrakk> \<And> a b c. \<lbrakk>(a,b)\<in>r; (a,c)\<in>r\<rbrakk> \<Longrightarrow> b=c; (a,x)\<in>r\<^sup>*; (a,y)\<in>r\<^sup>*\<rbrakk> 
    86  \<Longrightarrow> (x,y)\<in>r\<^sup>* \<or> (y,x)\<in>r\<^sup>*"
    87 proof -
    88   note converse_rtrancl_induct = converse_rtrancl_induct [consumes 1]
    89   note converse_rtranclE = converse_rtranclE [consumes 1] 
    90   assume unique: "\<And> a b c. \<lbrakk>(a,b)\<in>r; (a,c)\<in>r\<rbrakk> \<Longrightarrow> b=c"
    91   assume "(a,x)\<in>r\<^sup>*" 
    92   then show "(a,y)\<in>r\<^sup>* \<Longrightarrow> (x,y)\<in>r\<^sup>* \<or> (y,x)\<in>r\<^sup>*"
    93   proof (induct rule: converse_rtrancl_induct)
    94     assume "(x,y)\<in>r\<^sup>*"
    95     then show ?thesis 
    96       by blast
    97   next
    98     fix a v
    99     assume a_v_r: "(a, v) \<in> r" and
   100           v_x_rt: "(v, x) \<in> r\<^sup>*" and
   101           a_y_rt: "(a, y) \<in> r\<^sup>*"  and
   102              hyp: "(v, y) \<in> r\<^sup>* \<Longrightarrow> (x, y) \<in> r\<^sup>* \<or> (y, x) \<in> r\<^sup>*"
   103     from a_y_rt 
   104     show "(x, y) \<in> r\<^sup>* \<or> (y, x) \<in> r\<^sup>*"
   105     proof (cases rule: converse_rtranclE)
   106       assume "a=y"
   107       with a_v_r v_x_rt have "(y,x) \<in> r\<^sup>*"
   108 	by (auto intro: r_into_rtrancl rtrancl_trans)
   109       then show ?thesis 
   110 	by blast
   111     next
   112       fix w 
   113       assume a_w_r: "(a, w) \<in> r" and
   114             w_y_rt: "(w, y) \<in> r\<^sup>*"
   115       from a_v_r a_w_r unique 
   116       have "v=w" 
   117 	by auto
   118       with w_y_rt hyp 
   119       show ?thesis
   120 	by blast
   121     qed
   122   qed
   123 qed
   124 
   125 
   126 lemma rtrancl_cases [consumes 1, case_names Refl Trancl]:
   127  "\<lbrakk>(a,b)\<in>r\<^sup>*;  a = b \<Longrightarrow> P; (a,b)\<in>r\<^sup>+ \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
   128 apply (erule rtranclE)
   129 apply (auto dest: rtrancl_into_trancl1)
   130 done
   131 
   132 (* ### To Transitive_Closure *)
   133 theorems converse_rtrancl_induct 
   134  = converse_rtrancl_induct [consumes 1,case_names Id Step]
   135 
   136 theorems converse_trancl_induct 
   137          = converse_trancl_induct [consumes 1,case_names Single Step]
   138 
   139 (* context (theory "Set") *)
   140 lemma Ball_weaken:"\<lbrakk>Ball s P;\<And> x. P x\<longrightarrow>Q x\<rbrakk>\<Longrightarrow>Ball s Q"
   141 by auto
   142 
   143 (* context (theory "Finite") *)
   144 lemma finite_SetCompr2: "[| finite (Collect P); !y. P y --> finite (range (f y)) |] ==>  
   145   finite {f y x |x y. P y}"
   146 apply (subgoal_tac "{f y x |x y. P y} = UNION (Collect P) (%y. range (f y))")
   147 prefer 2 apply  fast
   148 apply (erule ssubst)
   149 apply (erule finite_UN_I)
   150 apply fast
   151 done
   152 
   153 
   154 (* ### TO theory "List" *)
   155 lemma list_all2_trans: "\<forall> a b c. P1 a b \<longrightarrow> P2 b c \<longrightarrow> P3 a c \<Longrightarrow>
   156  \<forall>xs2 xs3. list_all2 P1 xs1 xs2 \<longrightarrow> list_all2 P2 xs2 xs3 \<longrightarrow> list_all2 P3 xs1 xs3"
   157 apply (induct_tac "xs1")
   158 apply simp
   159 apply (rule allI)
   160 apply (induct_tac "xs2")
   161 apply simp
   162 apply (rule allI)
   163 apply (induct_tac "xs3")
   164 apply auto
   165 done
   166 
   167 
   168 section "pairs"
   169 
   170 lemma surjective_pairing5: "p = (fst p, fst (snd p), fst (snd (snd p)), fst (snd (snd (snd p))), 
   171   snd (snd (snd (snd p))))"
   172 apply auto
   173 done
   174 
   175 lemma fst_splitE [elim!]: 
   176 "[| fst s' = x';  !!x s. [| s' = (x,s);  x = x' |] ==> Q |] ==> Q"
   177 apply (cut_tac p = "s'" in surjective_pairing)
   178 apply auto
   179 done
   180 
   181 lemma fst_in_set_lemma [rule_format (no_asm)]: "(x, y) : set l --> x : fst ` set l"
   182 apply (induct_tac "l")
   183 apply  auto
   184 done
   185 
   186 
   187 section "quantifiers"
   188 
   189 (*###to be phased out *)
   190 ML {* 
   191 fun noAll_simpset () = simpset() setmksimps 
   192 	mksimps (filter (fn (x,_) => x<>"All") mksimps_pairs)
   193 *}
   194 
   195 lemma All_Ex_refl_eq2 [simp]: 
   196  "(!x. (? b. x = f b & Q b) \<longrightarrow> P x) = (!b. Q b --> P (f b))"
   197 apply auto
   198 done
   199 
   200 lemma ex_ex_miniscope1 [simp]:
   201   "(EX w v. P w v & Q v) = (EX v. (EX w. P w v) & Q v)"
   202 apply auto
   203 done
   204 
   205 lemma ex_miniscope2 [simp]:
   206   "(EX v. P v & Q & R v) = (Q & (EX v. P v & R v))" 
   207 apply auto
   208 done
   209 
   210 lemma ex_reorder31: "(\<exists>z x y. P x y z) = (\<exists>x y z. P x y z)"
   211 apply auto
   212 done
   213 
   214 lemma All_Ex_refl_eq1 [simp]: "(!x. (? b. x = f b) --> P x) = (!b. P (f b))"
   215 apply auto
   216 done
   217 
   218 
   219 section "sums"
   220 
   221 hide const In0 In1
   222 
   223 syntax
   224   fun_sum :: "('a => 'c) => ('b => 'c) => (('a+'b) => 'c)" (infixr "'(+')"80)
   225 translations
   226  "fun_sum" == "sum_case"
   227 
   228 consts    the_Inl  :: "'a + 'b \<Rightarrow> 'a"
   229           the_Inr  :: "'a + 'b \<Rightarrow> 'b"
   230 primrec  "the_Inl (Inl a) = a"
   231 primrec  "the_Inr (Inr b) = b"
   232 
   233 datatype ('a, 'b, 'c) sum3 = In1 'a | In2 'b | In3 'c
   234 
   235 consts    the_In1  :: "('a, 'b, 'c) sum3 \<Rightarrow> 'a"
   236           the_In2  :: "('a, 'b, 'c) sum3 \<Rightarrow> 'b"
   237           the_In3  :: "('a, 'b, 'c) sum3 \<Rightarrow> 'c"
   238 primrec  "the_In1 (In1 a) = a"
   239 primrec  "the_In2 (In2 b) = b"
   240 primrec  "the_In3 (In3 c) = c"
   241 
   242 syntax
   243 	 In1l	:: "'al \<Rightarrow> ('al + 'ar, 'b, 'c) sum3"
   244 	 In1r	:: "'ar \<Rightarrow> ('al + 'ar, 'b, 'c) sum3"
   245 translations
   246 	"In1l e" == "In1 (Inl e)"
   247 	"In1r c" == "In1 (Inr c)"
   248 
   249 syntax the_In1l :: "('al + 'ar, 'b, 'c) sum3 \<Rightarrow> 'al"
   250        the_In1r :: "('al + 'ar, 'b, 'c) sum3 \<Rightarrow> 'ar"
   251 translations
   252    "the_In1l" == "the_Inl \<circ> the_In1"
   253    "the_In1r" == "the_Inr \<circ> the_In1"
   254 
   255 ML {*
   256 fun sum3_instantiate thm = map (fn s => simplify(simpset()delsimps[not_None_eq])
   257  (read_instantiate [("t","In"^s^" ?x")] thm)) ["1l","2","3","1r"]
   258 *}
   259 (* e.g. lemmas is_stmt_rews = is_stmt_def [of "In1l x", simplified] *)
   260 
   261 translations
   262   "option"<= (type) "Datatype.option"
   263   "list"  <= (type) "List.list"
   264   "sum3"  <= (type) "Basis.sum3"
   265 
   266 
   267 section "quantifiers for option type"
   268 
   269 syntax
   270   Oall :: "[pttrn, 'a option, bool] => bool"   ("(3! _:_:/ _)" [0,0,10] 10)
   271   Oex  :: "[pttrn, 'a option, bool] => bool"   ("(3? _:_:/ _)" [0,0,10] 10)
   272 
   273 syntax (symbols)
   274   Oall :: "[pttrn, 'a option, bool] => bool"   ("(3\<forall>_\<in>_:/ _)"  [0,0,10] 10)
   275   Oex  :: "[pttrn, 'a option, bool] => bool"   ("(3\<exists>_\<in>_:/ _)"  [0,0,10] 10)
   276 
   277 translations
   278   "! x:A: P"    == "! x:o2s A. P"
   279   "? x:A: P"    == "? x:o2s A. P"
   280 
   281 
   282 section "unique association lists"
   283 
   284 constdefs
   285   unique   :: "('a \<times> 'b) list \<Rightarrow> bool"
   286  "unique \<equiv> distinct \<circ> map fst"
   287 
   288 lemma uniqueD [rule_format (no_asm)]: 
   289 "unique l--> (!x y. (x,y):set l --> (!x' y'. (x',y'):set l --> x=x'-->  y=y'))"
   290 apply (unfold unique_def o_def)
   291 apply (induct_tac "l")
   292 apply  (auto dest: fst_in_set_lemma)
   293 done
   294 
   295 lemma unique_Nil [simp]: "unique []"
   296 apply (unfold unique_def)
   297 apply (simp (no_asm))
   298 done
   299 
   300 lemma unique_Cons [simp]: "unique ((x,y)#l) = (unique l & (!y. (x,y) ~: set l))"
   301 apply (unfold unique_def)
   302 apply  (auto dest: fst_in_set_lemma)
   303 done
   304 
   305 lemmas unique_ConsI = conjI [THEN unique_Cons [THEN iffD2], standard]
   306 
   307 lemma unique_single [simp]: "!!p. unique [p]"
   308 apply auto
   309 done
   310 
   311 lemma unique_ConsD: "unique (x#xs) ==> unique xs"
   312 apply (simp add: unique_def)
   313 done
   314 
   315 lemma unique_append [rule_format (no_asm)]: "unique l' ==> unique l -->  
   316   (!(x,y):set l. !(x',y'):set l'. x' ~= x) --> unique (l @ l')"
   317 apply (induct_tac "l")
   318 apply  (auto dest: fst_in_set_lemma)
   319 done
   320 
   321 lemma unique_map_inj [rule_format (no_asm)]: "unique l --> inj f --> unique (map (%(k,x). (f k, g k x)) l)"
   322 apply (induct_tac "l")
   323 apply  (auto dest: fst_in_set_lemma simp add: inj_eq)
   324 done
   325 
   326 lemma map_of_SomeI [rule_format (no_asm)]: "unique l --> (k, x) : set l --> map_of l k = Some x"
   327 apply (induct_tac "l")
   328 apply auto
   329 done
   330 
   331 
   332 section "list patterns"
   333 
   334 consts
   335   lsplit         :: "[['a, 'a list] => 'b, 'a list] => 'b"
   336 defs
   337   lsplit_def:    "lsplit == %f l. f (hd l) (tl l)"
   338 (*  list patterns -- extends pre-defined type "pttrn" used in abstractions *)
   339 syntax
   340   "_lpttrn"    :: "[pttrn,pttrn] => pttrn"     ("_#/_" [901,900] 900)
   341 translations
   342   "%y#x#xs. b"  == "lsplit (%y x#xs. b)"
   343   "%x#xs  . b"  == "lsplit (%x xs  . b)"
   344 
   345 lemma lsplit [simp]: "lsplit c (x#xs) = c x xs"
   346 apply (unfold lsplit_def)
   347 apply (simp (no_asm))
   348 done
   349 
   350 lemma lsplit2 [simp]: "lsplit P (x#xs) y z = P x xs y z"
   351 apply (unfold lsplit_def)
   352 apply simp
   353 done 
   354 
   355 
   356 section "dummy pattern for quantifiers, let, etc."
   357 
   358 syntax
   359   "@dummy_pat"   :: pttrn    ("'_")
   360 
   361 parse_translation {*
   362 let fun dummy_pat_tr [] = Free ("_",dummyT)
   363   | dummy_pat_tr ts = raise TERM ("dummy_pat_tr", ts);
   364 in [("@dummy_pat", dummy_pat_tr)] 
   365 end
   366 *}
   367 
   368 end