src/FOL/ex/LocaleTest.thy
author ballarin
Mon, 11 Apr 2005 12:34:34 +0200
changeset 15696 1da4ce092c0b
parent 15624 484178635bd8
child 15763 b901a127ac73
permissions -rw-r--r--
First release of interpretation commands.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
     1
(*  Title:      FOL/ex/LocaleTest.thy
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
     2
    ID:         $Id$
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
     3
    Author:     Clemens Ballarin
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
     4
    Copyright (c) 2005 by Clemens Ballarin
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
     5
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
     6
Collection of regression tests for locales.
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
     7
*)
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
     8
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
     9
header {* Test of Locale instantiation *}
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    10
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    11
theory LocaleTest = FOL:
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    12
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    13
ML {* set quick_and_dirty *}    (* allow for thm command in batch mode *)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    14
ML {* set Toplevel.debug *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    15
ML {* set show_hyps *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    16
ML {* set show_sorts *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    17
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    18
section {* interpretation *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    19
15598
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    20
(* interpretation input syntax *)
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    21
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    22
locale L
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    23
locale M = fixes a and b and c
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    24
15598
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    25
interpretation test [simp]: L + M a b c [x y z] .
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    26
15598
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    27
print_interps L
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    28
print_interps M
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    29
15624
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
    30
interpretation test [simp]: L print_interps M .
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    31
15598
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    32
interpretation L .
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    33
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    34
(* processing of locale expression *)
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    35
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    36
locale A = fixes a assumes asm_A: "a = a"
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    37
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    38
locale (open) B = fixes b assumes asm_B [simp]: "b = b"
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    39
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    40
locale C = A + B + assumes asm_C: "c = c"
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    41
  (* TODO: independent type var in c, prohibit locale declaration *)
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    42
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    43
locale D = A + B + fixes d defines def_D: "d == (a = b)"
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    44
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    45
theorem (in A)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    46
  includes D
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    47
  shows True ..
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    48
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    49
theorem (in D) True ..
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    50
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    51
typedecl i
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    52
arities i :: "term"
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    53
15598
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    54
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    55
interpretation p1: C ["X::'b" "Y::'b"] by (auto intro: A.intro C_axioms.intro)
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    56
  (* both X and Y get type 'b since 'b is the internal type of parameter b,
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    57
     not wanted, but put up with for now. *)
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    58
15598
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    59
print_interps A
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    60
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    61
(* possible accesses *)
15624
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
    62
thm p1.a.asm_A thm LocaleTest.p1.a.asm_A
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
    63
thm LocaleTest.asm_A thm p1.asm_A
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    64
15624
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
    65
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
    66
(* without prefix *)
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
    67
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
    68
interpretation C ["W::'b" "Z::'b"] by (auto intro: A.intro C_axioms.intro)
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
    69
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
    70
print_interps A
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
    71
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    72
(* possible accesses *)
15624
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
    73
thm a.asm_A thm asm_A thm LocaleTest.a.asm_A thm LocaleTest.asm_A
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    74
15598
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    75
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    76
interpretation p2: D [X Y "Y = X"] by (auto intro: A.intro simp: eq_commute)
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    77
15598
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    78
print_interps D
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    79
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    80
thm p2.a.asm_A
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    81
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    82
15624
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
    83
interpretation p3: D [X Y] .
15598
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    84
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    85
(* duplicate: not registered *)
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    86
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    87
(* thm p3.a.asm_A *)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    88
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    89
15598
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    90
print_interps A
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    91
print_interps B
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    92
print_interps C
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    93
print_interps D
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    94
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    95
(* not permitted
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    96
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    97
interpretation p4: A ["?x::?'a1"] apply (rule A.intro) apply rule done
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    98
15598
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    99
print_interps A
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   100
*)
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
   101
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   102
interpretation p10: D + D a' b' d' [X Y _ U V _] by (auto intro: A.intro)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   103
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   104
corollary (in D) th_x: True ..
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   105
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   106
(* possible accesses: for each registration *)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   107
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   108
thm p2.th_x thm p3.th_x thm p10.th_x
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   109
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   110
lemma (in D) th_y: "d == (a = b)" .
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   111
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   112
thm p2.th_y thm p3.th_y thm p10.th_y
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   113
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   114
lemmas (in D) th_z = th_y
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   115
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   116
thm p2.th_z
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   117
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   118
thm asm_A
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   119
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   120
section {* Interpretation in proof contexts *}
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
   121
15624
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   122
theorem True
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   123
proof -
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   124
  fix alpha::i and beta::i and gamma::i
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   125
  have alpha_A: "A(alpha)" by (auto intro: A.intro)
15624
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   126
  then interpret p5: A [alpha] .
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   127
  print_interps A
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   128
  thm p5.asm_A
15624
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   129
  interpret p6: C [alpha beta] by (auto intro: C_axioms.intro)
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   130
  print_interps A   (* p6 not added! *)
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   131
  print_interps C
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   132
qed rule
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   133
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   134
theorem (in A) True
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   135
proof -
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   136
  print_interps A
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   137
  fix beta and gamma
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   138
  interpret p9: D [a beta _]
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   139
    (* no proof obligation for A !!! *)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   140
    apply - apply (rule refl) apply assumption done
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   141
qed rule
15624
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   142
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   143
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   144
(* Definition involving free variable *)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   145
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   146
ML {* reset show_sorts *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   147
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   148
locale E = fixes e defines e_def: "e(x) == x & x"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   149
  notes e_def2 = e_def
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   150
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   151
lemma (in E) True thm e_def by fast
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   152
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   153
interpretation p7: E ["(%x. x)"] by simp
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   154
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   155
(* TODO: goal mustn't be beta-reduced here, is doesn't match meta-hyp *)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   156
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   157
thm p7.e_def2
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   158
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   159
locale E' = fixes e defines e_def: "e == (%x. x & x)"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   160
  notes e_def2 = e_def
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   161
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   162
interpretation p7': E' ["(%x. x)"] by simp
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   163
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   164
thm p7'.e_def2
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   165
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   166
(* Definition involving free variable in assm *)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   167
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   168
locale (open) F = fixes f assumes asm_F: "f --> x"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   169
  notes asm_F2 = asm_F
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   170
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   171
interpretation p8: F ["False"] by fast
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   172
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   173
thm p8.asm_F2
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   174
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   175
subsection {* Locale without assumptions *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   176
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   177
locale L1 = notes rev_conjI [intro] = conjI [THEN iffD1 [OF conj_commute]]
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   178
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   179
lemma "[| P; Q |] ==> P & Q"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   180
proof -
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   181
  interpret my: L1 .           txt {* No chained fact required. *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   182
  assume Q and P               txt {* order reversed *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   183
  then show "P & Q" ..         txt {* Applies @{thm my.rev_conjI}. *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   184
qed
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   185
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   186
locale L11 = notes rev_conjI = conjI [THEN iffD1 [OF conj_commute]]
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   187
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   188
lemma "[| P; Q |] ==> P & Q"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   189
proof -
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   190
  interpret [intro]: L11 .     txt {* Attribute supplied at instantiation. *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   191
  assume Q and P
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   192
  then show "P & Q" ..
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   193
qed
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   194
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   195
subsection {* Simple locale with assumptions *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   196
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   197
consts bin :: "[i, i] => i" (infixl "#" 60)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   198
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   199
axioms i_assoc: "(x # y) # z = x # (y # z)"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   200
  i_comm: "x # y = y # x"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   201
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   202
locale L2 =
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   203
  fixes OP (infixl "+" 60)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   204
  assumes assoc: "(x + y) + z = x + (y + z)"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   205
    and comm: "x + y = y + x"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   206
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   207
lemma (in L2) lcomm: "x + (y + z) = y + (x + z)"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   208
proof -
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   209
  have "x + (y + z) = (x + y) + z" by (simp add: assoc)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   210
  also have "... = (y + x) + z" by (simp add: comm)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   211
  also have "... = y + (x + z)" by (simp add: assoc)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   212
  finally show ?thesis .
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   213
qed
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   214
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   215
lemmas (in L2) AC = comm assoc lcomm
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   216
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   217
lemma "(x::i) # y # z # w = y # x # w # z"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   218
proof -
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   219
  interpret my: L2 ["op #"] by (rule L2.intro [of "op #", OF i_assoc i_comm])
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   220
    txt {* Chained fact required to discharge assumptions of @{text L2}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   221
      and instantiate parameters. *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   222
  show ?thesis by (simp only: my.OP.AC)  (* or simply AC *)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   223
qed
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   224
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   225
subsection {* Nested locale with assumptions *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   226
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   227
locale L3 =
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   228
  fixes OP (infixl "+" 60)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   229
  assumes assoc: "(x + y) + z = x + (y + z)"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   230
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   231
locale L4 = L3 +
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   232
  assumes comm: "x + y = y + x"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   233
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   234
lemma (in L4) lcomm: "x + (y + z) = y + (x + z)"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   235
proof -
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   236
  have "x + (y + z) = (x + y) + z" by (simp add: assoc)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   237
  also have "... = (y + x) + z" by (simp add: comm)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   238
  also have "... = y + (x + z)" by (simp add: assoc)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   239
  finally show ?thesis .
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   240
qed
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   241
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   242
lemmas (in L4) AC = comm assoc lcomm
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   243
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   244
lemma "(x::i) # y # z # w = y # x # w # z"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   245
proof -
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   246
  interpret my: L4 ["op #"]
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   247
    by (auto intro: L3.intro L4_axioms.intro i_assoc i_comm)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   248
  show ?thesis by (simp only: my.OP.AC)  (* or simply AC *)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   249
qed
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   250
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   251
subsection {* Locale with definition *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   252
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   253
text {* This example is admittedly not very creative :-) *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   254
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   255
locale L5 = L4 + var A +
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   256
  defines A_def: "A == True"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   257
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   258
lemma (in L5) lem: A
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   259
  by (unfold A_def) rule
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   260
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   261
lemma "L5(op #) ==> True"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   262
proof -
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   263
  assume "L5(op #)"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   264
  then interpret L5 ["op #"] by (auto intro: L5.axioms)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   265
  show ?thesis by (rule lem)  (* lem instantiated to True *)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   266
qed
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   267
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   268
subsection {* Instantiation in a context with target *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   269
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   270
lemma (in L4)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   271
  fixes A (infixl "$" 60)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   272
  assumes A: "L4(A)"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   273
  shows "(x::i) $ y $ z $ w = y $ x $ w $ z"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   274
proof -
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   275
  from A interpret A: L4 ["A"] by (auto intro: L4.axioms)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   276
  show ?thesis by (simp only: A.OP.AC)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   277
qed
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   278
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
   279
end