src/FOL/ex/NewLocaleTest.thy
author ballarin
Mon, 01 Dec 2008 16:59:31 +0100
changeset 28936 f1647bf418f5
parent 28927 7e631979922f
child 28993 829e684b02ef
permissions -rw-r--r--
No resolution of patterns within context statements.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28873
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
     1
(*  Title:      FOL/ex/NewLocaleTest.thy
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
     2
    ID:         $Id$
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
     3
    Author:     Clemens Ballarin, TU Muenchen
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
     4
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
     5
Testing environment for locale expressions --- experimental.
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
     6
*)
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
     7
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
     8
theory NewLocaleTest
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
     9
imports NewLocaleSetup
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    10
begin
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    11
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    12
ML_val {* set new_locales *}
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    13
ML_val {* set Toplevel.debug *}
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    14
ML_val {* set show_hyps *}
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    15
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    16
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    17
typedecl int arities int :: "term"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    18
consts plus :: "int => int => int" (infixl "+" 60)
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    19
  zero :: int ("0")
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    20
  minus :: "int => int" ("- _")
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    21
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    22
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    23
text {* Inference of parameter types *}
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    24
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    25
locale param1 = fixes p
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    26
print_locale! param1
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    27
28881
df2525ad10c6 Some regression tests for theorem statements.
ballarin
parents: 28873
diff changeset
    28
locale param2 = fixes p :: 'b
28873
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    29
print_locale! param2
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    30
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    31
(*
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    32
locale param_top = param2 r for r :: "'b :: {}"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    33
print_locale! param_top
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    34
*)
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    35
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    36
locale param3 = fixes p (infix ".." 50)
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    37
print_locale! param3
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    38
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    39
locale param4 = fixes p :: "'a => 'a => 'a" (infix ".." 50)
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    40
print_locale! param4
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    41
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    42
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    43
text {* Incremental type constraints *}
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    44
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    45
locale constraint1 =
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    46
  fixes  prod (infixl "**" 65)
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    47
  assumes l_id: "x ** y = x"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    48
  assumes assoc: "(x ** y) ** z = x ** (y ** z)"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    49
print_locale! constraint1
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    50
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    51
locale constraint2 =
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    52
  fixes p and q
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    53
  assumes "p = q"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    54
print_locale! constraint2
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    55
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    56
28881
df2525ad10c6 Some regression tests for theorem statements.
ballarin
parents: 28873
diff changeset
    57
text {* Inheritance *}
28873
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    58
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    59
locale semi =
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    60
  fixes prod (infixl "**" 65)
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    61
  assumes assoc: "(x ** y) ** z = x ** (y ** z)"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    62
print_locale! semi thm semi_def
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    63
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    64
locale lgrp = semi +
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    65
  fixes one and inv
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    66
  assumes lone: "one ** x = x"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    67
    and linv: "inv(x) ** x = one"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    68
print_locale! lgrp thm lgrp_def lgrp_axioms_def
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    69
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    70
locale add_lgrp = semi "op ++" for sum (infixl "++" 60) +
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    71
  fixes zero and neg
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    72
  assumes lzero: "zero ++ x = x"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    73
    and lneg: "neg(x) ++ x = zero"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    74
print_locale! add_lgrp thm add_lgrp_def add_lgrp_axioms_def
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    75
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    76
locale rev_lgrp = semi "%x y. y ++ x" for sum (infixl "++" 60)
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    77
print_locale! rev_lgrp thm rev_lgrp_def
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    78
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    79
locale hom = f: semi f + g: semi g for f and g
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    80
print_locale! hom thm hom_def
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    81
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    82
locale perturbation = semi + d: semi "%x y. delta(x) ** delta(y)" for delta
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    83
print_locale! perturbation thm perturbation_def
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    84
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    85
locale pert_hom = d1: perturbation f d1 + d2: perturbation f d2 for f d1 d2
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    86
print_locale! pert_hom thm pert_hom_def
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    87
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    88
text {* Alternative expression, obtaining nicer names in @{text "semi f"}. *}
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    89
locale pert_hom' = semi f + d1: perturbation f d1 + d2: perturbation f d2 for f d1 d2
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    90
print_locale! pert_hom' thm pert_hom'_def
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    91
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    92
28881
df2525ad10c6 Some regression tests for theorem statements.
ballarin
parents: 28873
diff changeset
    93
text {* Syntax declarations *}
28873
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    94
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    95
locale logic =
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    96
  fixes land (infixl "&&" 55)
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    97
    and lnot ("-- _" [60] 60)
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    98
  assumes assoc: "(x && y) && z = x && (y && z)"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    99
    and notnot: "-- (-- x) = x"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   100
begin
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   101
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   102
definition lor (infixl "||" 50) where
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   103
  "x || y = --(-- x && -- y)"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   104
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   105
end
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   106
print_locale! logic
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   107
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   108
locale use_decl = logic + semi "op ||"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   109
print_locale! use_decl thm use_decl_def
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   110
28881
df2525ad10c6 Some regression tests for theorem statements.
ballarin
parents: 28873
diff changeset
   111
df2525ad10c6 Some regression tests for theorem statements.
ballarin
parents: 28873
diff changeset
   112
text {* Theorem statements *}
df2525ad10c6 Some regression tests for theorem statements.
ballarin
parents: 28873
diff changeset
   113
28873
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   114
lemma (in lgrp) lcancel:
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   115
  "x ** y = x ** z <-> y = z"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   116
proof
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   117
  assume "x ** y = x ** z"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   118
  then have "inv(x) ** x ** y = inv(x) ** x ** z" by (simp add: assoc)
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   119
  then show "y = z" by (simp add: lone linv)
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   120
qed simp
28881
df2525ad10c6 Some regression tests for theorem statements.
ballarin
parents: 28873
diff changeset
   121
print_locale! lgrp
df2525ad10c6 Some regression tests for theorem statements.
ballarin
parents: 28873
diff changeset
   122
28873
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   123
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   124
locale rgrp = semi +
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   125
  fixes one and inv
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   126
  assumes rone: "x ** one = x"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   127
    and rinv: "x ** inv(x) = one"
28881
df2525ad10c6 Some regression tests for theorem statements.
ballarin
parents: 28873
diff changeset
   128
begin
28873
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   129
28881
df2525ad10c6 Some regression tests for theorem statements.
ballarin
parents: 28873
diff changeset
   130
lemma rcancel:
28873
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   131
  "y ** x = z ** x <-> y = z"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   132
proof
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   133
  assume "y ** x = z ** x"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   134
  then have "y ** (x ** inv(x)) = z ** (x ** inv(x))"
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   135
    by (simp add: assoc [symmetric])
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   136
  then show "y = z" by (simp add: rone rinv)
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   137
qed simp
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   138
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
   139
end
28881
df2525ad10c6 Some regression tests for theorem statements.
ballarin
parents: 28873
diff changeset
   140
print_locale! rgrp
df2525ad10c6 Some regression tests for theorem statements.
ballarin
parents: 28873
diff changeset
   141
28886
9cb1297b6f13 Test for term patterns added.
ballarin
parents: 28881
diff changeset
   142
9cb1297b6f13 Test for term patterns added.
ballarin
parents: 28881
diff changeset
   143
text {* Patterns *}
9cb1297b6f13 Test for term patterns added.
ballarin
parents: 28881
diff changeset
   144
9cb1297b6f13 Test for term patterns added.
ballarin
parents: 28881
diff changeset
   145
lemma (in rgrp)
9cb1297b6f13 Test for term patterns added.
ballarin
parents: 28881
diff changeset
   146
  assumes "y ** x = z ** x" (is ?a)
9cb1297b6f13 Test for term patterns added.
ballarin
parents: 28881
diff changeset
   147
  shows "y = z" (is ?t)
9cb1297b6f13 Test for term patterns added.
ballarin
parents: 28881
diff changeset
   148
proof -
9cb1297b6f13 Test for term patterns added.
ballarin
parents: 28881
diff changeset
   149
  txt {* Weird proof involving patterns from context element and conclusion. *}
9cb1297b6f13 Test for term patterns added.
ballarin
parents: 28881
diff changeset
   150
  {
9cb1297b6f13 Test for term patterns added.
ballarin
parents: 28881
diff changeset
   151
    assume ?a
9cb1297b6f13 Test for term patterns added.
ballarin
parents: 28881
diff changeset
   152
    then have "y ** (x ** inv(x)) = z ** (x ** inv(x))"
9cb1297b6f13 Test for term patterns added.
ballarin
parents: 28881
diff changeset
   153
      by (simp add: assoc [symmetric])
9cb1297b6f13 Test for term patterns added.
ballarin
parents: 28881
diff changeset
   154
    then have ?t by (simp add: rone rinv)
9cb1297b6f13 Test for term patterns added.
ballarin
parents: 28881
diff changeset
   155
  }
9cb1297b6f13 Test for term patterns added.
ballarin
parents: 28881
diff changeset
   156
  note x = this
9cb1297b6f13 Test for term patterns added.
ballarin
parents: 28881
diff changeset
   157
  show ?t by (rule x [OF `?a`])
9cb1297b6f13 Test for term patterns added.
ballarin
parents: 28881
diff changeset
   158
qed
9cb1297b6f13 Test for term patterns added.
ballarin
parents: 28881
diff changeset
   159
28896
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   160
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   161
text {* Interpretation between locales: sublocales *}
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   162
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   163
sublocale lgrp < right: rgrp
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   164
print_facts
28927
7e631979922f Methods intro_locales and unfold_locales apply to both old and new locales.
ballarin
parents: 28903
diff changeset
   165
proof unfold_locales
28896
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   166
  {
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   167
    fix x
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   168
    have "inv(x) ** x ** one = inv(x) ** x" by (simp add: linv lone)
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   169
    then show "x ** one = x" by (simp add: assoc lcancel)
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   170
  }
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   171
  note rone = this
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   172
  {
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   173
    fix x
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   174
    have "inv(x) ** x ** inv(x) = inv(x) ** one"
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   175
      by (simp add: linv lone rone)
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   176
    then show "x ** inv(x) = one" by (simp add: assoc lcancel)
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   177
  }
28903
b3fc3a62247a Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents: 28899
diff changeset
   178
qed
28896
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   179
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   180
(* effect on printed locale *)
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   181
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   182
print_locale! lgrp
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   183
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   184
(* use of derived theorem *)
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   185
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   186
lemma (in lgrp)
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   187
  "y ** x = z ** x <-> y = z"
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   188
  apply (rule rcancel)
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   189
  done
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   190
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   191
(* circular interpretation *)
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   192
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   193
sublocale rgrp < left: lgrp
28927
7e631979922f Methods intro_locales and unfold_locales apply to both old and new locales.
ballarin
parents: 28903
diff changeset
   194
proof unfold_locales
28903
b3fc3a62247a Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents: 28899
diff changeset
   195
  {
b3fc3a62247a Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents: 28899
diff changeset
   196
    fix x
b3fc3a62247a Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents: 28899
diff changeset
   197
    have "one ** (x ** inv(x)) = x ** inv(x)" by (simp add: rinv rone)
b3fc3a62247a Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents: 28899
diff changeset
   198
    then show "one ** x = x" by (simp add: assoc [symmetric] rcancel)
b3fc3a62247a Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents: 28899
diff changeset
   199
  }
b3fc3a62247a Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents: 28899
diff changeset
   200
  note lone = this
b3fc3a62247a Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents: 28899
diff changeset
   201
  {
b3fc3a62247a Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents: 28899
diff changeset
   202
    fix x
b3fc3a62247a Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents: 28899
diff changeset
   203
    have "inv(x) ** (x ** inv(x)) = one ** inv(x)"
b3fc3a62247a Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents: 28899
diff changeset
   204
      by (simp add: rinv lone rone)
b3fc3a62247a Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents: 28899
diff changeset
   205
    then show "inv(x) ** x = one" by (simp add: assoc [symmetric] rcancel)
b3fc3a62247a Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents: 28899
diff changeset
   206
  }
b3fc3a62247a Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents: 28899
diff changeset
   207
qed
28896
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   208
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   209
(* effect on printed locale *)
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   210
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   211
print_locale! rgrp
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   212
print_locale! lgrp
f30016592375 Tests for sublocale command.
ballarin
parents: 28886
diff changeset
   213
28898
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   214
28899
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   215
(* Duality *)
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   216
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   217
locale order =
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   218
  fixes less :: "'a => 'a => o" (infix "<<" 50)
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   219
  assumes refl: "x << x"
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   220
    and trans: "[| x << y; y << z |] ==> x << z"
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   221
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   222
sublocale order < dual: order "%x y. y << x"
28927
7e631979922f Methods intro_locales and unfold_locales apply to both old and new locales.
ballarin
parents: 28903
diff changeset
   223
  apply unfold_locales apply (rule refl) apply (blast intro: trans)
28899
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   224
  done
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   225
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   226
print_locale! order  (* Only two instances of order. *)
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   227
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   228
locale order' =
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   229
  fixes less :: "'a => 'a => o" (infix "<<" 50)
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   230
  assumes refl: "x << x"
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   231
    and trans: "[| x << y; y << z |] ==> x << z"
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   232
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   233
locale order_with_def = order'
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   234
begin
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   235
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   236
definition greater :: "'a => 'a => o" (infix ">>" 50) where
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   237
  "x >> y <-> y << x"
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   238
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   239
end
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   240
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   241
sublocale order_with_def < dual: order' "op >>"
28927
7e631979922f Methods intro_locales and unfold_locales apply to both old and new locales.
ballarin
parents: 28903
diff changeset
   242
  apply unfold_locales
28899
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   243
  unfolding greater_def
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   244
  apply (rule refl) apply (blast intro: trans)
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   245
  done
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   246
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   247
print_locale! order_with_def
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   248
(* Note that decls come after theorems that make use of them.
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   249
  Appears to be harmless at least in this example. *)
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   250
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   251
28898
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   252
(* locale with many parameters ---
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   253
   interpretations generate alternating group A5 *)
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   254
28899
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   255
28898
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   256
locale A5 =
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   257
  fixes A and B and C and D and E
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   258
  assumes eq: "A <-> B <-> C <-> D <-> E"
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   259
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   260
sublocale A5 < 1: A5 _ _ D E C
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   261
print_facts
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   262
  using eq apply (blast intro: A5.intro) done
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   263
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   264
sublocale A5 < 2: A5 C _ E _ A
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   265
print_facts
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   266
  using eq apply (blast intro: A5.intro) done
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   267
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   268
sublocale A5 < 3: A5 B C A _ _
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   269
print_facts
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   270
  using eq apply (blast intro: A5.intro) done
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   271
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   272
(* Any even permutation of parameters is subsumed by the above. *)
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   273
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   274
print_locale! A5
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   275
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   276
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   277
(* Free arguments of instance *)
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   278
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   279
locale trivial =
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   280
  fixes P and Q :: o
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   281
  assumes Q: "P <-> P <-> Q"
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   282
begin
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   283
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   284
lemma Q_triv: "Q" using Q by fast
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   285
28881
df2525ad10c6 Some regression tests for theorem statements.
ballarin
parents: 28873
diff changeset
   286
end
28898
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   287
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   288
sublocale trivial < x: trivial x _
28927
7e631979922f Methods intro_locales and unfold_locales apply to both old and new locales.
ballarin
parents: 28903
diff changeset
   289
  apply unfold_locales using Q by fast
28898
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   290
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   291
print_locale! trivial
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   292
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   293
context trivial begin thm x.Q [where ?x = True] end
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   294
28899
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   295
sublocale trivial < y: trivial Q Q
28927
7e631979922f Methods intro_locales and unfold_locales apply to both old and new locales.
ballarin
parents: 28903
diff changeset
   296
  by unfold_locales
28903
b3fc3a62247a Intro_locales_tac to simplify goals involving locale predicates.
ballarin
parents: 28899
diff changeset
   297
  (* Succeeds since previous interpretation is more general. *)
28899
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   298
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   299
print_locale! trivial  (* No instance for y created (subsumed). *)
7bf5d7f154b8 Perform higher-order pattern matching during round-up.
ballarin
parents: 28898
diff changeset
   300
28898
530c7d28a962 Proper treatment of expressions with free arguments.
ballarin
parents: 28896
diff changeset
   301
end