src/HOL/Hoare/Hoare.thy
author nipkow
Fri, 24 Nov 2000 16:49:27 +0100
changeset 10519 ade64af4c57c
parent 9397 358e67410253
child 11606 43abedd4467e
permissions -rw-r--r--
hide many names from Datatype_Universe.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1476
608483c2122a expanded tabs; incorporated Konrad's changes
clasohm
parents: 1384
diff changeset
     1
(*  Title:      HOL/Hoare/Hoare.thy
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
     2
    ID:         $Id$
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
     3
    Author:     Leonor Prensa Nieto & Tobias Nipkow
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
     4
    Copyright   1998 TUM
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
     5
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
     6
Sugared semantic embedding of Hoare logic.
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
     7
Strictly speaking a shallow embedding (as implemented by Norbert Galm
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
     8
following Mike Gordon) would suffice. Maybe the datatype com comes in useful
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
     9
later.
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    10
*)
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    11
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    12
Hoare  = Main +
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    13
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    14
types
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    15
    'a bexp = 'a set
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    16
    'a assn = 'a set
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    17
    'a fexp = 'a =>'a
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    18
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    19
datatype
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    20
 'a com = Basic ('a fexp)         
6055
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5646
diff changeset
    21
   | Seq ('a com) ('a com)               ("(_;/ _)"      [61,60] 60)
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    22
   | Cond ('a bexp) ('a com) ('a com)    ("(1IF _/ THEN _ / ELSE _/ FI)"  [0,0,0] 61)
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    23
   | While ('a bexp) ('a assn) ('a com)  ("(1WHILE _/ INV {_} //DO _ /OD)"  [0,0,0] 61)
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    24
  
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    25
syntax
6055
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5646
diff changeset
    26
  "@assign"  :: id => 'b => 'a com        ("(2_ :=/ _)" [70,65] 61)
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    27
  "@annskip" :: 'a com                    ("SKIP")
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    28
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    29
translations
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    30
            "SKIP" == "Basic id"
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    31
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    32
types 'a sem = 'a => 'a => bool
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    33
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    34
consts iter :: nat => 'a bexp => 'a sem => 'a sem
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    35
primrec
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    36
"iter 0 b S = (%s s'. s ~: b & (s=s'))"
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    37
"iter (Suc n) b S = (%s s'. s : b & (? s''. S s s'' & iter n b S s'' s'))"
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    38
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    39
consts Sem :: 'a com => 'a sem
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    40
primrec
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    41
"Sem(Basic f) s s' = (s' = f s)"
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    42
"Sem(c1;c2) s s' = (? s''. Sem c1 s s'' & Sem c2 s'' s')"
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    43
"Sem(IF b THEN c1 ELSE c2 FI) s s' = ((s  : b --> Sem c1 s s') &
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    44
                                      (s ~: b --> Sem c2 s s'))"
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    45
"Sem(While b x c) s s' = (? n. iter n b (Sem c) s s')"
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    46
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    47
constdefs Valid :: ['a bexp, 'a com, 'a bexp] => bool
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    48
  "Valid p c q == !s s'. Sem c s s' --> s : p --> s' : q"
5007
0ebd6c91088a nonterminals prog;
wenzelm
parents: 3842
diff changeset
    49
0ebd6c91088a nonterminals prog;
wenzelm
parents: 3842
diff changeset
    50
0ebd6c91088a nonterminals prog;
wenzelm
parents: 3842
diff changeset
    51
nonterminals
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    52
  vars
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    53
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    54
syntax
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    55
  ""		     :: "id => vars"		       ("_")
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    56
  "_vars" 	     :: "[id, vars] => vars"	       ("_ _")
1558
9c6ebfab4e05 added constdefs section
clasohm
parents: 1476
diff changeset
    57
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    58
syntax
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    59
 "@hoare_vars" :: [vars, 'a assn,'a com,'a assn] => bool
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    60
                 ("|- VARS _.// {_} // _ // {_}" [0,0,55,0] 50)
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    61
syntax ("" output)
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    62
 "@hoare"      :: ['a assn,'a com,'a assn] => bool
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    63
                 ("|- {_} // _ // {_}" [0,55,0] 50)
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    64
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    65
end
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    66
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    67
ML
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    68
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    69
(** parse translations **)
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    70
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    71
fun mk_abstuple []     body = absfree ("x", dummyT, body)
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    72
  | mk_abstuple [v]    body = absfree ((fst o dest_Free) v, dummyT, body)
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    73
  | mk_abstuple (v::w) body = Syntax.const "split" $
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    74
                              absfree ((fst o dest_Free) v, dummyT, mk_abstuple w body);
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    75
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    76
  
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    77
fun mk_fbody v e []      = Syntax.const "()"
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    78
  | mk_fbody v e [x]     = if v=x then e else x
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    79
  | mk_fbody v e (x::xs) = Syntax.const "Pair" $ (if v=x then e else x) $
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    80
                           mk_fbody v e xs;
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    81
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    82
fun mk_fexp v e xs = mk_abstuple xs (mk_fbody v e xs);
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    83
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    84
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    85
(* bexp_tr & assn_tr *)
9397
358e67410253 Updating of some comments
prensani
parents: 6055
diff changeset
    86
(*all meta-variables for bexp except for TRUE are translated as if they
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    87
  were boolean expressions*)
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    88
  
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    89
fun bexp_tr (Const ("TRUE", _)) xs = Syntax.const "TRUE"
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    90
  | bexp_tr b xs = Syntax.const "Collect" $ mk_abstuple xs b;
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    91
  
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    92
fun assn_tr r xs = Syntax.const "Collect" $ mk_abstuple xs r;
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    93
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    94
(* com_tr *)
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    95
  
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    96
fun assign_tr [Free (V,_),E] xs = Syntax.const "Basic" $
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    97
                                      mk_fexp (Free(V,dummyT)) E xs
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
    98
  | assign_tr ts _ = raise TERM ("assign_tr", ts);
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    99
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   100
fun com_tr (Const("@assign",_) $ Free (V,_) $ E) xs =
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   101
               assign_tr [Free (V,dummyT),E] xs
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   102
  | com_tr (Const ("Basic",_) $ f) xs = Syntax.const "Basic" $ f
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   103
  | com_tr (Const ("Seq",_) $ c1 $ c2) xs = Syntax.const "Seq" $
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   104
                                                 com_tr c1 xs $ com_tr c2 xs
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   105
  | com_tr (Const ("Cond",_) $ b $ c1 $ c2) xs = Syntax.const "Cond" $
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   106
                                  bexp_tr b xs $ com_tr c1 xs $ com_tr c2 xs
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   107
  | com_tr (Const ("While",_) $ b $ I $ c) xs = Syntax.const "While" $
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   108
                                         bexp_tr b xs $ assn_tr I xs $ com_tr c xs
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   109
  | com_tr trm _ = trm;
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   110
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   111
(* triple_tr *)
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
   112
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   113
fun vars_tr (x as Free _) = [x]
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   114
  | vars_tr (Const ("_vars", _) $ (x as Free _) $ vars) = x :: vars_tr vars
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   115
  | vars_tr t = raise TERM ("vars_tr", [t]);
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   116
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   117
fun hoare_vars_tr [vars, pre, prg, post] =
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   118
      let val xs = vars_tr vars
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   119
      in Syntax.const "Valid" $
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   120
           assn_tr pre xs $ com_tr prg xs $ assn_tr post xs
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   121
      end
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   122
  | hoare_vars_tr ts = raise TERM ("hoare_vars_tr", ts);
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   123
  
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   124
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   125
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   126
val parse_translation = [("@hoare_vars", hoare_vars_tr)];
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
   127
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
   128
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   129
(*****************************************************************************)
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   130
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   131
(*** print translations ***)
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
   132
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   133
fun dest_abstuple (Const ("split",_) $ (Abs(v,_, body))) =
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   134
                            subst_bound (Syntax.free v, dest_abstuple body)
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   135
  | dest_abstuple (Abs(v,_, body)) = subst_bound (Syntax.free v, body)
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   136
  | dest_abstuple trm = trm;
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
   137
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   138
fun abs2list (Const ("split",_) $ (Abs(x,T,t))) = Free (x, T)::abs2list t
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   139
  | abs2list (Abs(x,T,t)) = [Free (x, T)]
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   140
  | abs2list _ = [];
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
   141
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   142
fun mk_ts (Const ("split",_) $ (Abs(x,_,t))) = mk_ts t
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   143
  | mk_ts (Abs(x,_,t)) = mk_ts t
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   144
  | mk_ts (Const ("Pair",_) $ a $ b) = a::(mk_ts b)
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   145
  | mk_ts t = [t];
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
   146
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   147
fun mk_vts (Const ("split",_) $ (Abs(x,_,t))) = 
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   148
           ((Syntax.free x)::(abs2list t), mk_ts t)
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   149
  | mk_vts (Abs(x,_,t)) = ([Syntax.free x], [t])
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   150
  | mk_vts t = raise Match;
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   151
  
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   152
fun find_ch [] i xs = (false, (Syntax.free "not_ch",Syntax.free "not_ch" ))
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   153
  | find_ch ((v,t)::vts) i xs = if t=(Bound i) then find_ch vts (i-1) xs
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   154
              else (true, (v, subst_bounds (xs,t)));
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   155
  
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   156
fun is_f (Const ("split",_) $ (Abs(x,_,t))) = true
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   157
  | is_f (Abs(x,_,t)) = true
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   158
  | is_f t = false;
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   159
  
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   160
(* assn_tr' & bexp_tr'*)
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   161
  
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   162
fun assn_tr' (Const ("Collect",_) $ T) = dest_abstuple T
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   163
  | assn_tr' (Const ("op Int",_) $ (Const ("Collect",_) $ T1) $ 
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   164
                                   (Const ("Collect",_) $ T2)) =  
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   165
            Syntax.const "op Int" $ dest_abstuple T1 $ dest_abstuple T2
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   166
  | assn_tr' t = t;
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
   167
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   168
fun bexp_tr' (Const ("Collect",_) $ T) = dest_abstuple T 
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   169
  | bexp_tr' t = t;
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   170
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   171
(*com_tr' *)
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
   172
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   173
fun mk_assign f =
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   174
  let val (vs, ts) = mk_vts f;
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   175
      val (ch, which) = find_ch (vs~~ts) ((length vs)-1) (rev vs)
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   176
  in if ch then Syntax.const "@assign" $ fst(which) $ snd(which)
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   177
     else Syntax.const "@skip" end;
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
   178
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   179
fun com_tr' (Const ("Basic",_) $ f) = if is_f f then mk_assign f
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   180
                                           else Syntax.const "Basic" $ f
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   181
  | com_tr' (Const ("Seq",_) $ c1 $ c2) = Syntax.const "Seq" $
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   182
                                                 com_tr' c1 $ com_tr' c2
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   183
  | com_tr' (Const ("Cond",_) $ b $ c1 $ c2) = Syntax.const "Cond" $
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   184
                                           bexp_tr' b $ com_tr' c1 $ com_tr' c2
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   185
  | com_tr' (Const ("While",_) $ b $ I $ c) = Syntax.const "While" $
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   186
                                               bexp_tr' b $ assn_tr' I $ com_tr' c
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   187
  | com_tr' t = t;
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
   188
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
   189
5646
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   190
fun spec_tr' [p, c, q] =
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   191
  Syntax.const "@hoare" $ assn_tr' p $ com_tr' c $ assn_tr' q
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   192
 
7c2ddbaf8b8c New many-sorted version.
nipkow
parents: 5565
diff changeset
   193
val print_translation = [("Valid", spec_tr')];