[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlaplus] Finding Inductive Invariants using TLC and Proving it using TLAPS



Hello,

apologies for the late reply – I tried to reconstruct your spec from what you pasted in the message but it may be a bit out of sync with the spec you are actually working on.

The first issue that I noticed was that your invariant mentions both constants MaxBufferLen and MaxTotalNumberOfItemsProduced but you only have an assumption for the first constant. So I added the conjunct

         /\ MaxTotalNumberOfItemsProduced \in Nat

to your constant assumption. Also, that assumption must of course be used in the proof but this is not shown in the proof that you reported being able to finish. Note that TLC will not help find you problems involving missing assumptions about constants because constants have fixed values in your model.

The second issue concerns the Consume action: it increments the variable num_of_items_consumed while leaving num_of_items_produced unchanged. Therefore you will not be able to conclude that the inequality

  num_of_items_consumed <= num_of_items_produced

(which is your SafetyProperty) is preserved. This should have been discovered when you used TLC to check if your invariant was inductive. A minute of reflection indicates that the invariant that you really need is

  num_of_items_consumed + Len(buffer) <= num_of_items_produced

Now we can start the formal proof of the invariant, based on the general schema for invariant proofs. The only non-obvious step is the one that shows that [Next]_vars preserves the invariant, so I used the "decompose proof" command to split it into individual proof steps corresponding to the sub-actions of [Next]_vars. The cases corresponding to Produce and UNCHANGED vars are again simple, leaving us with the Consume action, which unfortunately isn't proved automatically. I now guessed that the prover needed to know that the length of the buffer decreases in this step and therefore asserted

    <3>. Len(buffer') = Len(buffer)-1

With this knowledge, the prover indeed managed to prove the step corresponding to the Consume action. (I could have split the conclusion IInv' into its individual conjuncts to find out which ones go through and which ones don't, further narrowing down the source of the problem.)

For proving the auxiliary level-3 step, I use the lemma HeadTailProperties from the library module SequenceTheorems. (These modules are by default installed in /usr/local/lib/tlaps/, just like TLAPS.tla, it is worth looking at the theorems they provide if you are doing any non-trivial proof. You may also look at the proofs of these lemmas in SequenceTheorems_proofs.tla if you are stuck in some proof about sequences.)

The overall module with the full proof is attached.

Hope this helps,
Stephan

P.S.: In a first approximation, you should not have to care about which backend (SMT, Zenon or Isabelle) proves any given step since TLAPS will call all of them. Adding "BY SMT" etc. to a step simply documents which backend succeeds in proving a step and avoids unnecessary calls to the other backends. -s

--
You received this message because you are subscribed to the Google Groups "tlaplus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tlaplus+unsubscribe@xxxxxxxxxxxxxxxx.
To view this discussion on the web visit https://groups.google.com/d/msgid/tlaplus/9BDED377-1BA4-4A2F-944B-E58D3D2D1A26%40gmail.com.

Attachment: producer_consumer.tla
Description: Binary data



On 11 Nov 2020, at 17:52, Smruti Padhy <smruti.padhy@xxxxxxxxx> wrote:

Thanks Markus.  Yes, by including the conjunct in IInv, TLC was able to IInv again.
It helped me to understand to find an inductive invariant using TLC for my simplified version of the spec.
Now I am trying to prove the inductive invariant using TLAPS.

Best,
Smruti

On Friday, November 6, 2020 at 1:42:56 PM UTC-6 Markus Alexander Kuppe wrote:
On 06.11.20 11:03, Smruti Padhy wrote: 
> Thanks for pointing that out. I redefined Seq with MySeq. Now I am 
> getting, a different error:  
> 
> ------------------------------------------- 
> 
> In evaluation, the identifier buffer is either undefined or not an operator. 
> 
> line 64, col 19 to line 64, col 24 of module BlockingQueue 
> 
> ------------------------------------------- 
> 
> I am not sure what I am missing here. 


Hi Smruti, 

if you compare git commit v16 [1] with v18 [2], you will find that the 
first conjunct of TypeInv has been excluded from IInv (see [3]). If you 
include the conjunct in IInv, TLC will be able to check IInv again. 

Best, 
Markus 

[1] 
https://github.com/lemmy/BlockingQueue/blob/03fe04a9d63d0c92c77547bc10063e83e39a1878/BlockingQueue.tla#L96 
[2] 
https://github.com/lemmy/BlockingQueue/commit/c7adc434e02ed6a667396fc76194ca43df4172a3 
[3] 
https://github.com/lemmy/BlockingQueue/#v18-tlaps-co-domain-of-buffer-not-relevant-for-proof 

-- 
You received this message because you are subscribed to the Google Groups "tlaplus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tlaplus+unsubscribe@xxxxxxxxxxxxxxxx.
To view this discussion on the web visit https://groups.google.com/d/msgid/tlaplus/14047959-eaa6-4691-995d-4d6aa27cbec5n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "tlaplus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tlaplus+unsubscribe@xxxxxxxxxxxxxxxx.
To view this discussion on the web visit https://groups.google.com/d/msgid/tlaplus/9BDED377-1BA4-4A2F-944B-E58D3D2D1A26%40gmail.com.