src/HOL/IMP/AbsInt0.thy
author huffman
Thu, 08 Sep 2011 10:07:53 -0700
changeset 44846 e9d1fcbc7d20
parent 44656 22bbd0d1b943
child 44890 22f665a2e91c
permissions -rw-r--r--
remove unnecessary intermediate lemmas
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     1
(* Author: Tobias Nipkow *)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     2
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     3
theory AbsInt0
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     4
imports Astate
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     5
begin
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     6
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     7
subsection "Computable Abstract Interpretation"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     8
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     9
text{* Abstract interpretation over type @{text astate} instead of
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    10
functions. *}
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    11
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    12
locale Abs_Int = Val_abs
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    13
begin
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    14
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    15
fun aval' :: "aexp \<Rightarrow> 'a astate \<Rightarrow> 'a"  ("aval\<^isup>#") where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    16
"aval' (N n) _ = num' n" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    17
"aval' (V x) S = lookup S x" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    18
"aval' (Plus e1 e2) S = plus' (aval' e1 S) (aval' e2 S)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    19
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    20
abbreviation astate_in_rep (infix "<:" 50) where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    21
"s <: S == ALL x. s x <: lookup S x"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    22
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    23
lemma astate_in_rep_le: "(s::state) <: S \<Longrightarrow> S \<sqsubseteq> T \<Longrightarrow> s <: T"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    24
by (metis in_mono le_astate_def le_rep lookup_def top)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    25
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    26
lemma aval'_sound: "s <: S \<Longrightarrow> aval a s <: aval' a S"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    27
by (induct a) (auto simp: rep_num' rep_plus')
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    28
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    29
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    30
fun AI :: "com \<Rightarrow> 'a astate \<Rightarrow> 'a astate" where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    31
"AI SKIP S = S" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    32
"AI (x ::= a) S = update S x (aval' a S)" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    33
"AI (c1;c2) S = AI c2 (AI c1 S)" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    34
"AI (IF b THEN c1 ELSE c2) S = (AI c1 S) \<squnion> (AI c2 S)" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    35
"AI (WHILE b DO c) S = pfp_above (AI c) S"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    36
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    37
lemma AI_sound: "(c,s) \<Rightarrow> t \<Longrightarrow> s <: S0 \<Longrightarrow> t <: AI c S0"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    38
proof(induct c arbitrary: s t S0)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    39
  case SKIP thus ?case by fastsimp
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    40
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    41
  case Assign thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    42
    by (auto simp: lookup_update aval'_sound)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    43
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    44
  case Semi thus ?case by auto
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    45
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    46
  case If thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    47
    by (metis AI.simps(4) IfE astate_in_rep_le join_ge1 join_ge2)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    48
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    49
  case (While b c)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    50
  let ?P = "pfp_above (AI c) S0"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    51
  have pfp: "AI c ?P \<sqsubseteq> ?P" and "S0 \<sqsubseteq> ?P"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    52
    by(simp_all add: SL_top_class.pfp_above_pfp)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    53
  { fix s t have "(WHILE b DO c,s) \<Rightarrow> t \<Longrightarrow> s <: ?P \<Longrightarrow> t <: ?P"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    54
    proof(induct "WHILE b DO c" s t rule: big_step_induct)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    55
      case WhileFalse thus ?case by simp
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    56
    next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    57
      case WhileTrue thus ?case using While.hyps pfp astate_in_rep_le by metis
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    58
    qed
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    59
  }
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    60
  with astate_in_rep_le[OF `s <: S0` `S0 \<sqsubseteq> ?P`]
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    61
  show ?case by (metis While(2) AI.simps(5))
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    62
qed
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    63
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    64
end
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    65
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    66
end