src/HOL/IMP/Abs_Int_Den/Abs_Int_den0_const.thy
author haftmann
Wed, 19 Feb 2014 22:05:05 +0100
changeset 55599 6535c537b243
parent 52046 bc01725d7918
child 55600 3c7610b8dcfc
permissions -rw-r--r--
aggiornamento for "interpretation with definitions": operate uniformly on theory and locale level under the brand of "permanent interpretation"
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
45111
054a9ac0d7ef Added Hoare-like Abstract Interpretation
nipkow
parents: 45110
diff changeset
     3
theory Abs_Int_den0_const
054a9ac0d7ef Added Hoare-like Abstract Interpretation
nipkow
parents: 45110
diff changeset
     4
imports Abs_Int_den0
44656
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 "Constant Propagation"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     8
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
     9
datatype cval = Const val | Any
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    10
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    11
fun rep_cval where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    12
"rep_cval (Const n) = {n}" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    13
"rep_cval (Any) = UNIV"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    14
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    15
fun plus_cval where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    16
"plus_cval (Const m) (Const n) = Const(m+n)" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    17
"plus_cval _ _ = Any"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    18
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    19
instantiation cval :: SL_top
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    20
begin
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    21
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    22
fun le_cval where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    23
"_ \<sqsubseteq> Any = True" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    24
"Const n \<sqsubseteq> Const m = (n=m)" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    25
"Any \<sqsubseteq> Const _ = False"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    26
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    27
fun join_cval where
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    28
"Const m \<squnion> Const n = (if n=m then Const m else Any)" |
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    29
"_ \<squnion> _ = Any"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    30
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    31
definition "Top = Any"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    32
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    33
instance
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    34
proof
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    35
  case goal1 thus ?case by (cases x) simp_all
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    36
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    37
  case goal2 thus ?case by(cases z, cases y, cases x, simp_all)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    38
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    39
  case goal3 thus ?case by(cases x, cases y, simp_all)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    40
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    41
  case goal4 thus ?case by(cases y, cases x, simp_all)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    42
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    43
  case goal5 thus ?case by(cases z, cases y, cases x, simp_all)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    44
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    45
  case goal6 thus ?case by(simp add: Top_cval_def)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    46
qed
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    47
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    48
end
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    49
55599
6535c537b243 aggiornamento for "interpretation with definitions": operate uniformly on theory and locale level under the brand of "permanent interpretation"
haftmann
parents: 52046
diff changeset
    50
permanent_interpretation Rep rep_cval
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    51
proof
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    52
  case goal1 thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    53
    by(cases a, cases b, simp, simp, cases b, simp, simp)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    54
qed
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    55
55599
6535c537b243 aggiornamento for "interpretation with definitions": operate uniformly on theory and locale level under the brand of "permanent interpretation"
haftmann
parents: 52046
diff changeset
    56
permanent_interpretation Val_abs rep_cval Const plus_cval
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    57
proof
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    58
  case goal1 show ?case by simp
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    59
next
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    60
  case goal2 thus ?case
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    61
    by(cases a1, cases a2, simp, simp, cases a2, simp, simp)
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    62
qed
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    63
55599
6535c537b243 aggiornamento for "interpretation with definitions": operate uniformly on theory and locale level under the brand of "permanent interpretation"
haftmann
parents: 52046
diff changeset
    64
permanent_interpretation Abs_Int rep_cval Const plus_cval "(iter' 3)"
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    65
defines AI_const is AI
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    66
and aval'_const is aval'
44944
f136409c2cef tuned post fixpoint setup
nipkow
parents: 44932
diff changeset
    67
proof qed (auto simp: iter'_pfp_above)
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    68
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    69
text{* Straight line code: *}
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    70
definition "test1_const =
52046
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 45200
diff changeset
    71
 ''y'' ::= N 7;;
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 45200
diff changeset
    72
 ''z'' ::= Plus (V ''y'') (N 2);;
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    73
 ''y'' ::= Plus (V ''x'') (N 0)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    74
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    75
text{* Conditional: *}
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    76
definition "test2_const =
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    77
 IF Less (N 41) (V ''x'') THEN ''x'' ::= N 5 ELSE ''x'' ::= N 5"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    78
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    79
text{* Conditional, test is ignored: *}
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    80
definition "test3_const =
52046
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 45200
diff changeset
    81
 ''x'' ::= N 42;;
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    82
 IF Less (N 41) (V ''x'') THEN ''x'' ::= N 5 ELSE ''x'' ::= N 6"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    83
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    84
text{* While: *}
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    85
definition "test4_const =
52046
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 45200
diff changeset
    86
 ''x'' ::= N 0;; WHILE Bc True DO ''x'' ::= N 0"
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    87
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    88
text{* While, test is ignored: *}
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    89
definition "test5_const =
52046
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 45200
diff changeset
    90
 ''x'' ::= N 0;; WHILE Less (V ''x'') (N 1) DO ''x'' ::= N 1"
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    91
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    92
text{* Iteration is needed: *}
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    93
definition "test6_const =
52046
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 45200
diff changeset
    94
  ''x'' ::= N 0;; ''y'' ::= N 0;; ''z'' ::= N 2;;
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 45200
diff changeset
    95
  WHILE Less (V ''x'') (N 1) DO (''x'' ::= V ''y'';; ''y'' ::= V ''z'')"
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    96
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    97
text{* More iteration would be needed: *}
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
    98
definition "test7_const =
52046
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 45200
diff changeset
    99
  ''x'' ::= N 0;; ''y'' ::= N 0;; ''z'' ::= N 0;; ''u'' ::= N 3;;
44932
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44656
diff changeset
   100
  WHILE Less (V ''x'') (N 1)
52046
bc01725d7918 replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents: 45200
diff changeset
   101
  DO (''x'' ::= V ''y'';; ''y'' ::= V ''z'';; ''z'' ::= V ''u'')"
44932
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44656
diff changeset
   102
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44656
diff changeset
   103
value [code] "list (AI_const test1_const Top)"
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44656
diff changeset
   104
value [code] "list (AI_const test2_const Top)"
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44656
diff changeset
   105
value [code] "list (AI_const test3_const Top)"
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44656
diff changeset
   106
value [code] "list (AI_const test4_const Top)"
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44656
diff changeset
   107
value [code] "list (AI_const test5_const Top)"
7c93ee993cae revised AbsInt and added widening and narrowing
nipkow
parents: 44656
diff changeset
   108
value [code] "list (AI_const test6_const Top)"
44656
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   109
value [code] "list (AI_const test7_const Top)"
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   110
22bbd0d1b943 Added Abstract Interpretation theories
nipkow
parents:
diff changeset
   111
end