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