Generating sequences of functions

35 views
Skip to first unread message

pablo fernandez

unread,
Oct 4, 2021, 6:35:14 PM10/4/21
to tla...@googlegroups.com
Hello!

I have a function that represents a transaction:

[user: 1..3, amount: 1..6]

And would like to have the set of all sequences from 0 to 3 transactions, e.g:

{<<>>, <<[user:1, amount: 0]>>, <<[user:1, amount: 0], [user:2, amount: 0]>> ... }

How can I achieve this?

Pablo
Message has been deleted

Isaac DeFrain

unread,
Oct 4, 2021, 7:16:21 PM10/4/21
to tla...@googlegroups.com
Hey Pablo,

If you only need an implicit (non-enumerable) definition, this will do the trick:

Seq_n(n, s) == { seq \in Seq(s) : Len(seq) <= n }

If you need an explicit definition, a recursive definition will do the trick:

RECURSIVE seq_n(_, _, _)
seq_n(n, s, acc) ==
  IF n = 0 THEN acc
  ELSE
    LET next == { Append(a, x) : x \in s, a \in acc }
    IN seq_n(n - 1, s, acc \cup next)

\* set of sequences of length at most n
Seq_n(n, s) == seq_n(n, s, {<<>>})

I hope this helps!


Best,

Isaac DeFrain


--
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+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tlaplus/CAN3aEu7h%3DuR%2B4EJSBNP9qMGWddzpkPFo8bccUjPeKFovob-tsQ%40mail.gmail.com.

Markus Kuppe

unread,
Oct 4, 2021, 7:33:52 PM10/4/21
to tla...@googlegroups.com
On 10/4/21 4:04 PM, Markus Kuppe wrote:
>
> { <<e>> : e \in [user: 1..3, amount: 1..6]} \cup {<<>>}

Apologies, I didn't read your example carefully.

Use Isaac's solution or

SeqOf([user: 1..3, amount: 0..6], 3)

with SeqOf from the CommunityModules [1].

Markus

[1]
https://github.com/tlaplus/CommunityModules/blob/913ba86e3e5a40d5b37b8adb1b1f4883cbe62ef4/modules/SequencesExt.tla#L34-L39

Pablo Fernandez

unread,
Oct 5, 2021, 10:54:43 PM10/5/21
to tlaplus
Thanks so much Isaac and Markus!
Reply all
Reply to author
Forward
0 new messages