90 likes | 206 Views
Satisfiability example – from 9(13). Proof obligation is now: forall o:Object, s:Store, p:Point & pre_Place(o,s,p) => inv_Store(Place(o,s,p)) which we can rewrite as: forall o:Object, s:Store, p:Point & RoomAt(o.xlength, o.ylength, s, p) => inv_Store(Place(o,s,p)).
E N D
Satisfiability example – from 9(13) • Proof obligation is now: • forall o:Object, s:Store, p:Point & pre_Place(o,s,p) => inv_Store(Place(o,s,p)) • which we can rewrite as: • forall o:Object, s:Store, p:Point & RoomAt(o.xlength, o.ylength, s, p) =>inv_Store(Place(o,s,p))
Satisfiability example (2) • Expanding both sides and rewriting leads to this: • forall o:Object, s:Store, p:Point & • let new_o = mk_Object(p,o.xlength,o.ylength) in • InBounds(new_o, s.xbound, s.ybound) • and (forall o in set s.contents & not Overlap(new_o,o)) • => • forall o in set (s.contents union {new_o}) & • InBounds(o,s.xbound,s.ybound) • and • not exists o1,o2 • in set (s.contents union {new_o}) & • o1 <> o2 and Overlap(o1,o2)
Satisfiability example (3) • In ‘plain’ english, we have to prove that: • If an object being added to the store at a given point is within the bounds of the store and will not overlap with any of the existing contents, • then • all objects in the resulting store will fit within the bounds of the store, and none of them will overlap
Satisfiability example (4) • Proof depends on the fact that the input store, s, is a valid store • i.e. we have • inv_Store(s) • which allows us to argue: • All objects in the input store fit within the bounds, and the new object fits within the bounds, so all objects in the resulting store will fit within bounds • No objects in the input store overlap, and the new object does not overlap with any objects in the input store, so no objects in the resulting store will overlap
Exercise • Given these datatype definitions: • Word = seq of char; • Dictionary = set of Word • inv d = card d <= 500; • and this function • AddWord: Dictionary * Word -> Dictionary • AddWord(d,w) == d union {w} • pre card d < 500; • What is the satisfiability proof obligation? • How would you discharge it?
Solution • Proof obligation: • forall d:Dictionary, w:Word & pre_AddWord(d,w) => inv_Dictionary(d union {w}) • forall d:Dictionary, w:Word & card d < 500 => card(d union {w}) <= 500 • forall d:Dictionary, w:Word & card d < 500 => (card d) + 1 <= 500 • which is true by rules of arithmetic.
Satisfiability for implicit functions • From the Guided Tour, 2(24) • ExpertToPage(al:Alarm, per:Period, pl:Plant) r:Expert • post r in set pl.sch(per) and • al.quali in set r.quali • Satisfiability proof obligation is: • forall al:Alarm, per:Period, pl:Plant & • exists r:Expert & • r in set pl.sch(per) and • al.quali in set r.quali
Satisfiability for implicit functions (2) • To prove: • forall al:Alarm, per:Period, pl:Plant & • exists r:Expert & • r in set pl.sch(per) and • al.quali in set r.quali • We have an invariant on Plant: • inv_Plant(p)== • forall a in set p.alarms & • forall per in set dom p.sch & • exists ex in set p.sch(per) & • a.quali in set ex.quali • Is this enough?
Satisfiability for implicit functions (3) • Informally we argue that the plant has qualified, available experts available at all times for all sorts of alarms. • Something is missing: • ExpertToPage(al:Alarm, per:Period, pl:Plant) r:Expert • post r in set pl.sch(per) and • al.quali in set r.quali • We haven’t ensured that the inputs al:Alarm and per:Period are known to the plant! • ExpertToPage(al:Alarm, per:Period, pl:Plant) r:Expert • pre al in set pl.alarms and • per in set dom pl.sch • post r in set pl.sch(per) and • al.quali in set r.quali