src/HOL/Word/TdThs.thy
author wenzelm
Wed Sep 17 21:27:14 2008 +0200 (2008-09-17)
changeset 28263 69eaa97e7e96
parent 27138 63fdfcf6c7a3
child 29234 60f7fb56f8cd
permissions -rw-r--r--
moved global ML bindings to global place;
kleing@24333
     1
(* 
kleing@24333
     2
    ID:         $Id$
kleing@24333
     3
    Author:     Jeremy Dawson and Gerwin Klein, NICTA
kleing@24333
     4
kleing@24333
     5
  consequences of type definition theorems, 
kleing@24333
     6
  and of extended type definition theorems
kleing@24333
     7
*)
huffman@24350
     8
huffman@24350
     9
header {* Type Definition Theorems *}
huffman@24350
    10
haftmann@26560
    11
theory TdThs
haftmann@26560
    12
imports Main
haftmann@26560
    13
begin
kleing@24333
    14
kleing@25262
    15
section "More lemmas about normal type definitions"
kleing@25262
    16
kleing@24333
    17
lemma
kleing@24333
    18
  tdD1: "type_definition Rep Abs A \<Longrightarrow> \<forall>x. Rep x \<in> A" and
kleing@24333
    19
  tdD2: "type_definition Rep Abs A \<Longrightarrow> \<forall>x. Abs (Rep x) = x" and
kleing@24333
    20
  tdD3: "type_definition Rep Abs A \<Longrightarrow> \<forall>y. y \<in> A \<longrightarrow> Rep (Abs y) = y"
kleing@24333
    21
  by (auto simp: type_definition_def)
kleing@24333
    22
kleing@24333
    23
lemma td_nat_int: 
kleing@24333
    24
  "type_definition int nat (Collect (op <= 0))"
kleing@24333
    25
  unfolding type_definition_def by auto
kleing@24333
    26
kleing@24333
    27
context type_definition
kleing@24333
    28
begin
kleing@24333
    29
kleing@24333
    30
lemmas Rep' [iff] = Rep [simplified]  (* if A is given as Collect .. *)
kleing@24333
    31
kleing@24333
    32
declare Rep_inverse [simp] Rep_inject [simp]
kleing@24333
    33
kleing@24333
    34
lemma Abs_eqD: "Abs x = Abs y ==> x \<in> A ==> y \<in> A ==> x = y"
kleing@24333
    35
  by (simp add: Abs_inject)
kleing@24333
    36
   
kleing@24333
    37
lemma Abs_inverse': 
kleing@24333
    38
  "r : A ==> Abs r = a ==> Rep a = r"
kleing@24333
    39
  by (safe elim!: Abs_inverse)
kleing@24333
    40
kleing@24333
    41
lemma Rep_comp_inverse: 
kleing@24333
    42
  "Rep o f = g ==> Abs o g = f"
kleing@24333
    43
  using Rep_inverse by (auto intro: ext)
kleing@24333
    44
kleing@24333
    45
lemma Rep_eqD [elim!]: "Rep x = Rep y ==> x = y"
kleing@24333
    46
  by simp
kleing@24333
    47
kleing@24333
    48
lemma Rep_inverse': "Rep a = r ==> Abs r = a"
kleing@24333
    49
  by (safe intro!: Rep_inverse)
kleing@24333
    50
kleing@24333
    51
lemma comp_Abs_inverse: 
kleing@24333
    52
  "f o Abs = g ==> g o Rep = f"
kleing@24333
    53
  using Rep_inverse by (auto intro: ext) 
kleing@24333
    54
kleing@24333
    55
lemma set_Rep: 
kleing@24333
    56
  "A = range Rep"
kleing@24333
    57
proof (rule set_ext)
kleing@24333
    58
  fix x
kleing@24333
    59
  show "(x \<in> A) = (x \<in> range Rep)"
kleing@24333
    60
    by (auto dest: Abs_inverse [of x, symmetric])
kleing@24333
    61
qed  
kleing@24333
    62
kleing@24333
    63
lemma set_Rep_Abs: "A = range (Rep o Abs)"
kleing@24333
    64
proof (rule set_ext)
kleing@24333
    65
  fix x
kleing@24333
    66
  show "(x \<in> A) = (x \<in> range (Rep o Abs))"
kleing@24333
    67
    by (auto dest: Abs_inverse [of x, symmetric])
kleing@24333
    68
qed  
kleing@24333
    69
kleing@24333
    70
lemma Abs_inj_on: "inj_on Abs A"
kleing@24333
    71
  unfolding inj_on_def 
kleing@24333
    72
  by (auto dest: Abs_inject [THEN iffD1])
kleing@24333
    73
kleing@24333
    74
lemma image: "Abs ` A = UNIV"
kleing@24333
    75
  by (auto intro!: image_eqI)
kleing@24333
    76
kleing@24333
    77
lemmas td_thm = type_definition_axioms
kleing@24333
    78
kleing@24333
    79
lemma fns1: 
kleing@24333
    80
  "Rep o fa = fr o Rep | fa o Abs = Abs o fr ==> Abs o fr o Rep = fa"
kleing@24333
    81
  by (auto dest: Rep_comp_inverse elim: comp_Abs_inverse simp: o_assoc)
kleing@24333
    82
kleing@24333
    83
lemmas fns1a = disjI1 [THEN fns1]
kleing@24333
    84
lemmas fns1b = disjI2 [THEN fns1]
kleing@24333
    85
kleing@24333
    86
lemma fns4:
kleing@24333
    87
  "Rep o fa o Abs = fr ==> 
kleing@24333
    88
   Rep o fa = fr o Rep & fa o Abs = Abs o fr"
kleing@24333
    89
  by (auto intro!: ext)
kleing@24333
    90
kleing@24333
    91
end
kleing@24333
    92
kleing@24333
    93
interpretation nat_int: type_definition [int nat "Collect (op <= 0)"]
kleing@24333
    94
  by (rule td_nat_int)
kleing@24333
    95
wenzelm@27138
    96
declare
wenzelm@27138
    97
  nat_int.Rep_cases [cases del]
wenzelm@27138
    98
  nat_int.Abs_cases [cases del]
wenzelm@27138
    99
  nat_int.Rep_induct [induct del]
wenzelm@27138
   100
  nat_int.Abs_induct [induct del]
kleing@24333
   101
kleing@24333
   102
huffman@24350
   103
subsection "Extended form of type definition predicate"
kleing@24333
   104
kleing@24333
   105
lemma td_conds:
kleing@24333
   106
  "norm o norm = norm ==> (fr o norm = norm o fr) = 
kleing@24333
   107
    (norm o fr o norm = fr o norm & norm o fr o norm = norm o fr)"
kleing@24333
   108
  apply safe
kleing@24333
   109
    apply (simp_all add: o_assoc [symmetric])
kleing@24333
   110
   apply (simp_all add: o_assoc)
kleing@24333
   111
  done
kleing@24333
   112
kleing@24333
   113
lemma fn_comm_power:
kleing@24333
   114
  "fa o tr = tr o fr ==> fa ^ n o tr = tr o fr ^ n" 
kleing@24333
   115
  apply (rule ext) 
kleing@24333
   116
  apply (induct n)
kleing@24333
   117
   apply (auto dest: fun_cong)
kleing@24333
   118
  done
kleing@24333
   119
kleing@24333
   120
lemmas fn_comm_power' =
kleing@24333
   121
  ext [THEN fn_comm_power, THEN fun_cong, unfolded o_def, standard]
kleing@24333
   122
kleing@24333
   123
kleing@24333
   124
locale td_ext = type_definition +
kleing@24333
   125
  fixes norm
kleing@24333
   126
  assumes eq_norm: "\<And>x. Rep (Abs x) = norm x"
kleing@24333
   127
begin
kleing@24333
   128
kleing@24333
   129
lemma Abs_norm [simp]: 
kleing@24333
   130
  "Abs (norm x) = Abs x"
kleing@24333
   131
  using eq_norm [of x] by (auto elim: Rep_inverse')
kleing@24333
   132
kleing@24333
   133
lemma td_th:
kleing@24333
   134
  "g o Abs = f ==> f (Rep x) = g x"
kleing@24333
   135
  by (drule comp_Abs_inverse [symmetric]) simp
kleing@24333
   136
kleing@24333
   137
lemma eq_norm': "Rep o Abs = norm"
kleing@24333
   138
  by (auto simp: eq_norm intro!: ext)
kleing@24333
   139
kleing@24333
   140
lemma norm_Rep [simp]: "norm (Rep x) = Rep x"
kleing@24333
   141
  by (auto simp: eq_norm' intro: td_th)
kleing@24333
   142
kleing@24333
   143
lemmas td = td_thm
kleing@24333
   144
kleing@24333
   145
lemma set_iff_norm: "w : A <-> w = norm w"
kleing@24333
   146
  by (auto simp: set_Rep_Abs eq_norm' eq_norm [symmetric])
kleing@24333
   147
kleing@24333
   148
lemma inverse_norm: 
kleing@24333
   149
  "(Abs n = w) = (Rep w = norm n)"
kleing@24333
   150
  apply (rule iffI)
kleing@24333
   151
   apply (clarsimp simp add: eq_norm)
kleing@24333
   152
  apply (simp add: eq_norm' [symmetric])
kleing@24333
   153
  done
kleing@24333
   154
kleing@24333
   155
lemma norm_eq_iff: 
kleing@24333
   156
  "(norm x = norm y) = (Abs x = Abs y)"
kleing@24333
   157
  by (simp add: eq_norm' [symmetric])
kleing@24333
   158
kleing@24333
   159
lemma norm_comps: 
kleing@24333
   160
  "Abs o norm = Abs" 
kleing@24333
   161
  "norm o Rep = Rep" 
kleing@24333
   162
  "norm o norm = norm"
kleing@24333
   163
  by (auto simp: eq_norm' [symmetric] o_def)
kleing@24333
   164
kleing@24333
   165
lemmas norm_norm [simp] = norm_comps
kleing@24333
   166
kleing@24333
   167
lemma fns5: 
kleing@24333
   168
  "Rep o fa o Abs = fr ==> 
kleing@24333
   169
  fr o norm = fr & norm o fr = fr"
kleing@24333
   170
  by (fold eq_norm') (auto intro!: ext)
kleing@24333
   171
kleing@24333
   172
(* following give conditions for converses to td_fns1
kleing@24333
   173
  the condition (norm o fr o norm = fr o norm) says that 
kleing@24333
   174
  fr takes normalised arguments to normalised results,
kleing@24333
   175
  (norm o fr o norm = norm o fr) says that fr 
kleing@24333
   176
  takes norm-equivalent arguments to norm-equivalent results,
kleing@24333
   177
  (fr o norm = fr) says that fr 
kleing@24333
   178
  takes norm-equivalent arguments to the same result, and 
kleing@24333
   179
  (norm o fr = fr) says that fr takes any argument to a normalised result 
kleing@24333
   180
  *)
kleing@24333
   181
lemma fns2: 
kleing@24333
   182
  "Abs o fr o Rep = fa ==> 
kleing@24333
   183
   (norm o fr o norm = fr o norm) = (Rep o fa = fr o Rep)"
kleing@24333
   184
  apply (fold eq_norm')
kleing@24333
   185
  apply safe
kleing@24333
   186
   prefer 2
kleing@24333
   187
   apply (simp add: o_assoc)
kleing@24333
   188
  apply (rule ext)
kleing@24333
   189
  apply (drule_tac x="Rep x" in fun_cong)
kleing@24333
   190
  apply auto
kleing@24333
   191
  done
kleing@24333
   192
kleing@24333
   193
lemma fns3: 
kleing@24333
   194
  "Abs o fr o Rep = fa ==> 
kleing@24333
   195
   (norm o fr o norm = norm o fr) = (fa o Abs = Abs o fr)"
kleing@24333
   196
  apply (fold eq_norm')
kleing@24333
   197
  apply safe
kleing@24333
   198
   prefer 2
kleing@24333
   199
   apply (simp add: o_assoc [symmetric])
kleing@24333
   200
  apply (rule ext)
kleing@24333
   201
  apply (drule fun_cong)
kleing@24333
   202
  apply simp
kleing@24333
   203
  done
kleing@24333
   204
kleing@24333
   205
lemma fns: 
kleing@24333
   206
  "fr o norm = norm o fr ==> 
kleing@24333
   207
    (fa o Abs = Abs o fr) = (Rep o fa = fr o Rep)"
kleing@24333
   208
  apply safe
kleing@24333
   209
   apply (frule fns1b)
kleing@24333
   210
   prefer 2 
kleing@24333
   211
   apply (frule fns1a) 
kleing@24333
   212
   apply (rule fns3 [THEN iffD1])
kleing@24333
   213
     prefer 3
kleing@24333
   214
     apply (rule fns2 [THEN iffD1])
kleing@24333
   215
       apply (simp_all add: o_assoc [symmetric])
kleing@24333
   216
   apply (simp_all add: o_assoc)
kleing@24333
   217
  done
kleing@24333
   218
kleing@24333
   219
lemma range_norm:
kleing@24333
   220
  "range (Rep o Abs) = A"
kleing@24333
   221
  by (simp add: set_Rep_Abs)
kleing@24333
   222
kleing@24333
   223
end
kleing@24333
   224
kleing@24333
   225
lemmas td_ext_def' =
kleing@24333
   226
  td_ext_def [unfolded type_definition_def td_ext_axioms_def]
kleing@24333
   227
kleing@24333
   228
end
kleing@24333
   229