src/HOL/ex/Executable_Relation.thy
author haftmann
Mon, 20 Feb 2012 21:04:00 +0100
changeset 46556 2848e36e0348
parent 46395 f56be74d7f51
child 46871 9100e6aa9272
permissions -rw-r--r--
tuned whitespace
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46395
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
     1
theory Executable_Relation
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
     2
imports Main
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
     3
begin
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
     4
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
     5
text {*
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
     6
 Current problem: rtrancl is not executable on an infinite type. 
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
     7
*}
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
     8
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
     9
lemma
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    10
  "(x, (y :: nat)) : rtrancl (R Un S) \<Longrightarrow> (x, y) : (rtrancl R) Un (rtrancl S)"
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    11
(* quickcheck[exhaustive] fails ! *)
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    12
oops
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    13
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    14
code_thms rtrancl
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    15
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    16
hide_const (open) rtrancl trancl
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    17
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    18
quotient_type 'a rel = "('a * 'a) set" / "(op =)"
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    19
morphisms set_of_rel rel_of_set by (metis identity_equivp)
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    20
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    21
lemma [simp]:
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    22
  "rel_of_set (set_of_rel S) = S"
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    23
by (rule Quotient_abs_rep[OF Quotient_rel])
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    24
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    25
lemma [simp]:
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    26
  "set_of_rel (rel_of_set R) = R"
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    27
by (rule Quotient_rep_abs[OF Quotient_rel]) (rule refl)
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    28
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    29
no_notation
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    30
   Set.member ("(_/ : _)" [50, 51] 50)
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    31
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    32
quotient_definition member :: "'a * 'a => 'a rel => bool" where
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    33
  "member" is "Set.member :: 'a * 'a => ('a * 'a) set => bool"
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    34
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    35
notation
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    36
   member  ("(_/ : _)" [50, 51] 50)
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    37
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    38
quotient_definition union :: "'a rel => 'a rel => 'a rel" where
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    39
  "union" is "Set.union :: ('a * 'a) set => ('a * 'a) set => ('a * 'a) set"
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    40
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    41
quotient_definition rtrancl :: "'a rel => 'a rel" where
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    42
  "rtrancl" is "Transitive_Closure.rtrancl :: ('a * 'a) set => ('a * 'a) set" 
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    43
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    44
definition reflcl_raw 
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    45
where "reflcl_raw R = R \<union> Id"
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    46
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    47
quotient_definition reflcl :: "('a * 'a) set => 'a rel" where
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    48
  "reflcl" is "reflcl_raw :: ('a * 'a) set => ('a * 'a) set"
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    49
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    50
code_datatype reflcl rel_of_set
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    51
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    52
lemma member_code[code]:
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    53
  "(x, y) : rel_of_set R = Set.member (x, y) R"
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    54
  "(x, y) : reflcl R = ((x = y) \<or> Set.member (x, y) R)"
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    55
unfolding member_def reflcl_def reflcl_raw_def map_fun_def_raw o_def id_def
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    56
by auto
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    57
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    58
lemma union_code[code]:
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    59
  "union (rel_of_set R) (rel_of_set S) = rel_of_set (Set.union R S)"
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    60
  "union (reflcl R) (rel_of_set S) = reflcl (Set.union R S)"
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    61
  "union (reflcl R) (reflcl S) = reflcl (Set.union R S)"
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    62
  "union (rel_of_set R) (reflcl S) = reflcl (Set.union R S)"
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    63
unfolding union_def reflcl_def reflcl_raw_def map_fun_def_raw o_def id_def
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    64
by (auto intro: arg_cong[where f=rel_of_set])
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    65
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    66
lemma rtrancl_code[code]:
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    67
  "rtrancl (rel_of_set R) = reflcl (Transitive_Closure.trancl R)"
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    68
  "rtrancl (reflcl R) = reflcl (Transitive_Closure.trancl R)"
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    69
unfolding rtrancl_def reflcl_def reflcl_raw_def map_fun_def_raw o_def id_def
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    70
by (auto intro: arg_cong[where f=rel_of_set])
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    71
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    72
quickcheck_generator rel constructors: rel_of_set
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    73
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    74
lemma
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    75
  "(x, (y :: nat)) : rtrancl (union R S) \<Longrightarrow> (x, y) : (union (rtrancl R) (rtrancl S))"
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    76
quickcheck[exhaustive]
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    77
oops
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    78
f56be74d7f51 adding an example for a datatype refinement which would allow rtrancl to be executable on an infinite type
bulwahn
parents:
diff changeset
    79
end