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