src/CCL/CCL.thy
author wenzelm
Sat, 17 Sep 2005 17:35:26 +0200
changeset 17456 bcf7544875b2
parent 3837 d7f033c74b38
child 20140 98acc6d0fab6
permissions -rw-r--r--
converted to Isar theory format;
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
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
   153
ML {* use_legacy_bindings (the_context ()) *}
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
   154
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
   155
end