src/FOL/ex/Locale_Test/Locale_Test1.thy
author haftmann
Tue, 31 Aug 2010 13:55:54 +0200
changeset 38924 fcd1d0457e27
parent 38109 06fd1914b902
child 39557 fe5722fce758
permissions -rw-r--r--
removed serializer interface redundancies
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
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    16
axioms
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    17
  int_assoc: "(x + y::int) + z = x + (y + z)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    18
  int_zero: "0 + x = x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
    19
  int_minus: "(-x) + x = 0"
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
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   107
locale use_decl = logic + semi "op ||"
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
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   159
ML {*
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   160
  check_syntax @{context} @{thm d1_def} "d1(?x) <-> ~ p2(p1(?x))";
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   161
  check_syntax @{context} @{thm d2_def} "d2(?x) <-> ~ p2(?x)";
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   162
*}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   163
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   164
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   165
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   166
locale syntax'' = "syntax" p3 p2 for p3 :: "'a => 'b" and p2 :: "'b => o"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   167
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   168
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   169
thm d1_def d2_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   170
  (* should print as "syntax.d1(p3, p2, ?x) <-> ..." and "d2(?x) <-> ..." *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   171
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   172
ML {*
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   173
  check_syntax @{context} @{thm d1_def} "syntax.d1(p3, p2, ?x) <-> ~ p2(p3(?x))";
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   174
  check_syntax @{context} @{thm d2_def} "d2(?x) <-> ~ p2(?x)";
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   175
*}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   176
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   177
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   178
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   179
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   180
section {* Foundational versions of theorems *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   181
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   182
thm logic.assoc
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   183
thm logic.lor_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   184
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   185
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   186
section {* Defines *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   187
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   188
locale logic_def =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   189
  fixes land (infixl "&&" 55)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   190
    and lor (infixl "||" 50)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   191
    and lnot ("-- _" [60] 60)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   192
  assumes assoc: "(x && y) && z = x && (y && z)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   193
    and notnot: "-- (-- x) = x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   194
  defines "x || y == --(-- x && -- y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   195
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   196
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   197
thm lor_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   198
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   199
lemma "x || y = --(-- x && --y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   200
  by (unfold lor_def) (rule refl)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   201
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   202
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   203
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   204
(* Inheritance of defines *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   205
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   206
locale logic_def2 = logic_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   207
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   208
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   209
lemma "x || y = --(-- x && --y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   210
  by (unfold lor_def) (rule refl)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   211
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   212
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   213
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   214
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   215
section {* Notes *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   216
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   217
(* A somewhat arcane homomorphism example *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   218
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   219
definition semi_hom where
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   220
  "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
   221
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   222
lemma semi_hom_mult:
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   223
  "semi_hom(prod, sum, h) ==> h(prod(x, y)) = sum(h(x), h(y))"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   224
  by (simp add: semi_hom_def)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   225
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   226
locale semi_hom_loc = prod: semi prod + sum: semi sum
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   227
  for prod and sum and h +
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   228
  assumes semi_homh: "semi_hom(prod, sum, h)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   229
  notes semi_hom_mult = semi_hom_mult [OF semi_homh]
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   230
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   231
thm semi_hom_loc.semi_hom_mult
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   232
(* unspecified, attribute not applied in backgroud theory !!! *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   233
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   234
lemma (in semi_hom_loc) "h(prod(x, y)) = sum(h(x), h(y))"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   235
  by (rule semi_hom_mult)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   236
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   237
(* Referring to facts from within a context specification *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   238
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   239
lemma
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   240
  assumes x: "P <-> P"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   241
  notes y = x
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   242
  shows True ..
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   243
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   244
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   245
section {* Theorem statements *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   246
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   247
lemma (in lgrp) lcancel:
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   248
  "x ** y = x ** z <-> y = z"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   249
proof
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   250
  assume "x ** y = x ** z"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   251
  then have "inv(x) ** x ** y = inv(x) ** x ** z" by (simp add: assoc)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   252
  then show "y = z" by (simp add: lone linv)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   253
qed simp
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   254
print_locale! lgrp
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   255
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   256
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   257
locale rgrp = semi +
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   258
  fixes one and inv
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   259
  assumes rone: "x ** one = x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   260
    and rinv: "x ** inv(x) = one"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   261
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   262
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   263
lemma rcancel:
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   264
  "y ** x = z ** x <-> y = z"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   265
proof
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   266
  assume "y ** x = z ** x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   267
  then have "y ** (x ** inv(x)) = z ** (x ** inv(x))"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   268
    by (simp add: assoc [symmetric])
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   269
  then show "y = z" by (simp add: rone rinv)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   270
qed simp
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   271
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   272
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   273
print_locale! rgrp
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   274
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   275
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   276
subsection {* Patterns *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   277
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   278
lemma (in rgrp)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   279
  assumes "y ** x = z ** x" (is ?a)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   280
  shows "y = z" (is ?t)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   281
proof -
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   282
  txt {* Weird proof involving patterns from context element and conclusion. *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   283
  {
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   284
    assume ?a
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   285
    then have "y ** (x ** inv(x)) = z ** (x ** inv(x))"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   286
      by (simp add: assoc [symmetric])
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   287
    then have ?t by (simp add: rone rinv)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   288
  }
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   289
  note x = this
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   290
  show ?t by (rule x [OF `?a`])
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   291
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   292
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   293
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   294
section {* Interpretation between locales: sublocales *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   295
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   296
sublocale lgrp < right: rgrp
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   297
print_facts
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   298
proof unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   299
  {
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   300
    fix x
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   301
    have "inv(x) ** x ** one = inv(x) ** x" by (simp add: linv lone)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   302
    then show "x ** one = x" by (simp add: assoc lcancel)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   303
  }
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   304
  note rone = this
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   305
  {
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   306
    fix x
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   307
    have "inv(x) ** x ** inv(x) = inv(x) ** one"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   308
      by (simp add: linv lone rone)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   309
    then show "x ** inv(x) = one" by (simp add: assoc lcancel)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   310
  }
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   311
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   312
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   313
(* effect on printed locale *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   314
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   315
print_locale! lgrp
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   316
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   317
(* use of derived theorem *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   318
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   319
lemma (in lgrp)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   320
  "y ** x = z ** x <-> y = z"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   321
  apply (rule rcancel)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   322
  done
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   323
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   324
(* circular interpretation *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   325
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   326
sublocale rgrp < left: lgrp
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   327
proof unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   328
  {
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   329
    fix x
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   330
    have "one ** (x ** inv(x)) = x ** inv(x)" by (simp add: rinv rone)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   331
    then show "one ** x = x" by (simp add: assoc [symmetric] rcancel)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   332
  }
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   333
  note lone = this
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   334
  {
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   335
    fix x
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   336
    have "inv(x) ** (x ** inv(x)) = one ** inv(x)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   337
      by (simp add: rinv lone rone)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   338
    then show "inv(x) ** x = one" by (simp add: assoc [symmetric] rcancel)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   339
  }
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   340
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   341
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   342
(* effect on printed locale *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   343
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   344
print_locale! rgrp
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   345
print_locale! lgrp
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   346
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   347
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   348
(* Duality *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   349
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   350
locale order =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   351
  fixes less :: "'a => 'a => o" (infix "<<" 50)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   352
  assumes refl: "x << x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   353
    and trans: "[| x << y; y << z |] ==> x << z"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   354
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   355
sublocale order < dual: order "%x y. y << x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   356
  apply unfold_locales apply (rule refl) apply (blast intro: trans)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   357
  done
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   358
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   359
print_locale! order  (* Only two instances of order. *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   360
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   361
locale order' =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   362
  fixes less :: "'a => 'a => o" (infix "<<" 50)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   363
  assumes refl: "x << x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   364
    and trans: "[| x << y; y << z |] ==> x << z"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   365
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   366
locale order_with_def = order'
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   367
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   368
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   369
definition greater :: "'a => 'a => o" (infix ">>" 50) where
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   370
  "x >> y <-> y << x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   371
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   372
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   373
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   374
sublocale order_with_def < dual: order' "op >>"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   375
  apply unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   376
  unfolding greater_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   377
  apply (rule refl) apply (blast intro: trans)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   378
  done
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   379
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   380
print_locale! order_with_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   381
(* Note that decls come after theorems that make use of them. *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   382
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   383
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   384
(* locale with many parameters ---
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   385
   interpretations generate alternating group A5 *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   386
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   387
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   388
locale A5 =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   389
  fixes A and B and C and D and E
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   390
  assumes eq: "A <-> B <-> C <-> D <-> E"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   391
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   392
sublocale A5 < 1: A5 _ _ D E C
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   393
print_facts
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   394
  using eq apply (blast intro: A5.intro) done
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   395
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   396
sublocale A5 < 2: A5 C _ E _ A
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   397
print_facts
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   398
  using eq apply (blast intro: A5.intro) done
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   399
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   400
sublocale A5 < 3: A5 B C A _ _
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   401
print_facts
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   402
  using eq apply (blast intro: A5.intro) done
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   403
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   404
(* Any even permutation of parameters is subsumed by the above. *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   405
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   406
print_locale! A5
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   407
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   408
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   409
(* Free arguments of instance *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   410
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   411
locale trivial =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   412
  fixes P and Q :: o
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   413
  assumes Q: "P <-> P <-> Q"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   414
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   415
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   416
lemma Q_triv: "Q" using Q by fast
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   417
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   418
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   419
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   420
sublocale trivial < x: trivial x _
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   421
  apply unfold_locales using Q by fast
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   422
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   423
print_locale! trivial
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   424
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   425
context trivial begin thm x.Q [where ?x = True] end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   426
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   427
sublocale trivial < y: trivial Q Q
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   428
  by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   429
  (* Succeeds since previous interpretation is more general. *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   430
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   431
print_locale! trivial  (* No instance for y created (subsumed). *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   432
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   433
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   434
subsection {* Sublocale, then interpretation in theory *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   435
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   436
interpretation int?: lgrp "op +" "0" "minus"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   437
proof unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   438
qed (rule int_assoc int_zero int_minus)+
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   439
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   440
thm int.assoc int.semi_axioms
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   441
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   442
interpretation int2?: semi "op +"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   443
  by unfold_locales  (* subsumed, thm int2.assoc not generated *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   444
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   445
ML {* (PureThy.get_thms @{theory} "int2.assoc";
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   446
    error "thm int2.assoc was generated")
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   447
  handle ERROR "Unknown fact \"int2.assoc\"" => ([]:thm list); *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   448
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   449
thm int.lone int.right.rone
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   450
  (* the latter comes through the sublocale relation *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   451
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   452
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   453
subsection {* Interpretation in theory, then sublocale *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   454
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   455
interpretation fol: logic "op +" "minus"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   456
  by unfold_locales (rule int_assoc int_minus2)+
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   457
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   458
locale logic2 =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   459
  fixes land (infixl "&&" 55)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   460
    and lnot ("-- _" [60] 60)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   461
  assumes assoc: "(x && y) && z = x && (y && z)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   462
    and notnot: "-- (-- x) = x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   463
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   464
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   465
definition lor (infixl "||" 50) where
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   466
  "x || y = --(-- x && -- y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   467
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   468
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   469
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   470
sublocale logic < two: logic2
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   471
  by unfold_locales (rule assoc notnot)+
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   472
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   473
thm fol.two.assoc
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   474
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   475
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   476
subsection {* Declarations and sublocale *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   477
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   478
locale logic_a = logic
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   479
locale logic_b = logic
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   480
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   481
sublocale logic_a < logic_b
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   482
  by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   483
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   484
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   485
subsection {* Equations *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   486
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   487
locale logic_o =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   488
  fixes land (infixl "&&" 55)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   489
    and lnot ("-- _" [60] 60)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   490
  assumes assoc_o: "(x && y) && z <-> x && (y && z)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   491
    and notnot_o: "-- (-- x) <-> x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   492
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   493
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   494
definition lor_o (infixl "||" 50) where
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   495
  "x || y <-> --(-- x && -- y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   496
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   497
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   498
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   499
interpretation x: logic_o "op &" "Not"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   500
  where bool_logic_o: "logic_o.lor_o(op &, Not, x, y) <-> x | y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   501
proof -
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   502
  show bool_logic_o: "PROP logic_o(op &, Not)" by unfold_locales fast+
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   503
  show "logic_o.lor_o(op &, Not, x, y) <-> x | y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   504
    by (unfold logic_o.lor_o_def [OF bool_logic_o]) fast
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   505
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   506
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   507
thm x.lor_o_def bool_logic_o
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   508
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   509
lemma lor_triv: "z <-> z" ..
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   510
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   511
lemma (in logic_o) lor_triv: "x || y <-> x || y" by fast
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   512
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   513
thm lor_triv [where z = True] (* Check strict prefix. *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   514
  x.lor_triv
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   515
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   516
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   517
subsection {* Inheritance of mixins *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   518
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   519
locale reflexive =
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   520
  fixes le :: "'a => 'a => o" (infix "\<sqsubseteq>" 50)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   521
  assumes refl: "x \<sqsubseteq> x"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   522
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   523
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   524
definition less (infix "\<sqsubset>" 50) where "x \<sqsubset> y <-> x \<sqsubseteq> y & x ~= y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   525
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   526
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   527
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   528
consts
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   529
  gle :: "'a => 'a => o" gless :: "'a => 'a => o"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   530
  gle' :: "'a => 'a => o" gless' :: "'a => 'a => o"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   531
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   532
axioms
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   533
  grefl: "gle(x, x)" gless_def: "gless(x, y) <-> gle(x, y) & x ~= y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   534
  grefl': "gle'(x, x)" gless'_def: "gless'(x, y) <-> gle'(x, y) & x ~= y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   535
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   536
text {* Setup *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   537
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   538
locale mixin = reflexive
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   539
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   540
lemmas less_thm = less_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   541
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   542
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   543
interpretation le: mixin gle where "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   544
proof -
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   545
  show "mixin(gle)" by unfold_locales (rule grefl)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   546
  note reflexive = this[unfolded mixin_def]
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   547
  show "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   548
    by (simp add: reflexive.less_def[OF reflexive] gless_def)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   549
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   550
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   551
text {* Mixin propagated along the locale hierarchy *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   552
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   553
locale mixin2 = mixin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   554
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   555
lemmas less_thm2 = less_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   556
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   557
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   558
interpretation le: mixin2 gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   559
  by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   560
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   561
thm le.less_thm2  (* mixin applied *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   562
lemma "gless(x, y) <-> gle(x, y) & x ~= y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   563
  by (rule le.less_thm2)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   564
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   565
text {* Mixin does not leak to a side branch. *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   566
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   567
locale mixin3 = reflexive
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   568
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   569
lemmas less_thm3 = less_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   570
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   571
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   572
interpretation le: mixin3 gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   573
  by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   574
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   575
thm le.less_thm3  (* mixin not applied *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   576
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
   577
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   578
text {* Mixin only available in original context *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   579
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   580
locale mixin4_base = reflexive
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   581
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   582
locale mixin4_mixin = mixin4_base
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   583
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   584
interpretation le: mixin4_mixin gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   585
  where "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   586
proof -
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   587
  show "mixin4_mixin(gle)" by unfold_locales (rule grefl)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   588
  note reflexive = this[unfolded mixin4_mixin_def mixin4_base_def mixin_def]
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   589
  show "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   590
    by (simp add: reflexive.less_def[OF reflexive] gless_def)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   591
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   592
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   593
locale mixin4_copy = mixin4_base
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   594
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   595
lemmas less_thm4 = less_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   596
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   597
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   598
locale mixin4_combined = le1: mixin4_mixin le' + le2: mixin4_copy le for le' le
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   599
begin
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   600
lemmas less_thm4' = less_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   601
end
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   602
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   603
interpretation le4: mixin4_combined gle' gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   604
  by unfold_locales (rule grefl')
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   605
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   606
thm le4.less_thm4' (* mixin not applied *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   607
lemma "reflexive.less(gle, x, y) <-> gle(x, y) & x ~= y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   608
  by (rule le4.less_thm4')
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   609
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   610
text {* Inherited mixin applied to new theorem *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   611
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   612
locale mixin5_base = reflexive
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   613
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   614
locale mixin5_inherited = mixin5_base
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   615
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   616
interpretation le5: mixin5_base gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   617
  where "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   618
proof -
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   619
  show "mixin5_base(gle)" by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   620
  note reflexive = this[unfolded mixin5_base_def mixin_def]
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   621
  show "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   622
    by (simp add: reflexive.less_def[OF reflexive] gless_def)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   623
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   624
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   625
interpretation le5: mixin5_inherited gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   626
  by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   627
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   628
lemmas (in mixin5_inherited) less_thm5 = less_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   629
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   630
thm le5.less_thm5  (* mixin applied *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   631
lemma "gless(x, y) <-> gle(x, y) & x ~= y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   632
  by (rule le5.less_thm5)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   633
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   634
text {* Mixin pushed down to existing inherited locale *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   635
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   636
locale mixin6_base = reflexive
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   637
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   638
locale mixin6_inherited = mixin5_base
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   639
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   640
interpretation le6: mixin6_base gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   641
  by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   642
interpretation le6: mixin6_inherited gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   643
  by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   644
interpretation le6: mixin6_base gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   645
  where "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   646
proof -
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   647
  show "mixin6_base(gle)" by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   648
  note reflexive = this[unfolded mixin6_base_def mixin_def]
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   649
  show "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   650
    by (simp add: reflexive.less_def[OF reflexive] gless_def)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   651
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   652
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   653
lemmas (in mixin6_inherited) less_thm6 = less_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   654
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   655
thm le6.less_thm6  (* mixin applied *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   656
lemma "gless(x, y) <-> gle(x, y) & x ~= y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   657
  by (rule le6.less_thm6)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   658
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   659
text {* Existing mixin inherited through sublocale relation *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   660
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   661
locale mixin7_base = reflexive
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   662
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   663
locale mixin7_inherited = reflexive
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   664
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   665
interpretation le7: mixin7_base gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   666
  where "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   667
proof -
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   668
  show "mixin7_base(gle)" by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   669
  note reflexive = this[unfolded mixin7_base_def mixin_def]
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   670
  show "reflexive.less(gle, x, y) <-> gless(x, y)"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   671
    by (simp add: reflexive.less_def[OF reflexive] gless_def)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   672
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   673
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   674
interpretation le7: mixin7_inherited gle
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   675
  by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   676
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   677
lemmas (in mixin7_inherited) less_thm7 = less_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   678
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   679
thm le7.less_thm7  (* before, mixin not applied *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   680
lemma "reflexive.less(gle, x, y) <-> gle(x, y) & x ~= y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   681
  by (rule le7.less_thm7)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   682
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   683
sublocale mixin7_inherited < mixin7_base
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   684
  by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   685
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   686
lemmas (in mixin7_inherited) less_thm7b = less_def
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   687
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   688
thm le7.less_thm7b  (* after, mixin applied *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   689
lemma "gless(x, y) <-> gle(x, y) & x ~= y"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   690
  by (rule le7.less_thm7b)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   691
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   692
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   693
text {* This locale will be interpreted in later theories. *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   694
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   695
locale mixin_thy_merge = le: reflexive le + le': reflexive le' for le le'
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   696
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   697
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   698
subsection {* Interpretation in proofs *}
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   699
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   700
lemma True
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   701
proof
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   702
  interpret "local": lgrp "op +" "0" "minus"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   703
    by unfold_locales  (* subsumed *)
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   704
  {
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   705
    fix zero :: int
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   706
    assume "!!x. zero + x = x" "!!x. (-x) + x = zero"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   707
    then interpret local_fixed: lgrp "op +" zero "minus"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   708
      by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   709
    thm local_fixed.lone
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   710
  }
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   711
  assume "!!x zero. zero + x = x" "!!x zero. (-x) + x = zero"
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   712
  then interpret local_free: lgrp "op +" zero "minus" for zero
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   713
    by unfold_locales
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   714
  thm local_free.lone [where ?zero = 0]
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   715
qed
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   716
38108
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   717
lemma True
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   718
proof
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   719
  {
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   720
    fix pand and pnot and por
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   721
    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
   722
      and pnotnot: "!!x. pnot(pnot(x)) <-> x"
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   723
      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
   724
    interpret loc: logic_o pand pnot
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   725
      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
   726
    proof -
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   727
      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
   728
      fix x y
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   729
      show "logic_o.lor_o(pand, pnot, x, y) <-> por(x, y)"
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   730
        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
   731
    qed
38109
06fd1914b902 print_interps shows interpretations in proofs.
ballarin
parents: 38108
diff changeset
   732
    print_interps logic_o
38108
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   733
    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
   734
  }
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   735
qed
b4115423c049 Interpretation in proofs supports mixins.
ballarin
parents: 37146
diff changeset
   736
37134
29bd6c2ffba8 Revise locale test theory layout.
ballarin
parents:
diff changeset
   737
end