Theory Derive_Eq
section "Equality"
theory Derive_Eq
imports Main "../Derive" Derive_Datatypes
begin
class eq =
fixes eq :: "'a ⇒ 'a ⇒ bool"
instantiation nat and unit:: eq
begin
definition eq_nat : "eq (x::nat) y ⟷ x = y"
definition eq_unit_def: "eq (x::unit) y ⟷ True"
instance ..
end
instantiation prod and sum :: (eq, eq) eq
begin
definition eq_prod_def: "eq x y ⟷ (eq (fst x) (fst y)) ∧ (eq (snd x) (snd y))"
definition eq_sum_def: "eq x y = (case x of Inl a ⇒ (case y of Inl b ⇒ eq a b | Inr b ⇒ False)
| Inr a ⇒ (case y of Inl b ⇒ False | Inr b ⇒ eq a b))"
instance ..
end
derive_generic eq simple .
lemma "eq (A 4) (A 4)" by eval
lemma "eq (A 6) (A 4) ⟷ False" by eval
lemma "eq C C" by eval
lemma "eq (B 4 5) (B 4 5)" by eval
lemma "eq (B 4 4) (A 3) ⟷ False" by eval
lemma "eq C (A 4) ⟷ False" by eval
derive_generic eq either .
lemma "eq (L (3::nat)) (R 3) ⟷ False" by code_simp
lemma "eq (L (3::nat)) (L 3)" by code_simp
lemma "eq (L (3::nat)) (L 4) ⟷ False" by code_simp