Theory Coerce

Up to index of Isabelle/HOL/Constructor

theory Coerce
imports Representable
begin

header {* Coercion Operators *}

theory Coerce
imports Representable
begin

constdefs 
  coerce :: "'a => 'b"
  "coerce x ≡ proj (emb x)"

lemma proj_emb: "proj (emb x) = coerce x"
by (simp add: coerce_def)

text "Trivial instances of @{term coerce}"

lemma coerce_eq_id [simp]: "(coerce::'a => 'a) = id"
by (rule ext, simp add: coerce_def)

lemma coerce_eq_emb [simp]: "(coerce::'a => U) = emb"
by (rule ext, simp add: coerce_def)

lemma coerce_eq_proj [simp]: "(coerce::U => 'a) = proj"
by (rule ext, simp add: coerce_def)

text "Cancellation rules"

lemma emb_coerce [simp]:
  "emb x ::: rep_of TYPE('a) ==> emb ((coerce x)::'a) = emb x"
by (simp add: coerce_def)

lemma emb_coerce2:
  "rep_of TYPE('a) ≤ rep_of TYPE('b)
   ==> emb ((coerce::'a => 'b) x) = emb x"
by (simp add: coerce_def)

lemma coerce_idem [simp]:
  "rep_of TYPE('a) ≤ rep_of TYPE('b)
   ==> coerce ((coerce::'a => 'b) x) = coerce x"
by (simp add: coerce_def)

lemma coerce_inverse [simp]:
  "emb (x::'a) ::: rep_of TYPE('b) ==> coerce (coerce x :: 'b) = x"
by (simp only: coerce_def proj_inverse emb_inverse)

lemma coerce_type:
  "rep_of TYPE('a) ≤ rep_of TYPE('b)
   ==> emb ((coerce::'a => 'b) x) ::: rep_of TYPE('a)"
by (simp add: coerce_def)

lemma inj_coerce:
  "rep_of TYPE('a) ≤ rep_of TYPE('b)
   ==> inj (coerce::'a => 'b)"
 apply (rule inj_on_inverseI)
 apply (rule coerce_inverse)
 apply simp
done

end

lemma proj_emb:

  proj (emb x) = coerce x

lemma coerce_eq_id:

  coerce = id

lemma coerce_eq_emb:

  coerce = emb

lemma coerce_eq_proj:

  coerce = proj

lemma emb_coerce:

  emb x ::: rep_of TYPE('a) ==> emb (coerce x) = emb x

lemma emb_coerce2:

  rep_of TYPE('a) ≤ rep_of TYPE('b) ==> emb (coerce x) = emb x

lemma coerce_idem:

  rep_of TYPE('a) ≤ rep_of TYPE('b) ==> coerce (coerce x) = coerce x

lemma coerce_inverse:

  emb x ::: rep_of TYPE('b) ==> coerce (coerce x) = x

lemma coerce_type:

  rep_of TYPE('a) ≤ rep_of TYPE('b) ==> emb (coerce x) ::: rep_of TYPE('a)

lemma inj_coerce:

  rep_of TYPE('a) ≤ rep_of TYPE('b) ==> inj coerce