src/HOL/Library/SCT_Implementation.thy
author chaieb
Mon Jun 11 11:06:04 2007 +0200 (2007-06-11)
changeset 23315 df3a7e9ebadb
parent 22845 5f9138bcb3d7
child 23374 a2f492c599e0
permissions -rw-r--r--
tuned Proof
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
haftmann@22744
    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
definition test_SCT :: "acg \<Rightarrow> bool"
krauss@22359
    27
where
krauss@22359
    28
  "test_SCT \<A> = 
krauss@22359
    29
  (let \<T> = mk_tcl \<A> \<A>
krauss@22359
    30
    in (\<T> \<noteq> 0 \<and>
krauss@22359
    31
       (\<forall>(n,G,m)\<in>dest_graph \<T>. 
krauss@22359
    32
          n \<noteq> m \<or> G * G \<noteq> G \<or> 
krauss@22359
    33
         (\<exists>(p::nat,e,q)\<in>dest_graph G. p = q \<and> e = LESS))))"
krauss@22359
    34
krauss@22359
    35
krauss@22359
    36
lemma SCT'_exec:
krauss@22359
    37
  assumes a: "test_SCT \<A>"
krauss@22359
    38
  shows "SCT' \<A>"
krauss@22359
    39
proof -
krauss@22359
    40
  from mk_tcl_correctness2 a 
krauss@22359
    41
  have "mk_tcl \<A> \<A> = tcl \<A>" 
krauss@22359
    42
    unfolding test_SCT_def Let_def by auto
krauss@22359
    43
  
krauss@22359
    44
  with a
krauss@22359
    45
  show ?thesis
krauss@22359
    46
    unfolding SCT'_def no_bad_graphs_def test_SCT_def Let_def has_edge_def
krauss@22359
    47
    by auto
krauss@22359
    48
qed
krauss@22359
    49
krauss@22359
    50
code_modulename SML
krauss@22359
    51
  Implementation Graphs
krauss@22359
    52
krauss@22359
    53
lemma [code func]:
krauss@22359
    54
  "(G\<Colon>('a\<Colon>eq, 'b\<Colon>eq) graph) \<le> H \<longleftrightarrow> dest_graph G \<subseteq> dest_graph H"
krauss@22359
    55
  "(G\<Colon>('a\<Colon>eq, 'b\<Colon>eq) graph) < H \<longleftrightarrow> dest_graph G \<subset> dest_graph H"
krauss@22359
    56
  unfolding graph_leq_def graph_less_def by rule+
krauss@22359
    57
krauss@22359
    58
lemma [code func]:
krauss@22359
    59
  "(G\<Colon>('a\<Colon>eq, 'b\<Colon>eq) graph) + H = Graph (dest_graph G \<union> dest_graph H)"
krauss@22359
    60
  unfolding graph_plus_def ..
krauss@22359
    61
krauss@22359
    62
lemma [code func]:
krauss@22359
    63
  "(G\<Colon>('a\<Colon>eq, 'b\<Colon>{eq, times}) graph) * H = grcomp G H"
krauss@22359
    64
  unfolding graph_mult_def ..
krauss@22359
    65
krauss@22359
    66
krauss@22359
    67
krauss@22359
    68
lemma SCT'_empty: "SCT' (Graph {})"
krauss@22359
    69
  unfolding SCT'_def no_bad_graphs_def graph_zero_def[symmetric]
krauss@22359
    70
  tcl_zero
krauss@22359
    71
  by (simp add:in_grzero)
krauss@22359
    72
krauss@22359
    73
krauss@22359
    74
krauss@22359
    75
subsection {* Witness checking *}
krauss@22359
    76
krauss@22359
    77
krauss@22359
    78
definition test_SCT_witness :: "acg \<Rightarrow> acg \<Rightarrow> bool"
krauss@22359
    79
where
krauss@22359
    80
  "test_SCT_witness A T = 
krauss@22359
    81
  (A \<le> T \<and> A * T \<le> T \<and>
krauss@22359
    82
       (\<forall>(n,G,m)\<in>dest_graph T. 
krauss@22359
    83
          n \<noteq> m \<or> G * G \<noteq> G \<or> 
krauss@22359
    84
         (\<exists>(p::nat,e,q)\<in>dest_graph G. p = q \<and> e = LESS)))"
krauss@22359
    85
krauss@22359
    86
krauss@22359
    87
lemma no_bad_graphs_ucl:
krauss@22359
    88
  assumes "A \<le> B"
krauss@22359
    89
  assumes "no_bad_graphs B"
krauss@22359
    90
  shows "no_bad_graphs A"
krauss@22359
    91
using prems
krauss@22359
    92
unfolding no_bad_graphs_def has_edge_def graph_leq_def 
krauss@22359
    93
by blast
krauss@22359
    94
krauss@22359
    95
krauss@22359
    96
krauss@22359
    97
lemma SCT'_witness:
krauss@22359
    98
  assumes a: "test_SCT_witness A T"
krauss@22359
    99
  shows "SCT' A"
krauss@22359
   100
proof -
krauss@22359
   101
  from a have "A \<le> T" "A * T \<le> T" by (auto simp:test_SCT_witness_def)
krauss@22359
   102
  hence "A + A * T \<le> T" 
krauss@22359
   103
    by (subst add_idem[of T, symmetric], rule add_mono)
krauss@22359
   104
  with star3' have "tcl A \<le> T" unfolding tcl_def .
krauss@22359
   105
  moreover
krauss@22359
   106
  from a have "no_bad_graphs T"
krauss@22359
   107
    unfolding no_bad_graphs_def test_SCT_witness_def has_edge_def
krauss@22359
   108
    by auto
krauss@22359
   109
  ultimately
krauss@22359
   110
  show ?thesis
krauss@22359
   111
    unfolding SCT'_def
krauss@22359
   112
    by (rule no_bad_graphs_ucl)
krauss@22359
   113
qed
krauss@22359
   114
krauss@22359
   115
krauss@22359
   116
code_modulename SML
krauss@22359
   117
  Graphs SCT
krauss@22359
   118
  Kleene_Algebras SCT
krauss@22359
   119
  SCT_Implementation SCT
krauss@22359
   120
haftmann@22845
   121
code_gen test_SCT in SML
krauss@22359
   122
krauss@22359
   123
end