src/HOLCF/Universal.thy
author huffman
Fri, 13 Mar 2009 07:30:47 -0700
changeset 30505 110e59507eec
parent 29252 ea97aa6aeba2
child 30561 5e6088e1d6df
permissions -rw-r--r--
introduce new helper functions; clean up proofs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
     1
(*  Title:      HOLCF/Universal.thy
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
     2
    Author:     Brian Huffman
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
     3
*)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
     4
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
     5
theory Universal
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
     6
imports CompactBasis NatIso
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
     7
begin
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
     8
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
     9
subsection {* Basis datatype *}
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    10
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    11
types ubasis = nat
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    12
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    13
definition
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    14
  node :: "nat \<Rightarrow> ubasis \<Rightarrow> ubasis set \<Rightarrow> ubasis"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    15
where
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
    16
  "node i a S = Suc (prod2nat (i, prod2nat (a, set2nat S)))"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    17
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
    18
lemma node_not_0 [simp]: "node i a S \<noteq> 0"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    19
unfolding node_def by simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    20
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
    21
lemma node_gt_0 [simp]: "0 < node i a S"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    22
unfolding node_def by simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    23
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    24
lemma node_inject [simp]:
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
    25
  "\<lbrakk>finite S; finite T\<rbrakk>
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
    26
    \<Longrightarrow> node i a S = node j b T \<longleftrightarrow> i = j \<and> a = b \<and> S = T"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    27
unfolding node_def by simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    28
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
    29
lemma node_gt0: "i < node i a S"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    30
unfolding node_def less_Suc_eq_le
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    31
by (rule le_prod2nat_1)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    32
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
    33
lemma node_gt1: "a < node i a S"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    34
unfolding node_def less_Suc_eq_le
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    35
by (rule order_trans [OF le_prod2nat_1 le_prod2nat_2])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    36
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    37
lemma nat_less_power2: "n < 2^n"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    38
by (induct n) simp_all
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    39
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
    40
lemma node_gt2: "\<lbrakk>finite S; b \<in> S\<rbrakk> \<Longrightarrow> b < node i a S"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    41
unfolding node_def less_Suc_eq_le set2nat_def
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    42
apply (rule order_trans [OF _ le_prod2nat_2])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    43
apply (rule order_trans [OF _ le_prod2nat_2])
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
    44
apply (rule order_trans [where y="setsum (op ^ 2) {b}"])
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    45
apply (simp add: nat_less_power2 [THEN order_less_imp_le])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    46
apply (erule setsum_mono2, simp, simp)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    47
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    48
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    49
lemma eq_prod2nat_pairI:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    50
  "\<lbrakk>fst (nat2prod x) = a; snd (nat2prod x) = b\<rbrakk> \<Longrightarrow> x = prod2nat (a, b)"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    51
by (erule subst, erule subst, simp)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    52
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    53
lemma node_cases:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    54
  assumes 1: "x = 0 \<Longrightarrow> P"
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
    55
  assumes 2: "\<And>i a S. \<lbrakk>finite S; x = node i a S\<rbrakk> \<Longrightarrow> P"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    56
  shows "P"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    57
 apply (cases x)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    58
  apply (erule 1)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    59
 apply (rule 2)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    60
  apply (rule finite_nat2set)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    61
 apply (simp add: node_def)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    62
 apply (rule eq_prod2nat_pairI [OF refl])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    63
 apply (rule eq_prod2nat_pairI [OF refl refl])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    64
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    65
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    66
lemma node_induct:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    67
  assumes 1: "P 0"
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
    68
  assumes 2: "\<And>i a S. \<lbrakk>P a; finite S; \<forall>b\<in>S. P b\<rbrakk> \<Longrightarrow> P (node i a S)"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    69
  shows "P x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    70
 apply (induct x rule: nat_less_induct)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    71
 apply (case_tac n rule: node_cases)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    72
  apply (simp add: 1)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    73
 apply (simp add: 2 node_gt1 node_gt2)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    74
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    75
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    76
subsection {* Basis ordering *}
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    77
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    78
inductive
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    79
  ubasis_le :: "nat \<Rightarrow> nat \<Rightarrow> bool"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    80
where
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
    81
  ubasis_le_refl: "ubasis_le a a"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    82
| ubasis_le_trans:
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
    83
    "\<lbrakk>ubasis_le a b; ubasis_le b c\<rbrakk> \<Longrightarrow> ubasis_le a c"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    84
| ubasis_le_lower:
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
    85
    "finite S \<Longrightarrow> ubasis_le a (node i a S)"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    86
| ubasis_le_upper:
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
    87
    "\<lbrakk>finite S; b \<in> S; ubasis_le a b\<rbrakk> \<Longrightarrow> ubasis_le (node i a S) b"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    88
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    89
lemma ubasis_le_minimal: "ubasis_le 0 x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    90
apply (induct x rule: node_induct)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    91
apply (rule ubasis_le_refl)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    92
apply (erule ubasis_le_trans)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    93
apply (erule ubasis_le_lower)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    94
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    95
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    96
subsubsection {* Generic take function *}
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    97
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    98
function
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
    99
  ubasis_until :: "(ubasis \<Rightarrow> bool) \<Rightarrow> ubasis \<Rightarrow> ubasis"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   100
where
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   101
  "ubasis_until P 0 = 0"
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   102
| "finite S \<Longrightarrow> ubasis_until P (node i a S) =
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   103
    (if P (node i a S) then node i a S else ubasis_until P a)"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   104
    apply clarify
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   105
    apply (rule_tac x=b in node_cases)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   106
     apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   107
    apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   108
    apply fast
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   109
   apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   110
  apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   111
 apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   112
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   113
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   114
termination ubasis_until
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   115
apply (relation "measure snd")
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   116
apply (rule wf_measure)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   117
apply (simp add: node_gt1)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   118
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   119
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   120
lemma ubasis_until: "P 0 \<Longrightarrow> P (ubasis_until P x)"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   121
by (induct x rule: node_induct) simp_all
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   122
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   123
lemma ubasis_until': "0 < ubasis_until P x \<Longrightarrow> P (ubasis_until P x)"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   124
by (induct x rule: node_induct) auto
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   125
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   126
lemma ubasis_until_same: "P x \<Longrightarrow> ubasis_until P x = x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   127
by (induct x rule: node_induct) simp_all
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   128
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   129
lemma ubasis_until_idem:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   130
  "P 0 \<Longrightarrow> ubasis_until P (ubasis_until P x) = ubasis_until P x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   131
by (rule ubasis_until_same [OF ubasis_until])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   132
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   133
lemma ubasis_until_0:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   134
  "\<forall>x. x \<noteq> 0 \<longrightarrow> \<not> P x \<Longrightarrow> ubasis_until P x = 0"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   135
by (induct x rule: node_induct) simp_all
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   136
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   137
lemma ubasis_until_less: "ubasis_le (ubasis_until P x) x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   138
apply (induct x rule: node_induct)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   139
apply (simp add: ubasis_le_refl)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   140
apply (simp add: ubasis_le_refl)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   141
apply (rule impI)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   142
apply (erule ubasis_le_trans)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   143
apply (erule ubasis_le_lower)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   144
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   145
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   146
lemma ubasis_until_chain:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   147
  assumes PQ: "\<And>x. P x \<Longrightarrow> Q x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   148
  shows "ubasis_le (ubasis_until P x) (ubasis_until Q x)"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   149
apply (induct x rule: node_induct)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   150
apply (simp add: ubasis_le_refl)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   151
apply (simp add: ubasis_le_refl)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   152
apply (simp add: PQ)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   153
apply clarify
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   154
apply (rule ubasis_le_trans)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   155
apply (rule ubasis_until_less)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   156
apply (erule ubasis_le_lower)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   157
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   158
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   159
lemma ubasis_until_mono:
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   160
  assumes "\<And>i a S b. \<lbrakk>finite S; P (node i a S); b \<in> S; ubasis_le a b\<rbrakk> \<Longrightarrow> P b"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   161
  shows "ubasis_le a b \<Longrightarrow> ubasis_le (ubasis_until P a) (ubasis_until P b)"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   162
 apply (induct set: ubasis_le)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   163
    apply (rule ubasis_le_refl)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   164
   apply (erule (1) ubasis_le_trans)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   165
  apply (simp add: ubasis_le_refl)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   166
  apply (rule impI)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   167
  apply (rule ubasis_le_trans)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   168
   apply (rule ubasis_until_less)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   169
  apply (erule ubasis_le_lower)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   170
 apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   171
 apply (rule impI)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   172
 apply (subst ubasis_until_same)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   173
  apply (erule (3) prems)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   174
 apply (erule (2) ubasis_le_upper)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   175
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   176
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   177
lemma finite_range_ubasis_until:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   178
  "finite {x. P x} \<Longrightarrow> finite (range (ubasis_until P))"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   179
apply (rule finite_subset [where B="insert 0 {x. P x}"])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   180
apply (clarsimp simp add: ubasis_until')
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   181
apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   182
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   183
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   184
subsubsection {* Take function for @{typ ubasis} *}
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   185
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   186
definition
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   187
  ubasis_take :: "nat \<Rightarrow> ubasis \<Rightarrow> ubasis"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   188
where
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   189
  "ubasis_take n = ubasis_until (\<lambda>x. x \<le> n)"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   190
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   191
lemma ubasis_take_le: "ubasis_take n x \<le> n"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   192
unfolding ubasis_take_def by (rule ubasis_until, rule le0)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   193
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   194
lemma ubasis_take_same: "x \<le> n \<Longrightarrow> ubasis_take n x = x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   195
unfolding ubasis_take_def by (rule ubasis_until_same)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   196
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   197
lemma ubasis_take_idem: "ubasis_take n (ubasis_take n x) = ubasis_take n x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   198
by (rule ubasis_take_same [OF ubasis_take_le])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   199
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   200
lemma ubasis_take_0 [simp]: "ubasis_take 0 x = 0"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   201
unfolding ubasis_take_def by (simp add: ubasis_until_0)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   202
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   203
lemma ubasis_take_less: "ubasis_le (ubasis_take n x) x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   204
unfolding ubasis_take_def by (rule ubasis_until_less)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   205
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   206
lemma ubasis_take_chain: "ubasis_le (ubasis_take n x) (ubasis_take (Suc n) x)"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   207
unfolding ubasis_take_def by (rule ubasis_until_chain) simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   208
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   209
lemma ubasis_take_mono:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   210
  assumes "ubasis_le x y"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   211
  shows "ubasis_le (ubasis_take n x) (ubasis_take n y)"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   212
unfolding ubasis_take_def
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   213
 apply (rule ubasis_until_mono [OF _ prems])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   214
 apply (frule (2) order_less_le_trans [OF node_gt2])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   215
 apply (erule order_less_imp_le)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   216
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   217
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   218
lemma finite_range_ubasis_take: "finite (range (ubasis_take n))"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   219
apply (rule finite_subset [where B="{..n}"])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   220
apply (simp add: subset_eq ubasis_take_le)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   221
apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   222
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   223
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   224
lemma ubasis_take_covers: "\<exists>n. ubasis_take n x = x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   225
apply (rule exI [where x=x])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   226
apply (simp add: ubasis_take_same)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   227
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   228
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28889
diff changeset
   229
interpretation udom!: preorder ubasis_le
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   230
apply default
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   231
apply (rule ubasis_le_refl)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   232
apply (erule (1) ubasis_le_trans)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   233
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   234
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28889
diff changeset
   235
interpretation udom!: basis_take ubasis_le ubasis_take
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   236
apply default
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   237
apply (rule ubasis_take_less)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   238
apply (rule ubasis_take_idem)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   239
apply (erule ubasis_take_mono)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   240
apply (rule ubasis_take_chain)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   241
apply (rule finite_range_ubasis_take)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   242
apply (rule ubasis_take_covers)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   243
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   244
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   245
subsection {* Defining the universal domain by ideal completion *}
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   246
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   247
typedef (open) udom = "{S. udom.ideal S}"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   248
by (fast intro: udom.ideal_principal)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   249
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   250
instantiation udom :: sq_ord
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   251
begin
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   252
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   253
definition
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   254
  "x \<sqsubseteq> y \<longleftrightarrow> Rep_udom x \<subseteq> Rep_udom y"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   255
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   256
instance ..
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   257
end
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   258
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   259
instance udom :: po
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   260
by (rule udom.typedef_ideal_po
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   261
    [OF type_definition_udom sq_le_udom_def])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   262
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   263
instance udom :: cpo
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   264
by (rule udom.typedef_ideal_cpo
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   265
    [OF type_definition_udom sq_le_udom_def])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   266
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   267
lemma Rep_udom_lub:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   268
  "chain Y \<Longrightarrow> Rep_udom (\<Squnion>i. Y i) = (\<Union>i. Rep_udom (Y i))"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   269
by (rule udom.typedef_ideal_rep_contlub
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   270
    [OF type_definition_udom sq_le_udom_def])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   271
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   272
lemma ideal_Rep_udom: "udom.ideal (Rep_udom xs)"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   273
by (rule Rep_udom [unfolded mem_Collect_eq])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   274
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   275
definition
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   276
  udom_principal :: "nat \<Rightarrow> udom" where
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   277
  "udom_principal t = Abs_udom {u. ubasis_le u t}"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   278
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   279
lemma Rep_udom_principal:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   280
  "Rep_udom (udom_principal t) = {u. ubasis_le u t}"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   281
unfolding udom_principal_def
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   282
by (simp add: Abs_udom_inverse udom.ideal_principal)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   283
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28889
diff changeset
   284
interpretation udom!:
e90d9d51106b More porting to new locales.
ballarin
parents: 28889
diff changeset
   285
  ideal_completion ubasis_le ubasis_take udom_principal Rep_udom
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   286
apply unfold_locales
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   287
apply (rule ideal_Rep_udom)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   288
apply (erule Rep_udom_lub)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   289
apply (rule Rep_udom_principal)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   290
apply (simp only: sq_le_udom_def)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   291
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   292
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   293
text {* Universal domain is pointed *}
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   294
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   295
lemma udom_minimal: "udom_principal 0 \<sqsubseteq> x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   296
apply (induct x rule: udom.principal_induct)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   297
apply (simp, simp add: ubasis_le_minimal)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   298
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   299
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   300
instance udom :: pcpo
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   301
by intro_classes (fast intro: udom_minimal)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   302
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   303
lemma inst_udom_pcpo: "\<bottom> = udom_principal 0"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   304
by (rule udom_minimal [THEN UU_I, symmetric])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   305
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   306
text {* Universal domain is bifinite *}
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   307
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   308
instantiation udom :: bifinite
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   309
begin
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   310
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   311
definition
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   312
  approx_udom_def: "approx = udom.completion_approx"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   313
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   314
instance
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   315
apply (intro_classes, unfold approx_udom_def)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   316
apply (rule udom.chain_completion_approx)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   317
apply (rule udom.lub_completion_approx)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   318
apply (rule udom.completion_approx_idem)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   319
apply (rule udom.finite_fixes_completion_approx)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   320
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   321
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   322
end
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   323
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   324
lemma approx_udom_principal [simp]:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   325
  "approx n\<cdot>(udom_principal x) = udom_principal (ubasis_take n x)"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   326
unfolding approx_udom_def
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   327
by (rule udom.completion_approx_principal)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   328
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   329
lemma approx_eq_udom_principal:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   330
  "\<exists>a\<in>Rep_udom x. approx n\<cdot>x = udom_principal (ubasis_take n a)"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   331
unfolding approx_udom_def
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   332
by (rule udom.completion_approx_eq_principal)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   333
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   334
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   335
subsection {* Universality of @{typ udom} *}
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   336
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   337
defaultsort bifinite
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   338
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   339
subsubsection {* Choosing a maximal element from a finite set *}
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   340
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   341
lemma finite_has_maximal:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   342
  fixes A :: "'a::po set"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   343
  shows "\<lbrakk>finite A; A \<noteq> {}\<rbrakk> \<Longrightarrow> \<exists>x\<in>A. \<forall>y\<in>A. x \<sqsubseteq> y \<longrightarrow> x = y"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   344
proof (induct rule: finite_ne_induct)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   345
  case (singleton x)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   346
    show ?case by simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   347
next
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   348
  case (insert a A)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   349
  from `\<exists>x\<in>A. \<forall>y\<in>A. x \<sqsubseteq> y \<longrightarrow> x = y`
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   350
  obtain x where x: "x \<in> A"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   351
           and x_eq: "\<And>y. \<lbrakk>y \<in> A; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> x = y" by fast
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   352
  show ?case
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   353
  proof (intro bexI ballI impI)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   354
    fix y
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   355
    assume "y \<in> insert a A" and "(if x \<sqsubseteq> a then a else x) \<sqsubseteq> y"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   356
    thus "(if x \<sqsubseteq> a then a else x) = y"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   357
      apply auto
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   358
      apply (frule (1) trans_less)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   359
      apply (frule (1) x_eq)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   360
      apply (rule antisym_less, assumption)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   361
      apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   362
      apply (erule (1) x_eq)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   363
      done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   364
  next
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   365
    show "(if x \<sqsubseteq> a then a else x) \<in> insert a A"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   366
      by (simp add: x)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   367
  qed
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   368
qed
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   369
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   370
definition
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   371
  choose :: "'a compact_basis set \<Rightarrow> 'a compact_basis"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   372
where
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   373
  "choose A = (SOME x. x \<in> {x\<in>A. \<forall>y\<in>A. x \<sqsubseteq> y \<longrightarrow> x = y})"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   374
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   375
lemma choose_lemma:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   376
  "\<lbrakk>finite A; A \<noteq> {}\<rbrakk> \<Longrightarrow> choose A \<in> {x\<in>A. \<forall>y\<in>A. x \<sqsubseteq> y \<longrightarrow> x = y}"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   377
unfolding choose_def
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   378
apply (rule someI_ex)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   379
apply (frule (1) finite_has_maximal, fast)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   380
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   381
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   382
lemma maximal_choose:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   383
  "\<lbrakk>finite A; y \<in> A; choose A \<sqsubseteq> y\<rbrakk> \<Longrightarrow> choose A = y"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   384
apply (cases "A = {}", simp)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   385
apply (frule (1) choose_lemma, simp)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   386
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   387
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   388
lemma choose_in: "\<lbrakk>finite A; A \<noteq> {}\<rbrakk> \<Longrightarrow> choose A \<in> A"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   389
by (frule (1) choose_lemma, simp)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   390
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   391
function
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   392
  choose_pos :: "'a compact_basis set \<Rightarrow> 'a compact_basis \<Rightarrow> nat"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   393
where
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   394
  "choose_pos A x =
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   395
    (if finite A \<and> x \<in> A \<and> x \<noteq> choose A
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   396
      then Suc (choose_pos (A - {choose A}) x) else 0)"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   397
by auto
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   398
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   399
termination choose_pos
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   400
apply (relation "measure (card \<circ> fst)", simp)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   401
apply clarsimp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   402
apply (rule card_Diff1_less)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   403
apply assumption
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   404
apply (erule choose_in)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   405
apply clarsimp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   406
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   407
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   408
declare choose_pos.simps [simp del]
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   409
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   410
lemma choose_pos_choose: "finite A \<Longrightarrow> choose_pos A (choose A) = 0"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   411
by (simp add: choose_pos.simps)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   412
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   413
lemma inj_on_choose_pos [OF refl]:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   414
  "\<lbrakk>card A = n; finite A\<rbrakk> \<Longrightarrow> inj_on (choose_pos A) A"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   415
 apply (induct n arbitrary: A)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   416
  apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   417
 apply (case_tac "A = {}", simp)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   418
 apply (frule (1) choose_in)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   419
 apply (rule inj_onI)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   420
 apply (drule_tac x="A - {choose A}" in meta_spec, simp)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   421
 apply (simp add: choose_pos.simps)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   422
 apply (simp split: split_if_asm)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   423
 apply (erule (1) inj_onD, simp, simp)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   424
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   425
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   426
lemma choose_pos_bounded [OF refl]:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   427
  "\<lbrakk>card A = n; finite A; x \<in> A\<rbrakk> \<Longrightarrow> choose_pos A x < n"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   428
apply (induct n arbitrary: A)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   429
apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   430
 apply (case_tac "A = {}", simp)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   431
 apply (frule (1) choose_in)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   432
apply (subst choose_pos.simps)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   433
apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   434
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   435
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   436
lemma choose_pos_lessD:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   437
  "\<lbrakk>choose_pos A x < choose_pos A y; finite A; x \<in> A; y \<in> A\<rbrakk> \<Longrightarrow> \<not> x \<sqsubseteq> y"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   438
 apply (induct A x arbitrary: y rule: choose_pos.induct)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   439
 apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   440
 apply (case_tac "x = choose A")
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   441
  apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   442
  apply (rule notI)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   443
  apply (frule (2) maximal_choose)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   444
  apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   445
 apply (case_tac "y = choose A")
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   446
  apply (simp add: choose_pos_choose)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   447
 apply (drule_tac x=y in meta_spec)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   448
 apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   449
 apply (erule meta_mp)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   450
 apply (simp add: choose_pos.simps)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   451
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   452
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   453
subsubsection {* Rank of basis elements *}
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   454
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   455
primrec
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   456
  cb_take :: "nat \<Rightarrow> 'a compact_basis \<Rightarrow> 'a compact_basis"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   457
where
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   458
  "cb_take 0 = (\<lambda>x. compact_bot)"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   459
| "cb_take (Suc n) = compact_take n"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   460
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   461
lemma cb_take_covers: "\<exists>n. cb_take n x = x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   462
apply (rule exE [OF compact_basis.take_covers [where a=x]])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   463
apply (rename_tac n, rule_tac x="Suc n" in exI, simp)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   464
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   465
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   466
lemma cb_take_less: "cb_take n x \<sqsubseteq> x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   467
by (cases n, simp, simp add: compact_basis.take_less)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   468
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   469
lemma cb_take_idem: "cb_take n (cb_take n x) = cb_take n x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   470
by (cases n, simp, simp add: compact_basis.take_take)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   471
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   472
lemma cb_take_mono: "x \<sqsubseteq> y \<Longrightarrow> cb_take n x \<sqsubseteq> cb_take n y"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   473
by (cases n, simp, simp add: compact_basis.take_mono)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   474
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   475
lemma cb_take_chain_le: "m \<le> n \<Longrightarrow> cb_take m x \<sqsubseteq> cb_take n x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   476
apply (cases m, simp)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   477
apply (cases n, simp)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   478
apply (simp add: compact_basis.take_chain_le)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   479
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   480
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   481
lemma range_const: "range (\<lambda>x. c) = {c}"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   482
by auto
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   483
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   484
lemma finite_range_cb_take: "finite (range (cb_take n))"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   485
apply (cases n)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   486
apply (simp add: range_const)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   487
apply (simp add: compact_basis.finite_range_take)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   488
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   489
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   490
definition
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   491
  rank :: "'a compact_basis \<Rightarrow> nat"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   492
where
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   493
  "rank x = (LEAST n. cb_take n x = x)"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   494
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   495
lemma compact_approx_rank: "cb_take (rank x) x = x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   496
unfolding rank_def
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   497
apply (rule LeastI_ex)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   498
apply (rule cb_take_covers)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   499
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   500
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   501
lemma rank_leD: "rank x \<le> n \<Longrightarrow> cb_take n x = x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   502
apply (rule antisym_less [OF cb_take_less])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   503
apply (subst compact_approx_rank [symmetric])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   504
apply (erule cb_take_chain_le)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   505
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   506
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   507
lemma rank_leI: "cb_take n x = x \<Longrightarrow> rank x \<le> n"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   508
unfolding rank_def by (rule Least_le)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   509
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   510
lemma rank_le_iff: "rank x \<le> n \<longleftrightarrow> cb_take n x = x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   511
by (rule iffI [OF rank_leD rank_leI])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   512
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   513
lemma rank_compact_bot [simp]: "rank compact_bot = 0"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   514
using rank_leI [of 0 compact_bot] by simp
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   515
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   516
lemma rank_eq_0_iff [simp]: "rank x = 0 \<longleftrightarrow> x = compact_bot"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   517
using rank_le_iff [of x 0] by auto
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   518
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   519
definition
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   520
  rank_le :: "'a compact_basis \<Rightarrow> 'a compact_basis set"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   521
where
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   522
  "rank_le x = {y. rank y \<le> rank x}"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   523
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   524
definition
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   525
  rank_lt :: "'a compact_basis \<Rightarrow> 'a compact_basis set"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   526
where
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   527
  "rank_lt x = {y. rank y < rank x}"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   528
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   529
definition
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   530
  rank_eq :: "'a compact_basis \<Rightarrow> 'a compact_basis set"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   531
where
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   532
  "rank_eq x = {y. rank y = rank x}"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   533
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   534
lemma rank_eq_cong: "rank x = rank y \<Longrightarrow> rank_eq x = rank_eq y"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   535
unfolding rank_eq_def by simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   536
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   537
lemma rank_lt_cong: "rank x = rank y \<Longrightarrow> rank_lt x = rank_lt y"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   538
unfolding rank_lt_def by simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   539
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   540
lemma rank_eq_subset: "rank_eq x \<subseteq> rank_le x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   541
unfolding rank_eq_def rank_le_def by auto
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   542
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   543
lemma rank_lt_subset: "rank_lt x \<subseteq> rank_le x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   544
unfolding rank_lt_def rank_le_def by auto
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   545
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   546
lemma finite_rank_le: "finite (rank_le x)"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   547
unfolding rank_le_def
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   548
apply (rule finite_subset [where B="range (cb_take (rank x))"])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   549
apply clarify
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   550
apply (rule range_eqI)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   551
apply (erule rank_leD [symmetric])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   552
apply (rule finite_range_cb_take)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   553
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   554
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   555
lemma finite_rank_eq: "finite (rank_eq x)"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   556
by (rule finite_subset [OF rank_eq_subset finite_rank_le])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   557
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   558
lemma finite_rank_lt: "finite (rank_lt x)"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   559
by (rule finite_subset [OF rank_lt_subset finite_rank_le])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   560
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   561
lemma rank_lt_Int_rank_eq: "rank_lt x \<inter> rank_eq x = {}"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   562
unfolding rank_lt_def rank_eq_def rank_le_def by auto
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   563
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   564
lemma rank_lt_Un_rank_eq: "rank_lt x \<union> rank_eq x = rank_le x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   565
unfolding rank_lt_def rank_eq_def rank_le_def by auto
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   566
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   567
subsubsection {* Sequencing basis elements *}
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   568
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   569
definition
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   570
  place :: "'a compact_basis \<Rightarrow> nat"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   571
where
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   572
  "place x = card (rank_lt x) + choose_pos (rank_eq x) x"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   573
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   574
lemma place_bounded: "place x < card (rank_le x)"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   575
unfolding place_def
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   576
 apply (rule ord_less_eq_trans)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   577
  apply (rule add_strict_left_mono)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   578
  apply (rule choose_pos_bounded)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   579
   apply (rule finite_rank_eq)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   580
  apply (simp add: rank_eq_def)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   581
 apply (subst card_Un_disjoint [symmetric])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   582
    apply (rule finite_rank_lt)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   583
   apply (rule finite_rank_eq)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   584
  apply (rule rank_lt_Int_rank_eq)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   585
 apply (simp add: rank_lt_Un_rank_eq)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   586
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   587
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   588
lemma place_ge: "card (rank_lt x) \<le> place x"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   589
unfolding place_def by simp
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   590
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   591
lemma place_rank_mono:
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   592
  fixes x y :: "'a compact_basis"
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   593
  shows "rank x < rank y \<Longrightarrow> place x < place y"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   594
apply (rule less_le_trans [OF place_bounded])
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   595
apply (rule order_trans [OF _ place_ge])
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   596
apply (rule card_mono)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   597
apply (rule finite_rank_lt)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   598
apply (simp add: rank_le_def rank_lt_def subset_eq)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   599
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   600
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   601
lemma place_eqD: "place x = place y \<Longrightarrow> x = y"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   602
 apply (rule linorder_cases [where x="rank x" and y="rank y"])
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   603
   apply (drule place_rank_mono, simp)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   604
  apply (simp add: place_def)
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   605
  apply (rule inj_on_choose_pos [where A="rank_eq x", THEN inj_onD])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   606
     apply (rule finite_rank_eq)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   607
    apply (simp cong: rank_lt_cong rank_eq_cong)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   608
   apply (simp add: rank_eq_def)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   609
  apply (simp add: rank_eq_def)
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   610
 apply (drule place_rank_mono, simp)
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   611
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   612
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   613
lemma inj_place: "inj place"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   614
by (rule inj_onI, erule place_eqD)
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   615
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   616
subsubsection {* Embedding and projection on basis elements *}
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   617
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   618
definition
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   619
  sub :: "'a compact_basis \<Rightarrow> 'a compact_basis"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   620
where
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   621
  "sub x = (case rank x of 0 \<Rightarrow> compact_bot | Suc k \<Rightarrow> cb_take k x)"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   622
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   623
lemma rank_sub_less: "x \<noteq> compact_bot \<Longrightarrow> rank (sub x) < rank x"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   624
unfolding sub_def
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   625
apply (cases "rank x", simp)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   626
apply (simp add: less_Suc_eq_le)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   627
apply (rule rank_leI)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   628
apply (rule cb_take_idem)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   629
done
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   630
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   631
lemma place_sub_less: "x \<noteq> compact_bot \<Longrightarrow> place (sub x) < place x"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   632
apply (rule place_rank_mono)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   633
apply (erule rank_sub_less)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   634
done
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   635
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   636
lemma sub_below: "sub x \<sqsubseteq> x"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   637
unfolding sub_def by (cases "rank x", simp_all add: cb_take_less)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   638
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   639
lemma rank_less_imp_below_sub: "\<lbrakk>x \<sqsubseteq> y; rank x < rank y\<rbrakk> \<Longrightarrow> x \<sqsubseteq> sub y"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   640
unfolding sub_def
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   641
apply (cases "rank y", simp)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   642
apply (simp add: less_Suc_eq_le)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   643
apply (subgoal_tac "cb_take nat x \<sqsubseteq> cb_take nat y")
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   644
apply (simp add: rank_leD)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   645
apply (erule cb_take_mono)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   646
done
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   647
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   648
function
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   649
  basis_emb :: "'a compact_basis \<Rightarrow> ubasis"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   650
where
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   651
  "basis_emb x = (if x = compact_bot then 0 else
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   652
    node (place x) (basis_emb (sub x))
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   653
      (basis_emb ` {y. place y < place x \<and> x \<sqsubseteq> y}))"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   654
by auto
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   655
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   656
termination basis_emb
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   657
apply (relation "measure place", simp)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   658
apply (simp add: place_sub_less)
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   659
apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   660
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   661
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   662
declare basis_emb.simps [simp del]
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   663
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   664
lemma basis_emb_compact_bot [simp]: "basis_emb compact_bot = 0"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   665
by (simp add: basis_emb.simps)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   666
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   667
lemma fin1: "finite {y. place y < place x \<and> x \<sqsubseteq> y}"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   668
apply (subst Collect_conj_eq)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   669
apply (rule finite_Int)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   670
apply (rule disjI1)
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   671
apply (subgoal_tac "finite (place -` {n. n < place x})", simp)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   672
apply (rule finite_vimageI [OF _ inj_place])
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   673
apply (simp add: lessThan_def [symmetric])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   674
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   675
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   676
lemma fin2: "finite (basis_emb ` {y. place y < place x \<and> x \<sqsubseteq> y})"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   677
by (rule finite_imageI [OF fin1])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   678
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   679
lemma rank_place_mono:
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   680
  "\<lbrakk>place x < place y; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> rank x < rank y"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   681
apply (rule linorder_cases, assumption)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   682
apply (simp add: place_def cong: rank_lt_cong rank_eq_cong)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   683
apply (drule choose_pos_lessD)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   684
apply (rule finite_rank_eq)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   685
apply (simp add: rank_eq_def)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   686
apply (simp add: rank_eq_def)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   687
apply simp
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   688
apply (drule place_rank_mono, simp)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   689
done
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   690
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   691
lemma basis_emb_mono:
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   692
  "x \<sqsubseteq> y \<Longrightarrow> ubasis_le (basis_emb x) (basis_emb y)"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   693
proof (induct n \<equiv> "max (place x) (place y)" arbitrary: x y rule: less_induct)
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   694
  case (less n)
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   695
  hence IH:
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   696
    "\<And>(a::'a compact_basis) b.
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   697
     \<lbrakk>max (place a) (place b) < max (place x) (place y); a \<sqsubseteq> b\<rbrakk>
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   698
        \<Longrightarrow> ubasis_le (basis_emb a) (basis_emb b)"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   699
    by simp
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   700
  show ?case proof (rule linorder_cases)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   701
    assume "place x < place y"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   702
    then have "rank x < rank y"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   703
      using `x \<sqsubseteq> y` by (rule rank_place_mono)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   704
    with `place x < place y` show ?case
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   705
      apply (case_tac "y = compact_bot", simp)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   706
      apply (simp add: basis_emb.simps [of y])
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   707
      apply (rule ubasis_le_trans [OF _ ubasis_le_lower [OF fin2]])
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   708
      apply (rule IH)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   709
       apply (simp add: less_max_iff_disj)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   710
       apply (erule place_sub_less)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   711
      apply (erule rank_less_imp_below_sub [OF `x \<sqsubseteq> y`])
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   712
      done
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   713
  next
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   714
    assume "place x = place y"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   715
    hence "x = y" by (rule place_eqD)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   716
    thus ?case by (simp add: ubasis_le_refl)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   717
  next
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   718
    assume "place x > place y"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   719
    with `x \<sqsubseteq> y` show ?case
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   720
      apply (case_tac "x = compact_bot", simp add: ubasis_le_minimal)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   721
      apply (simp add: basis_emb.simps [of x])
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   722
      apply (rule ubasis_le_upper [OF fin2], simp)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   723
      apply (rule IH)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   724
       apply (simp add: less_max_iff_disj)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   725
       apply (erule place_sub_less)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   726
      apply (erule rev_trans_less)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   727
      apply (rule sub_below)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   728
      done
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   729
  qed
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   730
qed
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   731
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   732
lemma inj_basis_emb: "inj basis_emb"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   733
 apply (rule inj_onI)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   734
 apply (case_tac "x = compact_bot")
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   735
  apply (case_tac [!] "y = compact_bot")
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   736
    apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   737
   apply (simp add: basis_emb.simps)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   738
  apply (simp add: basis_emb.simps)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   739
 apply (simp add: basis_emb.simps)
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   740
 apply (simp add: fin2 inj_eq [OF inj_place])
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   741
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   742
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   743
definition
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   744
  basis_prj :: "ubasis \<Rightarrow> 'a compact_basis"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   745
where
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   746
  "basis_prj x = inv basis_emb
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   747
    (ubasis_until (\<lambda>x. x \<in> range (basis_emb :: 'a compact_basis \<Rightarrow> ubasis)) x)"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   748
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   749
lemma basis_prj_basis_emb: "\<And>x. basis_prj (basis_emb x) = x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   750
unfolding basis_prj_def
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   751
 apply (subst ubasis_until_same)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   752
  apply (rule rangeI)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   753
 apply (rule inv_f_f)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   754
 apply (rule inj_basis_emb)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   755
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   756
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   757
lemma basis_prj_node:
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   758
  "\<lbrakk>finite S; node i a S \<notin> range (basis_emb :: 'a compact_basis \<Rightarrow> nat)\<rbrakk>
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   759
    \<Longrightarrow> basis_prj (node i a S) = (basis_prj a :: 'a compact_basis)"
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   760
unfolding basis_prj_def by simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   761
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   762
lemma basis_prj_0: "basis_prj 0 = compact_bot"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   763
apply (subst basis_emb_compact_bot [symmetric])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   764
apply (rule basis_prj_basis_emb)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   765
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   766
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   767
lemma node_eq_basis_emb_iff:
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   768
  "finite S \<Longrightarrow> node i a S = basis_emb x \<longleftrightarrow>
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   769
    x \<noteq> compact_bot \<and> i = place x \<and> a = basis_emb (sub x) \<and>
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   770
        S = basis_emb ` {y. place y < place x \<and> x \<sqsubseteq> y}"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   771
apply (cases "x = compact_bot", simp)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   772
apply (simp add: basis_emb.simps [of x])
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   773
apply (simp add: fin2)
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   774
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   775
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   776
lemma basis_prj_mono: "ubasis_le a b \<Longrightarrow> basis_prj a \<sqsubseteq> basis_prj b"
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   777
proof (induct a b rule: ubasis_le.induct)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   778
  case (ubasis_le_refl a) show ?case by (rule refl_less)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   779
next
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   780
  case (ubasis_le_trans a b c) thus ?case by - (rule trans_less)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   781
next
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   782
  case (ubasis_le_lower S a i) thus ?case
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   783
    apply (case_tac "node i a S \<in> range (basis_emb :: 'a compact_basis \<Rightarrow> nat)")
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   784
     apply (erule rangeE, rename_tac x)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   785
     apply (simp add: basis_prj_basis_emb)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   786
     apply (simp add: node_eq_basis_emb_iff)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   787
     apply (simp add: basis_prj_basis_emb)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   788
     apply (rule sub_below)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   789
    apply (simp add: basis_prj_node)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   790
    done
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   791
next
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   792
  case (ubasis_le_upper S b a i) thus ?case
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   793
    apply (case_tac "node i a S \<in> range (basis_emb :: 'a compact_basis \<Rightarrow> nat)")
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   794
     apply (erule rangeE, rename_tac x)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   795
     apply (simp add: basis_prj_basis_emb)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   796
     apply (clarsimp simp add: node_eq_basis_emb_iff)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   797
     apply (simp add: basis_prj_basis_emb)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   798
    apply (simp add: basis_prj_node)
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   799
    done
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   800
qed
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   801
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   802
lemma basis_emb_prj_less: "ubasis_le (basis_emb (basis_prj x)) x"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   803
unfolding basis_prj_def
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   804
 apply (subst f_inv_f [where f=basis_emb])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   805
  apply (rule ubasis_until)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   806
  apply (rule range_eqI [where x=compact_bot])
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   807
  apply simp
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   808
 apply (rule ubasis_until_less)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   809
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   810
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   811
hide (open) const
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   812
  node
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   813
  choose
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   814
  choose_pos
30505
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   815
  place
110e59507eec introduce new helper functions; clean up proofs
huffman
parents: 29252
diff changeset
   816
  sub
27411
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   817
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   818
subsubsection {* EP-pair from any bifinite domain into @{typ udom} *}
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   819
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   820
definition
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   821
  udom_emb :: "'a::bifinite \<rightarrow> udom"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   822
where
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   823
  "udom_emb = compact_basis.basis_fun (\<lambda>x. udom_principal (basis_emb x))"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   824
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   825
definition
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   826
  udom_prj :: "udom \<rightarrow> 'a::bifinite"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   827
where
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   828
  "udom_prj = udom.basis_fun (\<lambda>x. Rep_compact_basis (basis_prj x))"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   829
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   830
lemma udom_emb_principal:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   831
  "udom_emb\<cdot>(Rep_compact_basis x) = udom_principal (basis_emb x)"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   832
unfolding udom_emb_def
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   833
apply (rule compact_basis.basis_fun_principal)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   834
apply (rule udom.principal_mono)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   835
apply (erule basis_emb_mono)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   836
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   837
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   838
lemma udom_prj_principal:
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   839
  "udom_prj\<cdot>(udom_principal x) = Rep_compact_basis (basis_prj x)"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   840
unfolding udom_prj_def
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   841
apply (rule udom.basis_fun_principal)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   842
apply (rule compact_basis.principal_mono)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   843
apply (erule basis_prj_mono)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   844
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   845
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   846
lemma ep_pair_udom: "ep_pair udom_emb udom_prj"
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   847
 apply default
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   848
  apply (rule compact_basis.principal_induct, simp)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   849
  apply (simp add: udom_emb_principal udom_prj_principal)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   850
  apply (simp add: basis_prj_basis_emb)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   851
 apply (rule udom.principal_induct, simp)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   852
 apply (simp add: udom_emb_principal udom_prj_principal)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   853
 apply (rule basis_emb_prj_less)
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   854
done
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   855
60fad3219d32 universal bifinite domain
huffman
parents:
diff changeset
   856
end