src/CCL/CCL.thy
author wenzelm
Tue Aug 12 21:29:50 2014 +0200 (2014-08-12)
changeset 57920 c1953856cfca
parent 57521 b14c0794f97f
child 58889 5b7a9633cfa8
permissions -rw-r--r--
clarified focus and key handling -- more like SideKick;
avoid resetting input map with its potentially confusion propagation of key events to unrelated components, e.g. main text area or tree scrollbar;
wenzelm@17456
     1
(*  Title:      CCL/CCL.thy
clasohm@1474
     2
    Author:     Martin Coen
clasohm@0
     3
    Copyright   1993  University of Cambridge
clasohm@0
     4
*)
clasohm@0
     5
wenzelm@17456
     6
header {* Classical Computational Logic for Untyped Lambda Calculus
wenzelm@17456
     7
  with reduction to weak head-normal form *}
clasohm@0
     8
wenzelm@17456
     9
theory CCL
wenzelm@17456
    10
imports Gfp
wenzelm@17456
    11
begin
clasohm@0
    12
wenzelm@17456
    13
text {*
wenzelm@17456
    14
  Based on FOL extended with set collection, a primitive higher-order
wenzelm@17456
    15
  logic.  HOL is too strong - descriptions prevent a type of programs
wenzelm@17456
    16
  being defined which contains only executable terms.
wenzelm@17456
    17
*}
clasohm@0
    18
wenzelm@55380
    19
class prog = "term"
wenzelm@36452
    20
default_sort prog
wenzelm@17456
    21
wenzelm@55380
    22
instance "fun" :: (prog, prog) prog ..
wenzelm@17456
    23
wenzelm@17456
    24
typedecl i
wenzelm@55380
    25
instance i :: prog ..
wenzelm@17456
    26
clasohm@0
    27
clasohm@0
    28
consts
clasohm@0
    29
  (*** Evaluation Judgement ***)
wenzelm@24825
    30
  Eval      ::       "[i,i]=>prop"          (infixl "--->" 20)
clasohm@0
    31
clasohm@0
    32
  (*** Bisimulations for pre-order and equality ***)
wenzelm@24825
    33
  po          ::       "['a,'a]=>o"           (infixl "[=" 50)
clasohm@0
    34
clasohm@0
    35
  (*** Term Formers ***)
wenzelm@17456
    36
  true        ::       "i"
wenzelm@17456
    37
  false       ::       "i"
clasohm@0
    38
  pair        ::       "[i,i]=>i"             ("(1<_,/_>)")
clasohm@0
    39
  lambda      ::       "(i=>i)=>i"            (binder "lam " 55)
wenzelm@17456
    40
  "case"      ::       "[i,i,i,[i,i]=>i,(i=>i)=>i]=>i"
wenzelm@24825
    41
  "apply"     ::       "[i,i]=>i"             (infixl "`" 56)
clasohm@0
    42
  bot         ::       "i"
clasohm@0
    43
clasohm@0
    44
  (******* EVALUATION SEMANTICS *******)
clasohm@0
    45
clasohm@0
    46
  (**  This is the evaluation semantics from which the axioms below were derived.  **)
clasohm@0
    47
  (**  It is included here just as an evaluator for FUN and has no influence on    **)
clasohm@0
    48
  (**  inference in the theory CCL.                                                **)
clasohm@0
    49
wenzelm@51307
    50
axiomatization where
wenzelm@51307
    51
  trueV:       "true ---> true" and
wenzelm@51307
    52
  falseV:      "false ---> false" and
wenzelm@51307
    53
  pairV:       "<a,b> ---> <a,b>" and
wenzelm@51307
    54
  lamV:        "\<And>b. lam x. b(x) ---> lam x. b(x)" and
wenzelm@51307
    55
wenzelm@51307
    56
  caseVtrue:   "[| t ---> true;  d ---> c |] ==> case(t,d,e,f,g) ---> c" and
wenzelm@51307
    57
  caseVfalse:  "[| t ---> false;  e ---> c |] ==> case(t,d,e,f,g) ---> c" and
wenzelm@51307
    58
  caseVpair:   "[| t ---> <a,b>;  f(a,b) ---> c |] ==> case(t,d,e,f,g) ---> c" and
wenzelm@51307
    59
  caseVlam:    "\<And>b. [| t ---> lam x. b(x);  g(b) ---> c |] ==> case(t,d,e,f,g) ---> c"
clasohm@0
    60
clasohm@0
    61
  (*** Properties of evaluation: note that "t ---> c" impies that c is canonical ***)
clasohm@0
    62
wenzelm@51307
    63
axiomatization where
wenzelm@17456
    64
  canonical:  "[| t ---> c; c==true ==> u--->v;
wenzelm@17456
    65
                          c==false ==> u--->v;
wenzelm@17456
    66
                    !!a b. c==<a,b> ==> u--->v;
wenzelm@17456
    67
                      !!f. c==lam x. f(x) ==> u--->v |] ==>
clasohm@1149
    68
             u--->v"
clasohm@0
    69
clasohm@0
    70
  (* Should be derivable - but probably a bitch! *)
wenzelm@51307
    71
axiomatization where
wenzelm@17456
    72
  substitute: "[| a==a'; t(a)--->c(a) |] ==> t(a')--->c(a')"
clasohm@0
    73
clasohm@0
    74
  (************** LOGIC ***************)
clasohm@0
    75
clasohm@0
    76
  (*** Definitions used in the following rules ***)
clasohm@0
    77
wenzelm@51307
    78
axiomatization where
wenzelm@51307
    79
  bot_def:         "bot == (lam x. x`x)`(lam x. x`x)" and
wenzelm@17456
    80
  apply_def:     "f ` t == case(f,bot,bot,%x y. bot,%u. u(t))"
wenzelm@42156
    81
wenzelm@57521
    82
definition "fix" :: "(i=>i)=>i"
wenzelm@57521
    83
  where "fix(f) == (lam x. f(x`x))`(lam x. f(x`x))"
clasohm@0
    84
clasohm@0
    85
  (*  The pre-order ([=) is defined as a simulation, and behavioural equivalence (=) *)
clasohm@0
    86
  (*  as a bisimulation.  They can both be expressed as (bi)simulations up to        *)
clasohm@0
    87
  (*  behavioural equivalence (ie the relations PO and EQ defined below).            *)
clasohm@0
    88
wenzelm@57521
    89
definition SIM :: "[i,i,i set]=>o"
wenzelm@57521
    90
  where
wenzelm@17456
    91
  "SIM(t,t',R) ==  (t=true & t'=true) | (t=false & t'=false) |
wenzelm@17456
    92
                  (EX a a' b b'. t=<a,b> & t'=<a',b'> & <a,a'> : R & <b,b'> : R) |
wenzelm@3837
    93
                  (EX f f'. t=lam x. f(x) & t'=lam x. f'(x) & (ALL x.<f(x),f'(x)> : R))"
clasohm@0
    94
wenzelm@57521
    95
definition POgen :: "i set => i set"
wenzelm@57521
    96
  where "POgen(R) == {p. EX t t'. p=<t,t'> & (t = bot | SIM(t,t',R))}"
wenzelm@57521
    97
wenzelm@57521
    98
definition EQgen :: "i set => i set"
wenzelm@57521
    99
  where "EQgen(R) == {p. EX t t'. p=<t,t'> & (t = bot & t' = bot | SIM(t,t',R))}"
clasohm@0
   100
wenzelm@57521
   101
definition PO :: "i set"
wenzelm@57521
   102
  where "PO == gfp(POgen)"
wenzelm@57521
   103
wenzelm@57521
   104
definition EQ :: "i set"
wenzelm@57521
   105
  where "EQ == gfp(EQgen)"
wenzelm@57521
   106
clasohm@0
   107
clasohm@0
   108
  (*** Rules ***)
clasohm@0
   109
clasohm@0
   110
  (** Partial Order **)
clasohm@0
   111
wenzelm@51307
   112
axiomatization where
wenzelm@51307
   113
  po_refl:        "a [= a" and
wenzelm@51307
   114
  po_trans:       "[| a [= b;  b [= c |] ==> a [= c" and
wenzelm@51307
   115
  po_cong:        "a [= b ==> f(a) [= f(b)" and
clasohm@0
   116
clasohm@0
   117
  (* Extend definition of [= to program fragments of higher type *)
wenzelm@17456
   118
  po_abstractn:   "(!!x. f(x) [= g(x)) ==> (%x. f(x)) [= (%x. g(x))"
clasohm@0
   119
clasohm@0
   120
  (** Equality - equivalence axioms inherited from FOL.thy   **)
clasohm@0
   121
  (**          - congruence of "=" is axiomatised implicitly **)
clasohm@0
   122
wenzelm@51307
   123
axiomatization where
wenzelm@17456
   124
  eq_iff:         "t = t' <-> t [= t' & t' [= t"
clasohm@0
   125
clasohm@0
   126
  (** Properties of canonical values given by greatest fixed point definitions **)
wenzelm@17456
   127
wenzelm@51307
   128
axiomatization where
wenzelm@51307
   129
  PO_iff:         "t [= t' <-> <t,t'> : PO" and
wenzelm@17456
   130
  EQ_iff:         "t =  t' <-> <t,t'> : EQ"
clasohm@0
   131
clasohm@0
   132
  (** Behaviour of non-canonical terms (ie case) given by the following beta-rules **)
clasohm@0
   133
wenzelm@51307
   134
axiomatization where
wenzelm@51307
   135
  caseBtrue:            "case(true,d,e,f,g) = d" and
wenzelm@51307
   136
  caseBfalse:          "case(false,d,e,f,g) = e" and
wenzelm@51307
   137
  caseBpair:           "case(<a,b>,d,e,f,g) = f(a,b)" and
wenzelm@51307
   138
  caseBlam:       "\<And>b. case(lam x. b(x),d,e,f,g) = g(b)" and
wenzelm@51307
   139
  caseBbot:              "case(bot,d,e,f,g) = bot"           (* strictness *)
clasohm@0
   140
clasohm@0
   141
  (** The theory is non-trivial **)
wenzelm@51307
   142
axiomatization where
wenzelm@17456
   143
  distinctness:   "~ lam x. b(x) = bot"
clasohm@0
   144
clasohm@0
   145
  (*** Definitions of Termination and Divergence ***)
clasohm@0
   146
wenzelm@57521
   147
definition Dvg :: "i => o"
wenzelm@57521
   148
  where "Dvg(t) == t = bot"
wenzelm@57521
   149
wenzelm@57521
   150
definition Trm :: "i => o"
wenzelm@57521
   151
  where "Trm(t) == ~ Dvg(t)"
clasohm@0
   152
wenzelm@17456
   153
text {*
clasohm@0
   154
Would be interesting to build a similar theory for a typed programming language:
clasohm@0
   155
    ie.     true :: bool,      fix :: ('a=>'a)=>'a  etc......
clasohm@0
   156
clasohm@0
   157
This is starting to look like LCF.
wenzelm@17456
   158
What are the advantages of this approach?
wenzelm@17456
   159
        - less axiomatic
clasohm@0
   160
        - wfd induction / coinduction and fixed point induction available
wenzelm@17456
   161
*}
wenzelm@17456
   162
wenzelm@20140
   163
wenzelm@20140
   164
lemmas ccl_data_defs = apply_def fix_def
wenzelm@32153
   165
wenzelm@32153
   166
declare po_refl [simp]
wenzelm@20140
   167
wenzelm@20140
   168
wenzelm@20140
   169
subsection {* Congruence Rules *}
wenzelm@20140
   170
wenzelm@20140
   171
(*similar to AP_THM in Gordon's HOL*)
wenzelm@20140
   172
lemma fun_cong: "(f::'a=>'b) = g ==> f(x)=g(x)"
wenzelm@20140
   173
  by simp
wenzelm@20140
   174
wenzelm@20140
   175
(*similar to AP_TERM in Gordon's HOL and FOL's subst_context*)
wenzelm@20140
   176
lemma arg_cong: "x=y ==> f(x)=f(y)"
wenzelm@20140
   177
  by simp
wenzelm@20140
   178
wenzelm@20140
   179
lemma abstractn: "(!!x. f(x) = g(x)) ==> f = g"
wenzelm@20140
   180
  apply (simp add: eq_iff)
wenzelm@20140
   181
  apply (blast intro: po_abstractn)
wenzelm@20140
   182
  done
wenzelm@20140
   183
wenzelm@20140
   184
lemmas caseBs = caseBtrue caseBfalse caseBpair caseBlam caseBbot
wenzelm@20140
   185
wenzelm@20140
   186
wenzelm@20140
   187
subsection {* Termination and Divergence *}
wenzelm@20140
   188
wenzelm@20140
   189
lemma Trm_iff: "Trm(t) <-> ~ t = bot"
wenzelm@20140
   190
  by (simp add: Trm_def Dvg_def)
wenzelm@20140
   191
wenzelm@20140
   192
lemma Dvg_iff: "Dvg(t) <-> t = bot"
wenzelm@20140
   193
  by (simp add: Trm_def Dvg_def)
wenzelm@20140
   194
wenzelm@20140
   195
wenzelm@20140
   196
subsection {* Constructors are injective *}
wenzelm@20140
   197
wenzelm@20140
   198
lemma eq_lemma: "[| x=a;  y=b;  x=y |] ==> a=b"
wenzelm@20140
   199
  by simp
wenzelm@20140
   200
wenzelm@20140
   201
ML {*
wenzelm@32154
   202
  fun inj_rl_tac ctxt rews i =
wenzelm@24825
   203
    let
wenzelm@24825
   204
      fun mk_inj_lemmas r = [@{thm arg_cong}] RL [r RS (r RS @{thm eq_lemma})]
wenzelm@32153
   205
      val inj_lemmas = maps mk_inj_lemmas rews
wenzelm@32154
   206
    in
wenzelm@35409
   207
      CHANGED (REPEAT (ares_tac [@{thm iffI}, @{thm allI}, @{thm conjI}] i ORELSE
wenzelm@32154
   208
        eresolve_tac inj_lemmas i ORELSE
wenzelm@51717
   209
        asm_simp_tac (ctxt addsimps rews) i))
wenzelm@32154
   210
    end;
wenzelm@20140
   211
*}
wenzelm@20140
   212
wenzelm@32154
   213
method_setup inj_rl = {*
wenzelm@32154
   214
  Attrib.thms >> (fn rews => fn ctxt => SIMPLE_METHOD' (inj_rl_tac ctxt rews))
wenzelm@42814
   215
*}
wenzelm@32154
   216
wenzelm@32154
   217
lemma ccl_injs:
wenzelm@32154
   218
  "<a,b> = <a',b'> <-> (a=a' & b=b')"
wenzelm@32154
   219
  "!!b b'. (lam x. b(x) = lam x. b'(x)) <-> ((ALL z. b(z)=b'(z)))"
wenzelm@32154
   220
  by (inj_rl caseBs)
wenzelm@20140
   221
wenzelm@20140
   222
wenzelm@20140
   223
lemma pair_inject: "<a,b> = <a',b'> \<Longrightarrow> (a = a' \<Longrightarrow> b = b' \<Longrightarrow> R) \<Longrightarrow> R"
wenzelm@20140
   224
  by (simp add: ccl_injs)
wenzelm@20140
   225
wenzelm@20140
   226
wenzelm@20140
   227
subsection {* Constructors are distinct *}
wenzelm@20140
   228
wenzelm@20140
   229
lemma lem: "t=t' ==> case(t,b,c,d,e) = case(t',b,c,d,e)"
wenzelm@20140
   230
  by simp
wenzelm@20140
   231
wenzelm@20140
   232
ML {*
wenzelm@20140
   233
wenzelm@20140
   234
local
wenzelm@20140
   235
  fun pairs_of f x [] = []
wenzelm@20140
   236
    | pairs_of f x (y::ys) = (f x y) :: (f y x) :: (pairs_of f x ys)
wenzelm@20140
   237
wenzelm@20140
   238
  fun mk_combs ff [] = []
wenzelm@20140
   239
    | mk_combs ff (x::xs) = (pairs_of ff x xs) @ mk_combs ff xs
wenzelm@20140
   240
wenzelm@20140
   241
  (* Doesn't handle binder types correctly *)
wenzelm@20140
   242
  fun saturate thy sy name =
wenzelm@20140
   243
       let fun arg_str 0 a s = s
wenzelm@20140
   244
         | arg_str 1 a s = "(" ^ a ^ "a" ^ s ^ ")"
wenzelm@20140
   245
         | arg_str n a s = arg_str (n-1) a ("," ^ a ^ (chr((ord "a")+n-1)) ^ s)
wenzelm@20140
   246
           val T = Sign.the_const_type thy (Sign.intern_const thy sy);
wenzelm@40844
   247
           val arity = length (binder_types T)
wenzelm@20140
   248
       in sy ^ (arg_str arity name "") end
wenzelm@20140
   249
wenzelm@20140
   250
  fun mk_thm_str thy a b = "~ " ^ (saturate thy a "a") ^ " = " ^ (saturate thy b "b")
wenzelm@20140
   251
wenzelm@39159
   252
  val lemma = @{thm lem};
wenzelm@39159
   253
  val eq_lemma = @{thm eq_lemma};
wenzelm@39159
   254
  val distinctness = @{thm distinctness};
wenzelm@42480
   255
  fun mk_lemma (ra,rb) =
wenzelm@42480
   256
    [lemma] RL [ra RS (rb RS eq_lemma)] RL
wenzelm@42480
   257
    [distinctness RS @{thm notE}, @{thm sym} RS (distinctness RS @{thm notE})]
wenzelm@20140
   258
in
wenzelm@32153
   259
  fun mk_lemmas rls = maps mk_lemma (mk_combs pair rls)
wenzelm@20140
   260
  fun mk_dstnct_rls thy xs = mk_combs (mk_thm_str thy) xs
wenzelm@20140
   261
end
wenzelm@20140
   262
wenzelm@20140
   263
*}
wenzelm@20140
   264
wenzelm@20140
   265
ML {*
wenzelm@20140
   266
wenzelm@32010
   267
val caseB_lemmas = mk_lemmas @{thms caseBs}
wenzelm@20140
   268
wenzelm@20140
   269
val ccl_dstncts =
wenzelm@32175
   270
  let
wenzelm@32175
   271
    fun mk_raw_dstnct_thm rls s =
wenzelm@32175
   272
      Goal.prove_global @{theory} [] [] (Syntax.read_prop_global @{theory} s)
wenzelm@35409
   273
        (fn _=> rtac @{thm notI} 1 THEN eresolve_tac rls 1)
wenzelm@32175
   274
  in map (mk_raw_dstnct_thm caseB_lemmas)
wenzelm@32175
   275
    (mk_dstnct_rls @{theory} ["bot","true","false","pair","lambda"]) end
wenzelm@20140
   276
wenzelm@51670
   277
fun mk_dstnct_thms ctxt defs inj_rls xs =
wenzelm@32175
   278
  let
wenzelm@51670
   279
    val thy = Proof_Context.theory_of ctxt;
wenzelm@32175
   280
    fun mk_dstnct_thm rls s =
wenzelm@51670
   281
      Goal.prove_global thy [] [] (Syntax.read_prop ctxt s)
wenzelm@32175
   282
        (fn _ =>
wenzelm@54742
   283
          rewrite_goals_tac ctxt defs THEN
wenzelm@51717
   284
          simp_tac (ctxt addsimps (rls @ inj_rls)) 1)
wenzelm@32149
   285
  in map (mk_dstnct_thm ccl_dstncts) (mk_dstnct_rls thy xs) end
wenzelm@20140
   286
wenzelm@51670
   287
fun mkall_dstnct_thms ctxt defs i_rls xss = maps (mk_dstnct_thms ctxt defs i_rls) xss
wenzelm@20140
   288
wenzelm@20140
   289
(*** Rewriting and Proving ***)
wenzelm@20140
   290
wenzelm@42480
   291
fun XH_to_I rl = rl RS @{thm iffD2}
wenzelm@42480
   292
fun XH_to_D rl = rl RS @{thm iffD1}
wenzelm@20140
   293
val XH_to_E = make_elim o XH_to_D
wenzelm@20140
   294
val XH_to_Is = map XH_to_I
wenzelm@20140
   295
val XH_to_Ds = map XH_to_D
wenzelm@20140
   296
val XH_to_Es = map XH_to_E;
wenzelm@20140
   297
wenzelm@56199
   298
ML_Thms.bind_thms ("ccl_rews", @{thms caseBs} @ @{thms ccl_injs} @ ccl_dstncts);
wenzelm@56199
   299
ML_Thms.bind_thms ("ccl_dstnctsEs", ccl_dstncts RL [@{thm notE}]);
wenzelm@56199
   300
ML_Thms.bind_thms ("ccl_injDs", XH_to_Ds @{thms ccl_injs});
wenzelm@20140
   301
*}
wenzelm@20140
   302
wenzelm@20140
   303
lemmas [simp] = ccl_rews
wenzelm@20140
   304
  and [elim!] = pair_inject ccl_dstnctsEs
wenzelm@20140
   305
  and [dest!] = ccl_injDs
wenzelm@20140
   306
wenzelm@20140
   307
wenzelm@20140
   308
subsection {* Facts from gfp Definition of @{text "[="} and @{text "="} *}
wenzelm@20140
   309
wenzelm@20140
   310
lemma XHlemma1: "[| A=B;  a:B <-> P |] ==> a:A <-> P"
wenzelm@20140
   311
  by simp
wenzelm@20140
   312
wenzelm@20140
   313
lemma XHlemma2: "(P(t,t') <-> Q) ==> (<t,t'> : {p. EX t t'. p=<t,t'> &  P(t,t')} <-> Q)"
wenzelm@20140
   314
  by blast
wenzelm@20140
   315
wenzelm@20140
   316
wenzelm@20140
   317
subsection {* Pre-Order *}
wenzelm@20140
   318
wenzelm@20140
   319
lemma POgen_mono: "mono(%X. POgen(X))"
wenzelm@20140
   320
  apply (unfold POgen_def SIM_def)
wenzelm@20140
   321
  apply (rule monoI)
wenzelm@20140
   322
  apply blast
wenzelm@20140
   323
  done
wenzelm@20140
   324
wenzelm@20140
   325
lemma POgenXH: 
wenzelm@20140
   326
  "<t,t'> : POgen(R) <-> t= bot | (t=true & t'=true)  | (t=false & t'=false) |  
wenzelm@20140
   327
           (EX a a' b b'. t=<a,b> &  t'=<a',b'>  & <a,a'> : R & <b,b'> : R) |  
wenzelm@20140
   328
           (EX f f'. t=lam x. f(x) &  t'=lam x. f'(x) & (ALL x. <f(x),f'(x)> : R))"
wenzelm@20140
   329
  apply (unfold POgen_def SIM_def)
wenzelm@20140
   330
  apply (rule iff_refl [THEN XHlemma2])
wenzelm@20140
   331
  done
wenzelm@20140
   332
wenzelm@20140
   333
lemma poXH: 
wenzelm@20140
   334
  "t [= t' <-> t=bot | (t=true & t'=true) | (t=false & t'=false) |  
wenzelm@20140
   335
                 (EX a a' b b'. t=<a,b> &  t'=<a',b'>  & a [= a' & b [= b') |  
wenzelm@20140
   336
                 (EX f f'. t=lam x. f(x) &  t'=lam x. f'(x) & (ALL x. f(x) [= f'(x)))"
wenzelm@20140
   337
  apply (simp add: PO_iff del: ex_simps)
wenzelm@20140
   338
  apply (rule POgen_mono
wenzelm@20140
   339
    [THEN PO_def [THEN def_gfp_Tarski], THEN XHlemma1, unfolded POgen_def SIM_def])
wenzelm@20140
   340
  apply (rule iff_refl [THEN XHlemma2])
wenzelm@20140
   341
  done
wenzelm@20140
   342
wenzelm@20140
   343
lemma po_bot: "bot [= b"
wenzelm@20140
   344
  apply (rule poXH [THEN iffD2])
wenzelm@20140
   345
  apply simp
wenzelm@20140
   346
  done
wenzelm@20140
   347
wenzelm@20140
   348
lemma bot_poleast: "a [= bot ==> a=bot"
wenzelm@20140
   349
  apply (drule poXH [THEN iffD1])
wenzelm@20140
   350
  apply simp
wenzelm@20140
   351
  done
wenzelm@20140
   352
wenzelm@20140
   353
lemma po_pair: "<a,b> [= <a',b'> <->  a [= a' & b [= b'"
wenzelm@20140
   354
  apply (rule poXH [THEN iff_trans])
wenzelm@20140
   355
  apply simp
wenzelm@20140
   356
  done
wenzelm@20140
   357
wenzelm@20140
   358
lemma po_lam: "lam x. f(x) [= lam x. f'(x) <-> (ALL x. f(x) [= f'(x))"
wenzelm@20140
   359
  apply (rule poXH [THEN iff_trans])
wenzelm@47966
   360
  apply fastforce
wenzelm@20140
   361
  done
wenzelm@20140
   362
wenzelm@20140
   363
lemmas ccl_porews = po_bot po_pair po_lam
wenzelm@20140
   364
wenzelm@20140
   365
lemma case_pocong:
wenzelm@20140
   366
  assumes 1: "t [= t'"
wenzelm@20140
   367
    and 2: "a [= a'"
wenzelm@20140
   368
    and 3: "b [= b'"
wenzelm@20140
   369
    and 4: "!!x y. c(x,y) [= c'(x,y)"
wenzelm@20140
   370
    and 5: "!!u. d(u) [= d'(u)"
wenzelm@20140
   371
  shows "case(t,a,b,c,d) [= case(t',a',b',c',d')"
wenzelm@20140
   372
  apply (rule 1 [THEN po_cong, THEN po_trans])
wenzelm@20140
   373
  apply (rule 2 [THEN po_cong, THEN po_trans])
wenzelm@20140
   374
  apply (rule 3 [THEN po_cong, THEN po_trans])
wenzelm@20140
   375
  apply (rule 4 [THEN po_abstractn, THEN po_abstractn, THEN po_cong, THEN po_trans])
wenzelm@20140
   376
  apply (rule_tac f1 = "%d. case (t',a',b',c',d)" in
wenzelm@20140
   377
    5 [THEN po_abstractn, THEN po_cong, THEN po_trans])
wenzelm@20140
   378
  apply (rule po_refl)
wenzelm@20140
   379
  done
wenzelm@20140
   380
wenzelm@20140
   381
lemma apply_pocong: "[| f [= f';  a [= a' |] ==> f ` a [= f' ` a'"
wenzelm@20140
   382
  unfolding ccl_data_defs
wenzelm@20140
   383
  apply (rule case_pocong, (rule po_refl | assumption)+)
wenzelm@20140
   384
  apply (erule po_cong)
wenzelm@20140
   385
  done
wenzelm@20140
   386
wenzelm@20140
   387
lemma npo_lam_bot: "~ lam x. b(x) [= bot"
wenzelm@20140
   388
  apply (rule notI)
wenzelm@20140
   389
  apply (drule bot_poleast)
wenzelm@20140
   390
  apply (erule distinctness [THEN notE])
wenzelm@20140
   391
  done
wenzelm@20140
   392
wenzelm@20140
   393
lemma po_lemma: "[| x=a;  y=b;  x[=y |] ==> a[=b"
wenzelm@20140
   394
  by simp
wenzelm@20140
   395
wenzelm@20140
   396
lemma npo_pair_lam: "~ <a,b> [= lam x. f(x)"
wenzelm@20140
   397
  apply (rule notI)
wenzelm@20140
   398
  apply (rule npo_lam_bot [THEN notE])
wenzelm@20140
   399
  apply (erule case_pocong [THEN caseBlam [THEN caseBpair [THEN po_lemma]]])
wenzelm@20140
   400
  apply (rule po_refl npo_lam_bot)+
wenzelm@20140
   401
  done
wenzelm@20140
   402
wenzelm@20140
   403
lemma npo_lam_pair: "~ lam x. f(x) [= <a,b>"
wenzelm@20140
   404
  apply (rule notI)
wenzelm@20140
   405
  apply (rule npo_lam_bot [THEN notE])
wenzelm@20140
   406
  apply (erule case_pocong [THEN caseBpair [THEN caseBlam [THEN po_lemma]]])
wenzelm@20140
   407
  apply (rule po_refl npo_lam_bot)+
wenzelm@20140
   408
  done
wenzelm@20140
   409
wenzelm@32153
   410
lemma npo_rls1:
wenzelm@32153
   411
  "~ true [= false"
wenzelm@32153
   412
  "~ false [= true"
wenzelm@32153
   413
  "~ true [= <a,b>"
wenzelm@32153
   414
  "~ <a,b> [= true"
wenzelm@32153
   415
  "~ true [= lam x. f(x)"
wenzelm@32153
   416
  "~ lam x. f(x) [= true"
wenzelm@32153
   417
  "~ false [= <a,b>"
wenzelm@32153
   418
  "~ <a,b> [= false"
wenzelm@32153
   419
  "~ false [= lam x. f(x)"
wenzelm@32153
   420
  "~ lam x. f(x) [= false"
wenzelm@32153
   421
  by (tactic {*
wenzelm@35409
   422
    REPEAT (rtac @{thm notI} 1 THEN
wenzelm@32153
   423
      dtac @{thm case_pocong} 1 THEN
wenzelm@35409
   424
      etac @{thm rev_mp} 5 THEN
wenzelm@51717
   425
      ALLGOALS (simp_tac @{context}) THEN
wenzelm@32153
   426
      REPEAT (resolve_tac [@{thm po_refl}, @{thm npo_lam_bot}] 1)) *})
wenzelm@20140
   427
wenzelm@32153
   428
lemmas npo_rls = npo_pair_lam npo_lam_pair npo_rls1
wenzelm@20140
   429
wenzelm@20140
   430
wenzelm@20140
   431
subsection {* Coinduction for @{text "[="} *}
wenzelm@20140
   432
wenzelm@20140
   433
lemma po_coinduct: "[|  <t,u> : R;  R <= POgen(R) |] ==> t [= u"
wenzelm@20140
   434
  apply (rule PO_def [THEN def_coinduct, THEN PO_iff [THEN iffD2]])
wenzelm@20140
   435
   apply assumption+
wenzelm@20140
   436
  done
wenzelm@20140
   437
wenzelm@20140
   438
wenzelm@20140
   439
subsection {* Equality *}
wenzelm@20140
   440
wenzelm@20140
   441
lemma EQgen_mono: "mono(%X. EQgen(X))"
wenzelm@20140
   442
  apply (unfold EQgen_def SIM_def)
wenzelm@20140
   443
  apply (rule monoI)
wenzelm@20140
   444
  apply blast
wenzelm@20140
   445
  done
wenzelm@20140
   446
wenzelm@20140
   447
lemma EQgenXH: 
wenzelm@20140
   448
  "<t,t'> : EQgen(R) <-> (t=bot & t'=bot)  | (t=true & t'=true)  |  
wenzelm@20140
   449
                                             (t=false & t'=false) |  
wenzelm@20140
   450
                 (EX a a' b b'. t=<a,b> &  t'=<a',b'>  & <a,a'> : R & <b,b'> : R) |  
wenzelm@20140
   451
                 (EX f f'. t=lam x. f(x) &  t'=lam x. f'(x) & (ALL x.<f(x),f'(x)> : R))"
wenzelm@20140
   452
  apply (unfold EQgen_def SIM_def)
wenzelm@20140
   453
  apply (rule iff_refl [THEN XHlemma2])
wenzelm@20140
   454
  done
wenzelm@20140
   455
wenzelm@20140
   456
lemma eqXH: 
wenzelm@20140
   457
  "t=t' <-> (t=bot & t'=bot)  | (t=true & t'=true)  | (t=false & t'=false) |  
wenzelm@20140
   458
                     (EX a a' b b'. t=<a,b> &  t'=<a',b'>  & a=a' & b=b') |  
wenzelm@20140
   459
                     (EX f f'. t=lam x. f(x) &  t'=lam x. f'(x) & (ALL x. f(x)=f'(x)))"
wenzelm@20140
   460
  apply (subgoal_tac "<t,t'> : EQ <-> (t=bot & t'=bot) | (t=true & t'=true) | (t=false & t'=false) | (EX a a' b b'. t=<a,b> & t'=<a',b'> & <a,a'> : EQ & <b,b'> : EQ) | (EX f f'. t=lam x. f (x) & t'=lam x. f' (x) & (ALL x. <f (x) ,f' (x) > : EQ))")
wenzelm@20140
   461
  apply (erule rev_mp)
wenzelm@20140
   462
  apply (simp add: EQ_iff [THEN iff_sym])
wenzelm@20140
   463
  apply (rule EQgen_mono [THEN EQ_def [THEN def_gfp_Tarski], THEN XHlemma1,
wenzelm@20140
   464
    unfolded EQgen_def SIM_def])
wenzelm@20140
   465
  apply (rule iff_refl [THEN XHlemma2])
wenzelm@20140
   466
  done
wenzelm@20140
   467
wenzelm@20140
   468
lemma eq_coinduct: "[|  <t,u> : R;  R <= EQgen(R) |] ==> t = u"
wenzelm@20140
   469
  apply (rule EQ_def [THEN def_coinduct, THEN EQ_iff [THEN iffD2]])
wenzelm@20140
   470
   apply assumption+
wenzelm@20140
   471
  done
wenzelm@20140
   472
wenzelm@20140
   473
lemma eq_coinduct3:
wenzelm@20140
   474
  "[|  <t,u> : R;  R <= EQgen(lfp(%x. EQgen(x) Un R Un EQ)) |] ==> t = u"
wenzelm@20140
   475
  apply (rule EQ_def [THEN def_coinduct3, THEN EQ_iff [THEN iffD2]])
wenzelm@20140
   476
  apply (rule EQgen_mono | assumption)+
wenzelm@20140
   477
  done
wenzelm@20140
   478
wenzelm@20140
   479
ML {*
wenzelm@27239
   480
  fun eq_coinduct_tac ctxt s i = res_inst_tac ctxt [(("R", 0), s)] @{thm eq_coinduct} i
wenzelm@27239
   481
  fun eq_coinduct3_tac ctxt s i = res_inst_tac ctxt [(("R", 0), s)] @{thm eq_coinduct3} i
wenzelm@20140
   482
*}
wenzelm@20140
   483
wenzelm@20140
   484
wenzelm@20140
   485
subsection {* Untyped Case Analysis and Other Facts *}
wenzelm@20140
   486
wenzelm@20140
   487
lemma cond_eta: "(EX f. t=lam x. f(x)) ==> t = lam x.(t ` x)"
wenzelm@20140
   488
  by (auto simp: apply_def)
wenzelm@20140
   489
wenzelm@20140
   490
lemma exhaustion: "(t=bot) | (t=true) | (t=false) | (EX a b. t=<a,b>) | (EX f. t=lam x. f(x))"
wenzelm@20140
   491
  apply (cut_tac refl [THEN eqXH [THEN iffD1]])
wenzelm@20140
   492
  apply blast
wenzelm@20140
   493
  done
wenzelm@20140
   494
wenzelm@20140
   495
lemma term_case:
wenzelm@20140
   496
  "[| P(bot);  P(true);  P(false);  !!x y. P(<x,y>);  !!b. P(lam x. b(x)) |] ==> P(t)"
wenzelm@20140
   497
  using exhaustion [of t] by blast
wenzelm@17456
   498
wenzelm@17456
   499
end