src/CCL/ex/Flag.thy
author haftmann
Mon, 05 Jul 2010 15:12:20 +0200
changeset 37715 44b27ea94a16
parent 32153 a0e57fb1b930
child 42155 ffe99b07c9c0
permissions -rw-r--r--
tuned proof
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
     1
(*  Title:      CCL/ex/Flag.thy
1474
3f7d67927fe2 expanded tabs
clasohm
parents: 1149
diff changeset
     2
    Author:     Martin Coen, Cambridge University Computer Laboratory
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
    Copyright   1993  University of Cambridge
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
     6
header {* Dutch national flag program -- except that the point of Dijkstra's example was to use
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
     7
  arrays and this uses lists. *}
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
     8
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
     9
theory Flag
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    10
imports List
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    11
begin
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
consts
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
  Colour             :: "i set"
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    15
  red                :: "i"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    16
  white              :: "i"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    17
  blue               :: "i"
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
  ccase              :: "[i,i,i,i]=>i"
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
  flag               :: "i"
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    20
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    21
axioms
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    22
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    23
  Colour_def:  "Colour == Unit + Unit + Unit"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    24
  red_def:        "red == inl(one)"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    25
  white_def:    "white == inr(inl(one))"
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    26
  blue_def:     "blue == inr(inr(one))"
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    27
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    28
  ccase_def:   "ccase(c,r,w,b) == when(c,%x. r,%wb. when(wb,%x. w,%x. b))"
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    29
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    30
  flag_def:    "flag == lam l. letrec
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    31
      flagx l be lcase(l,<[],<[],[]>>,
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    32
                       %h t. split(flagx(t),%lr p. split(p,%lw lb.
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    33
                            ccase(h, <red$lr,<lw,lb>>,
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    34
                                     <lr,<white$lw,lb>>,
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    35
                                     <lr,<lw,blue$lb>>))))
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    36
      in flagx(l)"
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    37
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    38
  Flag_def:
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    39
     "Flag(l,x) == ALL lr:List(Colour).ALL lw:List(Colour).ALL lb:List(Colour).
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    40
                    x = <lr,<lw,lb>> -->
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    41
                  (ALL c:Colour.(c mem lr = true --> c=red) &
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    42
                                (c mem lw = true --> c=white) &
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    43
                                (c mem lb = true --> c=blue)) &
1149
5750eba8820d removed \...\ inside strings
clasohm
parents: 290
diff changeset
    44
                  Perm(l,lr @ lw @ lb)"
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    45
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    46
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    47
lemmas flag_defs = Colour_def red_def white_def blue_def ccase_def
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    48
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    49
lemma ColourXH: "a : Colour <-> (a=red | a=white | a=blue)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    50
  unfolding simp_type_defs flag_defs by blast
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    51
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    52
lemma redT: "red : Colour"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    53
  and whiteT: "white : Colour"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    54
  and blueT: "blue : Colour"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    55
  unfolding ColourXH by blast+
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    56
32153
a0e57fb1b930 misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents: 28272
diff changeset
    57
lemma ccaseT:
a0e57fb1b930 misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents: 28272
diff changeset
    58
  "[| c:Colour; c=red ==> r : C(red); c=white ==> w : C(white); c=blue ==> b : C(blue) |]
a0e57fb1b930 misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents: 28272
diff changeset
    59
    ==> ccase(c,r,w,b) : C(c)"
a0e57fb1b930 misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents: 28272
diff changeset
    60
  unfolding flag_defs by ncanT
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    61
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    62
lemma "flag : List(Colour)->List(Colour)*List(Colour)*List(Colour)"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    63
  apply (unfold flag_def)
27221
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 23894
diff changeset
    64
  apply (tactic {* typechk_tac @{context}
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 23894
diff changeset
    65
    [@{thm redT}, @{thm whiteT}, @{thm blueT}, @{thm ccaseT}] 1 *})
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 23894
diff changeset
    66
  apply (tactic "clean_ccs_tac @{context}")
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    67
  apply (erule ListPRI [THEN ListPR_wf [THEN wfI]])
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    68
  apply assumption
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    69
  done
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    70
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    71
lemma "flag : PROD l:List(Colour).{x:List(Colour)*List(Colour)*List(Colour).FLAG(x,l)}"
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    72
  apply (unfold flag_def)
27221
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 23894
diff changeset
    73
  apply (tactic {* gen_ccs_tac @{context}
31328dc30196 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 23894
diff changeset
    74
    [@{thm redT}, @{thm whiteT}, @{thm blueT}, @{thm ccaseT}] 1 *})
20140
98acc6d0fab6 removed obsolete ML files;
wenzelm
parents: 17456
diff changeset
    75
  oops
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    76
17456
bcf7544875b2 converted to Isar theory format;
wenzelm
parents: 3837
diff changeset
    77
end