src/Cube/Example.thy
author haftmann
Sun Oct 08 22:28:22 2017 +0200 (22 months ago)
changeset 66816 212a3334e7da
parent 62020 5d208fd2507d
permissions -rw-r--r--
more fundamental definition of div and mod on int
wenzelm@58889
     1
section \<open>Lambda Cube Examples\<close>
wenzelm@17453
     2
wenzelm@17453
     3
theory Example
wenzelm@17453
     4
imports Cube
wenzelm@17453
     5
begin
wenzelm@17453
     6
wenzelm@58617
     7
text \<open>Examples taken from:
wenzelm@17453
     8
wenzelm@17453
     9
  H. Barendregt. Introduction to Generalised Type Systems.
wenzelm@58617
    10
  J. Functional Programming.\<close>
wenzelm@17453
    11
wenzelm@58617
    12
method_setup depth_solve =
wenzelm@59499
    13
  \<open>Attrib.thms >> (fn thms => fn ctxt => METHOD (fn facts =>
wenzelm@59499
    14
    (DEPTH_SOLVE (HEADGOAL (assume_tac ctxt ORELSE' resolve_tac ctxt (facts @ thms))))))\<close>
wenzelm@17453
    15
wenzelm@58617
    16
method_setup depth_solve1 =
wenzelm@59499
    17
  \<open>Attrib.thms >> (fn thms => fn ctxt => METHOD (fn facts =>
wenzelm@59499
    18
    (DEPTH_SOLVE_1 (HEADGOAL (assume_tac ctxt ORELSE' resolve_tac ctxt (facts @ thms))))))\<close>
wenzelm@17453
    19
wenzelm@58617
    20
method_setup strip_asms =
wenzelm@59498
    21
  \<open>Attrib.thms >> (fn thms => fn ctxt => METHOD (fn facts =>
wenzelm@61389
    22
    REPEAT (resolve_tac ctxt @{thms strip_b strip_s} 1 THEN
wenzelm@59499
    23
    DEPTH_SOLVE_1 (assume_tac ctxt 1 ORELSE resolve_tac ctxt (facts @ thms) 1))))\<close>
wenzelm@17453
    24
wenzelm@17453
    25
wenzelm@58617
    26
subsection \<open>Simple types\<close>
wenzelm@17453
    27
wenzelm@61337
    28
schematic_goal "A:* \<turnstile> A\<rightarrow>A : ?T"
wenzelm@17453
    29
  by (depth_solve rules)
wenzelm@17453
    30
wenzelm@61388
    31
schematic_goal "A:* \<turnstile> \<^bold>\<lambda>a:A. a : ?T"
wenzelm@17453
    32
  by (depth_solve rules)
wenzelm@17453
    33
wenzelm@61388
    34
schematic_goal "A:* B:* b:B \<turnstile> \<^bold>\<lambda>x:A. b : ?T"
wenzelm@17453
    35
  by (depth_solve rules)
wenzelm@17453
    36
wenzelm@61388
    37
schematic_goal "A:* b:A \<turnstile> (\<^bold>\<lambda>a:A. a)\<cdot>b: ?T"
wenzelm@17453
    38
  by (depth_solve rules)
wenzelm@17453
    39
wenzelm@61388
    40
schematic_goal "A:* B:* c:A b:B \<turnstile> (\<^bold>\<lambda>x:A. b)\<cdot> c: ?T"
wenzelm@17453
    41
  by (depth_solve rules)
wenzelm@17453
    42
wenzelm@61388
    43
schematic_goal "A:* B:* \<turnstile> \<^bold>\<lambda>a:A. \<^bold>\<lambda>b:B. a : ?T"
wenzelm@17453
    44
  by (depth_solve rules)
wenzelm@17453
    45
wenzelm@17453
    46
wenzelm@58617
    47
subsection \<open>Second-order types\<close>
wenzelm@17453
    48
wenzelm@61388
    49
schematic_goal (in L2) "\<turnstile> \<^bold>\<lambda>A:*. \<^bold>\<lambda>a:A. a : ?T"
wenzelm@17453
    50
  by (depth_solve rules)
wenzelm@17453
    51
wenzelm@61390
    52
schematic_goal (in L2) "A:* \<turnstile> (\<^bold>\<lambda>B:*. \<^bold>\<lambda>b:B. b)\<cdot>A : ?T"
wenzelm@17453
    53
  by (depth_solve rules)
wenzelm@17453
    54
wenzelm@61390
    55
schematic_goal (in L2) "A:* b:A \<turnstile> (\<^bold>\<lambda>B:*. \<^bold>\<lambda>b:B. b) \<cdot> A \<cdot> b: ?T"
wenzelm@17453
    56
  by (depth_solve rules)
wenzelm@17453
    57
wenzelm@61390
    58
schematic_goal (in L2) "\<turnstile> \<^bold>\<lambda>B:*. \<^bold>\<lambda>a:(\<Prod>A:*.A).a \<cdot> ((\<Prod>A:*.A)\<rightarrow>B) \<cdot> a: ?T"
wenzelm@17453
    59
  by (depth_solve rules)
wenzelm@17453
    60
wenzelm@17453
    61
wenzelm@58617
    62
subsection \<open>Weakly higher-order propositional logic\<close>
wenzelm@17453
    63
wenzelm@61388
    64
schematic_goal (in Lomega) "\<turnstile> \<^bold>\<lambda>A:*.A\<rightarrow>A : ?T"
wenzelm@17453
    65
  by (depth_solve rules)
wenzelm@17453
    66
wenzelm@61388
    67
schematic_goal (in Lomega) "B:* \<turnstile> (\<^bold>\<lambda>A:*.A\<rightarrow>A) \<cdot> B : ?T"
wenzelm@17453
    68
  by (depth_solve rules)
wenzelm@17453
    69
wenzelm@61388
    70
schematic_goal (in Lomega) "B:* b:B \<turnstile> (\<^bold>\<lambda>y:B. b): ?T"
wenzelm@17453
    71
  by (depth_solve rules)
wenzelm@17453
    72
wenzelm@61388
    73
schematic_goal (in Lomega) "A:* F:*\<rightarrow>* \<turnstile> F\<cdot>(F\<cdot>A): ?T"
wenzelm@17453
    74
  by (depth_solve rules)
wenzelm@17453
    75
wenzelm@61388
    76
schematic_goal (in Lomega) "A:* \<turnstile> \<^bold>\<lambda>F:*\<rightarrow>*.F\<cdot>(F\<cdot>A): ?T"
wenzelm@17453
    77
  by (depth_solve rules)
wenzelm@17453
    78
wenzelm@17453
    79
wenzelm@58617
    80
subsection \<open>LP\<close>
wenzelm@17453
    81
wenzelm@61337
    82
schematic_goal (in LP) "A:* \<turnstile> A \<rightarrow> * : ?T"
wenzelm@17453
    83
  by (depth_solve rules)
wenzelm@17453
    84
wenzelm@61388
    85
schematic_goal (in LP) "A:* P:A\<rightarrow>* a:A \<turnstile> P\<cdot>a: ?T"
wenzelm@17453
    86
  by (depth_solve rules)
wenzelm@17453
    87
wenzelm@61388
    88
schematic_goal (in LP) "A:* P:A\<rightarrow>A\<rightarrow>* a:A \<turnstile> \<Prod>a:A. P\<cdot>a\<cdot>a: ?T"
wenzelm@17453
    89
  by (depth_solve rules)
wenzelm@17453
    90
wenzelm@61388
    91
schematic_goal (in LP) "A:* P:A\<rightarrow>* Q:A\<rightarrow>* \<turnstile> \<Prod>a:A. P\<cdot>a \<rightarrow> Q\<cdot>a: ?T"
wenzelm@17453
    92
  by (depth_solve rules)
wenzelm@17453
    93
wenzelm@61388
    94
schematic_goal (in LP) "A:* P:A\<rightarrow>* \<turnstile> \<Prod>a:A. P\<cdot>a \<rightarrow> P\<cdot>a: ?T"
wenzelm@17453
    95
  by (depth_solve rules)
wenzelm@17453
    96
wenzelm@61388
    97
schematic_goal (in LP) "A:* P:A\<rightarrow>* \<turnstile> \<^bold>\<lambda>a:A. \<^bold>\<lambda>x:P\<cdot>a. x: ?T"
wenzelm@17453
    98
  by (depth_solve rules)
wenzelm@17453
    99
wenzelm@61388
   100
schematic_goal (in LP) "A:* P:A\<rightarrow>* Q:* \<turnstile> (\<Prod>a:A. P\<cdot>a\<rightarrow>Q) \<rightarrow> (\<Prod>a:A. P\<cdot>a) \<rightarrow> Q : ?T"
wenzelm@17453
   101
  by (depth_solve rules)
wenzelm@17453
   102
wenzelm@61337
   103
schematic_goal (in LP) "A:* P:A\<rightarrow>* Q:* a0:A \<turnstile>
wenzelm@61388
   104
        \<^bold>\<lambda>x:\<Prod>a:A. P\<cdot>a\<rightarrow>Q. \<^bold>\<lambda>y:\<Prod>a:A. P\<cdot>a. x\<cdot>a0\<cdot>(y\<cdot>a0): ?T"
wenzelm@17453
   105
  by (depth_solve rules)
wenzelm@17453
   106
wenzelm@17453
   107
wenzelm@58617
   108
subsection \<open>Omega-order types\<close>
wenzelm@17453
   109
wenzelm@61388
   110
schematic_goal (in L2) "A:* B:* \<turnstile> \<Prod>C:*.(A\<rightarrow>B\<rightarrow>C)\<rightarrow>C : ?T"
wenzelm@17453
   111
  by (depth_solve rules)
wenzelm@17453
   112
wenzelm@61390
   113
schematic_goal (in Lomega2) "\<turnstile> \<^bold>\<lambda>A:*. \<^bold>\<lambda>B:*.\<Prod>C:*.(A\<rightarrow>B\<rightarrow>C)\<rightarrow>C : ?T"
wenzelm@17453
   114
  by (depth_solve rules)
wenzelm@17453
   115
wenzelm@61390
   116
schematic_goal (in Lomega2) "\<turnstile> \<^bold>\<lambda>A:*. \<^bold>\<lambda>B:*. \<^bold>\<lambda>x:A. \<^bold>\<lambda>y:B. x : ?T"
wenzelm@17453
   117
  by (depth_solve rules)
wenzelm@17453
   118
wenzelm@61388
   119
schematic_goal (in Lomega2) "A:* B:* \<turnstile> ?p : (A\<rightarrow>B) \<rightarrow> ((B\<rightarrow>\<Prod>P:*.P)\<rightarrow>(A\<rightarrow>\<Prod>P:*.P))"
wenzelm@17453
   120
  apply (strip_asms rules)
wenzelm@17453
   121
  apply (rule lam_ss)
wenzelm@17453
   122
    apply (depth_solve1 rules)
wenzelm@17453
   123
   prefer 2
wenzelm@17453
   124
   apply (depth_solve1 rules)
wenzelm@17453
   125
  apply (rule lam_ss)
wenzelm@17453
   126
    apply (depth_solve1 rules)
wenzelm@17453
   127
   prefer 2
wenzelm@17453
   128
   apply (depth_solve1 rules)
wenzelm@17453
   129
  apply (rule lam_ss)
wenzelm@17453
   130
    apply assumption
wenzelm@17453
   131
   prefer 2
wenzelm@17453
   132
   apply (depth_solve1 rules)
wenzelm@17453
   133
  apply (erule pi_elim)
wenzelm@17453
   134
   apply assumption
wenzelm@17453
   135
  apply (erule pi_elim)
wenzelm@17453
   136
   apply assumption
wenzelm@17453
   137
  apply assumption
wenzelm@17453
   138
  done
wenzelm@17453
   139
wenzelm@17453
   140
wenzelm@58617
   141
subsection \<open>Second-order Predicate Logic\<close>
wenzelm@17453
   142
wenzelm@61388
   143
schematic_goal (in LP2) "A:* P:A\<rightarrow>* \<turnstile> \<^bold>\<lambda>a:A. P\<cdot>a\<rightarrow>(\<Prod>A:*.A) : ?T"
wenzelm@17453
   144
  by (depth_solve rules)
wenzelm@17453
   145
wenzelm@61337
   146
schematic_goal (in LP2) "A:* P:A\<rightarrow>A\<rightarrow>* \<turnstile>
wenzelm@61388
   147
    (\<Prod>a:A. \<Prod>b:A. P\<cdot>a\<cdot>b\<rightarrow>P\<cdot>b\<cdot>a\<rightarrow>\<Prod>P:*.P) \<rightarrow> \<Prod>a:A. P\<cdot>a\<cdot>a\<rightarrow>\<Prod>P:*.P : ?T"
wenzelm@17453
   148
  by (depth_solve rules)
wenzelm@17453
   149
wenzelm@61337
   150
schematic_goal (in LP2) "A:* P:A\<rightarrow>A\<rightarrow>* \<turnstile>
wenzelm@61388
   151
    ?p: (\<Prod>a:A. \<Prod>b:A. P\<cdot>a\<cdot>b\<rightarrow>P\<cdot>b\<cdot>a\<rightarrow>\<Prod>P:*.P) \<rightarrow> \<Prod>a:A. P\<cdot>a\<cdot>a\<rightarrow>\<Prod>P:*.P"
wenzelm@62020
   152
  \<comment> \<open>Antisymmetry implies irreflexivity:\<close>
wenzelm@17453
   153
  apply (strip_asms rules)
wenzelm@17453
   154
  apply (rule lam_ss)
wenzelm@17453
   155
    apply (depth_solve1 rules)
wenzelm@17453
   156
   prefer 2
wenzelm@17453
   157
   apply (depth_solve1 rules)
wenzelm@17453
   158
  apply (rule lam_ss)
wenzelm@17453
   159
    apply assumption
wenzelm@17453
   160
   prefer 2
wenzelm@17453
   161
   apply (depth_solve1 rules)
wenzelm@17453
   162
  apply (rule lam_ss)
wenzelm@17453
   163
    apply (depth_solve1 rules)
wenzelm@17453
   164
   prefer 2
wenzelm@17453
   165
   apply (depth_solve1 rules)
wenzelm@17453
   166
  apply (erule pi_elim, assumption, assumption?)+
wenzelm@17453
   167
  done
wenzelm@17453
   168
wenzelm@17453
   169
wenzelm@58617
   170
subsection \<open>LPomega\<close>
wenzelm@17453
   171
wenzelm@61390
   172
schematic_goal (in LPomega) "A:* \<turnstile> \<^bold>\<lambda>P:A\<rightarrow>A\<rightarrow>*. \<^bold>\<lambda>a:A. P\<cdot>a\<cdot>a : ?T"
wenzelm@17453
   173
  by (depth_solve rules)
wenzelm@17453
   174
wenzelm@61390
   175
schematic_goal (in LPomega) "\<turnstile> \<^bold>\<lambda>A:*. \<^bold>\<lambda>P:A\<rightarrow>A\<rightarrow>*. \<^bold>\<lambda>a:A. P\<cdot>a\<cdot>a : ?T"
wenzelm@17453
   176
  by (depth_solve rules)
wenzelm@17453
   177
wenzelm@17453
   178
wenzelm@58617
   179
subsection \<open>Constructions\<close>
wenzelm@17453
   180
wenzelm@61390
   181
schematic_goal (in CC) "\<turnstile> \<^bold>\<lambda>A:*. \<^bold>\<lambda>P:A\<rightarrow>*. \<^bold>\<lambda>a:A. P\<cdot>a\<rightarrow>\<Prod>P:*.P: ?T"
wenzelm@17453
   182
  by (depth_solve rules)
wenzelm@17453
   183
wenzelm@61390
   184
schematic_goal (in CC) "\<turnstile> \<^bold>\<lambda>A:*. \<^bold>\<lambda>P:A\<rightarrow>*.\<Prod>a:A. P\<cdot>a: ?T"
wenzelm@17453
   185
  by (depth_solve rules)
wenzelm@17453
   186
wenzelm@61388
   187
schematic_goal (in CC) "A:* P:A\<rightarrow>* a:A \<turnstile> ?p : (\<Prod>a:A. P\<cdot>a)\<rightarrow>P\<cdot>a"
wenzelm@17453
   188
  apply (strip_asms rules)
wenzelm@17453
   189
  apply (rule lam_ss)
wenzelm@17453
   190
    apply (depth_solve1 rules)
wenzelm@17453
   191
   prefer 2
wenzelm@17453
   192
   apply (depth_solve1 rules)
wenzelm@17453
   193
  apply (erule pi_elim, assumption, assumption)
wenzelm@17453
   194
  done
wenzelm@17453
   195
wenzelm@17453
   196
wenzelm@58617
   197
subsection \<open>Some random examples\<close>
wenzelm@17453
   198
wenzelm@61337
   199
schematic_goal (in LP2) "A:* c:A f:A\<rightarrow>A \<turnstile>
wenzelm@61388
   200
    \<^bold>\<lambda>a:A. \<Prod>P:A\<rightarrow>*.P\<cdot>c \<rightarrow> (\<Prod>x:A. P\<cdot>x\<rightarrow>P\<cdot>(f\<cdot>x)) \<rightarrow> P\<cdot>a : ?T"
wenzelm@17453
   201
  by (depth_solve rules)
wenzelm@17453
   202
wenzelm@61390
   203
schematic_goal (in CC) "\<^bold>\<lambda>A:*. \<^bold>\<lambda>c:A. \<^bold>\<lambda>f:A\<rightarrow>A.
wenzelm@61388
   204
    \<^bold>\<lambda>a:A. \<Prod>P:A\<rightarrow>*.P\<cdot>c \<rightarrow> (\<Prod>x:A. P\<cdot>x\<rightarrow>P\<cdot>(f\<cdot>x)) \<rightarrow> P\<cdot>a : ?T"
wenzelm@17453
   205
  by (depth_solve rules)
wenzelm@17453
   206
wenzelm@61337
   207
schematic_goal (in LP2)
wenzelm@61388
   208
  "A:* a:A b:A \<turnstile> ?p: (\<Prod>P:A\<rightarrow>*.P\<cdot>a\<rightarrow>P\<cdot>b) \<rightarrow> (\<Prod>P:A\<rightarrow>*.P\<cdot>b\<rightarrow>P\<cdot>a)"
wenzelm@62020
   209
  \<comment> \<open>Symmetry of Leibnitz equality\<close>
wenzelm@17453
   210
  apply (strip_asms rules)
wenzelm@17453
   211
  apply (rule lam_ss)
wenzelm@17453
   212
    apply (depth_solve1 rules)
wenzelm@17453
   213
   prefer 2
wenzelm@17453
   214
   apply (depth_solve1 rules)
wenzelm@61388
   215
  apply (erule_tac a = "\<^bold>\<lambda>x:A. \<Prod>Q:A\<rightarrow>*.Q\<cdot>x\<rightarrow>Q\<cdot>a" in pi_elim)
wenzelm@17453
   216
   apply (depth_solve1 rules)
wenzelm@17453
   217
  apply (unfold beta)
wenzelm@17453
   218
  apply (erule imp_elim)
wenzelm@17453
   219
   apply (rule lam_bs)
wenzelm@17453
   220
     apply (depth_solve1 rules)
wenzelm@17453
   221
    prefer 2
wenzelm@17453
   222
    apply (depth_solve1 rules)
wenzelm@17453
   223
   apply (rule lam_ss)
wenzelm@17453
   224
     apply (depth_solve1 rules)
wenzelm@17453
   225
    prefer 2
wenzelm@17453
   226
    apply (depth_solve1 rules)
wenzelm@17453
   227
   apply assumption
wenzelm@17453
   228
  apply assumption
wenzelm@17453
   229
  done
wenzelm@17453
   230
wenzelm@17453
   231
end