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