src/FOL/ex/Locale_Test/Locale_Test1.thy
author ballarin
Tue, 03 Sep 2013 22:12:47 +0200
changeset 53367 1f383542226b
parent 53366 c8c548d83862
child 55380 4de48353034e
permissions -rw-r--r--
New test case: interpretation in named contexts is not persistent.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
     1
(*  Title:      FOL/ex/Locale_Test/Locale_Test1.thy
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
     2
    Author:     Clemens Ballarin, TU Muenchen
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
     3
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
     4
Test environment for the locale implementation.
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
     5
*)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
     6
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
     7
theory Locale_Test1
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
     8
imports FOL
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
     9
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    10
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    11
typedecl int arities int :: "term"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    12
consts plus :: "int => int => int" (infixl "+" 60)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    13
  zero :: int ("0")
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    14
  minus :: "int => int" ("- _")
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    15
41779
a68f503805ed modernized specifications;
wenzelm
parents: 41435
diff changeset
    16
axiomatization where
a68f503805ed modernized specifications;
wenzelm
parents: 41435
diff changeset
    17
  int_assoc: "(x + y::int) + z = x + (y + z)" and
a68f503805ed modernized specifications;
wenzelm
parents: 41435
diff changeset
    18
  int_zero: "0 + x = x" and
a68f503805ed modernized specifications;
wenzelm
parents: 41435
diff changeset
    19
  int_minus: "(-x) + x = 0" and
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    20
  int_minus2: "-(-x) = x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    21
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    22
section {* Inference of parameter types *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    23
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    24
locale param1 = fixes p
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    25
print_locale! param1
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    26
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    27
locale param2 = fixes p :: 'b
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    28
print_locale! param2
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    29
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    30
(*
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    31
locale param_top = param2 r for r :: "'b :: {}"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    32
  Fails, cannot generalise parameter.
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    33
*)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    34
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    35
locale param3 = fixes p (infix ".." 50)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    36
print_locale! param3
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    37
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    38
locale param4 = fixes p :: "'a => 'a => 'a" (infix ".." 50)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    39
print_locale! param4
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    40
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    41
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    42
subsection {* Incremental type constraints *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    43
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    44
locale constraint1 =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    45
  fixes  prod (infixl "**" 65)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    46
  assumes l_id: "x ** y = x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    47
  assumes assoc: "(x ** y) ** z = x ** (y ** z)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    48
print_locale! constraint1
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    49
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    50
locale constraint2 =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    51
  fixes p and q
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    52
  assumes "p = q"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    53
print_locale! constraint2
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    54
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    55
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    56
section {* Inheritance *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    57
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    58
locale semi =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    59
  fixes prod (infixl "**" 65)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    60
  assumes assoc: "(x ** y) ** z = x ** (y ** z)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    61
print_locale! semi thm semi_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    62
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    63
locale lgrp = semi +
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    64
  fixes one and inv
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    65
  assumes lone: "one ** x = x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    66
    and linv: "inv(x) ** x = one"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    67
print_locale! lgrp thm lgrp_def lgrp_axioms_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    68
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    69
locale add_lgrp = semi "op ++" for sum (infixl "++" 60) +
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    70
  fixes zero and neg
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    71
  assumes lzero: "zero ++ x = x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    72
    and lneg: "neg(x) ++ x = zero"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    73
print_locale! add_lgrp thm add_lgrp_def add_lgrp_axioms_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    74
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    75
locale rev_lgrp = semi "%x y. y ++ x" for sum (infixl "++" 60)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    76
print_locale! rev_lgrp thm rev_lgrp_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    77
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    78
locale hom = f: semi f + g: semi g for f and g
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    79
print_locale! hom thm hom_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    80
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    81
locale perturbation = semi + d: semi "%x y. delta(x) ** delta(y)" for delta
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    82
print_locale! perturbation thm perturbation_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    83
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    84
locale pert_hom = d1: perturbation f d1 + d2: perturbation f d2 for f d1 d2
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    85
print_locale! pert_hom thm pert_hom_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    86
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    87
text {* Alternative expression, obtaining nicer names in @{text "semi f"}. *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    88
locale pert_hom' = semi f + d1: perturbation f d1 + d2: perturbation f d2 for f d1 d2
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    89
print_locale! pert_hom' thm pert_hom'_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    90
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    91
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    92
section {* Syntax declarations *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    93
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    94
locale logic =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    95
  fixes land (infixl "&&" 55)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    96
    and lnot ("-- _" [60] 60)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    97
  assumes assoc: "(x && y) && z = x && (y && z)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    98
    and notnot: "-- (-- x) = x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    99
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   100
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   101
definition lor (infixl "||" 50) where
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   102
  "x || y = --(-- x && -- y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   103
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   104
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   105
print_locale! logic
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   106
49756
28e37eab4e6f added some ad-hoc namespace prefixes to avoid duplicate facts;
wenzelm
parents: 43543
diff changeset
   107
locale use_decl = l: logic + semi "op ||"
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   108
print_locale! use_decl thm use_decl_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   109
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   110
locale extra_type =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   111
  fixes a :: 'a
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   112
    and P :: "'a => 'b => o"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   113
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   114
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   115
definition test :: "'a => o" where
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   116
  "test(x) <-> (ALL b. P(x, b))"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   117
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   118
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   119
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   120
term extra_type.test thm extra_type.test_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   121
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   122
interpretation var?: extra_type "0" "%x y. x = 0" .
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   123
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   124
thm var.test_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   125
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   126
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   127
text {* Under which circumstances term syntax remains active. *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   128
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   129
locale "syntax" =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   130
  fixes p1 :: "'a => 'b"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   131
    and p2 :: "'b => o"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   132
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   133
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   134
definition d1 :: "'a => o" where "d1(x) <-> ~ p2(p1(x))"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   135
definition d2 :: "'b => o" where "d2(x) <-> ~ p2(x)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   136
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   137
thm d1_def d2_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   138
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   139
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   140
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   141
thm syntax.d1_def syntax.d2_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   142
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   143
locale syntax' = "syntax" p1 p2 for p1 :: "'a => 'a" and p2 :: "'a => o"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   144
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   145
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   146
thm d1_def d2_def  (* should print as "d1(?x) <-> ..." and "d2(?x) <-> ..." *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   147
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   148
ML {*
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   149
  fun check_syntax ctxt thm expected =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   150
    let
37146
f652333bbf8e renamed structure PrintMode to Print_Mode, keeping the old name as legacy alias for some time;
wenzelm
parents: 37134
diff changeset
   151
      val obtained = Print_Mode.setmp [] (Display.string_of_thm ctxt) thm;
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   152
    in
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   153
      if obtained <> expected
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   154
      then error ("Theorem syntax '" ^ obtained ^ "' obtained, but '" ^ expected ^ "' expected.")
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   155
      else ()
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   156
    end;
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   157
*}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   158
41305
42967939ea81 actually enable show_hyps option, unlike local_setup in 6da953d30f48 which merely affects the (temporary) auxiliary context;
wenzelm
parents: 41272
diff changeset
   159
declare [[show_hyps]]
41271
6da953d30f48 Enable show_hyps, which appears to be set in batch mode but in an interactive session.
ballarin
parents: 39557
diff changeset
   160
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   161
ML {*
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   162
  check_syntax @{context} @{thm d1_def} "d1(?x) <-> ~ p2(p1(?x))";
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   163
  check_syntax @{context} @{thm d2_def} "d2(?x) <-> ~ p2(?x)";
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   164
*}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   165
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   166
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   167
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   168
locale syntax'' = "syntax" p3 p2 for p3 :: "'a => 'b" and p2 :: "'b => o"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   169
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   170
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   171
thm d1_def d2_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   172
  (* should print as "syntax.d1(p3, p2, ?x) <-> ..." and "d2(?x) <-> ..." *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   173
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   174
ML {*
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   175
  check_syntax @{context} @{thm d1_def} "syntax.d1(p3, p2, ?x) <-> ~ p2(p3(?x))";
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   176
  check_syntax @{context} @{thm d2_def} "d2(?x) <-> ~ p2(?x)";
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   177
*}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   178
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   179
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   180
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   181
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   182
section {* Foundational versions of theorems *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   183
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   184
thm logic.assoc
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   185
thm logic.lor_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   186
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   187
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   188
section {* Defines *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   189
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   190
locale logic_def =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   191
  fixes land (infixl "&&" 55)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   192
    and lor (infixl "||" 50)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   193
    and lnot ("-- _" [60] 60)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   194
  assumes assoc: "(x && y) && z = x && (y && z)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   195
    and notnot: "-- (-- x) = x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   196
  defines "x || y == --(-- x && -- y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   197
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   198
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   199
thm lor_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   200
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   201
lemma "x || y = --(-- x && --y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   202
  by (unfold lor_def) (rule refl)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   203
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   204
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   205
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   206
(* Inheritance of defines *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   207
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   208
locale logic_def2 = logic_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   209
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   210
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   211
lemma "x || y = --(-- x && --y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   212
  by (unfold lor_def) (rule refl)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   213
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   214
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   215
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   216
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   217
section {* Notes *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   218
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   219
(* A somewhat arcane homomorphism example *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   220
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   221
definition semi_hom where
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   222
  "semi_hom(prod, sum, h) <-> (ALL x y. h(prod(x, y)) = sum(h(x), h(y)))"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   223
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   224
lemma semi_hom_mult:
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   225
  "semi_hom(prod, sum, h) ==> h(prod(x, y)) = sum(h(x), h(y))"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   226
  by (simp add: semi_hom_def)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   227
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   228
locale semi_hom_loc = prod: semi prod + sum: semi sum
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   229
  for prod and sum and h +
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   230
  assumes semi_homh: "semi_hom(prod, sum, h)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   231
  notes semi_hom_mult = semi_hom_mult [OF semi_homh]
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   232
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   233
thm semi_hom_loc.semi_hom_mult
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   234
(* unspecified, attribute not applied in backgroud theory !!! *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   235
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   236
lemma (in semi_hom_loc) "h(prod(x, y)) = sum(h(x), h(y))"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   237
  by (rule semi_hom_mult)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   238
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   239
(* Referring to facts from within a context specification *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   240
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   241
lemma
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   242
  assumes x: "P <-> P"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   243
  notes y = x
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   244
  shows True ..
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   245
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   246
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   247
section {* Theorem statements *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   248
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   249
lemma (in lgrp) lcancel:
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   250
  "x ** y = x ** z <-> y = z"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   251
proof
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   252
  assume "x ** y = x ** z"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   253
  then have "inv(x) ** x ** y = inv(x) ** x ** z" by (simp add: assoc)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   254
  then show "y = z" by (simp add: lone linv)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   255
qed simp
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   256
print_locale! lgrp
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   257
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   258
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   259
locale rgrp = semi +
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   260
  fixes one and inv
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   261
  assumes rone: "x ** one = x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   262
    and rinv: "x ** inv(x) = one"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   263
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   264
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   265
lemma rcancel:
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   266
  "y ** x = z ** x <-> y = z"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   267
proof
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   268
  assume "y ** x = z ** x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   269
  then have "y ** (x ** inv(x)) = z ** (x ** inv(x))"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   270
    by (simp add: assoc [symmetric])
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   271
  then show "y = z" by (simp add: rone rinv)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   272
qed simp
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   273
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   274
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   275
print_locale! rgrp
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   276
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   277
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   278
subsection {* Patterns *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   279
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   280
lemma (in rgrp)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   281
  assumes "y ** x = z ** x" (is ?a)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   282
  shows "y = z" (is ?t)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   283
proof -
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   284
  txt {* Weird proof involving patterns from context element and conclusion. *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   285
  {
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   286
    assume ?a
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   287
    then have "y ** (x ** inv(x)) = z ** (x ** inv(x))"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   288
      by (simp add: assoc [symmetric])
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   289
    then have ?t by (simp add: rone rinv)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   290
  }
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   291
  note x = this
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   292
  show ?t by (rule x [OF `?a`])
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   293
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   294
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   295
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   296
section {* Interpretation between locales: sublocales *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   297
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   298
sublocale lgrp < right: rgrp
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   299
print_facts
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   300
proof unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   301
  {
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   302
    fix x
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   303
    have "inv(x) ** x ** one = inv(x) ** x" by (simp add: linv lone)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   304
    then show "x ** one = x" by (simp add: assoc lcancel)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   305
  }
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   306
  note rone = this
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   307
  {
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   308
    fix x
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   309
    have "inv(x) ** x ** inv(x) = inv(x) ** one"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   310
      by (simp add: linv lone rone)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   311
    then show "x ** inv(x) = one" by (simp add: assoc lcancel)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   312
  }
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   313
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   314
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   315
(* effect on printed locale *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   316
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   317
print_locale! lgrp
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   318
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   319
(* use of derived theorem *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   320
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   321
lemma (in lgrp)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   322
  "y ** x = z ** x <-> y = z"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   323
  apply (rule rcancel)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   324
  done
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   325
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   326
(* circular interpretation *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   327
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   328
sublocale rgrp < left: lgrp
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   329
proof unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   330
  {
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   331
    fix x
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   332
    have "one ** (x ** inv(x)) = x ** inv(x)" by (simp add: rinv rone)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   333
    then show "one ** x = x" by (simp add: assoc [symmetric] rcancel)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   334
  }
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   335
  note lone = this
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   336
  {
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   337
    fix x
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   338
    have "inv(x) ** (x ** inv(x)) = one ** inv(x)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   339
      by (simp add: rinv lone rone)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   340
    then show "inv(x) ** x = one" by (simp add: assoc [symmetric] rcancel)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   341
  }
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   342
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   343
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   344
(* effect on printed locale *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   345
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   346
print_locale! rgrp
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   347
print_locale! lgrp
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   348
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   349
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   350
(* Duality *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   351
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   352
locale order =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   353
  fixes less :: "'a => 'a => o" (infix "<<" 50)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   354
  assumes refl: "x << x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   355
    and trans: "[| x << y; y << z |] ==> x << z"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   356
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   357
sublocale order < dual: order "%x y. y << x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   358
  apply unfold_locales apply (rule refl) apply (blast intro: trans)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   359
  done
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   360
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   361
print_locale! order  (* Only two instances of order. *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   362
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   363
locale order' =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   364
  fixes less :: "'a => 'a => o" (infix "<<" 50)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   365
  assumes refl: "x << x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   366
    and trans: "[| x << y; y << z |] ==> x << z"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   367
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   368
locale order_with_def = order'
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   369
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   370
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   371
definition greater :: "'a => 'a => o" (infix ">>" 50) where
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   372
  "x >> y <-> y << x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   373
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   374
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   375
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   376
sublocale order_with_def < dual: order' "op >>"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   377
  apply unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   378
  unfolding greater_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   379
  apply (rule refl) apply (blast intro: trans)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   380
  done
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   381
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   382
print_locale! order_with_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   383
(* Note that decls come after theorems that make use of them. *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   384
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   385
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   386
(* locale with many parameters ---
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   387
   interpretations generate alternating group A5 *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   388
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   389
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   390
locale A5 =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   391
  fixes A and B and C and D and E
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   392
  assumes eq: "A <-> B <-> C <-> D <-> E"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   393
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   394
sublocale A5 < 1: A5 _ _ D E C
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   395
print_facts
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   396
  using eq apply (blast intro: A5.intro) done
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   397
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   398
sublocale A5 < 2: A5 C _ E _ A
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   399
print_facts
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   400
  using eq apply (blast intro: A5.intro) done
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   401
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   402
sublocale A5 < 3: A5 B C A _ _
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   403
print_facts
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   404
  using eq apply (blast intro: A5.intro) done
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   405
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   406
(* Any even permutation of parameters is subsumed by the above. *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   407
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   408
print_locale! A5
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   409
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   410
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   411
(* Free arguments of instance *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   412
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   413
locale trivial =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   414
  fixes P and Q :: o
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   415
  assumes Q: "P <-> P <-> Q"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   416
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   417
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   418
lemma Q_triv: "Q" using Q by fast
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   419
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   420
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   421
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   422
sublocale trivial < x: trivial x _
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   423
  apply unfold_locales using Q by fast
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   424
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   425
print_locale! trivial
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   426
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   427
context trivial begin thm x.Q [where ?x = True] end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   428
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   429
sublocale trivial < y: trivial Q Q
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   430
  by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   431
  (* Succeeds since previous interpretation is more general. *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   432
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   433
print_locale! trivial  (* No instance for y created (subsumed). *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   434
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   435
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   436
subsection {* Sublocale, then interpretation in theory *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   437
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   438
interpretation int?: lgrp "op +" "0" "minus"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   439
proof unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   440
qed (rule int_assoc int_zero int_minus)+
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   441
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   442
thm int.assoc int.semi_axioms
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   443
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   444
interpretation int2?: semi "op +"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   445
  by unfold_locales  (* subsumed, thm int2.assoc not generated *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   446
39557
fe5722fce758 renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents: 38109
diff changeset
   447
ML {* (Global_Theory.get_thms @{theory} "int2.assoc";
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   448
    error "thm int2.assoc was generated")
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   449
  handle ERROR "Unknown fact \"int2.assoc\"" => ([]:thm list); *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   450
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   451
thm int.lone int.right.rone
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   452
  (* the latter comes through the sublocale relation *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   453
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   454
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   455
subsection {* Interpretation in theory, then sublocale *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   456
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   457
interpretation fol: logic "op +" "minus"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   458
  by unfold_locales (rule int_assoc int_minus2)+
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   459
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   460
locale logic2 =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   461
  fixes land (infixl "&&" 55)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   462
    and lnot ("-- _" [60] 60)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   463
  assumes assoc: "(x && y) && z = x && (y && z)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   464
    and notnot: "-- (-- x) = x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   465
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   466
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   467
definition lor (infixl "||" 50) where
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   468
  "x || y = --(-- x && -- y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   469
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   470
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   471
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   472
sublocale logic < two: logic2
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   473
  by unfold_locales (rule assoc notnot)+
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   474
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   475
thm fol.two.assoc
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   476
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   477
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   478
subsection {* Declarations and sublocale *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   479
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   480
locale logic_a = logic
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   481
locale logic_b = logic
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   482
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   483
sublocale logic_a < logic_b
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   484
  by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   485
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   486
53366
c8c548d83862 Terminology: mixin -> rewrite morphism.
ballarin
parents: 51515
diff changeset
   487
subsection {* Interpretation *}
c8c548d83862 Terminology: mixin -> rewrite morphism.
ballarin
parents: 51515
diff changeset
   488
c8c548d83862 Terminology: mixin -> rewrite morphism.
ballarin
parents: 51515
diff changeset
   489
subsection {* Rewrite morphism *}
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   490
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   491
locale logic_o =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   492
  fixes land (infixl "&&" 55)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   493
    and lnot ("-- _" [60] 60)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   494
  assumes assoc_o: "(x && y) && z <-> x && (y && z)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   495
    and notnot_o: "-- (-- x) <-> x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   496
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   497
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   498
definition lor_o (infixl "||" 50) where
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   499
  "x || y <-> --(-- x && -- y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   500
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   501
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   502
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   503
interpretation x: logic_o "op &" "Not"
43543
eb8b4851b039 While reading equations of an interpretation, already allow syntax provided by the interpretation base.
ballarin
parents: 41779
diff changeset
   504
  where bool_logic_o: "x.lor_o(x, y) <-> x | y"
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   505
proof -
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   506
  show bool_logic_o: "PROP logic_o(op &, Not)" by unfold_locales fast+
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   507
  show "logic_o.lor_o(op &, Not, x, y) <-> x | y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   508
    by (unfold logic_o.lor_o_def [OF bool_logic_o]) fast
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   509
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   510
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   511
thm x.lor_o_def bool_logic_o
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   512
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   513
lemma lor_triv: "z <-> z" ..
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   514
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   515
lemma (in logic_o) lor_triv: "x || y <-> x || y" by fast
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   516
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   517
thm lor_triv [where z = True] (* Check strict prefix. *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   518
  x.lor_triv
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   519
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   520
53366
c8c548d83862 Terminology: mixin -> rewrite morphism.
ballarin
parents: 51515
diff changeset
   521
subsection {* Inheritance of rewrite morphisms *}
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   522
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   523
locale reflexive =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   524
  fixes le :: "'a => 'a => o" (infix "\<sqsubseteq>" 50)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   525
  assumes refl: "x \<sqsubseteq> x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   526
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   527
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   528
definition less (infix "\<sqsubset>" 50) where "x \<sqsubset> y <-> x \<sqsubseteq> y & x ~= y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   529
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   530
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   531
41779
a68f503805ed modernized specifications;
wenzelm
parents: 41435
diff changeset
   532
axiomatization
a68f503805ed modernized specifications;
wenzelm
parents: 41435
diff changeset
   533
  gle :: "'a => 'a => o" and gless :: "'a => 'a => o" and
a68f503805ed modernized specifications;
wenzelm
parents: 41435
diff changeset
   534
  gle' :: "'a => 'a => o" and gless' :: "'a => 'a => o"
a68f503805ed modernized specifications;
wenzelm
parents: 41435
diff changeset
   535
where
a68f503805ed modernized specifications;
wenzelm
parents: 41435
diff changeset
   536
  grefl: "gle(x, x)" and gless_def: "gless(x, y) <-> gle(x, y) & x ~= y" and
a68f503805ed modernized specifications;
wenzelm
parents: 41435
diff changeset
   537
  grefl': "gle'(x, x)" and gless'_def: "gless'(x, y) <-> gle'(x, y) & x ~= y"
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   538
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   539
text {* Setup *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   540
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   541
locale mixin = reflexive
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   542
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   543
lemmas less_thm = less_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   544
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   545
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   546
interpretation le: mixin gle where "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   547
proof -
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   548
  show "mixin(gle)" by unfold_locales (rule grefl)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   549
  note reflexive = this[unfolded mixin_def]
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   550
  show "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   551
    by (simp add: reflexive.less_def[OF reflexive] gless_def)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   552
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   553
53366
c8c548d83862 Terminology: mixin -> rewrite morphism.
ballarin
parents: 51515
diff changeset
   554
text {* Rewrite morphism propagated along the locale hierarchy *}
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   555
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   556
locale mixin2 = mixin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   557
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   558
lemmas less_thm2 = less_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   559
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   560
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   561
interpretation le: mixin2 gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   562
  by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   563
53366
c8c548d83862 Terminology: mixin -> rewrite morphism.
ballarin
parents: 51515
diff changeset
   564
thm le.less_thm2  (* rewrite morphism applied *)
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   565
lemma "gless(x, y) <-> gle(x, y) & x ~= y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   566
  by (rule le.less_thm2)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   567
53366
c8c548d83862 Terminology: mixin -> rewrite morphism.
ballarin
parents: 51515
diff changeset
   568
text {* Rewrite morphism does not leak to a side branch. *}
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   569
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   570
locale mixin3 = reflexive
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   571
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   572
lemmas less_thm3 = less_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   573
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   574
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   575
interpretation le: mixin3 gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   576
  by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   577
53366
c8c548d83862 Terminology: mixin -> rewrite morphism.
ballarin
parents: 51515
diff changeset
   578
thm le.less_thm3  (* rewrite morphism not applied *)
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   579
lemma "reflexive.less(gle, x, y) <-> gle(x, y) & x ~= y" by (rule le.less_thm3)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   580
53366
c8c548d83862 Terminology: mixin -> rewrite morphism.
ballarin
parents: 51515
diff changeset
   581
text {* Rewrite morphism only available in original context *}
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   582
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   583
locale mixin4_base = reflexive
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   584
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   585
locale mixin4_mixin = mixin4_base
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   586
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   587
interpretation le: mixin4_mixin gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   588
  where "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   589
proof -
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   590
  show "mixin4_mixin(gle)" by unfold_locales (rule grefl)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   591
  note reflexive = this[unfolded mixin4_mixin_def mixin4_base_def mixin_def]
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   592
  show "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   593
    by (simp add: reflexive.less_def[OF reflexive] gless_def)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   594
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   595
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   596
locale mixin4_copy = mixin4_base
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   597
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   598
lemmas less_thm4 = less_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   599
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   600
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   601
locale mixin4_combined = le1: mixin4_mixin le' + le2: mixin4_copy le for le' le
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   602
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   603
lemmas less_thm4' = less_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   604
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   605
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   606
interpretation le4: mixin4_combined gle' gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   607
  by unfold_locales (rule grefl')
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   608
53366
c8c548d83862 Terminology: mixin -> rewrite morphism.
ballarin
parents: 51515
diff changeset
   609
thm le4.less_thm4' (* rewrite morphism not applied *)
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   610
lemma "reflexive.less(gle, x, y) <-> gle(x, y) & x ~= y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   611
  by (rule le4.less_thm4')
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   612
53366
c8c548d83862 Terminology: mixin -> rewrite morphism.
ballarin
parents: 51515
diff changeset
   613
text {* Inherited rewrite morphism applied to new theorem *}
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   614
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   615
locale mixin5_base = reflexive
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   616
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   617
locale mixin5_inherited = mixin5_base
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   618
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   619
interpretation le5: mixin5_base gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   620
  where "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   621
proof -
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   622
  show "mixin5_base(gle)" by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   623
  note reflexive = this[unfolded mixin5_base_def mixin_def]
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   624
  show "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   625
    by (simp add: reflexive.less_def[OF reflexive] gless_def)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   626
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   627
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   628
interpretation le5: mixin5_inherited gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   629
  by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   630
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   631
lemmas (in mixin5_inherited) less_thm5 = less_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   632
53366
c8c548d83862 Terminology: mixin -> rewrite morphism.
ballarin
parents: 51515
diff changeset
   633
thm le5.less_thm5  (* rewrite morphism applied *)
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   634
lemma "gless(x, y) <-> gle(x, y) & x ~= y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   635
  by (rule le5.less_thm5)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   636
53366
c8c548d83862 Terminology: mixin -> rewrite morphism.
ballarin
parents: 51515
diff changeset
   637
text {* Rewrite morphism pushed down to existing inherited locale *}
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   638
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   639
locale mixin6_base = reflexive
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   640
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   641
locale mixin6_inherited = mixin5_base
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   642
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   643
interpretation le6: mixin6_base gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   644
  by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   645
interpretation le6: mixin6_inherited gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   646
  by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   647
interpretation le6: mixin6_base gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   648
  where "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   649
proof -
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   650
  show "mixin6_base(gle)" by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   651
  note reflexive = this[unfolded mixin6_base_def mixin_def]
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   652
  show "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   653
    by (simp add: reflexive.less_def[OF reflexive] gless_def)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   654
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   655
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   656
lemmas (in mixin6_inherited) less_thm6 = less_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   657
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   658
thm le6.less_thm6  (* mixin applied *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   659
lemma "gless(x, y) <-> gle(x, y) & x ~= y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   660
  by (rule le6.less_thm6)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   661
53366
c8c548d83862 Terminology: mixin -> rewrite morphism.
ballarin
parents: 51515
diff changeset
   662
text {* Existing rewrite morphism inherited through sublocale relation *}
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   663
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   664
locale mixin7_base = reflexive
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   665
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   666
locale mixin7_inherited = reflexive
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   667
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   668
interpretation le7: mixin7_base gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   669
  where "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   670
proof -
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   671
  show "mixin7_base(gle)" by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   672
  note reflexive = this[unfolded mixin7_base_def mixin_def]
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   673
  show "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   674
    by (simp add: reflexive.less_def[OF reflexive] gless_def)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   675
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   676
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   677
interpretation le7: mixin7_inherited gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   678
  by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   679
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   680
lemmas (in mixin7_inherited) less_thm7 = less_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   681
53366
c8c548d83862 Terminology: mixin -> rewrite morphism.
ballarin
parents: 51515
diff changeset
   682
thm le7.less_thm7  (* before, rewrite morphism not applied *)
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   683
lemma "reflexive.less(gle, x, y) <-> gle(x, y) & x ~= y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   684
  by (rule le7.less_thm7)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   685
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   686
sublocale mixin7_inherited < mixin7_base
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   687
  by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   688
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   689
lemmas (in mixin7_inherited) less_thm7b = less_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   690
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   691
thm le7.less_thm7b  (* after, mixin applied *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   692
lemma "gless(x, y) <-> gle(x, y) & x ~= y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   693
  by (rule le7.less_thm7b)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   694
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   695
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   696
text {* This locale will be interpreted in later theories. *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   697
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   698
locale mixin_thy_merge = le: reflexive le + le': reflexive le' for le le'
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   699
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   700
53366
c8c548d83862 Terminology: mixin -> rewrite morphism.
ballarin
parents: 51515
diff changeset
   701
subsection {* Rewrite morphisms in sublocale *}
41272
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   702
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   703
text {* Simulate a specification of left groups where unit and inverse are defined
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   704
  rather than specified.  This is possible, but not in FOL, due to the lack of a
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   705
  selection operator. *}
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   706
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   707
axiomatization glob_one and glob_inv
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   708
  where glob_lone: "prod(glob_one(prod), x) = x"
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   709
    and glob_linv: "prod(glob_inv(prod, x), x) = glob_one(prod)"
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   710
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   711
locale dgrp = semi
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   712
begin
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   713
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   714
definition one where "one = glob_one(prod)"
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   715
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   716
lemma lone: "one ** x = x"
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   717
  unfolding one_def by (rule glob_lone)
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   718
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   719
definition inv where "inv(x) = glob_inv(prod, x)"
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   720
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   721
lemma linv: "inv(x) ** x = one"
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   722
  unfolding one_def inv_def by (rule glob_linv)
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   723
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   724
end
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   725
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   726
sublocale lgrp < "def": dgrp
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   727
  where one_equation: "dgrp.one(prod) = one" and inv_equation: "dgrp.inv(prod, x) = inv(x)"
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   728
proof -
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   729
  show "dgrp(prod)" by unfold_locales
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   730
  from this interpret d: dgrp .
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   731
  -- Unit
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   732
  have "dgrp.one(prod) = glob_one(prod)" by (rule d.one_def)
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   733
  also have "... = glob_one(prod) ** one" by (simp add: rone)
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   734
  also have "... = one" by (simp add: glob_lone)
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   735
  finally show "dgrp.one(prod) = one" .
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   736
  -- Inverse
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   737
  then have "dgrp.inv(prod, x) ** x = inv(x) ** x" by (simp add: glob_linv d.linv linv)
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   738
  then show "dgrp.inv(prod, x) = inv(x)" by (simp add: rcancel)
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   739
qed
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   740
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   741
print_locale! lgrp
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   742
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   743
context lgrp begin
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   744
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   745
text {* Equations stored in target *}
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   746
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   747
lemma "dgrp.one(prod) = one" by (rule one_equation)
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   748
lemma "dgrp.inv(prod, x) = inv(x)" by (rule inv_equation)
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   749
53366
c8c548d83862 Terminology: mixin -> rewrite morphism.
ballarin
parents: 51515
diff changeset
   750
text {* Rewrite morphisms applied *}
41272
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   751
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   752
lemma "one = glob_one(prod)" by (rule one_def)
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   753
lemma "inv(x) = glob_inv(prod, x)" by (rule inv_def)
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   754
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   755
end
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   756
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   757
text {* Interpreted versions *}
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   758
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   759
lemma "0 = glob_one (op +)" by (rule int.def.one_def)
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   760
lemma "- x = glob_inv(op +, x)" by (rule int.def.inv_def)
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   761
53366
c8c548d83862 Terminology: mixin -> rewrite morphism.
ballarin
parents: 51515
diff changeset
   762
text {* Roundup applies rewrite morphisms at declaration level in DFS tree *}
51515
c3eb0b517ced Fix issue related to mixins in roundup.
ballarin
parents: 49756
diff changeset
   763
c3eb0b517ced Fix issue related to mixins in roundup.
ballarin
parents: 49756
diff changeset
   764
locale roundup = fixes x assumes true: "x <-> True"
c3eb0b517ced Fix issue related to mixins in roundup.
ballarin
parents: 49756
diff changeset
   765
c3eb0b517ced Fix issue related to mixins in roundup.
ballarin
parents: 49756
diff changeset
   766
sublocale roundup \<subseteq> sub: roundup x where "x <-> True & True"
c3eb0b517ced Fix issue related to mixins in roundup.
ballarin
parents: 49756
diff changeset
   767
  apply unfold_locales apply (simp add: true) done
c3eb0b517ced Fix issue related to mixins in roundup.
ballarin
parents: 49756
diff changeset
   768
lemma (in roundup) "True & True <-> True" by (rule sub.true)
c3eb0b517ced Fix issue related to mixins in roundup.
ballarin
parents: 49756
diff changeset
   769
41272
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   770
53367
1f383542226b New test case: interpretation in named contexts is not persistent.
ballarin
parents: 53366
diff changeset
   771
section {* Interpretation in named contexts *}
1f383542226b New test case: interpretation in named contexts is not persistent.
ballarin
parents: 53366
diff changeset
   772
1f383542226b New test case: interpretation in named contexts is not persistent.
ballarin
parents: 53366
diff changeset
   773
locale container
1f383542226b New test case: interpretation in named contexts is not persistent.
ballarin
parents: 53366
diff changeset
   774
begin
1f383542226b New test case: interpretation in named contexts is not persistent.
ballarin
parents: 53366
diff changeset
   775
interpretation private!: roundup True by unfold_locales rule
1f383542226b New test case: interpretation in named contexts is not persistent.
ballarin
parents: 53366
diff changeset
   776
lemmas true_copy = private.true
1f383542226b New test case: interpretation in named contexts is not persistent.
ballarin
parents: 53366
diff changeset
   777
end
1f383542226b New test case: interpretation in named contexts is not persistent.
ballarin
parents: 53366
diff changeset
   778
1f383542226b New test case: interpretation in named contexts is not persistent.
ballarin
parents: 53366
diff changeset
   779
context container begin
1f383542226b New test case: interpretation in named contexts is not persistent.
ballarin
parents: 53366
diff changeset
   780
ML {* (Context.>> (fn generic => let val context = Context.proof_of generic
1f383542226b New test case: interpretation in named contexts is not persistent.
ballarin
parents: 53366
diff changeset
   781
  val _ = Proof_Context.get_thms context "private.true" in generic end);
1f383542226b New test case: interpretation in named contexts is not persistent.
ballarin
parents: 53366
diff changeset
   782
  error "thm private.true was persisted")
1f383542226b New test case: interpretation in named contexts is not persistent.
ballarin
parents: 53366
diff changeset
   783
  handle ERROR "Unknown fact \"private.true\"" => ([]:thm list); *}
1f383542226b New test case: interpretation in named contexts is not persistent.
ballarin
parents: 53366
diff changeset
   784
thm true_copy
1f383542226b New test case: interpretation in named contexts is not persistent.
ballarin
parents: 53366
diff changeset
   785
end
1f383542226b New test case: interpretation in named contexts is not persistent.
ballarin
parents: 53366
diff changeset
   786
1f383542226b New test case: interpretation in named contexts is not persistent.
ballarin
parents: 53366
diff changeset
   787
41272
b806a7678083 Add mixins to locale dependencies.
ballarin
parents: 41271
diff changeset
   788
section {* Interpretation in proofs *}
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   789
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   790
lemma True
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   791
proof
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   792
  interpret "local": lgrp "op +" "0" "minus"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   793
    by unfold_locales  (* subsumed *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   794
  {
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   795
    fix zero :: int
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   796
    assume "!!x. zero + x = x" "!!x. (-x) + x = zero"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   797
    then interpret local_fixed: lgrp "op +" zero "minus"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   798
      by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   799
    thm local_fixed.lone
41435
12585dfb86fe Diagnostic command to show locale dependencies.
ballarin
parents: 41305
diff changeset
   800
    print_dependencies! lgrp "op +" 0 minus + lgrp "op +" zero minus
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   801
  }
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   802
  assume "!!x zero. zero + x = x" "!!x zero. (-x) + x = zero"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   803
  then interpret local_free: lgrp "op +" zero "minus" for zero
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   804
    by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   805
  thm local_free.lone [where ?zero = 0]
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   806
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   807
38108
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   808
lemma True
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   809
proof
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   810
  {
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   811
    fix pand and pnot and por
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   812
    assume passoc: "!!x y z. pand(pand(x, y), z) <-> pand(x, pand(y, z))"
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   813
      and pnotnot: "!!x. pnot(pnot(x)) <-> x"
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   814
      and por_def: "!!x y. por(x, y) <-> pnot(pand(pnot(x), pnot(y)))"
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   815
    interpret loc: logic_o pand pnot
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   816
      where por_eq: "!!x y. logic_o.lor_o(pand, pnot, x, y) <-> por(x, y)"  (* FIXME *)
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   817
    proof -
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   818
      show logic_o: "PROP logic_o(pand, pnot)" using passoc pnotnot by unfold_locales
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   819
      fix x y
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   820
      show "logic_o.lor_o(pand, pnot, x, y) <-> por(x, y)"
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   821
        by (unfold logic_o.lor_o_def [OF logic_o]) (rule por_def [symmetric])
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   822
    qed
38109
06fd1914b902 print_interps shows interpretations in proofs.
ballarin
parents: 38108
diff changeset
   823
    print_interps logic_o
38108
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   824
    have "!!x y. por(x, y) <-> pnot(pand(pnot(x), pnot(y)))" by (rule loc.lor_o_def)
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   825
  }
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   826
qed
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   827
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   828
end