423 apply (case_tac a) |
424 apply (case_tac a) |
424 apply auto |
425 apply auto |
425 done |
426 done |
426 |
427 |
427 section {* Evaluation of unary operations *} |
428 section {* Evaluation of unary operations *} |
428 consts eval_unop :: "unop \<Rightarrow> val \<Rightarrow> val" |
429 primrec eval_unop :: "unop \<Rightarrow> val \<Rightarrow> val" |
429 primrec |
430 where |
430 "eval_unop UPlus v = Intg (the_Intg v)" |
431 "eval_unop UPlus v = Intg (the_Intg v)" |
431 "eval_unop UMinus v = Intg (- (the_Intg v))" |
432 | "eval_unop UMinus v = Intg (- (the_Intg v))" |
432 "eval_unop UBitNot v = Intg 42" -- "FIXME: Not yet implemented" |
433 | "eval_unop UBitNot v = Intg 42" -- "FIXME: Not yet implemented" |
433 "eval_unop UNot v = Bool (\<not> the_Bool v)" |
434 | "eval_unop UNot v = Bool (\<not> the_Bool v)" |
434 |
435 |
435 section {* Evaluation of binary operations *} |
436 section {* Evaluation of binary operations *} |
436 consts eval_binop :: "binop \<Rightarrow> val \<Rightarrow> val \<Rightarrow> val" |
437 primrec eval_binop :: "binop \<Rightarrow> val \<Rightarrow> val \<Rightarrow> val" |
437 primrec |
438 where |
438 "eval_binop Mul v1 v2 = Intg ((the_Intg v1) * (the_Intg v2))" |
439 "eval_binop Mul v1 v2 = Intg ((the_Intg v1) * (the_Intg v2))" |
439 "eval_binop Div v1 v2 = Intg ((the_Intg v1) div (the_Intg v2))" |
440 | "eval_binop Div v1 v2 = Intg ((the_Intg v1) div (the_Intg v2))" |
440 "eval_binop Mod v1 v2 = Intg ((the_Intg v1) mod (the_Intg v2))" |
441 | "eval_binop Mod v1 v2 = Intg ((the_Intg v1) mod (the_Intg v2))" |
441 "eval_binop Plus v1 v2 = Intg ((the_Intg v1) + (the_Intg v2))" |
442 | "eval_binop Plus v1 v2 = Intg ((the_Intg v1) + (the_Intg v2))" |
442 "eval_binop Minus v1 v2 = Intg ((the_Intg v1) - (the_Intg v2))" |
443 | "eval_binop Minus v1 v2 = Intg ((the_Intg v1) - (the_Intg v2))" |
443 |
444 |
444 -- "Be aware of the explicit coercion of the shift distance to nat" |
445 -- "Be aware of the explicit coercion of the shift distance to nat" |
445 "eval_binop LShift v1 v2 = Intg ((the_Intg v1) * (2^(nat (the_Intg v2))))" |
446 | "eval_binop LShift v1 v2 = Intg ((the_Intg v1) * (2^(nat (the_Intg v2))))" |
446 "eval_binop RShift v1 v2 = Intg ((the_Intg v1) div (2^(nat (the_Intg v2))))" |
447 | "eval_binop RShift v1 v2 = Intg ((the_Intg v1) div (2^(nat (the_Intg v2))))" |
447 "eval_binop RShiftU v1 v2 = Intg 42" --"FIXME: Not yet implemented" |
448 | "eval_binop RShiftU v1 v2 = Intg 42" --"FIXME: Not yet implemented" |
448 |
449 |
449 "eval_binop Less v1 v2 = Bool ((the_Intg v1) < (the_Intg v2))" |
450 | "eval_binop Less v1 v2 = Bool ((the_Intg v1) < (the_Intg v2))" |
450 "eval_binop Le v1 v2 = Bool ((the_Intg v1) \<le> (the_Intg v2))" |
451 | "eval_binop Le v1 v2 = Bool ((the_Intg v1) \<le> (the_Intg v2))" |
451 "eval_binop Greater v1 v2 = Bool ((the_Intg v2) < (the_Intg v1))" |
452 | "eval_binop Greater v1 v2 = Bool ((the_Intg v2) < (the_Intg v1))" |
452 "eval_binop Ge v1 v2 = Bool ((the_Intg v2) \<le> (the_Intg v1))" |
453 | "eval_binop Ge v1 v2 = Bool ((the_Intg v2) \<le> (the_Intg v1))" |
453 |
454 |
454 "eval_binop Eq v1 v2 = Bool (v1=v2)" |
455 | "eval_binop Eq v1 v2 = Bool (v1=v2)" |
455 "eval_binop Neq v1 v2 = Bool (v1\<noteq>v2)" |
456 | "eval_binop Neq v1 v2 = Bool (v1\<noteq>v2)" |
456 "eval_binop BitAnd v1 v2 = Intg 42" -- "FIXME: Not yet implemented" |
457 | "eval_binop BitAnd v1 v2 = Intg 42" -- "FIXME: Not yet implemented" |
457 "eval_binop And v1 v2 = Bool ((the_Bool v1) \<and> (the_Bool v2))" |
458 | "eval_binop And v1 v2 = Bool ((the_Bool v1) \<and> (the_Bool v2))" |
458 "eval_binop BitXor v1 v2 = Intg 42" -- "FIXME: Not yet implemented" |
459 | "eval_binop BitXor v1 v2 = Intg 42" -- "FIXME: Not yet implemented" |
459 "eval_binop Xor v1 v2 = Bool ((the_Bool v1) \<noteq> (the_Bool v2))" |
460 | "eval_binop Xor v1 v2 = Bool ((the_Bool v1) \<noteq> (the_Bool v2))" |
460 "eval_binop BitOr v1 v2 = Intg 42" -- "FIXME: Not yet implemented" |
461 | "eval_binop BitOr v1 v2 = Intg 42" -- "FIXME: Not yet implemented" |
461 "eval_binop Or v1 v2 = Bool ((the_Bool v1) \<or> (the_Bool v2))" |
462 | "eval_binop Or v1 v2 = Bool ((the_Bool v1) \<or> (the_Bool v2))" |
462 "eval_binop CondAnd v1 v2 = Bool ((the_Bool v1) \<and> (the_Bool v2))" |
463 | "eval_binop CondAnd v1 v2 = Bool ((the_Bool v1) \<and> (the_Bool v2))" |
463 "eval_binop CondOr v1 v2 = Bool ((the_Bool v1) \<or> (the_Bool v2))" |
464 | "eval_binop CondOr v1 v2 = Bool ((the_Bool v1) \<or> (the_Bool v2))" |
464 |
465 |
465 definition need_second_arg :: "binop \<Rightarrow> val \<Rightarrow> bool" where |
466 definition |
466 "need_second_arg binop v1 \<equiv> \<not> ((binop=CondAnd \<and> \<not> the_Bool v1) \<or> |
467 need_second_arg :: "binop \<Rightarrow> val \<Rightarrow> bool" where |
467 (binop=CondOr \<and> the_Bool v1))" |
468 "need_second_arg binop v1 = (\<not> ((binop=CondAnd \<and> \<not> the_Bool v1) \<or> |
|
469 (binop=CondOr \<and> the_Bool v1)))" |
468 text {* @{term CondAnd} and @{term CondOr} only evalulate the second argument |
470 text {* @{term CondAnd} and @{term CondOr} only evalulate the second argument |
469 if the value isn't already determined by the first argument*} |
471 if the value isn't already determined by the first argument*} |
470 |
472 |
471 lemma need_second_arg_CondAnd [simp]: "need_second_arg CondAnd (Bool b) = b" |
473 lemma need_second_arg_CondAnd [simp]: "need_second_arg CondAnd (Bool b) = b" |
472 by (simp add: need_second_arg_def) |
474 by (simp add: need_second_arg_def) |