src/HOL/IMP/Fold.thy
changeset 45212 e87feee00a4c
parent 45200 1f1897ac7877
child 47818 151d137f1095
equal deleted inserted replaced
45211:3dd426ae6bea 45212:e87feee00a4c
     3 theory Fold imports Sem_Equiv begin
     3 theory Fold imports Sem_Equiv begin
     4 
     4 
     5 subsection "Simple folding of arithmetic expressions"
     5 subsection "Simple folding of arithmetic expressions"
     6 
     6 
     7 type_synonym
     7 type_synonym
     8   tab = "name \<Rightarrow> val option"
     8   tab = "vname \<Rightarrow> val option"
     9 
     9 
    10 (* maybe better as the composition of substitution and the existing simp_const(0) *)
    10 (* maybe better as the composition of substitution and the existing simp_const(0) *)
    11 fun simp_const :: "aexp \<Rightarrow> tab \<Rightarrow> aexp" where
    11 fun simp_const :: "aexp \<Rightarrow> tab \<Rightarrow> aexp" where
    12 "simp_const (N n) _ = N n" |
    12 "simp_const (N n) _ = N n" |
    13 "simp_const (V x) t = (case t x of None \<Rightarrow> V x | Some k \<Rightarrow> N k)" |
    13 "simp_const (V x) t = (case t x of None \<Rightarrow> V x | Some k \<Rightarrow> N k)" |
    30      (auto simp: approx_def split: aexp.splits option.splits)
    30      (auto simp: approx_def split: aexp.splits option.splits)
    31 
    31 
    32 definition
    32 definition
    33   "merge t1 t2 = (\<lambda>m. if t1 m = t2 m then t1 m else None)"
    33   "merge t1 t2 = (\<lambda>m. if t1 m = t2 m then t1 m else None)"
    34 
    34 
    35 primrec lnames :: "com \<Rightarrow> name set" where
    35 primrec lnames :: "com \<Rightarrow> vname set" where
    36 "lnames SKIP = {}" |
    36 "lnames SKIP = {}" |
    37 "lnames (x ::= a) = {x}" |
    37 "lnames (x ::= a) = {x}" |
    38 "lnames (c1; c2) = lnames c1 \<union> lnames c2" |
    38 "lnames (c1; c2) = lnames c1 \<union> lnames c2" |
    39 "lnames (IF b THEN c1 ELSE c2) = lnames c1 \<union> lnames c2" |
    39 "lnames (IF b THEN c1 ELSE c2) = lnames c1 \<union> lnames c2" |
    40 "lnames (WHILE b DO c) = lnames c"
    40 "lnames (WHILE b DO c) = lnames c"