src/HOL/IMPP/Natural.thy
author nipkow
Fri, 15 Feb 2008 17:36:21 +0100
changeset 26073 0e70d3bd2eb4
parent 24178 4ff1dc2aa18d
child 27362 a6dc1769fdda
permissions -rw-r--r--
more lemmas
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
     1
(*  Title:      HOL/IMPP/Natural.thy
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
     2
    ID:         $Id$
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
     3
    Author:     David von Oheimb (based on a theory by Tobias Nipkow et al), TUM
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
     4
    Copyright   1999 TUM
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
     5
*)
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
     6
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
     7
header {* Natural semantics of commands *}
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
     8
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
     9
theory Natural
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    10
imports Com
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    11
begin
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    12
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    13
(** Execution of commands **)
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    14
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    15
consts
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    16
  newlocs :: locals
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    17
  setlocs :: "state => locals => state"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    18
  getlocs :: "state => locals"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    19
  update  :: "state => vname => val => state"     ("_/[_/::=/_]" [900,0,0] 900)
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    20
syntax (* IN Natural.thy *)
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    21
  loc :: "state => locals"    ("_<_>" [75,0] 75)
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    22
translations
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    23
  "s<X>" == "getlocs s X"
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    24
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    25
inductive
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    26
  evalc :: "[com,state,    state] => bool"  ("<_,_>/ -c-> _" [0,0,  51] 51)
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    27
  where
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    28
    Skip:    "<SKIP,s> -c-> s"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    29
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    30
  | Assign:  "<X :== a,s> -c-> s[X::=a s]"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    31
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    32
  | Local:   "<c, s0[Loc Y::= a s0]> -c-> s1 ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    33
              <LOCAL Y := a IN c, s0> -c-> s1[Loc Y::=s0<Y>]"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    34
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    35
  | Semi:    "[| <c0,s0> -c-> s1; <c1,s1> -c-> s2 |] ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    36
              <c0;; c1, s0> -c-> s2"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    37
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    38
  | IfTrue:  "[| b s; <c0,s> -c-> s1 |] ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    39
              <IF b THEN c0 ELSE c1, s> -c-> s1"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    40
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    41
  | IfFalse: "[| ~b s; <c1,s> -c-> s1 |] ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    42
              <IF b THEN c0 ELSE c1, s> -c-> s1"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    43
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    44
  | WhileFalse: "~b s ==> <WHILE b DO c,s> -c-> s"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    45
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    46
  | WhileTrue:  "[| b s0;  <c,s0> -c-> s1;  <WHILE b DO c, s1> -c-> s2 |] ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    47
                 <WHILE b DO c, s0> -c-> s2"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    48
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    49
  | Body:       "<the (body pn), s0> -c-> s1 ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    50
                 <BODY pn, s0> -c-> s1"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    51
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    52
  | Call:       "<BODY pn, (setlocs s0 newlocs)[Loc Arg::=a s0]> -c-> s1 ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    53
                 <X:=CALL pn(a), s0> -c-> (setlocs s1 (getlocs s0))
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    54
                                          [X::=s1<Res>]"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    55
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    56
inductive
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    57
  evaln :: "[com,state,nat,state] => bool"  ("<_,_>/ -_-> _" [0,0,0,51] 51)
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    58
  where
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    59
    Skip:    "<SKIP,s> -n-> s"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    60
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    61
  | Assign:  "<X :== a,s> -n-> s[X::=a s]"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    62
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    63
  | Local:   "<c, s0[Loc Y::= a s0]> -n-> s1 ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    64
              <LOCAL Y := a IN c, s0> -n-> s1[Loc Y::=s0<Y>]"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    65
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    66
  | Semi:    "[| <c0,s0> -n-> s1; <c1,s1> -n-> s2 |] ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    67
              <c0;; c1, s0> -n-> s2"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    68
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    69
  | IfTrue:  "[| b s; <c0,s> -n-> s1 |] ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    70
              <IF b THEN c0 ELSE c1, s> -n-> s1"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    71
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    72
  | IfFalse: "[| ~b s; <c1,s> -n-> s1 |] ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    73
              <IF b THEN c0 ELSE c1, s> -n-> s1"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    74
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    75
  | WhileFalse: "~b s ==> <WHILE b DO c,s> -n-> s"
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    76
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    77
  | WhileTrue:  "[| b s0;  <c,s0> -n-> s1;  <WHILE b DO c, s1> -n-> s2 |] ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    78
                 <WHILE b DO c, s0> -n-> s2"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    79
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    80
  | Body:       "<the (body pn), s0> -    n-> s1 ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    81
                 <BODY pn, s0> -Suc n-> s1"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    82
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 19803
diff changeset
    83
  | Call:       "<BODY pn, (setlocs s0 newlocs)[Loc Arg::=a s0]> -n-> s1 ==>
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    84
                 <X:=CALL pn(a), s0> -n-> (setlocs s1 (getlocs s0))
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    85
                                          [X::=s1<Res>]"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    86
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    87
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    88
inductive_cases evalc_elim_cases:
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    89
  "<SKIP,s> -c-> t"  "<X:==a,s> -c-> t"  "<LOCAL Y:=a IN c,s> -c-> t"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    90
  "<c1;;c2,s> -c-> t"  "<IF b THEN c1 ELSE c2,s> -c-> t"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    91
  "<BODY P,s> -c-> s1"  "<X:=CALL P(a),s> -c-> s1"
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    92
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    93
inductive_cases evaln_elim_cases:
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    94
  "<SKIP,s> -n-> t"  "<X:==a,s> -n-> t"  "<LOCAL Y:=a IN c,s> -n-> t"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    95
  "<c1;;c2,s> -n-> t"  "<IF b THEN c1 ELSE c2,s> -n-> t"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    96
  "<BODY P,s> -n-> s1"  "<X:=CALL P(a),s> -n-> s1"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    97
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    98
inductive_cases evalc_WHILE_case: "<WHILE b DO c,s> -c-> t"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    99
inductive_cases evaln_WHILE_case: "<WHILE b DO c,s> -n-> t"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
   100
19803
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   101
declare evalc.intros [intro]
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   102
declare evaln.intros [intro]
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   103
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   104
declare evalc_elim_cases [elim!]
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   105
declare evaln_elim_cases [elim!]
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   106
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   107
(* evaluation of com is deterministic *)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   108
lemma com_det [rule_format (no_asm)]: "<c,s> -c-> t ==> (!u. <c,s> -c-> u --> u=t)"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   109
apply (erule evalc.induct)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   110
apply (erule_tac [8] V = "<?c,s1> -c-> s2" in thin_rl)
24178
4ff1dc2aa18d turned Unify flags into configuration options (global only);
wenzelm
parents: 23746
diff changeset
   111
(*blast needs unify_search_bound = 40*)
19803
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   112
apply (best elim: evalc_WHILE_case)+
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   113
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   114
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   115
lemma evaln_evalc: "<c,s> -n-> t ==> <c,s> -c-> t"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   116
apply (erule evaln.induct)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   117
apply (tactic {* ALLGOALS (resolve_tac (thms "evalc.intros") THEN_ALL_NEW atac) *})
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   118
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   119
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   120
lemma Suc_le_D_lemma: "[| Suc n <= m'; (!!m. n <= m ==> P (Suc m)) |] ==> P m'"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   121
apply (frule Suc_le_D)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   122
apply blast
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   123
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   124
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   125
lemma evaln_nonstrict [rule_format]: "<c,s> -n-> t ==> !m. n<=m --> <c,s> -m-> t"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   126
apply (erule evaln.induct)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   127
apply (tactic {* ALLGOALS (EVERY'[strip_tac,TRY o etac (thm "Suc_le_D_lemma"), REPEAT o smp_tac 1]) *})
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   128
apply (tactic {* ALLGOALS (resolve_tac (thms "evaln.intros") THEN_ALL_NEW atac) *})
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   129
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   130
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   131
lemma evaln_Suc: "<c,s> -n-> s' ==> <c,s> -Suc n-> s'"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   132
apply (erule evaln_nonstrict)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   133
apply auto
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   134
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   135
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   136
lemma evaln_max2: "[| <c1,s1> -n1-> t1;  <c2,s2> -n2-> t2 |] ==>  
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   137
    ? n. <c1,s1> -n -> t1 & <c2,s2> -n -> t2"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   138
apply (cut_tac m = "n1" and n = "n2" in nat_le_linear)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   139
apply (blast dest: evaln_nonstrict)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   140
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   141
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   142
lemma evalc_evaln: "<c,s> -c-> t ==> ? n. <c,s> -n-> t"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   143
apply (erule evalc.induct)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   144
apply (tactic {* ALLGOALS (REPEAT o etac exE) *})
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   145
apply (tactic {* TRYALL (EVERY'[datac (thm "evaln_max2") 1, REPEAT o eresolve_tac [exE, conjE]]) *})
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   146
apply (tactic {* ALLGOALS (rtac exI THEN' resolve_tac (thms "evaln.intros") THEN_ALL_NEW atac) *})
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   147
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   148
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   149
lemma eval_eq: "<c,s> -c-> t = (? n. <c,s> -n-> t)"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   150
apply (fast elim: evalc_evaln evaln_evalc)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   151
done
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
   152
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
   153
end