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

Re: [tlaplus] Converting TLA+ spec to PlusCal

Thank you, Stephan!!

I'm also wondering how I could write the following in PlusCal.

I have these global variables:

peers = {n_1, n_2, n_3, n_4}
msgs = [node_id \in peers |-> {}]

I want to add [t |-> "PROPOSE"] message for every peer in a process.

I've tried to do it like this, but it does not work as expected. What may I be doing wrong?

        print <<"with">>;
        with peer_id \in peers do
            print <<"peers", peers, "peer", peer_id>>;
            msgs[peer_id] := msgs[peer_id] \union {[t |-> "PROPOSE"]};
        end with;

        print <<"msgs", msgs>>;

I get the following output:


<<"peers", {n_1, n_2, n_3, n_4}, "peer", n_1>>

<<"msgs", (n_1 :> {[t |-> "PROPOSE"]} @@ n_2 :> {} @@ n_3 :> {} @@ n_4 :> {})>>

<<"peers", {n_1, n_2, n_3, n_4}, "peer", n_2>>

<<"msgs", (n_1 :> {} @@ n_2 :> {[t |-> "PROPOSE"]} @@ n_3 :> {} @@ n_4 :> {})>>

<<"peers", {n_1, n_2, n_3, n_4}, "peer", n_3>>

<<"msgs", (n_1 :> {} @@ n_2 :> {} @@ n_3 :> {[t |-> "PROPOSE"]} @@ n_4 :> {})>>

<<"peers", {n_1, n_2, n_3, n_4}, "peer", n_4>>

<<"msgs", (n_1 :> {} @@ n_2 :> {} @@ n_3 :> {} @@ n_4 :> {[t |-> "PROPOSE"]})>>

Where I would expect:


<<"peers", {n_1, n_2, n_3, n_4}, "peer", n_1>>

<<"peers", {n_1, n_2, n_3, n_4}, "peer", n_2>>

<<"peers", {n_1, n_2, n_3, n_4}, "peer", n_3>>

<<"peers", {n_1, n_2, n_3, n_4}, "peer", n_4>>

<<"msgs", (n_1 :> {[t |-> "PROPOSE"]} @@ n_2 :>  {[t |-> "PROPOSE"]}   @@ n_3 :>  {[t |-> "PROPOSE"]}   @@ n_4 :>  {[t |-> "PROPOSE"]}  )>>

On Monday, December 19, 2022 at 8:30:20 AM UTC+2 Stephan Merz wrote:

TLA+ is more general than PlusCal, and a systematic conversion to PlusCal is unlikely to yield idiomatic results, if it is possible at all: you will probably end up with a single while loop containing all possible actions. It is a bit like the normal form theorem in computability theory.

On 18 Dec 2022, at 13:24, Deividas Bražėnas <deividas...@xxxxxxxxx> wrote:

Hello all,
I have a TLA+ spec that I'd like to convert to PlusCal, but I'm facing some issues as I don't know how to convert a few parts of the specification.

1. I want to have this predicate as a process, but I'm not sure how to convert this part "\E n \in CN, p \in BOOLEAN :"

UpdatePredicate ==
\E n \in CN, p \in BOOLEAN :
/\ predicate[n] => p \* Only monotonic updates are make the algorithm to terminate.
/\ predicate' = [predicate EXCEPT ![n] = p]
/\ UNCHANGED <<bcNode, bcValue, output, msgs>>

In PlusCal you could represent this as

with (n \in CN, p \in BOOLEAN) {
  await (predicate[n] => p);
  predicate[n] := p

2. I want to specify global variable bcValue in Init based on the set of bcNode

/\ \/ bcNode \in CN /\ bcValue \in Value
    \/ bcNode \in FN /\ bcValue = NotValue

You could perhaps write

  bcNode \in CN \union FN,
  bcValue \in (CASE bcNode \in CN -> Value [] bcNode \in FN -> {NotValue});


The content of this email, including all attachments, is confidential. If you are not the intended recipient, please notify us immediately and delete this email. Any disclosure, copying, distribution or any other use of its content is strictly prohibited.

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/3fb78eb2-9d83-4e1b-b747-29a683469f7an%40googlegroups.com.