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