diff -r 041d78bf9403 -r a34e38154413 src/HOL/Bali/Eval.thy --- a/src/HOL/Bali/Eval.thy Tue Jul 16 18:52:26 2002 +0200 +++ b/src/HOL/Bali/Eval.thy Tue Jul 16 20:25:21 2002 +0200 @@ -455,8 +455,6 @@ "eval_unop UNot v = Bool (\ the_Bool v)" consts eval_binop :: "binop \ val \ val \ val" - - primrec "eval_binop Mul v1 v2 = Intg ((the_Intg v1) * (the_Intg v2))" "eval_binop Div v1 v2 = Intg ((the_Intg v1) div (the_Intg v2))" @@ -482,7 +480,25 @@ "eval_binop Xor v1 v2 = Bool ((the_Bool v1) \ (the_Bool v2))" "eval_binop BitOr v1 v2 = Intg 42" -- "FIXME: Not yet implemented" "eval_binop Or v1 v2 = Bool ((the_Bool v1) \ (the_Bool v2))" +"eval_binop CondAnd v1 v2 = Bool ((the_Bool v1) \ (the_Bool v2))" +"eval_binop CondOr v1 v2 = Bool ((the_Bool v1) \ (the_Bool v2))" +constdefs need_second_arg :: "binop \ val \ bool" +"need_second_arg binop v1 \ \ ((binop=CondAnd \ \ the_Bool v1) \ + (binop=CondOr \ the_Bool v1))" +text {* @{term CondAnd} and @{term CondOr} only evalulate the second argument + if the value isn't already determined by the first argument*} + +lemma need_second_arg_CondAnd [simp]: "need_second_arg CondAnd (Bool b) = b" +by (simp add: need_second_arg_def) + +lemma need_second_arg_CondOr [simp]: "need_second_arg CondOr (Bool b) = (\ b)" +by (simp add: need_second_arg_def) + +lemma need_second_arg_strict[simp]: + "\binop\CondAnd; binop\CondOr\ \ need_second_arg binop b" +by (cases binop) + (simp_all add: need_second_arg_def) consts eval :: "prog \ (state \ term \ vals \ state) set" @@ -550,6 +566,11 @@ SXcpt: "\G\Norm s0 \halloc (CInst (SXcpt xn))\a\ (x,s1)\ \ G\(Some (Xcpt (Std xn)),s0) \sxalloc\ (Some (Xcpt (Loc a)),s1)" +text {* +\par +*} (* dummy text command to break paragraph for latex; + large paragraphs exhaust memory of debian pdflatex *) + inductive "eval G" intros (* propagation of abrupt completion *) @@ -671,8 +692,11 @@ UnOp: "\G\Norm s0 \e-\v\ s1\ \ G\Norm s0 \UnOp unop e-\(eval_unop unop v)\ s1" - - BinOp: "\G\Norm s0 \e1-\v1\ s1; G\s1 \e2-\v2\ s2\ + + BinOp: "\G\Norm s0 \e1-\v1\ s1; + G\s1 \(if need_second_arg binop v1 then (In1l e2) else (In1r Skip)) + \\ (In1 v2,s2) + \ \ G\Norm s0 \BinOp binop e1 e2-\(eval_binop binop v1 v2)\ s2" (* cf. 15.10.2 *) @@ -764,6 +788,10 @@ *} +text {* +\par +*} (* dummy text command to break paragraph for latex; + large paragraphs exhaust memory of debian pdflatex *) lemmas eval_induct = eval_induct_ [split_format and and and and and and and and and and and and and and s1 (* Acc *) and and s2 (* Comp *) and and and and @@ -1104,6 +1132,31 @@ apply force done +lemma eval_binop_arg2_indep: +"\ need_second_arg binop v1 \ eval_binop binop v1 x = eval_binop binop v1 y" +by (cases binop) + (simp_all add: need_second_arg_def) + + +lemma eval_BinOp_arg2_indepI: + assumes eval_e1: "G\Norm s0 \e1-\v1\ s1" and + no_need: "\ need_second_arg binop v1" + shows "G\Norm s0 \BinOp binop e1 e2-\(eval_binop binop v1 v2)\ s1" + (is "?EvalBinOp v2") +proof - + from eval_e1 + have "?EvalBinOp Unit" + by (rule eval.BinOp) + (simp add: no_need) + moreover + from no_need + have "eval_binop binop v1 Unit = eval_binop binop v1 v2" + by (simp add: eval_binop_arg2_indep) + ultimately + show ?thesis + by simp +qed + section "single valued"