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