equal
deleted
inserted
replaced
1 header "Constant Folding" |
1 header "Constant Folding" |
2 |
2 |
3 theory Fold imports Sem_Equiv begin |
3 theory Fold imports Sem_Equiv begin |
4 |
4 |
5 section "Simple folding of arithmetic expressions" |
5 subsection "Simple folding of arithmetic expressions" |
6 |
6 |
7 types |
7 types |
8 tab = "name \<Rightarrow> val option" |
8 tab = "name \<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) *) |
224 using approx_eq [of empty c] |
224 using approx_eq [of empty c] |
225 by (simp add: equiv_up_to_True equiv_sym) |
225 by (simp add: equiv_up_to_True equiv_sym) |
226 |
226 |
227 |
227 |
228 |
228 |
229 section {* More ambitious folding including boolean expressions *} |
229 subsection {* More ambitious folding including boolean expressions *} |
230 |
230 |
231 |
231 |
232 fun bsimp_const :: "bexp \<Rightarrow> tab \<Rightarrow> bexp" where |
232 fun bsimp_const :: "bexp \<Rightarrow> tab \<Rightarrow> bexp" where |
233 "bsimp_const (Less a1 a2) t = less (simp_const a1 t) (simp_const a2 t)" | |
233 "bsimp_const (Less a1 a2) t = less (simp_const a1 t) (simp_const a2 t)" | |
234 "bsimp_const (And b1 b2) t = and (bsimp_const b1 t) (bsimp_const b2 t)" | |
234 "bsimp_const (And b1 b2) t = and (bsimp_const b1 t) (bsimp_const b2 t)" | |