src/HOL/Library/SCT_Implementation.thy
author wenzelm
Fri Apr 13 21:26:35 2007 +0200 (2007-04-13)
changeset 22665 cf152ff55d16
parent 22371 c9f5895972b0
child 22744 5cbe966d67a2
permissions -rw-r--r--
tuned document (headers, sections, spacing);
krauss@22371
     1
(*  Title:      HOL/Library/SCT_Implementation.thy
krauss@22371
     2
    ID:         $Id$
krauss@22371
     3
    Author:     Alexander Krauss, TU Muenchen
krauss@22371
     4
*)
krauss@22371
     5
wenzelm@22665
     6
header ""
wenzelm@22665
     7
krauss@22359
     8
theory SCT_Implementation
krauss@22359
     9
imports ExecutableSet SCT_Definition
krauss@22359
    10
begin
krauss@22359
    11
krauss@22359
    12
fun edges_match :: "('n \<times> 'e \<times> 'n) \<times> ('n \<times> 'e \<times> 'n) \<Rightarrow> bool"
krauss@22359
    13
where
krauss@22359
    14
  "edges_match ((n, e, m), (n',e',m')) = (m = n')"
krauss@22359
    15
krauss@22359
    16
fun connect_edges :: 
krauss@22359
    17
  "('n \<times> ('e::times) \<times> 'n) \<times> ('n \<times> 'e \<times> 'n)
krauss@22359
    18
  \<Rightarrow> ('n \<times> 'e \<times> 'n)"
krauss@22359
    19
where
krauss@22359
    20
  "connect_edges ((n,e,m), (n', e', m')) = (n, e * e', m')"
krauss@22359
    21
krauss@22359
    22
lemma grcomp_code[code]:
krauss@22359
    23
  "grcomp (Graph G) (Graph H) = Graph (connect_edges ` { x \<in> G\<times>H. edges_match x })"
krauss@22359
    24
  by (rule graph_ext) (auto simp:graph_mult_def has_edge_def image_def)
krauss@22359
    25
krauss@22359
    26
krauss@22359
    27
definition test_SCT :: "acg \<Rightarrow> bool"
krauss@22359
    28
where
krauss@22359
    29
  "test_SCT \<A> = 
krauss@22359
    30
  (let \<T> = mk_tcl \<A> \<A>
krauss@22359
    31
    in (\<T> \<noteq> 0 \<and>
krauss@22359
    32
       (\<forall>(n,G,m)\<in>dest_graph \<T>. 
krauss@22359
    33
          n \<noteq> m \<or> G * G \<noteq> G \<or> 
krauss@22359
    34
         (\<exists>(p::nat,e,q)\<in>dest_graph G. p = q \<and> e = LESS))))"
krauss@22359
    35
krauss@22359
    36
krauss@22359
    37
lemma SCT'_exec:
krauss@22359
    38
  assumes a: "test_SCT \<A>"
krauss@22359
    39
  shows "SCT' \<A>"
krauss@22359
    40
proof -
krauss@22359
    41
  from mk_tcl_correctness2 a 
krauss@22359
    42
  have "mk_tcl \<A> \<A> = tcl \<A>" 
krauss@22359
    43
    unfolding test_SCT_def Let_def by auto
krauss@22359
    44
  
krauss@22359
    45
  with a
krauss@22359
    46
  show ?thesis
krauss@22359
    47
    unfolding SCT'_def no_bad_graphs_def test_SCT_def Let_def has_edge_def
krauss@22359
    48
    by auto
krauss@22359
    49
qed
krauss@22359
    50
krauss@22359
    51
code_modulename SML
krauss@22359
    52
  Implementation Graphs
krauss@22359
    53
krauss@22359
    54
lemma [code func]:
krauss@22359
    55
  "(G\<Colon>('a\<Colon>eq, 'b\<Colon>eq) graph) \<le> H \<longleftrightarrow> dest_graph G \<subseteq> dest_graph H"
krauss@22359
    56
  "(G\<Colon>('a\<Colon>eq, 'b\<Colon>eq) graph) < H \<longleftrightarrow> dest_graph G \<subset> dest_graph H"
krauss@22359
    57
  unfolding graph_leq_def graph_less_def by rule+
krauss@22359
    58
krauss@22359
    59
lemma [code func]:
krauss@22359
    60
  "(G\<Colon>('a\<Colon>eq, 'b\<Colon>eq) graph) + H = Graph (dest_graph G \<union> dest_graph H)"
krauss@22359
    61
  unfolding graph_plus_def ..
krauss@22359
    62
krauss@22359
    63
lemma [code func]:
krauss@22359
    64
  "(G\<Colon>('a\<Colon>eq, 'b\<Colon>{eq, times}) graph) * H = grcomp G H"
krauss@22359
    65
  unfolding graph_mult_def ..
krauss@22359
    66
krauss@22359
    67
krauss@22359
    68
krauss@22359
    69
lemma SCT'_empty: "SCT' (Graph {})"
krauss@22359
    70
  unfolding SCT'_def no_bad_graphs_def graph_zero_def[symmetric]
krauss@22359
    71
  tcl_zero
krauss@22359
    72
  by (simp add:in_grzero)
krauss@22359
    73
krauss@22359
    74
krauss@22359
    75
krauss@22359
    76
subsection {* Witness checking *}
krauss@22359
    77
krauss@22359
    78
krauss@22359
    79
definition test_SCT_witness :: "acg \<Rightarrow> acg \<Rightarrow> bool"
krauss@22359
    80
where
krauss@22359
    81
  "test_SCT_witness A T = 
krauss@22359
    82
  (A \<le> T \<and> A * T \<le> T \<and>
krauss@22359
    83
       (\<forall>(n,G,m)\<in>dest_graph T. 
krauss@22359
    84
          n \<noteq> m \<or> G * G \<noteq> G \<or> 
krauss@22359
    85
         (\<exists>(p::nat,e,q)\<in>dest_graph G. p = q \<and> e = LESS)))"
krauss@22359
    86
krauss@22359
    87
krauss@22359
    88
lemma no_bad_graphs_ucl:
krauss@22359
    89
  assumes "A \<le> B"
krauss@22359
    90
  assumes "no_bad_graphs B"
krauss@22359
    91
  shows "no_bad_graphs A"
krauss@22359
    92
using prems
krauss@22359
    93
unfolding no_bad_graphs_def has_edge_def graph_leq_def 
krauss@22359
    94
by blast
krauss@22359
    95
krauss@22359
    96
krauss@22359
    97
krauss@22359
    98
lemma SCT'_witness:
krauss@22359
    99
  assumes a: "test_SCT_witness A T"
krauss@22359
   100
  shows "SCT' A"
krauss@22359
   101
proof -
krauss@22359
   102
  from a have "A \<le> T" "A * T \<le> T" by (auto simp:test_SCT_witness_def)
krauss@22359
   103
  hence "A + A * T \<le> T" 
krauss@22359
   104
    by (subst add_idem[of T, symmetric], rule add_mono)
krauss@22359
   105
  with star3' have "tcl A \<le> T" unfolding tcl_def .
krauss@22359
   106
  moreover
krauss@22359
   107
  from a have "no_bad_graphs T"
krauss@22359
   108
    unfolding no_bad_graphs_def test_SCT_witness_def has_edge_def
krauss@22359
   109
    by auto
krauss@22359
   110
  ultimately
krauss@22359
   111
  show ?thesis
krauss@22359
   112
    unfolding SCT'_def
krauss@22359
   113
    by (rule no_bad_graphs_ucl)
krauss@22359
   114
qed
krauss@22359
   115
krauss@22359
   116
krauss@22359
   117
code_modulename SML
krauss@22359
   118
  Graphs SCT
krauss@22359
   119
  Kleene_Algebras SCT
krauss@22359
   120
  SCT_Implementation SCT
krauss@22359
   121
krauss@22359
   122
code_gen test_SCT (SML -)
krauss@22359
   123
krauss@22359
   124
end