I believe that the post [1] on StackOverflow, with a link to a worked-out example on GitHub, should help you get started. If I understand correctly, the TLA+ specification of your operator would be Range(s) == { s[i] : i \in DOMAIN s } RECURSIVE PermSeqs(_,_) \* set of sequences of length k that are permutations of elements of sequence s
-- PermSeqs(s,k) == IF k=0 THEN { << >> } ELSE { t \in [1..k -> Range(s)] : \E i \in 1 .. Len(s) : /\ Head(t) = s[i] /\ Tail(t) \in PermSeqs(SubSeq(s,1,i-1) \o SubSeq(s,i+1,Len(s)), k-1) } For example, PermSeqs(<<1,2,2,3,4>>, 2) = { <<1, 2>>, <<1, 3>>, <<1, 4>>, <<2, 1>>, <<2, 2>>, <<2, 3>>, <<2, 4>>, <<3, 1>>, <<3, 2>>, <<3, 4>>, <<4, 1>>, <<4, 2>>, <<4, 3>> } PermSeqs(<<1,2>>, 3) = {} Stephan [1] https://stackoverflow.com/questions/53908653/use-module-overloading-to-implement-a-hash-function-in-tla
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 post to this group, send email to tlaplus@xxxxxxxxxxxxxxxx. Visit this group at https://groups.google.com/group/tlaplus. For more options, visit https://groups.google.com/d/optout. |