The question is:
P1 {C} Q1
-------------------------
P1 && P2 {C} Q1||Q2
Is this rule valid?
How would I go about tackling something like this? All I can think of is to try to find an example where it would be false.
I’ve been trying to come up with it so that the combination of P1 && P2 make both Q1 and Q2 false but I cant think of any. So im leaning towards this being valid, but I dont know where to go about proving it… The text for this class is absolute rubbish and I can’t find any resources online for combination of correctness statements…
I’m assuming these are Hoare triples, normally denoted
{P} C {Q}; I also use Wikipedia as a reference.So your rule:
is valid!
Intuitively it is quite clear if you unterstand the logic:
{P1} C {Q1}means: WheneverP1holds,Q1will hold after executing commandC.P1 && P2holds,P1holds.Q1holds,Q1 || Q2holds.You can piece these statements together to see, why your rule must be valid:
P1 && P2impliesP1, so when you executeC, you get by assumptionQ1, which impliesQ1 || Q2.Therefore
{P1 && P2} C {Q1 || Q2}, whenever you assume{P1} C {Q1}, which is exactly what your rule states.Formally you can use the following rule (excerpt from Wikipedia):
Consequence rule
where you simply set
P'asP1 && P2,PasP1,QasQ1and finallyQ'asQ1 || Q2.