src/HOL/ex/LocaleTest2.thy
author wenzelm
Sun, 03 Jun 2007 23:16:47 +0200
changeset 23219 87ad6e8a5f2c
parent 22757 d3298d63b7b6
child 23919 af871d13e320
permissions -rw-r--r--
tuned document;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22657
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
     1
(*  Title:      HOL/ex/LocaleTest2.thy
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
     2
    ID:         $Id$
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
     3
    Author:     Clemens Ballarin
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
     4
    Copyright (c) 2007 by Clemens Ballarin
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
     5
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
     6
More regression tests for locales.
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
     7
Definitions are less natural in FOL, since there is no selection operator.
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
     8
Hence we do them in HOL, not in the main test suite for locales:
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
     9
FOL/ex/LocaleTest.thy
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    10
*)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    11
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    12
header {* Test of Locale Interpretation *}
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    13
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    14
theory LocaleTest2
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    15
imports Main
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    16
begin
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    17
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    18
ML {* set quick_and_dirty *}    (* allow for thm command in batch mode *)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    19
ML {* set show_hyps *}
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    20
ML {* set show_sorts *}
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    21
23219
87ad6e8a5f2c tuned document;
wenzelm
parents: 22757
diff changeset
    22
87ad6e8a5f2c tuned document;
wenzelm
parents: 22757
diff changeset
    23
subsection {* Interpretation of Defined Concepts *}
22657
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    24
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    25
text {* Naming convention for global objects: prefixes D and d *}
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    26
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    27
(* Group example with defined operation inv *)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    28
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    29
locale Dsemi =
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    30
  fixes prod (infixl "**" 65)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    31
  assumes assoc: "(x ** y) ** z = x ** (y ** z)"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    32
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    33
locale Dmonoid = Dsemi +
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    34
  fixes one
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    35
  assumes lone: "one ** x = x"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    36
    and rone: "x ** one = x"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    37
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    38
definition (in Dmonoid)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    39
  inv where "inv(x) == THE y. x ** y = one & y ** x = one"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    40
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    41
lemma (in Dmonoid) inv_unique:
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    42
  assumes eq: "y ** x = one" "x ** y' = one"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    43
  shows "y = y'"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    44
proof -
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    45
  from eq have "y = y ** (x ** y')" by (simp add: rone)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    46
  also have "... = (y ** x) ** y'" by (simp add: assoc)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    47
  also from eq have "... = y'" by (simp add: lone)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    48
  finally show ?thesis .
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    49
qed
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    50
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    51
locale Dgrp = Dmonoid +
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    52
  assumes linv_ex: "EX y. y ** x = one"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    53
    and rinv_ex: "EX y. x ** y = one"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    54
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    55
lemma (in Dgrp) linv:
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    56
  "inv x ** x = one"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    57
apply (unfold inv_def)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    58
apply (insert rinv_ex [where x = x])
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    59
apply (insert linv_ex [where x = x])
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    60
apply (erule exE) apply (erule exE)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    61
apply (rule theI2)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    62
apply rule apply assumption
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    63
apply (frule inv_unique, assumption)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    64
apply simp
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    65
apply (rule inv_unique)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    66
apply fast+
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    67
done
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    68
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    69
lemma (in Dgrp) rinv:
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    70
  "x ** inv x = one"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    71
apply (unfold inv_def)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    72
apply (insert rinv_ex [where x = x])
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    73
apply (insert linv_ex [where x = x])
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    74
apply (erule exE) apply (erule exE)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    75
apply (rule theI2)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    76
apply rule apply assumption
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    77
apply (frule inv_unique, assumption)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    78
apply simp
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    79
apply (rule inv_unique)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    80
apply fast+
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    81
done
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    82
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    83
lemma (in Dgrp) lcancel:
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    84
  "x ** y = x ** z <-> y = z"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    85
proof
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    86
  assume "x ** y = x ** z"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    87
  then have "inv(x) ** x ** y = inv(x) ** x ** z" by (simp add: assoc)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    88
  then show "y = z" by (simp add: lone linv)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    89
qed simp
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    90
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    91
interpretation Dint: Dmonoid ["op +" "0::int"]
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    92
  where "Dmonoid.inv (op +) (0::int)" = "uminus"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    93
proof -
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    94
  show "Dmonoid (op +) (0::int)" by unfold_locales auto
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    95
  note Dint = this (* should have this as an assumption in further goals *)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    96
  {
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    97
    fix x
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    98
    have "Dmonoid.inv (op +) (0::int) x = - x"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
    99
      by (auto simp: Dmonoid.inv_def [OF Dint])
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   100
  }
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   101
  then show "Dmonoid.inv (op +) (0::int) == uminus"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   102
    by (rule_tac eq_reflection) (fast intro: ext)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   103
qed
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   104
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   105
thm Dmonoid.inv_def Dint.inv_def
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   106
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   107
lemma "- x \<equiv> THE y. x + y = 0 \<and> y + x = (0::int)"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   108
  apply (rule Dint.inv_def) done
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   109
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   110
interpretation Dclass: Dmonoid ["op +" "0::'a::ab_group_add"]
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   111
  where "Dmonoid.inv (op +) (0::'a::ab_group_add)" = "uminus"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   112
proof -
22757
d3298d63b7b6 Interpretation equations applied to attributes
ballarin
parents: 22676
diff changeset
   113
  show "Dmonoid (op +) (0::'a::ab_group_add)" by unfold_locales auto
22657
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   114
  note Dclass = this (* should have this as an assumption in further goals *)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   115
  {
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   116
    fix x
22757
d3298d63b7b6 Interpretation equations applied to attributes
ballarin
parents: 22676
diff changeset
   117
    have "Dmonoid.inv (op +) (0::'a::ab_group_add) x = - x"
22657
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   118
      by (auto simp: Dmonoid.inv_def [OF Dclass] equals_zero_I [symmetric])
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   119
  }
22757
d3298d63b7b6 Interpretation equations applied to attributes
ballarin
parents: 22676
diff changeset
   120
  then show "Dmonoid.inv (op +) (0::'a::ab_group_add) == uminus"
22657
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   121
    by (rule_tac eq_reflection) (fast intro: ext)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   122
qed
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   123
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   124
interpretation Dclass: Dgrp ["op +" "0::'a::ring"]
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   125
apply unfold_locales
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   126
apply (rule_tac x="-x" in exI) apply simp
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   127
apply (rule_tac x="-x" in exI) apply simp
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   128
done
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   129
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   130
(* Equation for inverse from Dclass: Dmonoid effective. *)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   131
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   132
thm Dclass.linv
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   133
lemma "-x + x = (0::'a::ring)" apply (rule Dclass.linv) done
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   134
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   135
(* Equations have effect in "subscriptions" *)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   136
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   137
(* In the same module *)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   138
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   139
lemma (in Dmonoid) trivial:
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   140
  "inv one = inv one"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   141
  by rule
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   142
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   143
thm Dclass.trivial
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   144
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   145
(* Inherited: interpretation *)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   146
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   147
lemma (in Dgrp) inv_inv:
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   148
  "inv (inv x) = x"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   149
proof -
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   150
  have "inv x ** inv (inv x) = inv x ** x"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   151
    by (simp add: linv rinv)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   152
  then show ?thesis by (simp add: lcancel)
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   153
qed
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   154
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   155
thm Dclass.inv_inv
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   156
lemma "- (- x) = (x::'a::ring)"
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   157
  apply (rule Dclass.inv_inv) done
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   158
731622340817 New file for locale regression tests.
ballarin
parents:
diff changeset
   159
end