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

Re: [tlaplus] recursion



Hello,

I am not sure I fully understand what you are trying to achieve (also, your data structure really appears to be a sequence, not a set, because you assume an order on the entries). Here is a suggestion for part of your problem: given an index i into the sequence, find the closest index for which the associated entry has its flag set to true, otherwise return 0 (which is not a valid sequence index). I presume that this should help you write the function that you are actually interested in.

\* the smallest integer in S, 0 if S is empty
Least(S) ==
  IF S = {} THEN 0
  ELSE CHOOSE i \in S : \A j \in S : i <= j

FindNextTrueEntry(seq, i) == Least({j \in i+1 .. Len(seq) : seq[j].flag})

Note that the Community modules [1] contain the definition of Min, which is similar to Least above, except it assumes that the set is non-empty.

You could write a recursive definition of the operator, but a purely set-theoretic definition like the above is often easier to read.

Hope this helps,
Stephan

[1] https://github.com/tlaplus/CommunityModules/blob/master/modules/FiniteSetsExt.tla

On 3 Mar 2022, at 03:09, jiaojiao cai <caijiaojiao118921@xxxxxxxxx> wrote:

I have a sequence, which is a set of records. The records include three parts: oldVal, newVal and Boolean value. Now I need to traverse the sequence. When I traverse the record a, I need to find the Boolean value of the record B closest to a as true. If the Boolean value of a is true, you need to judge whether the a.oldVal is equal to the B.newVal. if so, traverse the next record, otherwise return false; If the Boolean value of a is false, you need to judge whether a.oldVal is not equal to B.newVal. if so traverse the next record, otherwise returns false。
How can such function be implemented using recursion in TLA+

<question.jpg>

--
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/ef8335ae-08d3-42dc-a8e6-b37c5ef3d595n%40googlegroups.com.
<question.jpg>

--
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/854D0551-F606-420C-B3B1-4467F6AEE0BB%40gmail.com.