src/FOL/ex/LocaleTest.thy
author ballarin
Thu, 07 Jul 2005 15:52:31 +0200
changeset 16736 1e792b32abef
parent 16620 2a7f46324218
child 17000 552df70f52c2
permissions -rw-r--r--
Preparations for interpretation of locales in locales.
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
16102
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
     9
header {* Test of Locale Interpretation *}
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    10
16102
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    11
theory LocaleTest
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    12
imports FOL
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    13
begin
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    14
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    15
ML {* set quick_and_dirty *}    (* allow for thm command in batch mode *)
16168
adb83939177f Locales: new element constrains, parameter renaming with syntax,
ballarin
parents: 16102
diff changeset
    16
ML {* set Toplevel.debug *}
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    17
ML {* set show_hyps *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    18
ML {* set show_sorts *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    19
16102
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    20
section {* Renaming with Syntax *}
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    21
16168
adb83939177f Locales: new element constrains, parameter renaming with syntax,
ballarin
parents: 16102
diff changeset
    22
adb83939177f Locales: new element constrains, parameter renaming with syntax,
ballarin
parents: 16102
diff changeset
    23
locale (open) S = var mult +
16102
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    24
  assumes "mult(x, y) = mult(y, x)"
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    25
16168
adb83939177f Locales: new element constrains, parameter renaming with syntax,
ballarin
parents: 16102
diff changeset
    26
print_locale S
adb83939177f Locales: new element constrains, parameter renaming with syntax,
ballarin
parents: 16102
diff changeset
    27
16325
a6431098a929 Fixed "axiom" generation for mixed locales with and without predicates.
ballarin
parents: 16168
diff changeset
    28
locale S' = S mult (infixl "**" 60)
16102
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    29
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    30
print_locale S'
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    31
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    32
locale T = var mult (infixl "**" 60) +
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    33
  assumes "x ** y = y ** x"
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    34
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    35
locale U = T mult (infixl "**" 60) + T add (infixl "++" 55) + var h +
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    36
  assumes hom: "h(x ** y) = h(x) ++ h(y)"
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    37
16168
adb83939177f Locales: new element constrains, parameter renaming with syntax,
ballarin
parents: 16102
diff changeset
    38
locale V = U _ add
16102
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    39
16168
adb83939177f Locales: new element constrains, parameter renaming with syntax,
ballarin
parents: 16102
diff changeset
    40
adb83939177f Locales: new element constrains, parameter renaming with syntax,
ballarin
parents: 16102
diff changeset
    41
section {* Constrains *}
16102
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    42
16168
adb83939177f Locales: new element constrains, parameter renaming with syntax,
ballarin
parents: 16102
diff changeset
    43
locale Z = fixes a (structure)
adb83939177f Locales: new element constrains, parameter renaming with syntax,
ballarin
parents: 16102
diff changeset
    44
locale Z' = Z +
adb83939177f Locales: new element constrains, parameter renaming with syntax,
ballarin
parents: 16102
diff changeset
    45
  constrains a :: "'a => 'b"
adb83939177f Locales: new element constrains, parameter renaming with syntax,
ballarin
parents: 16102
diff changeset
    46
  assumes "a (x :: 'a) = a (y)"
adb83939177f Locales: new element constrains, parameter renaming with syntax,
ballarin
parents: 16102
diff changeset
    47
print_locale Z'
16102
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    48
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    49
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
    50
section {* Interpretation *}
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    51
15598
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    52
(* interpretation input syntax *)
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    53
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    54
locale L
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    55
locale M = fixes a and b and c
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    56
15598
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    57
interpretation test [simp]: L + M a b c [x y z] .
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    58
15837
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
    59
print_interps L    (* output: test *)
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
    60
print_interps M    (* output: test *)
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    61
15624
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
    62
interpretation test [simp]: L print_interps M .
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    63
15598
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    64
interpretation L .
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    65
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    66
(* processing of locale expression *)
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    67
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    68
locale A = fixes a assumes asm_A: "a = a"
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    69
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    70
locale (open) B = fixes b assumes asm_B [simp]: "b = b"
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    71
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    72
locale C = A + B + assumes asm_C: "c = c"
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    73
  (* TODO: independent type var in c, prohibit locale declaration *)
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    74
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    75
locale D = A + B + fixes d defines def_D: "d == (a = b)"
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    76
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    77
theorem (in A)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    78
  includes D
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    79
  shows True ..
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    80
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    81
theorem (in D) True ..
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    82
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    83
typedecl i
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    84
arities i :: "term"
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    85
15598
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
    86
15837
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
    87
interpretation p1: C ["X::i" "Y::i"] by (auto intro: A.intro C_axioms.intro)
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    88
15837
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
    89
print_interps A  (* output: p1 *)
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
    90
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    91
(* possible accesses *)
15624
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
    92
thm p1.a.asm_A thm LocaleTest.p1.a.asm_A
15763
b901a127ac73 Interpretation supports statically scoped attributes; documentation.
ballarin
parents: 15696
diff changeset
    93
thm p1.asm_A thm LocaleTest.p1.asm_A
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    94
15624
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
    95
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
    96
(* without prefix *)
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
    97
15837
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
    98
interpretation C ["W::i" "Z::i"] .  (* subsumed by p1: C *)
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
    99
interpretation C ["W::'a" "Z::i"] by (auto intro: A.intro C_axioms.intro)
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   100
  (* subsumes p1: A and p1: C *)
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   101
15598
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
   102
15837
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   103
print_interps A  (* output: <no prefix>, p1 *)
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
   104
15837
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   105
(* possible accesses *)
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   106
thm asm_C thm a_b.asm_C thm LocaleTest.a_b.asm_C thm LocaleTest.a_b.asm_C
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   107
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
   108
15837
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   109
interpretation p2: D [X "Y::i" "Y = X"] by (simp add: eq_commute)
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   110
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   111
print_interps A  (* output: <no prefix>, p1 *)
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   112
print_interps D  (* output: p2 *)
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   113
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   114
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   115
interpretation p3: D [X "Y::i"] .
15598
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
   116
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
   117
(* duplicate: not registered *)
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   118
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   119
(* thm p3.a.asm_A *)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   120
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
   121
15837
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   122
print_interps A  (* output: <no prefix>, p1 *)
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   123
print_interps B  (* output: p1 *)
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   124
print_interps C  (* output: <no name>, p1 *)
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   125
print_interps D  (* output: p2, p3 *)
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
   126
15837
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   127
(* schematic vars in instantiation not permitted *)
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   128
(*
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   129
interpretation p4: A ["?x::?'a1"] apply (rule A.intro) apply rule done
15598
4ab52355bb53 Registrations of global locale interpretations: improved, better naming.
ballarin
parents: 15596
diff changeset
   130
print_interps A
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   131
*)
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
   132
16102
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
   133
interpretation p10: D + D a' b' d' [X "Y::i" _ u "v::i" _] .
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   134
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   135
corollary (in D) th_x: True ..
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   136
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   137
(* possible accesses: for each registration *)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   138
15837
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   139
thm p2.th_x thm p3.th_x
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   140
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   141
lemma (in D) th_y: "d == (a = b)" .
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   142
15837
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   143
thm p2.th_y thm p3.th_y
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   144
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   145
lemmas (in D) th_z = th_y
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   146
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   147
thm p2.th_z
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   148
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   149
section {* Interpretation in proof contexts *}
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
   150
16102
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
   151
locale F = fixes f assumes asm_F: "f & f --> f"
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
   152
15624
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   153
theorem True
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   154
proof -
16102
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
   155
  fix alpha::i and beta::'a and gamma::o
15837
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   156
  (* FIXME: omitting type of beta leads to error later at interpret p6 *)
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   157
  have alpha_A: "A(alpha)" by (auto intro: A.intro)
15837
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   158
  interpret p5: A [alpha] .  (* subsumed *)
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   159
  print_interps A  (* output: <no prefix>, p1 *)
15624
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   160
  interpret p6: C [alpha beta] by (auto intro: C_axioms.intro)
15837
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   161
  print_interps A   (* output: <no prefix>, p1 *)
7a567dcd4cda Subsumption of locale interpretations.
ballarin
parents: 15763
diff changeset
   162
  print_interps C   (* output: <no prefix>, p1, p6 *)
16102
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
   163
  interpret p11: F [gamma] by (fast intro: F.intro)
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
   164
  thm p11.asm_F      (* gamma is a Free *)
15624
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   165
qed rule
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   166
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   167
theorem (in A) True
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   168
proof -
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   169
  print_interps A
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   170
  fix beta and gamma
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   171
  interpret p9: D [a beta _]
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   172
    (* no proof obligation for A !!! *)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   173
    apply - apply (rule refl) apply assumption done
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   174
qed rule
15624
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   175
484178635bd8 Further work on interpretation commands. New command `interpret' for
ballarin
parents: 15598
diff changeset
   176
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   177
(* Definition involving free variable *)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   178
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   179
ML {* reset show_sorts *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   180
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   181
locale E = fixes e defines e_def: "e(x) == x & x"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   182
  notes e_def2 = e_def
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   183
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   184
lemma (in E) True thm e_def by fast
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   185
16620
2a7f46324218 Proper treatment of beta-redexes in witness theorems.
ballarin
parents: 16325
diff changeset
   186
interpretation p7: E ["%x. x"] by simp
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   187
16620
2a7f46324218 Proper treatment of beta-redexes in witness theorems.
ballarin
parents: 16325
diff changeset
   188
thm p7.e_def2 (* has no premise *)
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   189
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   190
locale E' = fixes e defines e_def: "e == (%x. x & x)"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   191
  notes e_def2 = e_def
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   192
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   193
interpretation p7': E' ["(%x. x)"] by simp
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   194
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   195
thm p7'.e_def2
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   196
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   197
(* Definition involving free variable in assm *)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   198
16102
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
   199
locale (open) G = fixes g assumes asm_G: "g --> x"
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
   200
  notes asm_G2 = asm_G
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   201
16102
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
   202
interpretation p8: G ["False"] by fast
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   203
16102
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 15837
diff changeset
   204
thm p8.asm_G2
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   205
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   206
subsection {* Locale without assumptions *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   207
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   208
locale L1 = notes rev_conjI [intro] = conjI [THEN iffD1 [OF conj_commute]]
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   209
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   210
lemma "[| P; Q |] ==> P & Q"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   211
proof -
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   212
  interpret my: L1 .           txt {* No chained fact required. *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   213
  assume Q and P               txt {* order reversed *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   214
  then show "P & Q" ..         txt {* Applies @{thm my.rev_conjI}. *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   215
qed
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   216
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   217
locale L11 = notes rev_conjI = conjI [THEN iffD1 [OF conj_commute]]
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   218
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   219
lemma "[| P; Q |] ==> P & Q"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   220
proof -
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   221
  interpret [intro]: L11 .     txt {* Attribute supplied at instantiation. *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   222
  assume Q and P
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   223
  then show "P & Q" ..
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   224
qed
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   225
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   226
subsection {* Simple locale with assumptions *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   227
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   228
consts bin :: "[i, i] => i" (infixl "#" 60)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   229
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   230
axioms i_assoc: "(x # y) # z = x # (y # z)"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   231
  i_comm: "x # y = y # x"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   232
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   233
locale L2 =
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   234
  fixes OP (infixl "+" 60)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   235
  assumes assoc: "(x + y) + z = x + (y + z)"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   236
    and comm: "x + y = y + x"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   237
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   238
lemma (in L2) lcomm: "x + (y + z) = y + (x + z)"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   239
proof -
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   240
  have "x + (y + z) = (x + y) + z" by (simp add: assoc)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   241
  also have "... = (y + x) + z" by (simp add: comm)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   242
  also have "... = y + (x + z)" by (simp add: assoc)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   243
  finally show ?thesis .
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   244
qed
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   245
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   246
lemmas (in L2) AC = comm assoc lcomm
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   247
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   248
lemma "(x::i) # y # z # w = y # x # w # z"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   249
proof -
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   250
  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
   251
    txt {* Chained fact required to discharge assumptions of @{text L2}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   252
      and instantiate parameters. *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   253
  show ?thesis by (simp only: my.OP.AC)  (* or simply AC *)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   254
qed
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   255
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   256
subsection {* Nested locale with assumptions *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   257
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   258
locale L3 =
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   259
  fixes OP (infixl "+" 60)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   260
  assumes assoc: "(x + y) + z = x + (y + z)"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   261
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   262
locale L4 = L3 +
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   263
  assumes comm: "x + y = y + x"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   264
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   265
lemma (in L4) lcomm: "x + (y + z) = y + (x + z)"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   266
proof -
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   267
  have "x + (y + z) = (x + y) + z" by (simp add: assoc)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   268
  also have "... = (y + x) + z" by (simp add: comm)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   269
  also have "... = y + (x + z)" by (simp add: assoc)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   270
  finally show ?thesis .
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   271
qed
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   272
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   273
lemmas (in L4) AC = comm assoc lcomm
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   274
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   275
lemma "(x::i) # y # z # w = y # x # w # z"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   276
proof -
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   277
  interpret my: L4 ["op #"]
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   278
    by (auto intro: L3.intro L4_axioms.intro i_assoc i_comm)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   279
  show ?thesis by (simp only: my.OP.AC)  (* or simply AC *)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   280
qed
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   281
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   282
subsection {* Locale with definition *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   283
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   284
text {* This example is admittedly not very creative :-) *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   285
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   286
locale L5 = L4 + var A +
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   287
  defines A_def: "A == True"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   288
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   289
lemma (in L5) lem: A
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   290
  by (unfold A_def) rule
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   291
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   292
lemma "L5(op #) ==> True"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   293
proof -
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   294
  assume "L5(op #)"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   295
  then interpret L5 ["op #"] by (auto intro: L5.axioms)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   296
  show ?thesis by (rule lem)  (* lem instantiated to True *)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   297
qed
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   298
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   299
subsection {* Instantiation in a context with target *}
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   300
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   301
lemma (in L4)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   302
  fixes A (infixl "$" 60)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   303
  assumes A: "L4(A)"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   304
  shows "(x::i) $ y $ z $ w = y $ x $ w $ z"
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   305
proof -
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   306
  from A interpret A: L4 ["A"] by (auto intro: L4.axioms)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   307
  show ?thesis by (simp only: A.OP.AC)
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   308
qed
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   309
16736
1e792b32abef Preparations for interpretation of locales in locales.
ballarin
parents: 16620
diff changeset
   310
section {* Interpretation in Locales *}
1e792b32abef Preparations for interpretation of locales in locales.
ballarin
parents: 16620
diff changeset
   311
1e792b32abef Preparations for interpretation of locales in locales.
ballarin
parents: 16620
diff changeset
   312
interpretation M < L .
1e792b32abef Preparations for interpretation of locales in locales.
ballarin
parents: 16620
diff changeset
   313
15596
8665d08085df First version of global registration command.
ballarin
parents:
diff changeset
   314
end