src/CCL/CCL.thy
author wenzelm
Sat, 14 Jun 2008 23:19:51 +0200
changeset 27208 5fe899199f85
parent 27146 443c19953137
child 27239 f2f42f9fa09d
permissions -rw-r--r--
proper context for tactics derived from res_inst_tac;
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
24825
c4f13ab78f9d avoid unnamed infixes;
wenzelm
parents: 20140
diff changeset
    23
arities "fun" :: (prog, prog) prog
17456
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 ***)
24825
c4f13ab78f9d avoid unnamed infixes;
wenzelm
parents: 20140
diff changeset
    31
  Eval      ::       "[i,i]=>prop"          (infixl "--->" 20)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    32
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    33
  (*** Bisimulations for pre-order and equality ***)
24825
c4f13ab78f9d avoid unnamed infixes;
wenzelm
parents: 20140
diff changeset
    34
  po          ::       "['a,'a]=>o"           (infixl "[=" 50)
0
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"
24825
c4f13ab78f9d avoid unnamed infixes;
wenzelm
parents: 20140
diff changeset
    47
  "apply"     ::       "[i,i]=>i"             (infixl "`" 56)
0
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 {*
24825
c4f13ab78f9d avoid unnamed infixes;
wenzelm
parents: 20140
diff changeset
   191
  fun mk_inj_rl thy rews s =
c4f13ab78f9d avoid unnamed infixes;
wenzelm
parents: 20140
diff changeset
   192
    let
c4f13ab78f9d avoid unnamed infixes;
wenzelm
parents: 20140
diff changeset
   193
      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
   194
      val inj_lemmas = List.concat (map mk_inj_lemmas rews)
c4f13ab78f9d avoid unnamed infixes;
wenzelm
parents: 20140
diff changeset
   195
      val tac = REPEAT (ares_tac [iffI, allI, conjI] 1 ORELSE
c4f13ab78f9d avoid unnamed infixes;
wenzelm
parents: 20140
diff changeset
   196
        eresolve_tac inj_lemmas 1 ORELSE
c4f13ab78f9d avoid unnamed infixes;
wenzelm
parents: 20140
diff changeset
   197
        asm_simp_tac (Simplifier.theory_context thy @{simpset} addsimps rews) 1)
c4f13ab78f9d avoid unnamed infixes;
wenzelm
parents: 20140
diff changeset
   198
    in prove_goal thy s (fn _ => [tac]) end  
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   199
*}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   200
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   201
ML {*
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   202
  bind_thms ("ccl_injs",
24825
c4f13ab78f9d avoid unnamed infixes;
wenzelm
parents: 20140
diff changeset
   203
    map (mk_inj_rl @{theory} @{thms caseBs})
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   204
      ["<a,b> = <a',b'> <-> (a=a' & b=b')",
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   205
       "(lam x. b(x) = lam x. b'(x)) <-> ((ALL z. b(z)=b'(z)))"])
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
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   209
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
   210
  by (simp add: ccl_injs)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   211
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   212
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   213
subsection {* Constructors are distinct *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   214
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   215
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
   216
  by simp
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   217
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   218
ML {*
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   219
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   220
local
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   221
  fun pairs_of f x [] = []
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   222
    | 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
   223
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   224
  fun mk_combs ff [] = []
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   225
    | mk_combs ff (x::xs) = (pairs_of ff x xs) @ mk_combs ff xs
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   226
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   227
  (* Doesn't handle binder types correctly *)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   228
  fun saturate thy sy name =
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   229
       let fun arg_str 0 a s = s
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   230
         | arg_str 1 a s = "(" ^ a ^ "a" ^ s ^ ")"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   231
         | 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
   232
           val T = Sign.the_const_type thy (Sign.intern_const thy sy);
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   233
           val arity = length (fst (strip_type T))
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   234
       in sy ^ (arg_str arity name "") end
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   235
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   236
  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
   237
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   238
  val lemma = thm "lem";
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   239
  val eq_lemma = thm "eq_lemma";
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   240
  val distinctness = thm "distinctness";
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   241
  fun mk_lemma (ra,rb) = [lemma] RL [ra RS (rb RS eq_lemma)] RL
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   242
                           [distinctness RS notE,sym RS (distinctness RS notE)]
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   243
in
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   244
  fun mk_lemmas rls = List.concat (map mk_lemma (mk_combs pair rls))
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   245
  fun mk_dstnct_rls thy xs = mk_combs (mk_thm_str thy) xs
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   246
end
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
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   250
ML {*
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   251
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   252
val caseB_lemmas = mk_lemmas (thms "caseBs")
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   253
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   254
val ccl_dstncts =
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   255
        let fun mk_raw_dstnct_thm rls s =
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   256
                  prove_goal (the_context ()) s (fn _=> [rtac notI 1,eresolve_tac rls 1])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   257
        in map (mk_raw_dstnct_thm caseB_lemmas)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   258
                (mk_dstnct_rls (the_context ()) ["bot","true","false","pair","lambda"]) end
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   259
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   260
fun mk_dstnct_thms thy defs inj_rls xs =
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   261
          let fun mk_dstnct_thm rls s = prove_goalw thy defs s
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   262
                               (fn _ => [simp_tac (simpset_of thy addsimps (rls@inj_rls)) 1])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   263
          in map (mk_dstnct_thm ccl_dstncts) (mk_dstnct_rls thy xs) end
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   264
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   265
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
   266
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   267
(*** Rewriting and Proving ***)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   268
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   269
fun XH_to_I rl = rl RS iffD2
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   270
fun XH_to_D rl = rl RS iffD1
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   271
val XH_to_E = make_elim o XH_to_D
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   272
val XH_to_Is = map XH_to_I
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   273
val XH_to_Ds = map XH_to_D
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   274
val XH_to_Es = map XH_to_E;
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   275
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   276
bind_thms ("ccl_rews", thms "caseBs" @ ccl_injs @ ccl_dstncts);
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   277
bind_thms ("ccl_dstnctsEs", ccl_dstncts RL [notE]);
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   278
bind_thms ("ccl_injDs", XH_to_Ds (thms "ccl_injs"));
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   279
*}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   280
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   281
lemmas [simp] = ccl_rews
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   282
  and [elim!] = pair_inject ccl_dstnctsEs
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   283
  and [dest!] = ccl_injDs
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   284
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   285
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   286
subsection {* Facts from gfp Definition of @{text "[="} and @{text "="} *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   287
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   288
lemma XHlemma1: "[| A=B;  a:B <-> P |] ==> a:A <-> P"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   289
  by simp
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   290
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   291
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
   292
  by blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   293
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   294
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   295
subsection {* Pre-Order *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   296
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   297
lemma POgen_mono: "mono(%X. POgen(X))"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   298
  apply (unfold POgen_def SIM_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   299
  apply (rule monoI)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   300
  apply blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   301
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   302
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   303
lemma POgenXH: 
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   304
  "<t,t'> : POgen(R) <-> t= bot | (t=true & t'=true)  | (t=false & t'=false) |  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   305
           (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
   306
           (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
   307
  apply (unfold POgen_def SIM_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   308
  apply (rule iff_refl [THEN XHlemma2])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   309
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   310
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   311
lemma poXH: 
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   312
  "t [= t' <-> t=bot | (t=true & t'=true) | (t=false & t'=false) |  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   313
                 (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
   314
                 (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
   315
  apply (simp add: PO_iff del: ex_simps)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   316
  apply (rule POgen_mono
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   317
    [THEN PO_def [THEN def_gfp_Tarski], THEN XHlemma1, unfolded POgen_def SIM_def])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   318
  apply (rule iff_refl [THEN XHlemma2])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   319
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   320
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   321
lemma po_bot: "bot [= b"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   322
  apply (rule poXH [THEN iffD2])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   323
  apply simp
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   324
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   325
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   326
lemma bot_poleast: "a [= bot ==> a=bot"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   327
  apply (drule poXH [THEN iffD1])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   328
  apply simp
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   329
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   330
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   331
lemma po_pair: "<a,b> [= <a',b'> <->  a [= a' & b [= b'"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   332
  apply (rule poXH [THEN iff_trans])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   333
  apply simp
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   334
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   335
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   336
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
   337
  apply (rule poXH [THEN iff_trans])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   338
  apply fastsimp
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   339
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   340
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   341
lemmas ccl_porews = po_bot po_pair po_lam
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   342
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   343
lemma case_pocong:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   344
  assumes 1: "t [= t'"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   345
    and 2: "a [= a'"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   346
    and 3: "b [= b'"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   347
    and 4: "!!x y. c(x,y) [= c'(x,y)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   348
    and 5: "!!u. d(u) [= d'(u)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   349
  shows "case(t,a,b,c,d) [= case(t',a',b',c',d')"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   350
  apply (rule 1 [THEN po_cong, THEN po_trans])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   351
  apply (rule 2 [THEN po_cong, THEN po_trans])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   352
  apply (rule 3 [THEN po_cong, THEN po_trans])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   353
  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
   354
  apply (rule_tac f1 = "%d. case (t',a',b',c',d)" in
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   355
    5 [THEN po_abstractn, THEN po_cong, THEN po_trans])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   356
  apply (rule po_refl)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   357
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   358
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   359
lemma apply_pocong: "[| f [= f';  a [= a' |] ==> f ` a [= f' ` a'"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   360
  unfolding ccl_data_defs
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   361
  apply (rule case_pocong, (rule po_refl | assumption)+)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   362
  apply (erule po_cong)
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 npo_lam_bot: "~ lam x. b(x) [= bot"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   366
  apply (rule notI)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   367
  apply (drule bot_poleast)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   368
  apply (erule distinctness [THEN notE])
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 po_lemma: "[| x=a;  y=b;  x[=y |] ==> a[=b"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   372
  by simp
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   373
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   374
lemma npo_pair_lam: "~ <a,b> [= lam x. f(x)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   375
  apply (rule notI)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   376
  apply (rule npo_lam_bot [THEN notE])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   377
  apply (erule case_pocong [THEN caseBlam [THEN caseBpair [THEN po_lemma]]])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   378
  apply (rule po_refl npo_lam_bot)+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   379
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   380
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   381
lemma npo_lam_pair: "~ lam x. f(x) [= <a,b>"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   382
  apply (rule notI)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   383
  apply (rule npo_lam_bot [THEN notE])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   384
  apply (erule case_pocong [THEN caseBpair [THEN caseBlam [THEN po_lemma]]])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   385
  apply (rule po_refl npo_lam_bot)+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   386
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   387
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   388
ML {*
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   389
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   390
local
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   391
  fun mk_thm s = prove_goal (the_context ()) s (fn _ =>
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   392
                          [rtac notI 1,dtac (thm "case_pocong") 1,etac rev_mp 5,
26342
0f65fa163304 more antiquotations;
wenzelm
parents: 24825
diff changeset
   393
                           ALLGOALS (simp_tac @{simpset}),
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   394
                           REPEAT (resolve_tac [thm "po_refl", thm "npo_lam_bot"] 1)])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   395
in
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   396
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   397
val npo_rls = [thm "npo_pair_lam", thm "npo_lam_pair"] @ map mk_thm
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   398
            ["~ true [= false",          "~ false [= true",
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   399
             "~ true [= <a,b>",          "~ <a,b> [= true",
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   400
             "~ true [= lam x. f(x)","~ lam x. f(x) [= true",
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   401
            "~ false [= <a,b>",          "~ <a,b> [= false",
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   402
            "~ false [= lam x. f(x)","~ lam x. f(x) [= false"]
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   403
end;
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   404
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   405
bind_thms ("npo_rls", npo_rls);
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
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   409
subsection {* Coinduction for @{text "[="} *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   410
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   411
lemma po_coinduct: "[|  <t,u> : R;  R <= POgen(R) |] ==> t [= u"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   412
  apply (rule PO_def [THEN def_coinduct, THEN PO_iff [THEN iffD2]])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   413
   apply assumption+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   414
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   415
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   416
ML {*
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27146
diff changeset
   417
  fun po_coinduct_tac ctxt s i =
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27146
diff changeset
   418
    RuleInsts.res_inst_tac ctxt [(("R", 0), s)] @{thm po_coinduct} i
20140
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
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   422
subsection {* Equality *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   423
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   424
lemma EQgen_mono: "mono(%X. EQgen(X))"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   425
  apply (unfold EQgen_def SIM_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   426
  apply (rule monoI)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   427
  apply blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   428
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   429
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   430
lemma EQgenXH: 
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   431
  "<t,t'> : EQgen(R) <-> (t=bot & t'=bot)  | (t=true & t'=true)  |  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   432
                                             (t=false & t'=false) |  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   433
                 (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
   434
                 (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
   435
  apply (unfold EQgen_def SIM_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   436
  apply (rule iff_refl [THEN XHlemma2])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   437
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   438
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   439
lemma eqXH: 
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   440
  "t=t' <-> (t=bot & t'=bot)  | (t=true & t'=true)  | (t=false & t'=false) |  
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   441
                     (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
   442
                     (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
   443
  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
   444
  apply (erule rev_mp)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   445
  apply (simp add: EQ_iff [THEN iff_sym])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   446
  apply (rule EQgen_mono [THEN EQ_def [THEN def_gfp_Tarski], THEN XHlemma1,
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   447
    unfolded EQgen_def SIM_def])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   448
  apply (rule iff_refl [THEN XHlemma2])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   449
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   450
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   451
lemma eq_coinduct: "[|  <t,u> : R;  R <= EQgen(R) |] ==> t = u"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   452
  apply (rule EQ_def [THEN def_coinduct, THEN EQ_iff [THEN iffD2]])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   453
   apply assumption+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   454
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   455
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   456
lemma eq_coinduct3:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   457
  "[|  <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
   458
  apply (rule EQ_def [THEN def_coinduct3, THEN EQ_iff [THEN iffD2]])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   459
  apply (rule EQgen_mono | 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
ML {*
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27146
diff changeset
   463
  fun eq_coinduct_tac ctxt s i =
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27146
diff changeset
   464
    RuleInsts.res_inst_tac ctxt [(("R", 0), s)] @{thm eq_coinduct} i
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27146
diff changeset
   465
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27146
diff changeset
   466
  fun eq_coinduct3_tac ctxt s i =
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 27146
diff changeset
   467
    RuleInsts.res_inst_tac ctxt [(("R", 0), s)] @{thm eq_coinduct3} i
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   468
*}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   469
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   470
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   471
subsection {* Untyped Case Analysis and Other Facts *}
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   472
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   473
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
   474
  by (auto simp: apply_def)
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   475
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   476
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
   477
  apply (cut_tac refl [THEN eqXH [THEN iffD1]])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   478
  apply blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   479
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   480
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   481
lemma term_case:
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
   482
  "[| 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
   483
  using exhaustion [of t] by blast
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
   484
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
   485
end