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