src/HOL/ex/Executable_Relation.thy
changeset 46395 f56be74d7f51
child 46871 9100e6aa9272
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/ex/Executable_Relation.thy	Thu Feb 02 10:12:11 2012 +0100
     1.3 @@ -0,0 +1,79 @@
     1.4 +theory Executable_Relation
     1.5 +imports Main
     1.6 +begin
     1.7 +
     1.8 +text {*
     1.9 + Current problem: rtrancl is not executable on an infinite type. 
    1.10 +*}
    1.11 +
    1.12 +lemma
    1.13 +  "(x, (y :: nat)) : rtrancl (R Un S) \<Longrightarrow> (x, y) : (rtrancl R) Un (rtrancl S)"
    1.14 +(* quickcheck[exhaustive] fails ! *)
    1.15 +oops
    1.16 +
    1.17 +code_thms rtrancl
    1.18 +
    1.19 +hide_const (open) rtrancl trancl
    1.20 +
    1.21 +quotient_type 'a rel = "('a * 'a) set" / "(op =)"
    1.22 +morphisms set_of_rel rel_of_set by (metis identity_equivp)
    1.23 +
    1.24 +lemma [simp]:
    1.25 +  "rel_of_set (set_of_rel S) = S"
    1.26 +by (rule Quotient_abs_rep[OF Quotient_rel])
    1.27 +
    1.28 +lemma [simp]:
    1.29 +  "set_of_rel (rel_of_set R) = R"
    1.30 +by (rule Quotient_rep_abs[OF Quotient_rel]) (rule refl)
    1.31 +
    1.32 +no_notation
    1.33 +   Set.member ("(_/ : _)" [50, 51] 50)
    1.34 +
    1.35 +quotient_definition member :: "'a * 'a => 'a rel => bool" where
    1.36 +  "member" is "Set.member :: 'a * 'a => ('a * 'a) set => bool"
    1.37 +
    1.38 +notation
    1.39 +   member  ("(_/ : _)" [50, 51] 50)
    1.40 +
    1.41 +quotient_definition union :: "'a rel => 'a rel => 'a rel" where
    1.42 +  "union" is "Set.union :: ('a * 'a) set => ('a * 'a) set => ('a * 'a) set"
    1.43 +
    1.44 +quotient_definition rtrancl :: "'a rel => 'a rel" where
    1.45 +  "rtrancl" is "Transitive_Closure.rtrancl :: ('a * 'a) set => ('a * 'a) set" 
    1.46 +
    1.47 +definition reflcl_raw 
    1.48 +where "reflcl_raw R = R \<union> Id"
    1.49 +
    1.50 +quotient_definition reflcl :: "('a * 'a) set => 'a rel" where
    1.51 +  "reflcl" is "reflcl_raw :: ('a * 'a) set => ('a * 'a) set"
    1.52 +
    1.53 +code_datatype reflcl rel_of_set
    1.54 +
    1.55 +lemma member_code[code]:
    1.56 +  "(x, y) : rel_of_set R = Set.member (x, y) R"
    1.57 +  "(x, y) : reflcl R = ((x = y) \<or> Set.member (x, y) R)"
    1.58 +unfolding member_def reflcl_def reflcl_raw_def map_fun_def_raw o_def id_def
    1.59 +by auto
    1.60 +
    1.61 +lemma union_code[code]:
    1.62 +  "union (rel_of_set R) (rel_of_set S) = rel_of_set (Set.union R S)"
    1.63 +  "union (reflcl R) (rel_of_set S) = reflcl (Set.union R S)"
    1.64 +  "union (reflcl R) (reflcl S) = reflcl (Set.union R S)"
    1.65 +  "union (rel_of_set R) (reflcl S) = reflcl (Set.union R S)"
    1.66 +unfolding union_def reflcl_def reflcl_raw_def map_fun_def_raw o_def id_def
    1.67 +by (auto intro: arg_cong[where f=rel_of_set])
    1.68 +
    1.69 +lemma rtrancl_code[code]:
    1.70 +  "rtrancl (rel_of_set R) = reflcl (Transitive_Closure.trancl R)"
    1.71 +  "rtrancl (reflcl R) = reflcl (Transitive_Closure.trancl R)"
    1.72 +unfolding rtrancl_def reflcl_def reflcl_raw_def map_fun_def_raw o_def id_def
    1.73 +by (auto intro: arg_cong[where f=rel_of_set])
    1.74 +
    1.75 +quickcheck_generator rel constructors: rel_of_set
    1.76 +
    1.77 +lemma
    1.78 +  "(x, (y :: nat)) : rtrancl (union R S) \<Longrightarrow> (x, y) : (union (rtrancl R) (rtrancl S))"
    1.79 +quickcheck[exhaustive]
    1.80 +oops
    1.81 +
    1.82 +end