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