src/CTT/CTT.thy
author wenzelm
Wed, 27 Mar 2013 16:38:25 +0100
changeset 51553 63327f679cff
parent 51308 51e158e988a5
child 56250 2c9f841f36b8
permissions -rw-r--r--
more ambitious Goal.skip_proofs: covers Goal.prove forms as well, and do not insist in quick_and_dirty (for the sake of Isabelle/jEdit);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
     1
(*  Title:      CTT/CTT.thy
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
    Copyright   1993  University of Cambridge
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
     6
header {* Constructive Type Theory *}
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
     8
theory CTT
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
     9
imports Pure
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
    10
begin
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
    11
48891
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 41526
diff changeset
    12
ML_file "~~/src/Provers/typedsimp.ML"
39557
fe5722fce758 renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents: 35762
diff changeset
    13
setup Pure_Thy.old_appl_syntax_setup
26956
1309a6a0a29f setup PureThy.old_appl_syntax_setup -- theory Pure provides regular application syntax by default;
wenzelm
parents: 26391
diff changeset
    14
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
    15
typedecl i
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
    16
typedecl t
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
    17
typedecl o
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
consts
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    20
  (*Types*)
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
    21
  F         :: "t"
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
    22
  T         :: "t"          (*F is empty, T contains one element*)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
  contr     :: "i=>i"
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    24
  tt        :: "i"
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    25
  (*Natural numbers*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    26
  N         :: "t"
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    27
  succ      :: "i=>i"
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    28
  rec       :: "[i, i, [i,i]=>i] => i"
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    29
  (*Unions*)
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
    30
  inl       :: "i=>i"
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
    31
  inr       :: "i=>i"
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    32
  when      :: "[i, i=>i, i=>i]=>i"
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    33
  (*General Sum and Binary Product*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    34
  Sum       :: "[t, i=>t]=>t"
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
    35
  fst       :: "i=>i"
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
    36
  snd       :: "i=>i"
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    37
  split     :: "[i, [i,i]=>i] =>i"
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    38
  (*General Product and Function Space*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    39
  Prod      :: "[t, i=>t]=>t"
14765
bafb24c150c1 proper use of 'syntax';
wenzelm
parents: 14565
diff changeset
    40
  (*Types*)
22808
a7daa74e2980 eliminated unnamed infixes, tuned syntax;
wenzelm
parents: 21524
diff changeset
    41
  Plus      :: "[t,t]=>t"           (infixr "+" 40)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    42
  (*Equality type*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    43
  Eq        :: "[t,i,i]=>t"
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    44
  eq        :: "i"
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    45
  (*Judgements*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    46
  Type      :: "t => prop"          ("(_ type)" [10] 5)
10467
e6e7205e9e91 x-symbol support for Pi, Sigma, -->, : (membership)
paulson
parents: 3837
diff changeset
    47
  Eqtype    :: "[t,t]=>prop"        ("(_ =/ _)" [10,10] 5)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    48
  Elem      :: "[i, t]=>prop"       ("(_ /: _)" [10,10] 5)
10467
e6e7205e9e91 x-symbol support for Pi, Sigma, -->, : (membership)
paulson
parents: 3837
diff changeset
    49
  Eqelem    :: "[i,i,t]=>prop"      ("(_ =/ _ :/ _)" [10,10,10] 5)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    50
  Reduce    :: "[i,i]=>prop"        ("Reduce[_,_]")
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    51
  (*Types*)
14765
bafb24c150c1 proper use of 'syntax';
wenzelm
parents: 14565
diff changeset
    52
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    53
  (*Functions*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    54
  lambda    :: "(i => i) => i"      (binder "lam " 10)
22808
a7daa74e2980 eliminated unnamed infixes, tuned syntax;
wenzelm
parents: 21524
diff changeset
    55
  app       :: "[i,i]=>i"           (infixl "`" 60)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    56
  (*Natural numbers*)
41310
65631ca437c9 proper identifiers for consts and types;
wenzelm
parents: 39557
diff changeset
    57
  Zero      :: "i"                  ("0")
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    58
  (*Pairing*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    59
  pair      :: "[i,i]=>i"           ("(1<_,/_>)")
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    60
14765
bafb24c150c1 proper use of 'syntax';
wenzelm
parents: 14565
diff changeset
    61
syntax
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
    62
  "_PROD"   :: "[idt,t,t]=>t"       ("(3PROD _:_./ _)" 10)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
    63
  "_SUM"    :: "[idt,t,t]=>t"       ("(3SUM _:_./ _)" 10)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    64
translations
35054
a5db9779b026 modernized some syntax translations;
wenzelm
parents: 27239
diff changeset
    65
  "PROD x:A. B" == "CONST Prod(A, %x. B)"
a5db9779b026 modernized some syntax translations;
wenzelm
parents: 27239
diff changeset
    66
  "SUM x:A. B"  == "CONST Sum(A, %x. B)"
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
    67
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
    68
abbreviation
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
    69
  Arrow     :: "[t,t]=>t"  (infixr "-->" 30) where
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
    70
  "A --> B == PROD _:A. B"
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
    71
abbreviation
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
    72
  Times     :: "[t,t]=>t"  (infixr "*" 50) where
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
    73
  "A * B == SUM _:A. B"
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    74
21210
c17fd2df4e9e renamed 'const_syntax' to 'notation';
wenzelm
parents: 19761
diff changeset
    75
notation (xsymbols)
21524
7843e2fd14a9 updated (binder) syntax/notation;
wenzelm
parents: 21404
diff changeset
    76
  lambda  (binder "\<lambda>\<lambda>" 10) and
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
    77
  Elem  ("(_ /\<in> _)" [10,10] 5) and
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
    78
  Eqelem  ("(2_ =/ _ \<in>/ _)" [10,10,10] 5) and
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
    79
  Arrow  (infixr "\<longrightarrow>" 30) and
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
    80
  Times  (infixr "\<times>" 50)
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
    81
21210
c17fd2df4e9e renamed 'const_syntax' to 'notation';
wenzelm
parents: 19761
diff changeset
    82
notation (HTML output)
21524
7843e2fd14a9 updated (binder) syntax/notation;
wenzelm
parents: 21404
diff changeset
    83
  lambda  (binder "\<lambda>\<lambda>" 10) and
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
    84
  Elem  ("(_ /\<in> _)" [10,10] 5) and
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
    85
  Eqelem  ("(2_ =/ _ \<in>/ _)" [10,10,10] 5) and
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
    86
  Times  (infixr "\<times>" 50)
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
    87
10467
e6e7205e9e91 x-symbol support for Pi, Sigma, -->, : (membership)
paulson
parents: 3837
diff changeset
    88
syntax (xsymbols)
21524
7843e2fd14a9 updated (binder) syntax/notation;
wenzelm
parents: 21404
diff changeset
    89
  "_PROD"   :: "[idt,t,t] => t"     ("(3\<Pi> _\<in>_./ _)"    10)
7843e2fd14a9 updated (binder) syntax/notation;
wenzelm
parents: 21404
diff changeset
    90
  "_SUM"    :: "[idt,t,t] => t"     ("(3\<Sigma> _\<in>_./ _)" 10)
10467
e6e7205e9e91 x-symbol support for Pi, Sigma, -->, : (membership)
paulson
parents: 3837
diff changeset
    91
14565
c6dc17aab88a use more symbols in HTML output
kleing
parents: 12110
diff changeset
    92
syntax (HTML output)
21524
7843e2fd14a9 updated (binder) syntax/notation;
wenzelm
parents: 21404
diff changeset
    93
  "_PROD"   :: "[idt,t,t] => t"     ("(3\<Pi> _\<in>_./ _)"    10)
7843e2fd14a9 updated (binder) syntax/notation;
wenzelm
parents: 21404
diff changeset
    94
  "_SUM"    :: "[idt,t,t] => t"     ("(3\<Sigma> _\<in>_./ _)" 10)
14565
c6dc17aab88a use more symbols in HTML output
kleing
parents: 12110
diff changeset
    95
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    96
  (*Reduction: a weaker notion than equality;  a hack for simplification.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    97
    Reduce[a,b] means either that  a=b:A  for some A or else that "a" and "b"
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    98
    are textually identical.*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    99
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   100
  (*does not verify a:A!  Sound because only trans_red uses a Reduce premise
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   101
    No new theorems can be proved about the standard judgements.*)
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   102
axiomatization where
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   103
  refl_red: "\<And>a. Reduce[a,a]" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   104
  red_if_equal: "\<And>a b A. a = b : A ==> Reduce[a,b]" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   105
  trans_red: "\<And>a b c A. [| a = b : A;  Reduce[b,c] |] ==> a = c : A" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   106
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   107
  (*Reflexivity*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   108
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   109
  refl_type: "\<And>A. A type ==> A = A" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   110
  refl_elem: "\<And>a A. a : A ==> a = a : A" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   111
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   112
  (*Symmetry*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   113
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   114
  sym_type:  "\<And>A B. A = B ==> B = A" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   115
  sym_elem:  "\<And>a b A. a = b : A ==> b = a : A" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   116
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   117
  (*Transitivity*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   118
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   119
  trans_type:   "\<And>A B C. [| A = B;  B = C |] ==> A = C" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   120
  trans_elem:   "\<And>a b c A. [| a = b : A;  b = c : A |] ==> a = c : A" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   121
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   122
  equal_types:  "\<And>a A B. [| a : A;  A = B |] ==> a : B" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   123
  equal_typesL: "\<And>a b A B. [| a = b : A;  A = B |] ==> a = b : B" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   124
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   125
  (*Substitution*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   126
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   127
  subst_type:   "\<And>a A B. [| a : A;  !!z. z:A ==> B(z) type |] ==> B(a) type" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   128
  subst_typeL:  "\<And>a c A B D. [| a = c : A;  !!z. z:A ==> B(z) = D(z) |] ==> B(a) = D(c)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   129
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   130
  subst_elem:   "\<And>a b A B. [| a : A;  !!z. z:A ==> b(z):B(z) |] ==> b(a):B(a)" and
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   131
  subst_elemL:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   132
    "\<And>a b c d A B. [| a=c : A;  !!z. z:A ==> b(z)=d(z) : B(z) |] ==> b(a)=d(c) : B(a)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   133
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   134
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   135
  (*The type N -- natural numbers*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   136
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   137
  NF: "N type" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   138
  NI0: "0 : N" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   139
  NI_succ: "\<And>a. a : N ==> succ(a) : N" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   140
  NI_succL:  "\<And>a b. a = b : N ==> succ(a) = succ(b) : N" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   141
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   142
  NE:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   143
   "\<And>p a b C. [| p: N;  a: C(0);  !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) |]
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   144
   ==> rec(p, a, %u v. b(u,v)) : C(p)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   145
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   146
  NEL:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   147
   "\<And>p q a b c d C. [| p = q : N;  a = c : C(0);
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   148
      !!u v. [| u: N; v: C(u) |] ==> b(u,v) = d(u,v): C(succ(u)) |]
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   149
   ==> rec(p, a, %u v. b(u,v)) = rec(q,c,d) : C(p)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   150
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   151
  NC0:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   152
   "\<And>a b C. [| a: C(0);  !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) |]
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   153
   ==> rec(0, a, %u v. b(u,v)) = a : C(0)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   154
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   155
  NC_succ:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   156
   "\<And>p a b C. [| p: N;  a: C(0);
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   157
       !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) |] ==>
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   158
   rec(succ(p), a, %u v. b(u,v)) = b(p, rec(p, a, %u v. b(u,v))) : C(succ(p))" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   159
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   160
  (*The fourth Peano axiom.  See page 91 of Martin-Lof's book*)
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   161
  zero_ne_succ:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   162
    "\<And>a. [| a: N;  0 = succ(a) : N |] ==> 0: F" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   163
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   164
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   165
  (*The Product of a family of types*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   166
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   167
  ProdF:  "\<And>A B. [| A type; !!x. x:A ==> B(x) type |] ==> PROD x:A. B(x) type" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   168
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   169
  ProdFL:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   170
   "\<And>A B C D. [| A = C;  !!x. x:A ==> B(x) = D(x) |] ==>
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   171
   PROD x:A. B(x) = PROD x:C. D(x)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   172
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   173
  ProdI:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   174
   "\<And>b A B. [| A type;  !!x. x:A ==> b(x):B(x)|] ==> lam x. b(x) : PROD x:A. B(x)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   175
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   176
  ProdIL:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   177
   "\<And>b c A B. [| A type;  !!x. x:A ==> b(x) = c(x) : B(x)|] ==>
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   178
   lam x. b(x) = lam x. c(x) : PROD x:A. B(x)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   179
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   180
  ProdE:  "\<And>p a A B. [| p : PROD x:A. B(x);  a : A |] ==> p`a : B(a)" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   181
  ProdEL: "\<And>p q a b A B. [| p=q: PROD x:A. B(x);  a=b : A |] ==> p`a = q`b : B(a)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   182
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   183
  ProdC:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   184
   "\<And>a b A B. [| a : A;  !!x. x:A ==> b(x) : B(x)|] ==>
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   185
   (lam x. b(x)) ` a = b(a) : B(a)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   186
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   187
  ProdC2:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   188
   "\<And>p A B. p : PROD x:A. B(x) ==> (lam x. p`x) = p : PROD x:A. B(x)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   189
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   190
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   191
  (*The Sum of a family of types*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   192
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   193
  SumF:  "\<And>A B. [| A type;  !!x. x:A ==> B(x) type |] ==> SUM x:A. B(x) type" and
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   194
  SumFL:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   195
    "\<And>A B C D. [| A = C;  !!x. x:A ==> B(x) = D(x) |] ==> SUM x:A. B(x) = SUM x:C. D(x)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   196
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   197
  SumI:  "\<And>a b A B. [| a : A;  b : B(a) |] ==> <a,b> : SUM x:A. B(x)" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   198
  SumIL: "\<And>a b c d A B. [| a=c:A;  b=d:B(a) |] ==> <a,b> = <c,d> : SUM x:A. B(x)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   199
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   200
  SumE:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   201
    "\<And>p c A B C. [| p: SUM x:A. B(x);  !!x y. [| x:A; y:B(x) |] ==> c(x,y): C(<x,y>) |]
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   202
    ==> split(p, %x y. c(x,y)) : C(p)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   203
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   204
  SumEL:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   205
    "\<And>p q c d A B C. [| p=q : SUM x:A. B(x);
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   206
       !!x y. [| x:A; y:B(x) |] ==> c(x,y)=d(x,y): C(<x,y>)|]
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   207
    ==> split(p, %x y. c(x,y)) = split(q, % x y. d(x,y)) : C(p)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   208
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   209
  SumC:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   210
    "\<And>a b c A B C. [| a: A;  b: B(a);  !!x y. [| x:A; y:B(x) |] ==> c(x,y): C(<x,y>) |]
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   211
    ==> split(<a,b>, %x y. c(x,y)) = c(a,b) : C(<a,b>)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   212
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   213
  fst_def:   "\<And>a. fst(a) == split(a, %x y. x)" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   214
  snd_def:   "\<And>a. snd(a) == split(a, %x y. y)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   215
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   216
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   217
  (*The sum of two types*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   218
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   219
  PlusF:   "\<And>A B. [| A type;  B type |] ==> A+B type" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   220
  PlusFL:  "\<And>A B C D. [| A = C;  B = D |] ==> A+B = C+D" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   221
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   222
  PlusI_inl:   "\<And>a A B. [| a : A;  B type |] ==> inl(a) : A+B" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   223
  PlusI_inlL: "\<And>a c A B. [| a = c : A;  B type |] ==> inl(a) = inl(c) : A+B" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   224
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   225
  PlusI_inr:   "\<And>b A B. [| A type;  b : B |] ==> inr(b) : A+B" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   226
  PlusI_inrL: "\<And>b d A B. [| A type;  b = d : B |] ==> inr(b) = inr(d) : A+B" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   227
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   228
  PlusE:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   229
    "\<And>p c d A B C. [| p: A+B;  !!x. x:A ==> c(x): C(inl(x));
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   230
                !!y. y:B ==> d(y): C(inr(y)) |]
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   231
    ==> when(p, %x. c(x), %y. d(y)) : C(p)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   232
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   233
  PlusEL:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   234
    "\<And>p q c d e f A B C. [| p = q : A+B;  !!x. x: A ==> c(x) = e(x) : C(inl(x));
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   235
                     !!y. y: B ==> d(y) = f(y) : C(inr(y)) |]
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   236
    ==> when(p, %x. c(x), %y. d(y)) = when(q, %x. e(x), %y. f(y)) : C(p)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   237
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   238
  PlusC_inl:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   239
    "\<And>a c d A C. [| a: A;  !!x. x:A ==> c(x): C(inl(x));
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   240
              !!y. y:B ==> d(y): C(inr(y)) |]
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   241
    ==> when(inl(a), %x. c(x), %y. d(y)) = c(a) : C(inl(a))" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   242
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   243
  PlusC_inr:
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   244
    "\<And>b c d A B C. [| b: B;  !!x. x:A ==> c(x): C(inl(x));
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   245
              !!y. y:B ==> d(y): C(inr(y)) |]
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   246
    ==> when(inr(b), %x. c(x), %y. d(y)) = d(b) : C(inr(b))" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   247
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   248
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   249
  (*The type Eq*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   250
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   251
  EqF:    "\<And>a b A. [| A type;  a : A;  b : A |] ==> Eq(A,a,b) type" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   252
  EqFL: "\<And>a b c d A B. [| A=B;  a=c: A;  b=d : A |] ==> Eq(A,a,b) = Eq(B,c,d)" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   253
  EqI: "\<And>a b A. a = b : A ==> eq : Eq(A,a,b)" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   254
  EqE: "\<And>p a b A. p : Eq(A,a,b) ==> a = b : A" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   255
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   256
  (*By equality of types, can prove C(p) from C(eq), an elimination rule*)
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   257
  EqC: "\<And>p a b A. p : Eq(A,a,b) ==> p = eq : Eq(A,a,b)" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   258
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   259
  (*The type F*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   260
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   261
  FF: "F type" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   262
  FE: "\<And>p C. [| p: F;  C type |] ==> contr(p) : C" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   263
  FEL:  "\<And>p q C. [| p = q : F;  C type |] ==> contr(p) = contr(q) : C" and
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   264
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   265
  (*The type T
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   266
     Martin-Lof's book (page 68) discusses elimination and computation.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   267
     Elimination can be derived by computation and equality of types,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   268
     but with an extra premise C(x) type x:T.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   269
     Also computation can be derived from elimination. *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   270
51308
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   271
  TF: "T type" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   272
  TI: "tt : T" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   273
  TE: "\<And>p c C. [| p : T;  c : C(tt) |] ==> c : C(p)" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   274
  TEL: "\<And>p q c d C. [| p = q : T;  c = d : C(tt) |] ==> c = d : C(p)" and
51e158e988a5 eliminated legacy 'axioms';
wenzelm
parents: 48891
diff changeset
   275
  TC: "\<And>p. p : T ==> p = tt : T"
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   276
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   277
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   278
subsection "Tactics and derived rules for Constructive Type Theory"
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   279
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   280
(*Formation rules*)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   281
lemmas form_rls = NF ProdF SumF PlusF EqF FF TF
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   282
  and formL_rls = ProdFL SumFL PlusFL EqFL
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   283
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   284
(*Introduction rules
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   285
  OMITTED: EqI, because its premise is an eqelem, not an elem*)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   286
lemmas intr_rls = NI0 NI_succ ProdI SumI PlusI_inl PlusI_inr TI
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   287
  and intrL_rls = NI_succL ProdIL SumIL PlusI_inlL PlusI_inrL
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   288
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   289
(*Elimination rules
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   290
  OMITTED: EqE, because its conclusion is an eqelem,  not an elem
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   291
           TE, because it does not involve a constructor *)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   292
lemmas elim_rls = NE ProdE SumE PlusE FE
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   293
  and elimL_rls = NEL ProdEL SumEL PlusEL FEL
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   294
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   295
(*OMITTED: eqC are TC because they make rewriting loop: p = un = un = ... *)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   296
lemmas comp_rls = NC0 NC_succ ProdC SumC PlusC_inl PlusC_inr
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   297
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   298
(*rules with conclusion a:A, an elem judgement*)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   299
lemmas element_rls = intr_rls elim_rls
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   300
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   301
(*Definitions are (meta)equality axioms*)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   302
lemmas basic_defs = fst_def snd_def
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   303
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   304
(*Compare with standard version: B is applied to UNSIMPLIFIED expression! *)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   305
lemma SumIL2: "[| c=a : A;  d=b : B(a) |] ==> <c,d> = <a,b> : Sum(A,B)"
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   306
apply (rule sym_elem)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   307
apply (rule SumIL)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   308
apply (rule_tac [!] sym_elem)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   309
apply assumption+
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   310
done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   311
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   312
lemmas intrL2_rls = NI_succL ProdIL SumIL2 PlusI_inlL PlusI_inrL
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   313
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   314
(*Exploit p:Prod(A,B) to create the assumption z:B(a).
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   315
  A more natural form of product elimination. *)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   316
lemma subst_prodE:
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   317
  assumes "p: Prod(A,B)"
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   318
    and "a: A"
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   319
    and "!!z. z: B(a) ==> c(z): C(z)"
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   320
  shows "c(p`a): C(p`a)"
41526
54b4686704af eliminated global prems;
wenzelm
parents: 41310
diff changeset
   321
apply (rule assms ProdE)+
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   322
done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   323
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   324
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   325
subsection {* Tactics for type checking *}
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   326
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   327
ML {*
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   328
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   329
local
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   330
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   331
fun is_rigid_elem (Const("CTT.Elem",_) $ a $ _) = not(is_Var (head_of a))
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   332
  | is_rigid_elem (Const("CTT.Eqelem",_) $ a $ _ $ _) = not(is_Var (head_of a))
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   333
  | is_rigid_elem (Const("CTT.Type",_) $ a) = not(is_Var (head_of a))
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   334
  | is_rigid_elem _ = false
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   335
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   336
in
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   337
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   338
(*Try solving a:A or a=b:A by assumption provided a is rigid!*)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   339
val test_assume_tac = SUBGOAL(fn (prem,i) =>
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   340
    if is_rigid_elem (Logic.strip_assums_concl prem)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   341
    then  assume_tac i  else  no_tac)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   342
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   343
fun ASSUME tf i = test_assume_tac i  ORELSE  tf i
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   344
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   345
end;
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   346
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   347
*}
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   348
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   349
(*For simplification: type formation and checking,
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   350
  but no equalities between terms*)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   351
lemmas routine_rls = form_rls formL_rls refl_type element_rls
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   352
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   353
ML {*
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   354
local
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26956
diff changeset
   355
  val equal_rls = @{thms form_rls} @ @{thms element_rls} @ @{thms intrL_rls} @
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26956
diff changeset
   356
    @{thms elimL_rls} @ @{thms refl_elem}
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   357
in
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   358
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   359
fun routine_tac rls prems = ASSUME (filt_resolve_tac (prems @ rls) 4);
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   360
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   361
(*Solve all subgoals "A type" using formation rules. *)
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26956
diff changeset
   362
val form_tac = REPEAT_FIRST (ASSUME (filt_resolve_tac @{thms form_rls} 1));
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   363
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   364
(*Type checking: solve a:A (a rigid, A flexible) by intro and elim rules. *)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   365
fun typechk_tac thms =
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26956
diff changeset
   366
  let val tac = filt_resolve_tac (thms @ @{thms form_rls} @ @{thms element_rls}) 3
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   367
  in  REPEAT_FIRST (ASSUME tac)  end
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   368
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   369
(*Solve a:A (a flexible, A rigid) by introduction rules.
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   370
  Cannot use stringtrees (filt_resolve_tac) since
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   371
  goals like ?a:SUM(A,B) have a trivial head-string *)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   372
fun intr_tac thms =
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26956
diff changeset
   373
  let val tac = filt_resolve_tac(thms @ @{thms form_rls} @ @{thms intr_rls}) 1
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   374
  in  REPEAT_FIRST (ASSUME tac)  end
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   375
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   376
(*Equality proving: solve a=b:A (where a is rigid) by long rules. *)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   377
fun equal_tac thms =
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   378
  REPEAT_FIRST (ASSUME (filt_resolve_tac (thms @ equal_rls) 3))
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   379
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 14854
diff changeset
   380
end
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   381
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   382
*}
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   383
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   384
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   385
subsection {* Simplification *}
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   386
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   387
(*To simplify the type in a goal*)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   388
lemma replace_type: "[| B = A;  a : A |] ==> a : B"
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   389
apply (rule equal_types)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   390
apply (rule_tac [2] sym_type)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   391
apply assumption+
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   392
done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   393
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   394
(*Simplify the parameter of a unary type operator.*)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   395
lemma subst_eqtyparg:
23467
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 22808
diff changeset
   396
  assumes 1: "a=c : A"
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 22808
diff changeset
   397
    and 2: "!!z. z:A ==> B(z) type"
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   398
  shows "B(a)=B(c)"
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   399
apply (rule subst_typeL)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   400
apply (rule_tac [2] refl_type)
23467
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 22808
diff changeset
   401
apply (rule 1)
d1b97708d5eb tuned proofs -- avoid implicit prems;
wenzelm
parents: 22808
diff changeset
   402
apply (erule 2)
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   403
done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   404
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   405
(*Simplification rules for Constructive Type Theory*)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   406
lemmas reduction_rls = comp_rls [THEN trans_elem]
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   407
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   408
ML {*
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   409
(*Converts each goal "e : Eq(A,a,b)" into "a=b:A" for simplification.
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   410
  Uses other intro rules to avoid changing flexible goals.*)
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26956
diff changeset
   411
val eqintr_tac = REPEAT_FIRST (ASSUME (filt_resolve_tac (@{thm EqI} :: @{thms intr_rls}) 1))
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   412
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   413
(** Tactics that instantiate CTT-rules.
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   414
    Vars in the given terms will be incremented!
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   415
    The (rtac EqE i) lets them apply to equality judgements. **)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   416
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26956
diff changeset
   417
fun NE_tac ctxt sp i =
27239
f2f42f9fa09d pervasive RuleInsts;
wenzelm
parents: 27208
diff changeset
   418
  TRY (rtac @{thm EqE} i) THEN res_inst_tac ctxt [(("p", 0), sp)] @{thm NE} i
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   419
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26956
diff changeset
   420
fun SumE_tac ctxt sp i =
27239
f2f42f9fa09d pervasive RuleInsts;
wenzelm
parents: 27208
diff changeset
   421
  TRY (rtac @{thm EqE} i) THEN res_inst_tac ctxt [(("p", 0), sp)] @{thm SumE} i
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   422
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26956
diff changeset
   423
fun PlusE_tac ctxt sp i =
27239
f2f42f9fa09d pervasive RuleInsts;
wenzelm
parents: 27208
diff changeset
   424
  TRY (rtac @{thm EqE} i) THEN res_inst_tac ctxt [(("p", 0), sp)] @{thm PlusE} i
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   425
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   426
(** Predicate logic reasoning, WITH THINNING!!  Procedures adapted from NJ. **)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   427
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   428
(*Finds f:Prod(A,B) and a:A in the assumptions, concludes there is z:B(a) *)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   429
fun add_mp_tac i =
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26956
diff changeset
   430
    rtac @{thm subst_prodE} i  THEN  assume_tac i  THEN  assume_tac i
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   431
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   432
(*Finds P-->Q and P in the assumptions, replaces implication by Q *)
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26956
diff changeset
   433
fun mp_tac i = etac @{thm subst_prodE} i  THEN  assume_tac i
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   434
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   435
(*"safe" when regarded as predicate calculus rules*)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   436
val safe_brls = sort (make_ord lessb)
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26956
diff changeset
   437
    [ (true, @{thm FE}), (true,asm_rl),
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26956
diff changeset
   438
      (false, @{thm ProdI}), (true, @{thm SumE}), (true, @{thm PlusE}) ]
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   439
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   440
val unsafe_brls =
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26956
diff changeset
   441
    [ (false, @{thm PlusI_inl}), (false, @{thm PlusI_inr}), (false, @{thm SumI}),
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26956
diff changeset
   442
      (true, @{thm subst_prodE}) ]
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   443
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   444
(*0 subgoals vs 1 or more*)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   445
val (safe0_brls, safep_brls) =
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   446
    List.partition (curry (op =) 0 o subgoals_of_brl) safe_brls
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   447
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   448
fun safestep_tac thms i =
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   449
    form_tac  ORELSE
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   450
    resolve_tac thms i  ORELSE
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   451
    biresolve_tac safe0_brls i  ORELSE  mp_tac i  ORELSE
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   452
    DETERM (biresolve_tac safep_brls i)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   453
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   454
fun safe_tac thms i = DEPTH_SOLVE_1 (safestep_tac thms i)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   455
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   456
fun step_tac thms = safestep_tac thms  ORELSE'  biresolve_tac unsafe_brls
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   457
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   458
(*Fails unless it solves the goal!*)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   459
fun pc_tac thms = DEPTH_SOLVE_1 o (step_tac thms)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   460
*}
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   461
48891
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 41526
diff changeset
   462
ML_file "rew.ML"
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   463
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   464
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   465
subsection {* The elimination rules for fst/snd *}
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   466
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   467
lemma SumE_fst: "p : Sum(A,B) ==> fst(p) : A"
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   468
apply (unfold basic_defs)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   469
apply (erule SumE)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   470
apply assumption
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   471
done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   472
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   473
(*The first premise must be p:Sum(A,B) !!*)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   474
lemma SumE_snd:
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   475
  assumes major: "p: Sum(A,B)"
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   476
    and "A type"
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   477
    and "!!x. x:A ==> B(x) type"
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   478
  shows "snd(p) : B(fst(p))"
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   479
  apply (unfold basic_defs)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   480
  apply (rule major [THEN SumE])
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   481
  apply (rule SumC [THEN subst_eqtyparg, THEN replace_type])
26391
6e8aa5a4eb82 more antiquotations;
wenzelm
parents: 23467
diff changeset
   482
  apply (tactic {* typechk_tac @{thms assms} *})
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   483
  done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   484
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17782
diff changeset
   485
end